MDL-49412 tool_monitor: Minor fixes to stop errors.

Part of MDL-45774.
This commit is contained in:
Adrian Greeve 2015-04-09 11:00:20 +08:00
parent 06347532f0
commit f3a493debe
2 changed files with 21 additions and 12 deletions

View File

@ -33,6 +33,12 @@ $subscriptionid = optional_param('subscriptionid', 0, PARAM_INT);
$confirm = optional_param('confirm', false, PARAM_BOOL);
require_login();
// We need to explicitly check that the course id is something legitimate.
if (empty($courseid)) {
$courseid = SITEID;
}
$coursecontext = context_course::instance($courseid);
if (!get_config('tool_monitor', 'enablemonitor')) {

View File

@ -77,18 +77,21 @@ function tool_monitor_extend_navigation_frontpage($navigation, $course, $context
function tool_monitor_extend_navigation_user_settings($navigation, $user, $usercontext, $course, $coursecontext) {
global $USER, $SITE;
// The $course->id will always be the course that corresponds to the current context.
$courseid = $course->id;
// A $course->id of $SITE->id might either be the frontpage or the site. So if we get the site ID back, check the...
// ...courseid parameter passed to the page so we can know if we are looking at the frontpage rules or site level rules.
if ($course->id == $SITE->id && optional_param('courseid', $course->id, PARAM_INT) == 0) {
$courseid = 0;
}
$url = new moodle_url('/admin/tool/monitor/index.php', array('courseid' => $courseid));
$subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url,
navigation_node::TYPE_SETTING, null, 'monitor', new pix_icon('i/settings', ''));
// Don't show the setting if the event monitor isn't turned on.
if (get_config('tool_monitor', 'enablemonitor')) {
// The $course->id will always be the course that corresponds to the current context.
$courseid = $course->id;
// A $course->id of $SITE->id might either be the frontpage or the site. So if we get the site ID back, check the...
// ...courseid parameter passed to the page so we can know if we are looking at the frontpage rules or site level rules.
if ($course->id == $SITE->id && optional_param('courseid', $course->id, PARAM_INT) == 0) {
$courseid = 0;
}
$url = new moodle_url('/admin/tool/monitor/index.php', array('courseid' => $courseid));
$subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url,
navigation_node::TYPE_SETTING, null, 'monitor', new pix_icon('i/settings', ''));
if (isset($subsnode) && !empty($navigation)) {
$navigation->add_node($subsnode);
if (isset($subsnode) && !empty($navigation)) {
$navigation->add_node($subsnode);
}
}
}