forked from blindsidenetworks-ps/moodle-mod_bigbluebuttonbn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewlib.php
384 lines (368 loc) · 15.1 KB
/
viewlib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* View a BigBlueButton room.
*
* @package mod_bigbluebuttonbn
* @copyright 2010 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com)
* @author Fred Dixon (ffdixon [at] blindsidenetworks [dt] com)
* @author Darko Miletic (darko.miletic [at] gmail [dt] com)
*/
defined('MOODLE_INTERNAL') || die();
/**
* Displays the view for groups.
*
* @param array $bbbsession
* @return void
*/
function bigbluebuttonbn_view_groups(&$bbbsession) {
global $CFG;
// Find out current group mode.
$groupmode = groups_get_activity_groupmode($bbbsession['cm']);
if ($groupmode == NOGROUPS) {
// No groups mode.
return;
}
// Separate or visible group mode.
$groups = groups_get_activity_allowed_groups($bbbsession['cm']);
if (empty($groups)) {
// No groups in this course.
bigbluebuttonbn_view_message_box($bbbsession, get_string('view_groups_nogroups_warning', 'bigbluebuttonbn'), 'info', true);
return;
}
$bbbsession['group'] = groups_get_activity_group($bbbsession['cm'], true);
$groupname = get_string('allparticipants');
if ($bbbsession['group'] != 0) {
$groupname = groups_get_group_name($bbbsession['group']);
}
// Assign group default values.
$bbbsession['meetingid'] .= '['.$bbbsession['group'].']';
$bbbsession['meetingname'] .= ' ('.$groupname.')';
if (count($groups) == 0) {
// Only the All participants group exists.
bigbluebuttonbn_view_message_box($bbbsession, get_string('view_groups_notenrolled_warning', 'bigbluebuttonbn'), 'info');
return;
}
$context = context_module::instance($bbbsession['cm']->id);
if (has_capability('moodle/site:accessallgroups', $context)) {
bigbluebuttonbn_view_message_box($bbbsession, get_string('view_groups_selection_warning', 'bigbluebuttonbn'));
}
$urltoroot = $CFG->wwwroot.'/mod/bigbluebuttonbn/view.php?id='.$bbbsession['cm']->id;
groups_print_activity_menu($bbbsession['cm'], $urltoroot);
echo '<br><br>';
}
/**
* Displays the view for messages.
*
* @param array $bbbsession
* @param string $message
* @param string $type
* @param boolean $onlymoderator
* @return void
*/
function bigbluebuttonbn_view_message_box(&$bbbsession, $message, $type = 'warning', $onlymoderator = false) {
global $OUTPUT;
if ($onlymoderator && !$bbbsession['moderator'] && !$bbbsession['administrator']) {
return;
}
echo $OUTPUT->box_start('generalbox boxaligncenter');
echo '<br><div class="alert alert-' . $type . '">' . $message . '</div>';
echo $OUTPUT->box_end();
}
/**
* Displays the general view.
*
* @param array $bbbsession
* @param string $activity
* @return void
*/
function bigbluebuttonbn_view_render(&$bbbsession, $activity) {
global $OUTPUT, $PAGE;
$type = null;
if (isset($bbbsession['bigbluebuttonbn']->type)) {
$type = $bbbsession['bigbluebuttonbn']->type;
}
$typeprofiles = bigbluebuttonbn_get_instance_type_profiles();
$enabledfeatures = bigbluebuttonbn_get_enabled_features($typeprofiles, $type);
$pinginterval = (int)\mod_bigbluebuttonbn\locallib\config::get('waitformoderator_ping_interval') * 1000;
// JavaScript for locales.
$PAGE->requires->strings_for_js(array_keys(bigbluebuttonbn_get_strings_for_js()), 'bigbluebuttonbn');
// JavaScript variables.
$jsvars = array('activity' => $activity, 'ping_interval' => $pinginterval,
'locale' => bigbluebuttonbn_get_localcode(), 'profile_features' => $typeprofiles[0]['features']);
$output = '';
// Renders warning messages when configured.
$output .= bigbluebuttonbn_view_warning_default_server($bbbsession);
$output .= bigbluebuttonbn_view_warning_general($bbbsession);
// Renders the rest of the page.
// Renders the completed description.
$desc = file_rewrite_pluginfile_urls($bbbsession['meetingdescription'], 'pluginfile.php',
$bbbsession['context']->id, 'mod_bigbluebuttonbn', 'intro', null);
$output .= $OUTPUT->heading($desc, 5);
if ($enabledfeatures['showroom']) {
$output .= bigbluebuttonbn_view_render_room($bbbsession, $activity, $jsvars);
$PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-rooms',
'M.mod_bigbluebuttonbn.rooms.init', array($jsvars));
}
if ($enabledfeatures['showrecordings']) {
$output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings'));
$output .= bigbluebuttonbn_view_render_recording_section($bbbsession, $type, $enabledfeatures, $jsvars);
$output .= html_writer::end_tag('div');
$PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-recordings',
'M.mod_bigbluebuttonbn.recordings.init', array($jsvars));
} else if ($type == BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY) {
$recordingsdisabled = get_string('view_message_recordings_disabled', 'bigbluebuttonbn');
$output .= bigbluebuttonbn_render_warning($recordingsdisabled, 'danger');
}
echo $output.html_writer::empty_tag('br').html_writer::empty_tag('br').html_writer::empty_tag('br');
$PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-broker', 'M.mod_bigbluebuttonbn.broker.init', array($jsvars));
}
/**
* Renders the view for recordings.
*
* @param array $bbbsession
* @param integer $type
* @param array $enabledfeatures
* @param array $jsvars
* @return string
*/
function bigbluebuttonbn_view_render_recording_section(&$bbbsession, $type, $enabledfeatures, &$jsvars) {
if ($type == BIGBLUEBUTTONBN_TYPE_ROOM_ONLY) {
return '';
}
$output = '';
if ($type == BIGBLUEBUTTONBN_TYPE_ALL && $bbbsession['record']) {
$output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_header'));
$output .= html_writer::tag('h4', get_string('view_section_title_recordings', 'bigbluebuttonbn'));
$output .= html_writer::end_tag('div');
}
if ($type == BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY || $bbbsession['record']) {
$output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_content'));
$output .= bigbluebuttonbn_view_render_recordings($bbbsession, $enabledfeatures, $jsvars);
$output .= html_writer::end_tag('div');
$output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_footer'));
$output .= bigbluebuttonbn_view_render_imported($bbbsession, $enabledfeatures);
$output .= html_writer::end_tag('div');
}
return $output;
}
/**
* Evaluates if the warning box should be shown.
*
* @param array $bbbsession
*
* @return boolean
*/
function bigbluebuttonbn_view_warning_shown($bbbsession) {
if (is_siteadmin($bbbsession['userID'])) {
return true;
}
$generalwarningroles = explode(',', \mod_bigbluebuttonbn\locallib\config::get('general_warning_roles'));
$userroles = bigbluebuttonbn_get_user_roles($bbbsession['context'], $bbbsession['userID']);
foreach ($userroles as $userrole) {
if (in_array($userrole->shortname, $generalwarningroles)) {
return true;
}
}
return false;
}
/**
* Renders the view for room.
*
* @param array $bbbsession
* @param string $activity
* @param array $jsvars
*
* @return string
*/
function bigbluebuttonbn_view_render_room(&$bbbsession, $activity, &$jsvars) {
global $OUTPUT;
// JavaScript variables for room.
$openingtime = '';
if ($bbbsession['openingtime']) {
$openingtime = get_string('mod_form_field_openingtime', 'bigbluebuttonbn').': '.
userdate($bbbsession['openingtime']);
}
$closingtime = '';
if ($bbbsession['closingtime']) {
$closingtime = get_string('mod_form_field_closingtime', 'bigbluebuttonbn').': '.
userdate($bbbsession['closingtime']);
}
$jsvars += array(
'meetingid' => $bbbsession['meetingid'],
'bigbluebuttonbnid' => $bbbsession['bigbluebuttonbn']->id,
'userlimit' => $bbbsession['userlimit'],
'opening' => $openingtime,
'closing' => $closingtime,
);
// Main box.
$output = $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_message_box');
$output .= '<br><span id="status_bar"></span>';
$output .= '<br><span id="control_panel"></span>';
$output .= $OUTPUT->box_end();
// Action button box.
$output .= $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_action_button_box');
$output .= '<br><br><span id="join_button"></span> <span id="end_button"></span>'."\n";
$output .= $OUTPUT->box_end();
if ($activity == 'ended') {
$output .= bigbluebuttonbn_view_ended($bbbsession);
}
return $output;
}
/**
* Renders the view for recordings.
*
* @param array $bbbsession
* @param array $enabledfeatures
* @param array $jsvars
*
* @return string
*/
function bigbluebuttonbn_view_render_recordings(&$bbbsession, $enabledfeatures, &$jsvars) {
$bigbluebuttonbnid = null;
if ($enabledfeatures['showroom']) {
$bigbluebuttonbnid = $bbbsession['bigbluebuttonbn']->id;
}
// Get recordings.
$recordings = bigbluebuttonbn_get_recordings(
$bbbsession['course']->id, $bigbluebuttonbnid, $enabledfeatures['showroom'],
$bbbsession['bigbluebuttonbn']->recordings_deleted
);
if ($enabledfeatures['importrecordings']) {
// Get recording links.
$bigbluebuttonbnid = $bbbsession['bigbluebuttonbn']->id;
$recordingsimported = bigbluebuttonbn_get_recordings_imported_array(
$bbbsession['course']->id, $bigbluebuttonbnid, true
);
/* Perform aritmetic addition instead of merge so the imported recordings corresponding to existent
* recordings are not included. */
if ($bbbsession['bigbluebuttonbn']->recordings_imported) {
$recordings = $recordingsimported;
} else {
$recordings += $recordingsimported;
}
}
if (empty($recordings) || array_key_exists('messageKey', $recordings)) {
// There are no recordings to be shown.
return html_writer::div(get_string('view_message_norecordings', 'bigbluebuttonbn'), '',
array('id' => 'bigbluebuttonbn_recordings_table'));
}
// There are recordings for this meeting.
// JavaScript variables for recordings.
$jsvars += array(
'recordings_html' => $bbbsession['bigbluebuttonbn']->recordings_html == '1',
);
// If there are meetings with recordings load the data to the table.
if ($bbbsession['bigbluebuttonbn']->recordings_html) {
// Render a plain html table.
return bigbluebuttonbn_output_recording_table($bbbsession, $recordings)."\n";
}
// JavaScript variables for recordings with YUI.
$jsvars += array(
'columns' => bigbluebuttonbn_get_recording_columns($bbbsession),
'data' => bigbluebuttonbn_get_recording_data($bbbsession, $recordings),
);
// Render a YUI table.
$reset = get_string('reset');
$search = get_string('search');
$output = "<form id='bigbluebuttonbn_recordings_searchform'>
<input id='searchtext' type='text'>
<input id='searchsubmit' type='submit' value='{$search}'>
<input id='searchreset' type='submit' value='{$reset}'>
</form>";
$output .= html_writer::div('', '', array('id' => 'bigbluebuttonbn_recordings_table'));
return $output;
}
/**
* Renders the view for importing recordings.
*
* @param array $bbbsession
* @param array $enabledfeatures
*
* @return string
*/
function bigbluebuttonbn_view_render_imported($bbbsession, $enabledfeatures) {
global $CFG;
if (!$enabledfeatures['importrecordings'] || !$bbbsession['importrecordings']) {
return '';
}
$button = html_writer::tag('input', '',
array('type' => 'button',
'value' => get_string('view_recording_button_import', 'bigbluebuttonbn'),
'class' => 'btn btn-secondary',
'onclick' => 'window.location=\''.$CFG->wwwroot.'/mod/bigbluebuttonbn/import_view.php?bn='.
$bbbsession['bigbluebuttonbn']->id.'\''));
$output = html_writer::empty_tag('br');
$output .= html_writer::tag('span', $button, array('id' => 'import_recording_links_button'));
$output .= html_writer::tag('span', '', array('id' => 'import_recording_links_table'));
return $output;
}
/**
* Renders the content for ended meeting.
*
* @param array $bbbsession
*
* @return string
*/
function bigbluebuttonbn_view_ended(&$bbbsession) {
global $OUTPUT;
if (!is_null($bbbsession['presentation']['url'])) {
$attributes = array('title' => $bbbsession['presentation']['name']);
$icon = new pix_icon($bbbsession['presentation']['icon'], $bbbsession['presentation']['mimetype_description']);
return '<h4>'.get_string('view_section_title_presentation', 'bigbluebuttonbn').'</h4>'.
$OUTPUT->action_icon($bbbsession['presentation']['url'], $icon, null, array(), false).
$OUTPUT->action_link($bbbsession['presentation']['url'],
$bbbsession['presentation']['name'], null, $attributes).'<br><br>';
}
return '';
}
/**
* Renders a default server warning message when using test-install.
*
* @param array $bbbsession
*
* @return string
*/
function bigbluebuttonbn_view_warning_default_server(&$bbbsession) {
if (!is_siteadmin($bbbsession['userID'])) {
return '';
}
if (BIGBLUEBUTTONBN_DEFAULT_SERVER_URL != \mod_bigbluebuttonbn\locallib\config::get('server_url')) {
return '';
}
return bigbluebuttonbn_render_warning(get_string('view_warning_default_server', 'bigbluebuttonbn'), 'warning');
}
/**
* Renders a general warning message when it is configured.
*
* @param array $bbbsession
*
* @return string
*/
function bigbluebuttonbn_view_warning_general(&$bbbsession) {
if (!bigbluebuttonbn_view_warning_shown($bbbsession)) {
return '';
}
return bigbluebuttonbn_render_warning(
(string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_message'),
(string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_box_type'),
(string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_href'),
(string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_text'),
(string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_class')
);
}