[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/report/outline/ -> 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 file contains public API of outline report
  19   *
  20   * @package    report
  21   * @subpackage outline
  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 course 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_outline_extend_navigation_course($navigation, $course, $context) {
  36      if (has_capability('report/outline:view', $context)) {
  37          $url = new moodle_url('/report/outline/index.php', array('id'=>$course->id));
  38          $navigation->add(get_string('pluginname', 'report_outline'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
  39      }
  40  }
  41  
  42  /**
  43   * This function extends the course navigation with the report items
  44   *
  45   * @param navigation_node $navigation The navigation node to extend
  46   * @param stdClass $user
  47   * @param stdClass $course The course to object for the report
  48   */
  49  function report_outline_extend_navigation_user($navigation, $user, $course) {
  50      if (report_outline_can_access_user_report($user, $course)) {
  51          $url = new moodle_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>'outline'));
  52          $navigation->add(get_string('outlinereport'), $url);
  53          $url = new moodle_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>'complete'));
  54          $navigation->add(get_string('completereport'), $url);
  55      }
  56  }
  57  
  58  /**
  59   * Is current user allowed to access this report
  60   *
  61   * @private defined in lib.php for performance reasons
  62   *
  63   * @param stdClass $user
  64   * @param stdClass $course
  65   * @return bool
  66   */
  67  function report_outline_can_access_user_report($user, $course) {
  68      global $USER;
  69  
  70      $coursecontext = context_course::instance($course->id);
  71      $personalcontext = context_user::instance($user->id);
  72  
  73      if (has_capability('report/outline:view', $coursecontext)) {
  74          return true;
  75      }
  76  
  77      if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
  78          if ($course->showreports and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
  79              return true;
  80          }
  81  
  82      } else if ($user->id == $USER->id) {
  83          if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
  84              return true;
  85          }
  86      }
  87  
  88      return false;
  89  }
  90  
  91  /**
  92   * Return a list of page types
  93   * @param string $pagetype current page type
  94   * @param stdClass $parentcontext Block's parent context
  95   * @param stdClass $currentcontext Current context of block
  96   * @return array
  97   */
  98  function report_outline_page_type_list($pagetype, $parentcontext, $currentcontext) {
  99      $array = array(
 100          '*'                    => get_string('page-x', 'pagetype'),
 101          'report-*'             => get_string('page-report-x', 'pagetype'),
 102          'report-outline-*'     => get_string('page-report-outline-x',  'report_outline'),
 103          'report-outline-index' => get_string('page-report-outline-index',  'report_outline'),
 104          'report-outline-user'  => get_string('page-report-outline-user',  'report_outline')
 105      );
 106      return $array;
 107  }
 108  
 109  /**
 110   * Callback to verify if the given instance of store is supported by this report or not.
 111   *
 112   * @param string $instance store instance.
 113   *
 114   * @return bool returns true if the store is supported by the report, false otherwise.
 115   */
 116  function report_outline_supports_logstore($instance) {
 117      if ($instance instanceof \core\log\sql_internal_table_reader || $instance instanceof \logstore_legacy\log\store) {
 118          return true;
 119      }
 120      return false;
 121  }
 122  
 123  /**
 124   * Add nodes to myprofile page.
 125   *
 126   * @param \core_user\output\myprofile\tree $tree Tree object
 127   * @param stdClass $user user object
 128   * @param bool $iscurrentuser
 129   * @param stdClass $course Course object
 130   *
 131   * @return bool
 132   */
 133  function report_outline_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
 134      if (empty($course)) {
 135          // We want to display these reports under the site context.
 136          $course = get_fast_modinfo(SITEID)->get_course();
 137      }
 138      if (report_outline_can_access_user_report($user, $course)) {
 139          $url = new moodle_url('/report/outline/user.php',
 140                  array('id' => $user->id, 'course' => $course->id, 'mode' => 'outline'));
 141          $node = new core_user\output\myprofile\node('reports', 'outline', get_string('outlinereport'), null, $url);
 142          $tree->add_node($node);
 143          $url = new moodle_url('/report/outline/user.php',
 144              array('id' => $user->id, 'course' => $course->id, 'mode' => 'complete'));
 145          $node = new core_user\output\myprofile\node('reports', 'complete', get_string('completereport'), null, $url);
 146          $tree->add_node($node);
 147      }
 148  }


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