MDL-49846 tool_monitor: Subscription page now filters on site events.

This commit is contained in:
Adrian Greeve 2015-04-16 10:04:07 +08:00
parent 24a2babdd3
commit 19452c99d7
3 changed files with 25 additions and 27 deletions

View file

@ -215,17 +215,13 @@ class rules extends \table_sql implements \renderable {
return false; return false;
} }
$orderby = 'visible DESC, sortorder ASC'; $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)) { if ($courses = get_user_capability_course('tool/monitor:subscribe', null, true, 'fullname', $orderby)) {
foreach ($courses as $course) { foreach ($courses as $course) {
$options[$course->id] = format_string($course->fullname, true, $options[$course->id] = format_string($course->fullname, true,
array('context' => \context_course::instance($course->id))); 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'); $url = new \moodle_url('/admin/tool/monitor/index.php');
$select = new \single_select($url, 'courseid', $options, $this->courseid); $select = new \single_select($url, 'courseid', $options, $this->courseid);
$select->set_label(get_string('selectacourse', 'tool_monitor')); $select->set_label(get_string('selectacourse', 'tool_monitor'));

View file

@ -25,27 +25,35 @@
require_once(__DIR__ . '/../../../config.php'); require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir.'/adminlib.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); $action = optional_param('action', '', PARAM_ALPHA);
$cmid = optional_param('cmid', 0, PARAM_INT); $cmid = optional_param('cmid', 0, PARAM_INT);
$ruleid = optional_param('ruleid', 0, PARAM_INT); $ruleid = optional_param('ruleid', 0, PARAM_INT);
$subscriptionid = optional_param('subscriptionid', 0, PARAM_INT); $subscriptionid = optional_param('subscriptionid', 0, PARAM_INT);
$confirm = optional_param('confirm', false, PARAM_BOOL); $confirm = optional_param('confirm', false, PARAM_BOOL);
require_login(); // Validate course id.
// We need to explicitly check that the course id is something legitimate.
if (empty($courseid)) { 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')) { if (!get_config('tool_monitor', 'enablemonitor')) {
// This should never happen as the this page does not appear in navigation when the tool is disabled. // 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'); 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)); $PAGE->set_context(context_user::instance($USER->id));
// Set up the page. // Set up the page.
@ -85,7 +93,7 @@ if (!empty($action)) {
} else { } else {
$subscription = \tool_monitor\subscription_manager::get_subscription($subscriptionid); $subscription = \tool_monitor\subscription_manager::get_subscription($subscriptionid);
echo $OUTPUT->header(); 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); $confirmurl, $cancelurl);
echo $OUTPUT->footer(); echo $OUTPUT->footer();
exit(); exit();
@ -121,14 +129,15 @@ if (!empty($totalsubs)) {
} }
// Render the potential rules list. // Render the potential rules list.
// Check the capability here before displaying any rules to subscribe to. echo $OUTPUT->heading(get_string('rulescansubscribe', 'tool_monitor'), 3);
if (has_capability('tool/monitor:subscribe', $coursecontext)) { 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. // 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)) { if (empty($totalrules)) {
// No rules present. Show a link to manage rules page if permissions permit. // No rules present. Show a link to manage rules page if permissions permit.

View file

@ -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. // 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) { if (get_config('tool_monitor', 'enablemonitor') && $USER->id == $user->id) {
// The $course->id will always be the course that corresponds to the current context. $url = new moodle_url('/admin/tool/monitor/index.php');
$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, $subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url,
navigation_node::TYPE_SETTING, null, 'monitor', new pix_icon('i/settings', '')); navigation_node::TYPE_SETTING, null, 'monitor', new pix_icon('i/settings', ''));