Completed
Branch master (50b31b)
by Jesus
02:05
created

mod_bigbluebuttonbn_mod_form::validation()   B

Complexity

Conditions 8
Paths 9

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 9
nop 2
dl 0
loc 15
rs 8.4444
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
 * Config all BigBlueButtonBN instances in this course.
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
defined('MOODLE_INTERNAL') || die();
28
29
require_once(dirname(__FILE__).'/locallib.php');
30
require_once($CFG->dirroot.'/course/moodleform_mod.php');
31
32
/**
33
 * Moodle class for mod_form.
34
 *
35
 * @copyright 2010 onwards, Blindside Networks Inc
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class mod_bigbluebuttonbn_mod_form extends moodleform_mod {
39
40
    /**
41
     * Define (add) particular settings this activity can have.
42
     *
43
     * @return void
44
     */
45
    public function definition() {
46
        global $CFG, $DB, $OUTPUT, $PAGE;
47
        // Validates if the BigBlueButton server is running.
48
        $serverversion = bigbluebuttonbn_get_server_version();
49
        if (is_null($serverversion)) {
50
            print_error('general_error_unable_connect', 'bigbluebuttonbn',
51
                $CFG->wwwroot.'/admin/settings.php?section=modsettingbigbluebuttonbn');
52
            return;
53
        }
54
        // Context.
55
        $bigbluebuttonbn = null;
56
        $course = null;
57
        $courseid = optional_param('course', 0, PARAM_INT);
58
        if ($courseid) {
59
            $course = get_course($courseid);
60
        }
61
        if (!$course) {
62
            $cm = get_coursemodule_from_id('bigbluebuttonbn',
63
                optional_param('update', 0, PARAM_INT), 0, false, MUST_EXIST);
64
            $course = $DB->get_record('course', array('id' => $cm->course),
65
                '*', MUST_EXIST);
66
            $bigbluebuttonbn = $DB->get_record('bigbluebuttonbn',
67
                array('id' => $cm->instance), '*', MUST_EXIST);
68
        }
69
        $context = context_course::instance($course->id);
70
        // UI configuration options.
71
        $cfg = \mod_bigbluebuttonbn\locallib\config::get_options();
72
        $mform = &$this->_form;
73
        $jsvars = array();
74
        // Get only those that are allowed.
75
        $createroom = has_capability('mod/bigbluebuttonbn:meeting', $context);
76
        $createrecording = has_capability('mod/bigbluebuttonbn:recording', $context);
77
        $jsvars['instanceTypeProfiles'] = bigbluebuttonbn_get_instance_type_profiles_create_allowed(
78
            $createroom, $createrecording);
79
        $jsvars['instanceTypeDefault'] = array_keys($jsvars['instanceTypeProfiles'])[0];
80
        // If none is allowed, fail and return.
81
        if (empty($jsvars['instanceTypeProfiles'])) {
82
            print_error('general_error_not_allowed_to_create_instances)', 'bigbluebuttonbn',
83
                $CFG->wwwroot.'/admin/settings.php?section=modsettingbigbluebuttonbn');
84
            return;
85
        }
86
        $this->bigbluebuttonbn_mform_add_block_profiles($mform, $jsvars['instanceTypeProfiles']);
87
        // Data for participant selection.
88
        $participantlist = bigbluebuttonbn_get_participant_list($bigbluebuttonbn, $context);
89
        // Add block 'General'.
90
        $this->bigbluebuttonbn_mform_add_block_general($mform, $cfg);
91
        // Add block 'Room'.
92
        $this->bigbluebuttonbn_mform_add_block_room($mform, $cfg);
93
        // Add block 'Preuploads'.
94
        $this->bigbluebuttonbn_mform_add_block_preuploads($mform, $cfg);
95
        // Add block 'Participant List'.
96
        $this->bigbluebuttonbn_mform_add_block_participants($mform, $participantlist);
97
        // Add block 'Schedule'.
98
        $this->bigbluebuttonbn_mform_add_block_schedule($mform, $this->current);
99
        // Add block 'client Type'.
100
        $this->bigbluebuttonbn_mform_add_block_clienttype($mform, $cfg);
101
        // Add standard elements, common to all modules.
102
        $this->standard_coursemodule_elements();
103
        // Add standard buttons, common to all modules.
104
        $this->add_action_buttons();
105
        // JavaScript for locales.
106
        $PAGE->requires->strings_for_js(array_keys(bigbluebuttonbn_get_strings_for_js()), 'bigbluebuttonbn');
107
        $jsvars['participantData'] = bigbluebuttonbn_get_participant_data($context);
108
        $jsvars['participantList'] = $participantlist;
109
        $jsvars['iconsEnabled'] = (boolean)$cfg['recording_icons_enabled'];
110
        $jsvars['pixIconDelete'] = (string)$OUTPUT->pix_icon('t/delete', get_string('delete'), 'moodle');
111
        $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-modform',
112
            'M.mod_bigbluebuttonbn.modform.init', array($jsvars));
