Completed
Pull Request — master (#355)
by
unknown
02:01
created

viewlib.php ➔ bigbluebuttonbn_build_groups_session()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 6
nop 1
dl 0
loc 29
rs 9.1448
c 0
b 0
f 0
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
 * View a BigBlueButton room.
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
 * @author    Darko Miletic  (darko.miletic [at] gmail [dt] com)
26
 */
27
28
defined('MOODLE_INTERNAL') || die();
29
30
/**
31
 * Displays the view for groups.
32
 *
33
 * @param array $bbbsession
34
 * @return void
35
 */
36
function bigbluebuttonbn_view_groups(&$bbbsession) {
37
    global $CFG;
38
    // Find out current group mode.
39
    $groupmode = groups_get_activity_groupmode($bbbsession['cm']);
40
    if ($groupmode == NOGROUPS) {
41
        // No groups mode.
42
        return;
43
    }
44
    // Separate or visible group mode.
45
    $groups = groups_get_activity_allowed_groups($bbbsession['cm']);
46
    if (empty($groups)) {
47
        // No groups in this course.
48
        bigbluebuttonbn_view_message_box($bbbsession, get_string('view_groups_nogroups_warning', 'bigbluebuttonbn'), 'info', true);
49
        return;
50
    }
51
    $bbbsession['group'] = groups_get_activity_group($bbbsession['cm'], true);
52
    $groupname = get_string('allparticipants');
53
    if ($bbbsession['group'] != 0) {
54
        $groupname = groups_get_group_name($bbbsession['group']);
55
    }
56
    // Assign group default values.
57
    $bbbsession['meetingid'] .= '['.$bbbsession['group'].']';
58
    $bbbsession['meetingname'] .= ' ('.$groupname.')';
59
    if (count($groups) == 0) {
60
        // Only the All participants group exists.
61
        bigbluebuttonbn_view_message_box($bbbsession, get_string('view_groups_notenrolled_warning', 'bigbluebuttonbn'), 'info');
62
        return;
63
    }
64
    $context = context_module::instance($bbbsession['cm']->id);
65
    if (has_capability('moodle/site:accessallgroups', $context)) {
66
        bigbluebuttonbn_view_message_box($bbbsession, get_string('view_groups_selection_warning', 'bigbluebuttonbn'));
67
    }
68
    $urltoroot = $CFG->wwwroot.'/mod/bigbluebuttonbn/view.php?id='.$bbbsession['cm']->id;
69
    groups_print_activity_menu($bbbsession['cm'], $urltoroot);
70
    echo '<br><br>';
71
}
72
73
/**
74
 * Modify session according to the group information.
75
 *
76
 * @param array $bbbsession
77
 * @return void
78
 */
79
function bigbluebuttonbn_build_groups_session(&$bbbsession) {
80
    global $CFG;
81
    // Find out current group mode.
82
    $groupmode = groups_get_activity_groupmode($bbbsession['cm']);
83
    if ($groupmode == NOGROUPS) {
84
        // No groups mode.
85
        return;
86
    }
87
    // Separate or visible group mode.
88
    $groups = groups_get_activity_allowed_groups($bbbsession['cm']);
89
    if (empty($groups)) {
90
        // No groups in this course.
91
        return;
92
    }
93
    $bbbsession['group'] = groups_get_activity_group($bbbsession['cm'], true);
94
    $groupname = get_string('allparticipants');
95
    if ($bbbsession['group'] != 0) {
96
        $groupname = groups_get_group_name($bbbsession['group']);
97
    }
98
    // Assign group default values.
99
    $bbbsession['meetingid'] .= '['.$bbbsession['group'].']';
100
    $bbbsession['meetingname'] .= ' ('.$groupname.')';
101
    if (count($groups) == 0) {
102
        // Only the All participants group exists.
103
        return;
104
    }
105
    $context = context_module::instance($bbbsession['cm']->id);
0 ignored issues
show
Unused Code introduced by
$context is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
106
    $urltoroot = $CFG->wwwroot.'/mod/bigbluebuttonbn/view.php?id='.$bbbsession['cm']->id;
0 ignored issues
show
Unused Code introduced by
$urltoroot is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
107
}
108
109
/**
110
 * Displays the view for messages.
111
 *
112
 * @param array $bbbsession
113
 * @param string $message
114
 * @param string $type
115
 * @param boolean $onlymoderator
116
 * @return void
117
 */
118
function bigbluebuttonbn_view_message_box(&$bbbsession, $message, $type = 'warning', $onlymoderator = false) {
119
    global $OUTPUT;
120
    if ($onlymoderator && !$bbbsession['moderator'] && !$bbbsession['administrator']) {
121
        return;
122
    }
123
    echo $OUTPUT->box_start('generalbox boxaligncenter');
124
    echo '<br><div class="alert alert-' . $type . '">' . $message . '</div>';
125
    echo $OUTPUT->box_end();
126
}
127
128
/**
129
 * Displays the general view.
130
 *
131
 * @param array $bbbsession
132
 * @param string $activity
133
 * @return void
134
 */
135
function bigbluebuttonbn_view_render(&$bbbsession, $activity) {
136
    global $OUTPUT, $PAGE;
137
    $type = null;
138
    if (isset($bbbsession['bigbluebuttonbn']->type)) {
139
        $type = $bbbsession['bigbluebuttonbn']->type;
140
    }
141
    $typeprofiles = bigbluebuttonbn_get_instance_type_profiles();
142
    $enabledfeatures = bigbluebuttonbn_get_enabled_features($typeprofiles, $type);
143
    $pinginterval = (int)\mod_bigbluebuttonbn\locallib\config::get('waitformoderator_ping_interval') * 1000;
144
    // JavaScript for locales.
145
    $PAGE->requires->strings_for_js(array_keys(bigbluebuttonbn_get_strings_for_js()), 'bigbluebuttonbn');
146
    // JavaScript variables.
147
    $jsvars = array('activity' => $activity, 'ping_interval' => $pinginterval,
148
        'locale' => bigbluebuttonbn_get_localcode(), 'profile_features' => $typeprofiles[0]['features']);
149
    $output  = '';
150
    // Renders warning messages when configured.
151
    $output .= bigbluebuttonbn_view_warning_default_server($bbbsession);
152
    $output .= bigbluebuttonbn_view_warning_general($bbbsession);
153
154
    // Renders the rest of the page.
155
    $output .= $OUTPUT->heading($bbbsession['meetingname'], 3);
156
    // Renders the completed description.
157
    $desc = file_rewrite_pluginfile_urls($bbbsession['meetingdescription'], 'pluginfile.php',
158
        $bbbsession['context']->id, 'mod_bigbluebuttonbn', 'intro', null);
159
    $output .= $OUTPUT->heading($desc, 5);
160
161
    if ($enabledfeatures['showroom']) {
162
        $output .= bigbluebuttonbn_view_render_room($bbbsession, $activity, $jsvars);
163
        $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-rooms',
164
            'M.mod_bigbluebuttonbn.rooms.init', array($jsvars));
165
    }
166
    // Show recordings should only be enabled if recordings are also enabled in session.
167
    if ($enabledfeatures['showrecordings'] && $bbbsession['record']) {
168
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings'));
169
        $output .= "<i class='icon fa fa-spinner fa-spin' aria-hidden='true'></i> Loading Recordings ...";
170
        $output .= html_writer::end_tag('div');
171
        $output .= html_writer::start_tag('script', array('language' => 'javascript'));
172
        $id = $bbbsession['cm']->id;
173
        $group = isset($bbbsession['group']) ? $bbbsession['group'] : 0;
174
        $js = "jQuery(document).ready(function(){"
175
                . "jQuery.get('recordings.php?id=$id&group=$group', function(data) { "
176
                . "jQuery('#bigbluebuttonbn_view_recordings').html(data);"
177
                . "Y.use('moodle-mod_bigbluebuttonbn-recordings',function() {M.mod_bigbluebuttonbn.recordings.init({'bbbid': '" . $bbbsession['bigbluebuttonbn']->id . "'})});"
178
                . "});"
179
                . "})";
180
        $output .= html_writer::end_tag('script');
181
        $PAGE->requires->js_amd_inline($js);
182
    } else if ($type == BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY) {
183
        $recordingsdisabled = get_string('view_message_recordings_disabled', 'bigbluebuttonbn');
184
        $output .= bigbluebuttonbn_render_warning($recordingsdisabled, 'danger');
185
    }
186
    echo $output.html_writer::empty_tag('br').html_writer::empty_tag('br').html_writer::empty_tag('br');
187
    $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-broker', 'M.mod_bigbluebuttonbn.broker.init', array($jsvars));
188
}
189
190
/**
191
 * Displays the recordings view.
192
 *
193
 * @param array $bbbsession
194
 * @param string $activity
195
 * @return void
196
 */
