mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
Merge branch 'wip-MDL-49846-master-v2' of git://github.com/abgreeve/moodle
This commit is contained in:
commit
23c4c76ff9
@ -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'));
|
||||
|
@ -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.
|
||||
|
@ -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', ''));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user