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
|
|
|
* Internal library of functions for module BigBlueButtonBN. |
19
|
|
|
* |
20
|
|
|
* @package mod_bigbluebuttonbn |
21
|
|
|
* @copyright 2010 onwards, 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
|
|
|
* @author Fred Dixon (ffdixon [at] blindsidenetworks [dt] com) |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
use mod_bigbluebuttonbn\locallib; |
28
|
|
|
use mod_bigbluebuttonbn\plugin; |
29
|
|
|
use mod_bigbluebuttonbn\task; |
30
|
|
|
|
31
|
|
|
defined('MOODLE_INTERNAL') || die; |
32
|
|
|
|
33
|
|
|
global $CFG; |
34
|
|
|
|
35
|
|
|
require_once(__DIR__ . '/lib.php'); |
36
|
|
|
|
37
|
|
|
/** @var BIGBLUEBUTTONBN_UPDATE_CACHE boolean set to true indicates that cache has to be updated */ |
38
|
|
|
const BIGBLUEBUTTONBN_UPDATE_CACHE = true; |
39
|
|
|
/** @var BIGBLUEBUTTONBN_TYPE_ALL integer set to 0 defines an instance type that inclueds room and recordings */ |
40
|
|
|
const BIGBLUEBUTTONBN_TYPE_ALL = 0; |
41
|
|
|
/** @var BIGBLUEBUTTONBN_TYPE_ROOM_ONLY integer set to 1 defines an instance type that inclueds only room */ |
42
|
|
|
const BIGBLUEBUTTONBN_TYPE_ROOM_ONLY = 1; |
43
|
|
|
/** @var BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY integer set to 2 defines an instance type that inclueds only recordings */ |
44
|
|
|
const BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY = 2; |
45
|
|
|
/** @var BIGBLUEBUTTONBN_ROLE_VIEWER string defines the bigbluebutton viewer role */ |
46
|
|
|
const BIGBLUEBUTTONBN_ROLE_VIEWER = 'viewer'; |
47
|
|
|
/** @var BIGBLUEBUTTONBN_ROLE_MODERATOR string defines the bigbluebutton moderator role */ |
48
|
|
|
const BIGBLUEBUTTONBN_ROLE_MODERATOR = 'moderator'; |
49
|
|
|
/** @var BIGBLUEBUTTON_EVENT_ACTIVITY_VIEWED string defines the bigbluebuttonbn activity_viewed event */ |
50
|
|
|
const BIGBLUEBUTTON_EVENT_ACTIVITY_VIEWED = 'activity_viewed'; |
51
|
|
|
/** @var BIGBLUEBUTTON_EVENT_ACTIVITY_MANAGEMENT_VIEWED string defines the bigbluebuttonbn activity_management_viewed event */ |
52
|
|
|
const BIGBLUEBUTTON_EVENT_ACTIVITY_MANAGEMENT_VIEWED = 'activity_management_viewed'; |
53
|
|
|
/** @var BIGBLUEBUTTON_EVENT_LIVE_SESSION string defines the bigbluebuttonbn live_session event */ |
54
|
|
|
const BIGBLUEBUTTON_EVENT_LIVE_SESSION = 'live_session'; |
55
|
|
|
/** @var BIGBLUEBUTTON_EVENT_MEETING_CREATED string defines the bigbluebuttonbn meeting_created event */ |
56
|
|
|
const BIGBLUEBUTTON_EVENT_MEETING_CREATED = 'meeting_created'; |
57
|
|
|
/** @var BIGBLUEBUTTON_EVENT_MEETING_ENDED string defines the bigbluebuttonbn meeting_ended event */ |
58
|
|
|
const BIGBLUEBUTTON_EVENT_MEETING_ENDED = 'meeting_ended'; |
59
|
|
|
/** @var BIGBLUEBUTTON_EVENT_MEETING_JOINED string defines the bigbluebuttonbn meeting_joined event */ |
60
|
|
|
const BIGBLUEBUTTON_EVENT_MEETING_JOINED = 'meeting_joined'; |
61
|
|
|
/** @var BIGBLUEBUTTON_EVENT_MEETING_LEFT string defines the bigbluebuttonbn meeting_left event */ |
62
|
|
|
const BIGBLUEBUTTON_EVENT_MEETING_LEFT = 'meeting_left'; |
63
|
|
|
/** @var BIGBLUEBUTTON_EVENT_RECORDING_DELETED string defines the bigbluebuttonbn recording_deleted event */ |
64
|
|
|
const BIGBLUEBUTTON_EVENT_RECORDING_DELETED = 'recording_deleted'; |
65
|
|
|
/** @var BIGBLUEBUTTON_EVENT_RECORDING_IMPORTED string defines the bigbluebuttonbn recording_imported event */ |
66
|
|
|
const BIGBLUEBUTTON_EVENT_RECORDING_IMPORTED = 'recording_imported'; |
67
|
|
|
/** @var BIGBLUEBUTTON_EVENT_RECORDING_PROTECTED string defines the bigbluebuttonbn recording_protected event */ |
68
|
|
|
const BIGBLUEBUTTON_EVENT_RECORDING_PROTECTED = 'recording_protected'; |
69
|
|
|
/** @var BIGBLUEBUTTON_EVENT_RECORDING_PUBLISHED string defines the bigbluebuttonbn recording_published event */ |
70
|
|
|
const BIGBLUEBUTTON_EVENT_RECORDING_PUBLISHED = 'recording_published'; |
71
|
|
|
/** @var BIGBLUEBUTTON_EVENT_RECORDING_UNPROTECTED string defines the bigbluebuttonbn recording_unprotected event */ |
72
|
|
|
const BIGBLUEBUTTON_EVENT_RECORDING_UNPROTECTED = 'recording_unprotected'; |
73
|
|
|
/** @var BIGBLUEBUTTON_EVENT_RECORDING_UNPUBLISHED string defines the bigbluebuttonbn recording_unpublished event */ |
74
|
|
|
const BIGBLUEBUTTON_EVENT_RECORDING_UNPUBLISHED = 'recording_unpublished'; |
75
|
|
|
/** @var BIGBLUEBUTTON_EVENT_RECORDING_EDITED string defines the bigbluebuttonbn recording_edited event */ |
76
|
|
|
const BIGBLUEBUTTON_EVENT_RECORDING_EDITED = 'recording_edited'; |
77
|
|
|
/** @var BIGBLUEBUTTON_EVENT_RECORDING_VIEWED string defines the bigbluebuttonbn recording_viewed event */ |
78
|
|
|
const BIGBLUEBUTTON_EVENT_RECORDING_VIEWED = 'recording_viewed'; |
79
|
|
|
/** @var BIGBLUEBUTTON_EVENT_MEETING_START string defines the bigbluebuttonbn meeting_start event */ |
80
|
|
|
const BIGBLUEBUTTON_EVENT_MEETING_START = 'meeting_start'; |
81
|
|
|
/** @var BIGBLUEBUTTON_CLIENTTYPE_FLASH integer that defines the bigbluebuttonbn default web client based on Adobe FLASH */ |
82
|
|
|
const BIGBLUEBUTTON_CLIENTTYPE_FLASH = 0; |
83
|
|
|
/** @var BIGBLUEBUTTON_CLIENTTYPE_HTML5 integer that defines the bigbluebuttonbn default web client based on HTML5 */ |
84
|
|
|
const BIGBLUEBUTTON_CLIENTTYPE_HTML5 = 1; |
85
|
|
|
/** @var BIGBLUEBUTTON_ORIGIN_BASE integer set to 0 defines that the user acceded the session from activity page */ |
86
|
|
|
const BIGBLUEBUTTON_ORIGIN_BASE = 0; |
87
|
|
|
/** @var BIGBLUEBUTTON_ORIGIN_TIMELINE integer set to 1 defines that the user acceded the session from Timeline */ |
88
|
|
|
const BIGBLUEBUTTON_ORIGIN_TIMELINE = 1; |
89
|
|
|
/** @var BIGBLUEBUTTON_ORIGIN_INDEX integer set to 2 defines that the user acceded the session from Index */ |
90
|
|
|
const BIGBLUEBUTTON_ORIGIN_INDEX = 2; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Builds and retunrs a url for joining a bigbluebutton meeting. |
94
|
|
|
* |
95
|
|
|
* @param string $meetingid |
96
|
|
|
* @param string $username |
97
|
|
|
* @param string $pw |
98
|
|
|
* @param string $logouturl |
99
|
|
|
* @param string $configtoken |
100
|
|
|
* @param string $userid |
101
|
|
|
* @param string $clienttype |
102
|
|
|
* @param string $createtime |
103
|
|
|
* |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
function bigbluebuttonbn_get_join_url( |
107
|
|
|
$meetingid, |
108
|
|
|
$username, |
109
|
|
|
$pw, |
110
|
|
|
$logouturl, |
111
|
|
|
$configtoken = null, |
112
|
|
|
$userid = null, |
113
|
|
|
$clienttype = BIGBLUEBUTTON_CLIENTTYPE_FLASH, |
114
|
|
|
$createtime = null |
115
|
|
|
) { |
116
|
|
|
$data = ['meetingID' => $meetingid, |
117
|
|
|
'fullName' => $username, |
118
|
|
|
'password' => $pw, |
119
|
|
|
'logoutURL' => $logouturl, |
120
|
|
|
]; |
121
|
|
|
// Choose between Adobe Flash or HTML5 Client. |
122
|
|
|
if ($clienttype == BIGBLUEBUTTON_CLIENTTYPE_HTML5) { |
123
|
|
|
$data['joinViaHtml5'] = 'true'; |
124
|
|
|
} |
125
|
|
|
if (!is_null($configtoken)) { |
126
|
|
|
$data['configToken'] = $configtoken; |
127
|
|
|
} |
128
|
|
|
if (!is_null($userid)) { |
129
|
|
|
$data['userID'] = $userid; |
130
|
|
|
} |
131
|
|
|
if (!is_null($createtime)) { |
132
|
|
|
$data['createTime'] = $createtime; |
133
|
|
|
} |
134
|
|
|
return \mod_bigbluebuttonbn\locallib\bigbluebutton::action_url('join', $data); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Creates a bigbluebutton meeting and returns the response in an array. |
139
|
|
|
* |
140
|
|
|
* @param array $data |
141
|
|
|
* @param array $metadata |
142
|
|
|
* @param string $pname |
143
|
|
|
* @param string $purl |
144
|
|
|
* |
145
|
|
|
* @return array |
146
|
|
|
*/ |
147
|
|
|
function bigbluebuttonbn_get_create_meeting_array($data, $metadata = array(), $pname = null, $purl = null) { |
148
|
|
|
$createmeetingurl = \mod_bigbluebuttonbn\locallib\bigbluebutton::action_url('create', $data, $metadata); |
149
|
|
|
$method = 'GET'; |
150
|
|
|
$payload = null; |
151
|
|
|
if (!is_null($pname) && !is_null($purl)) { |
152
|
|
|
$method = 'POST'; |
153
|
|
|
$payload = "<?xml version='1.0' encoding='UTF-8'?><modules><module name='presentation'><document url='". |
154
|
|
|
$purl."' /></module></modules>"; |
155
|
|
|
} |
156
|
|
|
$xml = bigbluebuttonbn_wrap_xml_load_file($createmeetingurl, $method, $payload); |
157
|
|
|
if ($xml) { |
158
|
|
|
$response = array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey); |
159
|
|
|
if ($xml->meetingID) { |
160
|
|
|
$response += array('meetingID' => $xml->meetingID, 'attendeePW' => $xml->attendeePW, |
161
|
|
|
'moderatorPW' => $xml->moderatorPW, 'hasBeenForciblyEnded' => $xml->hasBeenForciblyEnded); |
162
|
|
|
} |
163
|
|
|
return $response; |
164
|
|
|
} |
165
|
|
|
return array('returncode' => 'FAILED', 'message' => 'unreachable', 'messageKey' => 'Server is unreachable'); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Fetch meeting info and wrap response in array. |
170
|
|
|
* |
171
|
|
|
* @param string $meetingid |
172
|
|
|
* |
173
|
|
|
* @return array |
174
|
|
|
*/ |
175
|
|
|
function bigbluebuttonbn_get_meeting_info_array($meetingid) { |
176
|
|
|
$xml = bigbluebuttonbn_wrap_xml_load_file( |
177
|
|
|
\mod_bigbluebuttonbn\locallib\bigbluebutton::action_url('getMeetingInfo', ['meetingID' => $meetingid]) |
178
|
|
|
); |
179
|
|
|
if ($xml && $xml->returncode == 'SUCCESS' && empty($xml->messageKey)) { |
180
|
|
|
// Meeting info was returned. |
181
|
|
|
return array('returncode' => $xml->returncode, |
182
|
|
|
'meetingID' => $xml->meetingID, |
183
|
|
|
'moderatorPW' => $xml->moderatorPW, |
184
|
|
|
'attendeePW' => $xml->attendeePW, |
185
|
|
|
'hasBeenForciblyEnded' => $xml->hasBeenForciblyEnded, |
186
|
|
|
'running' => $xml->running, |
187
|
|
|
'recording' => $xml->recording, |
188
|
|
|
'startTime' => $xml->startTime, |
189
|
|
|
'endTime' => $xml->endTime, |
190
|
|
|
'participantCount' => $xml->participantCount, |
191
|
|
|
'moderatorCount' => $xml->moderatorCount, |
192
|
|
|
'attendees' => $xml->attendees, |
193
|
|
|
'metadata' => $xml->metadata, |
194
|
|
|
); |
195
|
|
|
} |
196
|
|
|
if ($xml) { |
197
|
|
|
// Either failure or success without meeting info. |
198
|
|
|
return (array) $xml; |
199
|
|
|
} |
200
|
|
|
// If the server is unreachable, then prompts the user of the necessary action. |
201
|
|
|
return array('returncode' => 'FAILED', 'message' => 'unreachable', 'messageKey' => 'Server is unreachable'); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Helper function to retrieve recordings from a BigBlueButton server. |
206
|
|
|
* |
207
|
|
|
* @param string|array $meetingids list of meetingIDs "mid1,mid2,mid3" or array("mid1","mid2","mid3") |
208
|
|
|
* @param string|array $recordingids list of $recordingids "rid1,rid2,rid3" or array("rid1","rid2","rid3") for filtering |
209
|
|
|
* |
210
|
|
|
* @return associative array with recordings indexed by recordID, each recording is a non sequential associative array |
211
|
|
|
*/ |
212
|
|
|
function bigbluebuttonbn_get_recordings_array($meetingids, $recordingids = []) { |
213
|
|
|
$meetingidsarray = $meetingids; |
214
|
|
|
if (!is_array($meetingids)) { |
215
|
|
|
$meetingidsarray = explode(',', $meetingids); |
216
|
|
|
} |
217
|
|
|
// If $meetingidsarray is empty there is no need to go further. |
218
|
|
|
if (empty($meetingidsarray)) { |
219
|
|
|
return array(); |
220
|
|
|
} |
221
|
|
|
$recordings = bigbluebuttonbn_get_recordings_array_fetch($meetingidsarray); |
|
|
|
|
222
|
|
|
// Sort recordings. |
223
|
|
|
uasort($recordings, 'bigbluebuttonbn_recording_build_sorter'); |
224
|
|
|
// Filter recordings based on recordingIDs. |
225
|
|
|
$recordingidsarray = $recordingids; |
226
|
|
|
if (!is_array($recordingids)) { |
227
|
|
|
$recordingidsarray = explode(',', $recordingids); |
228
|
|
|
} |
229
|
|
|
if (empty($recordingidsarray)) { |
230
|
|
|
// No recording ids, no need to filter. |
231
|
|
|
return $recordings; |
232
|
|
|
} |
233
|
|
|
return bigbluebuttonbn_get_recordings_array_filter($recordingidsarray, $recordings); |
|
|
|
|
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Helper function to fetch recordings from a BigBlueButton server. |
238
|
|
|
* |
239
|
|
|
* @param array $meetingidsarray array with meeting ids in the form array("mid1","mid2","mid3") |
240
|
|
|
* |
241
|
|
|
* @return array (associative) with recordings indexed by recordID, each recording is a non sequential associative array |
242
|
|
|
*/ |
243
|
|
|
function bigbluebuttonbn_get_recordings_array_fetch($meetingidsarray) { |
244
|
|
|
if ((defined('PHPUNIT_TEST') && PHPUNIT_TEST) |
245
|
|
|
|| defined('BEHAT_SITE_RUNNING') |
246
|
|
|
|| defined('BEHAT_TEST') |
247
|
|
|
|| defined('BEHAT_UTIL')) { |
248
|
|
|
// Just return the fake recording. |
249
|
|
|
global $CFG; |
250
|
|
|
require_once($CFG->libdir . '/testing/generator/lib.php'); |
251
|
|
|
require_once(__DIR__ . '/tests/generator/lib.php'); |
252
|
|
|
return mod_bigbluebuttonbn_generator::bigbluebuttonbn_get_recordings_array_fetch($meetingidsarray); |
253
|
|
|
} |
254
|
|
|
$recordings = array(); |
255
|
|
|
// Execute a paginated getRecordings request. |
256
|
|
|
$pagecount = 25; |
257
|
|
|
$pages = floor(count($meetingidsarray) / $pagecount) + 1; |
258
|
|
|
if (count($meetingidsarray) > 0 && count($meetingidsarray) % $pagecount == 0) { |
259
|
|
|
$pages--; |
260
|
|
|
} |
261
|
|
|
for ($page = 1; $page <= $pages; ++$page) { |
262
|
|
|
$mids = array_slice($meetingidsarray, ($page - 1) * $pagecount, $pagecount); |
263
|
|
|
$recordings += bigbluebuttonbn_get_recordings_array_fetch_page($mids); |
264
|
|
|
} |
265
|
|
|
return $recordings; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Helper function to fetch one page of upto 25 recordings from a BigBlueButton server. |
270
|
|
|
* |
271
|
|
|
* @param array $mids |
272
|
|
|
* |
273
|
|
|
* @return array |
274
|
|
|
*/ |
275
|
|
|
function bigbluebuttonbn_get_recordings_array_fetch_page($mids) { |
276
|
|
|
$recordings = array(); |
277
|
|
|
// Do getRecordings is executed using a method GET (supported by all versions of BBB). |
278
|
|
|
$url = \mod_bigbluebuttonbn\locallib\bigbluebutton::action_url('getRecordings', ['meetingID' => implode(',', $mids)]); |
279
|
|
|
$xml = bigbluebuttonbn_wrap_xml_load_file($url); |
280
|
|
|
if ($xml && $xml->returncode == 'SUCCESS' && isset($xml->recordings)) { |
281
|
|
|
// If there were meetings already created. |
282
|
|
|
foreach ($xml->recordings->recording as $recordingxml) { |
283
|
|
|
$recording = bigbluebuttonbn_get_recording_array_value($recordingxml); |
284
|
|
|
$recordings[$recording['recordID']] = $recording; |
285
|
|
|
|
286
|
|
|
// Check if there is childs. |
287
|
|
|
if (isset($recordingxml->breakoutRooms->breakoutRoom)) { |
288
|
|
|
foreach ($recordingxml->breakoutRooms->breakoutRoom as $breakoutroom) { |
289
|
|
|
$url = \mod_bigbluebuttonbn\locallib\bigbluebutton::action_url( |
290
|
|
|
'getRecordings', |
291
|
|
|
['recordID' => implode(',', (array) $breakoutroom)] |
292
|
|
|
); |
293
|
|
|
$xml = bigbluebuttonbn_wrap_xml_load_file($url); |
294
|
|
|
if ($xml && $xml->returncode == 'SUCCESS' && isset($xml->recordings)) { |
295
|
|
|
// If there were meetings already created. |
296
|
|
|
foreach ($xml->recordings->recording as $recordingxml) { |
297
|
|
|
$recording = bigbluebuttonbn_get_recording_array_value($recordingxml); |
298
|
|
|
$recordings[$recording['recordID']] = $recording; |
299
|
|
|
} |
300
|
|
|
} |
301
|
|
|
} |
302
|
|
|
} |
303
|
|
|
} |
304
|
|
|
} |
305
|
|
|
return $recordings; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Helper function to remove a set of recordings from an array. |
310
|
|
|
* |
311
|
|
|
* @param array $rids |
312
|
|
|
* @param array $recordings |
313
|
|
|
* |
314
|
|
|
* @return array |
315
|
|
|
*/ |
316
|
|
|
function bigbluebuttonbn_get_recordings_array_filter($rids, &$recordings) { |
317
|
|
|
foreach ($recordings as $key => $recording) { |
318
|
|
|
if (!in_array($recording['recordID'], $rids)) { |
319
|
|
|
unset($recordings[$key]); |
320
|
|
|
} |
321
|
|
|
} |
322
|
|
|
return $recordings; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* Helper function to retrieve imported recordings from the Moodle database. |
327
|
|
|
* The references are stored as events in bigbluebuttonbn_logs. |
328
|
|
|
* |
329
|
|
|
* @param string $courseid |
330
|
|
|
* @param string $bigbluebuttonbnid |
331
|
|
|
* @param bool $subset |
332
|
|
|
* |
333
|
|
|
* @return associative array with imported recordings indexed by recordID, each recording |
334
|
|
|
* is a non sequential associative array that corresponds to the actual recording in BBB |
335
|
|
|
*/ |
336
|
|
|
function bigbluebuttonbn_get_recordings_imported_array($courseid = 0, $bigbluebuttonbnid = null, $subset = true) { |
337
|
|
|
global $DB; |
338
|
|
|
$select = bigbluebuttonbn_get_recordings_imported_sql_select($courseid, $bigbluebuttonbnid, $subset); |
339
|
|
|
$recordsimported = $DB->get_records_select('bigbluebuttonbn_logs', $select); |
340
|
|
|
$recordsimportedarray = array(); |
341
|
|
|
foreach ($recordsimported as $recordimported) { |
342
|
|
|
$meta = json_decode($recordimported->meta, true); |
343
|
|
|
$recording = $meta['recording']; |
344
|
|
|
// Override imported flag with actual ID. |
345
|
|
|
$recording['imported'] = $recordimported->id; |
346
|
|
|
if (isset($recordimported->protected)) { |
347
|
|
|
$recording['protected'] = (string) $recordimported->protected; |
348
|
|
|
} |
349
|
|
|
$recordsimportedarray[$recording['recordID']] = $recording; |
350
|
|
|
} |
351
|
|
|
return $recordsimportedarray; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Helper function to retrive the default config.xml file. |
356
|
|
|
* |
357
|
|
|
* @return string |
358
|
|
|
*/ |
359
|
|
|
function bigbluebuttonbn_get_default_config_xml() { |
360
|
|
|
$xml = bigbluebuttonbn_wrap_xml_load_file( |
361
|
|
|
\mod_bigbluebuttonbn\locallib\bigbluebutton::action_url('getDefaultConfigXML') |
362
|
|
|
); |
363
|
|
|
return $xml; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* Helper function to convert an xml recording object to an array in the format used by the plugin. |
368
|
|
|
* |
369
|
|
|
* @param object $recording |
370
|
|
|
* |
371
|
|
|
* @return array |
372
|
|
|
*/ |
373
|
|
|
function bigbluebuttonbn_get_recording_array_value($recording) { |
374
|
|
|
// Add formats. |
375
|
|
|
$playbackarray = array(); |
376
|
|
|
foreach ($recording->playback->format as $format) { |
377
|
|
|
$playbackarray[(string) $format->type] = array('type' => (string) $format->type, |
378
|
|
|
'url' => trim((string) $format->url), 'length' => (string) $format->length); |
379
|
|
|
// Add preview per format when existing. |
380
|
|
|
if ($format->preview) { |
381
|
|
|
$playbackarray[(string) $format->type]['preview'] = bigbluebuttonbn_get_recording_preview_images($format->preview); |
382
|
|
|
} |
383
|
|
|
} |
384
|
|
|
// Add the metadata to the recordings array. |
385
|
|
|
$metadataarray = bigbluebuttonbn_get_recording_array_meta(get_object_vars($recording->metadata)); |
386
|
|
|
$recordingarray = array('recordID' => (string) $recording->recordID, |
387
|
|
|
'meetingID' => (string) $recording->meetingID, 'meetingName' => (string) $recording->name, |
388
|
|
|
'published' => (string) $recording->published, 'startTime' => (string) $recording->startTime, |
389
|
|
|
'endTime' => (string) $recording->endTime, 'playbacks' => $playbackarray); |
390
|
|
|
if (isset($recording->protected)) { |
391
|
|
|
$recordingarray['protected'] = (string) $recording->protected; |
392
|
|
|
} |
393
|
|
|
return $recordingarray + $metadataarray; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* Helper function to convert an xml recording preview images to an array in the format used by the plugin. |
398
|
|
|
* |
399
|
|
|
* @param object $preview |
400
|
|
|
* |
401
|
|
|
* @return array |
402
|
|
|
*/ |
403
|
|
|
function bigbluebuttonbn_get_recording_preview_images($preview) { |
404
|
|
|
$imagesarray = array(); |
405
|
|
|
foreach ($preview->images->image as $image) { |
406
|
|
|
$imagearray = array('url' => trim((string) $image)); |
407
|
|
|
foreach ($image->attributes() as $attkey => $attvalue) { |
408
|
|
|
$imagearray[$attkey] = (string) $attvalue; |
409
|
|
|
} |
410
|
|
|
array_push($imagesarray, $imagearray); |
411
|
|
|
} |
412
|
|
|
return $imagesarray; |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* Helper function to convert an xml recording metadata object to an array in the format used by the plugin. |
417
|
|
|
* |
418
|
|
|
* @param array $metadata |
419
|
|
|
* |
420
|
|
|
* @return array |
421
|
|
|
*/ |
422
|
|
|
function bigbluebuttonbn_get_recording_array_meta($metadata) { |
423
|
|
|
$metadataarray = array(); |
424
|
|
|
foreach ($metadata as $key => $value) { |
425
|
|
|
if (is_object($value)) { |
426
|
|
|
$value = ''; |
427
|
|
|
} |
428
|
|
|
$metadataarray['meta_' . $key] = $value; |
429
|
|
|
} |
430
|
|
|
return $metadataarray; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* Helper function to sort an array of recordings. It compares the startTime in two recording objecs. |
435
|
|
|
* |
436
|
|
|
* @param object $a |
437
|
|
|
* @param object $b |
438
|
|
|
* |
439
|
|
|
* @return array |
440
|
|
|
*/ |
441
|
|
|
function bigbluebuttonbn_recording_build_sorter($a, $b) { |
442
|
|
|
global $CFG; |
443
|
|
|
$resultless = !empty($CFG->bigbluebuttonbn_recordings_sortorder) ? -1 : 1; |
444
|
|
|
$resultmore = !empty($CFG->bigbluebuttonbn_recordings_sortorder) ? 1 : -1; |
445
|
|
|
if ($a['startTime'] < $b['startTime']) { |
446
|
|
|
return $resultless; |
447
|
|
|
} |
448
|
|
|
if ($a['startTime'] == $b['startTime']) { |
449
|
|
|
return 0; |
450
|
|
|
} |
451
|
|
|
return $resultmore; |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* Perform deleteRecordings on BBB. |
456
|
|
|
* |
457
|
|
|
* @param string $recordids |
458
|
|
|
* |
459
|
|
|
* @return boolean |
460
|
|
|
*/ |
461
|
|
View Code Duplication |
function bigbluebuttonbn_delete_recordings($recordids) { |
|
|
|
|
462
|
|
|
$ids = explode(',', $recordids); |
463
|
|
|
foreach ($ids as $id) { |
464
|
|
|
$xml = bigbluebuttonbn_wrap_xml_load_file( |
465
|
|
|
\mod_bigbluebuttonbn\locallib\bigbluebutton::action_url('deleteRecordings', ['recordID' => $id]) |
466
|
|
|
); |
467
|
|
|
if ($xml && $xml->returncode != 'SUCCESS') { |
468
|
|
|
return false; |
469
|
|
|
} |
470
|
|
|
} |
471
|
|
|
return true; |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
/** |
475
|
|
|
* Perform publishRecordings on BBB. |
476
|
|
|
* |
477
|
|
|
* @param string $recordids |
478
|
|
|
* @param string $publish |
479
|
|
|
*/ |
480
|
|
View Code Duplication |
function bigbluebuttonbn_publish_recordings($recordids, $publish = 'true') { |
|
|
|
|
481
|
|
|
$ids = explode(',', $recordids); |
482
|
|
|
foreach ($ids as $id) { |
483
|
|
|
$xml = bigbluebuttonbn_wrap_xml_load_file( |
484
|
|
|
\mod_bigbluebuttonbn\locallib\bigbluebutton::action_url('publishRecordings', ['recordID' => $id, 'publish' => $publish]) |
485
|
|
|
); |
486
|
|
|
if ($xml && $xml->returncode != 'SUCCESS') { |
487
|
|
|
return false; |
488
|
|
|
} |
489
|
|
|
} |
490
|
|
|
return true; |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* Perform updateRecordings on BBB. |
495
|
|
|
* |
496
|
|
|
* @param string $recordids |
497
|
|
|
* @param array $params ['key'=>param_key, 'value'] |
498
|
|
|
*/ |
499
|
|
View Code Duplication |
function bigbluebuttonbn_update_recordings($recordids, $params) { |
|
|
|
|
500
|
|
|
$ids = explode(',', $recordids); |
501
|
|
|
foreach ($ids as $id) { |
502
|
|
|
$xml = bigbluebuttonbn_wrap_xml_load_file( |
503
|
|
|
\mod_bigbluebuttonbn\locallib\bigbluebutton::action_url('updateRecordings', ['recordID' => $id] + (array) $params) |
504
|
|
|
); |
505
|
|
|
if ($xml && $xml->returncode != 'SUCCESS') { |
506
|
|
|
return false; |
507
|
|
|
} |
508
|
|
|
} |
509
|
|
|
return true; |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* Perform end on BBB. |
514
|
|
|
* |
515
|
|
|
* @param string $meetingid |
516
|
|
|
* @param string $modpw |
517
|
|
|
*/ |
518
|
|
|
function bigbluebuttonbn_end_meeting($meetingid, $modpw) { |
519
|
|
|
$xml = bigbluebuttonbn_wrap_xml_load_file( |
520
|
|
|
\mod_bigbluebuttonbn\locallib\bigbluebutton::action_url('end', ['meetingID' => $meetingid, 'password' => $modpw]) |
521
|
|
|
); |
522
|
|
|
if ($xml) { |
523
|
|
|
// If the xml packet returned failure it displays the message to the user. |
524
|
|
|
return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey); |
525
|
|
|
} |
526
|
|
|
// If the server is unreachable, then prompts the user of the necessary action. |
527
|
|
|
return null; |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
/** |
531
|
|
|
* Perform api request on BBB. |
532
|
|
|
* |
533
|
|
|
* @return string |
534
|
|
|
*/ |
535
|
|
|
function bigbluebuttonbn_get_server_version() { |
536
|
|
|
$xml = bigbluebuttonbn_wrap_xml_load_file( |
537
|
|
|
\mod_bigbluebuttonbn\locallib\bigbluebutton::action_url() |
538
|
|
|
); |
539
|
|
|
if ($xml && $xml->returncode == 'SUCCESS') { |
540
|
|
|
return $xml->version; |
541
|
|
|
} |
542
|
|
|
return null; |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
/** |
546
|
|
|
* Perform api request on BBB and wraps the response in an XML object |
547
|
|
|
* |
548
|
|
|
* @param string $url |
549
|
|
|
* @param string $method |
550
|
|
|
* @param string $data |
551
|
|
|
* @param string $contenttype |
552
|
|
|
* |
553
|
|
|
* @return object |
554
|
|
|
*/ |
555
|
|
|
function bigbluebuttonbn_wrap_xml_load_file($url, $method = 'GET', $data = null, $contenttype = 'text/xml') { |
556
|
|
|
if (extension_loaded('curl')) { |
557
|
|
|
$response = bigbluebuttonbn_wrap_xml_load_file_curl_request($url, $method, $data, $contenttype); |
558
|
|
|
if (!$response) { |
559
|
|
|
debugging('No response on wrap_simplexml_load_file', DEBUG_DEVELOPER); |
560
|
|
|
return null; |
561
|
|
|
} |
562
|
|
|
$previous = libxml_use_internal_errors(true); |
563
|
|
|
try { |
564
|
|
|
$xml = simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS); |
565
|
|
|
return $xml; |
566
|
|
|
} catch (Exception $e) { |
567
|
|
|
libxml_use_internal_errors($previous); |
568
|
|
|
$error = 'Caught exception: ' . $e->getMessage(); |
569
|
|
|
debugging($error, DEBUG_DEVELOPER); |
570
|
|
|
return null; |
571
|
|
|
} |
572
|
|
|
} |
573
|
|
|
// Alternative request non CURL based. |
574
|
|
|
$previous = libxml_use_internal_errors(true); |
575
|
|
|
try { |
576
|
|
|
$response = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS); |
577
|
|
|
return $response; |
578
|
|
|
} catch (Exception $e) { |
579
|
|
|
$error = 'Caught exception: ' . $e->getMessage(); |
580
|
|
|
debugging($error, DEBUG_DEVELOPER); |
581
|
|
|
libxml_use_internal_errors($previous); |
582
|
|
|
return null; |
583
|
|
|
} |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
/** |
587
|
|
|
* Perform api request on BBB using CURL and wraps the response in an XML object |
588
|
|
|
* |
589
|
|
|
* @param string $url |
590
|
|
|
* @param string $method |
591
|
|
|
* @param string $data |
592
|
|
|
* @param string $contenttype |
593
|
|
|
* |
594
|
|
|
* @return object |
595
|
|
|
*/ |
596
|
|
|
function bigbluebuttonbn_wrap_xml_load_file_curl_request($url, $method = 'GET', $data = null, $contenttype = 'text/xml') { |
597
|
|
|
global $CFG; |
598
|
|
|
require_once($CFG->libdir . '/filelib.php'); |
599
|
|
|
$c = new curl(); |
600
|
|
|
$c->setopt(array('SSL_VERIFYPEER' => true)); |
601
|
|
|
if ($method == 'POST') { |
602
|
|
|
if (is_null($data) || is_array($data)) { |
603
|
|
|
return $c->post($url); |
604
|
|
|
} |
605
|
|
|
$options = array(); |
606
|
|
|
$options['CURLOPT_HTTPHEADER'] = array( |
607
|
|
|
'Content-Type: ' . $contenttype, |
608
|
|
|
'Content-Length: ' . strlen($data), |
609
|
|
|
'Content-Language: en-US', |
610
|
|
|
); |
611
|
|
|
|
612
|
|
|
return $c->post($url, $data, $options); |
613
|
|
|
} |
614
|
|
|
if ($method == 'HEAD') { |
615
|
|
|
$c->head($url, array('followlocation' => true, 'timeout' => 1)); |
616
|
|
|
return $c->get_info(); |
617
|
|
|
} |
618
|
|
|
return $c->get($url); |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
/** |
622
|
|
|
* End the session associated with this instance (if it's running). |
623
|
|
|
* |
624
|
|
|
* @param object $bigbluebuttonbn |
625
|
|
|
* |
626
|
|
|
* @return void |
627
|
|
|
*/ |
628
|
|
|
function bigbluebuttonbn_end_meeting_if_running($bigbluebuttonbn) { |
629
|
|
|
$meetingid = $bigbluebuttonbn->meetingid . '-' . $bigbluebuttonbn->course . '-' . $bigbluebuttonbn->id; |
630
|
|
|
if (bigbluebuttonbn_is_meeting_running($meetingid)) { |
631
|
|
|
bigbluebuttonbn_end_meeting($meetingid, $bigbluebuttonbn->moderatorpass); |
632
|
|
|
} |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
/** |
636
|
|
|
* Returns user roles in a context. |
637
|
|
|
* |
638
|
|
|
* @param object $context |
639
|
|
|
* @param integer $userid |
640
|
|
|
* |
641
|
|
|
* @return array $userroles |
642
|
|
|
*/ |
643
|
|
|
function bigbluebuttonbn_get_user_roles($context, $userid) { |
644
|
|
|
global $DB; |
645
|
|
|
$userroles = get_user_roles($context, $userid); |
646
|
|
|
if ($userroles) { |
647
|
|
|
$where = ''; |
648
|
|
|
foreach ($userroles as $userrole) { |
649
|
|
|
$where .= (empty($where) ? ' WHERE' : ' OR') . ' id=' . $userrole->roleid; |
650
|
|
|
} |
651
|
|
|
$userroles = $DB->get_records_sql('SELECT * FROM {role}' . $where); |
652
|
|
|
} |
653
|
|
|
return $userroles; |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
/** |
657
|
|
|
* Returns guest role wrapped in an array. |
658
|
|
|
* |
659
|
|
|
* @return array |
660
|
|
|
*/ |
661
|
|
|
function bigbluebuttonbn_get_guest_role() { |
662
|
|
|
$guestrole = get_guest_role(); |
663
|
|
|
return array($guestrole->id => $guestrole); |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
/** |
667
|
|
|
* Returns an array containing all the users in a context. |
668
|
|
|
* |
669
|
|
|
* @param context $context |
670
|
|
|
* |
671
|
|
|
* @return array $users |
672
|
|
|
*/ |
673
|
|
|
function bigbluebuttonbn_get_users(context $context = null) { |
674
|
|
|
$users = (array) get_enrolled_users($context, '', 0, 'u.*', null, 0, 0, true); |
675
|
|
|
foreach ($users as $key => $value) { |
676
|
|
|
$users[$key] = fullname($value); |
677
|
|
|
} |
678
|
|
|
return $users; |
679
|
|
|
} |
680
|
|
|
|
681
|
|
|
/** |
682
|
|
|
* Returns an array containing all the users in a context wrapped for html select element. |
683
|
|
|
* |
684
|
|
|
* @param context_course $context |
685
|
|
|
* @param null $bbactivity |
686
|
|
|
* @return array $users |
687
|
|
|
* @throws coding_exception |
688
|
|
|
* @throws moodle_exception |
689
|
|
|
*/ |
690
|
|
|
function bigbluebuttonbn_get_users_select(context_course $context, $bbactivity = null) { |
691
|
|
|
// CONTRIB-7972, check the group of current user and course group mode. |
692
|
|
|
$groups = null; |
|
|
|
|
693
|
|
|
$users = (array) get_enrolled_users($context, '', 0, 'u.*', null, 0, 0, true); |
694
|
|
|
$course = get_course($context->instanceid); |
695
|
|
|
$groupmode = groups_get_course_groupmode($course); |
696
|
|
|
if ($bbactivity) { |
697
|
|
|
list($bbcourse, $cm) = get_course_and_cm_from_instance($bbactivity->id, 'bigbluebuttonbn'); |
|
|
|
|
698
|
|
|
$groupmode = groups_get_activity_groupmode($cm); |
699
|
|
|
|
700
|
|
|
} |
701
|
|
|
if ($groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context)) { |
702
|
|
|
global $USER; |
703
|
|
|
$groups = groups_get_all_groups($course->id, $USER->id); |
704
|
|
|
$users = []; |
705
|
|
|
foreach ($groups as $g) { |
706
|
|
|
$users += (array) get_enrolled_users($context, '', $g->id, 'u.*', null, 0, 0, true); |
707
|
|
|
} |
708
|
|
|
} |
709
|
|
|
return array_map( |
710
|
|
|
function($u) { |
711
|
|
|
return array('id' => $u->id, 'name' => fullname($u)); |
712
|
|
|
}, |
713
|
|
|
$users); |
714
|
|
|
} |
715
|
|
|
|
716
|
|
|
/** |
717
|
|
|
* Returns an array containing all the roles in a context. |
718
|
|
|
* |
719
|
|
|
* @param context $context |
720
|
|
|
* @param bool $onlyviewableroles |
721
|
|
|
* |
722
|
|
|
* @return array $roles |
723
|
|
|
*/ |
724
|
|
|
function bigbluebuttonbn_get_roles(context $context = null, bool $onlyviewableroles = true) { |
725
|
|
|
global $CFG; |
726
|
|
|
|
727
|
|
|
if ($onlyviewableroles == true && $CFG->branch >= 35) { |
|
|
|
|
728
|
|
|
$roles = (array) get_viewable_roles($context); |
729
|
|
|
foreach ($roles as $key => $value) { |
730
|
|
|
$roles[$key] = $value; |
731
|
|
|
} |
732
|
|
|
} else { |
733
|
|
|
$roles = (array) role_get_names($context); |
734
|
|
|
foreach ($roles as $key => $value) { |
735
|
|
|
$roles[$key] = $value->localname; |
736
|
|
|
} |
737
|
|
|
} |
738
|
|
|
|
739
|
|
|
return $roles; |
740
|
|
|
} |
741
|
|
|
|
742
|
|
|
/** |
743
|
|
|
* Returns an array containing all the roles in a context wrapped for html select element. |
744
|
|
|
* |
745
|
|
|
* @param context $context |
746
|
|
|
* @param bool $onlyviewableroles |
747
|
|
|
* |
748
|
|
|
* @return array $users |
749
|
|
|
*/ |
750
|
|
|
function bigbluebuttonbn_get_roles_select(context $context = null, bool $onlyviewableroles = true) { |
751
|
|
|
global $CFG; |
752
|
|
|
|
753
|
|
|
if ($onlyviewableroles == true && $CFG->branch >= 35) { |
|
|
|
|
754
|
|
|
$roles = (array) get_viewable_roles($context); |
755
|
|
|
foreach ($roles as $key => $value) { |
756
|
|
|
$roles[$key] = array('id' => $key, 'name' => $value); |
757
|
|
|
} |
758
|
|
|
} else { |
759
|
|
|
$roles = (array) role_get_names($context); |
760
|
|
|
foreach ($roles as $key => $value) { |
761
|
|
|
$roles[$key] = array('id' => $value->id, 'name' => $value->localname); |
762
|
|
|
} |
763
|
|
|
} |
764
|
|
|
|
765
|
|
|
return $roles; |
766
|
|
|
} |
767
|
|
|
|
768
|
|
|
/** |
769
|
|
|
* Returns role that corresponds to an id. |
770
|
|
|
* |
771
|
|
|
* @param string|integer $id |
772
|
|
|
* |
773
|
|
|
* @return object $role |
774
|
|
|
*/ |
775
|
|
|
function bigbluebuttonbn_get_role($id) { |
776
|
|
|
$roles = (array) role_get_names(); |
777
|
|
|
if (is_numeric($id) && isset($roles[$id])) { |
778
|
|
|
return (object) $roles[$id]; |
779
|
|
|
} |
780
|
|
|
foreach ($roles as $role) { |
781
|
|
|
if ($role->shortname == $id) { |
782
|
|
|
return $role; |
783
|
|
|
} |
784
|
|
|
} |
785
|
|
|
} |
786
|
|
|
|
787
|
|
|
/** |
788
|
|
|
* Returns an array to populate a list of participants used in mod_form.js. |
789
|
|
|
* |
790
|
|
|
* @param context $context |
791
|
|
|
* @param null|object $bbactivity |
792
|
|
|
* @return array $data |
793
|
|
|
*/ |
794
|
|
|
function bigbluebuttonbn_get_participant_data($context, $bbactivity = null) { |
795
|
|
|
$data = array( |
796
|
|
|
'all' => array( |
797
|
|
|
'name' => get_string('mod_form_field_participant_list_type_all', 'bigbluebuttonbn'), |
798
|
|
|
'children' => [] |
799
|
|
|
), |
800
|
|
|
); |
801
|
|
|
$data['role'] = array( |
802
|
|
|
'name' => get_string('mod_form_field_participant_list_type_role', 'bigbluebuttonbn'), |
803
|
|
|
'children' => bigbluebuttonbn_get_roles_select($context, true) |
804
|
|
|
); |
805
|
|
|
$data['user'] = array( |
806
|
|
|
'name' => get_string('mod_form_field_participant_list_type_user', 'bigbluebuttonbn'), |
807
|
|
|
'children' => bigbluebuttonbn_get_users_select($context, $bbactivity), |
|
|
|
|
808
|
|
|
); |
809
|
|
|
return $data; |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
/** |
813
|
|
|
* Returns an array to populate a list of participants used in mod_form.php. |
814
|
|
|
* |
815
|
|
|
* @param object $bigbluebuttonbn |
816
|
|
|
* @param context $context |
817
|
|
|
* |
818
|
|
|
* @return array |
819
|
|
|
*/ |
820
|
|
|
function bigbluebuttonbn_get_participant_list($bigbluebuttonbn, $context) { |
821
|
|
|
global $USER; |
822
|
|
|
if ($bigbluebuttonbn == null) { |
823
|
|
|
return bigbluebuttonbn_get_participant_rules_encoded( |
824
|
|
|
bigbluebuttonbn_get_participant_list_default($context, $USER->id) |
825
|
|
|
); |
826
|
|
|
} |
827
|
|
|
if (empty($bigbluebuttonbn->participants)) { |
828
|
|
|
$bigbluebuttonbn->participants = "[]"; |
829
|
|
|
} |
830
|
|
|
$rules = json_decode($bigbluebuttonbn->participants, true); |
831
|
|
|
if (empty($rules)) { |
832
|
|
|
$rules = bigbluebuttonbn_get_participant_list_default($context, bigbluebuttonbn_instance_ownerid($bigbluebuttonbn)); |
833
|
|
|
} |
834
|
|
|
return bigbluebuttonbn_get_participant_rules_encoded($rules); |
835
|
|
|
} |
836
|
|
|
|
837
|
|
|
/** |
838
|
|
|
* Returns an array to populate a list of participants used in mod_form.php with default values. |
839
|
|
|
* |
840
|
|
|
* @param context $context |
841
|
|
|
* @param integer $ownerid |
842
|
|
|
* |
843
|
|
|
* @return array |
844
|
|
|
*/ |
845
|
|
|
function bigbluebuttonbn_get_participant_list_default($context, $ownerid = null) { |
846
|
|
|
$participantlist = array(); |
847
|
|
|
$participantlist[] = array( |
848
|
|
|
'selectiontype' => 'all', |
849
|
|
|
'selectionid' => 'all', |
850
|
|
|
'role' => BIGBLUEBUTTONBN_ROLE_VIEWER, |
851
|
|
|
); |
852
|
|
|
$defaultrules = explode(',', \mod_bigbluebuttonbn\locallib\config::get('participant_moderator_default')); |
853
|
|
|
foreach ($defaultrules as $defaultrule) { |
854
|
|
|
if ($defaultrule == '0') { |
855
|
|
|
if (!empty($ownerid) && is_enrolled($context, $ownerid)) { |
856
|
|
|
$participantlist[] = array( |
857
|
|
|
'selectiontype' => 'user', |
858
|
|
|
'selectionid' => (string) $ownerid, |
859
|
|
|
'role' => BIGBLUEBUTTONBN_ROLE_MODERATOR); |
860
|
|
|
} |
861
|
|
|
continue; |
862
|
|
|
} |
863
|
|
|
$participantlist[] = array( |
864
|
|
|
'selectiontype' => 'role', |
865
|
|
|
'selectionid' => $defaultrule, |
866
|
|
|
'role' => BIGBLUEBUTTONBN_ROLE_MODERATOR); |
867
|
|
|
} |
868
|
|
|
return $participantlist; |
869
|
|
|
} |
870
|
|
|
|
871
|
|
|
/** |
872
|
|
|
* Returns an array to populate a list of participants used in mod_form.php with bigbluebuttonbn values. |
873
|
|
|
* |
874
|
|
|
* @param array $rules |
875
|
|
|
* |
876
|
|
|
* @return array |
877
|
|
|
*/ |
878
|
|
|
function bigbluebuttonbn_get_participant_rules_encoded($rules) { |
879
|
|
|
foreach ($rules as $key => $rule) { |
880
|
|
|
if ($rule['selectiontype'] !== 'role' || is_numeric($rule['selectionid'])) { |
881
|
|
|
continue; |
882
|
|
|
} |
883
|
|
|
$role = bigbluebuttonbn_get_role($rule['selectionid']); |
884
|
|
|
if ($role == null) { |
885
|
|
|
unset($rules[$key]); |
886
|
|
|
continue; |
887
|
|
|
} |
888
|
|
|
$rule['selectionid'] = $role->id; |
889
|
|
|
$rules[$key] = $rule; |
890
|
|
|
} |
891
|
|
|
return $rules; |
892
|
|
|
} |
893
|
|
|
|
894
|
|
|
/** |
895
|
|
|
* Returns an array to populate a list of participant_selection used in mod_form.php. |
896
|
|
|
* |
897
|
|
|
* @return array |
898
|
|
|
*/ |
899
|
|
|
function bigbluebuttonbn_get_participant_selection_data() { |
900
|
|
|
return [ |
901
|
|
|
'type_options' => [ |
902
|
|
|
'all' => get_string('mod_form_field_participant_list_type_all', 'bigbluebuttonbn'), |
903
|
|
|
'role' => get_string('mod_form_field_participant_list_type_role', 'bigbluebuttonbn'), |
904
|
|
|
'user' => get_string('mod_form_field_participant_list_type_user', 'bigbluebuttonbn'), |
905
|
|
|
], |
906
|
|
|
'type_selected' => 'all', |
907
|
|
|
'options' => ['all' => '---------------'], |
908
|
|
|
'selected' => 'all', |
909
|
|
|
]; |
910
|
|
|
} |
911
|
|
|
|
912
|
|
|
/** |
913
|
|
|
* Evaluate if a user in a context is moderator based on roles and participation rules. |
914
|
|
|
* |
915
|
|
|
* @param context $context |
916
|
|
|
* @param array $participantlist |
917
|
|
|
* @param integer $userid |
918
|
|
|
* |
919
|
|
|
* @return boolean |
920
|
|
|
*/ |
921
|
|
|
function bigbluebuttonbn_is_moderator($context, $participantlist, $userid = null) { |
922
|
|
|
global $USER; |
923
|
|
|
if (!is_array($participantlist)) { |
924
|
|
|
return false; |
925
|
|
|
} |
926
|
|
|
if (empty($userid)) { |
927
|
|
|
$userid = $USER->id; |
928
|
|
|
} |
929
|
|
|
$userroles = bigbluebuttonbn_get_guest_role(); |
930
|
|
|
if (!isguestuser()) { |
931
|
|
|
$userroles = bigbluebuttonbn_get_user_roles($context, $userid); |
932
|
|
|
} |
933
|
|
|
return bigbluebuttonbn_is_moderator_validator($participantlist, $userid, $userroles); |
934
|
|
|
} |
935
|
|
|
|
936
|
|
|
/** |
937
|
|
|
* Iterates participant list rules to evaluate if a user is moderator. |
938
|
|
|
* |
939
|
|
|
* @param array $participantlist |
940
|
|
|
* @param integer $userid |
941
|
|
|
* @param array $userroles |
942
|
|
|
* |
943
|
|
|
* @return boolean |
944
|
|
|
*/ |
945
|
|
|
function bigbluebuttonbn_is_moderator_validator($participantlist, $userid, $userroles) { |
946
|
|
|
// Iterate participant rules. |
947
|
|
|
foreach ($participantlist as $participant) { |
948
|
|
|
if (bigbluebuttonbn_is_moderator_validate_rule($participant, $userid, $userroles)) { |
949
|
|
|
return true; |
950
|
|
|
} |
951
|
|
|
} |
952
|
|
|
return false; |
953
|
|
|
} |
954
|
|
|
|
955
|
|
|
/** |
956
|
|
|
* Evaluate if a user is moderator based on roles and a particular participation rule. |
957
|
|
|
* |
958
|
|
|
* @param object $participant |
959
|
|
|
* @param integer $userid |
960
|
|
|
* @param array $userroles |
961
|
|
|
* |
962
|
|
|
* @return boolean |
963
|
|
|
*/ |
964
|
|
|
function bigbluebuttonbn_is_moderator_validate_rule($participant, $userid, $userroles) { |
965
|
|
|
if ($participant['role'] == BIGBLUEBUTTONBN_ROLE_VIEWER) { |
966
|
|
|
return false; |
967
|
|
|
} |
968
|
|
|
// Validation for the 'all' rule. |
969
|
|
|
if ($participant['selectiontype'] == 'all') { |
970
|
|
|
return true; |
971
|
|
|
} |
972
|
|
|
// Validation for a 'user' rule. |
973
|
|
|
if ($participant['selectiontype'] == 'user') { |
974
|
|
|
if ($participant['selectionid'] == $userid) { |
975
|
|
|
return true; |
976
|
|
|
} |
977
|
|
|
return false; |
978
|
|
|
} |
979
|
|
|
// Validation for a 'role' rule. |
980
|
|
|
$role = bigbluebuttonbn_get_role($participant['selectionid']); |
981
|
|
|
if ($role != null && array_key_exists($role->id, $userroles)) { |
982
|
|
|
return true; |
983
|
|
|
} |
984
|
|
|
return false; |
985
|
|
|
} |
986
|
|
|
|
987
|
|
|
/** |
988
|
|
|
* Helper returns error message key for the language file that corresponds to a bigbluebutton error key. |
989
|
|
|
* |
990
|
|
|
* @param string $messagekey |
991
|
|
|
* @param string $defaultkey |
992
|
|
|
* |
993
|
|
|
* @return string |
994
|
|
|
*/ |
995
|
|
|
function bigbluebuttonbn_get_error_key($messagekey, $defaultkey = null) { |
996
|
|
|
if ($messagekey == 'checksumError') { |
997
|
|
|
return 'index_error_checksum'; |
998
|
|
|
} |
999
|
|
|
if ($messagekey == 'maxConcurrent') { |
1000
|
|
|
return 'view_error_max_concurrent'; |
1001
|
|
|
} |
1002
|
|
|
return $defaultkey; |
1003
|
|
|
} |
1004
|
|
|
|
1005
|
|
|
/** |
1006
|
|
|
* Helper evaluates if a voicebridge number is unique. |
1007
|
|
|
* |
1008
|
|
|
* @param integer $instance |
1009
|
|
|
* @param integer $voicebridge |
1010
|
|
|
* |
1011
|
|
|
* @return string |
1012
|
|
|
*/ |
1013
|
|
|
function bigbluebuttonbn_voicebridge_unique($instance, $voicebridge) { |
1014
|
|
|
global $DB; |
1015
|
|
|
if ($voicebridge == 0) { |
1016
|
|
|
return true; |
1017
|
|
|
} |
1018
|
|
|
$select = 'voicebridge = ' . $voicebridge; |
1019
|
|
|
if ($instance != 0) { |
1020
|
|
|
$select .= ' AND id <>' . $instance; |
1021
|
|
|
} |
1022
|
|
|
if (!$DB->get_records_select('bigbluebuttonbn', $select)) { |
1023
|
|
|
return true; |
1024
|
|
|
} |
1025
|
|
|
return false; |
1026
|
|
|
} |
1027
|
|
|
|
1028
|
|
|
/** |
1029
|
|
|
* Helper estimate a duration for the meeting based on the closingtime. |
1030
|
|
|
* |
1031
|
|
|
* @param integer $closingtime |
1032
|
|
|
* |
1033
|
|
|
* @return integer |
1034
|
|
|
*/ |
1035
|
|
|
function bigbluebuttonbn_get_duration($closingtime) { |
1036
|
|
|
$duration = 0; |
1037
|
|
|
$now = time(); |
1038
|
|
|
if ($closingtime > 0 && $now < $closingtime) { |
1039
|
|
|
$duration = ceil(($closingtime - $now) / 60); |
1040
|
|
|
$compensationtime = intval((int) \mod_bigbluebuttonbn\locallib\config::get('scheduled_duration_compensation')); |
1041
|
|
|
$duration = intval($duration) + $compensationtime; |
1042
|
|
|
} |
1043
|
|
|
return $duration; |
1044
|
|
|
} |
1045
|
|
|
|
1046
|
|
|
/** |
1047
|
|
|
* Helper return array containing the file descriptor for a preuploaded presentation. |
1048
|
|
|
* |
1049
|
|
|
* @param context $context |
1050
|
|
|
* @param string $presentation |
1051
|
|
|
* @param integer $id |
1052
|
|
|
* |
1053
|
|
|
* @return array |
1054
|
|
|
*/ |
1055
|
|
|
function bigbluebuttonbn_get_presentation_array($context, $presentation, $id = null) { |
1056
|
|
|
global $CFG; |
1057
|
|
|
if (empty($presentation)) { |
1058
|
|
|
if ($CFG->bigbluebuttonbn_preuploadpresentation_enabled) { |
1059
|
|
|
// Item has not presentation but presentation is enabled.. |
1060
|
|
|
// Check if exist some file by default in general mod setting ("presentationdefault"). |
1061
|
|
|
$fs = get_file_storage(); |
1062
|
|
|
$files = $fs->get_area_files( |
1063
|
|
|
context_system::instance()->id, |
1064
|
|
|
'mod_bigbluebuttonbn', |
1065
|
|
|
'presentationdefault', |
1066
|
|
|
0, |
1067
|
|
|
"filename", |
1068
|
|
|
false |
1069
|
|
|
); |
1070
|
|
|
|
1071
|
|
View Code Duplication |
if (count($files) == 0) { |
|
|
|
|
1072
|
|
|
// Not exist file by default in "presentationbydefault" setting. |
1073
|
|
|
return array('url' => null, 'name' => null, 'icon' => null, 'mimetype_description' => null); |
1074
|
|
|
} |
1075
|
|
|
|
1076
|
|
|
// Exists file in general setting to use as default for presentation. Cache image for temp public access. |
1077
|
|
|
$file = reset($files); |
1078
|
|
|
unset($files); |
1079
|
|
|
$pnoncevalue = null; |
1080
|
|
View Code Duplication |
if (!is_null($id)) { |
|
|
|
|
1081
|
|
|
// Create the nonce component for granting a temporary public access. |
1082
|
|
|
$cache = cache::make_from_params( |
1083
|
|
|
cache_store::MODE_APPLICATION, |
1084
|
|
|
'mod_bigbluebuttonbn', |
1085
|
|
|
'presentationdefault_cache' |
1086
|
|
|
); |
1087
|
|
|
$pnoncekey = sha1(context_system::instance()->id); |
1088
|
|
|
/* The item id was adapted for granting public access to the presentation once in order |
1089
|
|
|
* to allow BigBlueButton to gather the file. */ |
1090
|
|
|
$pnoncevalue = bigbluebuttonbn_generate_nonce(); |
1091
|
|
|
$cache->set($pnoncekey, array('value' => $pnoncevalue, 'counter' => 0)); |
1092
|
|
|
} |
1093
|
|
|
|
1094
|
|
|
$url = moodle_url::make_pluginfile_url( |
1095
|
|
|
$file->get_contextid(), |
1096
|
|
|
$file->get_component(), |
1097
|
|
|
$file->get_filearea(), |
1098
|
|
|
$pnoncevalue, |
1099
|
|
|
$file->get_filepath(), |
1100
|
|
|
$file->get_filename() |
1101
|
|
|
); |
1102
|
|
|
return (array('name' => $file->get_filename(), 'icon' => file_file_icon($file, 24), |
1103
|
|
|
'url' => $url->out(false), 'mimetype_description' => get_mimetype_description($file))); |
1104
|
|
|
} |
1105
|
|
|
|
1106
|
|
|
return array('url' => null, 'name' => null, 'icon' => null, 'mimetype_description' => null); |
1107
|
|
|
} |
1108
|
|
|
$fs = get_file_storage(); |
1109
|
|
|
$files = $fs->get_area_files( |
1110
|
|
|
$context->id, |
1111
|
|
|
'mod_bigbluebuttonbn', |
1112
|
|
|
'presentation', |
1113
|
|
|
0, |
1114
|
|
|
'itemid, filepath, filename', |
1115
|
|
|
false |
1116
|
|
|
); |
1117
|
|
View Code Duplication |
if (count($files) == 0) { |
|
|
|
|
1118
|
|
|
return array('url' => null, 'name' => null, 'icon' => null, 'mimetype_description' => null); |
1119
|
|
|
} |
1120
|
|
|
$file = reset($files); |
1121
|
|
|
unset($files); |
1122
|
|
|
$pnoncevalue = null; |
1123
|
|
View Code Duplication |
if (!is_null($id)) { |
|
|
|
|
1124
|
|
|
// Create the nonce component for granting a temporary public access. |
1125
|
|
|
$cache = cache::make_from_params( |
1126
|
|
|
cache_store::MODE_APPLICATION, |
1127
|
|
|
'mod_bigbluebuttonbn', |
1128
|
|
|
'presentation_cache' |
1129
|
|
|
); |
1130
|
|
|
$pnoncekey = sha1($id); |
1131
|
|
|
/* The item id was adapted for granting public access to the presentation once in order |
1132
|
|
|
* to allow BigBlueButton to gather the file. */ |
1133
|
|
|
$pnoncevalue = bigbluebuttonbn_generate_nonce(); |
1134
|
|
|
$cache->set($pnoncekey, array('value' => $pnoncevalue, 'counter' => 0)); |
1135
|
|
|
} |
1136
|
|
|
$url = moodle_url::make_pluginfile_url( |
1137
|
|
|
$file->get_contextid(), |
1138
|
|
|
$file->get_component(), |
1139
|
|
|
$file->get_filearea(), |
1140
|
|
|
$pnoncevalue, |
1141
|
|
|
$file->get_filepath(), |
1142
|
|
|
$file->get_filename() |
1143
|
|
|
); |
1144
|
|
|
return array('name' => $file->get_filename(), 'icon' => file_file_icon($file, 24), |
1145
|
|
|
'url' => $url->out(false), 'mimetype_description' => get_mimetype_description($file)); |
1146
|
|
|
} |
1147
|
|
|
|
1148
|
|
|
/** |
1149
|
|
|
* Helper generates a nonce used for the preuploaded presentation callback url. |
1150
|
|
|
* |
1151
|
|
|
* @return string |
1152
|
|
|
*/ |
1153
|
|
|
function bigbluebuttonbn_generate_nonce() { |
1154
|
|
|
$mt = microtime(); |
1155
|
|
|
$rand = mt_rand(); |
1156
|
|
|
return md5($mt . $rand); |
1157
|
|
|
} |
1158
|
|
|
|
1159
|
|
|
/** |
1160
|
|
|
* Helper generates a random password. |
1161
|
|
|
* |
1162
|
|
|
* @param integer $length |
1163
|
|
|
* @param string $unique |
1164
|
|
|
* |
1165
|
|
|
* @return string |
1166
|
|
|
*/ |
1167
|
|
|
function bigbluebuttonbn_random_password($length = 8, $unique = "") { |
1168
|
|
|
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; |
1169
|
|
|
do { |
1170
|
|
|
$password = substr(str_shuffle($chars), 0, $length); |
1171
|
|
|
} while ($unique == $password); |
1172
|
|
|
return $password; |
1173
|
|
|
} |
1174
|
|
|
|
1175
|
|
|
/** |
1176
|
|
|
* Helper register a bigbluebuttonbn event. |
1177
|
|
|
* |
1178
|
|
|
* @param string $type |
1179
|
|
|
* @param object $bigbluebuttonbn |
1180
|
|
|
* @param array $options [timecreated, userid, other] |
1181
|
|
|
* |
1182
|
|
|
* @return void |
1183
|
|
|
*/ |
1184
|
|
|
function bigbluebuttonbn_event_log($type, $bigbluebuttonbn, $options = []) { |
1185
|
|
|
global $DB; |
1186
|
|
|
if (!in_array($type, \mod_bigbluebuttonbn\event\events::$events)) { |
1187
|
|
|
// No log will be created. |
1188
|
|
|
return; |
1189
|
|
|
} |
1190
|
|
|
$course = $DB->get_record('course', array('id' => $bigbluebuttonbn->course), '*', MUST_EXIST); |
1191
|
|
|
$cm = get_coursemodule_from_instance('bigbluebuttonbn', $bigbluebuttonbn->id, $course->id, false, MUST_EXIST); |
1192
|
|
|
$context = context_module::instance($cm->id); |
1193
|
|
|
$params = array('context' => $context, 'objectid' => $bigbluebuttonbn->id); |
1194
|
|
|
if (array_key_exists('timecreated', $options)) { |
1195
|
|
|
$params['timecreated'] = $options['timecreated']; |
1196
|
|
|
} |
1197
|
|
|
if (array_key_exists('userid', $options)) { |
1198
|
|
|
$params['userid'] = $options['userid']; |
1199
|
|
|
} |
1200
|
|
|
if (array_key_exists('other', $options)) { |
1201
|
|
|
$params['other'] = $options['other']; |
1202
|
|
|
} |
1203
|
|
|
$event = call_user_func_array( |
1204
|
|
|
'\mod_bigbluebuttonbn\event\\' . $type . '::create', |
1205
|
|
|
array($params) |
1206
|
|
|
); |
1207
|
|
|
$event->add_record_snapshot('course_modules', $cm); |
1208
|
|
|
$event->add_record_snapshot('course', $course); |
1209
|
|
|
$event->add_record_snapshot('bigbluebuttonbn', $bigbluebuttonbn); |
1210
|
|
|
$event->trigger(); |
1211
|
|
|
} |
1212
|
|
|
|
1213
|
|
|
/** |
1214
|
|
|
* Updates the meeting info cached object when a participant has joined. |
1215
|
|
|
* |
1216
|
|
|
* @param string $meetingid |
1217
|
|
|
* @param bool $ismoderator |
1218
|
|
|
* |
1219
|
|
|
* @return void |
1220
|
|
|
*/ |
1221
|
|
|
function bigbluebuttonbn_participant_joined($meetingid, $ismoderator) { |
1222
|
|
|
$cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'meetings_cache'); |
1223
|
|
|
$result = $cache->get($meetingid); |
1224
|
|
|
$meetinginfo = json_decode($result['meeting_info']); |
1225
|
|
|
$meetinginfo->participantCount += 1; |
1226
|
|
|
if ($ismoderator) { |
1227
|
|
|
$meetinginfo->moderatorCount += 1; |
1228
|
|
|
} |
1229
|
|
|
$cache->set($meetingid, array('creation_time' => $result['creation_time'], |
1230
|
|
|
'meeting_info' => json_encode($meetinginfo))); |
1231
|
|
|
} |
1232
|
|
|
|
1233
|
|
|
/** |
1234
|
|
|
* Gets a meeting info object cached or fetched from the live session. |
1235
|
|
|
* |
1236
|
|
|
* @param string $meetingid |
1237
|
|
|
* @param boolean $updatecache |
1238
|
|
|
* |
1239
|
|
|
* @return array |
1240
|
|
|
*/ |
1241
|
|
|
function bigbluebuttonbn_get_meeting_info($meetingid, $updatecache = false) { |
1242
|
|
|
$cachettl = (int) \mod_bigbluebuttonbn\locallib\config::get('waitformoderator_cache_ttl'); |
1243
|
|
|
$cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'meetings_cache'); |
1244
|
|
|
$result = $cache->get($meetingid); |
1245
|
|
|
$now = time(); |
1246
|
|
|
if (!$updatecache && !empty($result) && $now < ($result['creation_time'] + $cachettl)) { |
1247
|
|
|
// Use the value in the cache. |
1248
|
|
|
return (array) json_decode($result['meeting_info']); |
1249
|
|
|
} |
1250
|
|
|
// Ping again and refresh the cache. |
1251
|
|
|
$meetinginfo = (array) bigbluebuttonbn_wrap_xml_load_file( |
1252
|
|
|
\mod_bigbluebuttonbn\locallib\bigbluebutton::action_url('getMeetingInfo', ['meetingID' => $meetingid]) |
1253
|
|
|
); |
1254
|
|
|
$cache->set($meetingid, array('creation_time' => time(), 'meeting_info' => json_encode($meetinginfo))); |
1255
|
|
|
return $meetinginfo; |
1256
|
|
|
} |
1257
|
|
|
|
1258
|
|
|
/** |
1259
|
|
|
* Perform isMeetingRunning on BBB. |
1260
|
|
|
* |
1261
|
|
|
* @param string $meetingid |
1262
|
|
|
* @param boolean $updatecache |
1263
|
|
|
* |
1264
|
|
|
* @return boolean |
1265
|
|
|
*/ |
1266
|
|
|
function bigbluebuttonbn_is_meeting_running($meetingid, $updatecache = false) { |
1267
|
|
|
/* As a workaround to isMeetingRunning that always return SUCCESS but only returns true |
1268
|
|
|
* when at least one user is in the session, we use getMeetingInfo instead. |
1269
|
|
|
*/ |
1270
|
|
|
$meetinginfo = bigbluebuttonbn_get_meeting_info($meetingid, $updatecache); |
1271
|
|
|
return ($meetinginfo['returncode'] === 'SUCCESS'); |
1272
|
|
|
} |
1273
|
|
|
|
1274
|
|
|
/** |
1275
|
|
|
* Publish an imported recording. |
1276
|
|
|
* |
1277
|
|
|
* @param string $id |
1278
|
|
|
* @param boolean $publish |
1279
|
|
|
* |
1280
|
|
|
* @return boolean |
1281
|
|
|
*/ |
1282
|
|
View Code Duplication |
function bigbluebuttonbn_publish_recording_imported($id, $publish = true) { |
|
|
|
|
1283
|
|
|
global $DB; |
1284
|
|
|
// Locate the record to be updated. |
1285
|
|
|
$record = $DB->get_record('bigbluebuttonbn_logs', array('id' => $id)); |
1286
|
|
|
$meta = json_decode($record->meta, true); |
1287
|
|
|
// Prepare data for the update. |
1288
|
|
|
$meta['recording']['published'] = ($publish) ? 'true' : 'false'; |
1289
|
|
|
$record->meta = json_encode($meta); |
1290
|
|
|
// Proceed with the update. |
1291
|
|
|
$DB->update_record('bigbluebuttonbn_logs', $record); |
1292
|
|
|
return true; |
1293
|
|
|
} |
1294
|
|
|
|
1295
|
|
|
/** |
1296
|
|
|
* Delete an imported recording. |
1297
|
|
|
* |
1298
|
|
|
* @param string $id |
1299
|
|
|
* |
1300
|
|
|
* @return boolean |
1301
|
|
|
*/ |
1302
|
|
|
function bigbluebuttonbn_delete_recording_imported($id) { |
1303
|
|
|
global $DB; |
1304
|
|
|
// Execute delete. |
1305
|
|
|
$DB->delete_records('bigbluebuttonbn_logs', array('id' => $id)); |
1306
|
|
|
return true; |
1307
|
|
|
} |
1308
|
|
|
|
1309
|
|
|
/** |
1310
|
|
|
* Update an imported recording. |
1311
|
|
|
* |
1312
|
|
|
* @param string $id |
1313
|
|
|
* @param array $params ['key'=>param_key, 'value'] |
1314
|
|
|
* |
1315
|
|
|
* @return boolean |
1316
|
|
|
*/ |
1317
|
|
|
function bigbluebuttonbn_update_recording_imported($id, $params) { |
1318
|
|
|
global $DB; |
1319
|
|
|
// Locate the record to be updated. |
1320
|
|
|
$record = $DB->get_record('bigbluebuttonbn_logs', array('id' => $id)); |
1321
|
|
|
$meta = json_decode($record->meta, true); |
1322
|
|
|
// Prepare data for the update. |
1323
|
|
|
$meta['recording'] = $params + $meta['recording']; |
1324
|
|
|
$record->meta = json_encode($meta); |
1325
|
|
|
// Proceed with the update. |
1326
|
|
|
if (!$DB->update_record('bigbluebuttonbn_logs', $record)) { |
1327
|
|
|
return false; |
1328
|
|
|
} |
1329
|
|
|
return true; |
1330
|
|
|
} |
1331
|
|
|
|
1332
|
|
|
/** |
1333
|
|
|
* Protect/Unprotect an imported recording. |
1334
|
|
|
* |
1335
|
|
|
* @param string $id |
1336
|
|
|
* @param boolean $protect |
1337
|
|
|
* |
1338
|
|
|
* @return boolean |
1339
|
|
|
*/ |
1340
|
|
View Code Duplication |
function bigbluebuttonbn_protect_recording_imported($id, $protect = true) { |
|
|
|
|
1341
|
|
|
global $DB; |
1342
|
|
|
// Locate the record to be updated. |
1343
|
|
|
$record = $DB->get_record('bigbluebuttonbn_logs', array('id' => $id)); |
1344
|
|
|
$meta = json_decode($record->meta, true); |
1345
|
|
|
// Prepare data for the update. |
1346
|
|
|
$meta['recording']['protected'] = ($protect) ? 'true' : 'false'; |
1347
|
|
|
$record->meta = json_encode($meta); |
1348
|
|
|
// Proceed with the update. |
1349
|
|
|
$DB->update_record('bigbluebuttonbn_logs', $record); |
1350
|
|
|
return true; |
1351
|
|
|
} |
1352
|
|
|
|
1353
|
|
|
/** |
1354
|
|
|
* Sets a custom config.xml file for being used on create. |
1355
|
|
|
* |
1356
|
|
|
* @param string $meetingid |
1357
|
|
|
* @param string $configxml |
1358
|
|
|
* |
1359
|
|
|
* @return object |
1360
|
|
|
*/ |
1361
|
|
|
function bigbluebuttonbn_set_config_xml($meetingid, $configxml) { |
1362
|
|
|
$urldefaultconfig = \mod_bigbluebuttonbn\locallib\config::get('server_url') . 'api/setConfigXML?'; |
1363
|
|
|
$configxmlparams = bigbluebuttonbn_set_config_xml_params($meetingid, $configxml); |
1364
|
|
|
$xml = bigbluebuttonbn_wrap_xml_load_file( |
1365
|
|
|
$urldefaultconfig, |
1366
|
|
|
'POST', |
1367
|
|
|
$configxmlparams, |
1368
|
|
|
'application/x-www-form-urlencoded' |
1369
|
|
|
); |
1370
|
|
|
return $xml; |
1371
|
|
|
} |
1372
|
|
|
|
1373
|
|
|
/** |
1374
|
|
|
* Sets qs used with a custom config.xml file request. |
1375
|
|
|
* |
1376
|
|
|
* @param string $meetingid |
1377
|
|
|
* @param string $configxml |
1378
|
|
|
* |
1379
|
|
|
* @return string |
1380
|
|
|
*/ |
1381
|
|
|
function bigbluebuttonbn_set_config_xml_params($meetingid, $configxml) { |
1382
|
|
|
$params = 'configXML=' . urlencode($configxml) . '&meetingID=' . urlencode($meetingid); |
1383
|
|
|
$sharedsecret = \mod_bigbluebuttonbn\locallib\config::get('shared_secret'); |
1384
|
|
|
$configxmlparams = $params . '&checksum=' . sha1('setConfigXML' . $params . $sharedsecret); |
1385
|
|
|
return $configxmlparams; |
1386
|
|
|
} |
1387
|
|
|
|
1388
|
|
|
/** |
1389
|
|
|
* Sets a custom config.xml file for being used on create. |
1390
|
|
|
* |
1391
|
|
|
* @param string $meetingid |
1392
|
|
|
* @param string $configxml |
1393
|
|
|
* |
1394
|
|
|
* @return array |
1395
|
|
|
*/ |
1396
|
|
|
function bigbluebuttonbn_set_config_xml_array($meetingid, $configxml) { |
1397
|
|
|
$configxml = bigbluebuttonbn_set_config_xml($meetingid, $configxml); |
1398
|
|
|
$configxmlarray = (array) $configxml; |
1399
|
|
|
if ($configxmlarray['returncode'] != 'SUCCESS') { |
1400
|
|
|
debugging('BigBlueButton was not able to set the custom config.xml file', DEBUG_DEVELOPER); |
1401
|
|
|
return ''; |
1402
|
|
|
} |
1403
|
|
|
return $configxmlarray['configToken']; |
1404
|
|
|
} |
1405
|
|
|
|
1406
|
|
|
/** |
1407
|
|
|
* Helper function builds a row for the data used by the recording table. |
1408
|
|
|
* |
1409
|
|
|
* @param array $bbbsession |
1410
|
|
|
* @param array $recording |
1411
|
|
|
* @param array $tools |
1412
|
|
|
* |
1413
|
|
|
* @return array |
1414
|
|
|
*/ |
1415
|
|
|
function bigbluebuttonbn_get_recording_data_row($bbbsession, $recording, $tools = ['protect', 'publish', 'delete']) { |
1416
|
|
|
if (!bigbluebuttonbn_include_recording_table_row($bbbsession, $recording)) { |
1417
|
|
|
return; |
1418
|
|
|
} |
1419
|
|
|
$rowdata = new stdClass(); |
1420
|
|
|
// Set recording_types. |
1421
|
|
|
$rowdata->playback = bigbluebuttonbn_get_recording_data_row_types($recording, $bbbsession); |
1422
|
|
|
// Set activity name. |
1423
|
|
|
$rowdata->recording = bigbluebuttonbn_get_recording_data_row_meta_activity($recording, $bbbsession); |
1424
|
|
|
// Set activity description. |
1425
|
|
|
$rowdata->description = bigbluebuttonbn_get_recording_data_row_meta_description($recording, $bbbsession); |
1426
|
|
|
if (bigbluebuttonbn_get_recording_data_preview_enabled($bbbsession)) { |
1427
|
|
|
// Set recording_preview. |
1428
|
|
|
$rowdata->preview = bigbluebuttonbn_get_recording_data_row_preview($recording); |
1429
|
|
|
} |
1430
|
|
|
// Set date. |
1431
|
|
|
$rowdata->date = bigbluebuttonbn_get_recording_data_row_date($recording); |
1432
|
|
|
// Set formatted date. |
1433
|
|
|
$rowdata->date_formatted = bigbluebuttonbn_get_recording_data_row_date_formatted($rowdata->date); |
1434
|
|
|
// Set formatted duration. |
1435
|
|
|
$rowdata->duration_formatted = $rowdata->duration = bigbluebuttonbn_get_recording_data_row_duration($recording); |
1436
|
|
|
// Set actionbar, if user is allowed to manage recordings. |
1437
|
|
|
if ($bbbsession['managerecordings']) { |
1438
|
|
|
$rowdata->actionbar = bigbluebuttonbn_get_recording_data_row_actionbar($recording, $tools); |
1439
|
|
|
} |
1440
|
|
|
return $rowdata; |
1441
|
|
|
} |
1442
|
|
|
|
1443
|
|
|
/** |
1444
|
|
|
* Helper function evaluates if a row for the data used by the recording table is editable. |
1445
|
|
|
* |
1446
|
|
|
* @param array $bbbsession |
1447
|
|
|
* |
1448
|
|
|
* @return boolean |
1449
|
|
|
*/ |
1450
|
|
|
function bigbluebuttonbn_get_recording_data_row_editable($bbbsession) { |
1451
|
|
|
return ($bbbsession['managerecordings'] && ((double) $bbbsession['serverversion'] >= 1.0 || $bbbsession['bnserver'])); |
1452
|
|
|
} |
1453
|
|
|
|
1454
|
|
|
/** |
1455
|
|
|
* Helper function evaluates if recording preview should be included. |
1456
|
|
|
* |
1457
|
|
|
* @param array $bbbsession |
1458
|
|
|
* |
1459
|
|
|
* @return boolean |
1460
|
|
|
*/ |
1461
|
|
|
function bigbluebuttonbn_get_recording_data_preview_enabled($bbbsession) { |
1462
|
|
|
return ((double) $bbbsession['serverversion'] >= 1.0 && $bbbsession['bigbluebuttonbn']->recordings_preview == '1'); |
1463
|
|
|
} |
1464
|
|
|
|
1465
|
|
|
/** |
1466
|
|
|
* Helper function converts recording date used in row for the data used by the recording table. |
1467
|
|
|
* |
1468
|
|
|
* @param array $recording |
1469
|
|
|
* |
1470
|
|
|
* @return integer |
1471
|
|
|
*/ |
1472
|
|
|
function bigbluebuttonbn_get_recording_data_row_date($recording) { |
1473
|
|
|
if (!isset($recording['startTime'])) { |
1474
|
|
|
return 0; |
1475
|
|
|
} |
1476
|
|
|
return floatval($recording['startTime']); |
1477
|
|
|
} |
1478
|
|
|
|
1479
|
|
|
/** |
1480
|
|
|
* Helper function format recording date used in row for the data used by the recording table. |
1481
|
|
|
* |
1482
|
|
|
* @param integer $starttime |
1483
|
|
|
* |
1484
|
|
|
* @return string |
1485
|
|
|
*/ |
1486
|
|
|
function bigbluebuttonbn_get_recording_data_row_date_formatted($starttime) { |
1487
|
|
|
global $USER; |
1488
|
|
|
$starttime = $starttime - ($starttime % 1000); |
1489
|
|
|
// Set formatted date. |
1490
|
|
|
$dateformat = get_string('strftimerecentfull', 'langconfig') . ' %Z'; |
1491
|
|
|
return userdate($starttime / 1000, $dateformat, usertimezone($USER->timezone)); |
1492
|
|
|
} |
1493
|
|
|
|
1494
|
|
|
/** |
1495
|
|
|
* Helper function converts recording duration used in row for the data used by the recording table. |
1496
|
|
|
* |
1497
|
|
|
* @param array $recording |
1498
|
|
|
* |
1499
|
|
|
* @return integer |
1500
|
|
|
*/ |
1501
|
|
|
function bigbluebuttonbn_get_recording_data_row_duration($recording) { |
1502
|
|
|
foreach (array_values($recording['playbacks']) as $playback) { |
1503
|
|
|
// Ignore restricted playbacks. |
1504
|
|
|
if (array_key_exists('restricted', $playback) && strtolower($playback['restricted']) == 'true') { |
1505
|
|
|
continue; |
1506
|
|
|
} |
1507
|
|
|
// Take the lenght form the fist playback with an actual value. |
1508
|
|
|
if (!empty($playback['length'])) { |
1509
|
|
|
return intval($playback['length']); |
1510
|
|
|
} |
1511
|
|
|
} |
1512
|
|
|
return 0; |
1513
|
|
|
} |
1514
|
|
|
|
1515
|
|
|
/** |
1516
|
|
|
* Helper function builds recording actionbar used in row for the data used by the recording table. |
1517
|
|
|
* |
1518
|
|
|
* @param array $recording |
1519
|
|
|
* @param array $tools |
1520
|
|
|
* |
1521
|
|
|
* @return string |
1522
|
|
|
*/ |
1523
|
|
|
function bigbluebuttonbn_get_recording_data_row_actionbar($recording, $tools) { |
1524
|
|
|
$actionbar = ''; |
1525
|
|
|
foreach ($tools as $tool) { |
1526
|
|
|
$buttonpayload = bigbluebuttonbn_get_recording_data_row_actionbar_payload($recording, $tool); |
1527
|
|
|
if ($tool == 'protect') { |
1528
|
|
|
if (isset($recording['imported'])) { |
1529
|
|
|
$buttonpayload['disabled'] = 'disabled'; |
1530
|
|
|
} |
1531
|
|
|
if (!isset($recording['protected'])) { |
1532
|
|
|
$buttonpayload['disabled'] = 'invisible'; |
1533
|
|
|
} |
1534
|
|
|
} |
1535
|
|
|
$actionbar .= bigbluebuttonbn_actionbar_render_button($recording, $buttonpayload); |
1536
|
|
|
} |
1537
|
|
|
$head = html_writer::start_tag('div', array( |
1538
|
|
|
'id' => 'recording-actionbar-' . $recording['recordID'], |
1539
|
|
|
'data-recordingid' => $recording['recordID'], |
1540
|
|
|
'data-meetingid' => $recording['meetingID'])); |
1541
|
|
|
$tail = html_writer::end_tag('div'); |
1542
|
|
|
return $head . $actionbar . $tail; |
1543
|
|
|
} |
1544
|
|
|
|
1545
|
|
|
/** |
1546
|
|
|
* Helper function returns the corresponding payload for an actionbar button used in row |
1547
|
|
|
* for the data used by the recording table. |
1548
|
|
|
* |
1549
|
|
|
* @param array $recording |
1550
|
|
|
* @param array $tool |
1551
|
|
|
* |
1552
|
|
|
* @return array |
1553
|
|
|
*/ |
1554
|
|
|
function bigbluebuttonbn_get_recording_data_row_actionbar_payload($recording, $tool) { |
1555
|
|
|
if ($tool == 'protect') { |
1556
|
|
|
$protected = 'false'; |
1557
|
|
|
if (isset($recording['protected'])) { |
1558
|
|
|
$protected = $recording['protected']; |
1559
|
|
|
} |
1560
|
|
|
return bigbluebuttonbn_get_recording_data_row_action_protect($protected); |
1561
|
|
|
} |
1562
|
|
|
if ($tool == 'publish') { |
1563
|
|
|
return bigbluebuttonbn_get_recording_data_row_action_publish($recording['published']); |
1564
|
|
|
} |
1565
|
|
|
return array('action' => $tool, 'tag' => $tool); |
1566
|
|
|
} |
1567
|
|
|
|
1568
|
|
|
/** |
1569
|
|
|
* Helper function returns the payload for protect action button used in row |
1570
|
|
|
* for the data used by the recording table. |
1571
|
|
|
* |
1572
|
|
|
* @param string $protected |
1573
|
|
|
* |
1574
|
|
|
* @return array |
1575
|
|
|
*/ |
1576
|
|
|
function bigbluebuttonbn_get_recording_data_row_action_protect($protected) { |
1577
|
|
|
if ($protected == 'true') { |
1578
|
|
|
return array('action' => 'unprotect', 'tag' => 'lock'); |
1579
|
|
|
} |
1580
|
|
|
return array('action' => 'protect', 'tag' => 'unlock'); |
1581
|
|
|
} |
1582
|
|
|
|
1583
|
|
|
/** |
1584
|
|
|
* Helper function returns the payload for publish action button used in row |
1585
|
|
|
* for the data used by the recording table. |
1586
|
|
|
* |
1587
|
|
|
* @param string $published |
1588
|
|
|
* |
1589
|
|
|
* @return array |
1590
|
|
|
*/ |
1591
|
|
|
function bigbluebuttonbn_get_recording_data_row_action_publish($published) { |
1592
|
|
|
if ($published == 'true') { |
1593
|
|
|
return array('action' => 'unpublish', 'tag' => 'hide'); |
1594
|
|
|
} |
1595
|
|
|
return array('action' => 'publish', 'tag' => 'show'); |
1596
|
|
|
} |
1597
|
|
|
|
1598
|
|
|
/** |
1599
|
|
|
* Helper function builds recording preview used in row for the data used by the recording table. |
1600
|
|
|
* |
1601
|
|
|
* @param array $recording |
1602
|
|
|
* |
1603
|
|
|
* @return string |
1604
|
|
|
*/ |
1605
|
|
|
function bigbluebuttonbn_get_recording_data_row_preview($recording) { |
1606
|
|
|
$options = array('id' => 'preview-' . $recording['recordID']); |
1607
|
|
|
if ($recording['published'] === 'false') { |
1608
|
|
|
$options['hidden'] = 'hidden'; |
1609
|
|
|
} |
1610
|
|
|
$recordingpreview = html_writer::start_tag('div', $options); |
1611
|
|
|
foreach ($recording['playbacks'] as $playback) { |
1612
|
|
|
if (isset($playback['preview'])) { |
1613
|
|
|
$recordingpreview .= bigbluebuttonbn_get_recording_data_row_preview_images($playback); |
1614
|
|
|
break; |
1615
|
|
|
} |
1616
|
|
|
} |
1617
|
|
|
$recordingpreview .= html_writer::end_tag('div'); |
1618
|
|
|
return $recordingpreview; |
1619
|
|
|
} |
1620
|
|
|
|
1621
|
|
|
/** |
1622
|
|
|
* Helper function builds element with actual images used in recording preview row based on a selected playback. |
1623
|
|
|
* |
1624
|
|
|
* @param array $playback |
1625
|
|
|
* |
1626
|
|
|
* @return string |
1627
|
|
|
*/ |
1628
|
|
|
function bigbluebuttonbn_get_recording_data_row_preview_images($playback) { |
1629
|
|
|
global $CFG; |
1630
|
|
|
$recordingpreview = html_writer::start_tag('div', array('class' => 'container-fluid')); |
1631
|
|
|
$recordingpreview .= html_writer::start_tag('div', array('class' => 'row')); |
1632
|
|
|
foreach ($playback['preview'] as $image) { |
1633
|
|
|
if ($CFG->bigbluebuttonbn_recordings_validate_url && !bigbluebuttonbn_is_valid_resource(trim($image['url']))) { |
1634
|
|
|
return ''; |
1635
|
|
|
} |
1636
|
|
|
$recordingpreview .= html_writer::start_tag('div', array('class' => '')); |
1637
|
|
|
$recordingpreview .= html_writer::empty_tag( |
1638
|
|
|
'img', |
1639
|
|
|
array('src' => trim($image['url']) . '?' . time(), 'class' => 'recording-thumbnail pull-left') |
1640
|
|
|
); |
1641
|
|
|
$recordingpreview .= html_writer::end_tag('div'); |
1642
|
|
|
} |
1643
|
|
|
$recordingpreview .= html_writer::end_tag('div'); |
1644
|
|
|
$recordingpreview .= html_writer::start_tag('div', array('class' => 'row')); |
1645
|
|
|
$recordingpreview .= html_writer::tag( |
1646
|
|
|
'div', |
1647
|
|
|
get_string('view_recording_preview_help', 'bigbluebuttonbn'), |
1648
|
|
|
array('class' => 'text-center text-muted small') |
1649
|
|
|
); |
1650
|
|
|
$recordingpreview .= html_writer::end_tag('div'); |
1651
|
|
|
$recordingpreview .= html_writer::end_tag('div'); |
1652
|
|
|
return $recordingpreview; |
1653
|
|
|
} |
1654
|
|
|
|
1655
|
|
|
/** |
1656
|
|
|
* Helper function renders recording types to be used in row for the data used by the recording table. |
1657
|
|
|
* |
1658
|
|
|
* @param array $recording |
1659
|
|
|
* @param array $bbbsession |
1660
|
|
|
* |
1661
|
|
|
* @return string |
1662
|
|
|
*/ |
1663
|
|
|
function bigbluebuttonbn_get_recording_data_row_types($recording, $bbbsession) { |
1664
|
|
|
$dataimported = 'false'; |
1665
|
|
|
$title = ''; |
1666
|
|
|
if (isset($recording['imported'])) { |
1667
|
|
|
$dataimported = 'true'; |
1668
|
|
|
$title = get_string('view_recording_link_warning', 'bigbluebuttonbn'); |
1669
|
|
|
} |
1670
|
|
|
$visibility = ''; |
1671
|
|
|
if ($recording['published'] === 'false') { |
1672
|
|
|
$visibility = 'hidden '; |
1673
|
|
|
} |
1674
|
|
|
$id = 'playbacks-' . $recording['recordID']; |
1675
|
|
|
$recordingtypes = html_writer::start_tag('div', array('id' => $id, 'data-imported' => $dataimported, |
1676
|
|
|
'data-meetingid' => $recording['meetingID'], 'data-recordingid' => $recording['recordID'], |
1677
|
|
|
'title' => $title, $visibility => $visibility)); |
1678
|
|
|
foreach ($recording['playbacks'] as $playback) { |
1679
|
|
|
$recordingtypes .= bigbluebuttonbn_get_recording_data_row_type($recording, $bbbsession, $playback); |
1680
|
|
|
} |
1681
|
|
|
$recordingtypes .= html_writer::end_tag('div'); |
1682
|
|
|
return $recordingtypes; |
1683
|
|
|
} |
1684
|
|
|
|
1685
|
|
|
/** |
1686
|
|
|
* Helper function renders the link used for recording type in row for the data used by the recording table. |
1687
|
|
|
* |
1688
|
|
|
* @param array $recording |
1689
|
|
|
* @param array $bbbsession |
1690
|
|
|
* @param array $playback |
1691
|
|
|
* |
1692
|
|
|
* @return string |
1693
|
|
|
*/ |
1694
|
|
|
function bigbluebuttonbn_get_recording_data_row_type($recording, $bbbsession, $playback) { |
1695
|
|
|
global $CFG, $OUTPUT; |
1696
|
|
|
if (!bigbluebuttonbn_include_recording_data_row_type($recording, $bbbsession, $playback)) { |
1697
|
|
|
return ''; |
1698
|
|
|
} |
1699
|
|
|
$text = bigbluebuttonbn_get_recording_type_text($playback['type']); |
1700
|
|
|
$href = $CFG->wwwroot . '/mod/bigbluebuttonbn/bbb_view.php?action=play&bn=' . $bbbsession['bigbluebuttonbn']->id . |
1701
|
|
|
'&mid=' . $recording['meetingID'] . '&rid=' . $recording['recordID'] . '&rtype=' . $playback['type']; |
1702
|
|
|
if (!isset($recording['imported']) || !isset($recording['protected']) || $recording['protected'] === 'false') { |
1703
|
|
|
$href .= '&href=' . urlencode(trim($playback['url'])); |
1704
|
|
|
} |
1705
|
|
|
$linkattributes = array( |
1706
|
|
|
'id' => 'recording-play-' . $playback['type'] . '-' . $recording['recordID'], |
1707
|
|
|
'class' => 'btn btn-sm btn-default', |
1708
|
|
|
'onclick' => 'M.mod_bigbluebuttonbn.recordings.recordingPlay(this);', |
1709
|
|
|
'data-action' => 'play', |
1710
|
|
|
'data-target' => $playback['type'], |
1711
|
|
|
'data-href' => $href, |
1712
|
|
|
); |
1713
|
|
|
if ($CFG->bigbluebuttonbn_recordings_validate_url && !bigbluebuttonbn_is_bn_server() |
1714
|
|
|
&& !bigbluebuttonbn_is_valid_resource(trim($playback['url']))) { |
1715
|
|
|
$linkattributes['class'] = 'btn btn-sm btn-warning'; |
1716
|
|
|
$linkattributes['title'] = get_string('view_recording_format_errror_unreachable', 'bigbluebuttonbn'); |
1717
|
|
|
unset($linkattributes['data-href']); |
1718
|
|
|
} |
1719
|
|
|
return $OUTPUT->action_link('#', $text, null, $linkattributes) . ' '; |
1720
|
|
|
} |
1721
|
|
|
|
1722
|
|
|
/** |
1723
|
|
|
* Helper function to handle yet unknown recording types |
1724
|
|
|
* |
1725
|
|
|
* @param string $playbacktype : for now presentation, video, statistics, capture, notes, podcast |
1726
|
|
|
* |
1727
|
|
|
* @return string the matching language string or a capitalised version of the provided string |
1728
|
|
|
*/ |
1729
|
|
|
function bigbluebuttonbn_get_recording_type_text($playbacktype) { |
1730
|
|
|
// Check first if string exists, and if it does'nt just default to the capitalised version of the string. |
1731
|
|
|
$text = ucwords($playbacktype); |
1732
|
|
|
$typestringid = 'view_recording_format_' . $playbacktype; |
1733
|
|
|
if (get_string_manager()->string_exists($typestringid, 'bigbluebuttonbn')) { |
1734
|
|
|
$text = get_string($typestringid, 'bigbluebuttonbn'); |
1735
|
|
|
} |
1736
|
|
|
return $text; |
1737
|
|
|
} |
1738
|
|
|
|
1739
|
|
|
/** |
1740
|
|
|
* Helper function validates a remote resource. |
1741
|
|
|
* |
1742
|
|
|
* @param string $url |
1743
|
|
|
* |
1744
|
|
|
* @return boolean |
1745
|
|
|
*/ |
1746
|
|
|
function bigbluebuttonbn_is_valid_resource($url) { |
1747
|
|
|
$urlhost = parse_url($url, PHP_URL_HOST); |
1748
|
|
|
$serverurlhost = parse_url(\mod_bigbluebuttonbn\locallib\config::get('server_url'), PHP_URL_HOST); |
1749
|
|
|
// Skip validation when the recording URL host is the same as the configured BBB server. |
1750
|
|
|
if ($urlhost == $serverurlhost) { |
1751
|
|
|
return true; |
1752
|
|
|
} |
1753
|
|
|
// Skip validation when the recording URL was already validated. |
1754
|
|
|
$validatedurls = bigbluebuttonbn_cache_get('recordings_cache', 'validated_urls', array()); |
|
|
|
|
1755
|
|
|
if (array_key_exists($urlhost, $validatedurls)) { |
1756
|
|
|
return $validatedurls[$urlhost]; |
1757
|
|
|
} |
1758
|
|
|
// Validate the recording URL. |
1759
|
|
|
$validatedurls[$urlhost] = true; |
1760
|
|
|
$curlinfo = bigbluebuttonbn_wrap_xml_load_file_curl_request($url, 'HEAD'); |
1761
|
|
|
if (!isset($curlinfo['http_code']) || $curlinfo['http_code'] != 200) { |
1762
|
|
|
$error = "Resources hosted by " . $urlhost . " are unreachable. Server responded with code " . $curlinfo['http_code']; |
1763
|
|
|
debugging($error, DEBUG_DEVELOPER); |
1764
|
|
|
$validatedurls[$urlhost] = false; |
1765
|
|
|
} |
1766
|
|
|
bigbluebuttonbn_cache_set('recordings_cache', 'validated_urls', $validatedurls); |
1767
|
|
|
return $validatedurls[$urlhost]; |
1768
|
|
|
} |
1769
|
|
|
|
1770
|
|
|
/** |
1771
|
|
|
* Helper function renders the name for meeting used in row for the data used by the recording table. |
1772
|
|
|
* |
1773
|
|
|
* @param array $recording |
1774
|
|
|
* @param array $bbbsession |
1775
|
|
|
* |
1776
|
|
|
* @return string |
1777
|
|
|
*/ |
1778
|
|
|
function bigbluebuttonbn_get_recording_data_row_meeting($recording, $bbbsession) { |
|
|
|
|
1779
|
|
|
$payload = array(); |
1780
|
|
|
$source = 'meetingName'; |
1781
|
|
|
$metaname = trim($recording['meetingName']); |
1782
|
|
|
return bigbluebuttonbn_get_recording_data_row_text($recording, $metaname, $source, $payload); |
1783
|
|
|
} |
1784
|
|
|
|
1785
|
|
|
/** |
1786
|
|
|
* Helper function renders the name for recording used in row for the data used by the recording table. |
1787
|
|
|
* |
1788
|
|
|
* @param array $recording |
1789
|
|
|
* @param array $bbbsession |
1790
|
|
|
* |
1791
|
|
|
* @return string |
1792
|
|
|
*/ |
1793
|
|
|
function bigbluebuttonbn_get_recording_data_row_meta_activity($recording, $bbbsession) { |
1794
|
|
|
$payload = array(); |
1795
|
|
View Code Duplication |
if (bigbluebuttonbn_get_recording_data_row_editable($bbbsession)) { |
|
|
|
|
1796
|
|
|
$payload = array('recordingid' => $recording['recordID'], 'meetingid' => $recording['meetingID'], |
1797
|
|
|
'action' => 'edit', 'tag' => 'edit', |
1798
|
|
|
'target' => 'name'); |
1799
|
|
|
} |
1800
|
|
|
$oldsource = 'meta_contextactivity'; |
1801
|
|
|
if (isset($recording[$oldsource])) { |
1802
|
|
|
$metaname = trim($recording[$oldsource]); |
1803
|
|
|
return bigbluebuttonbn_get_recording_data_row_text($recording, $metaname, $oldsource, $payload); |
1804
|
|
|
} |
1805
|
|
|
$newsource = 'meta_bbb-recording-name'; |
1806
|
|
View Code Duplication |
if (isset($recording[$newsource])) { |
|
|
|
|
1807
|
|
|
$metaname = trim($recording[$newsource]); |
1808
|
|
|
return bigbluebuttonbn_get_recording_data_row_text($recording, $metaname, $newsource, $payload); |
1809
|
|
|
} |
1810
|
|
|
$metaname = trim($recording['meetingName']); |
1811
|
|
|
return bigbluebuttonbn_get_recording_data_row_text($recording, $metaname, $newsource, $payload); |
1812
|
|
|
} |
1813
|
|
|
|
1814
|
|
|
/** |
1815
|
|
|
* Helper function renders the description for recording used in row for the data used by the recording table. |
1816
|
|
|
* |
1817
|
|
|
* @param array $recording |
1818
|
|
|
* @param array $bbbsession |
1819
|
|
|
* |
1820
|
|
|
* @return string |
1821
|
|
|
*/ |
1822
|
|
|
function bigbluebuttonbn_get_recording_data_row_meta_description($recording, $bbbsession) { |
1823
|
|
|
$payload = array(); |
1824
|
|
View Code Duplication |
if (bigbluebuttonbn_get_recording_data_row_editable($bbbsession)) { |
|
|
|
|
1825
|
|
|
$payload = array('recordingid' => $recording['recordID'], 'meetingid' => $recording['meetingID'], |
1826
|
|
|
'action' => 'edit', 'tag' => 'edit', |
1827
|
|
|
'target' => 'description'); |
1828
|
|
|
} |
1829
|
|
|
$oldsource = 'meta_contextactivitydescription'; |
1830
|
|
View Code Duplication |
if (isset($recording[$oldsource])) { |
|
|
|
|
1831
|
|
|
$metadescription = trim($recording[$oldsource]); |
1832
|
|
|
return bigbluebuttonbn_get_recording_data_row_text($recording, $metadescription, $oldsource, $payload); |
1833
|
|
|
} |
1834
|
|
|
$newsource = 'meta_bbb-recording-description'; |
1835
|
|
View Code Duplication |
if (isset($recording[$newsource])) { |
|
|
|
|
1836
|
|
|
$metadescription = trim($recording[$newsource]); |
1837
|
|
|
return bigbluebuttonbn_get_recording_data_row_text($recording, $metadescription, $newsource, $payload); |
1838
|
|
|
} |
1839
|
|
|
return bigbluebuttonbn_get_recording_data_row_text($recording, '', $newsource, $payload); |
1840
|
|
|
} |
1841
|
|
|
|
1842
|
|
|
/** |
1843
|
|
|
* Helper function renders text element for recording used in row for the data used by the recording table. |
1844
|
|
|
* |
1845
|
|
|
* @param array $recording |
1846
|
|
|
* @param string $text |
1847
|
|
|
* @param string $source |
1848
|
|
|
* @param array $data |
1849
|
|
|
* |
1850
|
|
|
* @return string |
1851
|
|
|
*/ |
1852
|
|
|
function bigbluebuttonbn_get_recording_data_row_text($recording, $text, $source, $data) { |
1853
|
|
|
$htmltext = '<span>' . htmlentities($text) . '</span>'; |
1854
|
|
|
if (empty($data)) { |
1855
|
|
|
return $htmltext; |
1856
|
|
|
} |
1857
|
|
|
$target = $data['action'] . '-' . $data['target']; |
1858
|
|
|
$id = 'recording-' . $target . '-' . $data['recordingid']; |
1859
|
|
|
$attributes = array('id' => $id, 'class' => 'quickeditlink col-md-20', |
1860
|
|
|
'data-recordingid' => $data['recordingid'], 'data-meetingid' => $data['meetingid'], |
1861
|
|
|
'data-target' => $data['target'], 'data-source' => $source); |
1862
|
|
|
$head = html_writer::start_tag('div', $attributes); |
1863
|
|
|
$tail = html_writer::end_tag('div'); |
1864
|
|
|
$payload = array('action' => $data['action'], 'tag' => $data['tag'], 'target' => $data['target']); |
1865
|
|
|
$htmllink = bigbluebuttonbn_actionbar_render_button($recording, $payload); |
1866
|
|
|
return $head . $htmltext . $htmllink . $tail; |
1867
|
|
|
} |
1868
|
|
|
|
1869
|
|
|
/** |
1870
|
|
|
* Helper function render a button for the recording action bar |
1871
|
|
|
* |
1872
|
|
|
* @param array $recording |
1873
|
|
|
* @param array $data |
1874
|
|
|
* |
1875
|
|
|
* @return string |
1876
|
|
|
*/ |
1877
|
|
|
function bigbluebuttonbn_actionbar_render_button($recording, $data) { |
1878
|
|
|
global $OUTPUT; |
1879
|
|
|
if (empty($data)) { |
1880
|
|
|
return ''; |
1881
|
|
|
} |
1882
|
|
|
$target = $data['action']; |
1883
|
|
|
if (isset($data['target'])) { |
1884
|
|
|
$target .= '-' . $data['target']; |
1885
|
|
|
} |
1886
|
|
|
$id = 'recording-' . $target . '-' . $recording['recordID']; |
1887
|
|
|
$onclick = 'M.mod_bigbluebuttonbn.recordings.recording' . ucfirst($data['action']) . '(this); return false;'; |
1888
|
|
|
if ((boolean) \mod_bigbluebuttonbn\locallib\config::get('recording_icons_enabled')) { |
1889
|
|
|
// With icon for $manageaction. |
1890
|
|
|
$iconattributes = array('id' => $id, 'class' => 'iconsmall'); |
1891
|
|
|
$linkattributes = array( |
1892
|
|
|
'id' => $id, |
1893
|
|
|
'onclick' => $onclick, |
1894
|
|
|
'data-action' => $data['action'], |
1895
|
|
|
); |
1896
|
|
|
if (!isset($recording['imported'])) { |
1897
|
|
|
$linkattributes['data-links'] = bigbluebuttonbn_count_recording_imported_instances( |
1898
|
|
|
$recording['recordID'] |
1899
|
|
|
); |
1900
|
|
|
} |
1901
|
|
|
if (isset($data['disabled'])) { |
1902
|
|
|
$iconattributes['class'] .= ' fa-' . $data['disabled']; |
1903
|
|
|
$linkattributes['class'] = 'disabled'; |
1904
|
|
|
unset($linkattributes['onclick']); |
1905
|
|
|
} |
1906
|
|
|
$icon = new pix_icon( |
1907
|
|
|
'i/' . $data['tag'], |
1908
|
|
|
get_string('view_recording_list_actionbar_' . $data['action'], 'bigbluebuttonbn'), |
1909
|
|
|
'moodle', |
1910
|
|
|
$iconattributes |
1911
|
|
|
); |
1912
|
|
|
return $OUTPUT->action_icon('#', $icon, null, $linkattributes, false); |
1913
|
|
|
} |
1914
|
|
|
// With text for $manageaction. |
1915
|
|
|
$linkattributes = array('title' => get_string($data['tag']), 'class' => 'btn btn-xs btn-danger', |
1916
|
|
|
'onclick' => $onclick); |
1917
|
|
|
return $OUTPUT->action_link('#', get_string($data['action']), null, $linkattributes); |
1918
|
|
|
} |
1919
|
|
|
|
1920
|
|
|
/** |
1921
|
|
|
* Helper function builds the recording table. |
1922
|
|
|
* |
1923
|
|
|
* @param array $bbbsession |
1924
|
|
|
* @param array $recordings |
1925
|
|
|
* @param array $tools |
1926
|
|
|
* |
1927
|
|
|
* @return object |
1928
|
|
|
*/ |
1929
|
|
|
function bigbluebuttonbn_get_recording_table($bbbsession, $recordings, $tools = ['protect', 'publish', 'delete']) { |
1930
|
|
|
global $DB; |
1931
|
|
|
// Declare the table. |
1932
|
|
|
$table = new html_table(); |
1933
|
|
|
$table->data = array(); |
1934
|
|
|
// Initialize table headers. |
1935
|
|
|
$table->head[] = get_string('view_recording_playback', 'bigbluebuttonbn'); |
1936
|
|
|
$table->head[] = get_string('view_recording_name', 'bigbluebuttonbn'); |
1937
|
|
|
$table->head[] = get_string('view_recording_description', 'bigbluebuttonbn'); |
1938
|
|
|
if (bigbluebuttonbn_get_recording_data_preview_enabled($bbbsession)) { |
1939
|
|
|
$table->head[] = get_string('view_recording_preview', 'bigbluebuttonbn'); |
1940
|
|
|
} |
1941
|
|
|
$table->head[] = get_string('view_recording_date', 'bigbluebuttonbn'); |
1942
|
|
|
$table->head[] = get_string('view_recording_duration', 'bigbluebuttonbn'); |
1943
|
|
|
$table->align = array('left', 'left', 'left', 'left', 'left', 'center'); |
1944
|
|
|
$table->size = array('', '', '', '', '', ''); |
1945
|
|
|
if ($bbbsession['managerecordings']) { |
1946
|
|
|
$table->head[] = get_string('view_recording_actionbar', 'bigbluebuttonbn'); |
1947
|
|
|
$table->align[] = 'left'; |
1948
|
|
|
$table->size[] = (count($tools) * 40) . 'px'; |
1949
|
|
|
} |
1950
|
|
|
// Get the groups of the user. |
1951
|
|
|
$usergroups = groups_get_all_groups($bbbsession['course']->id, $bbbsession['userID']); |
1952
|
|
|
|
1953
|
|
|
// Build table content. |
1954
|
|
|
foreach ($recordings as $recording) { |
1955
|
|
|
$meetingid = $recording['meetingID']; |
|
|
|
|
1956
|
|
|
$shortmeetingid = explode('-', $recording['meetingID']); |
1957
|
|
|
if (isset($shortmeetingid[0])) { |
1958
|
|
|
$meetingid = $shortmeetingid[0]; |
|
|
|
|
1959
|
|
|
} |
1960
|
|
|
// Check if the record belongs to a Visible Group type. |
1961
|
|
|
list($course, $cm) = get_course_and_cm_from_cmid($bbbsession['cm']->id); |
|
|
|
|
1962
|
|
|
$groupmode = groups_get_activity_groupmode($cm); |
1963
|
|
|
$displayrow = true; |
1964
|
|
|
if (($groupmode != VISIBLEGROUPS) |
1965
|
|
|
&& !$bbbsession['administrator'] && !$bbbsession['moderator']) { |
1966
|
|
|
$groupid = explode('[', $recording['meetingID']); |
1967
|
|
|
if (isset($groupid[1])) { |
1968
|
|
|
// It is a group recording and the user is not moderator/administrator. Recording should not be included by default. |
1969
|
|
|
$displayrow = false; |
1970
|
|
|
$groupid = explode(']', $groupid[1]); |
1971
|
|
|
if (isset($groupid[0])) { |
1972
|
|
|
foreach ($usergroups as $usergroup) { |
1973
|
|
|
if ($usergroup->id == $groupid[0]) { |
1974
|
|
|
// Include recording if the user is in the same group. |
1975
|
|
|
$displayrow = true; |
1976
|
|
|
} |
1977
|
|
|
} |
1978
|
|
|
} |
1979
|
|
|
} |
1980
|
|
|
} |
1981
|
|
|
if ($displayrow) { |
1982
|
|
|
$rowdata = bigbluebuttonbn_get_recording_data_row($bbbsession, $recording, $tools); |
1983
|
|
|
if (!empty($rowdata)) { |
1984
|
|
|
$row = bigbluebuttonbn_get_recording_table_row($bbbsession, $recording, $rowdata); |
1985
|
|
|
array_push($table->data, $row); |
1986
|
|
|
} |
1987
|
|
|
} |
1988
|
|
|
} |
1989
|
|
|
return $table; |
1990
|
|
|
} |
1991
|
|
|
|
1992
|
|
|
/** |
1993
|
|
|
* Helper function builds the recording table row and insert into table. |
1994
|
|
|
* |
1995
|
|
|
* @param array $bbbsession |
1996
|
|
|
* @param array $recording |
1997
|
|
|
* @param object $rowdata |
1998
|
|
|
* |
1999
|
|
|
* @return object |
2000
|
|
|
*/ |
2001
|
|
|
function bigbluebuttonbn_get_recording_table_row($bbbsession, $recording, $rowdata) { |
2002
|
|
|
$row = new html_table_row(); |
2003
|
|
|
$row->id = 'recording-tr-' . $recording['recordID']; |
2004
|
|
|
$row->attributes['data-imported'] = 'false'; |
2005
|
|
|
$texthead = ''; |
2006
|
|
|
$texttail = ''; |
2007
|
|
|
if (isset($recording['imported'])) { |
2008
|
|
|
$row->attributes['title'] = get_string('view_recording_link_warning', 'bigbluebuttonbn'); |
2009
|
|
|
$row->attributes['data-imported'] = 'true'; |
2010
|
|
|
$texthead = '<em>'; |
2011
|
|
|
$texttail = '</em>'; |
2012
|
|
|
} |
2013
|
|
|
$rowdata->date_formatted = str_replace(' ', ' ', $rowdata->date_formatted); |
2014
|
|
|
$row->cells = array(); |
2015
|
|
|
$row->cells[] = $texthead . $rowdata->playback . $texttail; |
2016
|
|
|
$row->cells[] = $texthead . $rowdata->recording . $texttail; |
2017
|
|
|
$row->cells[] = $texthead . $rowdata->description . $texttail; |
2018
|
|
|
if (bigbluebuttonbn_get_recording_data_preview_enabled($bbbsession)) { |
2019
|
|
|
$row->cells[] = $rowdata->preview; |
2020
|
|
|
} |
2021
|
|
|
$row->cells[] = $texthead . $rowdata->date_formatted . $texttail; |
2022
|
|
|
$row->cells[] = $rowdata->duration_formatted; |
2023
|
|
|
if ($bbbsession['managerecordings']) { |
2024
|
|
|
$row->cells[] = $rowdata->actionbar; |
2025
|
|
|
} |
2026
|
|
|
return $row; |
2027
|
|
|
} |
2028
|
|
|
|
2029
|
|
|
/** |
2030
|
|
|
* Get the basic data to display in the table view |
2031
|
|
|
* |
2032
|
|
|
* @param array $bbbsession the current session |
2033
|
|
|
* @param array $enabledfeatures feature enabled for this activity |
2034
|
|
|
* @return associative array containing the recordings indexed by recordID, each recording is also a |
2035
|
|
|
* non sequential associative array itself that corresponds to the actual recording in BBB |
2036
|
|
|
*/ |
2037
|
|
|
function bigbluebutton_get_recordings_for_table_view($bbbsession, $enabledfeatures) { |
2038
|
|
|
$bigbluebuttonbnid = null; |
2039
|
|
|
if ($enabledfeatures['showroom']) { |
2040
|
|
|
$bigbluebuttonbnid = $bbbsession['bigbluebuttonbn']->id; |
2041
|
|
|
} |
2042
|
|
|
// Get recordings. |
2043
|
|
|
$recordings = bigbluebuttonbn_get_recordings( |
2044
|
|
|
$bbbsession['course']->id, $bigbluebuttonbnid, $enabledfeatures['showroom'], |
2045
|
|
|
$bbbsession['bigbluebuttonbn']->recordings_deleted |
2046
|
|
|
); |
2047
|
|
|
if ($enabledfeatures['importrecordings']) { |
2048
|
|
|
// Get recording links. |
2049
|
|
|
$bigbluebuttonbnid = $bbbsession['bigbluebuttonbn']->id; |
2050
|
|
|
$recordingsimported = bigbluebuttonbn_get_recordings_imported_array( |
2051
|
|
|
$bbbsession['course']->id, $bigbluebuttonbnid, true |
2052
|
|
|
); |
2053
|
|
|
/* Perform aritmetic addition instead of merge so the imported recordings corresponding to existent |
2054
|
|
|
* recordings are not included. */ |
2055
|
|
|
if ($bbbsession['bigbluebuttonbn']->recordings_imported) { |
2056
|
|
|
$recordings = $recordingsimported; |
2057
|
|
|
} else { |
2058
|
|
|
$recordings += $recordingsimported; |
2059
|
|
|
} |
2060
|
|
|
} |
2061
|
|
|
return $recordings; |
2062
|
|
|
} |
2063
|
|
|
|
2064
|
|
|
/** |
2065
|
|
|
* Helper function evaluates if recording row should be included in the table. |
2066
|
|
|
* |
2067
|
|
|
* @param array $bbbsession |
2068
|
|
|
* @param array $recording |
2069
|
|
|
* |
2070
|
|
|
* @return boolean |
2071
|
|
|
*/ |
2072
|
|
|
function bigbluebuttonbn_include_recording_table_row($bbbsession, $recording) { |
2073
|
|
|
// Exclude unpublished recordings, only if user has no rights to manage them. |
2074
|
|
|
if ($recording['published'] != 'true' && !$bbbsession['managerecordings']) { |
2075
|
|
|
return false; |
2076
|
|
|
} |
2077
|
|
|
// Imported recordings are always shown as long as they are published. |
2078
|
|
|
if (isset($recording['imported'])) { |
2079
|
|
|
return true; |
2080
|
|
|
} |
2081
|
|
|
// Administrators and moderators are always allowed. |
2082
|
|
|
if ($bbbsession['administrator'] || $bbbsession['moderator']) { |
2083
|
|
|
return true; |
2084
|
|
|
} |
2085
|
|
|
// When groups are enabled, exclude those to which the user doesn't have access to. |
2086
|
|
|
if (isset($bbbsession['group']) && $recording['meetingID'] != $bbbsession['meetingid']) { |
2087
|
|
|
return false; |
2088
|
|
|
} |
2089
|
|
|
return true; |
2090
|
|
|
} |
2091
|
|
|
|
2092
|
|
|
/** |
2093
|
|
|
* Helper function triggers a send notification when the recording is ready. |
2094
|
|
|
* |
2095
|
|
|
* @param object $bigbluebuttonbn |
2096
|
|
|
* |
2097
|
|
|
* @return void |
2098
|
|
|
*/ |
2099
|
|
|
function bigbluebuttonbn_send_notification_recording_ready($bigbluebuttonbn) { |
2100
|
|
|
\mod_bigbluebuttonbn\locallib\notifier::notify_recording_ready($bigbluebuttonbn); |
2101
|
|
|
} |
2102
|
|
|
|
2103
|
|
|
/** |
2104
|
|
|
* Helper function enqueues list of meeting events to be stored and processed as for completion. |
2105
|
|
|
* |
2106
|
|
|
* @param object $bigbluebuttonbn |
2107
|
|
|
* @param object $jsonobj |
2108
|
|
|
* |
2109
|
|
|
* @return void |
2110
|
|
|
*/ |
2111
|
|
|
function bigbluebuttonbn_process_meeting_events($bigbluebuttonbn, $jsonobj) { |
2112
|
|
|
$meetingid = $jsonobj->{'meeting_id'}; |
2113
|
|
|
$recordid = $jsonobj->{'internal_meeting_id'}; |
2114
|
|
|
$attendees = $jsonobj->{'data'}->{'attendees'}; |
2115
|
|
|
foreach ($attendees as $attendee) { |
2116
|
|
|
$userid = $attendee->{'ext_user_id'}; |
2117
|
|
|
$overrides['meetingid'] = $meetingid; |
|
|
|
|
2118
|
|
|
$overrides['userid'] = $userid; |
|
|
|
|
2119
|
|
|
$meta['recordid'] = $recordid; |
|
|
|
|
2120
|
|
|
$meta['data'] = $attendee; |
2121
|
|
|
// Stores the log. |
2122
|
|
|
bigbluebuttonbn_log($bigbluebuttonbn, BIGBLUEBUTTON_LOG_EVENT_SUMMARY, $overrides, json_encode($meta)); |
2123
|
|
|
// Enqueue a task for processing the completion. |
2124
|
|
|
bigbluebuttonbn_enqueue_completion_update($bigbluebuttonbn, $userid); |
2125
|
|
|
} |
2126
|
|
|
} |
2127
|
|
|
|
2128
|
|
|
/** |
2129
|
|
|
* Helper function enqueues one user for being validated as for completion. |
2130
|
|
|
* |
2131
|
|
|
* @param object $bigbluebuttonbn |
2132
|
|
|
* @param string $userid |
2133
|
|
|
* |
2134
|
|
|
* @return void |
2135
|
|
|
*/ |
2136
|
|
|
function bigbluebuttonbn_enqueue_completion_update($bigbluebuttonbn, $userid) { |
2137
|
|
|
try { |
2138
|
|
|
// Create the instance of completion_update_state task. |
2139
|
|
|
$task = new \mod_bigbluebuttonbn\task\completion_update_state(); |
2140
|
|
|
// Add custom data. |
2141
|
|
|
$data = array( |
2142
|
|
|
'bigbluebuttonbn' => $bigbluebuttonbn, |
2143
|
|
|
'userid' => $userid, |
2144
|
|
|
); |
2145
|
|
|
$task->set_custom_data($data); |
2146
|
|
|
// CONTRIB-7457: Task should be executed by a user, maybe Teacher as Student won't have rights for overriding. |
2147
|
|
|
// $ task -> set_userid ( $ user -> id );. |
2148
|
|
|
// Enqueue it. |
2149
|
|
|
\core\task\manager::queue_adhoc_task($task); |
2150
|
|
|
} catch (Exception $e) { |
2151
|
|
|
mtrace("Error while enqueuing completion_update_state task. " . (string) $e); |
2152
|
|
|
} |
2153
|
|
|
} |
2154
|
|
|
|
2155
|
|
|
/** |
2156
|
|
|
* Helper function enqueues completion trigger. |
2157
|
|
|
* |
2158
|
|
|
* @param object $bigbluebuttonbn |
2159
|
|
|
* @param string $userid |
2160
|
|
|
* |
2161
|
|
|
* @return void |
2162
|
|
|
*/ |
2163
|
|
|
function bigbluebuttonbn_completion_update_state($bigbluebuttonbn, $userid) { |
2164
|
|
|
global $CFG; |
2165
|
|
|
require_once($CFG->libdir.'/completionlib.php'); |
2166
|
|
|
list($course, $cm) = get_course_and_cm_from_instance($bigbluebuttonbn, 'bigbluebuttonbn'); |
2167
|
|
|
$completion = new completion_info($course); |
2168
|
|
|
if (!$completion->is_enabled($cm)) { |
2169
|
|
|
mtrace("Completion not enabled"); |
2170
|
|
|
return; |
2171
|
|
|
} |
2172
|
|
|
if (bigbluebuttonbn_get_completion_state($course, $cm, $userid, COMPLETION_AND)) { |
2173
|
|
|
mtrace("Completion succeeded for user $userid"); |
2174
|
|
|
$completion->update_state($cm, COMPLETION_COMPLETE, $userid, true); |
2175
|
|
|
} else { |
2176
|
|
|
mtrace("Completion did not succeed for user $userid"); |
2177
|
|
|
} |
2178
|
|
|
} |
2179
|
|
|
|
2180
|
|
|
/** |
2181
|
|
|
* Helper evaluates if the bigbluebutton server used belongs to blindsidenetworks domain. |
2182
|
|
|
* |
2183
|
|
|
* @return boolean |
2184
|
|
|
*/ |
2185
|
|
|
function bigbluebuttonbn_is_bn_server() { |
2186
|
|
|
if (\mod_bigbluebuttonbn\locallib\config::get('bn_server')) { |
2187
|
|
|
return true; |
2188
|
|
|
} |
2189
|
|
|
$parsedurl = parse_url(\mod_bigbluebuttonbn\locallib\config::get('server_url')); |
2190
|
|
|
if (!isset($parsedurl['host'])) { |
2191
|
|
|
return false; |
2192
|
|
|
} |
2193
|
|
|
$h = $parsedurl['host']; |
2194
|
|
|
$hends = explode('.', $h); |
2195
|
|
|
$hendslength = count($hends); |
2196
|
|
|
return ($hends[$hendslength - 1] == 'com' && $hends[$hendslength - 2] == 'blindsidenetworks'); |
2197
|
|
|
} |
2198
|
|
|
|
2199
|
|
|
/** |
2200
|
|
|
* Helper function returns a list of courses a user has access to, wrapped in an array that can be used |
2201
|
|
|
* by a html select. |
2202
|
|
|
* |
2203
|
|
|
* @param array $bbbsession |
2204
|
|
|
* |
2205
|
|
|
* @return array |
2206
|
|
|
*/ |
2207
|
|
|
function bigbluebuttonbn_import_get_courses_for_select(array $bbbsession) { |
2208
|
|
|
if ($bbbsession['administrator']) { |
2209
|
|
|
$courses = get_courses('all', 'c.fullname ASC'); |
2210
|
|
|
// It includes the name of the site as a course (category 0), so remove the first one. |
2211
|
|
|
unset($courses['1']); |
2212
|
|
|
} else { |
2213
|
|
|
$courses = enrol_get_users_courses($bbbsession['userID'], false, 'id,shortname,fullname'); |
2214
|
|
|
} |
2215
|
|
|
$coursesforselect = []; |
2216
|
|
|
foreach ($courses as $course) { |
2217
|
|
|
$coursesforselect[$course->id] = $course->fullname . " (" . $course->shortname . ")"; |
2218
|
|
|
} |
2219
|
|
|
return $coursesforselect; |
2220
|
|
|
} |
2221
|
|
|
|
2222
|
|
|
/** |
2223
|
|
|
* Helper function renders recording table. |
2224
|
|
|
* |
2225
|
|
|
* @param array $bbbsession |
2226
|
|
|
* @param array $recordings |
2227
|
|
|
* @param array $tools |
2228
|
|
|
* |
2229
|
|
|
* @return array |
2230
|
|
|
*/ |
2231
|
|
|
function bigbluebuttonbn_output_recording_table($bbbsession, $recordings, $tools = ['protect', 'publish', 'delete']) { |
2232
|
|
|
if (isset($recordings) && !empty($recordings)) { |
2233
|
|
|
// There are recordings for this meeting. |
2234
|
|
|
$table = bigbluebuttonbn_get_recording_table($bbbsession, $recordings, $tools); |
2235
|
|
|
} |
2236
|
|
|
if (!isset($table) || !isset($table->data)) { |
2237
|
|
|
// Render a table with "No recordings". |
2238
|
|
|
return html_writer::div( |
2239
|
|
|
get_string('view_message_norecordings', 'bigbluebuttonbn'), |
2240
|
|
|
'', |
2241
|
|
|
array('id' => 'bigbluebuttonbn_recordings_table') |
2242
|
|
|
); |
2243
|
|
|
} |
2244
|
|
|
// Render the table. |
2245
|
|
|
return html_writer::div(html_writer::table($table), '', array('id' => 'bigbluebuttonbn_recordings_table')); |
2246
|
|
|
} |
2247
|
|
|
|
2248
|
|
|
/** |
2249
|
|
|
* Helper function to convert an html string to plain text. |
2250
|
|
|
* |
2251
|
|
|
* @param string $html |
2252
|
|
|
* @param integer $len |
2253
|
|
|
* |
2254
|
|
|
* @return string |
2255
|
|
|
*/ |
2256
|
|
|
function bigbluebuttonbn_html2text($html, $len = 0) { |
2257
|
|
|
$text = strip_tags($html); |
2258
|
|
|
$text = str_replace(' ', ' ', $text); |
2259
|
|
|
$textlen = strlen($text); |
2260
|
|
|
$text = mb_substr($text, 0, $len); |
2261
|
|
|
if ($textlen > $len) { |
2262
|
|
|
$text .= '...'; |
2263
|
|
|
} |
2264
|
|
|
return $text; |
2265
|
|
|
} |
2266
|
|
|
|
2267
|
|
|
/** |
2268
|
|
|
* Helper function to obtain the tags linked to a bigbluebuttonbn activity |
2269
|
|
|
* |
2270
|
|
|
* @param string $id |
2271
|
|
|
* |
2272
|
|
|
* @return string containing the tags separated by commas |
2273
|
|
|
*/ |
2274
|
|
|
function bigbluebuttonbn_get_tags($id) { |
2275
|
|
|
if (class_exists('core_tag_tag')) { |
2276
|
|
|
return implode(',', core_tag_tag::get_item_tags_array('core', 'course_modules', $id)); |
2277
|
|
|
} |
2278
|
|
|
return implode(',', tag_get_tags('bigbluebuttonbn', $id)); |
2279
|
|
|
} |
2280
|
|
|
|
2281
|
|
|
/** |
2282
|
|
|
* Helper function to define the sql used for gattering the bigbluebuttonbnids whose meetingids should be included |
2283
|
|
|
* in the getRecordings request |
2284
|
|
|
* |
2285
|
|
|
* @param string $courseid |
2286
|
|
|
* @param string $bigbluebuttonbnid |
2287
|
|
|
* @param bool $subset |
2288
|
|
|
* |
2289
|
|
|
* @return string containing the sql used for getting the target bigbluebuttonbn instances |
2290
|
|
|
*/ |
2291
|
|
|
function bigbluebuttonbn_get_recordings_sql_select($courseid, $bigbluebuttonbnid = null, $subset = true) { |
2292
|
|
|
if (empty($courseid)) { |
2293
|
|
|
$courseid = 0; |
2294
|
|
|
} |
2295
|
|
|
if (empty($bigbluebuttonbnid)) { |
2296
|
|
|
return "course = '{$courseid}'"; |
2297
|
|
|
} |
2298
|
|
|
if ($subset) { |
2299
|
|
|
return "id = '{$bigbluebuttonbnid}'"; |
2300
|
|
|
} |
2301
|
|
|
return "id <> '{$bigbluebuttonbnid}' AND course = '{$courseid}'"; |
2302
|
|
|
} |
2303
|
|
|
|
2304
|
|
|
/** |
2305
|
|
|
* Helper function to define the sql used for gattering the bigbluebuttonbnids whose meetingids should be included |
2306
|
|
|
* in the getRecordings request considering only those that belong to deleted activities. |
2307
|
|
|
* |
2308
|
|
|
* @param string $courseid |
2309
|
|
|
* @param string $bigbluebuttonbnid |
2310
|
|
|
* @param bool $subset |
2311
|
|
|
* |
2312
|
|
|
* @return string containing the sql used for getting the target bigbluebuttonbn instances |
2313
|
|
|
*/ |
2314
|
|
View Code Duplication |
function bigbluebuttonbn_get_recordings_deleted_sql_select($courseid = 0, $bigbluebuttonbnid = null, $subset = true) { |
|
|
|
|
2315
|
|
|
$sql = "log = '" . BIGBLUEBUTTONBN_LOG_EVENT_DELETE . "' AND meta like '%has_recordings%' AND meta like '%true%'"; |
2316
|
|
|
if (empty($courseid)) { |
2317
|
|
|
$courseid = 0; |
2318
|
|
|
} |
2319
|
|
|
if (empty($bigbluebuttonbnid)) { |
2320
|
|
|
return $sql . " AND courseid = {$courseid}"; |
2321
|
|
|
} |
2322
|
|
|
if ($subset) { |
2323
|
|
|
return $sql . " AND bigbluebuttonbnid = '{$bigbluebuttonbnid}'"; |
2324
|
|
|
} |
2325
|
|
|
return $sql . " AND courseid = {$courseid} AND bigbluebuttonbnid <> '{$bigbluebuttonbnid}'"; |
2326
|
|
|
} |
2327
|
|
|
|
2328
|
|
|
/** |
2329
|
|
|
* Helper function to define the sql used for gattering the bigbluebuttonbnids whose meetingids should be included |
2330
|
|
|
* in the getRecordings request considering only those that belong to imported recordings. |
2331
|
|
|
* |
2332
|
|
|
* @param string $courseid |
2333
|
|
|
* @param string $bigbluebuttonbnid |
2334
|
|
|
* @param bool $subset |
2335
|
|
|
* |
2336
|
|
|
* @return string containing the sql used for getting the target bigbluebuttonbn instances |
2337
|
|
|
*/ |
2338
|
|
View Code Duplication |
function bigbluebuttonbn_get_recordings_imported_sql_select($courseid = 0, $bigbluebuttonbnid = null, $subset = true) { |
|
|
|
|
2339
|
|
|
$sql = "log = '" . BIGBLUEBUTTONBN_LOG_EVENT_IMPORT . "'"; |
2340
|
|
|
if (empty($courseid)) { |
2341
|
|
|
$courseid = 0; |
2342
|
|
|
} |
2343
|
|
|
if (empty($bigbluebuttonbnid)) { |
2344
|
|
|
return $sql . " AND courseid = '{$courseid}'"; |
2345
|
|
|
} |
2346
|
|
|
if ($subset) { |
2347
|
|
|
return $sql . " AND bigbluebuttonbnid = '{$bigbluebuttonbnid}'"; |
2348
|
|
|
} |
2349
|
|
|
return $sql . " AND courseid = '{$courseid}' AND bigbluebuttonbnid <> '{$bigbluebuttonbnid}'"; |
2350
|
|
|
} |
2351
|
|
|
|
2352
|
|
|
/** |
2353
|
|
|
* Helper function to get recordings and imported recordings together. |
2354
|
|
|
* |
2355
|
|
|
* @param string $courseid |
2356
|
|
|
* @param string $bigbluebuttonbnid |
2357
|
|
|
* @param bool $subset |
2358
|
|
|
* @param bool $includedeleted |
2359
|
|
|
* |
2360
|
|
|
* @return associative array containing the recordings indexed by recordID, each recording is also a |
2361
|
|
|
* non sequential associative array itself that corresponds to the actual recording in BBB |
2362
|
|
|
*/ |
2363
|
|
|
function bigbluebuttonbn_get_allrecordings($courseid = 0, $bigbluebuttonbnid = null, $subset = true, $includedeleted = false) { |
2364
|
|
|
$recordings = bigbluebuttonbn_get_recordings($courseid, $bigbluebuttonbnid, $subset, $includedeleted); |
2365
|
|
|
$recordingsimported = bigbluebuttonbn_get_recordings_imported_array($courseid, $bigbluebuttonbnid, $subset); |
2366
|
|
|
return ($recordings + $recordingsimported); |
2367
|
|
|
} |
2368
|
|
|
|
2369
|
|
|
/** |
2370
|
|
|
* Helper function to retrieve recordings from the BigBlueButton. The references are stored as events |
2371
|
|
|
* in bigbluebuttonbn_logs. |
2372
|
|
|
* |
2373
|
|
|
* @param string $courseid |
2374
|
|
|
* @param string $bigbluebuttonbnid |
2375
|
|
|
* @param bool $subset |
2376
|
|
|
* @param bool $includedeleted |
2377
|
|
|
* |
2378
|
|
|
* @return associative array containing the recordings indexed by recordID, each recording is also a |
2379
|
|
|
* non sequential associative array itself that corresponds to the actual recording in BBB |
2380
|
|
|
*/ |
2381
|
|
|
function bigbluebuttonbn_get_recordings($courseid = 0, $bigbluebuttonbnid = null, $subset = true, $includedeleted = false) { |
2382
|
|
|
global $DB; |
2383
|
|
|
$select = bigbluebuttonbn_get_recordings_sql_select($courseid, $bigbluebuttonbnid, $subset); |
2384
|
|
|
$bigbluebuttonbns = $DB->get_records_select_menu('bigbluebuttonbn', $select, null, 'id', 'id, meetingid'); |
2385
|
|
|
/* Consider logs from deleted bigbluebuttonbn instances whose meetingids should be included in |
2386
|
|
|
* the getRecordings request. */ |
2387
|
|
|
if ($includedeleted) { |
2388
|
|
|
$selectdeleted = bigbluebuttonbn_get_recordings_deleted_sql_select($courseid, $bigbluebuttonbnid, $subset); |
2389
|
|
|
$bigbluebuttonbnsdel = $DB->get_records_select_menu( |
2390
|
|
|
'bigbluebuttonbn_logs', |
2391
|
|
|
$selectdeleted, |
2392
|
|
|
null, |
2393
|
|
|
'bigbluebuttonbnid', |
2394
|
|
|
'bigbluebuttonbnid, meetingid' |
2395
|
|
|
); |
2396
|
|
|
if (!empty($bigbluebuttonbnsdel)) { |
2397
|
|
|
// Merge bigbluebuttonbnis from deleted instances, only keys are relevant. |
2398
|
|
|
// Artimetic merge is used in order to keep the keys. |
2399
|
|
|
$bigbluebuttonbns += $bigbluebuttonbnsdel; |
2400
|
|
|
} |
2401
|
|
|
} |
2402
|
|
|
// Gather the meetingids from bigbluebuttonbn logs that include a create with record=true. |
2403
|
|
|
if (empty($bigbluebuttonbns)) { |
2404
|
|
|
return array(); |
2405
|
|
|
} |
2406
|
|
|
// Prepare select for loading records based on existent bigbluebuttonbns. |
2407
|
|
|
$sql = 'SELECT DISTINCT meetingid, bigbluebuttonbnid FROM {bigbluebuttonbn_logs} WHERE '; |
2408
|
|
|
$sql .= '(bigbluebuttonbnid=' . implode(' OR bigbluebuttonbnid=', array_keys($bigbluebuttonbns)) . ')'; |
2409
|
|
|
// Include only Create events and exclude those with record not true. |
2410
|
|
|
$sql .= ' AND log = ? AND meta LIKE ? AND meta LIKE ?'; |
2411
|
|
|
// Execute select for loading records based on existent bigbluebuttonbns. |
2412
|
|
|
$records = $DB->get_records_sql_menu($sql, array(BIGBLUEBUTTONBN_LOG_EVENT_CREATE, '%record%', '%true%')); |
2413
|
|
|
// Get actual recordings. |
2414
|
|
|
return bigbluebuttonbn_get_recordings_array(array_keys($records)); |
2415
|
|
|
} |
2416
|
|
|
|
2417
|
|
|
/** |
2418
|
|
|
* Helper function iterates an array with recordings and unset those already imported. |
2419
|
|
|
* |
2420
|
|
|
* @param array $recordings |
2421
|
|
|
* @param integer $courseid |
2422
|
|
|
* @param integer $bigbluebuttonbnid |
2423
|
|
|
* |
2424
|
|
|
* @return array |
2425
|
|
|
*/ |
2426
|
|
|
function bigbluebuttonbn_unset_existent_recordings_already_imported($recordings, $courseid, $bigbluebuttonbnid) { |
2427
|
|
|
$recordingsimported = bigbluebuttonbn_get_recordings_imported_array($courseid, $bigbluebuttonbnid, true); |
2428
|
|
|
foreach ($recordings as $key => $recording) { |
2429
|
|
|
if (isset($recordingsimported[$recording['recordID']])) { |
2430
|
|
|
unset($recordings[$key]); |
2431
|
|
|
} |
2432
|
|
|
} |
2433
|
|
|
return $recordings; |
2434
|
|
|
} |
2435
|
|
|
|
2436
|
|
|
/** |
2437
|
|
|
* Helper function to count the imported recordings for a recordingid. |
2438
|
|
|
* |
2439
|
|
|
* @param string $recordid |
2440
|
|
|
* |
2441
|
|
|
* @return integer |
2442
|
|
|
*/ |
2443
|
|
|
function bigbluebuttonbn_count_recording_imported_instances($recordid) { |
2444
|
|
|
global $DB; |
2445
|
|
|
$sql = 'SELECT COUNT(DISTINCT id) FROM {bigbluebuttonbn_logs} WHERE log = ? AND meta LIKE ? AND meta LIKE ?'; |
2446
|
|
|
return $DB->count_records_sql($sql, array(BIGBLUEBUTTONBN_LOG_EVENT_IMPORT, '%recordID%', "%{$recordid}%")); |
2447
|
|
|
} |
2448
|
|
|
|
2449
|
|
|
/** |
2450
|
|
|
* Helper function returns an array with all the instances of imported recordings for a recordingid. |
2451
|
|
|
* |
2452
|
|
|
* @param string $recordid |
2453
|
|
|
* |
2454
|
|
|
* @return array |
2455
|
|
|
*/ |
2456
|
|
|
function bigbluebuttonbn_get_recording_imported_instances($recordid) { |
2457
|
|
|
global $DB; |
2458
|
|
|
$sql = 'SELECT * FROM {bigbluebuttonbn_logs} WHERE log = ? AND meta LIKE ? AND meta LIKE ?'; |
2459
|
|
|
$recordingsimported = $DB->get_records_sql($sql, array(BIGBLUEBUTTONBN_LOG_EVENT_IMPORT, '%recordID%', |
2460
|
|
|
"%{$recordid}%")); |
2461
|
|
|
return $recordingsimported; |
2462
|
|
|
} |
2463
|
|
|
|
2464
|
|
|
/** |
2465
|
|
|
* Helper function to get how much callback events are logged. |
2466
|
|
|
* |
2467
|
|
|
* @param string $recordid |
2468
|
|
|
* @param string $callbacktype |
2469
|
|
|
* |
2470
|
|
|
* @return integer |
2471
|
|
|
*/ |
2472
|
|
|
function bigbluebuttonbn_get_count_callback_event_log($recordid, $callbacktype = 'recording_ready') { |
2473
|
|
|
global $DB; |
2474
|
|
|
$sql = 'SELECT count(DISTINCT id) FROM {bigbluebuttonbn_logs} WHERE log = ? AND meta LIKE ? AND meta LIKE ?'; |
2475
|
|
|
// Callback type added on version 2.4, validate recording_ready first or assume it on records with no callback. |
2476
|
|
|
if ($callbacktype == 'recording_ready') { |
2477
|
|
|
$sql .= ' AND (meta LIKE ? OR meta NOT LIKE ? )'; |
2478
|
|
|
$count = $DB->count_records_sql($sql, array(BIGBLUEBUTTON_LOG_EVENT_CALLBACK, '%recordid%', "%$recordid%", |
2479
|
|
|
$callbacktype, 'callback')); |
2480
|
|
|
return $count; |
2481
|
|
|
} |
2482
|
|
|
$sql .= ' AND meta LIKE ?;'; |
2483
|
|
|
$count = $DB->count_records_sql($sql, array(BIGBLUEBUTTON_LOG_EVENT_CALLBACK, '%recordid%', "%$recordid%", "%$callbacktype%")); |
2484
|
|
|
return $count; |
2485
|
|
|
} |
2486
|
|
|
|
2487
|
|
|
/** |
2488
|
|
|
* Helper function returns an array with the profiles (with features per profile) for the different types |
2489
|
|
|
* of bigbluebuttonbn instances. |
2490
|
|
|
* |
2491
|
|
|
* @return array |
2492
|
|
|
*/ |
2493
|
|
|
function bigbluebuttonbn_get_instance_type_profiles() { |
2494
|
|
|
$instanceprofiles = array( |
2495
|
|
|
BIGBLUEBUTTONBN_TYPE_ALL => array('id' => BIGBLUEBUTTONBN_TYPE_ALL, |
2496
|
|
|
'name' => get_string('instance_type_default', 'bigbluebuttonbn'), |
2497
|
|
|
'features' => array('all')), |
2498
|
|
|
BIGBLUEBUTTONBN_TYPE_ROOM_ONLY => array('id' => BIGBLUEBUTTONBN_TYPE_ROOM_ONLY, |
2499
|
|
|
'name' => get_string('instance_type_room_only', 'bigbluebuttonbn'), |
2500
|
|
|
'features' => array('showroom', 'welcomemessage', 'voicebridge', 'waitformoderator', 'userlimit', |
2501
|
|
|
'recording', 'sendnotifications', 'preuploadpresentation', 'permissions', 'schedule', 'groups', |
2502
|
|
|
'modstandardelshdr', 'availabilityconditionsheader', 'tagshdr', 'competenciessection', |
2503
|
|
|
'clienttype', 'completionattendance', 'completionengagement', 'availabilityconditionsheader')), |
2504
|
|
|
BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY => array('id' => BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY, |
2505
|
|
|
'name' => get_string('instance_type_recording_only', 'bigbluebuttonbn'), |
2506
|
|
|
'features' => array('showrecordings', 'importrecordings', 'availabilityconditionsheader')), |
2507
|
|
|
); |
2508
|
|
|
return $instanceprofiles; |
2509
|
|
|
} |
2510
|
|
|
|
2511
|
|
|
/** |
2512
|
|
|
* Helper function returns an array with enabled features for an specific profile type. |
2513
|
|
|
* |
2514
|
|
|
* @param array $typeprofiles |
2515
|
|
|
* @param string $type |
2516
|
|
|
* |
2517
|
|
|
* @return array |
2518
|
|
|
*/ |
2519
|
|
|
function bigbluebuttonbn_get_enabled_features($typeprofiles, $type = null) { |
2520
|
|
|
$enabledfeatures = array(); |
2521
|
|
|
$features = $typeprofiles[BIGBLUEBUTTONBN_TYPE_ALL]['features']; |
2522
|
|
|
if (!is_null($type) && key_exists($type, $typeprofiles)) { |
2523
|
|
|
$features = $typeprofiles[$type]['features']; |
2524
|
|
|
} |
2525
|
|
|
$enabledfeatures['showroom'] = (in_array('all', $features) || in_array('showroom', $features)); |
2526
|
|
|
// Evaluates if recordings are enabled for the Moodle site. |
2527
|
|
|
$enabledfeatures['showrecordings'] = false; |
2528
|
|
|
if (\mod_bigbluebuttonbn\locallib\config::recordings_enabled()) { |
2529
|
|
|
$enabledfeatures['showrecordings'] = (in_array('all', $features) || in_array('showrecordings', $features)); |
2530
|
|
|
} |
2531
|
|
|
$enabledfeatures['importrecordings'] = false; |
2532
|
|
|
if (\mod_bigbluebuttonbn\locallib\config::importrecordings_enabled()) { |
2533
|
|
|
$enabledfeatures['importrecordings'] = (in_array('all', $features) || in_array('importrecordings', $features)); |
2534
|
|
|
} |
2535
|
|
|
// Evaluates if clienttype is enabled for the Moodle site. |
2536
|
|
|
$enabledfeatures['clienttype'] = false; |
2537
|
|
|
if (\mod_bigbluebuttonbn\locallib\config::clienttype_enabled()) { |
2538
|
|
|
$enabledfeatures['clienttype'] = (in_array('all', $features) || in_array('clienttype', $features)); |
2539
|
|
|
} |
2540
|
|
|
return $enabledfeatures; |
2541
|
|
|
} |
2542
|
|
|
|
2543
|
|
|
/** |
2544
|
|
|
* Helper function returns an array with the profiles (with features per profile) for the different types |
2545
|
|
|
* of bigbluebuttonbn instances that the user is allowed to create. |
2546
|
|
|
* |
2547
|
|
|
* @param boolean $room |
2548
|
|
|
* @param boolean $recording |
2549
|
|
|
* |
2550
|
|
|
* @return array |
2551
|
|
|
*/ |
2552
|
|
|
function bigbluebuttonbn_get_instance_type_profiles_create_allowed($room, $recording) { |
2553
|
|
|
$profiles = bigbluebuttonbn_get_instance_type_profiles(); |
2554
|
|
|
if (!$room) { |
2555
|
|
|
unset($profiles[BIGBLUEBUTTONBN_TYPE_ROOM_ONLY]); |
2556
|
|
|
unset($profiles[BIGBLUEBUTTONBN_TYPE_ALL]); |
2557
|
|
|
} |
2558
|
|
|
if (!$recording) { |
2559
|
|
|
unset($profiles[BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY]); |
2560
|
|
|
unset($profiles[BIGBLUEBUTTONBN_TYPE_ALL]); |
2561
|
|
|
} |
2562
|
|
|
return $profiles; |
2563
|
|
|
} |
2564
|
|
|
|
2565
|
|
|
/** |
2566
|
|
|
* Helper function returns an array with the profiles (with features per profile) for the different types |
2567
|
|
|
* of bigbluebuttonbn instances. |
2568
|
|
|
* |
2569
|
|
|
* @param array $profiles |
2570
|
|
|
* |
2571
|
|
|
* @return array |
2572
|
|
|
*/ |
2573
|
|
|
function bigbluebuttonbn_get_instance_profiles_array($profiles = []) { |
2574
|
|
|
$profilesarray = array(); |
2575
|
|
|
foreach ($profiles as $key => $profile) { |
2576
|
|
|
$profilesarray[$profile['id']] = $profile['name']; |
2577
|
|
|
} |
2578
|
|
|
return $profilesarray; |
2579
|
|
|
} |
2580
|
|
|
|
2581
|
|
|
/** |
2582
|
|
|
* Helper function returns time in a formatted string. |
2583
|
|
|
* |
2584
|
|
|
* @param integer $time |
2585
|
|
|
* |
2586
|
|
|
* @return string |
2587
|
|
|
*/ |
2588
|
|
|
function bigbluebuttonbn_format_activity_time($time) { |
2589
|
|
|
global $CFG; |
2590
|
|
|
require_once($CFG->dirroot.'/calendar/lib.php'); |
2591
|
|
|
$activitytime = ''; |
2592
|
|
|
if ($time) { |
2593
|
|
|
$activitytime = calendar_day_representation($time) . ' ' . |
2594
|
|
|
get_string('mod_form_field_notification_msg_at', 'bigbluebuttonbn') . ' ' . |
2595
|
|
|
calendar_time_representation($time); |
2596
|
|
|
} |
2597
|
|
|
return $activitytime; |
2598
|
|
|
} |
2599
|
|
|
|
2600
|
|
|
/** |
2601
|
|
|
* Helper function returns array with all the strings to be used in javascript. |
2602
|
|
|
* |
2603
|
|
|
* @return array |
2604
|
|
|
*/ |
2605
|
|
|
function bigbluebuttonbn_get_strings_for_js() { |
2606
|
|
|
$locale = bigbluebuttonbn_get_locale(); |
2607
|
|
|
$stringman = get_string_manager(); |
2608
|
|
|
$strings = $stringman->load_component_strings('bigbluebuttonbn', $locale); |
2609
|
|
|
return $strings; |
2610
|
|
|
} |
2611
|
|
|
|
2612
|
|
|
/** |
2613
|
|
|
* Helper function returns the locale set by moodle. |
2614
|
|
|
* |
2615
|
|
|
* @return string |
2616
|
|
|
*/ |
2617
|
|
|
function bigbluebuttonbn_get_locale() { |
2618
|
|
|
$lang = get_string('locale', 'core_langconfig'); |
2619
|
|
|
return substr($lang, 0, strpos($lang, '.')); |
2620
|
|
|
} |
2621
|
|
|
|
2622
|
|
|
/** |
2623
|
|
|
* Helper function returns the locale code based on the locale set by moodle. |
2624
|
|
|
* |
2625
|
|
|
* @return string |
2626
|
|
|
*/ |
2627
|
|
|
function bigbluebuttonbn_get_localcode() { |
2628
|
|
|
$locale = bigbluebuttonbn_get_locale(); |
2629
|
|
|
return substr($locale, 0, strpos($locale, '_')); |
2630
|
|
|
} |
2631
|
|
|
|
2632
|
|
|
/** |
2633
|
|
|
* Helper function returns array with the instance settings used in views. |
2634
|
|
|
* |
2635
|
|
|
* @param string $id |
2636
|
|
|
* @param object $bigbluebuttonbnid |
2637
|
|
|
* |
2638
|
|
|
* @return array |
2639
|
|
|
*/ |
2640
|
|
|
function bigbluebuttonbn_view_validator($id, $bigbluebuttonbnid) { |
2641
|
|
|
if ($id) { |
2642
|
|
|
return bigbluebuttonbn_view_instance_id($id); |
2643
|
|
|
} |
2644
|
|
|
if ($bigbluebuttonbnid) { |
2645
|
|
|
return bigbluebuttonbn_view_instance_bigbluebuttonbn($bigbluebuttonbnid); |
2646
|
|
|
} |
2647
|
|
|
} |
2648
|
|
|
|
2649
|
|
|
/** |
2650
|
|
|
* Helper function returns array with the instance settings used in views based on id. |
2651
|
|
|
* |
2652
|
|
|
* @param string $id |
2653
|
|
|
* |
2654
|
|
|
* @return array |
2655
|
|
|
*/ |
2656
|
|
View Code Duplication |
function bigbluebuttonbn_view_instance_id($id) { |
|
|
|
|
2657
|
|
|
global $DB; |
2658
|
|
|
$cm = get_coursemodule_from_id('bigbluebuttonbn', $id, 0, false, MUST_EXIST); |
2659
|
|
|
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); |
2660
|
|
|
$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $cm->instance), '*', MUST_EXIST); |
2661
|
|
|
return array('cm' => $cm, 'course' => $course, 'bigbluebuttonbn' => $bigbluebuttonbn); |
2662
|
|
|
} |
2663
|
|
|
|
2664
|
|
|
/** |
2665
|
|
|
* Helper function returns array with the instance settings used in views based on bigbluebuttonbnid. |
2666
|
|
|
* |
2667
|
|
|
* @param object $bigbluebuttonbnid |
2668
|
|
|
* |
2669
|
|
|
* @return array |
2670
|
|
|
*/ |
2671
|
|
View Code Duplication |
function bigbluebuttonbn_view_instance_bigbluebuttonbn($bigbluebuttonbnid) { |
|
|
|
|
2672
|
|
|
global $DB; |
2673
|
|
|
$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $bigbluebuttonbnid), '*', MUST_EXIST); |
2674
|
|
|
$course = $DB->get_record('course', array('id' => $bigbluebuttonbn->course), '*', MUST_EXIST); |
2675
|
|
|
$cm = get_coursemodule_from_instance('bigbluebuttonbn', $bigbluebuttonbn->id, $course->id, false, MUST_EXIST); |
2676
|
|
|
return array('cm' => $cm, 'course' => $course, 'bigbluebuttonbn' => $bigbluebuttonbn); |
2677
|
|
|
} |
2678
|
|
|
|
2679
|
|
|
/** |
2680
|
|
|
* Helper function renders general settings if the feature is enabled. |
2681
|
|
|
* |
2682
|
|
|
* @param object $renderer |
2683
|
|
|
* |
2684
|
|
|
* @return void |
2685
|
|
|
*/ |
2686
|
|
|
function bigbluebuttonbn_settings_general(&$renderer) { |
2687
|
|
|
// Configuration for BigBlueButton. |
2688
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_general_shown()) { |
2689
|
|
|
$renderer->render_group_header('general'); |
2690
|
|
|
$renderer->render_group_element( |
2691
|
|
|
'server_url', |
2692
|
|
|
$renderer->render_group_element_text('server_url', BIGBLUEBUTTONBN_DEFAULT_SERVER_URL) |
2693
|
|
|
); |
2694
|
|
|
$renderer->render_group_element( |
2695
|
|
|
'shared_secret', |
2696
|
|
|
$renderer->render_group_element_text('shared_secret', BIGBLUEBUTTONBN_DEFAULT_SHARED_SECRET) |
2697
|
|
|
); |
2698
|
|
|
} |
2699
|
|
|
} |
2700
|
|
|
|
2701
|
|
|
/** |
2702
|
|
|
* Helper function renders record settings if the feature is enabled. |
2703
|
|
|
* |
2704
|
|
|
* @param object $renderer |
2705
|
|
|
* |
2706
|
|
|
* @return void |
2707
|
|
|
*/ |
2708
|
|
|
function bigbluebuttonbn_settings_record(&$renderer) { |
2709
|
|
|
// Configuration for 'recording' feature. |
2710
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_record_meeting_shown()) { |
2711
|
|
|
$renderer->render_group_header('recording'); |
2712
|
|
|
$renderer->render_group_element( |
2713
|
|
|
'recording_default', |
2714
|
|
|
$renderer->render_group_element_checkbox('recording_default', 1) |
2715
|
|
|
); |
2716
|
|
|
$renderer->render_group_element( |
2717
|
|
|
'recording_editable', |
2718
|
|
|
$renderer->render_group_element_checkbox('recording_editable', 1) |
2719
|
|
|
); |
2720
|
|
|
$renderer->render_group_element( |
2721
|
|
|
'recording_icons_enabled', |
2722
|
|
|
$renderer->render_group_element_checkbox('recording_icons_enabled', 1) |
2723
|
|
|
); |
2724
|
|
|
|
2725
|
|
|
// Add recording start to load and allow/hide stop/pause. |
2726
|
|
|
$renderer->render_group_element( |
2727
|
|
|
'recording_all_from_start_default', |
2728
|
|
|
$renderer->render_group_element_checkbox('recording_all_from_start_default', 0) |
2729
|
|
|
); |
2730
|
|
|
$renderer->render_group_element( |
2731
|
|
|
'recording_all_from_start_editable', |
2732
|
|
|
$renderer->render_group_element_checkbox('recording_all_from_start_editable', 0) |
2733
|
|
|
); |
2734
|
|
|
$renderer->render_group_element( |
2735
|
|
|
'recording_hide_button_default', |
2736
|
|
|
$renderer->render_group_element_checkbox('recording_hide_button_default', 0) |
2737
|
|
|
); |
2738
|
|
|
$renderer->render_group_element( |
2739
|
|
|
'recording_hide_button_editable', |
2740
|
|
|
$renderer->render_group_element_checkbox('recording_hide_button_editable', 0) |
2741
|
|
|
); |
2742
|
|
|
} |
2743
|
|
|
} |
2744
|
|
|
|
2745
|
|
|
/** |
2746
|
|
|
* Helper function renders import recording settings if the feature is enabled. |
2747
|
|
|
* |
2748
|
|
|
* @param object $renderer |
2749
|
|
|
* |
2750
|
|
|
* @return void |
2751
|
|
|
*/ |
2752
|
|
View Code Duplication |
function bigbluebuttonbn_settings_importrecordings(&$renderer) { |
|
|
|
|
2753
|
|
|
// Configuration for 'import recordings' feature. |
2754
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_import_recordings_shown()) { |
2755
|
|
|
$renderer->render_group_header('importrecordings'); |
2756
|
|
|
$renderer->render_group_element( |
2757
|
|
|
'importrecordings_enabled', |
2758
|
|
|
$renderer->render_group_element_checkbox('importrecordings_enabled', 0) |
2759
|
|
|
); |
2760
|
|
|
$renderer->render_group_element( |
2761
|
|
|
'importrecordings_from_deleted_enabled', |
2762
|
|
|
$renderer->render_group_element_checkbox('importrecordings_from_deleted_enabled', 0) |
2763
|
|
|
); |
2764
|
|
|
} |
2765
|
|
|
} |
2766
|
|
|
|
2767
|
|
|
/** |
2768
|
|
|
* Helper function renders show recording settings if the feature is enabled. |
2769
|
|
|
* |
2770
|
|
|
* @param object $renderer |
2771
|
|
|
* |
2772
|
|
|
* @return void |
2773
|
|
|
*/ |
2774
|
|
|
function bigbluebuttonbn_settings_showrecordings(&$renderer) { |
2775
|
|
|
// Configuration for 'show recordings' feature. |
2776
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_show_recordings_shown()) { |
2777
|
|
|
$renderer->render_group_header('recordings'); |
2778
|
|
|
$renderer->render_group_element( |
2779
|
|
|
'recordings_html_default', |
2780
|
|
|
$renderer->render_group_element_checkbox('recordings_html_default', 1) |
2781
|
|
|
); |
2782
|
|
|
$renderer->render_group_element( |
2783
|
|
|
'recordings_html_editable', |
2784
|
|
|
$renderer->render_group_element_checkbox('recordings_html_editable', 0) |
2785
|
|
|
); |
2786
|
|
|
$renderer->render_group_element( |
2787
|
|
|
'recordings_deleted_default', |
2788
|
|
|
$renderer->render_group_element_checkbox('recordings_deleted_default', 1) |
2789
|
|
|
); |
2790
|
|
|
$renderer->render_group_element( |
2791
|
|
|
'recordings_deleted_editable', |
2792
|
|
|
$renderer->render_group_element_checkbox('recordings_deleted_editable', 0) |
2793
|
|
|
); |
2794
|
|
|
$renderer->render_group_element( |
2795
|
|
|
'recordings_imported_default', |
2796
|
|
|
$renderer->render_group_element_checkbox('recordings_imported_default', 0) |
2797
|
|
|
); |
2798
|
|
|
$renderer->render_group_element( |
2799
|
|
|
'recordings_imported_editable', |
2800
|
|
|
$renderer->render_group_element_checkbox('recordings_imported_editable', 1) |
2801
|
|
|
); |
2802
|
|
|
$renderer->render_group_element( |
2803
|
|
|
'recordings_preview_default', |
2804
|
|
|
$renderer->render_group_element_checkbox('recordings_preview_default', 1) |
2805
|
|
|
); |
2806
|
|
|
$renderer->render_group_element( |
2807
|
|
|
'recordings_preview_editable', |
2808
|
|
|
$renderer->render_group_element_checkbox('recordings_preview_editable', 0) |
2809
|
|
|
); |
2810
|
|
|
$renderer->render_group_element( |
2811
|
|
|
'recordings_sortorder', |
2812
|
|
|
$renderer->render_group_element_checkbox('recordings_sortorder', 0) |
2813
|
|
|
); |
2814
|
|
|
$renderer->render_group_element( |
2815
|
|
|
'recordings_validate_url', |
2816
|
|
|
$renderer->render_group_element_checkbox('recordings_validate_url', 1) |
2817
|
|
|
); |
2818
|
|
|
} |
2819
|
|
|
} |
2820
|
|
|
|
2821
|
|
|
/** |
2822
|
|
|
* Helper function renders wait for moderator settings if the feature is enabled. |
2823
|
|
|
* |
2824
|
|
|
* @param object $renderer |
2825
|
|
|
* |
2826
|
|
|
* @return void |
2827
|
|
|
*/ |
2828
|
|
|
function bigbluebuttonbn_settings_waitmoderator(&$renderer) { |
2829
|
|
|
// Configuration for wait for moderator feature. |
2830
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_wait_moderator_shown()) { |
2831
|
|
|
$renderer->render_group_header('waitformoderator'); |
2832
|
|
|
$renderer->render_group_element( |
2833
|
|
|
'waitformoderator_default', |
2834
|
|
|
$renderer->render_group_element_checkbox('waitformoderator_default', 0) |
2835
|
|
|
); |
2836
|
|
|
$renderer->render_group_element( |
2837
|
|
|
'waitformoderator_editable', |
2838
|
|
|
$renderer->render_group_element_checkbox('waitformoderator_editable', 1) |
2839
|
|
|
); |
2840
|
|
|
$renderer->render_group_element( |
2841
|
|
|
'waitformoderator_ping_interval', |
2842
|
|
|
$renderer->render_group_element_text('waitformoderator_ping_interval', 10, PARAM_INT) |
2843
|
|
|
); |
2844
|
|
|
$renderer->render_group_element( |
2845
|
|
|
'waitformoderator_cache_ttl', |
2846
|
|
|
$renderer->render_group_element_text('waitformoderator_cache_ttl', 60, PARAM_INT) |
2847
|
|
|
); |
2848
|
|
|
} |
2849
|
|
|
} |
2850
|
|
|
|
2851
|
|
|
/** |
2852
|
|
|
* Helper function renders static voice bridge settings if the feature is enabled. |
2853
|
|
|
* |
2854
|
|
|
* @param object $renderer |
2855
|
|
|
* |
2856
|
|
|
* @return void |
2857
|
|
|
*/ |
2858
|
|
|
function bigbluebuttonbn_settings_voicebridge(&$renderer) { |
2859
|
|
|
// Configuration for "static voice bridge" feature. |
2860
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_static_voice_bridge_shown()) { |
2861
|
|
|
$renderer->render_group_header('voicebridge'); |
2862
|
|
|
$renderer->render_group_element( |
2863
|
|
|
'voicebridge_editable', |
2864
|
|
|
$renderer->render_group_element_checkbox('voicebridge_editable', 0) |
2865
|
|
|
); |
2866
|
|
|
} |
2867
|
|
|
} |
2868
|
|
|
|
2869
|
|
|
/** |
2870
|
|
|
* Helper function renders preuploaded presentation settings if the feature is enabled. |
2871
|
|
|
* |
2872
|
|
|
* @param object $renderer |
2873
|
|
|
* |
2874
|
|
|
* @return void |
2875
|
|
|
*/ |
2876
|
|
|
function bigbluebuttonbn_settings_preupload(&$renderer) { |
2877
|
|
|
// Configuration for "preupload presentation" feature. |
2878
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_preupload_presentation_shown()) { |
2879
|
|
|
// This feature only works if curl is installed. |
2880
|
|
|
$preuploaddescripion = get_string('config_preuploadpresentation_description', 'bigbluebuttonbn'); |
2881
|
|
|
if (!extension_loaded('curl')) { |
2882
|
|
|
$preuploaddescripion .= '<div class="form-defaultinfo">'; |
2883
|
|
|
$preuploaddescripion .= get_string('config_warning_curl_not_installed', 'bigbluebuttonbn'); |
2884
|
|
|
$preuploaddescripion .= '</div><br>'; |
2885
|
|
|
} |
2886
|
|
|
$renderer->render_group_header('preuploadpresentation', null, $preuploaddescripion); |
2887
|
|
|
if (extension_loaded('curl')) { |
2888
|
|
|
$renderer->render_group_element( |
2889
|
|
|
'preuploadpresentation_enabled', |
2890
|
|
|
$renderer->render_group_element_checkbox('preuploadpresentation_enabled', 0) |
2891
|
|
|
); |
2892
|
|
|
} |
2893
|
|
|
} |
2894
|
|
|
} |
2895
|
|
|
|
2896
|
|
|
/** |
2897
|
|
|
* Helper function renders preuploaded presentation manage file if the feature is enabled. |
2898
|
|
|
* This allow to select a file for use as default in all BBB instances if preuploaded presetantion is enable. |
2899
|
|
|
* |
2900
|
|
|
* @param object $renderer |
2901
|
|
|
* |
2902
|
|
|
* @return void |
2903
|
|
|
*/ |
2904
|
|
|
function bigbluebuttonbn_settings_preupload_manage_default_file(&$renderer) { |
2905
|
|
|
// Configuration for "preupload presentation" feature. |
2906
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_preupload_presentation_shown()) { |
2907
|
|
|
if (extension_loaded('curl')) { |
2908
|
|
|
// This feature only works if curl is installed. |
2909
|
|
|
$renderer->render_filemanager_default_file_presentation("presentation_default"); |
2910
|
|
|
} |
2911
|
|
|
} |
2912
|
|
|
} |
2913
|
|
|
|
2914
|
|
|
/** |
2915
|
|
|
* Helper function renders userlimit settings if the feature is enabled. |
2916
|
|
|
* |
2917
|
|
|
* @param object $renderer |
2918
|
|
|
* |
2919
|
|
|
* @return void |
2920
|
|
|
*/ |
2921
|
|
|
function bigbluebuttonbn_settings_userlimit(&$renderer) { |
2922
|
|
|
// Configuration for "user limit" feature. |
2923
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_user_limit_shown()) { |
2924
|
|
|
$renderer->render_group_header('userlimit'); |
2925
|
|
|
$renderer->render_group_element( |
2926
|
|
|
'userlimit_default', |
2927
|
|
|
$renderer->render_group_element_text('userlimit_default', 0, PARAM_INT) |
2928
|
|
|
); |
2929
|
|
|
$renderer->render_group_element( |
2930
|
|
|
'userlimit_editable', |
2931
|
|
|
$renderer->render_group_element_checkbox('userlimit_editable', 0) |
2932
|
|
|
); |
2933
|
|
|
} |
2934
|
|
|
} |
2935
|
|
|
|
2936
|
|
|
/** |
2937
|
|
|
* Helper function renders duration settings if the feature is enabled. |
2938
|
|
|
* |
2939
|
|
|
* @param object $renderer |
2940
|
|
|
* |
2941
|
|
|
* @return void |
2942
|
|
|
*/ |
2943
|
|
|
function bigbluebuttonbn_settings_duration(&$renderer) { |
2944
|
|
|
// Configuration for "scheduled duration" feature. |
2945
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_scheduled_duration_shown()) { |
2946
|
|
|
$renderer->render_group_header('scheduled'); |
2947
|
|
|
$renderer->render_group_element( |
2948
|
|
|
'scheduled_duration_enabled', |
2949
|
|
|
$renderer->render_group_element_checkbox('scheduled_duration_enabled', 1) |
2950
|
|
|
); |
2951
|
|
|
$renderer->render_group_element( |
2952
|
|
|
'scheduled_duration_compensation', |
2953
|
|
|
$renderer->render_group_element_text('scheduled_duration_compensation', 10, PARAM_INT) |
2954
|
|
|
); |
2955
|
|
|
$renderer->render_group_element( |
2956
|
|
|
'scheduled_pre_opening', |
2957
|
|
|
$renderer->render_group_element_text('scheduled_pre_opening', 10, PARAM_INT) |
2958
|
|
|
); |
2959
|
|
|
} |
2960
|
|
|
} |
2961
|
|
|
|
2962
|
|
|
/** |
2963
|
|
|
* Helper function renders participant settings if the feature is enabled. |
2964
|
|
|
* |
2965
|
|
|
* @param object $renderer |
2966
|
|
|
* |
2967
|
|
|
* @return void |
2968
|
|
|
*/ |
2969
|
|
|
function bigbluebuttonbn_settings_participants(&$renderer) { |
2970
|
|
|
// Configuration for defining the default role/user that will be moderator on new activities. |
2971
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_moderator_default_shown()) { |
2972
|
|
|
$renderer->render_group_header('participant'); |
2973
|
|
|
// UI for 'participants' feature. |
2974
|
|
|
$roles = bigbluebuttonbn_get_roles(null, false); |
2975
|
|
|
$owner = array('0' => get_string('mod_form_field_participant_list_type_owner', 'bigbluebuttonbn')); |
2976
|
|
|
$renderer->render_group_element( |
2977
|
|
|
'participant_moderator_default', |
2978
|
|
|
$renderer->render_group_element_configmultiselect( |
2979
|
|
|
'participant_moderator_default', |
2980
|
|
|
array_keys($owner), |
2981
|
|
|
$owner + $roles // CONTRIB-7966: don't use array_merge here so it does not reindex the array. |
2982
|
|
|
) |
2983
|
|
|
); |
2984
|
|
|
} |
2985
|
|
|
} |
2986
|
|
|
|
2987
|
|
|
/** |
2988
|
|
|
* Helper function renders notification settings if the feature is enabled. |
2989
|
|
|
* |
2990
|
|
|
* @param object $renderer |
2991
|
|
|
* |
2992
|
|
|
* @return void |
2993
|
|
|
*/ |
2994
|
|
|
function bigbluebuttonbn_settings_notifications(&$renderer) { |
2995
|
|
|
// Configuration for "send notifications" feature. |
2996
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_send_notifications_shown()) { |
2997
|
|
|
$renderer->render_group_header('sendnotifications'); |
2998
|
|
|
$renderer->render_group_element( |
2999
|
|
|
'sendnotifications_enabled', |
3000
|
|
|
$renderer->render_group_element_checkbox('sendnotifications_enabled', 1) |
3001
|
|
|
); |
3002
|
|
|
} |
3003
|
|
|
} |
3004
|
|
|
|
3005
|
|
|
/** |
3006
|
|
|
* Helper function renders client type settings if the feature is enabled. |
3007
|
|
|
* |
3008
|
|
|
* @param object $renderer |
3009
|
|
|
* |
3010
|
|
|
* @return void |
3011
|
|
|
*/ |
3012
|
|
|
function bigbluebuttonbn_settings_clienttype(&$renderer) { |
3013
|
|
|
// Configuration for "clienttype" feature. |
3014
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_clienttype_shown()) { |
3015
|
|
|
$renderer->render_group_header('clienttype'); |
3016
|
|
|
$renderer->render_group_element( |
3017
|
|
|
'clienttype_editable', |
3018
|
|
|
$renderer->render_group_element_checkbox('clienttype_editable', 0) |
3019
|
|
|
); |
3020
|
|
|
// Web Client default. |
3021
|
|
|
$default = intval((int) \mod_bigbluebuttonbn\locallib\config::get('clienttype_default')); |
3022
|
|
|
$choices = array(BIGBLUEBUTTON_CLIENTTYPE_FLASH => get_string('mod_form_block_clienttype_flash', 'bigbluebuttonbn'), |
3023
|
|
|
BIGBLUEBUTTON_CLIENTTYPE_HTML5 => get_string('mod_form_block_clienttype_html5', 'bigbluebuttonbn')); |
3024
|
|
|
$renderer->render_group_element( |
3025
|
|
|
'clienttype_default', |
3026
|
|
|
$renderer->render_group_element_configselect( |
3027
|
|
|
'clienttype_default', |
3028
|
|
|
$default, |
3029
|
|
|
$choices |
3030
|
|
|
) |
3031
|
|
|
); |
3032
|
|
|
} |
3033
|
|
|
} |
3034
|
|
|
|
3035
|
|
|
/** |
3036
|
|
|
* Helper function renders general settings if the feature is enabled. |
3037
|
|
|
* |
3038
|
|
|
* @param object $renderer |
3039
|
|
|
* |
3040
|
|
|
* @return void |
3041
|
|
|
*/ |
3042
|
|
View Code Duplication |
function bigbluebuttonbn_settings_muteonstart(&$renderer) { |
|
|
|
|
3043
|
|
|
// Configuration for BigBlueButton. |
3044
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_muteonstart_shown()) { |
3045
|
|
|
$renderer->render_group_header('muteonstart'); |
3046
|
|
|
$renderer->render_group_element( |
3047
|
|
|
'muteonstart_default', |
3048
|
|
|
$renderer->render_group_element_checkbox('muteonstart_default', 0) |
3049
|
|
|
); |
3050
|
|
|
$renderer->render_group_element( |
3051
|
|
|
'muteonstart_editable', |
3052
|
|
|
$renderer->render_group_element_checkbox('muteonstart_editable', 0) |
3053
|
|
|
); |
3054
|
|
|
} |
3055
|
|
|
} |
3056
|
|
|
|
3057
|
|
|
/** |
3058
|
|
|
* Helper function renders general settings if the feature is enabled. |
3059
|
|
|
* |
3060
|
|
|
* @param object $renderer |
3061
|
|
|
* |
3062
|
|
|
* @return void |
3063
|
|
|
*/ |
3064
|
|
|
function bigbluebuttonbn_settings_locksettings(&$renderer) { |
3065
|
|
|
$renderer->render_group_header('locksettings'); |
3066
|
|
|
// Configuration for various lock settings for meetings. |
3067
|
|
|
bigbluebuttonbn_settings_disablecam($renderer); |
3068
|
|
|
bigbluebuttonbn_settings_disablemic($renderer); |
3069
|
|
|
bigbluebuttonbn_settings_disableprivatechat($renderer); |
3070
|
|
|
bigbluebuttonbn_settings_disablepublicchat($renderer); |
3071
|
|
|
bigbluebuttonbn_settings_disablenote($renderer); |
3072
|
|
|
bigbluebuttonbn_settings_hideuserlist($renderer); |
3073
|
|
|
bigbluebuttonbn_settings_lockedlayout($renderer); |
3074
|
|
|
bigbluebuttonbn_settings_lockonjoin($renderer); |
3075
|
|
|
bigbluebuttonbn_settings_lockonjoinconfigurable($renderer); |
3076
|
|
|
} |
3077
|
|
|
|
3078
|
|
|
/** |
3079
|
|
|
* Helper function renders general settings if the feature is enabled. |
3080
|
|
|
* |
3081
|
|
|
* @param object $renderer |
3082
|
|
|
* |
3083
|
|
|
* @return void |
3084
|
|
|
*/ |
3085
|
|
|
function bigbluebuttonbn_settings_disablecam(&$renderer) { |
3086
|
|
|
// Configuration for BigBlueButton. |
3087
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_disablecam_shown()) { |
3088
|
|
|
$renderer->render_group_element( |
3089
|
|
|
'disablecam_default', |
3090
|
|
|
$renderer->render_group_element_checkbox('disablecam_default', 0) |
3091
|
|
|
); |
3092
|
|
|
$renderer->render_group_element( |
3093
|
|
|
'disablecam_editable', |
3094
|
|
|
$renderer->render_group_element_checkbox('disablecam_editable', 1) |
3095
|
|
|
); |
3096
|
|
|
} |
3097
|
|
|
} |
3098
|
|
|
|
3099
|
|
|
/** |
3100
|
|
|
* Helper function renders general settings if the feature is enabled. |
3101
|
|
|
* |
3102
|
|
|
* @param object $renderer |
3103
|
|
|
* |
3104
|
|
|
* @return void |
3105
|
|
|
*/ |
3106
|
|
|
function bigbluebuttonbn_settings_disablemic(&$renderer) { |
3107
|
|
|
// Configuration for BigBlueButton. |
3108
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_disablemic_shown()) { |
3109
|
|
|
$renderer->render_group_element( |
3110
|
|
|
'disablemic_default', |
3111
|
|
|
$renderer->render_group_element_checkbox('disablemic_default', 0) |
3112
|
|
|
); |
3113
|
|
|
$renderer->render_group_element( |
3114
|
|
|
'disablecam_editable', |
3115
|
|
|
$renderer->render_group_element_checkbox('disablemic_editable', 1) |
3116
|
|
|
); |
3117
|
|
|
} |
3118
|
|
|
} |
3119
|
|
|
|
3120
|
|
|
/** |
3121
|
|
|
* Helper function renders general settings if the feature is enabled. |
3122
|
|
|
* |
3123
|
|
|
* @param object $renderer |
3124
|
|
|
* |
3125
|
|
|
* @return void |
3126
|
|
|
*/ |
3127
|
|
|
function bigbluebuttonbn_settings_disableprivatechat(&$renderer) { |
3128
|
|
|
// Configuration for BigBlueButton. |
3129
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_disableprivatechat_shown()) { |
3130
|
|
|
$renderer->render_group_element( |
3131
|
|
|
'disableprivatechat_default', |
3132
|
|
|
$renderer->render_group_element_checkbox('disableprivatechat_default', 0) |
3133
|
|
|
); |
3134
|
|
|
$renderer->render_group_element( |
3135
|
|
|
'disableprivatechat_editable', |
3136
|
|
|
$renderer->render_group_element_checkbox('disableprivatechat_editable', 1) |
3137
|
|
|
); |
3138
|
|
|
} |
3139
|
|
|
} |
3140
|
|
|
|
3141
|
|
|
/** |
3142
|
|
|
* Helper function renders general settings if the feature is enabled. |
3143
|
|
|
* |
3144
|
|
|
* @param object $renderer |
3145
|
|
|
* |
3146
|
|
|
* @return void |
3147
|
|
|
*/ |
3148
|
|
|
function bigbluebuttonbn_settings_disablepublicchat(&$renderer) { |
3149
|
|
|
// Configuration for BigBlueButton. |
3150
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_disablepublicchat_shown()) { |
3151
|
|
|
$renderer->render_group_element( |
3152
|
|
|
'disablepublicchat_default', |
3153
|
|
|
$renderer->render_group_element_checkbox('disablepublicchat_default', 0) |
3154
|
|
|
); |
3155
|
|
|
$renderer->render_group_element( |
3156
|
|
|
'disablepublicchat_editable', |
3157
|
|
|
$renderer->render_group_element_checkbox('disablepublicchat_editable', 1) |
3158
|
|
|
); |
3159
|
|
|
} |
3160
|
|
|
} |
3161
|
|
|
|
3162
|
|
|
/** |
3163
|
|
|
* Helper function renders general settings if the feature is enabled. |
3164
|
|
|
* |
3165
|
|
|
* @param object $renderer |
3166
|
|
|
* |
3167
|
|
|
* @return void |
3168
|
|
|
*/ |
3169
|
|
|
function bigbluebuttonbn_settings_disablenote(&$renderer) { |
3170
|
|
|
// Configuration for BigBlueButton. |
3171
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_disablenote_shown()) { |
3172
|
|
|
$renderer->render_group_element( |
3173
|
|
|
'disablenote_default', |
3174
|
|
|
$renderer->render_group_element_checkbox('disablenote_default', 0) |
3175
|
|
|
); |
3176
|
|
|
$renderer->render_group_element( |
3177
|
|
|
'disablenote_editable', |
3178
|
|
|
$renderer->render_group_element_checkbox('disablenote_editable', 1) |
3179
|
|
|
); |
3180
|
|
|
} |
3181
|
|
|
} |
3182
|
|
|
|
3183
|
|
|
/** |
3184
|
|
|
* Helper function renders general settings if the feature is enabled. |
3185
|
|
|
* |
3186
|
|
|
* @param object $renderer |
3187
|
|
|
* |
3188
|
|
|
* @return void |
3189
|
|
|
*/ |
3190
|
|
|
function bigbluebuttonbn_settings_hideuserlist(&$renderer) { |
3191
|
|
|
// Configuration for BigBlueButton. |
3192
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_hideuserlist_shown()) { |
3193
|
|
|
$renderer->render_group_element( |
3194
|
|
|
'hideuserlist_default', |
3195
|
|
|
$renderer->render_group_element_checkbox('hideuserlist_default', 0) |
3196
|
|
|
); |
3197
|
|
|
$renderer->render_group_element( |
3198
|
|
|
'hideuserlist_editable', |
3199
|
|
|
$renderer->render_group_element_checkbox('hideuserlist_editable', 1) |
3200
|
|
|
); |
3201
|
|
|
} |
3202
|
|
|
} |
3203
|
|
|
|
3204
|
|
|
/** |
3205
|
|
|
* Helper function renders general settings if the feature is enabled. |
3206
|
|
|
* |
3207
|
|
|
* @param object $renderer |
3208
|
|
|
* |
3209
|
|
|
* @return void |
3210
|
|
|
*/ |
3211
|
|
|
function bigbluebuttonbn_settings_lockedlayout(&$renderer) { |
3212
|
|
|
// Configuration for BigBlueButton. |
3213
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_lockedlayout_shown()) { |
3214
|
|
|
$renderer->render_group_element( |
3215
|
|
|
'lockedlayout_default', |
3216
|
|
|
$renderer->render_group_element_checkbox('lockedlayout_default', 0) |
3217
|
|
|
); |
3218
|
|
|
$renderer->render_group_element( |
3219
|
|
|
'lockedlayout_editable', |
3220
|
|
|
$renderer->render_group_element_checkbox('lockedlayout_editable', 1) |
3221
|
|
|
); |
3222
|
|
|
} |
3223
|
|
|
} |
3224
|
|
|
|
3225
|
|
|
/** |
3226
|
|
|
* Helper function renders general settings if the feature is enabled. |
3227
|
|
|
* |
3228
|
|
|
* @param object $renderer |
3229
|
|
|
* |
3230
|
|
|
* @return void |
3231
|
|
|
*/ |
3232
|
|
|
function bigbluebuttonbn_settings_lockonjoin(&$renderer) { |
3233
|
|
|
// Configuration for BigBlueButton. |
3234
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_lockonjoin_shown()) { |
3235
|
|
|
$renderer->render_group_element( |
3236
|
|
|
'lockonjoin_default', |
3237
|
|
|
$renderer->render_group_element_checkbox('lockonjoin_default', 0) |
3238
|
|
|
); |
3239
|
|
|
$renderer->render_group_element( |
3240
|
|
|
'lockonjoin_editable', |
3241
|
|
|
$renderer->render_group_element_checkbox('lockonjoin_editable', 1) |
3242
|
|
|
); |
3243
|
|
|
} |
3244
|
|
|
} |
3245
|
|
|
|
3246
|
|
|
/** |
3247
|
|
|
* Helper function renders general settings if the feature is enabled. |
3248
|
|
|
* |
3249
|
|
|
* @param object $renderer |
3250
|
|
|
* |
3251
|
|
|
* @return void |
3252
|
|
|
*/ |
3253
|
|
|
function bigbluebuttonbn_settings_lockonjoinconfigurable(&$renderer) { |
3254
|
|
|
// Configuration for BigBlueButton. |
3255
|
|
|
if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_lockonjoinconfigurable_shown()) { |
3256
|
|
|
$renderer->render_group_element( |
3257
|
|
|
'lockonjoinconfigurable_default', |
3258
|
|
|
$renderer->render_group_element_checkbox('lockonjoinconfigurable_default', 0) |
3259
|
|
|
); |
3260
|
|
|
$renderer->render_group_element( |
3261
|
|
|
'lockonjoinconfigurable_editable', |
3262
|
|
|
$renderer->render_group_element_checkbox('lockonjoinconfigurable_editable', 1) |
3263
|
|
|
); |
3264
|
|
|
} |
3265
|
|
|
} |
3266
|
|
|
|
3267
|
|
|
/** |
3268
|
|
|
* Helper function renders default messages settings. |
3269
|
|
|
* |
3270
|
|
|
* @param object $renderer |
3271
|
|
|
* |
3272
|
|
|
* @return void |
3273
|
|
|
*/ |
3274
|
|
|
function bigbluebuttonbn_settings_default_messages(&$renderer) { |
3275
|
|
|
$renderer->render_group_header('default_messages'); |
3276
|
|
|
$renderer->render_group_element( |
3277
|
|
|
'welcome_default', |
3278
|
|
|
$renderer->render_group_element_textarea('welcome_default', '', PARAM_TEXT) |
3279
|
|
|
); |
3280
|
|
|
} |
3281
|
|
|
|
3282
|
|
|
/** |
3283
|
|
|
* Helper function renders extended settings if any of the features there is enabled. |
3284
|
|
|
* |
3285
|
|
|
* @param object $renderer |
3286
|
|
|
* |
3287
|
|
|
* @return void |
3288
|
|
|
*/ |
3289
|
|
|
function bigbluebuttonbn_settings_extended(&$renderer) { |
3290
|
|
|
// Configuration for extended capabilities. |
3291
|
|
|
if (!(boolean) \mod_bigbluebuttonbn\settings\validator::section_settings_extended_shown()) { |
3292
|
|
|
return; |
3293
|
|
|
} |
3294
|
|
|
$renderer->render_group_header('extended_capabilities'); |
3295
|
|
|
// UI for 'notify users when recording ready' feature. |
3296
|
|
|
$renderer->render_group_element( |
3297
|
|
|
'recordingready_enabled', |
3298
|
|
|
$renderer->render_group_element_checkbox('recordingready_enabled', 0) |
3299
|
|
|
); |
3300
|
|
|
// Configuration for extended BN capabilities should go here. |
3301
|
|
|
} |
3302
|
|
|
|
3303
|
|
|
/** |
3304
|
|
|
* Helper function renders experimental settings if any of the features there is enabled. |
3305
|
|
|
* |
3306
|
|
|
* @param object $renderer |
3307
|
|
|
* |
3308
|
|
|
* @return void |
3309
|
|
|
*/ |
3310
|
|
|
function bigbluebuttonbn_settings_experimental(&$renderer) { |
3311
|
|
|
// Configuration for experimental features should go here. |
3312
|
|
|
$renderer->render_group_header('experimental_features'); |
3313
|
|
|
// UI for 'register meeting events' feature. |
3314
|
|
|
$renderer->render_group_element( |
3315
|
|
|
'meetingevents_enabled', |
3316
|
|
|
$renderer->render_group_element_checkbox('meetingevents_enabled', 0) |
3317
|
|
|
); |
3318
|
|
|
} |
3319
|
|
|
|
3320
|
|
|
/** |
3321
|
|
|
* Helper function returns a sha1 encoded string that is unique and will be used as a seed for meetingid. |
3322
|
|
|
* |
3323
|
|
|
* @return string |
3324
|
|
|
*/ |
3325
|
|
|
function bigbluebuttonbn_unique_meetingid_seed() { |
3326
|
|
|
global $DB; |
3327
|
|
|
do { |
3328
|
|
|
$encodedseed = sha1(bigbluebuttonbn_random_password(12)); |
3329
|
|
|
$meetingid = (string) $DB->get_field('bigbluebuttonbn', 'meetingid', array('meetingid' => $encodedseed)); |
3330
|
|
|
} while ($meetingid == $encodedseed); |
3331
|
|
|
return $encodedseed; |
3332
|
|
|
} |
3333
|
|
|
|
3334
|
|
|
/** |
3335
|
|
|
* Helper function renders the link used for recording type in row for the data used by the recording table. |
3336
|
|
|
* |
3337
|
|
|
* @param array $recording |
3338
|
|
|
* @param array $bbbsession |
3339
|
|
|
* @param array $playback |
3340
|
|
|
* |
3341
|
|
|
* @return boolean |
3342
|
|
|
*/ |
3343
|
|
|
function bigbluebuttonbn_include_recording_data_row_type($recording, $bbbsession, $playback) { |
3344
|
|
|
// All types that are not restricted are included. |
3345
|
|
|
if (array_key_exists('restricted', $playback) && strtolower($playback['restricted']) == 'false') { |
3346
|
|
|
return true; |
3347
|
|
|
} |
3348
|
|
|
// All types that are not statistics are included. |
3349
|
|
|
if ($playback['type'] != 'statistics') { |
3350
|
|
|
return true; |
3351
|
|
|
} |
3352
|
|
|
// Exclude imported recordings. |
3353
|
|
|
if (isset($recording['imported'])) { |
3354
|
|
|
return false; |
3355
|
|
|
} |
3356
|
|
|
// Exclude non moderators. |
3357
|
|
|
if (!$bbbsession['administrator'] && !$bbbsession['moderator']) { |
3358
|
|
|
return false; |
3359
|
|
|
} |
3360
|
|
|
return true; |
3361
|
|
|
} |
3362
|
|
|
|
3363
|
|
|
/** |
3364
|
|
|
* Renders the general warning message. |
3365
|
|
|
* |
3366
|
|
|
* @param string $message |
3367
|
|
|
* @param string $type |
3368
|
|
|
* @param string $href |
3369
|
|
|
* @param string $text |
3370
|
|
|
* @param string $class |
3371
|
|
|
* |
3372
|
|
|
* @return string |
3373
|
|
|
*/ |
3374
|
|
|
function bigbluebuttonbn_render_warning($message, $type = 'info', $href = '', $text = '', $class = '') { |
3375
|
|
|
global $OUTPUT; |
3376
|
|
|
$output = "\n"; |
3377
|
|
|
// Evaluates if config_warning is enabled. |
3378
|
|
|
if (empty($message)) { |
3379
|
|
|
return $output; |
3380
|
|
|
} |
3381
|
|
|
$output .= $OUTPUT->box_start( |
3382
|
|
|
'box boxalignleft adminerror alert alert-' . $type . ' alert-block fade in', |
3383
|
|
|
'bigbluebuttonbn_view_general_warning' |
3384
|
|
|
) . "\n"; |
3385
|
|
|
$output .= ' ' . $message . "\n"; |
3386
|
|
|
$output .= ' <div class="singlebutton pull-right">' . "\n"; |
3387
|
|
|
if (!empty($href)) { |
3388
|
|
|
$output .= bigbluebuttonbn_render_warning_button($href, $text, $class); |
3389
|
|
|
} |
3390
|
|
|
$output .= ' </div>' . "\n"; |
3391
|
|
|
$output .= $OUTPUT->box_end() . "\n"; |
3392
|
|
|
return $output; |
3393
|
|
|
} |
3394
|
|
|
|
3395
|
|
|
/** |
3396
|
|
|
* Renders the general warning button. |
3397
|
|
|
* |
3398
|
|
|
* @param string $href |
3399
|
|
|
* @param string $text |
3400
|
|
|
* @param string $class |
3401
|
|
|
* @param string $title |
3402
|
|
|
* |
3403
|
|
|
* @return string |
3404
|
|
|
*/ |
3405
|
|
|
function bigbluebuttonbn_render_warning_button($href, $text = '', $class = '', $title = '') { |
3406
|
|
|
if ($text == '') { |
3407
|
|
|
$text = get_string('ok', 'moodle'); |
3408
|
|
|
} |
3409
|
|
|
if ($title == '') { |
3410
|
|
|
$title = $text; |
3411
|
|
|
} |
3412
|
|
|
if ($class == '') { |
3413
|
|
|
$class = 'btn btn-secondary'; |
3414
|
|
|
} |
3415
|
|
|
$output = ' <form method="post" action="' . $href . '" class="form-inline">' . "\n"; |
3416
|
|
|
$output .= ' <button type="submit" class="' . $class . '"' . "\n"; |
3417
|
|
|
$output .= ' title="' . $title . '"' . "\n"; |
3418
|
|
|
$output .= ' >' . $text . '</button>' . "\n"; |
3419
|
|
|
$output .= ' </form>' . "\n"; |
3420
|
|
|
return $output; |
3421
|
|
|
} |
3422
|
|
|
|
3423
|
|
|
/** |
3424
|
|
|
* Check if a BigBlueButtonBN is available to be used by the current user. |
3425
|
|
|
* |
3426
|
|
|
* @param stdClass $bigbluebuttonbn BigBlueButtonBN instance |
3427
|
|
|
* |
3428
|
|
|
* @return boolean status if room available and current user allowed to join |
3429
|
|
|
*/ |
3430
|
|
|
function bigbluebuttonbn_get_availability_status($bigbluebuttonbn) { |
3431
|
|
|
list($roomavailable) = bigbluebuttonbn_room_is_available($bigbluebuttonbn); |
3432
|
|
|
list($usercanjoin) = bigbluebuttonbn_user_can_join_meeting($bigbluebuttonbn); |
3433
|
|
|
return ($roomavailable && $usercanjoin); |
3434
|
|
|
} |
3435
|
|
|
|
3436
|
|
|
/** |
3437
|
|
|
* Helper for evaluating if scheduled activity is avaiable. |
3438
|
|
|
* |
3439
|
|
|
* @param stdClass $bigbluebuttonbn BigBlueButtonBN instance |
3440
|
|
|
* |
3441
|
|
|
* @return array status (room available or not and possible warnings) |
3442
|
|
|
*/ |
3443
|
|
|
function bigbluebuttonbn_room_is_available($bigbluebuttonbn) { |
3444
|
|
|
$open = true; |
3445
|
|
|
$closed = false; |
3446
|
|
|
$warnings = array(); |
3447
|
|
|
|
3448
|
|
|
$timenow = time(); |
3449
|
|
|
$timeopen = $bigbluebuttonbn->openingtime; |
3450
|
|
|
$timeclose = $bigbluebuttonbn->closingtime; |
3451
|
|
|
if (!empty($timeopen) && $timeopen > $timenow) { |
3452
|
|
|
$open = false; |
3453
|
|
|
} |
3454
|
|
|
if (!empty($timeclose) && $timenow > $timeclose) { |
3455
|
|
|
$closed = true; |
3456
|
|
|
} |
3457
|
|
|
|
3458
|
|
|
if (!$open || $closed) { |
3459
|
|
|
if (!$open) { |
3460
|
|
|
$warnings['notopenyet'] = userdate($timeopen); |
3461
|
|
|
} |
3462
|
|
|
if ($closed) { |
3463
|
|
|
$warnings['expired'] = userdate($timeclose); |
3464
|
|
|
} |
3465
|
|
|
return array(false, $warnings); |
3466
|
|
|
} |
3467
|
|
|
|
3468
|
|
|
return array(true, $warnings); |
3469
|
|
|
} |
3470
|
|
|
|
3471
|
|
|
/** |
3472
|
|
|
* Helper for evaluating if meeting can be joined. |
3473
|
|
|
* |
3474
|
|
|
* @param stdClass $bigbluebuttonbn BigBlueButtonBN instance |
3475
|
|
|
* @param string $mid |
3476
|
|
|
* @param integer $userid |
3477
|
|
|
* |
3478
|
|
|
* @return array status (user allowed to join or not and possible message) |
3479
|
|
|
*/ |
3480
|
|
|
function bigbluebuttonbn_user_can_join_meeting($bigbluebuttonbn, $mid = null, $userid = null) { |
3481
|
|
|
// By default, use a meetingid without groups. |
3482
|
|
|
if (empty($mid)) { |
3483
|
|
|
$mid = $bigbluebuttonbn->meetingid . '-' . $bigbluebuttonbn->course . '-' . $bigbluebuttonbn->id; |
3484
|
|
|
} |
3485
|
|
|
// When meeting is running, all authorized users can join right in. |
3486
|
|
|
if (bigbluebuttonbn_is_meeting_running($mid)) { |
3487
|
|
|
return array(true, get_string('view_message_conference_in_progress', 'bigbluebuttonbn')); |
3488
|
|
|
} |
3489
|
|
|
// When meeting is not running, see if the user can join. |
3490
|
|
|
$context = context_course::instance($bigbluebuttonbn->course); |
3491
|
|
|
$participantlist = bigbluebuttonbn_get_participant_list($bigbluebuttonbn, $context); |
3492
|
|
|
$isadmin = is_siteadmin($userid); |
3493
|
|
|
$ismoderator = bigbluebuttonbn_is_moderator($context, $participantlist, $userid); |
3494
|
|
|
// If user is administrator, moderator or if is viewer and no waiting is required, join allowed. |
3495
|
|
|
if ($isadmin || $ismoderator || !$bigbluebuttonbn->wait) { |
3496
|
|
|
return array(true, get_string('view_message_conference_room_ready', 'bigbluebuttonbn')); |
3497
|
|
|
} |
3498
|
|
|
// Otherwise, no join allowed. |
3499
|
|
|
return array(false, get_string('view_message_conference_wait_for_moderator', 'bigbluebuttonbn')); |
3500
|
|
|
} |
3501
|
|
|
|
3502
|
|
|
/** |
3503
|
|
|
* Helper for getting a value from a bigbluebuttonbn cache. |
3504
|
|
|
* |
3505
|
|
|
* @param string $name BigBlueButtonBN cache |
3506
|
|
|
* @param string $key Key to be retrieved |
3507
|
|
|
* @param integer $default Default value in case key is not found or it is empty |
3508
|
|
|
* |
3509
|
|
|
* @return variable key value |
3510
|
|
|
*/ |
3511
|
|
|
function bigbluebuttonbn_cache_get($name, $key, $default = null) { |
3512
|
|
|
$cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', $name); |
3513
|
|
|
$result = $cache->get($key); |
3514
|
|
|
if (!empty($result)) { |
3515
|
|
|
return $result; |
3516
|
|
|
} |
3517
|
|
|
return $default; |
3518
|
|
|
} |
3519
|
|
|
|
3520
|
|
|
/** |
3521
|
|
|
* Helper for setting a value in a bigbluebuttonbn cache. |
3522
|
|
|
* |
3523
|
|
|
* @param string $name BigBlueButtonBN cache |
3524
|
|
|
* @param string $key Key to be created/updated |
3525
|
|
|
* @param variable $value Default value to be set |
3526
|
|
|
*/ |
3527
|
|
|
function bigbluebuttonbn_cache_set($name, $key, $value) { |
3528
|
|
|
$cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', $name); |
3529
|
|
|
$cache->set($key, $value); |
3530
|
|
|
} |
3531
|
|
|
|
3532
|
|
|
/** |
3533
|
|
|
* Helper for getting the owner userid of a bigbluebuttonbn instance. |
3534
|
|
|
* |
3535
|
|
|
* @param stdClass $bigbluebuttonbn BigBlueButtonBN instance |
3536
|
|
|
* |
3537
|
|
|
* @return integer ownerid (a valid user id or null if not registered/found) |
3538
|
|
|
*/ |
3539
|
|
|
function bigbluebuttonbn_instance_ownerid($bigbluebuttonbn) { |
3540
|
|
|
global $DB; |
3541
|
|
|
$filters = array('bigbluebuttonbnid' => $bigbluebuttonbn->id, 'log' => 'Add'); |
3542
|
|
|
$ownerid = (integer) $DB->get_field('bigbluebuttonbn_logs', 'userid', $filters); |
3543
|
|
|
return $ownerid; |
3544
|
|
|
} |
3545
|
|
|
|
3546
|
|
|
/** |
3547
|
|
|
* Helper evaluates if the bigbluebutton server used belongs to blindsidenetworks domain. |
3548
|
|
|
* |
3549
|
|
|
* @return boolean |
3550
|
|
|
*/ |
3551
|
|
|
function bigbluebuttonbn_has_html5_client() { |
3552
|
|
|
$checkurl = \mod_bigbluebuttonbn\locallib\bigbluebutton::root() . "html5client/check"; |
3553
|
|
|
$curlinfo = bigbluebuttonbn_wrap_xml_load_file_curl_request($checkurl, 'HEAD'); |
3554
|
|
|
return (isset($curlinfo['http_code']) && $curlinfo['http_code'] == 200); |
3555
|
|
|
} |
3556
|
|
|
|
3557
|
|
|
/** |
3558
|
|
|
* Return the status of an activity [open|not_started|ended]. |
3559
|
|
|
* |
3560
|
|
|
* @param array $bbbsession |
3561
|
|
|
* @return string |
3562
|
|
|
*/ |
3563
|
|
View Code Duplication |
function bigbluebuttonbn_view_get_activity_status(&$bbbsession) { |
|
|
|
|
3564
|
|
|
$now = time(); |
3565
|
|
|
if (!empty($bbbsession['bigbluebuttonbn']->openingtime) && $now < $bbbsession['bigbluebuttonbn']->openingtime) { |
3566
|
|
|
// The activity has not been opened. |
3567
|
|
|
return 'not_started'; |
3568
|
|
|
} |
3569
|
|
|
if (!empty($bbbsession['bigbluebuttonbn']->closingtime) && $now > $bbbsession['bigbluebuttonbn']->closingtime) { |
3570
|
|
|
// The activity has been closed. |
3571
|
|
|
return 'ended'; |
3572
|
|
|
} |
3573
|
|
|
// The activity is open. |
3574
|
|
|
return 'open'; |
3575
|
|
|
} |
3576
|
|
|
|
3577
|
|
|
/** |
3578
|
|
|
* Set session URLs. |
3579
|
|
|
* |
3580
|
|
|
* @param array $bbbsession |
3581
|
|
|
* @param int $id |
3582
|
|
|
* @return string |
3583
|
|
|
*/ |
3584
|
|
|
function bigbluebuttonbn_view_session_config(&$bbbsession, $id) { |
3585
|
|
|
// Operation URLs. |
3586
|
|
|
$bbbsession['bigbluebuttonbnURL'] = plugin::necurl( |
3587
|
|
|
'/mod/bigbluebuttonbn/view.php', |
3588
|
|
|
['id' => $bbbsession['cm']->id] |
3589
|
|
|
); |
3590
|
|
|
$bbbsession['logoutURL'] = plugin::necurl( |
3591
|
|
|
'/mod/bigbluebuttonbn/bbb_view.php', |
3592
|
|
|
['action' => 'logout', 'id' => $id, 'bn' => $bbbsession['bigbluebuttonbn']->id] |
3593
|
|
|
); |
3594
|
|
|
$bbbsession['recordingReadyURL'] = plugin::necurl( |
3595
|
|
|
'/mod/bigbluebuttonbn/bbb_broker.php', |
3596
|
|
|
['action' => 'recording_ready', 'bigbluebuttonbn' => $bbbsession['bigbluebuttonbn']->id] |
3597
|
|
|
); |
3598
|
|
|
$bbbsession['meetingEventsURL'] = plugin::necurl( |
3599
|
|
|
'/mod/bigbluebuttonbn/bbb_broker.php', |
3600
|
|
|
['action' => 'meeting_events', 'bigbluebuttonbn' => $bbbsession['bigbluebuttonbn']->id] |
3601
|
|
|
); |
3602
|
|
|
$bbbsession['joinURL'] = plugin::necurl( |
3603
|
|
|
'/mod/bigbluebuttonbn/bbb_view.php', |
3604
|
|
|
['action' => 'join', 'id' => $id, 'bn' => $bbbsession['bigbluebuttonbn']->id] |
3605
|
|
|
); |
3606
|
|
|
|
3607
|
|
|
// Check status and set extra values. |
3608
|
|
|
$activitystatus = bigbluebuttonbn_view_get_activity_status($bbbsession); // In locallib. |
3609
|
|
View Code Duplication |
if ($activitystatus == 'ended') { |
|
|
|
|
3610
|
|
|
$bbbsession['presentation'] = bigbluebuttonbn_get_presentation_array( |
3611
|
|
|
$bbbsession['context'], |
3612
|
|
|
$bbbsession['bigbluebuttonbn']->presentation |
3613
|
|
|
); |
3614
|
|
|
} else if ($activitystatus == 'open') { |
3615
|
|
|
$bbbsession['presentation'] = bigbluebuttonbn_get_presentation_array( |
3616
|
|
|
$bbbsession['context'], |
3617
|
|
|
$bbbsession['bigbluebuttonbn']->presentation, |
3618
|
|
|
$bbbsession['bigbluebuttonbn']->id |
3619
|
|
|
); |
3620
|
|
|
} |
3621
|
|
|
|
3622
|
|
|
return $activitystatus; |
3623
|
|
|
} |
3624
|
|
|
|
3625
|
|
|
/** |
3626
|
|
|
* Helper for preparing metadata used while creating the meeting. |
3627
|
|
|
* |
3628
|
|
|
* @param array $bbbsession |
3629
|
|
|
* @return array |
3630
|
|
|
*/ |
3631
|
|
|
function bigbluebuttonbn_create_meeting_metadata(&$bbbsession) { |
3632
|
|
|
global $USER; |
3633
|
|
|
// Create standard metadata. |
3634
|
|
|
$metadata = [ |
3635
|
|
|
'bbb-origin' => $bbbsession['origin'], |
3636
|
|
|
'bbb-origin-version' => $bbbsession['originVersion'], |
3637
|
|
|
'bbb-origin-server-name' => $bbbsession['originServerName'], |
3638
|
|
|
'bbb-origin-server-common-name' => $bbbsession['originServerCommonName'], |
3639
|
|
|
'bbb-origin-tag' => $bbbsession['originTag'], |
3640
|
|
|
'bbb-context' => $bbbsession['course']->fullname, |
3641
|
|
|
'bbb-context-id' => $bbbsession['course']->id, |
3642
|
|
|
'bbb-context-name' => trim(html_to_text($bbbsession['course']->fullname, 0)), |
3643
|
|
|
'bbb-context-label' => trim(html_to_text($bbbsession['course']->shortname, 0)), |
3644
|
|
|
'bbb-recording-name' => bigbluebuttonbn_html2text($bbbsession['meetingname'], 64), |
3645
|
|
|
'bbb-recording-description' => bigbluebuttonbn_html2text($bbbsession['meetingdescription'], 64), |
3646
|
|
|
'bbb-recording-tags' => bigbluebuttonbn_get_tags($bbbsession['cm']->id), // Same as $id. |
3647
|
|
|
]; |
3648
|
|
|
// Special metadata for recording processing. |
3649
|
|
|
if ((boolean) \mod_bigbluebuttonbn\locallib\config::get('recordingstatus_enabled')) { |
3650
|
|
|
$metadata["bn-recording-status"] = json_encode( |
3651
|
|
|
array( |
3652
|
|
|
'email' => array('"' . fullname($USER) . '" <' . $USER->email . '>'), |
3653
|
|
|
'context' => $bbbsession['bigbluebuttonbnURL'], |
3654
|
|
|
) |
3655
|
|
|
); |
3656
|
|
|
} |
3657
|
|
|
if ((boolean) \mod_bigbluebuttonbn\locallib\config::get('recordingready_enabled')) { |
3658
|
|
|
$metadata['bn-recording-ready-url'] = $bbbsession['recordingReadyURL']; |
3659
|
|
|
} |
3660
|
|
|
if ((boolean) \mod_bigbluebuttonbn\locallib\config::get('meetingevents_enabled')) { |
3661
|
|
|
$metadata['analytics-callback-url'] = $bbbsession['meetingEventsURL']; |
3662
|
|
|
} |
3663
|
|
|
return $metadata; |
3664
|
|
|
} |
3665
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.