-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventslib.php
63 lines (45 loc) · 1.61 KB
/
eventslib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
abstract class grade_notify_handler {
private static function cleanup($params) {
global $DB;
return $DB->delete_records('block_grade_notify_entries', $params);
}
private static function retrieve($params) {
global $DB;
return $DB->get_record('block_grade_notify_entries', $params);
}
private static function always($userid) {
global $DB;
$params = array('userid' => $userid, 'courseid' => 0);
return self::retrieve($params);
}
private static function assignment_to_params($ra) {
$context = context::instance_by_id($ra->contextid, MUST_EXIST);
return array('userid' => $ra->userid, 'courseid' => $context->instanceid);
}
public static function user_deleted($user) {
return self::cleanup(array('userid' => $user->id));
}
public static function course_deleted($course) {
return self::cleanup(array('courseid' => $course->id));
}
public static function role_assigned($ra) {
$params = self::assignment_to_params($ra);
if (self::retrieve($params)) {
return true;
} else if (self::always($ra->userid)) {
global $DB;
$entry = (object)$params;
$DB->insert_record('block_grade_notify_entries', $entry);
}
return true;
}
public static function role_unassigned($ra) {
$params = self::assignment_to_params($ra);
// Only delete is exists (better DB performance)
if (self::retrieve($params)) {
return self::cleanup($params);
}
return true;
}
}