Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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   * H5P activity report viewed.
  19   *
  20   * @package     mod_h5pactivity
  21   * @copyright   2020 Ferran Recio <ferran@moodle.com>
  22   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace mod_h5pactivity\event;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * The report_viewed event class.
  31   *
  32   * @property-read array $other {
  33   *      Extra information about the event.
  34   *
  35   *      - int instanceid: The instance ID
  36   *      - int userid: The optional user ID
  37   *      - int attemptid: The optional attempt ID
  38   *
  39   * @package    mod_h5pactivity
  40   * @since      Moodle 3.9
  41   * @copyright  2020 Ferran Recio <ferran@moodle.com>
  42   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  43   */
  44  class report_viewed extends \core\event\base {
  45  
  46      /**
  47       * Init method.
  48       *
  49       * @return void
  50       */
  51      protected function init(): void {
  52          $this->data['objecttable'] = 'h5pactivity';
  53          $this->data['crud'] = 'r';
  54          $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
  55      }
  56  
  57      /**
  58       * Returns localised general event name.
  59       *
  60       * @return string
  61       */
  62      public static function get_name() {
  63          return get_string('report_viewed', 'mod_h5pactivity');
  64      }
  65  
  66      /**
  67       * Custom validation.
  68       *
  69       * @throws \coding_exception
  70       * @return void
  71       */
  72      protected function validate_data() {
  73          parent::validate_data();
  74  
  75          if (empty($this->other['instanceid'])) {
  76              throw new \coding_exception('The \'instanceid\' value must be set in other.');
  77          }
  78      }
  79  
  80      /**
  81       * Returns non-localised description of what happened.
  82       *
  83       * @return string
  84       */
  85      public function get_description() {
  86          return "The user with id '$this->userid' viewed the H5P report for the H5P with " .
  87              "course module id '$this->contextinstanceid'.";
  88      }
  89  
  90      /**
  91       * Get URL related to the action
  92       *
  93       * @return \moodle_url
  94       */
  95      public function get_url() {
  96          $params = ['a' => $this->other['instanceid']];
  97  
  98          if (!empty($this->other['userid'])) {
  99              $params['userid'] = $this->other['userid'];
 100          }
 101  
 102          if (!empty($this->other['attemptid'])) {
 103              $params['attemptid'] = $this->other['attemptid'];
 104          }
 105  
 106          return new \moodle_url('/mod/h5pactivity/report.php', $params);
 107      }
 108  
 109      /**
 110       * This is used when restoring course logs where it is required that we
 111       * map the objectid to it's new value in the new course.
 112       *
 113       * @return array
 114       */
 115      public static function get_objectid_mapping() {
 116          return ['db' => 'h5pactivity', 'restore' => 'h5pactivity'];
 117      }
 118  
 119      /**
 120       * Return the other field mapping.
 121       *
 122       * @return array
 123       */
 124      public static function get_other_mapping() {
 125          $othermapped = array();
 126          $othermapped['attemptid'] = array('db' => 'h5pactivity_attempts', 'restore' => 'h5pactivity_attempts');
 127          $othermapped['userid'] = array('db' => 'user', 'restore' => 'user');
 128          return $othermapped;
 129      }
 130  
 131  }