Completed
Pull Request — master (#125)
by
unknown
01:56
created

viewlib.php ➔ bigbluebuttonbn_view_groups()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

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