Completed
Pull Request — master (#367)
by
unknown
03:44
created

viewlib.php ➔ bigbluebuttonbn_view_render_room()   B

Complexity

Conditions 7
Paths 48

Size

Total Lines 61

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 48
nop 3
dl 0
loc 61
rs 7.9175
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 $CFG, $OUTPUT, $SESSION;
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
219
    $jsvars += array(
220
        'meetingid' => $bbbsession['meetingid'],
221
        'bigbluebuttonbnid' => $bbbsession['bigbluebuttonbn']->id,
222
        'userlimit' => $bbbsession['userlimit'],
223
        'opening' => $openingtime,
224
        'closing' => $closingtime,
225
    );
226
    // Main box.
227
    $output  = $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_message_box');
228
    $output .= '<br><span id="status_bar"></span>';
229
    $output .= '<br><span id="control_panel"></span>';
230
    $output .= $OUTPUT->box_end();
231
232
    // Setup access policy modal window.
233
    // If global editing is disabled, it is always the global version.
234
    if ((int) $CFG->bigbluebuttonbn_accessmodal_editable) {
235
        $policytext = format_text($bbbsession['bigbluebuttonbn']->accesspolicy ?? '');
236
        // If empty here, try the default policy.
237
        if (empty(strip_tags($policytext))) {
238
            $policytext = format_text($CFG->bigbluebuttonbn_accessmodal_default ?? '');
239
        }
240
    } else {
241
        $policytext = format_text($CFG->bigbluebuttonbn_accessmodal_default ?? '');
242
    }
243
244
    // Check if there is any content with HTML stripped.
245
    if (!empty(strip_tags($policytext))) {
246
        $modal = $OUTPUT->render_from_template('mod_bigbluebuttonbn/accesspolicy', [
247
            'body' => $policytext,
248
            'forward' => $bbbsession['joinURL'],
249
            'hash' => md5($policytext),
250
            'alert' => get_string('accesspolicyalert', 'mod_bigbluebuttonbn')
251
        ]);
252
        $output .= $modal;
253
        // Add the JS var to setup the modal from JS.
254
        $jsvars['accesspolicy'] = true;
255
    }
256
257
    // Action button box.
258
    $output .= $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_action_button_box');
259
    $output .= '<br><br><span id="join_button"></span>&nbsp;<span id="end_button"></span>'."\n";
260
    $output .= $OUTPUT->box_end();
261
    if ($activity == 'ended') {
262
        $output .= bigbluebuttonbn_view_ended($bbbsession);
263
    }
264
    return $output;
265
}
266
267
/**
268
 * Renders the view for recordings.
269
 *
270
 * @param array $bbbsession
271
 * @param array $enabledfeatures
272
 * @param array $jsvars
273
 *
274
 * @return string
275
 */
276
function bigbluebuttonbn_view_render_recordings(&$bbbsession, $enabledfeatures, &$jsvars) {
277
    $recordings = bigbluebutton_get_recordings_for_table_view($bbbsession, $enabledfeatures);
278
279
    if (empty($recordings) || array_key_exists('messageKey', $recordings)) {
280
        // There are no recordings to be shown.
281
        return html_writer::div(get_string('view_message_norecordings', 'bigbluebuttonbn'), '',
282
            array('id' => 'bigbluebuttonbn_recordings_table'));
283
    }
284
    // There are recordings for this meeting.
285
    // JavaScript variables for recordings.
286
    $jsvars += array(
287
        'recordings_html' => $bbbsession['bigbluebuttonbn']->recordings_html == '1',
288
    );
289
    // If there are meetings with recordings load the data to the table.
290
    if ($bbbsession['bigbluebuttonbn']->recordings_html) {
291
        // Render a plain html table.
292
        return bigbluebuttonbn_output_recording_table($bbbsession, $recordings)."\n";
293
    }
294
    // JavaScript variables for recordings with YUI.
295
    $jsvars += array(
296
        'bbbid' => $bbbsession['bigbluebuttonbn']->id,
297
    );
298
    // Render a YUI table.
299
    $reset = get_string('reset');
300
    $search = get_string('search');
301
    $output = "<form id='bigbluebuttonbn_recordings_searchform'>
302
                 <input id='searchtext' type='text'>
303
                 <input id='searchsubmit' type='submit' value='{$search}'>
304
                 <input id='searchreset' type='submit' value='{$reset}'>
305
               </form>";
306
    $output .= html_writer::div('', '', array('id' => 'bigbluebuttonbn_recordings_table'));
307
308
    return $output;
309
}
310
311
/**
312
 * Renders the view for importing recordings.
313
 *
314
 * @param array $bbbsession
315
 * @param array $enabledfeatures
316
 *
317
 * @return string
318
 */
