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