From 19452c99d7e17fe786272d0b27a4e7e40da15591 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Thu, 16 Apr 2015 10:04:07 +0800 Subject: [PATCH] MDL-49846 tool_monitor: Subscription page now filters on site events. --- .../classes/output/managesubs/rules.php | 6 +-- admin/tool/monitor/index.php | 37 ++++++++++++------- admin/tool/monitor/lib.php | 9 +---- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/admin/tool/monitor/classes/output/managesubs/rules.php b/admin/tool/monitor/classes/output/managesubs/rules.php index c0c031a1e31..b298abff3f6 100644 --- a/admin/tool/monitor/classes/output/managesubs/rules.php +++ b/admin/tool/monitor/classes/output/managesubs/rules.php @@ -215,17 +215,13 @@ class rules extends \table_sql implements \renderable { return false; } $orderby = 'visible DESC, sortorder ASC'; - $options = array(); + $options = array(0 => get_string('site')); if ($courses = get_user_capability_course('tool/monitor:subscribe', null, true, 'fullname', $orderby)) { foreach ($courses as $course) { $options[$course->id] = format_string($course->fullname, true, array('context' => \context_course::instance($course->id))); } } - // If there are no options to display, then don't display anything. - if (count($options) === 0) { - return false; - } $url = new \moodle_url('/admin/tool/monitor/index.php'); $select = new \single_select($url, 'courseid', $options, $this->courseid); $select->set_label(get_string('selectacourse', 'tool_monitor')); diff --git a/admin/tool/monitor/index.php b/admin/tool/monitor/index.php index 5dcc91633af..8d125e8b9b5 100644 --- a/admin/tool/monitor/index.php +++ b/admin/tool/monitor/index.php @@ -25,27 +25,35 @@ require_once(__DIR__ . '/../../../config.php'); require_once($CFG->libdir.'/adminlib.php'); -$courseid = optional_param('courseid', SITEID, PARAM_INT); +$courseid = optional_param('courseid', 0, PARAM_INT); $action = optional_param('action', '', PARAM_ALPHA); $cmid = optional_param('cmid', 0, PARAM_INT); $ruleid = optional_param('ruleid', 0, PARAM_INT); $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. +// Validate course id. if (empty($courseid)) { - $courseid = SITEID; + require_login(); +} else { + // They might want to see rules for this course. + $course = get_course($courseid); + require_login($course); + $coursecontext = context_course::instance($course->id); + // Check for caps. + require_capability('tool/monitor:subscribe', $coursecontext); + $coursename = format_string($course->fullname, true, array('context' => $coursecontext)); } -$coursecontext = context_course::instance($courseid); - if (!get_config('tool_monitor', 'enablemonitor')) { // This should never happen as the this page does not appear in navigation when the tool is disabled. throw new coding_exception('Event monitoring is disabled'); } +// Set the main context to a system context. +$systemcontext = context_system::instance(); +$sitename = format_string($SITE->fullname, true, array('context' => $systemcontext)); +// Use the user context here so that the header shows user information. $PAGE->set_context(context_user::instance($USER->id)); // Set up the page. @@ -85,7 +93,7 @@ if (!empty($action)) { } else { $subscription = \tool_monitor\subscription_manager::get_subscription($subscriptionid); echo $OUTPUT->header(); - echo $OUTPUT->confirm(get_string('subareyousure', 'tool_monitor', $subscription->get_name($coursecontext)), + echo $OUTPUT->confirm(get_string('subareyousure', 'tool_monitor', $subscription->get_name($systemcontext)), $confirmurl, $cancelurl); echo $OUTPUT->footer(); exit(); @@ -121,14 +129,15 @@ if (!empty($totalsubs)) { } // Render the potential rules list. -// Check the capability here before displaying any rules to subscribe to. -if (has_capability('tool/monitor:subscribe', $coursecontext)) { - echo $OUTPUT->heading(get_string('rulescansubscribe', 'tool_monitor'), 3); - echo $renderer->render($rules); -} +echo $OUTPUT->heading(get_string('rulescansubscribe', 'tool_monitor'), 3); +echo $renderer->render($rules); // Check if the user can manage the course rules we are viewing. -$canmanagerules = has_capability('tool/monitor:managerules', $coursecontext); +if (empty($courseid)) { + $canmanagerules = has_capability('tool/monitor:managerules', $systemcontext); +} else { + $canmanagerules = has_capability('tool/monitor:managerules', $coursecontext); +} if (empty($totalrules)) { // No rules present. Show a link to manage rules page if permissions permit. diff --git a/admin/tool/monitor/lib.php b/admin/tool/monitor/lib.php index 4091ef2fa00..cbce85662ff 100644 --- a/admin/tool/monitor/lib.php +++ b/admin/tool/monitor/lib.php @@ -79,14 +79,7 @@ function tool_monitor_extend_navigation_user_settings($navigation, $user, $userc // Don't show the setting if the event monitor isn't turned on. No access to other peoples subscriptions. if (get_config('tool_monitor', 'enablemonitor') && $USER->id == $user->id) { - // 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)); + $url = new moodle_url('/admin/tool/monitor/index.php'); $subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url, navigation_node::TYPE_SETTING, null, 'monitor', new pix_icon('i/settings', ''));