[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/report/completion/ -> 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   * 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;
  84      }
  85  
  86      $coursecontext = context_course::instance($course->id);
  87      $personalcontext = context_user::instance($user->id);
  88  
  89      if (has_capability('report/completion:view', $coursecontext)) {
  90          return true;
  91      }
  92  
  93      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      } else if ($user->id == $USER->id) {
  99          if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
 100              return true;
 101          }
 102      }
 103  
 104      return false;
 105  }
 106  
 107  /**
 108   * Return a list of page types
 109   * @param string $pagetype current page type
 110   * @param stdClass $parentcontext Block's parent context
 111   * @param stdClass $currentcontext Current context of block
 112   * @return array
 113   */
 114  function report_completion_page_type_list($pagetype, $parentcontext, $currentcontext) {
 115      $array = array(
 116          '*'                       => get_string('page-x', 'pagetype'),
 117          'report-*'                => get_string('page-report-x', 'pagetype'),
 118          'report-completion-*'     => get_string('page-report-completion-x',  'report_completion'),
 119          'report-completion-index' => get_string('page-report-completion-index',  'report_completion'),
 120          'report-completion-user'  => get_string('page-report-completion-user',  'report_completion')
 121      );
 122      return $array;
 123  }


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