Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
/**
20
 * The mod_quiz slot display updated event class.
21
 *
22
 * @property-read array $other {
23
 *      Extra information about event.
24
 *
25
 *      - int quizid: the id of the quiz.
26
 *      - string displaynumber: the slot's customised question number value.
27
 * }
28
 *
29
 * @package    mod_quiz
30
 * @copyright  2022 The Open University
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class slot_displaynumber_updated extends \core\event\base {
34
    /**
35
     * Initialise the quiz_slots table.
36
     */
37
    protected function init(): void {
38
        $this->data['objecttable'] = 'quiz_slots';
39
        $this->data['crud'] = 'u';
40
        $this->data['edulevel'] = self::LEVEL_TEACHING;
41
    }
42
 
43
    /**
44
     * Return the name of the event.
45
     *
46
     * @return string
47
     */
48
    public static function get_name(): string {
49
        return get_string('eventslotdisplayedquestionnumberupdated', 'mod_quiz');
50
    }
51
 
52
    /**
53
     * Log describes which user customised the question number in a given slot and in which quiz.
54
     *
55
     * @return string
56
     */
57
    public function get_description(): string {
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 customised question number value was set to '{$this->other['displaynumber']}'.";
61
    }
62
 
63
    /**
64
     * Return the url object of the quiz editing page.
65
     *
66
     * @return \moodle_url
67
     */
68
    public function get_url(): \moodle_url {
69
        return new \moodle_url('/mod/quiz/edit.php', ['cmid' => $this->contextinstanceid]);
70
    }
71
 
72
    /**
73
     * validate the data being logged.
74
     */
75
    protected function validate_data(): void {
76
        parent::validate_data();
77
 
78
        if (!isset($this->objectid)) {
79
            throw new \coding_exception('The \'objectid\' value must be set.');
80
        }
81
 
82
        if (!isset($this->contextinstanceid)) {
83
            throw new \coding_exception('The \'contextinstanceid\' value must be set.');
84
        }
85
 
86
        if (!isset($this->other['quizid'])) {
87
            throw new \coding_exception('The \'quizid\' value must be set in other.');
88
        }
89
 
90
        if (!isset($this->other['displaynumber'])) {
91
            throw new \coding_exception('The \'displaynumber\' value must be set in other.');
92
        }
93
    }
94
 
95
    /**
96
     * Return the mapped array.
97
     *
98
     * @return string[]
99
     */
100
    public static function get_objectid_mapping(): array {
101
        return ['db' => 'quiz_slots', 'restore' => 'quiz_question_instance'];
102
    }
103
 
104
    /**
105
     * Return the mapped array.
106
     *
107
     * @return array
108
     */
109
    public static function get_other_mapping(): array {
110
        $othermapped = [];
111
        $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz'];
112
 
113
        return $othermapped;
114
    }
115
}