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 |
namespace mod_quiz\hook;
|
|
|
17 |
|
|
|
18 |
use core\attribute;
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* A quiz attempt changed state.
|
|
|
22 |
*
|
|
|
23 |
* @package mod_quiz
|
|
|
24 |
* @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net}
|
|
|
25 |
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
|
|
|
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
27 |
*/
|
|
|
28 |
#[attribute\label('A quiz attempt changed state.')]
|
|
|
29 |
#[attribute\tags('quiz', 'attempt')]
|
|
|
30 |
#[attribute\hook\replaces_callbacks('quiz_attempt_deleted::callback')]
|
|
|
31 |
class attempt_state_changed {
|
|
|
32 |
/**
|
|
|
33 |
* Create a new hook instance.
|
|
|
34 |
*
|
|
|
35 |
* @param ?\stdClass $originalattempt The original database record for the attempt, null if it has just been created.
|
|
|
36 |
* @param ?\stdClass $updatedattempt The updated database record of the new attempt, null if it has just been deleted.
|
|
|
37 |
*/
|
|
|
38 |
public function __construct(
|
|
|
39 |
/** @var ?\stdClass The original database record for the attempt, null if it has just been created. */
|
|
|
40 |
protected ?\stdClass $originalattempt,
|
|
|
41 |
/** @var ?\stdClass The updated database record of the new attempt, null if it has just been deleted. */
|
|
|
42 |
protected ?\stdClass $updatedattempt,
|
|
|
43 |
) {
|
|
|
44 |
if (is_null($this->originalattempt) && is_null($this->updatedattempt)) {
|
|
|
45 |
throw new \InvalidArgumentException('originalattempt and updatedattempt cannot both be null.');
|
|
|
46 |
}
|
|
|
47 |
if (
|
|
|
48 |
!is_null($this->originalattempt)
|
|
|
49 |
&& !is_null($this->updatedattempt)
|
|
|
50 |
&& $this->originalattempt->id != $this->updatedattempt->id
|
|
|
51 |
) {
|
|
|
52 |
throw new \InvalidArgumentException('originalattempt and updatedattempt must have the same id.');
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Get the original attempt, null if it has just been created.
|
|
|
58 |
*
|
|
|
59 |
* @return ?\stdClass
|
|
|
60 |
*/
|
|
|
61 |
public function get_original_attempt(): ?\stdClass {
|
|
|
62 |
return $this->originalattempt;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Get the updated attempt, null if it has just been deleted.
|
|
|
67 |
*
|
|
|
68 |
* @return ?\stdClass
|
|
|
69 |
*/
|
|
|
70 |
public function get_updated_attempt(): ?\stdClass {
|
|
|
71 |
return $this->updatedattempt;
|
|
|
72 |
}
|
|
|
73 |
}
|