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
/**
18
 * The mod_quiz attempt submitted event.
19
 *
20
 * @package mod_quiz
21
 * @copyright 2024 Catalyst IT Europe Ltd.
22
 * @author Mark Johnson <mark.johnson@catalyst-eu.net>
23
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
namespace mod_quiz\event;
26
 
27
/**
28
 * The mod_quiz attempt graded event class.
29
 *
30
 * @package    mod_quiz
31
 * @since      Moodle 4.5
32
 * @copyright  2024
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class attempt_graded extends \core\event\base {
36
    /**
37
     * Init method.
38
     */
39
    protected function init(): void {
40
        $this->data['objecttable'] = 'quiz_attempts';
41
        $this->data['crud'] = 'u';
42
        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
43
    }
44
 
45
    /**
46
     * Returns description of what happened.
47
     *
48
     * @return string
49
     */
50
    public function get_description(): string {
51
        return "The attempt with id {$this->objectid} for for quiz with course module id {$this->contextinstanceid} by user with " .
52
            "id {$this->relateduserid} had automatic grading performed.";
53
    }
54
 
55
    /**
56
     * Returns localised general event name.
57
     *
58
     * @return string
59
     */
60
    public static function get_name(): string {
61
        return get_string('eventquizattemptgraded', 'mod_quiz');
62
    }
63
 
64
    /**
65
     * Returns relevant URL.
66
     *
67
     * @return \moodle_url
68
     */
69
    public function get_url(): \moodle_url {
70
        return new \moodle_url('/mod/quiz/review.php', ['attempt' => $this->objectid]);
71
    }
72
 
73
    /**
74
     * Custom validation.
75
     *
76
     * @throws \coding_exception
77
     * @return void
78
     */
79
    protected function validate_data(): void {
80
        parent::validate_data();
81
 
82
        if (!isset($this->relateduserid)) {
83
            throw new \coding_exception('The \'relateduserid\' must be set.');
84
        }
85
 
86
        if (!array_key_exists('submitterid', $this->other)) {
87
            throw new \coding_exception('The \'submitterid\' value must be set in other.');
88
        }
89
    }
90
 
91
    #[\Override]
92
    public static function get_objectid_mapping(): array {
93
        return ['db' => 'quiz_attempts', 'restore' => 'quiz_attempt'];
94
    }
95
 
96
    #[\Override]
97
    public static function get_other_mapping(): array {
98
        $othermapped = [];
99
        $othermapped['submitterid'] = ['db' => 'user', 'restore' => 'user'];
100
        $othermapped['quizid'] = ['db' => 'quiz', 'restore' => 'quiz'];
101
 
102
        return $othermapped;
103
    }
104
}