113
    }
114
115
    /**
116
     * Prepare the attachment for being stored.
117
     *
118
     * @param array $defaultvalues
119
     * @return void
120
     */
121
    public function data_preprocessing(&$defaultvalues) {
122
        parent::data_preprocessing($defaultvalues);
123
124
        // Completion: tick by default if completion attendance settings is set to 1 or more.
125
        $defaultvalues['completionattendanceenabled'] = 0;
126
        if (!empty($defaultvalues['completionattendance'])) {
127
            $defaultvalues['completionattendanceenabled'] = 1;
128
        }
129
        // Check if we are Editing an existing instance.
130
        if ($this->current->instance) {
131
            // Pre-uploaded presentation: copy existing files into draft area.
132
            try {
133
                $draftitemid = file_get_submitted_draft_itemid('presentation');
134
                file_prepare_draft_area($draftitemid, $this->context->id, 'mod_bigbluebuttonbn', 'presentation', 0,
135
                    array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1, 'mainfile' => true)
136
                );
137
                $defaultvalues['presentation'] = $draftitemid;
138
            } catch (Exception $e) {
139
                debugging('Presentation could not be loaded: '.$e->getMessage(), DEBUG_DEVELOPER);
140
                return;
141
            }
142
            // Completion: tick if completion attendance settings is set to 1 or more.
143
            $defaultvalues['completionattendanceenabled'] = 0;
144
            if (!empty($this->current->completionattendance)) {
145
                $defaultvalues['completionattendanceenabled'] = 1;
146
            }
147
        }
148
    }
149
150
    /**
151
     * Validates the data processed by the form.
152
     *
153
     * @param array $data
154
     * @param array $files
155
     * @return void
156
     */
157
    public function validation($data, $files) {
158
        $errors = parent::validation($data, $files);
159
        if (isset($data['openingtime']) && isset($data['closingtime'])) {
160
            if ($data['openingtime'] != 0 && $data['closingtime'] != 0 &&
161
                $data['closingtime'] < $data['openingtime']) {
162
                $errors['closingtime'] = get_string('bbbduetimeoverstartingtime', 'bigbluebuttonbn');
163
            }
164
        }
165
        if (isset($data['voicebridge'])) {
166
            if (!bigbluebuttonbn_voicebridge_unique($data['instance'], $data['voicebridge'])) {
167
                $errors['voicebridge'] = get_string('mod_form_field_voicebridge_notunique_error', 'bigbluebuttonbn');
168
            }
169
        }
170
        return $errors;
171
    }
172
173
    /**
174
     * Add elements for setting the custom completion rules.
175
     *
176
     * @category completion
177
     * @return array List of added element names, or names of wrapping group elements.
178
     */
