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.
   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 mod_quiz attempt updated event.
  19   *
  20   * @package    mod_quiz
  21   * @copyright  2021 The Open University
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace mod_quiz\event;
  26  
  27  /**
  28   * The mod_quiz attempt updated event class.
  29   *
  30   * @property-read array $other {
  31   *      Extra information about event.
  32   *
  33   *      - int quizid: the id of the quiz.
  34   *      - int page: the page number of attempt.
  35   * }
  36   *
  37   * @package    mod_quiz
  38   * @copyright  2021 The Open University
  39   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class attempt_updated extends \core\event\base {
  42  
  43      /**
  44       * Init method.
  45       */
  46      protected function init() {
  47          $this->data['objecttable'] = 'quiz_attempts';
  48          $this->data['crud'] = 'u';
  49          $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
  50      }
  51  
  52      /**
  53       * Returns localised general event name.
  54       *
  55       * @return string
  56       */
  57      public static function get_name() {
  58          return get_string('eventattemptupdated', 'mod_quiz');
  59      }
  60  
  61      /**
  62       * Returns description of what happened.
  63       *
  64       * @return string
  65       */
  66      public function get_description() {
  67          $pagenumber = $this->other['page'] + 1;
  68  
  69          return "The user with id '$this->userid' has updated responses on page '{$pagenumber}' of the attempt " .
  70              "with id '$this->objectid' belonging to the user " .
  71              "with id '$this->relateduserid' for the quiz with course module id '$this->contextinstanceid'.";
  72      }
  73  
  74      /**
  75       * Returns relevant URL.
  76       *
  77       * @return \moodle_url
  78       */
  79      public function get_url() {
  80          return new \moodle_url('/mod/quiz/review.php', [
  81              'attempt' => $this->objectid,
  82              'page' => $this->other['page']
  83          ]);
  84      }
  85  
  86      /**
  87       * Custom validation.
  88       *
  89       * @throws \coding_exception
  90       * @return void
  91       */
  92      protected function validate_data() {
  93          parent::validate_data();
  94  
  95          if (!isset($this->relateduserid)) {
  96              throw new \coding_exception('The \'relateduserid\' must be set.');
  97          }
  98  
  99          if (!isset($this->other['quizid'])) {
 100              throw new \coding_exception('The \'quizid\' value must be set in other.');
 101          }
 102  
 103          if (!isset($this->other['page'])) {
 104              throw new \coding_exception('The \'page\' value must be set in other.');
 105          }
 106      }
 107  
 108      /**
 109       * This is used when restoring course logs where it is required that we
 110       * map the objectid to it's new value in the new course.
 111       *
 112       * @return array Mapping of object id.
 113       */
 114      public static function get_objectid_mapping() {
 115          return ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt'];
 116      }
 117  
 118      /**
 119       * This is used when restoring course logs where it is required that we
 120       * map the information in 'other' to it's new value in the new course.
 121       *
 122       * @return array List of mapping of other ids.
 123       */
 124      public static function get_other_mapping() {
 125          $othermapped = [];
 126          $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz'];
 127  
 128          return $othermapped;
 129      }
 130  }