| 1 | efrain | 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 | namespace mod_quiz\event;
 | 
        
           |  |  | 18 |   | 
        
           |  |  | 19 | use coding_exception;
 | 
        
           |  |  | 20 | use core\event\base;
 | 
        
           |  |  | 21 | use moodle_url;
 | 
        
           |  |  | 22 |   | 
        
           |  |  | 23 | /**
 | 
        
           |  |  | 24 |  * Event fired when a quiz attempt is reopened.
 | 
        
           |  |  | 25 |  *
 | 
        
           |  |  | 26 |  * @property-read array $other {
 | 
        
           |  |  | 27 |  *      Extra information about event.
 | 
        
           |  |  | 28 |  *
 | 
        
           |  |  | 29 |  *      - int submitterid: id of submitter (null when triggered by CLI script).
 | 
        
           |  |  | 30 |  *      - int quizid: (optional) id of the quiz.
 | 
        
           |  |  | 31 |  * }
 | 
        
           |  |  | 32 |  *
 | 
        
           |  |  | 33 |  * @package   mod_quiz
 | 
        
           |  |  | 34 |  * @since     Moodle 4.2
 | 
        
           |  |  | 35 |  * @copyright 2023 The Open University
 | 
        
           |  |  | 36 |  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 37 |  */
 | 
        
           |  |  | 38 | class attempt_reopened extends base {
 | 
        
           |  |  | 39 |   | 
        
           |  |  | 40 |     protected function init() {
 | 
        
           |  |  | 41 |         $this->data['objecttable'] = 'quiz_attempts';
 | 
        
           |  |  | 42 |         $this->data['crud'] = 'u';
 | 
        
           |  |  | 43 |         $this->data['edulevel'] = self::LEVEL_TEACHING;
 | 
        
           |  |  | 44 |     }
 | 
        
           |  |  | 45 |   | 
        
           |  |  | 46 |     public function get_description(): string {
 | 
        
           |  |  | 47 |         return "The user with id '$this->relateduserid' has had their attempt with id '$this->objectid'" .
 | 
        
           |  |  | 48 |             "for the quiz with course module id '$this->contextinstanceid' re-opened by the user with id '$this->userid'.";
 | 
        
           |  |  | 49 |     }
 | 
        
           |  |  | 50 |   | 
        
           |  |  | 51 |     public static function get_name(): string {
 | 
        
           |  |  | 52 |         return get_string('eventquizattemptreopened', 'mod_quiz');
 | 
        
           |  |  | 53 |     }
 | 
        
           |  |  | 54 |   | 
        
           |  |  | 55 |     public function get_url(): moodle_url {
 | 
        
           |  |  | 56 |         return new moodle_url('/mod/quiz/review.php', ['attempt' => $this->objectid]);
 | 
        
           |  |  | 57 |     }
 | 
        
           |  |  | 58 |   | 
        
           |  |  | 59 |     protected function validate_data(): void {
 | 
        
           |  |  | 60 |         parent::validate_data();
 | 
        
           |  |  | 61 |   | 
        
           |  |  | 62 |         if (!isset($this->relateduserid)) {
 | 
        
           |  |  | 63 |             throw new coding_exception('The \'relateduserid\' must be set.');
 | 
        
           |  |  | 64 |         }
 | 
        
           |  |  | 65 |   | 
        
           |  |  | 66 |         if (!array_key_exists('submitterid', $this->other)) {
 | 
        
           |  |  | 67 |             throw new coding_exception('The \'submitterid\' value must be set in other.');
 | 
        
           |  |  | 68 |         }
 | 
        
           |  |  | 69 |     }
 | 
        
           |  |  | 70 |   | 
        
           |  |  | 71 |     public static function get_objectid_mapping(): array {
 | 
        
           |  |  | 72 |         return ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt'];
 | 
        
           |  |  | 73 |     }
 | 
        
           |  |  | 74 |   | 
        
           |  |  | 75 |     public static function get_other_mapping(): array {
 | 
        
           |  |  | 76 |         return [
 | 
        
           |  |  | 77 |             'submitterid' => ['db' => 'user', 'restore' => 'user'],
 | 
        
           |  |  | 78 |             'quizid' => ['db' => 'quiz', 'restore' => 'quiz'],
 | 
        
           |  |  | 79 |         ];
 | 
        
           |  |  | 80 |     }
 | 
        
           |  |  | 81 | }
 |