179
    public function add_completion_rules() {
180
        $mform = $this->_form;
181
        if (!bigbluebuttonbn_is_bn_server() || !(boolean)\mod_bigbluebuttonbn\locallib\config::get('meetingevents_enabled')) {
182
            return [];
183
        }
184
185
        // Elements for completion by Attendance.
186
        $attendance['grouplabel'] = get_string('completionattendancegroup', 'bigbluebuttonbn');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$attendance was never initialized. Although not strictly required by PHP, it is generally a good practice to add $attendance = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
187
        $attendance['rulelabel'] = get_string('completionattendance', 'bigbluebuttonbn');
188
        $attendance['group'] = [
189
            $mform->createElement('checkbox', 'completionattendanceenabled', '', $attendance['rulelabel'] . '&nbsp;'),
190
            $mform->createElement('text', 'completionattendance', '', ['size' => 3]),
191
            $mform->createElement('static', 'completionattendanceunit', ' ', get_string('minutes', 'bigbluebuttonbn'))
192
        ];
193
        $mform->setType('completionattendance', PARAM_INT);
194
        $mform->addGroup($attendance['group'], 'completionattendancegroup', $attendance['grouplabel'], [' '], false);
195
        $mform->addHelpButton('completionattendancegroup', 'completionattendancegroup', 'bigbluebuttonbn');
196
        $mform->disabledIf('completionattendancegroup', 'completionview', 'notchecked');
197
        $mform->disabledIf('completionattendance', 'completionattendanceenabled', 'notchecked');
198
199
        // Elements for completion by Engagement.
200
        $engagement['grouplabel'] = get_string('completionengagementgroup', 'bigbluebuttonbn');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$engagement was never initialized. Although not strictly required by PHP, it is generally a good practice to add $engagement = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
201
        $engagement['chatlabel'] = get_string('completionengagementchats', 'bigbluebuttonbn');
202
        $engagement['talklabel'] = get_string('completionengagementtalks', 'bigbluebuttonbn');
203
        $engagement['raisehand'] = get_string('completionengagementraisehand', 'bigbluebuttonbn');
204
        $engagement['pollvotes'] = get_string('completionengagementpollvotes', 'bigbluebuttonbn');
205
        $engagement['emojis'] = get_string('completionengagementemojis', 'bigbluebuttonbn');
206
        $engagement['group'] = [
207
            $mform->createElement('checkbox', 'completionengagementchats', '', $engagement['chatlabel'] . '&nbsp;&nbsp;'),
208
            $mform->createElement('checkbox', 'completionengagementtalks', '', $engagement['talklabel'] . '&nbsp;&nbsp;'),
209
            $mform->createElement('checkbox', 'completionengagementraisehand', '', $engagement['raisehand'] . '&nbsp;&nbsp;'),
210
            $mform->createElement('checkbox', 'completionengagementpollvotes', '', $engagement['pollvotes'] . '&nbsp;&nbsp;'),
211
            $mform->createElement('checkbox', 'completionengagementemojis', '', $engagement['emojis'] . '&nbsp;&nbsp;'),
212
        ];
213
        $mform->addGroup($engagement['group'], 'completionengagementgroup', $engagement['grouplabel'], [' '], false);
214
        $mform->addHelpButton('completionengagementgroup', 'completionengagementgroup', 'bigbluebuttonbn');
215
        $mform->disabledIf('completionengagementgroup', 'completionview', 'notchecked');
216
217
        return ['completionattendancegroup', 'completionengagementgroup'];
218
    }
219
220
    /**
221
     * Called during validation to see whether some module-specific completion rules are selected.
222
     *
223
     * @param array $data Input data not yet validated.
224
     * @return bool True if one or more rules is enabled, false if none are.
225
     */
226
    public function completion_rule_enabled($data) {
227
        return (!empty($data['completionattendanceenabled']) && $data['completionattendance'] != 0);
228
    }
229
230
    /**
231
     * Allows module to modify the data returned by form get_data().
232
     * This method is also called in the bulk activity completion form.
233
     *
234
     * Only available on moodleform_mod.
235
     *
236
     * @param stdClass $data the form data to be modified.
237
     */
238
    public function data_postprocessing($data) {
239
        parent::data_postprocessing($data);
240
        // Turn off completion settings if the checkboxes aren't ticked.
241
        if (!empty($data->completionunlocked)) {
242
            $autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
243
            if (empty($data->completionattendanceenabled) || !$autocompletion) {
244
                $data->completionattendance = 0;
245
            }
246
        }
247
    }
248
249
250
    /**
251
     * Function for showing the block for selecting profiles.
252
     *
253
     * @param object $mform
254
     * @param array $profiles
255
     * @return void
256
     */
257
    private function bigbluebuttonbn_mform_add_block_profiles(&$mform, $profiles) {
258
        if ((boolean)\mod_bigbluebuttonbn\locallib\config::recordings_enabled()) {
259
            $mform->addElement('select', 'type', get_string('mod_form_field_instanceprofiles', 'bigbluebuttonbn'),
260
                bigbluebuttonbn_get_instance_profiles_array($profiles),
261
                array('onchange' => 'M.mod_bigbluebuttonbn.modform.updateInstanceTypeProfile(this);'));
262
            $mform->addHelpButton('type', 'mod_form_field_instanceprofiles', 'bigbluebuttonbn');
263
        }
264
    }
