source: moodle/trunk/fuentes/admin/tool/monitor/lib.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

File size: 4.4 KB
Line 
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * This page lists public api for tool_monitor plugin.
19 *
20 * @package    tool_monitor
21 * @copyright  2014 onwards Ankit Agarwal <ankit.agrr@gmail.com>
22 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die;
26
27/**
28 * This function extends the navigation with the tool items
29 *
30 * @param navigation_node $navigation The navigation node to extend
31 * @param stdClass        $course     The course to object for the tool
32 * @param context         $context    The context of the course
33 */
34function tool_monitor_extend_navigation_course($navigation, $course, $context) {
35    if (has_capability('tool/monitor:managerules', $context) && get_config('tool_monitor', 'enablemonitor')) {
36        $url = new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => $course->id));
37        $settingsnode = navigation_node::create(get_string('managerules', 'tool_monitor'), $url, navigation_node::TYPE_SETTING,
38                null, null, new pix_icon('i/settings', ''));
39        $reportnode = $navigation->get('coursereports');
40
41        if (isset($settingsnode) && !empty($reportnode)) {
42            $reportnode->add_node($settingsnode);
43        }
44    }
45}
46
47/**
48 * This function extends the navigation with the tool items
49 *
50 * @param navigation_node $navigation The navigation node to extend
51 * @param stdClass        $course     The course to object for the tool
52 * @param context         $context    The context of the course
53 */
54function tool_monitor_extend_navigation_frontpage($navigation, $course, $context) {
55
56    if (has_capability('tool/monitor:managerules', $context)) {
57        $url = new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => $course->id));
58        $settingsnode = navigation_node::create(get_string('managerules', 'tool_monitor'), $url, navigation_node::TYPE_SETTING,
59                null, null, new pix_icon('i/settings', ''));
60        $reportnode = $navigation->get('frontpagereports');
61
62        if (isset($settingsnode) && !empty($reportnode)) {
63            $reportnode->add_node($settingsnode);
64        }
65    }
66}
67
68/**
69 * This function extends the navigation with the tool items for user settings node.
70 *
71 * @param navigation_node $navigation  The navigation node to extend
72 * @param stdClass        $user        The user object
73 * @param context         $usercontext The context of the user
74 * @param stdClass        $course      The course to object for the tool
75 * @param context         $coursecontext     The context of the course
76 */
77function tool_monitor_extend_navigation_user_settings($navigation, $user, $usercontext, $course, $coursecontext) {
78    global $USER, $SITE;
79    if (($USER->id == $user->id) && (has_capability('tool/monitor:subscribe', $coursecontext)
80            && get_config('tool_monitor', 'enablemonitor'))) {
81        // The $course->id will always be the course that corresponds to the current context.
82        $courseid = $course->id;
83        // A $course->id of $SITE->id might either be the frontpage or the site. So if we get the site ID back, check the...
84        // ...courseid parameter passed to the page so we can know if we are looking at the frontpage rules or site level rules.
85        if ($course->id == $SITE->id && optional_param('courseid', $course->id, PARAM_INT) == 0) {
86            $courseid = 0;
87        }
88        $url = new moodle_url('/admin/tool/monitor/index.php', array('courseid' => $courseid));
89        $subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url,
90                navigation_node::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
91
92        if (isset($subsnode) && !empty($navigation)) {
93            $navigation->add_node($subsnode);
94        }
95    }
96}
Note: See TracBrowser for help on using the repository browser.