Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

   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_log report viewed event.
  19   *
  20   * @package    report_log
  21   * @copyright  2013 Ankit Agarwal
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace report_log\event;
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * The report_log report viewed event class.
  30   *
  31   * @property-read array $other {
  32   *      Extra information about the event.
  33   *
  34   *      - int groupid: Group to display.
  35   *      - int date: Date to display logs from.
  36   *      - int modid: Module id for which logs were displayed.
  37   *      - string modaction: Module action.
  38   *      - string logformat: Log format in which logs were displayed.
  39   * }
  40   *
  41   * @package    report_log
  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_OTHER;
  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_log');
  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 log report for the course with id '$this->courseid'.";
  74      }
  75  
  76      /**
  77       * Returns relevant URL.
  78       *
  79       * @return \moodle_url
  80       */
  81      public function get_url() {
  82          return new \moodle_url('/report/log/index.php', array('id' => $this->courseid));
  83      }
  84  
  85      /**
  86       * Custom validation.
  87       *
  88       * @throws \coding_exception
  89       * @return void
  90       */
  91      protected function validate_data() {
  92          parent::validate_data();
  93          if (!isset($this->other['groupid'])) {
  94              throw new \coding_exception('The \'groupid\' value must be set in other.');
  95          }
  96  
  97          if (!isset($this->other['date'])) {
  98              throw new \coding_exception('The \'date\' value must be set in other.');
  99          }
 100  
 101          if (!isset($this->other['modid'])) {
 102              throw new \coding_exception('The \'modid\' value must be set in other.');
 103          }
 104  
 105          if (!isset($this->other['modaction'])) {
 106              throw new \coding_exception('The \'modaction\' value must be set in other.');
 107          }
 108  
 109          if (!isset($this->other['logformat'])) {
 110              throw new \coding_exception('The \'logformat\' value must be set in other.');
 111          }
 112  
 113          if (!isset($this->relateduserid)) {
 114              throw new \coding_exception('The \'relateduserid\' must be set.');
 115          }
 116      }
 117  
 118      public static function get_other_mapping() {
 119          $othermapped = array();
 120          $othermapped['modid'] = array('db' => 'course_modules', 'restore' => 'course_module');
 121          $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');
 122  
 123          return $othermapped;
 124      }
 125  }