265
266
    /**
267
     * Function for showing the block for general settings.
268
     *
269
     * @param object $mform
270
     * @param array $cfg
271
     * @return void
272
     */
273
    private function bigbluebuttonbn_mform_add_block_general(&$mform, $cfg) {
274
        global $CFG;
275
        $mform->addElement('header', 'general', get_string('mod_form_block_general', 'bigbluebuttonbn'));
276
        $mform->addElement('text', 'name', get_string('mod_form_field_name', 'bigbluebuttonbn'),
277
            'maxlength="64" size="32"');
278
        $mform->setType('name', empty($CFG->formatstringstriptags) ? PARAM_CLEANHTML : PARAM_TEXT);
279
        $mform->addRule('name', null, 'required', null, 'client');
280
        $this->standard_intro_elements(get_string('mod_form_field_intro', 'bigbluebuttonbn'));
281
        $mform->setAdvanced('introeditor');
282
        $mform->setAdvanced('showdescription');
283
        if ($cfg['sendnotifications_enabled']) {
284
            $field = ['type' => 'checkbox', 'name' => 'notification', 'data_type' => PARAM_INT,
285
                'description_key' => 'mod_form_field_notification'];
286
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
287
                $field['description_key'], 0);
288
        }
289
    }
290
291
    /**
292
     * Function for showing details of the room settings for the room.
293
     *
294
     * @param object $mform
295
     * @param array $cfg
296
     * @return void
297
     */
298
    private function bigbluebuttonbn_mform_add_block_room_room(&$mform, $cfg) {
299
        $field = ['type' => 'textarea', 'name' => 'welcome', 'data_type' => PARAM_TEXT,
300
            'description_key' => 'mod_form_field_welcome'];
301
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
302
            $field['description_key'], '', ['wrap' => 'virtual', 'rows' => 5, 'cols' => '60']);
303
        $field = ['type' => 'hidden', 'name' => 'voicebridge', 'data_type' => PARAM_INT,
304
            'description_key' => null];
305
        if ($cfg['voicebridge_editable']) {
306
            $field['type'] = 'text';
307
            $field['data_type'] = PARAM_TEXT;
308
            $field['description_key'] = 'mod_form_field_voicebridge';
309
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
310
                $field['description_key'], 0, ['maxlength' => 4, 'size' => 6],
311
                ['message' => get_string('mod_form_field_voicebridge_format_error', 'bigbluebuttonbn'),
312
                 'type' => 'numeric', 'rule' => '####', 'validator' => 'server']
313
              );
314
        } else {
315
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
316
                $field['description_key'], 0, ['maxlength' => 4, 'size' => 6]);
317
        }
318
        $field = ['type' => 'hidden', 'name' => 'wait', 'data_type' => PARAM_INT, 'description_key' => null];
319
        if ($cfg['waitformoderator_editable']) {
320
            $field['type'] = 'checkbox';
321
            $field['description_key'] = 'mod_form_field_wait';
322
        }
323
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
324
            $field['description_key'], $cfg['waitformoderator_default']);
325
        $field = ['type' => 'hidden', 'name' => 'userlimit', 'data_type' => PARAM_INT, 'description_key' => null];
326
        if ($cfg['userlimit_editable']) {
327
            $field['type'] = 'text';
328
            $field['data_type'] = PARAM_TEXT;
329
            $field['description_key'] = 'mod_form_field_userlimit';
330
        }
331
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
332
            $field['description_key'], $cfg['userlimit_default']);
333
        $field = ['type' => 'hidden', 'name' => 'record', 'data_type' => PARAM_INT, 'description_key' => null];
334
        if ($cfg['recording_editable']) {
335
            $field['type'] = 'checkbox';
336
            $field['description_key'] = 'mod_form_field_record';
337
        }
338
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
339
            $field['description_key'], $cfg['recording_default']);
340
341
        // Record all from start and hide button.
342
        $field = ['type' => 'hidden', 'name' => 'recordallfromstart', 'data_type' => PARAM_INT, 'description_key' => null];
