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_bigbluebuttonbn locallib/notifier. |
19
|
|
|
* |
20
|
|
|
* @package mod_bigbluebuttonbn |
21
|
|
|
* @copyright 2017 - present, Blindside Networks Inc |
22
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
23
|
|
|
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com) |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace mod_bigbluebuttonbn\locallib; |
27
|
|
|
|
28
|
|
|
defined('MOODLE_INTERNAL') || die(); |
29
|
|
|
|
30
|
|
|
require_once($CFG->dirroot . '/mod/bigbluebuttonbn/locallib.php'); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Helper class for sending notifications. |
34
|
|
|
* |
35
|
|
|
* @copyright 2010 onwards, Blindside Networks Inc |
36
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
37
|
|
|
*/ |
38
|
|
|
class notifier |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* Prepares html message body for instance updated notification. |
42
|
|
|
* |
43
|
|
|
* @param object $msg |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
|
|
public static function htmlmsg_instance_updated($msg) { |
47
|
|
|
$messagetext = '<p>'.$msg->activity_type.' "'.$msg->activity_title.'" '. |
48
|
|
|
get_string('email_body_notification_meeting_has_been', 'bigbluebuttonbn').' '.$msg->action.'.</p>'."\n"; |
49
|
|
|
$messagetext .= '<p><b>'.$msg->activity_title.'</b> '. |
50
|
|
|
get_string('email_body_notification_meeting_details', 'bigbluebuttonbn').':'."\n"; |
51
|
|
|
$messagetext .= '<table border="0" style="margin: 5px 0 0 20px"><tbody>'."\n"; |
52
|
|
|
$messagetext .= '<tr><td style="font-weight:bold;color:#555;">'. |
53
|
|
|
get_string('email_body_notification_meeting_title', 'bigbluebuttonbn').': </td><td>'."\n"; |
54
|
|
|
$messagetext .= $msg->activity_title.'</td></tr>'."\n"; |
55
|
|
|
$messagetext .= '<tr><td style="font-weight:bold;color:#555;">'. |
56
|
|
|
get_string('email_body_notification_meeting_description', 'bigbluebuttonbn').': </td><td>'."\n"; |
57
|
|
|
$messagetext .= $msg->activity_description.'</td></tr>'."\n"; |
58
|
|
|
$messagetext .= '<tr><td style="font-weight:bold;color:#555;">'. |
59
|
|
|
get_string('email_body_notification_meeting_start_date', 'bigbluebuttonbn').': </td><td>'."\n"; |
60
|
|
|
$messagetext .= $msg->activity_openingtime.'</td></tr>'."\n"; |
61
|
|
|
$messagetext .= '<tr><td style="font-weight:bold;color:#555;">'. |
62
|
|
|
get_string('email_body_notification_meeting_end_date', 'bigbluebuttonbn').': </td><td>'."\n"; |
63
|
|
|
$messagetext .= $msg->activity_closingtime.'</td></tr>'."\n"; |
64
|
|
|
$messagetext .= '<tr><td style="font-weight:bold;color:#555;">'.$msg->action.' '. |
65
|
|
|
get_string('email_body_notification_meeting_by', 'bigbluebuttonbn').': </td><td>'."\n"; |
66
|
|
|
$messagetext .= $msg->activity_owner.'</td></tr></tbody></table></p>'."\n"; |
67
|
|
|
$messagetext .= '<p><hr/><br/>'.get_string('email_footer_sent_by', 'bigbluebuttonbn').' '. |
68
|
|
|
$msg->user_name.'('.$msg->user_email.') '; |
69
|
|
|
$messagetext .= get_string('email_footer_sent_from', 'bigbluebuttonbn').' '.$msg->course_name.'.</p>'; |
70
|
|
|
return $messagetext; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Starts the notification process. |
75
|
|
|
* |
76
|
|
|
* @param object $bigbluebuttonbn |
77
|
|
|
* @param string $action |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
public static function notify_instance_updated($bigbluebuttonbn, $action) { |
81
|
|
|
global $USER; |
82
|
|
|
$coursemodinfo = \course_modinfo::instance($bigbluebuttonbn->course); |
83
|
|
|
$course = $coursemodinfo->get_course($bigbluebuttonbn->course); |
84
|
|
|
$sender = $USER; |
85
|
|
|
// Prepare message. |
86
|
|
|
$msg = (object) array(); |
87
|
|
|
// Build the message_body. |
88
|
|
|
$msg->action = $action; |
89
|
|
|
$msg->activity_type = ''; |
90
|
|
|
$msg->activity_title = $bigbluebuttonbn->name; |
91
|
|
|
// Add the meeting details to the message_body. |
92
|
|
|
$msg->action = ucfirst($action); |
93
|
|
|
$msg->activity_description = ''; |
94
|
|
|
if (!empty($bigbluebuttonbn->intro)) { |
95
|
|
|
$msg->activity_description = trim($bigbluebuttonbn->intro); |
96
|
|
|
} |
97
|
|
|
$msg->activity_openingtime = bigbluebuttonbn_format_activity_time($bigbluebuttonbn->openingtime); |
98
|
|
|
$msg->activity_closingtime = bigbluebuttonbn_format_activity_time($bigbluebuttonbn->closingtime); |
99
|
|
|
$msg->activity_owner = fullname($sender); |
100
|
|
|
|
101
|
|
|
$msg->user_name = fullname($sender); |
102
|
|
|
$msg->user_email = $sender->email; |
103
|
|
|
$msg->course_name = $course->fullname; |
104
|
|
|
|
105
|
|
|
// Send notification to all users enrolled. |
106
|
|
|
self::send_notifications($bigbluebuttonbn, $sender, self::htmlmsg_instance_updated($msg)); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Prepares html message body for recording ready notification. |
111
|
|
|
* |
112
|
|
|
* @param object $bigbluebuttonbn |
113
|
|
|
* |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
|
|
public static function htmlmsg_recording_ready($bigbluebuttonbn) { |
117
|
|
|
return '<p>'.get_string('email_body_recording_ready_for', 'bigbluebuttonbn'). |
118
|
|
|
' "' . $bigbluebuttonbn->name . '" '. |
119
|
|
|
get_string('email_body_recording_ready_is_ready', 'bigbluebuttonbn').'.</p>'; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Helper function triggers a send notification when the recording is ready. |
124
|
|
|
* |
125
|
|
|
* @param object $bigbluebuttonbn |
126
|
|
|
* |
127
|
|
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
public static function notify_recording_ready($bigbluebuttonbn) { |
130
|
|
|
$sender = get_admin(); |
131
|
|
|
$htmlmsg = self::htmlmsg_recording_ready($bigbluebuttonbn); |
132
|
|
|
self::send_notifications($bigbluebuttonbn, $sender, $htmlmsg); |
|
|
|
|
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Enqueue notifications to be sent to all users in a context where the instance belongs. |
137
|
|
|
* |
138
|
|
|
* @param object $bigbluebuttonbn |
139
|
|
|
* @param object $sender |
140
|
|
|
* @param string $htmlmsg |
141
|
|
|
* @return void |
142
|
|
|
*/ |
143
|
|
|
public static function enqueue_notifications($bigbluebuttonbn, $sender, $htmlmsg) { |
144
|
|
|
foreach (self::receivers($bigbluebuttonbn->course) as $receiver) { |
145
|
|
|
if ($sender->id != $receiver->id) { |
146
|
|
|
// Enqueue a task for sending a notification. |
147
|
|
|
try { |
148
|
|
|
// Create the instance of completion_update_state task. |
149
|
|
|
$task = new \mod_bigbluebuttonbn\task\send_notification(); |
150
|
|
|
// Add custom data. |
151
|
|
|
$data = array( |
152
|
|
|
'sender' => $sender, |
153
|
|
|
'receiver' => $receiver, |
154
|
|
|
'htmlmsg' => $htmlmsg |
155
|
|
|
); |
156
|
|
|
$task->set_custom_data($data); |
157
|
|
|
// CONTRIB-7457: Task should be executed by a user, maybe Teacher as Student won't have rights for everriding. |
158
|
|
|
// $ task -> set_userid ( $ user -> id );. |
159
|
|
|
// Queue it. |
160
|
|
|
\core\task\manager::queue_adhoc_task($task); |
161
|
|
|
} catch (Exception $e) { |
|
|
|
|
162
|
|
|
mtrace("Error while enqueuing completion_uopdate_state task. " . (string)$e); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Sends notification to a user. |
170
|
|
|
* |
171
|
|
|
* @param object $sender |
172
|
|
|
* @param object $receiver |
173
|
|
|
* @param object $htmlmsg |
174
|
|
|
* @return void |
175
|
|
|
*/ |
176
|
|
|
public static function send_notification($sender, $receiver, $htmlmsg) { |
177
|
|
|
// Send the message. |
178
|
|
|
message_post_message($sender, $receiver, $htmlmsg, FORMAT_HTML); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Define users to be notified. |
183
|
|
|
* |
184
|
|
|
* @param object $courseid |
185
|
|
|
* @return array |
186
|
|
|
*/ |
187
|
|
|
public static function receivers($courseid) { |
188
|
|
|
$context = \context_course::instance($courseid); |
189
|
|
|
$users = array(); |
|
|
|
|
190
|
|
|
// See if there are any users in the lesson. |
191
|
|
|
list($sort, $params) = users_order_by_sql('u'); |
|
|
|
|
192
|
|
|
$users = get_enrolled_users($context, 'mod/bigbluebuttonbn:view', 0, 'u.*', $sort); |
193
|
|
|
return $users; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.