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 tool_courserating;
|
|
|
18 |
|
|
|
19 |
use core\event\course_created;
|
|
|
20 |
use core\event\course_deleted;
|
|
|
21 |
use core\event\course_updated;
|
|
|
22 |
use tool_courserating\local\models\summary;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Events ovserver
|
|
|
26 |
*
|
|
|
27 |
* @package tool_courserating
|
|
|
28 |
* @copyright 2022 Marina Glancy <marina.glancy@gmail.com>
|
|
|
29 |
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
30 |
*/
|
|
|
31 |
class observer {
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Observer for course_updated event
|
|
|
35 |
*
|
|
|
36 |
* @param course_updated $event
|
|
|
37 |
*/
|
|
|
38 |
public static function course_updated(course_updated $event) {
|
|
|
39 |
if (helper::get_setting(constants::SETTING_PERCOURSE)) {
|
|
|
40 |
$summary = summary::get_for_course($event->courseid);
|
|
|
41 |
if ($summary->get('ratingmode') != helper::get_course_rating_mode($event->courseid)) {
|
|
|
42 |
// Rating mode has changed for this course.
|
|
|
43 |
api::reindex($event->courseid);
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* Observer for course_deleted event
|
|
|
50 |
*
|
|
|
51 |
* @param course_deleted $event
|
|
|
52 |
*/
|
|
|
53 |
public static function course_deleted(course_deleted $event) {
|
|
|
54 |
api::delete_all_data_for_course($event->courseid);
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* Observer for course_created event
|
|
|
59 |
*
|
|
|
60 |
* @param course_created $event
|
|
|
61 |
*/
|
|
|
62 |
public static function course_created(course_created $event) {
|
|
|
63 |
api::reindex($event->courseid);
|
|
|
64 |
}
|
|
|
65 |
}
|