Completed
Pull Request — master (#85)
by
unknown
04:51 queued 02:52
created

view.php ➔ bigbluebuttonbn_view_render()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 12
nop 2
dl 0
loc 39
rs 8.9848
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
 */
26
27
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
28
require_once(dirname(__FILE__).'/locallib.php');
29
30
$id = required_param('id', PARAM_INT);
31
$bn = optional_param('bn', 0, PARAM_INT);
32
$group = optional_param('group', 0, PARAM_INT);
33
34
$viewinstance = bigbluebuttonbn_view_validator($id, $bn);
35
if (!$viewinstance) {
36
    print_error(get_string('view_error_url_missing_parameters', 'bigbluebuttonbn'));
37
}
38
39
$cm = $viewinstance['cm'];
40
$course = $viewinstance['course'];
41
$bigbluebuttonbn = $viewinstance['bigbluebuttonbn'];
42
$context = context_module::instance($cm->id);
43
44
require_login($course, true, $cm);
45
46
bigbluebuttonbn_event_log(\mod_bigbluebuttonbn\event\events::$events['view'], $bigbluebuttonbn);
47
48
// Additional info related to the course.
49
$bbbsession['course'] = $course;
50
$bbbsession['coursename'] = $course->fullname;
51
$bbbsession['cm'] = $cm;
52
$bbbsession['bigbluebuttonbn'] = $bigbluebuttonbn;
53
bigbluebuttonbn_view_bbbsession_set($context, $bbbsession);
54
55
// Validates if the BigBlueButton server is working.
56
$serverversion = bigbluebuttonbn_get_server_version();
57 View Code Duplication
if (is_null($serverversion)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    if ($bbbsession['administrator']) {
59
        print_error('view_error_unable_join', 'bigbluebuttonbn',
60
            $CFG->wwwroot.'/admin/settings.php?section=modsettingbigbluebuttonbn');
61
        exit;
62
    }
63
    if ($bbbsession['moderator']) {
64
        print_error('view_error_unable_join_teacher', 'bigbluebuttonbn',
65
            $CFG->wwwroot.'/course/view.php?id='.$bigbluebuttonbn->course);
66
        exit;
67
    }
68
    print_error('view_error_unable_join_student', 'bigbluebuttonbn',
69
        $CFG->wwwroot.'/course/view.php?id='.$bigbluebuttonbn->course);
70
    exit;
71
}
72
$bbbsession['serverversion'] = (string) $serverversion;
73
74
// Mark viewed by user (if required).
75
$completion = new completion_info($course);
76
$completion->set_module_viewed($cm);
77
78
// Print the page header.
79
$PAGE->set_context($context);
80
$PAGE->set_url($CFG->wwwroot.'/mod/bigbluebuttonbn/view.php', array('id' => $cm->id));
81
$PAGE->set_title(format_string($bigbluebuttonbn->name));
82
$PAGE->set_cacheable(false);
83
$PAGE->set_heading($course->fullname);
84
$PAGE->set_pagelayout('incourse');
85
86
// Validate if the user is in a role allowed to join.
87
if (!has_capability('moodle/category:manage', $context) && !has_capability('mod/bigbluebuttonbn:join', $context)) {
88
    echo $OUTPUT->header();
89
    if (isguestuser()) {
90
        echo $OUTPUT->confirm('<p>'.get_string('view_noguests', 'bigbluebuttonbn').'</p>'.get_string('liketologin'),
91
            get_login_url(), $CFG->wwwroot.'/course/view.php?id='.$course->id);
92
    } else {
93
        echo $OUTPUT->confirm('<p>'.get_string('view_nojoin', 'bigbluebuttonbn').'</p>'.get_string('liketologin'),
94
            get_login_url(), $CFG->wwwroot.'/course/view.php?id='.$course->id);
95
    }
96
    echo $OUTPUT->footer();
97
    exit;
98
}
99
100
// Operation URLs.
101
$bbbsession['bigbluebuttonbnURL'] = $CFG->wwwroot . '/mod/bigbluebuttonbn/view.php?id=' . $bbbsession['cm']->id;
102
$bbbsession['logoutURL'] = $CFG->wwwroot . '/mod/bigbluebuttonbn/bbb_view.php?action=logout&id='.$id .
103
    '&bn=' . $bbbsession['bigbluebuttonbn']->id;
104
$bbbsession['recordingReadyURL'] = $CFG->wwwroot . '/mod/bigbluebuttonbn/bbb_broker.php?action=recording_' .
105
    'ready&bigbluebuttonbn=' . $bbbsession['bigbluebuttonbn']->id;
106
$bbbsession['meetingEventsURL'] = $CFG->wwwroot . '/mod/bigbluebuttonbn/bbb_broker.php?action=meeting' .
107
    '_events&bigbluebuttonbn=' . $bbbsession['bigbluebuttonbn']->id;
108
$bbbsession['joinURL'] = $CFG->wwwroot . '/mod/bigbluebuttonbn/bbb_view.php?action=join&id=' . $id .
109
    '&bn=' . $bbbsession['bigbluebuttonbn']->id;
110
111
// Output starts.
112
echo $OUTPUT->header();
113
114
bigbluebuttonbn_view_groups($bbbsession);
115
116
bigbluebuttonbn_view_render($bbbsession, bigbluebuttonbn_view_get_activity_status($bbbsession));
117
118
// Output finishes.
119
echo $OUTPUT->footer();
120
121
// Shows version as a comment.
122
echo '<!-- '.$bbbsession['originTag'].' -->'."\n";
123
124
// Initialize session variable used across views.
125
$SESSION->bigbluebuttonbn_bbbsession = $bbbsession;
126
127
/**
128
 * Displays the view for groups.
129
 *
130
 * @param array $bbbsession
131
 * @return void
132
 */
133
function bigbluebuttonbn_view_groups(&$bbbsession) {
134
    global $CFG;
135
    // Find out current group mode.
136
    $groupmode = groups_get_activity_groupmode($bbbsession['cm']);
137
    if ($groupmode == NOGROUPS) {
138
        // No groups mode.
139
        return;
140
    }
141
    // Separate or visible group mode.
142
    $groups = groups_get_activity_allowed_groups($bbbsession['cm']);
143
    if (empty($groups)) {
144
        // No groups in this course.
145
        bigbluebuttonbn_view_message_box($bbbsession, get_string('view_groups_nogroups_warning', 'bigbluebuttonbn'), 'info', true);
146
        return;
147
    }
148
    $bbbsession['group'] = groups_get_activity_group($bbbsession['cm'], true);
149
    $groupname = get_string('allparticipants');
150
    if ($bbbsession['group'] != 0) {
151
        $groupname = groups_get_group_name($bbbsession['group']);
152
    }
153
    // Assign group default values.
154
    $bbbsession['meetingid'] .= '['.$bbbsession['group'].']';
155
    $bbbsession['meetingname'] .= ' ('.$groupname.')';
156
    if (count($groups) == 0) {
157
        // Only the All participants group exists.
158
        bigbluebuttonbn_view_message_box($bbbsession, get_string('view_groups_notenrolled_warning', 'bigbluebuttonbn'), 'info');
159
        return;
160
    }
161
    $context = context_module::instance($bbbsession['cm']->id);
162
    if (has_capability('moodle/site:accessallgroups', $context)) {
163
        bigbluebuttonbn_view_message_box($bbbsession, get_string('view_groups_selection_warning', 'bigbluebuttonbn'));
164
    }
165
    $urltoroot = $CFG->wwwroot.'/mod/bigbluebuttonbn/view.php?id='.$bbbsession['cm']->id;
166
    groups_print_activity_menu($bbbsession['cm'], $urltoroot);
167
    echo '<br><br>';
168
}
169
170
/**
171
 * Displays the view for messages.
172
 *
173
 * @param array $bbbsession
174
 * @param string $message
175
 * @param string $type
176
 * @param boolean $onlymoderator
177
 * @return void
178
 */
179
function bigbluebuttonbn_view_message_box(&$bbbsession, $message, $type = 'warning', $onlymoderator = false) {
180
    global $OUTPUT;
181
    if ($onlymoderator && !$bbbsession['moderator'] && !$bbbsession['administrator']) {
182
        return;
183
    }
184
    echo $OUTPUT->box_start('generalbox boxaligncenter');
185
    echo '<br><div class="alert alert-' . $type . '">' . $message . '</div>';
186
    echo $OUTPUT->box_end();
187
}
188
189
/**
190
 * Displays the general view.
191
 *
192
 * @param array $bbbsession
193
 * @param string $activity
194
 * @return void
195
 */
196
function bigbluebuttonbn_view_render(&$bbbsession, $activity) {
197
    global $OUTPUT, $PAGE;
198
    $type = null;
199
    if (isset($bbbsession['bigbluebuttonbn']->type)) {
200
        $type = $bbbsession['bigbluebuttonbn']->type;
201
    }
202
    $typeprofiles = bigbluebuttonbn_get_instance_type_profiles();
203
    $enabledfeatures = bigbluebuttonbn_get_enabled_features($typeprofiles, $type);
204
    $pinginterval = (int)\mod_bigbluebuttonbn\locallib\config::get('waitformoderator_ping_interval') * 1000;
205
    // JavaScript for locales.
206
    $PAGE->requires->strings_for_js(array_keys(bigbluebuttonbn_get_strings_for_js()), 'bigbluebuttonbn');
207
    // JavaScript variables.
208
    $jsvars = array('activity' => $activity, 'ping_interval' => $pinginterval,
209
        'locale' => bigbluebuttonbn_get_localcode(), 'profile_features' => $typeprofiles[0]['features']);
210
    $output  = '';
211
    // Renders warning messages when configured.
212
    $output .= bigbluebuttonbn_view_warning_default_server($bbbsession);
213
    $output .= bigbluebuttonbn_view_warning_general($bbbsession);
214
    // Renders the rest of the page.
215
    $output .= $OUTPUT->heading($bbbsession['meetingname'], 3);
216
    $output .= $OUTPUT->heading($bbbsession['meetingdescription'], 5);
217
    if ($enabledfeatures['showroom']) {
218
        $output .= bigbluebuttonbn_view_render_room($bbbsession, $activity, $jsvars);
219
        $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-rooms',
220
            'M.mod_bigbluebuttonbn.rooms.init', array($jsvars));
221
    }
222
    if ($enabledfeatures['showrecordings']) {
223
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings'));
224
        $output .= bigbluebuttonbn_view_render_recording_section($bbbsession, $type, $enabledfeatures, $jsvars);
225
        $output .= html_writer::end_tag('div');
226
        $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-recordings',
227
                'M.mod_bigbluebuttonbn.recordings.init', array($jsvars));
228
    } else if ($type == BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY) {
229
        $recordingsdisabled = get_string('view_message_recordings_disabled', 'bigbluebuttonbn');
230
        $output .= bigbluebuttonbn_render_warning($recordingsdisabled, 'danger');
231
    }
