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
use core\event\base;
20
 
21
/**
22
 * The quiz sub-grade that this slot contributes to has changed.
23
 *
24
 * @property-read array $other {
25
 *      Extra information about event.
26
 *
27
 *      - int quizid: the id of the quiz.
28
 *      - int previousgradeitem: the previous max mark value.
29
 *      - int newgradeitem: the new max mark value.
30
 * }
31
 *
32
 * @package   mod_quiz
33
 * @copyright 2023 The Open University
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class slot_grade_item_updated extends base {
37
    protected function init() {
38
        $this->data['objecttable'] = 'quiz_slots';
39
        $this->data['crud'] = 'u';
40
        $this->data['edulevel'] = self::LEVEL_TEACHING;
41
    }
42
 
43
    public static function get_name() {
44
        return get_string('eventslotgradeitemupdated', 'mod_quiz');
45
    }
46
 
47
    public function get_description() {
48
        return "The user with id '$this->userid' updated the slot with id '{$this->objectid}' " .
49
            "belonging to the quiz with course module id '$this->contextinstanceid'. " .
50
            "The grade item this slot contributes to was changed from '{$this->other['previousgradeitem']}' " .
51
            "to '{$this->other['newgradeitem']}'.";
52
    }
53
 
54
    public function get_url() {
55
        return new \moodle_url('/mod/quiz/editgrading.php', [
56
            'cmid' => $this->contextinstanceid,
57
        ]);
58
    }
59
 
60
    protected function validate_data() {
61
        parent::validate_data();
62
 
63
        if (!isset($this->objectid)) {
64
            throw new \coding_exception('The \'objectid\' value must be set.');
65
        }
66
 
67
        if (!isset($this->contextinstanceid)) {
68
            throw new \coding_exception('The \'contextinstanceid\' value must be set.');
69
        }
70
 
71
        if (!isset($this->other['quizid'])) {
72
            throw new \coding_exception('The \'quizid\' value must be set in other.');
73
        }
74
 
75
        if (!array_key_exists('previousgradeitem', $this->other)) {
76
            throw new \coding_exception('The \'previousgradeitem\' value must be set in other.');
77
        }
78
 
79
        if (!array_key_exists('newgradeitem', $this->other)) {
80
            throw new \coding_exception('The \'newgradeitem\' value must be set in other.');
81
        }
82
    }
83
 
84
    public static function get_objectid_mapping() {
85
        return ['db' => 'quiz_slots', 'restore' => 'quiz_question_instance'];
86
    }
87
 
88
    public static function get_other_mapping() {
89
        return [
90
            'quizid' => ['db' => 'quiz', 'restore' => 'quiz'],
91
        ];
92
    }
93
}