Completed
Pull Request — master (#289)
by
unknown
02:13
created

viewlib.php ➔ bigbluebuttonbn_view_render_room()   B

Complexity

Conditions 9
Paths 48

Size

Total Lines 59

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
nc 48
nop 3
dl 0
loc 59
rs 7.3389
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
 * Displays the view for messages.
75
 *
76
 * @param array $bbbsession
77
 * @param string $message
78
 * @param string $type
79
 * @param boolean $onlymoderator
80
 * @return void
81
 */
82
function bigbluebuttonbn_view_message_box(&$bbbsession, $message, $type = 'warning', $onlymoderator = false) {
83
    global $OUTPUT;
84
    if ($onlymoderator && !$bbbsession['moderator'] && !$bbbsession['administrator']) {
85
        return;
86
    }
87
    echo $OUTPUT->box_start('generalbox boxaligncenter');
88
    echo '<br><div class="alert alert-' . $type . '">' . $message . '</div>';
89
    echo $OUTPUT->box_end();
90
}
91
92
/**
93
 * Displays the general view.
94
 *
95
 * @param array $bbbsession
96
 * @param string $activity
97
 * @return void
98
 */
99
function bigbluebuttonbn_view_render(&$bbbsession, $activity) {
100
    global $OUTPUT, $PAGE;
101
    $type = null;
102
    if (isset($bbbsession['bigbluebuttonbn']->type)) {
103
        $type = $bbbsession['bigbluebuttonbn']->type;
104
    }
105
    $typeprofiles = bigbluebuttonbn_get_instance_type_profiles();
106
    $enabledfeatures = bigbluebuttonbn_get_enabled_features($typeprofiles, $type);
107
    $pinginterval = (int)\mod_bigbluebuttonbn\locallib\config::get('waitformoderator_ping_interval') * 1000;
108
    // JavaScript for locales.
109
    $PAGE->requires->strings_for_js(array_keys(bigbluebuttonbn_get_strings_for_js()), 'bigbluebuttonbn');
110
    // JavaScript variables.
111
    $jsvars = array('activity' => $activity, 'ping_interval' => $pinginterval,
112
        'locale' => bigbluebuttonbn_get_localcode(), 'profile_features' => $typeprofiles[0]['features']);
113
    $output  = '';
114
    // Renders warning messages when configured.
115
    $output .= bigbluebuttonbn_view_warning_default_server($bbbsession);
116
    $output .= bigbluebuttonbn_view_warning_general($bbbsession);
117
118
    // Renders the rest of the page.
119
    $output .= $OUTPUT->heading($bbbsession['meetingname'], 3);
120
    // Renders the completed description.
121
    $desc = file_rewrite_pluginfile_urls($bbbsession['meetingdescription'], 'pluginfile.php',
122
        $bbbsession['context']->id, 'mod_bigbluebuttonbn', 'intro', null);
123
    $output .= $OUTPUT->heading($desc, 5);
124
125
    if ($enabledfeatures['showroom']) {
126
        $output .= bigbluebuttonbn_view_render_room($bbbsession, $activity, $jsvars);
127
        $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-rooms',
128
            'M.mod_bigbluebuttonbn.rooms.init', array($jsvars));
129
    }
130
    if ($enabledfeatures['showrecordings']) {
131
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings'));
132
        $output .= bigbluebuttonbn_view_render_recording_section($bbbsession, $type, $enabledfeatures, $jsvars);
133
        $output .= html_writer::end_tag('div');
134
        $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-recordings',
135
            'M.mod_bigbluebuttonbn.recordings.init', array($jsvars));
136
    } else if ($type == BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY) {
137
        $recordingsdisabled = get_string('view_message_recordings_disabled', 'bigbluebuttonbn');
138
        $output .= bigbluebuttonbn_render_warning($recordingsdisabled, 'danger');
139
    }
140
    echo $output.html_writer::empty_tag('br').html_writer::empty_tag('br').html_writer::empty_tag('br');
141
    $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-broker', 'M.mod_bigbluebuttonbn.broker.init', array($jsvars));
142
}
143
144
/**
145
 * Renders the view for recordings.
146
 *
147
 * @param array $bbbsession
148
 * @param integer $type
149
 * @param array $enabledfeatures
150
 * @param array $jsvars
151
 * @return string
152
 */