197
function bigbluebuttonbn_view_render_recordings_ajax(&$bbbsession, $activity) {
198
    global $OUTPUT, $PAGE;
199
    $type = null;
200
    if (isset($bbbsession['bigbluebuttonbn']->type)) {
201
        $type = $bbbsession['bigbluebuttonbn']->type;
202
    }
203
    $typeprofiles = bigbluebuttonbn_get_instance_type_profiles();
204
    $enabledfeatures = bigbluebuttonbn_get_enabled_features($typeprofiles, $type);
205
    $pinginterval = (int)\mod_bigbluebuttonbn\locallib\config::get('waitformoderator_ping_interval') * 1000;
206
    // JavaScript for locales.
207
    $PAGE->requires->strings_for_js(array_keys(bigbluebuttonbn_get_strings_for_js()), 'bigbluebuttonbn');
208
    // JavaScript variables.
209
    $jsvars = array('activity' => $activity, 'ping_interval' => $pinginterval,
210
        'locale' => bigbluebuttonbn_get_localcode(), 'profile_features' => $typeprofiles[0]['features'],
211
        'meetingid' => $bbbsession['meetingid'],
212
        'bigbluebuttonbnid' => $bbbsession['bigbluebuttonbn']->id,
213
        'userlimit' => $bbbsession['userlimit'],
214
        'opening' => $openingtime,
0 ignored issues
show
Bug introduced by
The variable $openingtime does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
215
        'closing' => $closingtime,
0 ignored issues
show
Bug introduced by
The variable $closingtime does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
216
    );
217
218
    $output  = '';
219
220
    $output .= bigbluebuttonbn_view_render_recording_section($bbbsession, $type, $enabledfeatures, $jsvars);
221
    echo $output.html_writer::empty_tag('br').html_writer::empty_tag('br').html_writer::empty_tag('br');
222
    $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-recordings',
223
            'M.mod_bigbluebuttonbn.recordings.init', array($jsvars));