343
        if ($cfg['recording_all_from_start_editable']) {
344
            $field['type'] = 'checkbox';
345
            $field['description_key'] = 'mod_form_field_recordallfromstart';
346
        }
347
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
348
            $field['description_key'], $cfg['recording_all_from_start_default']);
349
350
        $field = ['type' => 'hidden', 'name' => 'recordhidebutton', 'data_type' => PARAM_INT, 'description_key' => null];
351
        if ($cfg['recording_hide_button_editable']) {
352
            $field['type'] = 'checkbox';
353
            $field['description_key'] = 'mod_form_field_recordhidebutton';
354
        }
355
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
356
            $field['description_key'], $cfg['recording_hide_button_default']);
357
358
        $mform->disabledIf('recordallfromstart', 'record', $condition = 'notchecked', $value = '0');
359
        $mform->disabledIf('recordhidebutton', 'record', $condition = 'notchecked', $value = '0');
360
        $mform->disabledIf('recordhidebutton', 'recordallfromstart', $condition = 'notchecked', $value = '0');
361
        // End Record all from start and hide button.
362
363
        $field = ['type' => 'hidden', 'name' => 'muteonstart', 'data_type' => PARAM_INT, 'description_key' => null];
364
        if ($cfg['muteonstart_editable']) {
365
            $field['type'] = 'checkbox';
366
            $field['description_key'] = 'mod_form_field_muteonstart';
367
        }
368
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
369
            $field['description_key'], $cfg['muteonstart_default']);
370
371
    }
372
373
    /**
374
     * Function for showing details of the recording settings for the room.
375
     *
376
     * @param object $mform
377
     * @param array $cfg
378
     * @return void
379
     */
380
    private function bigbluebuttonbn_mform_add_block_room_recordings(&$mform, $cfg) {
381
        $recordingsettings = false;
382
        $field = ['type' => 'hidden', 'name' => 'recordings_html', 'data_type' => PARAM_INT,
383
                  'description_key' => null];
384
        if ($cfg['recordings_html_editable']) {
385
            $field['type'] = 'checkbox';
386
            $field['description_key'] = 'mod_form_field_recordings_html';
387
            $recordingsettings = true;
388
        }
389
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
390
            $field['description_key'], $cfg['recordings_html_default']);
391
        $field = ['type' => 'hidden', 'name' => 'recordings_deleted', 'data_type' => PARAM_INT,
392
                  'description_key' => null];
393
        if ($cfg['recordings_deleted_editable']) {
394
            $field['type'] = 'checkbox';
395
            $field['description_key'] = 'mod_form_field_recordings_deleted';
396
            $recordingsettings = true;
397
        }
398
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
399
            $field['description_key'], $cfg['recordings_deleted_default']);
400
        $field = ['type' => 'hidden', 'name' => 'recordings_imported', 'data_type' => PARAM_INT,
401
                  'description_key' => null];
402
        if ($cfg['importrecordings_enabled'] && $cfg['recordings_imported_editable']) {
403
            $field['type'] = 'checkbox';
404
            $field['description_key'] = 'mod_form_field_recordings_imported';
405
            $recordingsettings = true;
406
        }
407
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
408
            $field['description_key'], $cfg['recordings_imported_default']);
409
        $field = ['type' => 'hidden', 'name' => 'recordings_preview', 'data_type' => PARAM_INT,
410
                  'description_key' => null];
411
        if ($cfg['recordings_preview_editable']) {
412
            $field['type'] = 'checkbox';
413
            $field['description_key'] = 'mod_form_field_recordings_preview';
414
            $recordingsettings = true;
415
        }
416
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
417
            $field['description_key'], $cfg['recordings_preview_default']);
418
419
        if (!$recordingsettings) {
420
            $field = ['type' => 'static', 'name' => 'no_recordings',
421
                'defaultvalue' => get_string('mod_form_field_nosettings', 'bigbluebuttonbn')];
422
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], null, null,
423
                $field['defaultvalue']);
424
        }
425
    }
426
427
    /**
428
     * Function for showing the block for room settings.
429
     *
430
     * @param object $mform
431
     * @param array $cfg
432
     * @return void
433
     */