232
    echo $output.html_writer::empty_tag('br').html_writer::empty_tag('br').html_writer::empty_tag('br');
233
    $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-broker', 'M.mod_bigbluebuttonbn.broker.init', array($jsvars));
234
}
235
236
/**
237
 * Renders the view for recordings.
238
 *
239
 * @param array $bbbsession
240
 * @param integer $type
241
 * @param array $enabledfeatures
242
 * @param array $jsvars
243
 * @return string
244
 */
245
function bigbluebuttonbn_view_render_recording_section(&$bbbsession, $type, $enabledfeatures, &$jsvars) {
246
    if ($type == BIGBLUEBUTTONBN_TYPE_ROOM_ONLY) {
247
        return '';
248
    }
249
    $output = '';
250
    if ($type == BIGBLUEBUTTONBN_TYPE_ALL && $bbbsession['record']) {
251
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_header'));
252
        $output .= html_writer::tag('h4', get_string('view_section_title_recordings', 'bigbluebuttonbn'));
253
        $output .= html_writer::end_tag('div');
254
    }
255
    if ($type == BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY || $bbbsession['record']) {
256
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_content'));
257
        $output .= bigbluebuttonbn_view_render_recordings($bbbsession, $enabledfeatures, $jsvars);
258
        $output .= html_writer::end_tag('div');
259
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_footer'));
260
        $output .= bigbluebuttonbn_view_render_imported($bbbsession, $enabledfeatures);
261
        $output .= html_writer::end_tag('div');
262
    }
263
    return $output;
264
}
265
266
/**
267
 * Evaluates if the warning box should be shown.
268
 *
269
 * @param array $bbbsession
270
 *
271
 * @return boolean
272
 */
