Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
declare(strict_types=1);
18
 
19
namespace mod_quiz\event;
20
 
21
use core\exception\coding_exception;
22
use core\url;
23
 
24
/**
25
 * The question version of a slot has changed.
26
 *
27
 * @property-read array $other {
28
 *      Extra information about event.
29
 *
30
 *      - int quizid: the id of the quiz.
31
 *      - int previousversion: the previous question version.
32
 *      - int newversion: the new question version.
33
 * }
34
 *
35
 * @package   mod_quiz
36
 * @copyright 2024 Catalyst IT Australia Pty Ltd
37
 * @author    Cameron Ball <cameronball@catalyst-au.net>
38
 * @license   https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 */
40
class slot_version_updated extends \core\event\base {
41
 
42
    #[\Override]
43
    protected function init(): void {
44
        $this->data['objecttable'] = 'quiz_slots';
45
        $this->data['crud'] = 'u';
46
        $this->data['edulevel'] = self::LEVEL_TEACHING;
47
    }
48
 
49
    #[\Override]
50
    public static function get_name(): string {
51
        return get_string('eventslotversionupdated', 'mod_quiz');
52
    }
53
 
54
    #[\Override]
55
    public function get_description(): string {
56
        $previousversion = $this->other['previousversion'] ?? 'Always latest';
57
        $newversion = $this->other['newversion'] ?? 'Always latest';
58
        return "The user with id '$this->userid' updated the slot with id '{$this->objectid}' " .
59
            "belonging to the quiz with course module id '$this->contextinstanceid'. " .
60
            "Its question version was changed from '$previousversion' to '$newversion'.";
61
    }
62
 
63
    #[\Override]
64
    public function get_url(): url {
65
        return new url('/mod/quiz/edit.php', ['cmid' => $this->contextinstanceid]);
66
    }
67
 
68
    #[\Override]
69
    protected function validate_data(): void {
70
        parent::validate_data();
71
 
72
        if (!isset($this->objectid)) {
73
            throw new coding_exception('The \'objectid\' value must be set.');
74
        }
75
 
76
        if (!isset($this->contextinstanceid)) {
77
            throw new coding_exception('The \'contextinstanceid\' value must be set.');
78
        }
79
 
80
        if (!isset($this->other['quizid'])) {
81
            throw new coding_exception('The \'quizid\' value must be set in other.');
82
        }
83
 
84
        // The value of previousversion and newversion can be null, so we check if
85
        // the array key exists.
86
        if (!array_key_exists('previousversion', $this->other)) {
87
            throw new coding_exception('The \'previousversion\' value must be set in other.');
88
        }
89
 
90
        if (!array_key_exists('newversion', $this->other)) {
91
            throw new coding_exception('The \'newversion\' value must be set in other.');
92
        }
93
    }
94
 
95
    #[\Override]
96
    public static function get_objectid_mapping(): array {
97
        return ['db' => 'quiz_slots', 'restore' => 'quiz_question_instance'];
98
    }
99
 
100
    #[\Override]
101
    public static function get_other_mapping(): array {
102
        $othermapped = [];
103
        $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz'];
104
 
105
        return $othermapped;
106
    }
107
}