Skip to content

Commit

Permalink
MDL-49846 tool_monitor: Context simplification and clean up.
Browse files Browse the repository at this point in the history
Removed some unnecessary variables and simplified the context
usage in the index.php page.
  • Loading branch information
abgreeve committed May 4, 2015
1 parent 6df7f20 commit bdf899a
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions admin/tool/monitor/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,21 @@
// Validate course id.
if (empty($courseid)) {
require_login();
$context = context_system::instance();
} else {
// They might want to see rules for this course.
$course = get_course($courseid);
require_login($course);
$coursecontext = context_course::instance($course->id);
$context = context_course::instance($course->id);
// Check for caps.
require_capability('tool/monitor:subscribe', $coursecontext);
$coursename = format_string($course->fullname, true, array('context' => $coursecontext));
require_capability('tool/monitor:subscribe', $context);
}

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));

Expand Down Expand Up @@ -93,7 +90,7 @@
} else {
$subscription = \tool_monitor\subscription_manager::get_subscription($subscriptionid);
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('subareyousure', 'tool_monitor', $subscription->get_name($systemcontext)),
echo $OUTPUT->confirm(get_string('subareyousure', 'tool_monitor', $subscription->get_name($context)),
$confirmurl, $cancelurl);
echo $OUTPUT->footer();
exit();
Expand Down Expand Up @@ -133,11 +130,7 @@
echo $renderer->render($rules);

// Check if the user can manage the course rules we are viewing.
if (empty($courseid)) {
$canmanagerules = has_capability('tool/monitor:managerules', $systemcontext);
} else {
$canmanagerules = has_capability('tool/monitor:managerules', $coursecontext);
}
$canmanagerules = has_capability('tool/monitor:managerules', $context);

if (empty($totalrules)) {
// No rules present. Show a link to manage rules page if permissions permit.
Expand Down

0 comments on commit bdf899a

Please sign in to comment.