Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

   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   * The report_participation report viewed event.
  19   *
  20   * @package    report_participation
  21   * @copyright  2013 Ankit Agarwal
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace report_participation\event;
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * The report_participation report viewed event class.
  30   *
  31   * @property-read array $other {
  32   *      Extra information about the event.
  33   *
  34   *      - int instanceid: Id of instance.
  35   *      - int roleid: Role id for whom report is viewed.
  36   *      - int groupid: (optional) group id.
  37   *      - int timefrom: (optional) time from which report is viewed.
  38   *      - string action: (optional) action viewed.
  39   * }
  40   *
  41   * @package    report_participation
  42   * @since      Moodle 2.7
  43   * @copyright  2013 Ankit Agarwal
  44   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  45   */
  46  class report_viewed extends \core\event\base {
  47  
  48      /**
  49       * Init method.
  50       *
  51       * @return void
  52       */
  53      protected function init() {
  54          $this->data['crud'] = 'r';
  55          $this->data['edulevel'] = self::LEVEL_TEACHING;
  56      }
  57  
  58      /**
  59       * Return localised event name.
  60       *
  61       * @return string
  62       */
  63      public static function get_name() {
  64          return get_string('eventreportviewed', 'report_participation');
  65      }
  66  
  67      /**
  68       * Returns description of what happened.
  69       *
  70       * @return string
  71       */
  72      public function get_description() {
  73          return "The user with id '$this->userid' viewed the course participation report for the course with id '$this->courseid'.";
  74      }
  75  
  76      /**
  77       * Return the legacy event log data.
  78       *
  79       * @return array
  80       */
  81      protected function get_legacy_logdata() {
  82          return array($this->courseid, "course", "report participation", "report/participation/index.php?id=" . $this->courseid,
  83                  $this->courseid);
  84      }
  85  
  86      /**
  87       * Returns relevant URL.
  88       *
  89       * @return \moodle_url
  90       */
  91      public function get_url() {
  92          return new \moodle_url('/report/participation/index.php', array('id' => $this->courseid,
  93              'instanceid' => $this->other['instanceid'], 'roleid' => $this->other['roleid']));
  94      }
  95  
  96      /**
  97       * Custom validation.
  98       *
  99       * @throws \coding_exception
 100       * @return void
 101       */
 102      protected function validate_data() {
 103          parent::validate_data();
 104          if (empty($this->other['instanceid'])) {
 105              throw new \coding_exception('The \'instanceid\' value must be set in other.');
 106          }
 107  
 108          if (empty($this->other['roleid'])) {
 109              throw new \coding_exception('The \'roleid\' value must be set in other.');
 110          }
 111  
 112          if (!isset($this->other['groupid'])) {
 113              throw new \coding_exception('The \'groupid\' value must be set in other.');
 114          }
 115  
 116          if (!isset($this->other['timefrom'])) {
 117              throw new \coding_exception('The \'timefrom\' value must be set in other.');
 118          }
 119  
 120          if (!isset($this->other['action'])) {
 121              throw new \coding_exception('The \'action\' value must be set in other.');
 122          }
 123  
 124      }
 125  
 126      public static function get_other_mapping() {
 127          $othermapped = array();
 128          // This is a badly named variable - it represents "cm->id" not "cm->instance".
 129          $othermapped['instanceid'] = array('db' => 'course_modules', 'restore' => 'course_module');
 130  
 131          $othermapped['roleid'] = array('db' => 'role', 'restore' => 'role');
 132          $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');
 133  
 134          return $othermapped;
 135  
 136      }
 137  }
 138