224
}
225
226
/**
227
 * Renders the view for recordings.
228
 *
229
 * @param array $bbbsession
230
 * @param integer $type
231
 * @param array $enabledfeatures
232
 * @param array $jsvars
233
 * @return string
234
 */
235
function bigbluebuttonbn_view_render_recording_section(&$bbbsession, $type, $enabledfeatures, &$jsvars) {
236
    if ($type == BIGBLUEBUTTONBN_TYPE_ROOM_ONLY) {
237
        return '';
238
    }
239
    $output = '';
240
    if ($type == BIGBLUEBUTTONBN_TYPE_ALL && $bbbsession['record']) {
241
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_header'));
242
        $output .= html_writer::tag('h4', get_string('view_section_title_recordings', 'bigbluebuttonbn'));
243
        $output .= html_writer::end_tag('div');
244
    }
245
    if ($type == BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY || $bbbsession['record']) {
246
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_content'));
247
        $output .= bigbluebuttonbn_view_render_recordings($bbbsession, $enabledfeatures, $jsvars);
248
        $output .= html_writer::end_tag('div');
249
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_footer'));
250
        $output .= bigbluebuttonbn_view_render_imported($bbbsession, $enabledfeatures);
251
        $output .= html_writer::end_tag('div');
252
    }
253
    return $output;
254
}
255
256
/**
257
 * Evaluates if the warning box should be shown.
258
 *
259
 * @param array $bbbsession
260
 *
261
 * @return boolean
262
 */