153
function bigbluebuttonbn_view_render_recording_section(&$bbbsession, $type, $enabledfeatures, &$jsvars) {
154
    if ($type == BIGBLUEBUTTONBN_TYPE_ROOM_ONLY) {
155
        return '';
156
    }
157
    $output = '';
158
    if ($type == BIGBLUEBUTTONBN_TYPE_ALL && $bbbsession['record']) {
159
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_header'));
160
        $output .= html_writer::tag('h4', get_string('view_section_title_recordings', 'bigbluebuttonbn'));
161
        $output .= html_writer::end_tag('div');
162
    }
163
    if ($type == BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY || $bbbsession['record']) {
164
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_content'));
165
        $output .= bigbluebuttonbn_view_render_recordings($bbbsession, $enabledfeatures, $jsvars);
166
        $output .= html_writer::end_tag('div');
167
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_footer'));
168
        $output .= bigbluebuttonbn_view_render_imported($bbbsession, $enabledfeatures);
169
        $output .= html_writer::end_tag('div');
170
    }
171
    return $output;
172
}
173
174
/**
175
 * Evaluates if the warning box should be shown.
176
 *
177
 * @param array $bbbsession
178
 *
179
 * @return boolean
180
 */
181
function bigbluebuttonbn_view_warning_shown($bbbsession) {
182
    if (is_siteadmin($bbbsession['userID'])) {
183
        return true;
184
    }
185
    $generalwarningroles = explode(',', \mod_bigbluebuttonbn\locallib\config::get('general_warning_roles'));
186
    $userroles = bigbluebuttonbn_get_user_roles($bbbsession['context'], $bbbsession['userID']);
187
    foreach ($userroles as $userrole) {
188
        if (in_array($userrole->shortname, $generalwarningroles)) {
189
            return true;
190
        }
191
    }
192
    return false;
193
}
194
195
/**
196
 * Renders the view for room.
197
 *
198
 * @param array $bbbsession
199
 * @param string $activity
200
 * @param array $jsvars
201
 *
202
 * @return string
203
 */
204
function bigbluebuttonbn_view_render_room(&$bbbsession, $activity, &$jsvars) {
205
    global $OUTPUT;
206
    // JavaScript variables for room.
207
    $openingtime = '';
208
    if ($bbbsession['openingtime']) {
209
        $openingtime = get_string('mod_form_field_openingtime', 'bigbluebuttonbn').': '.
210
            userdate($bbbsession['openingtime']);
211
    }
212
    $closingtime = '';
213
    if ($bbbsession['closingtime']) {
214
        $closingtime = get_string('mod_form_field_closingtime', 'bigbluebuttonbn').': '.
215
            userdate($bbbsession['closingtime']);
216
    }
217
    $guestlink = [];
218
    if ($bbbsession['bigbluebuttonbn']->guestlinkenabled && \mod_bigbluebuttonbn\locallib\config::get('participant_guestlink')) {
219
        $cm = get_coursemodule_from_instance('bigbluebuttonbn', $bbbsession['bigbluebuttonbn']->id);
220
        $context = context_module::instance($cm->id);
221
        if (has_capability('mod/bigbluebuttonbn:guestlink_view', $context)) {
222
            $guestlink['enabled'] = true;
223
            $guestlinkurl = new moodle_url('/mod/bigbluebuttonbn/guestlink.php',
224
                ['gid' => $bbbsession['bigbluebuttonbn']->guestlinkid]);
225
            $guestlink['url'] = $guestlinkurl->__toString();
226
            if ($bbbsession['bigbluebuttonbn']->guestpass) {
227
                $guestlink['password'] = $bbbsession['bigbluebuttonbn']->guestpass;
228
            } else {
229
                $guestlink['nopassword'] = true;
230
            }
231
            if (has_capability('mod/bigbluebuttonbn:guestlink_change_password', $context)) {
232
                $guestlink['changepassenabled'] = true;
233
            } else {
234
                $guestlink['changepassdisabled'] = true;
235
            }
236
        }
237
    } else {
238
        $guestlink['enabled'] = false;
239
    }
240
    $jsvars += array(
241
        'meetingid' => $bbbsession['meetingid'],
242
        'bigbluebuttonbnid' => $bbbsession['bigbluebuttonbn']->id,
243
        'userlimit' => $bbbsession['userlimit'],
244
        'opening' => $openingtime,
245
        'closing' => $closingtime,
246
        'guestlink' => $guestlink,
247
    );
248
    // Main box.
249
    $output  = $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_message_box');
250
    $output .= '<br><span id="guestlink_panel"></span>';
251
    $output .= '<br><span id="status_bar"></span>';
252
    $output .= '<br><span id="control_panel"></span>';
253
    $output .= $OUTPUT->box_end();
254
    // Action button box.
255
    $output .= $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_action_button_box');
256
    $output .= '<br><br><span id="join_button"></span>&nbsp;<span id="end_button"></span>'."\n";
257
    $output .= $OUTPUT->box_end();
258
    if ($activity == 'ended') {
259
        $output .= bigbluebuttonbn_view_ended($bbbsession);
260
    }
261
    return $output;
262
}
263
264
/**
265
 * Renders the view for recordings.
266
 *
267
 * @param array $bbbsession
268
 * @param array $enabledfeatures
269
 * @param array $jsvars
270
 *
271
 * @return string
272
 */