319
function bigbluebuttonbn_view_render_imported($bbbsession, $enabledfeatures) {
320
    global $CFG;
321
    if (!$enabledfeatures['importrecordings'] || !$bbbsession['importrecordings']) {
322
        return '';
323
    }
324
    $button = html_writer::tag('input', '',
325
        array('type' => 'button',
326
            'value' => get_string('view_recording_button_import', 'bigbluebuttonbn'),
327
            'class' => 'btn btn-secondary',
328
            'onclick' => 'window.location=\''.$CFG->wwwroot.'/mod/bigbluebuttonbn/import_view.php?bn='.
329
                $bbbsession['bigbluebuttonbn']->id.'\''));
330
    $output  = html_writer::empty_tag('br');
331
    $output .= html_writer::tag('span', $button, array('id' => 'import_recording_links_button'));
332
    $output .= html_writer::tag('span', '', array('id' => 'import_recording_links_table'));
333
    return $output;
334
}
335
336
/**
337
 * Renders the content for ended meeting.
338
 *
339
 * @param array $bbbsession
340
 *
341
 * @return string
342
 */
343
function bigbluebuttonbn_view_ended(&$bbbsession) {
344
    global $OUTPUT;
345
    if (!is_null($bbbsession['presentation']['url'])) {
346
        $attributes = array('title' => $bbbsession['presentation']['name']);
347
        $icon = new pix_icon($bbbsession['presentation']['icon'], $bbbsession['presentation']['mimetype_description']);
348
        return '<h4>'.get_string('view_section_title_presentation', 'bigbluebuttonbn').'</h4>'.
349
            $OUTPUT->action_icon($bbbsession['presentation']['url'], $icon, null, array(), false).
350
            $OUTPUT->action_link($bbbsession['presentation']['url'],
351
                $bbbsession['presentation']['name'], null, $attributes).'<br><br>';
352
    }
353
    return '';
354
}
355
356
/**
357
 * Renders a default server warning message when using test-install.
358
 *
359
 * @param array $bbbsession
360
 *
361
 * @return string
362
 */
363
function bigbluebuttonbn_view_warning_default_server(&$bbbsession) {
364
    if (!is_siteadmin($bbbsession['userID'])) {
365
        return '';
366
    }
367
    if (BIGBLUEBUTTONBN_DEFAULT_SERVER_URL != \mod_bigbluebuttonbn\locallib\config::get('server_url')) {
368
        return '';
369
    }
370
    return bigbluebuttonbn_render_warning(get_string('view_warning_default_server', 'bigbluebuttonbn'), 'warning');
371
}
372
373
/**
374
 * Renders a general warning message when it is configured.
375
 *
376
 * @param array $bbbsession
377
 *
378
 * @return string
379
 */
380
function bigbluebuttonbn_view_warning_general(&$bbbsession) {
381
    if (!bigbluebuttonbn_view_warning_shown($bbbsession)) {
382
        return '';
383
    }
384
    return bigbluebuttonbn_render_warning(
385
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_message'),
386
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_box_type'),
387
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_href'),
388
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_text'),
389
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_class')
390
    );
391
}
392