263
function bigbluebuttonbn_view_warning_shown($bbbsession) {
264
    if (is_siteadmin($bbbsession['userID'])) {
265
        return true;
266
    }
267
    $generalwarningroles = explode(',', \mod_bigbluebuttonbn\locallib\config::get('general_warning_roles'));
268
    $userroles = bigbluebuttonbn_get_user_roles($bbbsession['context'], $bbbsession['userID']);
269
    foreach ($userroles as $userrole) {
270
        if (in_array($userrole->shortname, $generalwarningroles)) {
271
            return true;
272
        }
273
    }
274
    return false;
275
}
276
277
/**
278
 * Renders the view for room.
279
 *
280
 * @param array $bbbsession
281
 * @param string $activity
282
 * @param array $jsvars
283
 *
284
 * @return string
285
 */
286
function bigbluebuttonbn_view_render_room(&$bbbsession, $activity, &$jsvars) {
287
    global $OUTPUT;
288
    // JavaScript variables for room.
289
    $openingtime = '';
290
    if ($bbbsession['openingtime']) {
291
        $openingtime = get_string('mod_form_field_openingtime', 'bigbluebuttonbn').': '.
292
            userdate($bbbsession['openingtime']);
293
    }
294
    $closingtime = '';
295
    if ($bbbsession['closingtime']) {
296
        $closingtime = get_string('mod_form_field_closingtime', 'bigbluebuttonbn').': '.
297
            userdate($bbbsession['closingtime']);
298
    }
299
    $jsvars += array(
300
        'meetingid' => $bbbsession['meetingid'],
301
        'bigbluebuttonbnid' => $bbbsession['bigbluebuttonbn']->id,
302
        'userlimit' => $bbbsession['userlimit'],
303
        'opening' => $openingtime,
304
        'closing' => $closingtime,
305
    );
306
    // Main box.
307
    $output  = $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_message_box');
308
    $output .= '<br><span id="status_bar"></span>';
309
    $output .= '<br><span id="control_panel"></span>';
310
    $output .= $OUTPUT->box_end();
311
    // Action button box.
312
    $output .= $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_action_button_box');
313
    $output .= '<br><br><span id="join_button"></span>&nbsp;<span id="end_button"></span>'."\n";
314
    $output .= $OUTPUT->box_end();
315
    if ($activity == 'ended') {
316
        $output .= bigbluebuttonbn_view_ended($bbbsession);
317
    }
318
    return $output;
319
}
320
321
/**
322
 * Renders the view for recordings.
323
 *
324
 * @param array $bbbsession
325
 * @param array $enabledfeatures
326
 * @param array $jsvars
327
 *
328
 * @return string
329
 */
330
function bigbluebuttonbn_view_render_recordings(&$bbbsession, $enabledfeatures, &$jsvars) {
331
    $recordings = bigbluebutton_get_recordings_for_table_view($bbbsession, $enabledfeatures);
332
333
    if (empty($recordings) || array_key_exists('messageKey', $recordings)) {
334
        // There are no recordings to be shown.
335
        return html_writer::div(get_string('view_message_norecordings', 'bigbluebuttonbn'), '',
336
            array('id' => 'bigbluebuttonbn_recordings_table'));
337
    }
338
    // There are recordings for this meeting.
339
    // JavaScript variables for recordings.
340
    $jsvars += array(
341
        'recordings_html' => $bbbsession['bigbluebuttonbn']->recordings_html == '1',
342
    );
343
    // If there are meetings with recordings load the data to the table.
344
    if ($bbbsession['bigbluebuttonbn']->recordings_html) {
345
        // Render a plain html table.
346
        return bigbluebuttonbn_output_recording_table($bbbsession, $recordings)."\n";
347
    }
348
    // JavaScript variables for recordings with YUI.
349
    $jsvars += array(
350
        'bbbid' => $bbbsession['bigbluebuttonbn']->id,
351
    );
352
    // Render a YUI table.
353
    $reset = get_string('reset');
354
    $search = get_string('search');
355
    $output = "<form id='bigbluebuttonbn_recordings_searchform'>
356
                 <input id='searchtext' type='text'>
357
                 <input id='searchsubmit' type='submit' value='{$search}'>
358
                 <input id='searchreset' type='submit' value='{$reset}'>
359
               </form>";
360
    $output .= html_writer::div('', '', array('id' => 'bigbluebuttonbn_recordings_table'));
361
362
    return $output;
363
}
364
365
/**
366
 * Renders the view for importing recordings.
367
 *
368
 * @param array $bbbsession
369
 * @param array $enabledfeatures
370
 *
371
 * @return string
372
 */