273
function bigbluebuttonbn_view_render_recordings(&$bbbsession, $enabledfeatures, &$jsvars) {
274
    $recordings = bigbluebutton_get_recordings_for_table_view($bbbsession, $enabledfeatures);
275
276
    if (empty($recordings) || array_key_exists('messageKey', $recordings)) {
277
        // There are no recordings to be shown.
278
        return html_writer::div(get_string('view_message_norecordings', 'bigbluebuttonbn'), '',
279
            array('id' => 'bigbluebuttonbn_recordings_table'));
280
    }
281
    // There are recordings for this meeting.
282
    // JavaScript variables for recordings.
283
    $jsvars += array(
284
        'recordings_html' => $bbbsession['bigbluebuttonbn']->recordings_html == '1',
285
    );
286
    // If there are meetings with recordings load the data to the table.
287
    if ($bbbsession['bigbluebuttonbn']->recordings_html) {
288
        // Render a plain html table.
289
        return bigbluebuttonbn_output_recording_table($bbbsession, $recordings)."\n";
290
    }
291
    // JavaScript variables for recordings with YUI.
292
    $jsvars += array(
293
        'bbbid' => $bbbsession['bigbluebuttonbn']->id,
294
    );
295
    // Render a YUI table.
296
    $reset = get_string('reset');
297
    $search = get_string('search');
298
    $output = "<form id='bigbluebuttonbn_recordings_searchform'>
299
                 <input id='searchtext' type='text'>
300
                 <input id='searchsubmit' type='submit' value='{$search}'>
301
                 <input id='searchreset' type='submit' value='{$reset}'>
302
               </form>";
303
    $output .= html_writer::div('', '', array('id' => 'bigbluebuttonbn_recordings_table'));
304
305
    return $output;
306
}
307
308
/**
309
 * Renders the view for importing recordings.
310
 *
311
 * @param array $bbbsession
312
 * @param array $enabledfeatures
313
 *
314
 * @return string
315
 */
316
function bigbluebuttonbn_view_render_imported($bbbsession, $enabledfeatures) {
317
    global $CFG;
318
    if (!$enabledfeatures['importrecordings'] || !$bbbsession['importrecordings']) {
319
        return '';
320
    }
321
    $button = html_writer::tag('input', '',
322
        array('type' => 'button',
323
            'value' => get_string('view_recording_button_import', 'bigbluebuttonbn'),
324
            'class' => 'btn btn-secondary',
325
            'onclick' => 'window.location=\''.$CFG->wwwroot.'/mod/bigbluebuttonbn/import_view.php?bn='.
326
                $bbbsession['bigbluebuttonbn']->id.'\''));
327
    $output  = html_writer::empty_tag('br');
328
    $output .= html_writer::tag('span', $button, array('id' => 'import_recording_links_button'));
329
    $output .= html_writer::tag('span', '', array('id' => 'import_recording_links_table'));
330
    return $output;
331
}
332
333
/**
334
 * Renders the content for ended meeting.
335
 *
336
 * @param array $bbbsession
337
 *
338
 * @return string
339
 */
340
function bigbluebuttonbn_view_ended(&$bbbsession) {
341
    global $OUTPUT;
342
    if (!is_null($bbbsession['presentation']['url'])) {
343
        $attributes = array('title' => $bbbsession['presentation']['name']);
344
        $icon = new pix_icon($bbbsession['presentation']['icon'], $bbbsession['presentation']['mimetype_description']);
345
        return '<h4>'.get_string('view_section_title_presentation', 'bigbluebuttonbn').'</h4>'.
346
            $OUTPUT->action_icon($bbbsession['presentation']['url'], $icon, null, array(), false).
347
            $OUTPUT->action_link($bbbsession['presentation']['url'],
348
                $bbbsession['presentation']['name'], null, $attributes).'<br><br>';
349
    }
350
    return '';
351
}
352
353
/**
354
 * Renders a default server warning message when using test-install.
355
 *
356
 * @param array $bbbsession
357
 *
358
 * @return string
359
 */
360
function bigbluebuttonbn_view_warning_default_server(&$bbbsession) {
361
    if (!is_siteadmin($bbbsession['userID'])) {
362
        return '';
363
    }
364
    if (BIGBLUEBUTTONBN_DEFAULT_SERVER_URL != \mod_bigbluebuttonbn\locallib\config::get('server_url')) {
365
        return '';
366
    }
367
    return bigbluebuttonbn_render_warning(get_string('view_warning_default_server', 'bigbluebuttonbn'), 'warning');
368
}
369
370
/**
371
 * Renders a general warning message when it is configured.
372
 *
373
 * @param array $bbbsession
374
 *
375
 * @return string
376
 */
377
function bigbluebuttonbn_view_warning_general(&$bbbsession) {
378
    if (!bigbluebuttonbn_view_warning_shown($bbbsession)) {
379
        return '';
380
    }
381
    return bigbluebuttonbn_render_warning(
382
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_message'),
383
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_box_type'),
384
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_href'),
385
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_text'),
386
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_class')
387
    );
388
}
389