MDL-47862 tool_monitor: Fix tool monitor navigation tree

Added event monitor rules link to the frontpage navigation tree, when
editing the frontpage rules. Added hack so that when viewing the site
context subscriptions, the link in navigation is correct, allowing the
breadcrumbs to appear
This commit is contained in:
John Okely 2014-10-31 10:29:24 +08:00 committed by Sam Hemelryk
parent 8f6b6982fa
commit 9aa9a1c70a
2 changed files with 38 additions and 3 deletions

View File

@ -44,6 +44,27 @@ function tool_monitor_extend_navigation_course($navigation, $course, $context) {
}
}
/**
* This function extends the navigation with the tool items
*
* @param navigation_node $navigation The navigation node to extend
* @param stdClass $course The course to object for the tool
* @param context $context The context of the course
*/
function tool_monitor_extend_navigation_frontpage($navigation, $course, $context) {
if (has_capability('tool/monitor:managerules', $context)) {
$url = new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => $course->id));
$settingsnode = navigation_node::create(get_string('managerules', 'tool_monitor'), $url, navigation_node::TYPE_SETTING,
null, null, new pix_icon('i/settings', ''));
$reportnode = $navigation->get('frontpagereports');
if (isset($settingsnode) && !empty($reportnode)) {
$reportnode->add_node($settingsnode);
}
}
}
/**
* This function extends the navigation with the tool items for user settings node.
*
@ -54,10 +75,17 @@ function tool_monitor_extend_navigation_course($navigation, $course, $context) {
* @param context $coursecontext The context of the course
*/
function tool_monitor_extend_navigation_user_settings($navigation, $user, $usercontext, $course, $coursecontext) {
global $USER;
global $USER, $SITE;
if (($USER->id == $user->id) && (has_capability('tool/monitor:subscribe', $coursecontext)
&& get_config('tool_monitor', 'enablemonitor'))) {
$url = new moodle_url('/admin/tool/monitor/index.php', array('courseid' => $course->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));
$subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url,
navigation_node::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));

View File

@ -4512,7 +4512,7 @@ class settings_navigation extends navigation_node {
// View course reports.
if (has_capability('moodle/site:viewreports', $coursecontext)) { // Basic capability for listing of reports.
$frontpagenav = $frontpage->add(get_string('reports'), null, self::TYPE_CONTAINER, null, null,
$frontpagenav = $frontpage->add(get_string('reports'), null, self::TYPE_CONTAINER, null, 'frontpagereports',
new pix_icon('i/stats', ''));
$coursereports = core_component::get_plugin_list('coursereport');
foreach ($coursereports as $report=>$dir) {
@ -4554,6 +4554,13 @@ class settings_navigation extends navigation_node {
$url = new moodle_url('/files/index.php', array('contextid'=>$coursecontext->id));
$frontpage->add(get_string('sitelegacyfiles'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/folder', ''));
}
// Let admin tools hook into frontpage navigation.
$tools = get_plugin_list_with_function('tool', 'extend_navigation_frontpage', 'lib.php');
foreach ($tools as $toolfunction) {
$toolfunction($frontpage, $course, $coursecontext);
}
return $frontpage;
}