434
    private function bigbluebuttonbn_mform_add_block_room(&$mform, $cfg) {
435
        if ($cfg['voicebridge_editable'] || $cfg['waitformoderator_editable'] ||
436
            $cfg['userlimit_editable'] || $cfg['recording_editable']) {
437
            $mform->addElement('header', 'room', get_string('mod_form_block_room', 'bigbluebuttonbn'));
438
            $this->bigbluebuttonbn_mform_add_block_room_room($mform, $cfg);
439
        }
440
        if ($cfg['recordings_html_editable'] || $cfg['recordings_deleted_editable'] ||
441
            $cfg['recordings_imported_editable'] || $cfg['recordings_preview_editable']) {
442
            $mform->addElement('header', 'recordings', get_string('mod_form_block_recordings', 'bigbluebuttonbn'));
443
            $this->bigbluebuttonbn_mform_add_block_room_recordings($mform, $cfg);
444
        }
445
    }
446
447
    /**
448
     * Function for showing the block for preuploaded presentation.
449
     *
450
     * @param object $mform
451
     * @param array $cfg
452
     * @return void
453
     */
454
    private function bigbluebuttonbn_mform_add_block_preuploads(&$mform, $cfg) {
455
        if ($cfg['preuploadpresentation_enabled']) {
456
            $mform->addElement('header', 'preuploadpresentation',
457
                get_string('mod_form_block_presentation', 'bigbluebuttonbn'));
458
            $mform->setExpanded('preuploadpresentation');
459
            $filemanageroptions = array();
460
            $filemanageroptions['accepted_types'] = '*';
461
            $filemanageroptions['maxbytes'] = 0;
462
            $filemanageroptions['subdirs'] = 0;
463
            $filemanageroptions['maxfiles'] = 1;
464
            $filemanageroptions['mainfile'] = true;
465
            $mform->addElement('filemanager', 'presentation', get_string('selectfiles'),
466
                null, $filemanageroptions);
467
        }
468
    }
469
470
    /**
471
     * Function for showing the block for setting participant roles.
472
     *
473
     * @param object $mform
474
     * @param string $participantlist
475
     * @return void
476
     */
477
    private function bigbluebuttonbn_mform_add_block_participants(&$mform, $participantlist) {
478
        $participantselection = bigbluebuttonbn_get_participant_selection_data();
479
        $mform->addElement('header', 'permissions', get_string('mod_form_block_participants', 'bigbluebuttonbn'));
480
        $mform->setExpanded('permissions');
481
        $mform->addElement('hidden', 'participants', json_encode($participantlist));
482
        $mform->setType('participants', PARAM_TEXT);
483
        // Render elements for participant selection.
484
        $htmlselectiontype = html_writer::select($participantselection['type_options'],
485
            'bigbluebuttonbn_participant_selection_type', $participantselection['type_selected'], array(),
486
            array('id' => 'bigbluebuttonbn_participant_selection_type',
487
                  'onchange' => 'M.mod_bigbluebuttonbn.modform.participantSelectionSet(); return 0;'));
488
        $htmlselectionoptions = html_writer::select($participantselection['options'], 'bigbluebuttonbn_participant_selection',
489
            $participantselection['selected'], array(),
490
            array('id' => 'bigbluebuttonbn_participant_selection', 'disabled' => 'disabled'));
491
        $htmlselectioninput = html_writer::tag('input', '', array('id' => 'id_addselectionid',
492
            'type' => 'button', 'class' => 'btn btn-secondary',
493
            'value' => get_string('mod_form_field_participant_list_action_add', 'bigbluebuttonbn'),
494
            'onclick' => 'M.mod_bigbluebuttonbn.modform.participantAdd(); return 0;'
495
          ));
496
        $htmladdparticipant = html_writer::tag('div',
497
            $htmlselectiontype . '&nbsp;&nbsp;' . $htmlselectionoptions . '&nbsp;&nbsp;' . $htmlselectioninput, null);
498
        $mform->addElement('html', "\n\n");
499
        $mform->addElement('static', 'static_add_participant',
500
            get_string('mod_form_field_participant_add', 'bigbluebuttonbn'), $htmladdparticipant);
501
        $mform->addElement('html', "\n\n");
502
        // Declare the table.
503
        $htmltable = new html_table();
504
        $htmltable->align = array('left', 'left', 'left', 'left');
505
        $htmltable->id = 'participant_list_table';
506
        $htmltable->data = array(array());
507
        // Render elements for participant list.
508
        $htmlparticipantlist = html_writer::table($htmltable);
509
        $mform->addElement('html', "\n\n");
510
        $mform->addElement('static', 'static_participant_list',
511
            get_string('mod_form_field_participant_list', 'bigbluebuttonbn'), $htmlparticipantlist);
512
        $mform->addElement('html', "\n\n");
513
    }