273
function bigbluebuttonbn_view_warning_shown($bbbsession) {
274
    if (is_siteadmin($bbbsession['userID'])) {
275
        return true;
276
    }
277
    $generalwarningroles = explode(',', \mod_bigbluebuttonbn\locallib\config::get('general_warning_roles'));
278
    $userroles = bigbluebuttonbn_get_user_roles($bbbsession['context'], $bbbsession['userID']);
279
    foreach ($userroles as $userrole) {
280
        if (in_array($userrole->shortname, $generalwarningroles)) {
281
            return true;
282
        }
283
    }
284
    return false;
285
}
286
287
/**
288
 * Renders the view for room.
289
 *
290
 * @param array $bbbsession
291
 * @param string $activity
292
 * @param array $jsvars
293
 *
294
 * @return string
295
 */
296
function bigbluebuttonbn_view_render_room(&$bbbsession, $activity, &$jsvars) {
297
    global $OUTPUT;
298
    // JavaScript variables for room.
299
    $openingtime = '';
300
    if ($bbbsession['openingtime']) {
301
        $openingtime = get_string('mod_form_field_openingtime', 'bigbluebuttonbn').': '.
302
            userdate($bbbsession['openingtime']);
303
    }
304
    $closingtime = '';
305
    if ($bbbsession['closingtime']) {
306
        $closingtime = get_string('mod_form_field_closingtime', 'bigbluebuttonbn').': '.
307
            userdate($bbbsession['closingtime']);
308
    }
309
    $jsvars += array(
310
        'meetingid' => $bbbsession['meetingid'],
311
        'bigbluebuttonbnid' => $bbbsession['bigbluebuttonbn']->id,
312
        'userlimit' => $bbbsession['userlimit'],
313
        'opening' => $openingtime,
314
        'closing' => $closingtime,
315
    );
316
    // Main box.
317
    $output  = $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_message_box');
318
    $output .= '<br><span id="status_bar"></span>';
319
    $output .= '<br><span id="control_panel"></span>';
320
    $output .= $OUTPUT->box_end();
321
    // Action button box.
322
    $output .= $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_action_button_box');
323
    $output .= '<br><br><span id="join_button"></span>&nbsp;<span id="end_button"></span>'."\n";
324
    $output .= $OUTPUT->box_end();
325
    if ($activity == 'ended') {
326
        $output .= bigbluebuttonbn_view_ended($bbbsession);
327
    }
328
    return $output;
329
}
330
331
/**
332
 * Renders the view for recordings.
333
 *
334
 * @param array $bbbsession
335
 * @param array $enabledfeatures
336
 * @param array $jsvars
337
 *
338
 * @return string
339
 */
