[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/monitor/ -> lib.php (source)

   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  
  25  defined('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   */
  34  function 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   */
  54  function 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   */
  77  function tool_monitor_extend_navigation_user_settings($navigation, $user, $usercontext, $course, $coursecontext) {
  78      global $USER, $SITE;
  79  
  80      // Don't show the setting if the event monitor isn't turned on. No access to other peoples subscriptions.
  81      if (get_config('tool_monitor', 'enablemonitor') && $USER->id == $user->id) {
  82          // Now let's check to see if the user has any courses / site rules that they can subscribe to.
  83          if ($courses = tool_monitor_get_user_courses()) {
  84              $url = new moodle_url('/admin/tool/monitor/index.php');
  85              $subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url,
  86                      navigation_node::TYPE_SETTING, null, 'monitor', new pix_icon('i/settings', ''));
  87  
  88              if (isset($subsnode) && !empty($navigation)) {
  89                  $navigation->add_node($subsnode);
  90              }
  91          }
  92      }
  93  }
  94  
  95  /**
  96   * Get a list of courses and also include 'Site' for site wide rules.
  97   *
  98   * @return array|bool Returns an array of courses or false if the user has no permission to subscribe to rules.
  99   */
 100  function tool_monitor_get_user_courses() {
 101      $orderby = 'visible DESC, sortorder ASC';
 102      $options = array();
 103      if (has_capability('tool/monitor:subscribe', context_system::instance())) {
 104          $options[0] = get_string('site');
 105      }
 106      if ($courses = get_user_capability_course('tool/monitor:subscribe', null, true, 'fullname, visible', $orderby)) {
 107          foreach ($courses as $course) {
 108              $coursectx = context_course::instance($course->id);
 109              if ($course->visible || has_capability('moodle/course:viewhiddencourses', $coursectx)) {
 110                  $options[$course->id] = format_string($course->fullname, true, array('context' => $coursectx));
 111              }
 112          }
 113      }
 114      // If there are no courses and there is no site permission then return false.
 115      if (count($options) < 1) {
 116          return false;
 117      } else {
 118          return $options;
 119      }
 120  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1