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_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       * Return the legacy event log data.
  78       *
  79       * @return array
  80       */
  81      protected function get_legacy_logdata() {
  82          return array($this->courseid, "course", "report log", "report/log/index.php?id=$this->courseid", $this->courseid);
  83      }
  84  
  85      /**
  86       * Returns relevant URL.
  87       *
  88       * @return \moodle_url
  89       */
  90      public function get_url() {
  91          return new \moodle_url('/report/log/index.php', array('id' => $this->courseid));
  92      }
  93  
  94      /**
  95       * Custom validation.
  96       *
  97       * @throws \coding_exception
  98       * @return void
  99       */
 100      protected function validate_data() {
 101          parent::validate_data();
 102          if (!isset($this->other['groupid'])) {
 103              throw new \coding_exception('The \'groupid\' value must be set in other.');
 104          }
 105  
 106          if (!isset($this->other['date'])) {
 107              throw new \coding_exception('The \'date\' value must be set in other.');
 108          }
 109  
 110          if (!isset($this->other['modid'])) {
 111              throw new \coding_exception('The \'modid\' value must be set in other.');
 112          }
 113  
 114          if (!isset($this->other['modaction'])) {
 115              throw new \coding_exception('The \'modaction\' value must be set in other.');
 116          }
 117  
 118          if (!isset($this->other['logformat'])) {
 119              throw new \coding_exception('The \'logformat\' value must be set in other.');
 120          }
 121  
 122          if (!isset($this->relateduserid)) {
 123              throw new \coding_exception('The \'relateduserid\' must be set.');
 124          }
 125      }
 126  
 127      public static function get_other_mapping() {
 128          $othermapped = array();
 129          $othermapped['modid'] = array('db' => 'course_modules', 'restore' => 'course_module');
 130          $othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');
 131  
 132          return $othermapped;
 133      }
 134  }