340
function bigbluebuttonbn_view_render_recordings(&$bbbsession, $enabledfeatures, &$jsvars) {
341
    $bigbluebuttonbnid = null;
342
    if ($enabledfeatures['showroom']) {
343
        $bigbluebuttonbnid = $bbbsession['bigbluebuttonbn']->id;
344
    }
345
    // Get recordings.
346
    $recordings = bigbluebuttonbn_get_recordings(
347
        $bbbsession['course']->id, $bigbluebuttonbnid, $enabledfeatures['showroom'],
348
        $bbbsession['bigbluebuttonbn']->recordings_deleted
349
      );
350
    if ($enabledfeatures['importrecordings']) {
351
        // Get recording links.
352
        $recordingsimported = bigbluebuttonbn_get_recordings_imported_array(
353
            $bbbsession['course']->id, $bigbluebuttonbnid, $enabledfeatures['showroom']
354
          );
355
        /* Perform aritmetic addition instead of merge so the imported recordings corresponding to existent
356
         * recordings are not included. */
357
        if ($bbbsession['bigbluebuttonbn']->recordings_imported) {
358
            $recordings = $recordingsimported;
359
        } else {
360
            $recordings += $recordingsimported;
361
        }
362
    }
363
    if (empty($recordings) || array_key_exists('messageKey', $recordings)) {
364
        // There are no recordings to be shown.
365
        return html_writer::div(get_string('view_message_norecordings', 'bigbluebuttonbn'), '',
366
            array('id' => 'bigbluebuttonbn_recordings_table'));
367
    }
368
    // There are recordings for this meeting.
369
    // JavaScript variables for recordings.
370
    $jsvars += array(
371
            'recordings_html' => $bbbsession['bigbluebuttonbn']->recordings_html == '1',
372
          );
373
    // If there are meetings with recordings load the data to the table.
374
    if ($bbbsession['bigbluebuttonbn']->recordings_html) {
375
        // Render a plain html table.
376
        return bigbluebuttonbn_output_recording_table($bbbsession, $recordings)."\n";
377
    }
378
    // JavaScript variables for recordings with YUI.
379
    $jsvars += array(
380
            'columns' => bigbluebuttonbn_get_recording_columns($bbbsession),
381
            'data' => bigbluebuttonbn_get_recording_data($bbbsession, $recordings),
382
          );
383
    // Render a YUI table.
384
    return html_writer::div('', '', array('id' => 'bigbluebuttonbn_recordings_table'));
385
}
386
387
/**
388
 * Renders the view for importing recordings.
389
 *
390
 * @param array $bbbsession
391
 * @param array $enabledfeatures
392
 *
393
 * @return string
394
 */
