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_forum\event;
|
|
|
18 |
|
|
|
19 |
use coding_exception;
|
|
|
20 |
use moodle_url;
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* The mod_forum subscription mode updated event.
|
|
|
24 |
*
|
|
|
25 |
* @package mod_forum
|
|
|
26 |
* @copyright 2022 Université Rennes 2 {@link https://www.univ-rennes2.fr}
|
|
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
28 |
*/
|
|
|
29 |
class subscription_mode_updated extends \core\event\base {
|
|
|
30 |
/**
|
|
|
31 |
* Init method.
|
|
|
32 |
*
|
|
|
33 |
* @return void
|
|
|
34 |
*/
|
|
|
35 |
protected function init(): void {
|
|
|
36 |
$this->data['crud'] = 'u';
|
|
|
37 |
$this->data['edulevel'] = self::LEVEL_OTHER;
|
|
|
38 |
$this->data['objecttable'] = 'forum';
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Returns description of what happened.
|
|
|
43 |
*
|
|
|
44 |
* @return string
|
|
|
45 |
*/
|
|
|
46 |
public function get_description(): string {
|
|
|
47 |
return "The user with id '$this->userid' has updated the forum subscription
|
|
|
48 |
from mode '{$this->other['oldvalue']}' to mode '{$this->other['newvalue']}' in the forum id '$this->objectid'";
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Return localised event name.
|
|
|
53 |
*
|
|
|
54 |
* @return string
|
|
|
55 |
*/
|
|
|
56 |
public static function get_name(): string {
|
|
|
57 |
return get_string('eventforumsubscriptionupdated', 'mod_forum');
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Get URL related to the action
|
|
|
62 |
*
|
|
|
63 |
* @return moodle_url
|
|
|
64 |
*/
|
|
|
65 |
public function get_url(): moodle_url {
|
|
|
66 |
return new moodle_url('/mod/forum/subscribers.php', ['id' => $this->objectid]);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Custom validation.
|
|
|
71 |
*
|
|
|
72 |
* @throws coding_exception
|
|
|
73 |
* @return void
|
|
|
74 |
*/
|
|
|
75 |
protected function validate_data(): void {
|
|
|
76 |
parent::validate_data();
|
|
|
77 |
if (!isset($this->other['oldvalue'])) {
|
|
|
78 |
throw new coding_exception('oldvalue must be set in $other.');
|
|
|
79 |
}
|
|
|
80 |
if (!isset($this->other['newvalue'])) {
|
|
|
81 |
throw new coding_exception('newvalue must be set in $other.');
|
|
|
82 |
}
|
|
|
83 |
if ($this->contextlevel != CONTEXT_MODULE) {
|
|
|
84 |
throw new coding_exception('Context passed must be module context.');
|
|
|
85 |
}
|
|
|
86 |
if (!isset($this->objectid)) {
|
|
|
87 |
throw new coding_exception('objectid must be set to the forumid.');
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Forum object id mappings.
|
|
|
93 |
*
|
|
|
94 |
* @return array
|
|
|
95 |
*/
|
|
|
96 |
public static function get_objectid_mapping(): array {
|
|
|
97 |
return ['db' => 'forum', 'restore' => 'forum'];
|
|
|
98 |
}
|
|
|
99 |
}
|