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
|
|
|
* Library calls for Moodle and BigBlueButton. |
19
|
|
|
* |
20
|
|
|
* @package mod_bigbluebuttonbn |
21
|
|
|
* @copyright 2010-2017 Blindside Networks Inc |
22
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later |
23
|
|
|
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com) |
24
|
|
|
* @author Fred Dixon (ffdixon [at] blindsidenetworks [dt] com) |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
defined('MOODLE_INTERNAL') || die; |
28
|
|
|
|
29
|
|
|
global $CFG; |
30
|
|
|
|
31
|
|
|
require_once($CFG->dirroot.'/calendar/lib.php'); |
32
|
|
|
require_once($CFG->dirroot.'/message/lib.php'); |
33
|
|
|
require_once($CFG->dirroot.'/mod/lti/OAuth.php'); |
34
|
|
|
require_once($CFG->dirroot.'/tag/lib.php'); |
35
|
|
|
require_once($CFG->libdir.'/accesslib.php'); |
36
|
|
|
require_once($CFG->libdir.'/completionlib.php'); |
37
|
|
|
require_once($CFG->libdir.'/datalib.php'); |
38
|
|
|
require_once($CFG->libdir.'/coursecatlib.php'); |
39
|
|
|
require_once($CFG->libdir.'/enrollib.php'); |
40
|
|
|
require_once($CFG->libdir.'/filelib.php'); |
41
|
|
|
require_once($CFG->libdir.'/formslib.php'); |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
if (file_exists(dirname(__FILE__).'/vendor/firebase/php-jwt/src/JWT.php')) { |
45
|
|
|
require_once(dirname(__FILE__).'/vendor/firebase/php-jwt/src/JWT.php'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if (!isset($CFG->bigbluebuttonbn)) { |
49
|
|
|
$CFG->bigbluebuttonbn = array(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if (file_exists(dirname(__FILE__).'/config.php')) { |
53
|
|
|
require_once(dirname(__FILE__).'/config.php'); |
54
|
|
|
// Old BigBlueButtonBN cfg schema. For backward compatibility. |
55
|
|
|
global $BIGBLUEBUTTONBN_CFG; |
56
|
|
|
if (isset($BIGBLUEBUTTONBN_CFG)) { |
57
|
|
|
foreach ((array) $BIGBLUEBUTTONBN_CFG as $key => $value) { |
58
|
|
|
$cfgkey = str_replace("bigbluebuttonbn_", "", $key); |
59
|
|
|
$CFG->bigbluebuttonbn[$cfgkey] = $value; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/* |
65
|
|
|
* DURATIONCOMPENSATION: Feature removed by configuration |
66
|
|
|
*/ |
67
|
|
|
$CFG->bigbluebuttonbn['scheduled_duration_enabled'] = 0; |
68
|
|
|
/* |
69
|
|
|
* Remove this block when restored |
70
|
|
|
*/ |
71
|
|
|
|
72
|
|
|
/** @var BIGBLUEBUTTONBN_DEFAULT_SERVER_URL string of default bigbluebutton server url */ |
73
|
|
|
const BIGBLUEBUTTONBN_DEFAULT_SERVER_URL = 'http://test-install.blindsidenetworks.com/bigbluebutton/'; |
74
|
|
|
/** @var BIGBLUEBUTTONBN_DEFAULT_SHARED_SECRET string of default bigbluebutton server shared secret */ |
75
|
|
|
const BIGBLUEBUTTONBN_DEFAULT_SHARED_SECRET = '8cd8ef52e8e101574e400365b55e11a6'; |
76
|
|
|
/** @var BIGBLUEBUTTONBN_LOG_EVENT_CREATE string of event create for bigbluebuttonbn_logs */ |
77
|
|
|
const BIGBLUEBUTTONBN_LOG_EVENT_CREATE = 'Create'; |
78
|
|
|
/** @var BIGBLUEBUTTONBN_LOG_EVENT_JOIN string of event join for bigbluebuttonbn_logs */ |
79
|
|
|
const BIGBLUEBUTTONBN_LOG_EVENT_JOIN = 'Join'; |
80
|
|
|
/** @var BIGBLUEBUTTONBN_LOG_EVENT_LOGOUT string of event logout for bigbluebuttonbn_logs */ |
81
|
|
|
const BIGBLUEBUTTONBN_LOG_EVENT_LOGOUT = 'Logout'; |
82
|
|
|
/** @var BIGBLUEBUTTONBN_LOG_EVENT_IMPORT string of event import for bigbluebuttonbn_logs */ |
83
|
|
|
const BIGBLUEBUTTONBN_LOG_EVENT_IMPORT = 'Import'; |
84
|
|
|
/** @var BIGBLUEBUTTONBN_LOG_EVENT_DELETE string of event delete for bigbluebuttonbn_logs */ |
85
|
|
|
const BIGBLUEBUTTONBN_LOG_EVENT_DELETE = 'Delete'; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Indicates API features that the forum supports. |
89
|
|
|
* |
90
|
|
|
* @uses FEATURE_IDNUMBER |
91
|
|
|
* @uses FEATURE_GROUPS |
92
|
|
|
* @uses FEATURE_GROUPINGS |
93
|
|
|
* @uses FEATURE_GROUPMEMBERSONLY |
94
|
|
|
* @uses FEATURE_MOD_INTRO |
95
|
|
|
* @uses FEATURE_BACKUP_MOODLE2 |
96
|
|
|
* @uses FEATURE_COMPLETION_TRACKS_VIEWS |
97
|
|
|
* @uses FEATURE_GRADE_HAS_GRADE |
98
|
|
|
* @uses FEATURE_GRADE_OUTCOMES |
99
|
|
|
* @uses FEATURE_SHOW_DESCRIPTION |
100
|
|
|
* @param string $feature |
101
|
|
|
* @return mixed True if yes (some features may use other values) |
102
|
|
|
*/ |
103
|
|
|
function bigbluebuttonbn_supports($feature) { |
104
|
|
|
if (!$feature) { |
105
|
|
|
return null; |
106
|
|
|
} |
107
|
|
|
$features = array( |
108
|
|
|
(string) FEATURE_IDNUMBER => true, |
109
|
|
|
(string) FEATURE_GROUPS => true, |
110
|
|
|
(string) FEATURE_GROUPINGS => true, |
111
|
|
|
(string) FEATURE_GROUPMEMBERSONLY => true, |
112
|
|
|
(string) FEATURE_MOD_INTRO => true, |
113
|
|
|
(string) FEATURE_BACKUP_MOODLE2 => true, |
114
|
|
|
(string) FEATURE_COMPLETION_TRACKS_VIEWS => true, |
115
|
|
|
(string) FEATURE_GRADE_HAS_GRADE => false, |
116
|
|
|
(string) FEATURE_GRADE_OUTCOMES => false, |
117
|
|
|
(string) FEATURE_SHOW_DESCRIPTION => true, |
118
|
|
|
); |
119
|
|
|
if (isset($features[(string) $feature])) { |
120
|
|
|
return $features[$feature]; |
121
|
|
|
} |
122
|
|
|
return null; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Given an object containing all the necessary data, |
127
|
|
|
* (defined by the form in mod_form.php) this function |
128
|
|
|
* will create a new instance and return the id number |
129
|
|
|
* of the new instance. |
130
|
|
|
* |
131
|
|
|
* @param object $data An object from the form in mod_form.php |
132
|
|
|
* @return int The id of the newly inserted bigbluebuttonbn record |
133
|
|
|
*/ |
134
|
|
|
function bigbluebuttonbn_add_instance($data) { |
135
|
|
|
global $DB; |
136
|
|
|
// Excecute preprocess. |
137
|
|
|
bigbluebuttonbn_process_pre_save($data); |
138
|
|
|
// Pre-set initial values. |
139
|
|
|
$data->presentation = bigbluebuttonbn_get_media_file($data); |
140
|
|
|
// Insert a record. |
141
|
|
|
$data->id = $DB->insert_record('bigbluebuttonbn', $data); |
142
|
|
|
// Encode meetingid. |
143
|
|
|
$meetingid = bigbluebuttonbn_encode_meetingid($data->id); |
144
|
|
|
// Set the meetingid column in the bigbluebuttonbn table. |
145
|
|
|
$DB->set_field('bigbluebuttonbn', 'meetingid', $meetingid, array('id' => $data->id)); |
146
|
|
|
// Complete the process. |
147
|
|
|
bigbluebuttonbn_process_post_save($data); |
148
|
|
|
return $data->id; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Given an object containing all the necessary data, |
153
|
|
|
* (defined by the form in mod_form.php) this function |
154
|
|
|
* will update an existing instance with new data. |
155
|
|
|
* |
156
|
|
|
* @param object $data An object from the form in mod_form.php |
157
|
|
|
* @return bool Success/Fail |
158
|
|
|
*/ |
159
|
|
|
function bigbluebuttonbn_update_instance($data) { |
160
|
|
|
global $DB; |
161
|
|
|
// Excecute preprocess. |
162
|
|
|
bigbluebuttonbn_process_pre_save($data); |
163
|
|
|
// Pre-set initial values. |
164
|
|
|
$data->id = $data->instance; |
165
|
|
|
$data->presentation = bigbluebuttonbn_get_media_file($data); |
166
|
|
|
// Update a record. |
167
|
|
|
$DB->update_record('bigbluebuttonbn', $data); |
168
|
|
|
// Complete the process. |
169
|
|
|
bigbluebuttonbn_process_post_save($data); |
170
|
|
|
return true; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Given an ID of an instance of this module, |
175
|
|
|
* this function will permanently delete the instance |
176
|
|
|
* and any data that depends on it. |
177
|
|
|
* |
178
|
|
|
* @param int $id Id of the module instance |
179
|
|
|
* |
180
|
|
|
* @return bool Success/Failure |
181
|
|
|
*/ |
182
|
|
|
function bigbluebuttonbn_delete_instance($id) { |
183
|
|
|
global $DB; |
184
|
|
|
$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $id)); |
185
|
|
|
if (!$bigbluebuttonbn) { |
186
|
|
|
return false; |
187
|
|
|
} |
188
|
|
|
// TODO: End the meeting if it is running. |
189
|
|
|
|
190
|
|
|
// Perform delete. |
191
|
|
|
if (!$DB->delete_records('bigbluebuttonbn', array('id' => $bigbluebuttonbn->id))) { |
192
|
|
|
return false; |
193
|
|
|
} |
194
|
|
|
if (!$DB->delete_records('event', array('modulename' => 'bigbluebuttonbn', 'instance' => $bigbluebuttonbn->id))) { |
195
|
|
|
return false; |
196
|
|
|
} |
197
|
|
|
// Log action performed. |
198
|
|
|
return bigbluebuttonbn_delete_instance_log($bigbluebuttonbn); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Given an ID of an instance of this module, |
203
|
|
|
* this function will permanently delete the data that depends on it. |
204
|
|
|
* |
205
|
|
|
* @param object $bigbluebuttonbn Id of the module instance |
206
|
|
|
* |
207
|
|
|
* @return bool Success/Failure |
208
|
|
|
*/ |
209
|
|
|
function bigbluebuttonbn_delete_instance_log($bigbluebuttonbn) { |
210
|
|
|
global $DB, $USER; |
211
|
|
|
$log = new stdClass(); |
212
|
|
|
$log->meetingid = $bigbluebuttonbn->meetingid; |
213
|
|
|
$log->courseid = $bigbluebuttonbn->course; |
214
|
|
|
$log->bigbluebuttonbnid = $bigbluebuttonbn->id; |
215
|
|
|
$log->userid = $USER->id; |
216
|
|
|
$log->timecreated = time(); |
217
|
|
|
$log->log = BIGBLUEBUTTONBN_LOG_EVENT_DELETE; |
218
|
|
|
$sql = "SELECT * FROM {bigbluebuttonbn_logs} "; |
219
|
|
|
$sql .= "WHERE bigbluebuttonbnid = ? AND log = ? AND ". $DB->sql_compare_text('meta') . " = ?"; |
220
|
|
|
$logs = $DB->get_records_sql($sql, array($bigbluebuttonbn->id, BIGBLUEBUTTONBN_LOG_EVENT_CREATE, "{\"record\":true}")); |
221
|
|
|
$log->meta = "{\"has_recordings\":false}"; |
222
|
|
|
if (!empty($logs)) { |
223
|
|
|
$log->meta = "{\"has_recordings\":true}"; |
224
|
|
|
} |
225
|
|
|
if (!$DB->insert_record('bigbluebuttonbn_logs', $log)) { |
226
|
|
|
return false; |
227
|
|
|
} |
228
|
|
|
return true; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Return a small object with summary information about what a |
233
|
|
|
* user has done with a given particular instance of this module |
234
|
|
|
* Used for user activity reports. |
235
|
|
|
* $return->time = the time they did it |
236
|
|
|
* $return->info = a short text description. |
237
|
|
|
* |
238
|
|
|
* @param object $course |
239
|
|
|
* @param object $user |
240
|
|
|
* @param object $mod |
241
|
|
|
* @param object $bigbluebuttonbn |
242
|
|
|
* |
243
|
|
|
* @return bool |
244
|
|
|
*/ |
245
|
|
|
function bigbluebuttonbn_user_outline($course, $user, $mod, $bigbluebuttonbn) { |
|
|
|
|
246
|
|
|
global $DB; |
247
|
|
|
$completed = $DB->count_records('bigbluebuttonbn_logs', array('courseid' => $course->id, |
248
|
|
|
'bigbluebuttonbnid' => $bigbluebuttonbn->id, 'userid' => $user->id, 'log' => 'Join', ), '*'); |
249
|
|
|
if ($completed > 0) { |
250
|
|
|
return fullname($user).' '.get_string('view_message_has_joined', 'bigbluebuttonbn').' '. |
251
|
|
|
get_string('view_message_session_for', 'bigbluebuttonbn').' '.(string) $completed.' '. |
252
|
|
|
get_string('view_message_times', 'bigbluebuttonbn'); |
253
|
|
|
} |
254
|
|
|
return ''; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Print a detailed representation of what a user has done with |
259
|
|
|
* a given particular instance of this module, for user activity reports. |
260
|
|
|
* |
261
|
|
|
* @param object $course |
262
|
|
|
* @param object $user |
263
|
|
|
* @param object $mod |
264
|
|
|
* @param object $bigbluebuttonbn |
265
|
|
|
* |
266
|
|
|
* @return bool |
267
|
|
|
*/ |
268
|
|
|
function bigbluebuttonbn_user_complete($course, $user, $mod, $bigbluebuttonbn) { |
|
|
|
|
269
|
|
|
global $DB; |
270
|
|
|
$completed = $DB->count_records('bigbluebuttonbn_logs', array('courseid' => $course->id, |
271
|
|
|
'bigbluebuttonbnid' => $bigbluebuttonbn->id, 'userid' => $user->id, 'log' => 'Join', ), |
272
|
|
|
'*', IGNORE_MULTIPLE); |
273
|
|
|
return $completed > 0; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Returns all other caps used in module. |
278
|
|
|
* |
279
|
|
|
* @return string[] |
280
|
|
|
*/ |
281
|
|
|
function bigbluebuttonbn_get_extra_capabilities() { |
282
|
|
|
return array('moodle/site:accessallgroups'); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* List of view style log actions. |
287
|
|
|
* |
288
|
|
|
* @return string[] |
289
|
|
|
*/ |
290
|
|
|
function bigbluebuttonbn_get_view_actions() { |
291
|
|
|
return array('view', 'view all'); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* List of update style log actions. |
296
|
|
|
* |
297
|
|
|
* @return string[] |
298
|
|
|
*/ |
299
|
|
|
function bigbluebuttonbn_get_post_actions() { |
300
|
|
|
return array('update', 'add', 'create', 'join', 'end', 'left', 'publish', 'unpublish', 'delete'); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* Print an overview of all bigbluebuttonbn instances for the courses. |
305
|
|
|
* |
306
|
|
|
* @param array $courses |
307
|
|
|
* @param array $htmlarray Passed by reference |
308
|
|
|
* |
309
|
|
|
* @return void |
310
|
|
|
*/ |
311
|
|
|
function bigbluebuttonbn_print_overview($courses, &$htmlarray) { |
312
|
|
|
if (empty($courses) || !is_array($courses)) { |
313
|
|
|
return array(); |
314
|
|
|
} |
315
|
|
|
$bns = get_all_instances_in_courses('bigbluebuttonbn', $courses); |
316
|
|
|
foreach ($bns as $bn) { |
317
|
|
|
$now = time(); |
318
|
|
|
if ($bn->openingtime and (!$bn->closingtime or $bn->closingtime > $now)) { |
319
|
|
|
// A bigbluebuttonbn is scheduled. |
320
|
|
|
if (empty($htmlarray[$bn->course]['bigbluebuttonbn'])) { |
321
|
|
|
$htmlarray[$bn->course]['bigbluebuttonbn'] = ''; |
322
|
|
|
} |
323
|
|
|
$htmlarray[$bn->course]['bigbluebuttonbn'] = bigbluebuttonbn_print_overview_element($bn, $now); |
324
|
|
|
} |
325
|
|
|
} |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Print an overview of a bigbluebuttonbn instance. |
330
|
|
|
* |
331
|
|
|
* @param array $bigbluebuttonbn |
332
|
|
|
* @param int $now |
333
|
|
|
* |
334
|
|
|
* @return string |
335
|
|
|
*/ |
336
|
|
|
function bigbluebuttonbn_print_overview_element($bigbluebuttonbn, $now) { |
337
|
|
|
global $CFG; |
338
|
|
|
$start = 'started_at'; |
339
|
|
|
if ($bigbluebuttonbn->openingtime > $now) { |
340
|
|
|
$start = 'starts_at'; |
341
|
|
|
} |
342
|
|
|
$classes = ''; |
343
|
|
|
if ($bigbluebuttonbn->visible) { |
344
|
|
|
$classes = 'class="dimmed" '; |
345
|
|
|
} |
346
|
|
|
$str = '<div class="bigbluebuttonbn overview">'."\n"; |
347
|
|
|
$str .= ' <div class="name">'.get_string('modulename', 'bigbluebuttonbn').': '."\n"; |
348
|
|
|
$str .= ' <a '.$classes.'href="'.$CFG->wwwroot.'/mod/bigbluebuttonbn/view.php?id='.$bigbluebuttonbn->coursemodule. |
349
|
|
|
'">'.$bigbluebuttonbn->name.'</a>'."\n"; |
350
|
|
|
$str .= ' </div>'."\n"; |
351
|
|
|
$str .= ' <div class="info">'.get_string($start, 'bigbluebuttonbn').': '.userdate($bigbluebuttonbn->openingtime). |
352
|
|
|
'</div>'."\n"; |
353
|
|
|
$str .= ' <div class="info">'.get_string('ends_at', 'bigbluebuttonbn').': '.userdate($bigbluebuttonbn->closingtime) |
354
|
|
|
.'</div>'."\n"; |
355
|
|
|
$str .= '</div>'."\n"; |
356
|
|
|
return $str; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* Given a course_module object, this function returns any |
361
|
|
|
* "extra" information that may be needed when printing |
362
|
|
|
* this activity in a course listing. |
363
|
|
|
* See get_array_of_activities() in course/lib.php. |
364
|
|
|
* |
365
|
|
|
* @param object $coursemodule |
366
|
|
|
* |
367
|
|
|
* @return null|cached_cm_info |
368
|
|
|
*/ |
369
|
|
|
function bigbluebuttonbn_get_coursemodule_info($coursemodule) { |
370
|
|
|
global $DB; |
371
|
|
|
$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $coursemodule->instance), |
372
|
|
|
'id, name, intro, introformat'); |
373
|
|
|
if (!$bigbluebuttonbn) { |
374
|
|
|
return null; |
375
|
|
|
} |
376
|
|
|
$info = new cached_cm_info(); |
377
|
|
|
$info->name = $bigbluebuttonbn->name; |
378
|
|
|
if ($coursemodule->showdescription) { |
379
|
|
|
// Convert intro to html. Do not filter cached version, filters run at display time. |
380
|
|
|
$info->content = format_module_intro('bigbluebuttonbn', $bigbluebuttonbn, $coursemodule->id, false); |
381
|
|
|
} |
382
|
|
|
return $info; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* Runs any processes that must run before a bigbluebuttonbn insert/update. |
387
|
|
|
* |
388
|
|
|
* @param object $bigbluebuttonbn BigBlueButtonBN form data |
389
|
|
|
* |
390
|
|
|
* @return void |
391
|
|
|
**/ |
392
|
|
|
function bigbluebuttonbn_process_pre_save(&$bigbluebuttonbn) { |
393
|
|
|
bigbluebuttonbn_process_pre_save_instance($bigbluebuttonbn); |
394
|
|
|
bigbluebuttonbn_process_pre_save_checkboxes($bigbluebuttonbn); |
395
|
|
|
bigbluebuttonbn_process_pre_save_common($bigbluebuttonbn); |
396
|
|
|
$bigbluebuttonbn->participants = htmlspecialchars_decode($bigbluebuttonbn->participants); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* Runs process for defining the instance (insert/update). |
401
|
|
|
* |
402
|
|
|
* @param object $bigbluebuttonbn BigBlueButtonBN form data |
403
|
|
|
* |
404
|
|
|
* @return void |
405
|
|
|
**/ |
406
|
|
|
function bigbluebuttonbn_process_pre_save_instance(&$bigbluebuttonbn) { |
407
|
|
|
$bigbluebuttonbn->timemodified = time(); |
408
|
|
|
if ((integer)$bigbluebuttonbn->instance == 0) { |
409
|
|
|
$bigbluebuttonbn->timecreated = time(); |
410
|
|
|
$bigbluebuttonbn->timemodified = 0; |
411
|
|
|
// As it is a new activity, assign passwords. |
412
|
|
|
$bigbluebuttonbn->moderatorpass = bigbluebuttonbn_random_password(12); |
413
|
|
|
$bigbluebuttonbn->viewerpass = bigbluebuttonbn_random_password(12, $bigbluebuttonbn->moderatorpass); |
414
|
|
|
} |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Runs process for assigning default value to checkboxes. |
419
|
|
|
* |
420
|
|
|
* @param object $bigbluebuttonbn BigBlueButtonBN form data |
421
|
|
|
* |
422
|
|
|
* @return void |
423
|
|
|
**/ |
424
|
|
|
function bigbluebuttonbn_process_pre_save_checkboxes(&$bigbluebuttonbn) { |
425
|
|
|
if (!isset($bigbluebuttonbn->wait)) { |
426
|
|
|
$bigbluebuttonbn->wait = 0; |
427
|
|
|
} |
428
|
|
|
if (!isset($bigbluebuttonbn->record)) { |
429
|
|
|
$bigbluebuttonbn->record = 0; |
430
|
|
|
} |
431
|
|
|
if (!isset($bigbluebuttonbn->recordings_html)) { |
432
|
|
|
$bigbluebuttonbn->recordings_html = 0; |
433
|
|
|
} |
434
|
|
|
if (!isset($bigbluebuttonbn->recordings_deleted)) { |
435
|
|
|
$bigbluebuttonbn->recordings_deleted = 0; |
436
|
|
|
} |
437
|
|
|
if (!isset($bigbluebuttonbn->recordings_imported)) { |
438
|
|
|
$bigbluebuttonbn->recordings_imported = 0; |
439
|
|
|
} |
440
|
|
|
if (!isset($bigbluebuttonbn->recordings_preview)) { |
441
|
|
|
$bigbluebuttonbn->recordings_preview = 0; |
442
|
|
|
} |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* Runs process for wipping common settings when 'recordings only'. |
447
|
|
|
* |
448
|
|
|
* @param object $bigbluebuttonbn BigBlueButtonBN form data |
449
|
|
|
* |
450
|
|
|
* @return void |
451
|
|
|
**/ |
452
|
|
|
function bigbluebuttonbn_process_pre_save_common(&$bigbluebuttonbn) { |
453
|
|
|
// Make sure common settings are removed when 'recordings only'. |
454
|
|
|
if ($bigbluebuttonbn->type == BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY) { |
455
|
|
|
$bigbluebuttonbn->groupmode = 0; |
456
|
|
|
$bigbluebuttonbn->groupingid = 0; |
457
|
|
|
} |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
/** |
461
|
|
|
* Runs any processes that must be run after a bigbluebuttonbn insert/update. |
462
|
|
|
* |
463
|
|
|
* @param object $bigbluebuttonbn BigBlueButtonBN form data |
464
|
|
|
* |
465
|
|
|
* @return void |
466
|
|
|
**/ |
467
|
|
|
function bigbluebuttonbn_process_post_save(&$bigbluebuttonbn) { |
468
|
|
|
if (isset($bigbluebuttonbn->notification) && $bigbluebuttonbn->notification) { |
469
|
|
|
bigbluebuttonbn_process_post_save_notification($bigbluebuttonbn); |
470
|
|
|
} |
471
|
|
|
bigbluebuttonbn_process_post_save_event($bigbluebuttonbn); |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
/** |
475
|
|
|
* Generates a message on insert/update which is sent to all users enrolled. |
476
|
|
|
* |
477
|
|
|
* @param object $bigbluebuttonbn BigBlueButtonBN form data |
478
|
|
|
* |
479
|
|
|
* @return void |
480
|
|
|
**/ |
481
|
|
|
function bigbluebuttonbn_process_post_save_notification(&$bigbluebuttonbn) { |
482
|
|
|
$action = get_string('mod_form_field_notification_msg_modified', 'bigbluebuttonbn'); |
483
|
|
|
if (isset($bigbluebuttonbn->add) && !empty($bigbluebuttonbn->add)) { |
484
|
|
|
$action = get_string('mod_form_field_notification_msg_created', 'bigbluebuttonbn'); |
485
|
|
|
} |
486
|
|
|
$context = context_course::instance($bigbluebuttonbn->course); |
487
|
|
|
\mod_bigbluebuttonbn\locallib\notifier::notification_process($context, $bigbluebuttonbn, $action); |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* Generates an event after a bigbluebuttonbn insert/update. |
492
|
|
|
* |
493
|
|
|
* @param object $bigbluebuttonbn BigBlueButtonBN form data |
494
|
|
|
* |
495
|
|
|
* @return void |
496
|
|
|
**/ |
497
|
|
|
function bigbluebuttonbn_process_post_save_event(&$bigbluebuttonbn) { |
498
|
|
|
global $DB; |
499
|
|
|
$eventid = $DB->get_field('event', 'id', array('modulename' => 'bigbluebuttonbn', |
500
|
|
|
'instance' => $bigbluebuttonbn->id)); |
501
|
|
|
// Delete the event from calendar when/if openingtime is NOT set. |
502
|
|
|
if (!isset($bigbluebuttonbn->openingtime) || !$bigbluebuttonbn->openingtime) { |
503
|
|
|
if ($eventid) { |
504
|
|
|
$calendarevent = calendar_event::load($eventid); |
505
|
|
|
$calendarevent->delete(); |
506
|
|
|
} |
507
|
|
|
return; |
508
|
|
|
} |
509
|
|
|
// Add evento to the calendar as openingtime is set. |
510
|
|
|
$event = new stdClass(); |
511
|
|
|
$event->eventtype = BIGBLUEBUTTON_EVENT_MEETING_START; |
512
|
|
|
$event->type = CALENDAR_EVENT_TYPE_ACTION; |
513
|
|
|
$event->name = $bigbluebuttonbn->name . ' (' . get_string('starts_at', 'bigbluebuttonbn') . ')'; |
514
|
|
|
$event->description = format_module_intro('bigbluebuttonbn', $bigbluebuttonbn, $bigbluebuttonbn->coursemodule); |
515
|
|
|
$event->courseid = $bigbluebuttonbn->course; |
516
|
|
|
$event->groupid = 0; |
517
|
|
|
$event->userid = 0; |
518
|
|
|
$event->modulename = 'bigbluebuttonbn'; |
519
|
|
|
$event->instance = $bigbluebuttonbn->id; |
520
|
|
|
$event->timestart = $bigbluebuttonbn->openingtime; |
521
|
|
|
$event->timeduration = 0; |
522
|
|
|
if ($bigbluebuttonbn->closingtime) { |
523
|
|
|
$event->timeduration = $bigbluebuttonbn->closingtime - $bigbluebuttonbn->openingtime; |
524
|
|
|
} |
525
|
|
|
$event->timesort = $event->timestart + $event->timeduration; |
526
|
|
|
$event->visible = instance_is_visible('bigbluebuttonbn', $bigbluebuttonbn); |
527
|
|
|
$event->priority = null; |
528
|
|
|
// Update the event in calendar when/if eventid was found. |
529
|
|
|
if ($eventid) { |
530
|
|
|
$event->id = $eventid; |
531
|
|
|
$calendarevent = calendar_event::load($eventid); |
532
|
|
|
$calendarevent->update($event); |
533
|
|
|
return; |
534
|
|
|
} |
535
|
|
|
calendar_event::create($event); |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
/** |
539
|
|
|
* Get a full path to the file attached as a preuploaded presentation |
540
|
|
|
* or if there is none, set the presentation field will be set to blank. |
541
|
|
|
* |
542
|
|
|
* @param object $bigbluebuttonbn BigBlueButtonBN form data |
543
|
|
|
* |
544
|
|
|
* @return string |
545
|
|
|
*/ |
546
|
|
|
function bigbluebuttonbn_get_media_file(&$bigbluebuttonbn) { |
547
|
|
|
if (!isset($bigbluebuttonbn->presentation) || $bigbluebuttonbn->presentation == '') { |
548
|
|
|
return ''; |
549
|
|
|
} |
550
|
|
|
$context = context_module::instance($bigbluebuttonbn->coursemodule); |
551
|
|
|
// Set the filestorage object. |
552
|
|
|
$fs = get_file_storage(); |
553
|
|
|
// Save the file if it exists that is currently in the draft area. |
554
|
|
|
file_save_draft_area_files($bigbluebuttonbn->presentation, $context->id, 'mod_bigbluebuttonbn', 'presentation', 0); |
555
|
|
|
// Get the file if it exists. |
556
|
|
|
$files = $fs->get_area_files($context->id, 'mod_bigbluebuttonbn', 'presentation', 0, |
557
|
|
|
'itemid, filepath, filename', false); |
558
|
|
|
// Check that there is a file to process. |
559
|
|
|
$filesrc = ''; |
560
|
|
|
if (count($files) == 1) { |
561
|
|
|
// Get the first (and only) file. |
562
|
|
|
$file = reset($files); |
563
|
|
|
$filesrc = '/'.$file->get_filename(); |
564
|
|
|
} |
565
|
|
|
return $filesrc; |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
/** |
569
|
|
|
* Serves the bigbluebuttonbn attachments. Implements needed access control ;-). |
570
|
|
|
* |
571
|
|
|
* @category files |
572
|
|
|
* |
573
|
|
|
* @param stdClass $course course object |
574
|
|
|
* @param stdClass $cm course module object |
575
|
|
|
* @param stdClass $context context object |
576
|
|
|
* @param string $filearea file area |
577
|
|
|
* @param array $args extra arguments |
578
|
|
|
* @param bool $forcedownload whether or not force download |
579
|
|
|
* @param array $options additional options affecting the file serving |
580
|
|
|
* |
581
|
|
|
* @return false|null false if file not found, does not return if found - justsend the file |
582
|
|
|
*/ |
583
|
|
|
function bigbluebuttonbn_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) { |
584
|
|
|
if (!bigbluebuttonbn_pluginfile_valid($context, $filearea)) { |
585
|
|
|
return false; |
586
|
|
|
} |
587
|
|
|
$file = bigbluebuttonbn_pluginfile_file($course, $cm, $context, $filearea, $args); |
588
|
|
|
if (empty($file)) { |
589
|
|
|
return false; |
590
|
|
|
} |
591
|
|
|
// Finally send the file. |
592
|
|
|
send_stored_file($file, 0, 0, $forcedownload, $options); // download MUST be forced - security! |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
/** |
596
|
|
|
* Helper for validating pluginfile. |
597
|
|
|
* @param stdClass $context context object |
598
|
|
|
* @param string $filearea file area |
599
|
|
|
* |
600
|
|
|
* @return false|null false if file not valid |
601
|
|
|
*/ |
602
|
|
|
function bigbluebuttonbn_pluginfile_valid($context, $filearea) { |
603
|
|
|
if ($context->contextlevel != CONTEXT_MODULE) { |
604
|
|
|
return false; |
605
|
|
|
} |
606
|
|
|
if ($filearea !== 'presentation') { |
607
|
|
|
return false; |
608
|
|
|
} |
609
|
|
|
if (!array_key_exists($filearea, bigbluebuttonbn_get_file_areas())) { |
610
|
|
|
return false; |
611
|
|
|
} |
612
|
|
|
return true; |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
/** |
616
|
|
|
* Helper for getting pluginfile. |
617
|
|
|
* |
618
|
|
|
* @param stdClass $course course object |
619
|
|
|
* @param stdClass $cm course module object |
620
|
|
|
* @param stdClass $context context object |
621
|
|
|
* @param string $filearea file area |
622
|
|
|
* @param array $args extra arguments |
623
|
|
|
* |
624
|
|
|
* @return object |
625
|
|
|
*/ |
626
|
|
|
function bigbluebuttonbn_pluginfile_file($course, $cm, $context, $filearea, $args) { |
627
|
|
|
$filename = bigbluebuttonbn_pluginfile_filename($course, $cm, $context, $args); |
628
|
|
|
if (!$filename) { |
|
|
|
|
629
|
|
|
return false; |
630
|
|
|
} |
631
|
|
|
$fullpath = "/$context->id/mod_bigbluebuttonbn/$filearea/0/".$filename; |
632
|
|
|
$fs = get_file_storage(); |
633
|
|
|
$file = $fs->get_file_by_hash(sha1($fullpath)); |
634
|
|
|
if (!$file || $file->is_directory()) { |
635
|
|
|
return false; |
636
|
|
|
} |
637
|
|
|
return $file; |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
/** |
641
|
|
|
* Helper for getting pluginfile name. |
642
|
|
|
* |
643
|
|
|
* @param stdClass $course course object |
644
|
|
|
* @param stdClass $cm course module object |
645
|
|
|
* @param stdClass $context context object |
646
|
|
|
* @param array $args extra arguments |
647
|
|
|
* |
648
|
|
|
* @return array |
649
|
|
|
*/ |
650
|
|
|
function bigbluebuttonbn_pluginfile_filename($course, $cm, $context, $args) { |
651
|
|
|
global $DB; |
652
|
|
|
if (count($args) > 1) { |
653
|
|
|
if (!$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $cm->instance))) { |
654
|
|
|
return; |
655
|
|
|
} |
656
|
|
|
$cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'presentation_cache'); |
657
|
|
|
$noncekey = sha1($bigbluebuttonbn->id); |
658
|
|
|
$presentationnonce = $cache->get($noncekey); |
659
|
|
|
$noncevalue = $presentationnonce['value']; |
660
|
|
|
$noncecounter = $presentationnonce['counter']; |
661
|
|
|
if ($args['0'] != $noncevalue) { |
662
|
|
|
return; |
663
|
|
|
} |
664
|
|
|
// The nonce value is actually used twice because BigBlueButton reads the file two times. |
665
|
|
|
$noncecounter += 1; |
666
|
|
|
$cache->set($noncekey, array('value' => $noncevalue, 'counter' => $noncecounter)); |
667
|
|
|
if ($noncecounter == 2) { |
668
|
|
|
$cache->delete($noncekey); |
669
|
|
|
} |
670
|
|
|
return $args['1']; |
671
|
|
|
} |
672
|
|
|
require_course_login($course, true, $cm); |
673
|
|
|
if (!has_capability('mod/bigbluebuttonbn:join', $context)) { |
674
|
|
|
return; |
675
|
|
|
} |
676
|
|
|
return implode('/', $args); |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
/** |
680
|
|
|
* Returns an array of file areas. |
681
|
|
|
* |
682
|
|
|
* @category files |
683
|
|
|
* |
684
|
|
|
* @return array a list of available file areas |
685
|
|
|
*/ |
686
|
|
|
function bigbluebuttonbn_get_file_areas() { |
687
|
|
|
$areas = array(); |
688
|
|
|
$areas['presentation'] = get_string('mod_form_block_presentation', 'bigbluebuttonbn'); |
689
|
|
|
return $areas; |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
/** |
693
|
|
|
* Get icon mapping for font-awesome. |
694
|
|
|
*/ |
695
|
|
|
function mod_bigbluebuttonbn_get_fontawesome_icon_map() { |
696
|
|
|
return [ |
697
|
|
|
'mod_bigbluebuttonbn:i/bigbluebutton' => 'fa-bigbluebutton', |
698
|
|
|
]; |
699
|
|
|
} |
700
|
|
|
|
701
|
|
|
/** |
702
|
|
|
* This function receives a calendar event and returns the action associated with it, or null if there is none. |
703
|
|
|
* |
704
|
|
|
* This is used by block_myoverview in order to display the event appropriately. If null is returned then the event |
705
|
|
|
* is not displayed on the block. |
706
|
|
|
* |
707
|
|
|
* @param calendar_event $event |
708
|
|
|
* @param \core_calendar\action_factory $factory |
709
|
|
|
* @param int $userid User id to use for all capability checks, etc. Set to 0 for current user (default). |
|
|
|
|
710
|
|
|
* @return \core_calendar\local\event\entities\action_interface|null |
711
|
|
|
*/ |
712
|
|
|
function mod_bigbluebuttonbn_core_calendar_provide_event_action(calendar_event $event, |
713
|
|
|
\core_calendar\action_factory $factory) { |
714
|
|
|
global $CFG, $DB; |
715
|
|
|
|
716
|
|
|
require_once($CFG->dirroot . '/mod/bigbluebuttonbn/locallib.php'); |
717
|
|
|
|
718
|
|
|
$cm = get_fast_modinfo($event->courseid)->instances['bigbluebuttonbn'][$event->instance]; |
719
|
|
|
|
720
|
|
|
// Check that the bigbluebuttonbn activity is open. |
721
|
|
|
$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $event->instance), '*', MUST_EXIST); |
722
|
|
|
$actionable = bigbluebuttonbn_get_availability_status($bigbluebuttonbn); |
723
|
|
|
|
724
|
|
|
$string = get_string('view_room', 'bigbluebuttonbn'); |
725
|
|
|
$url = new \moodle_url('/mod/bigbluebuttonbn/view.php', array('id' => $cm->id)); |
726
|
|
|
if (groups_get_activity_groupmode($cm) == NOGROUPS) { |
727
|
|
|
// No groups mode. |
728
|
|
|
$string = get_string('view_conference_action_join', 'bigbluebuttonbn'); |
729
|
|
|
$url = new \moodle_url('/mod/bigbluebuttonbn/view.php', array('id' => $cm->id)); |
730
|
|
|
} |
731
|
|
|
|
732
|
|
|
return $factory->create_instance($string, $url, 1, $actionable); |
733
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.