395
function bigbluebuttonbn_view_render_imported($bbbsession, $enabledfeatures) {
396
    global $CFG;
397
    if (!$enabledfeatures['importrecordings'] || !$bbbsession['importrecordings']) {
398
        return '';
399
    }
400
    $button = html_writer::tag('input', '',
401
        array('type' => 'button',
402
              'value' => get_string('view_recording_button_import', 'bigbluebuttonbn'),
403
              'class' => 'btn btn-secondary',
404
              'onclick' => 'window.location=\''.$CFG->wwwroot.'/mod/bigbluebuttonbn/import_view.php?bn='.
405
                  $bbbsession['bigbluebuttonbn']->id.'\''));
406
    $output  = html_writer::empty_tag('br');
407
    $output .= html_writer::tag('span', $button, array('id' => 'import_recording_links_button'));
408
    $output .= html_writer::tag('span', '', array('id' => 'import_recording_links_table'));
409
    return $output;
410
}
411
412
/**
413
 * Renders the content for ended meeting.
414
 *
415
 * @param array $bbbsession
416
 *
417
 * @return string
418
 */
419
function bigbluebuttonbn_view_ended(&$bbbsession) {
420
    global $OUTPUT;
421
    if (!is_null($bbbsession['presentation']['url'])) {
422
        $attributes = array('title' => $bbbsession['presentation']['name']);
423
        $icon = new pix_icon($bbbsession['presentation']['icon'], $bbbsession['presentation']['mimetype_description']);
424
        return '<h4>'.get_string('view_section_title_presentation', 'bigbluebuttonbn').'</h4>'.
425
                $OUTPUT->action_icon($bbbsession['presentation']['url'], $icon, null, array(), false).
426
                $OUTPUT->action_link($bbbsession['presentation']['url'],
427
                $bbbsession['presentation']['name'], null, $attributes).'<br><br>';
428
    }
429
    return '';
430
}
431
432
/**
433
 * Renders a default server warning message when using test-install.
434
 *
435
 * @param array $bbbsession
436
 *
437
 * @return string
438
 */
439
function bigbluebuttonbn_view_warning_default_server(&$bbbsession) {
440
    if (!is_siteadmin($bbbsession['userID'])) {
441
        return '';
442
    }
443
    if (BIGBLUEBUTTONBN_DEFAULT_SERVER_URL != \mod_bigbluebuttonbn\locallib\config::get('server_url')) {
444
        return '';
445
    }
446
    return bigbluebuttonbn_render_warning(get_string('view_warning_default_server', 'bigbluebuttonbn'), 'warning');
447
}
448
449
/**
450
 * Renders a general warning message when it is configured.
451
 *
452
 * @param array $bbbsession
453
 *
454
 * @return string
455
 */
456
function bigbluebuttonbn_view_warning_general(&$bbbsession) {
457
    if (!bigbluebuttonbn_view_warning_shown($bbbsession)) {
458
        return '';
459
    }
460
    return bigbluebuttonbn_render_warning(
461
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_message'),
462
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_box_type'),
463
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_href'),
464
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_text'),
465
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_class')
466
      );
467
}
468