Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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   * Version details.
  19   *
  20   * @package    report
  21   * @subpackage completion
  22   * @copyright  2009 Sam Hemelryk
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die;
  27  
  28  /**
  29   * This function extends the navigation with the report items
  30   *
  31   * @param navigation_node $navigation The navigation node to extend
  32   * @param stdClass $course The course to object for the report
  33   * @param stdClass $context The context of the course
  34   */
  35  function report_completion_extend_navigation_course($navigation, $course, $context) {
  36      global $CFG;
  37  
  38      require_once($CFG->libdir.'/completionlib.php');
  39  
  40      if (has_capability('report/completion:view', $context)) {
  41          $completion = new completion_info($course);
  42          if ($completion->is_enabled() && $completion->has_criteria()) {
  43              $url = new moodle_url('/report/completion/index.php', array('course'=>$course->id));
  44              $navigation->add(get_string('pluginname','report_completion'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
  45          }
  46      }
  47  }
  48  
  49  /**
  50   * This function extends the course navigation with the report items
  51   *
  52   * @param navigation_node $navigation The navigation node to extend
  53   * @param stdClass $user
  54   * @param stdClass $course The course to object for the report
  55   */
  56  function report_completion_extend_navigation_user($navigation, $user, $course) {
  57  
  58      return; //TODO: this plugin was not linked from navigation in 2.0, let's keep it that way for now --skodak
  59  
  60      if (report_completion_can_access_user_report($user, $course)) {
  61          $url = new moodle_url('/report/completion/user.php', array('id'=>$user->id, 'course'=>$course->id));
  62          $navigation->add(get_string('coursecompletion'), $url);
  63      }
  64  }
  65  
  66  /**
  67   * Is current user allowed to access this report
  68   *
  69   * @private defined in lib.php for performance reasons
  70   *
  71   * @param stdClass $user
  72   * @param stdClass $course
  73   * @return bool
  74   */
  75  function report_completion_can_access_user_report($user, $course) {
  76      global $USER, $CFG;
  77  
  78      if (empty($CFG->enablecompletion)) {
  79          return false;
  80      }
  81  
  82      if ($course->id != SITEID and !$course->enablecompletion) {
  83          return false;
  84      }
  85  
  86      $coursecontext = context_course::instance($course->id);
  87      $personalcontext = context_user::instance($user->id);
  88  
  89      if ($user->id == $USER->id) {
  90          if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
  91              return true;
  92          }
  93      } else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
  94          if ($course->showreports and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
  95              return true;
  96          }
  97  
  98      }
  99  
 100      // Check if $USER shares group with $user (in case separated groups are enabled and 'moodle/site:accessallgroups' is disabled).
 101      if (!groups_user_groups_visible($course, $user->id)) {
 102          return false;
 103      }
 104  
 105      if (has_capability('report/completion:view', $coursecontext)) {
 106          return true;
 107      }
 108  
 109      return false;
 110  }
 111  
 112  /**
 113   * Return a list of page types
 114   * @param string $pagetype current page type
 115   * @param stdClass $parentcontext Block's parent context
 116   * @param stdClass $currentcontext Current context of block
 117   * @return array
 118   */
 119  function report_completion_page_type_list($pagetype, $parentcontext, $currentcontext) {
 120      $array = array(
 121          '*'                       => get_string('page-x', 'pagetype'),
 122          'report-*'                => get_string('page-report-x', 'pagetype'),
 123          'report-completion-*'     => get_string('page-report-completion-x',  'report_completion'),
 124          'report-completion-index' => get_string('page-report-completion-index',  'report_completion'),
 125          'report-completion-user'  => get_string('page-report-completion-user',  'report_completion')
 126      );
 127      return $array;
 128  }