373
function bigbluebuttonbn_view_render_imported($bbbsession, $enabledfeatures) {
374
    global $CFG;
375
    if (!$enabledfeatures['importrecordings'] || !$bbbsession['importrecordings']) {
376
        return '';
377
    }
378
    $button = html_writer::tag('input', '',
379
        array('type' => 'button',
380
            'value' => get_string('view_recording_button_import', 'bigbluebuttonbn'),
381
            'class' => 'btn btn-secondary',
382
            'onclick' => 'window.location=\''.$CFG->wwwroot.'/mod/bigbluebuttonbn/import_view.php?bn='.
383
                $bbbsession['bigbluebuttonbn']->id.'\''));
384
    $output  = html_writer::empty_tag('br');
385
    $output .= html_writer::tag('span', $button, array('id' => 'import_recording_links_button'));
386
    $output .= html_writer::tag('span', '', array('id' => 'import_recording_links_table'));
387
    return $output;
388
}
389
390
/**
391
 * Renders the content for ended meeting.
392
 *
393
 * @param array $bbbsession
394
 *
395
 * @return string
396
 */
397
function bigbluebuttonbn_view_ended(&$bbbsession) {
398
    global $OUTPUT;
399
    if (!is_null($bbbsession['presentation']['url'])) {
400
        $attributes = array('title' => $bbbsession['presentation']['name']);
401
        $icon = new pix_icon($bbbsession['presentation']['icon'], $bbbsession['presentation']['mimetype_description']);
402
        return '<h4>'.get_string('view_section_title_presentation', 'bigbluebuttonbn').'</h4>'.
403
            $OUTPUT->action_icon($bbbsession['presentation']['url'], $icon, null, array(), false).
404
            $OUTPUT->action_link($bbbsession['presentation']['url'],
405
                $bbbsession['presentation']['name'], null, $attributes).'<br><br>';
406
    }
407
    return '';
408
}
409
410
/**
411
 * Renders a default server warning message when using test-install.
412
 *
413
 * @param array $bbbsession
414
 *
415
 * @return string
416
 */
417
function bigbluebuttonbn_view_warning_default_server(&$bbbsession) {
418
    if (!is_siteadmin($bbbsession['userID'])) {
419
        return '';
420
    }
421
    if (BIGBLUEBUTTONBN_DEFAULT_SERVER_URL != \mod_bigbluebuttonbn\locallib\config::get('server_url')) {
422
        return '';
423
    }
424
    return bigbluebuttonbn_render_warning(get_string('view_warning_default_server', 'bigbluebuttonbn'), 'warning');
425
}
426
427
/**
428
 * Renders a general warning message when it is configured.
429
 *
430
 * @param array $bbbsession
431
 *
432
 * @return string
433
 */
434
function bigbluebuttonbn_view_warning_general(&$bbbsession) {
435
    if (!bigbluebuttonbn_view_warning_shown($bbbsession)) {
436
        return '';
437
    }
438
    return bigbluebuttonbn_render_warning(
439
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_message'),
440
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_box_type'),
441
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_href'),
442
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_text'),
443
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_class')
444
    );
445
}
446