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