514
515
    /**
516
     * Function for showing the client type
517
     *
518
     * @param object $mform
519
     * @param object $cfg
520
     * @return void
521
     */
522
    private function bigbluebuttonbn_mform_add_block_clienttype(&$mform, &$cfg) {
523
        // Validates if clienttype capability is enabled.
524
        if (!$cfg['clienttype_enabled']) {
525
            return;
526
        }
527
        // Validates if the html5client is supported by the BigBlueButton Server.
528
        if (!bigbluebuttonbn_has_html5_client()) {
529
            return;
530
        }
531
        $field = ['type' => 'hidden', 'name' => 'clienttype', 'data_type' => PARAM_INT,
532
            'description_key' => null];
533
        if ($cfg['clienttype_editable']) {
534
            $field['type'] = 'select';
535
            $field['data_type'] = PARAM_TEXT;
536
            $field['description_key'] = 'mod_form_field_block_clienttype';
537
             $choices = array(BIGBLUEBUTTON_CLIENTTYPE_FLASH => get_string('mod_form_block_clienttype_flash', 'bigbluebuttonbn'),
538
                             BIGBLUEBUTTON_CLIENTTYPE_HTML5 => get_string('mod_form_block_clienttype_html5', 'bigbluebuttonbn'));
539
             $mform->addElement('header', 'clienttypeselection', get_string('mod_form_block_clienttype', 'bigbluebuttonbn'));
540
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
541
                                    $field['description_key'], $cfg['clienttype_default'], $choices);
542
            return;
543
        }
544
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
545
                                null, $cfg['clienttype_default']);
546
    }
547
548
    /**
549
     * Function for showing the block for integration with the calendar.
550
     *
551
     * @param object $mform
552
     * @param object $activity
553
     * @return void
554
     */
555
    private function bigbluebuttonbn_mform_add_block_schedule(&$mform, &$activity) {
556
        $mform->addElement('header', 'schedule', get_string('mod_form_block_schedule', 'bigbluebuttonbn'));
557
        if (isset($activity->openingtime) && $activity->openingtime != 0 ||
558
            isset($activity->closingtime) && $activity->closingtime != 0) {
559
            $mform->setExpanded('schedule');
560
        }
561
        $mform->addElement('date_time_selector', 'openingtime',
562
            get_string('mod_form_field_openingtime', 'bigbluebuttonbn'), array('optional' => true));
563
        $mform->setDefault('openingtime', 0);
564
        $mform->addElement('date_time_selector', 'closingtime',
565
            get_string('mod_form_field_closingtime', 'bigbluebuttonbn'), array('optional' => true));
566
        $mform->setDefault('closingtime', 0);
567
    }
568
569
    /**
570
     * Function for showing an element.
571
     *
572
     * @param object $mform
573
     * @param string $type
574
     * @param string $name
575
     * @param string $datatype
576
     * @param string $descriptionkey
577
     * @param string $defaultvalue
578
     * @param array $options
579
     * @param string $rule
580
     * @return void
581
     */
582
    private function bigbluebuttonbn_mform_add_element(&$mform, $type, $name, $datatype,
583
            $descriptionkey, $defaultvalue = null, $options = null, $rule = null) {
584
        if ($type === 'hidden' || $type === 'static') {
585
            $mform->addElement($type, $name, $defaultvalue);
586
            $mform->setType($name, $datatype);
587
            return;
588
        }
589
        $mform->addElement($type, $name, get_string($descriptionkey, 'bigbluebuttonbn'), $options);
590
        if (get_string_manager()->string_exists($descriptionkey.'_help', 'bigbluebuttonbn')) {
591
            $mform->addHelpButton($name, $descriptionkey, 'bigbluebuttonbn');
592
        }
593
        if (!empty($rule)) {
594
            $mform->addRule($name, $rule['message'], $rule['type'], $rule['rule'], $rule['validator']);
595
        }
596
        $mform->setDefault($name, $defaultvalue);
597
        $mform->setType($name, $datatype);
598
    }
599
}
600