Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
use mod_bigbluebuttonbn\extension;
28
use mod_bigbluebuttonbn\instance;
29
use mod_bigbluebuttonbn\local\helpers\roles;
30
use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
31
 
32
defined('MOODLE_INTERNAL') || die();
33
global $CFG;
34
require_once($CFG->dirroot . '/course/moodleform_mod.php');
35
 
36
/**
37
 * Moodle class for mod_form.
38
 *
39
 * @copyright 2010 onwards, Blindside Networks Inc
40
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41
 */
42
class mod_bigbluebuttonbn_mod_form extends moodleform_mod {
43
 
44
    /**
45
     * @var array $formextensions extensions to this form
46
     */
47
    protected $formextensions = [];
48
    /**
49
     * Define (add) particular settings this activity can have.
50
     *
51
     * @return void
52
     * @throws moodle_exception
53
     */
54
    public function definition(): void {
55
        global $CFG, $DB, $PAGE;
56
        $mform = &$this->_form;
57
 
58
        // Validates if the BigBlueButton server is running.
59
        $serverversion = bigbluebutton_proxy::get_server_version();
60
        if (is_null($serverversion)) {
61
            throw new moodle_exception('general_error_unable_connect',
62
                'bigbluebuttonbn',
63
                $CFG->wwwroot . '/admin/settings.php?section=modsettingbigbluebuttonbn',
64
                \mod_bigbluebuttonbn\local\config::get('server_url')
65
            );
66
        }
67
        // UI configuration options.
68
        $cfg = \mod_bigbluebuttonbn\local\config::get_options();
69
 
70
        // Get only those that are allowed.
71
        $course = $this->_course;
72
        $context = context_course::instance($course->id);
73
        $bigbluebuttonbn = empty($this->get_current()->id) ? null : $this->get_current();
74
 
75
        $this->formextensions = extension::mod_form_addons_instances($mform, $bigbluebuttonbn, $this->get_suffix());
76
 
77
        $instancetyperofiles = $this->get_instance_type_profiles();
78
        $this->bigbluebuttonbn_mform_add_block_profiles($mform, $instancetyperofiles);
79
        // Data for participant selection.
80
        $participantlist = roles::get_participant_list($bigbluebuttonbn, $context);
81
        // Add block 'General'.
82
        $this->bigbluebuttonbn_mform_add_block_general($mform, $cfg);
83
        // Add block 'Room'.
84
        $this->bigbluebuttonbn_mform_add_block_room($mform, $cfg);
85
        // Add block 'Lock'.
86
        $this->bigbluebuttonbn_mform_add_block_locksettings($mform, $cfg);
87
        // Add block 'Preuploads'.
88
        $this->bigbluebuttonbn_mform_add_block_preuploads($mform, $cfg);
89
        // Add block 'Participant List'.
90
        $this->bigbluebuttonbn_mform_add_block_user_role_mapping($mform, $participantlist);
91
        // Add block 'Guest Access'.
92
        $this->bigbluebuttonbn_mform_add_block_guest_access($mform, $cfg, $this->current);
93
        // Add block 'Schedule'.
94
        $this->bigbluebuttonbn_mform_add_block_schedule($mform, $this->current);
95
        // Now add subplugins form elements.
96
        $this->add_subplugins_elements();
1441 ariadna 97
        // Add standard grading elements.
98
        $this->standard_grading_coursemodule_elements();
1 efrain 99
        // Add standard elements, common to all modules.
100
        $this->standard_coursemodule_elements();
101
        // Add standard buttons, common to all modules.
102
        $this->add_action_buttons();
103
 
104
        $jsvars = [
105
            'instanceTypeDefault' => array_keys($instancetyperofiles)[0],
106
        ];
107
 
108
        // Now add the instance type profiles to the form as a html hidden field.
109
        $mform->addElement('html', html_writer::div('', 'd-none', [
110
            'data-profile-types' => json_encode($instancetyperofiles),
111
            'data-participant-data' => json_encode(roles::get_participant_data($context, $bigbluebuttonbn)),
112
        ]));
113
 
114
        $PAGE->requires->js_call_amd('mod_bigbluebuttonbn/modform', 'init', [$jsvars]);
115
    }
116
 
117
    /**
118
     * Get instance type profile.
119
     *
120
     * @return array|array[]
121
     * @throws moodle_exception
122
     */
123
    protected function get_instance_type_profiles() {
124
        // Add profile data here instead of passing it by parameters.
125
        $context = context_course::instance($this->_course->id);
126
        $instancetyperofiles = bigbluebutton_proxy::get_instance_type_profiles_create_allowed(
127
            has_capability('mod/bigbluebuttonbn:addinstancewithmeeting', $context),
128
            has_capability('mod/bigbluebuttonbn:addinstancewithrecording', $context)
129
        );
130
        // If none is allowed, fail and return.
131
        if (empty($instancetyperofiles)) {
132
            global $CFG;
133
            // Also check module context for those that are allowed.
134
            $contextm = context_module::instance($this->_cm->id);
135
            $instancetyperofiles = bigbluebutton_proxy::get_instance_type_profiles_create_allowed(
136
                has_capability('mod/bigbluebuttonbn:addinstancewithmeeting', $contextm),
137
                has_capability('mod/bigbluebuttonbn:addinstancewithrecording', $contextm)
138
            );
139
            // If still none is allowed, fail and return.
140
            if (empty($instancetyperofiles)) {
141
                throw new moodle_exception('general_error_not_allowed_to_create_instances', 'bigbluebuttonbn',
142
                    $CFG->wwwroot . '/admin/settings.php?section=modsettingbigbluebuttonbn');
143
            }
144
        }
145
        return $instancetyperofiles;
146
    }
147
 
148
    /**
149
     * Prepare the attachment for being stored.
150
     *
151
     * @param array|null $defaultvalues
152
     * @return void
153
     */
154
    public function data_preprocessing(&$defaultvalues) {
155
        parent::data_preprocessing($defaultvalues);
156
 
157
        $suffix = $this->get_suffix();
158
        $completionattendanceenabledel = 'completionattendanceenabled' . $suffix;
159
        $completionattendanceel = 'completionattendance' . $suffix;
160
 
161
        // Completion: tick by default if completion attendance settings is set to 1 or more.
162
        $defaultvalues[$completionattendanceenabledel] = 0;
163
        if (!empty($defaultvalues[$completionattendanceel])) {
164
            $defaultvalues[$completionattendanceenabledel] = 1;
165
        }
166
        // Check if we are Editing an existing instance.
167
        if ($this->current->instance) {
168
            // Pre-uploaded presentation: copy existing files into draft area.
169
            try {
170
                $draftitemid = file_get_submitted_draft_itemid('presentation');
171
                file_prepare_draft_area($draftitemid, $this->context->id, 'mod_bigbluebuttonbn', 'presentation', 0,
172
                    ['subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1, 'mainfile' => true]
173
                );
174
                $defaultvalues['presentation'] = $draftitemid;
175
            } catch (Exception $e) {
176
                debugging('Presentation could not be loaded: ' . $e->getMessage(), DEBUG_DEVELOPER);
177
                return;
178
            }
179
            // Completion: tick if completion attendance settings is set to 1 or more.
180
            $defaultvalues[$completionattendanceenabledel] = 0;
181
            if (!empty($this->current->{$completionattendanceel})) {
182
                $defaultvalues[$completionattendanceenabledel] = 1;
183
            }
184
        }
185
        foreach ($this->formextensions as $formextension) {
186
            $formextension->data_preprocessing($defaultvalues);
187
        }
188
    }
189
 
190
    /**
191
     * Validates the data processed by the form.
192
     *
193
     * @param mixed $data
194
     * @param array $files
195
     * @return array
196
     */
197
    public function validation($data, $files) {
198
        $errors = parent::validation($data, $files);
199
        if (isset($data['openingtime']) && isset($data['closingtime'])) {
200
            if ($data['openingtime'] != 0 && $data['closingtime'] != 0 &&
201
                $data['closingtime'] < $data['openingtime']) {
202
                $errors['closingtime'] = get_string('bbbduetimeoverstartingtime', 'bigbluebuttonbn');
203
            }
204
        }
205
        if (isset($data['voicebridge'])) {
206
            if (!bigbluebutton_proxy::is_voicebridge_number_unique($data['instance'], $data['voicebridge'])) {
207
                $errors['voicebridge'] = get_string('mod_form_field_voicebridge_notunique_error', 'bigbluebuttonbn');
208
            }
209
        }
210
        $additionalsubpluginerrors = [];
211
        foreach ($this->formextensions as $formextension) {
212
            $additionalsubpluginerrors = array_merge($additionalsubpluginerrors, $formextension->validation($data, $files));
213
        }
214
        return array_merge($errors, $additionalsubpluginerrors);
215
    }
216
 
217
    /**
218
     * Add elements for setting the custom completion rules.
219
     *
220
     * @return array List of added element names, or names of wrapping group elements.
221
     * @category completion
222
     */
223
    public function add_completion_rules(): array {
224
        $mform = $this->_form;
225
        if (!(boolean) \mod_bigbluebuttonbn\local\config::get('meetingevents_enabled')) {
226
            return [];
227
        }
228
 
229
        $suffix = $this->get_suffix();
230
 
231
        // Elements for completion by Attendance.
232
        $attendance['rulelabel'] = get_string('completionattendance', 'bigbluebuttonbn');
233
        $completionattendanceenabledel = 'completionattendanceenabled' . $suffix;
234
        $completionattendanceel = 'completionattendance' . $suffix;
235
        $completionattendanceunitel = 'completionattendanceunit' . $suffix;
236
        $attendance['group'] = [
237
            $mform->createElement('advcheckbox', $completionattendanceenabledel, '', $attendance['rulelabel'] . '&nbsp;'),
238
            $mform->createElement('text', $completionattendanceel, 'minutes', ['size' => 3]),
239
        ];
240
        $mform->setType($completionattendanceel, PARAM_INT);
241
        $completionattendancegroupel = 'completionattendancegroup' . $suffix;
242
        $mform->addGroup($attendance['group'], $completionattendancegroupel, '', ' ', false);
243
        $completionel = 'completion' . $suffix;
244
        $mform->hideIf($completionattendancegroupel, $completionel, 'neq', COMPLETION_AGGREGATION_ANY);
245
        $mform->hideIf($completionattendanceel, $completionattendanceenabledel, 'notchecked');
246
 
247
        // Elements for completion by Engagement.
248
        $engagement['chatlabel'] = get_string('completionengagementchats', 'bigbluebuttonbn');
249
        $engagement['talklabel'] = get_string('completionengagementtalks', 'bigbluebuttonbn');
250
        $engagement['raisehand'] = get_string('completionengagementraisehand', 'bigbluebuttonbn');
251
        $engagement['pollvotes'] = get_string('completionengagementpollvotes', 'bigbluebuttonbn');
252
        $engagement['emojis'] = get_string('completionengagementemojis', 'bigbluebuttonbn');
253
 
254
        $completionengagementchatsel = 'completionengagementchats' . $suffix;
255
        $completionengagementtalksel = 'completionengagementtalks' . $suffix;
256
        $completionengagementraisehandel = 'completionengagementraisehand' . $suffix;
257
        $completionengagementpollvotesel = 'completionengagementpollvotes' . $suffix;
258
        $completionengagementemojisel = 'completionengagementemojis' . $suffix;
259
        $engagement['group'] = [
260
            $mform->createElement('advcheckbox', $completionengagementchatsel, '', $engagement['chatlabel'] . '&nbsp;&nbsp;'),
261
            $mform->createElement('advcheckbox', $completionengagementtalksel, '', $engagement['talklabel'] . '&nbsp;&nbsp;'),
262
            $mform->createElement('advcheckbox', $completionengagementraisehandel, '', $engagement['raisehand'] . '&nbsp;&nbsp;'),
263
            $mform->createElement('advcheckbox', $completionengagementpollvotesel, '', $engagement['pollvotes'] . '&nbsp;&nbsp;'),
264
            $mform->createElement('advcheckbox', $completionengagementemojisel, '', $engagement['emojis'] . '&nbsp;&nbsp;'),
265
        ];
266
        $completionengagementgroupel = 'completionengagementgroup' . $suffix;
267
        $mform->addGroup($engagement['group'], $completionengagementgroupel, '', ' ', false);
268
        $mform->addGroupRule($completionattendancegroupel, [
269
            $completionattendanceel => [
270
                [null, 'numeric', null, 'client']
271
            ]
272
        ]);
273
        $mform->hideIf($completionengagementgroupel, $completionel, 'neq', COMPLETION_AGGREGATION_ANY);
274
 
275
        $completionrules = [$completionattendancegroupel, $completionengagementgroupel];
276
        foreach ($this->formextensions as $formextension) {
277
            $completionrules = array_merge($completionrules, $formextension->add_completion_rules());
278
        }
279
        return $completionrules;
280
    }
281
 
282
    /**
283
     * Called during validation to see whether some module-specific completion rules are selected.
284
     *
285
     * @param array $data Input data not yet validated.
286
     * @return bool True if one or more rules is enabled, false if none are.
287
     */
288
    public function completion_rule_enabled($data) {
289
        $suffix = $this->get_suffix();
290
        $rules = [
291
            'completionattendanceenabled',
292
            'completionattendance',
293
            'completionengagementchats',
294
            'completionengagementtalks',
295
            'completionengagementraisehand',
296
            'completionengagementpollvotes',
297
            'completionengagementemojis'
298
        ];
299
        $enabled = array_reduce($rules, function($carry, $rule) use ($data, $suffix) {
300
            return $carry || !empty($data[$rule . $suffix]);
301
        }, false);
302
 
303
        foreach ($this->formextensions as $formextension) {
304
            $enabled = $enabled || $formextension->completion_rule_enabled($data);
305
        }
306
        return $enabled;
307
    }
308
 
309
    /**
310
     * Allows module to modify the data returned by form get_data().
311
     * This method is also called in the bulk activity completion form.
312
     *
313
     * Only available on moodleform_mod.
314
     *
315
     * @param stdClass $data the form data to be modified.
316
     */
317
    public function data_postprocessing($data) {
318
        parent::data_postprocessing($data);
319
        // Turn off completion settings if the checkboxes aren't ticked.
320
        if (!empty($data->completionunlocked)) {
321
            $suffix = $this->get_suffix();
322
            $completion = $data->{'completion' . $suffix};
323
            $autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC;
324
            if (empty($data->{'completionattendanceenabled' . $suffix}) || !$autocompletion) {
325
                $data->{'completionattendance' . $suffix} = 0;
326
            }
327
        }
328
        foreach ($this->formextensions as $formextension) {
329
            $formextension->data_postprocessing($data);
330
        }
331
    }
332
 
333
    /**
334
     * Function for showing the block for selecting profiles.
335
     *
336
     * @param MoodleQuickForm $mform
337
     * @param array $profiles
338
     * @return void
339
     */
340
    private function bigbluebuttonbn_mform_add_block_profiles(MoodleQuickForm &$mform, array $profiles): void {
341
        if ((boolean) \mod_bigbluebuttonbn\local\config::recordings_enabled()) {
342
            $mform->addElement('select', 'type', get_string('mod_form_field_instanceprofiles', 'bigbluebuttonbn'),
343
                bigbluebutton_proxy::get_instance_profiles_array($profiles));
344
            $mform->addHelpButton('type', 'mod_form_field_instanceprofiles', 'bigbluebuttonbn');
345
        }
346
    }
347
 
348
    /**
349
     * Function for showing the block for general settings.
350
     *
351
     * @param MoodleQuickForm $mform
352
     * @param array $cfg
353
     * @return void
354
     */
355
    private function bigbluebuttonbn_mform_add_block_general(MoodleQuickForm &$mform, array $cfg): void {
356
        global $CFG;
357
        $mform->addElement('header', 'general', get_string('mod_form_block_general', 'bigbluebuttonbn'));
358
        $mform->addElement('text', 'name', get_string('mod_form_field_name', 'bigbluebuttonbn'),
359
            'maxlength="64" size="32"');
360
        $mform->setType('name', empty($CFG->formatstringstriptags) ? PARAM_CLEANHTML : PARAM_TEXT);
361
        $mform->addRule('name', null, 'required', null, 'client');
362
        $this->standard_intro_elements(get_string('mod_form_field_intro', 'bigbluebuttonbn'));
363
        $mform->setAdvanced('introeditor');
364
        $mform->setAdvanced('showdescription');
365
    }
366
 
367
    /**
368
     * Function for showing details of the room settings for the room.
369
     *
370
     * @param MoodleQuickForm $mform
371
     * @param array $cfg
372
     * @return void
373
     */
374
    private function bigbluebuttonbn_mform_add_block_room_room(MoodleQuickForm &$mform, array $cfg): void {
375
        $field = ['type' => 'hidden', 'name' => 'welcome', 'data_type' => PARAM_INT,
376
            'description_key' => null];
377
        if ($cfg['welcome_editable']) {
378
            $field['type'] = 'textarea';
379
            $field['data_type'] = PARAM_CLEANHTML;
380
            $field['description_key'] = 'mod_form_field_welcome';
381
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
382
                $field['description_key'], $cfg['welcome_default'], ['wrap' => 'virtual', 'rows' => 5, 'cols' => '60']);
383
        }
384
        $field = ['type' => 'hidden', 'name' => 'voicebridge', 'data_type' => PARAM_INT,
385
            'description_key' => null];
386
        if ($cfg['voicebridge_editable']) {
387
            $field['type'] = 'text';
388
            $field['data_type'] = PARAM_TEXT;
389
            $field['description_key'] = 'mod_form_field_voicebridge';
390
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
391
                $field['description_key'], 0, ['maxlength' => 4, 'size' => 6],
392
                ['message' => get_string('mod_form_field_voicebridge_format_error', 'bigbluebuttonbn'),
393
                    'type' => 'numeric', 'rule' => '####', 'validator' => 'server']
394
            );
395
        } else {
396
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
397
                $field['description_key'], 0, ['maxlength' => 4, 'size' => 6]);
398
        }
399
        $field = ['type' => 'hidden', 'name' => 'wait', 'data_type' => PARAM_INT, 'description_key' => null];
400
        if ($cfg['waitformoderator_editable']) {
401
            $field['type'] = 'checkbox';
402
            $field['description_key'] = 'mod_form_field_wait';
403
        }
404
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
405
            $field['description_key'], $cfg['waitformoderator_default']);
406
        $field = ['type' => 'hidden', 'name' => 'userlimit', 'data_type' => PARAM_INT, 'description_key' => null];
407
        if ($cfg['userlimit_editable']) {
408
            $field['type'] = 'text';
409
            $field['data_type'] = PARAM_TEXT;
410
            $field['description_key'] = 'mod_form_field_userlimit';
411
        }
412
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
413
            $field['description_key'], $cfg['userlimit_default']);
414
        $field = ['type' => 'hidden', 'name' => 'record', 'data_type' => PARAM_INT, 'description_key' => null];
415
        if ($cfg['recording_editable']) {
416
            $field['type'] = 'checkbox';
417
            $field['description_key'] = 'mod_form_field_record';
418
        }
419
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
420
            $field['description_key'], $cfg['recording_default']);
421
 
422
        // Record all from start and hide button.
423
        $field = ['type' => 'hidden', 'name' => 'recordallfromstart', 'data_type' => PARAM_INT, 'description_key' => null];
424
        if ($cfg['recording_all_from_start_editable']) {
425
            $field['type'] = 'checkbox';
426
            $field['description_key'] = 'mod_form_field_recordallfromstart';
427
        }
428
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
429
            $field['description_key'], $cfg['recording_all_from_start_default']);
430
 
431
        $field = ['type' => 'hidden', 'name' => 'recordhidebutton', 'data_type' => PARAM_INT, 'description_key' => null];
432
        if ($cfg['recording_hide_button_editable']) {
433
            $field['type'] = 'checkbox';
434
            $field['description_key'] = 'mod_form_field_recordhidebutton';
435
        }
436
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
437
            $field['description_key'], $cfg['recording_hide_button_default']);
438
 
439
        $mform->disabledIf('recordallfromstart', 'record');
440
        $mform->disabledIf('recordhidebutton', 'record');
441
        $mform->hideIf('recordhidebutton', 'recordallfromstart', 'checked');
442
        // End Record all from start and hide button.
443
 
444
        $field = ['type' => 'hidden', 'name' => 'muteonstart', 'data_type' => PARAM_INT, 'description_key' => null];
445
        if ($cfg['muteonstart_editable']) {
446
            $field['type'] = 'checkbox';
447
            $field['description_key'] = 'mod_form_field_muteonstart';
448
        }
449
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
450
            $field['description_key'], $cfg['muteonstart_default']);
451
 
452
    }
453
 
454
    /**
455
     * Function for showing details of the lock settings for the room.
456
     *
457
     * @param MoodleQuickForm $mform
458
     * @param array $cfg
459
     * @return void
460
     */
461
    private function bigbluebuttonbn_mform_add_block_locksettings(MoodleQuickForm &$mform, array $cfg): void {
462
        $mform->addElement('header', 'lock', get_string('mod_form_locksettings', 'bigbluebuttonbn'));
463
 
464
        $locksettings = false;
465
 
466
        $field = ['type' => 'hidden', 'name' => 'disablecam', 'data_type' => PARAM_INT, 'description_key' => null];
467
        if ($cfg['disablecam_editable']) {
468
            $field['type'] = 'checkbox';
469
            $field['description_key'] = 'mod_form_field_disablecam';
470
            $locksettings = true;
471
        }
472
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
473
                $field['description_key'], $cfg['disablecam_default']);
474
 
475
        $field = ['type' => 'hidden', 'name' => 'disablemic', 'data_type' => PARAM_INT, 'description_key' => null];
476
        if ($cfg['disablemic_editable']) {
477
            $field['type'] = 'checkbox';
478
            $field['description_key'] = 'mod_form_field_disablemic';
479
            $locksettings = true;
480
        }
481
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
482
                $field['description_key'], $cfg['disablemic_default']);
483
 
484
        $field = ['type' => 'hidden', 'name' => 'disableprivatechat', 'data_type' => PARAM_INT, 'description_key' => null];
485
        if ($cfg['disableprivatechat_editable']) {
486
            $field['type'] = 'checkbox';
487
            $field['description_key'] = 'mod_form_field_disableprivatechat';
488
            $locksettings = true;
489
        }
490
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
491
                $field['description_key'], $cfg['disableprivatechat_default']);
492
 
493
        $field = ['type' => 'hidden', 'name' => 'disablepublicchat', 'data_type' => PARAM_INT, 'description_key' => null];
494
        if ($cfg['disablepublicchat_editable']) {
495
            $field['type'] = 'checkbox';
496
            $field['description_key'] = 'mod_form_field_disablepublicchat';
497
            $locksettings = true;
498
        }
499
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
500
                $field['description_key'], $cfg['disablepublicchat_default']);
501
 
502
        $field = ['type' => 'hidden', 'name' => 'disablenote', 'data_type' => PARAM_INT, 'description_key' => null];
503
        if ($cfg['disablenote_editable']) {
504
            $field['type'] = 'checkbox';
505
            $field['description_key'] = 'mod_form_field_disablenote';
506
            $locksettings = true;
507
        }
508
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
509
                $field['description_key'], $cfg['disablenote_default']);
510
 
511
        $field = ['type' => 'hidden', 'name' => 'hideuserlist', 'data_type' => PARAM_INT, 'description_key' => null];
512
        if ($cfg['hideuserlist_editable']) {
513
            $field['type'] = 'checkbox';
514
            $field['description_key'] = 'mod_form_field_hideuserlist';
515
            $locksettings = true;
516
        }
517
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
518
                $field['description_key'], $cfg['hideuserlist_default']);
519
 
520
        // Output message if no settings.
521
        if (!$locksettings) {
522
            $field = ['type' => 'static', 'name' => 'no_locksettings',
523
                    'defaultvalue' => get_string('mod_form_field_nosettings', 'bigbluebuttonbn')];
524
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], null, null,
525
                    $field['defaultvalue']);
526
        }
527
    }
528
 
529
    /**
530
     * Function for showing details of the recording settings for the room.
531
     *
532
     * @param MoodleQuickForm $mform
533
     * @param array $cfg
534
     * @return void
535
     */
536
    private function bigbluebuttonbn_mform_add_block_room_recordings(MoodleQuickForm &$mform, array $cfg): void {
537
        $recordingsettings = false;
538
        $field = ['type' => 'hidden', 'name' => 'recordings_deleted', 'data_type' => PARAM_INT,
539
            'description_key' => null];
540
        if ($cfg['recordings_deleted_editable']) {
541
            $field['type'] = 'checkbox';
542
            $field['description_key'] = 'mod_form_field_recordings_deleted';
543
            $recordingsettings = true;
544
        }
545
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
546
            $field['description_key'], $cfg['recordings_deleted_default']);
547
        $field = ['type' => 'hidden', 'name' => 'recordings_imported', 'data_type' => PARAM_INT,
548
            'description_key' => null];
549
        if ($cfg['importrecordings_enabled'] && $cfg['recordings_imported_editable']) {
550
            $field['type'] = 'checkbox';
551
            $field['description_key'] = 'mod_form_field_recordings_imported';
552
            $recordingsettings = true;
553
        }
554
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
555
            $field['description_key'], $cfg['recordings_imported_default']);
556
        $field = ['type' => 'hidden', 'name' => 'recordings_preview', 'data_type' => PARAM_INT,
557
            'description_key' => null];
558
        if ($cfg['recordings_preview_editable']) {
559
            $field['type'] = 'checkbox';
560
            $field['description_key'] = 'mod_form_field_recordings_preview';
561
            $recordingsettings = true;
562
        }
563
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
564
            $field['description_key'], $cfg['recordings_preview_default']);
565
 
566
        if (!$recordingsettings) {
567
            $field = ['type' => 'static', 'name' => 'no_recordings',
568
                'defaultvalue' => get_string('mod_form_field_nosettings', 'bigbluebuttonbn')];
569
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], null, null,
570
                $field['defaultvalue']);
571
        }
572
    }
573
 
574
    /**
575
     * Function for showing the block for room settings.
576
     *
577
     * @param MoodleQuickForm $mform
578
     * @param array $cfg
579
     * @return void
580
     */
581
    private function bigbluebuttonbn_mform_add_block_room(MoodleQuickForm &$mform, array $cfg) {
582
        if ($cfg['voicebridge_editable'] || $cfg['waitformoderator_editable'] ||
583
            $cfg['userlimit_editable'] || $cfg['recording_editable'] || $cfg['muteonstart_editable']) {
584
            $mform->addElement('header', 'room', get_string('mod_form_block_room', 'bigbluebuttonbn'));
585
            $this->bigbluebuttonbn_mform_add_block_room_room($mform, $cfg);
586
        }
587
        if ($cfg['recordings_deleted_editable'] ||
588
            $cfg['recordings_imported_editable'] || $cfg['recordings_preview_editable']) {
589
            $mform->addElement('header', 'recordings', get_string('mod_form_block_recordings', 'bigbluebuttonbn'));
590
            $this->bigbluebuttonbn_mform_add_block_room_recordings($mform, $cfg);
591
        }
592
    }
593
 
594
    /**
595
     * Function for showing the block for preuploaded presentation.
596
     *
597
     * @param MoodleQuickForm $mform
598
     * @param array $cfg
599
     * @return void
600
     */
601
    private function bigbluebuttonbn_mform_add_block_preuploads(MoodleQuickForm &$mform, array $cfg): void {
1441 ariadna 602
        $bigbluebuttonbn = get_config('mod_bigbluebuttonbn');
603
        if ($cfg['preuploadpresentation_editable'] || $bigbluebuttonbn->showpresentation_editable) {
1 efrain 604
            $mform->addElement('header', 'preuploadpresentation',
605
                get_string('mod_form_block_presentation', 'bigbluebuttonbn'));
606
            $mform->setExpanded('preuploadpresentation');
1441 ariadna 607
            if ($cfg['preuploadpresentation_editable']) {
608
                $filemanageroptions = [];
609
                $filemanageroptions['accepted_types'] = '*';
610
                $filemanageroptions['maxbytes'] = 0;
611
                $filemanageroptions['subdirs'] = 0;
612
                $filemanageroptions['maxfiles'] = 1;
613
                $filemanageroptions['mainfile'] = true;
614
                $mform->addElement('filemanager', 'presentation', get_string('selectfiles'),
615
                    null, $filemanageroptions);
616
            }
617
            if ($bigbluebuttonbn->showpresentation_editable) {
618
                $mform->addElement('advcheckbox', 'showpresentation',
619
                get_string('mod_form_field_showpresentation', 'bigbluebuttonbn'));
620
                $mform->setDefault('showpresentation', $bigbluebuttonbn->showpresentation_default);
621
            } else {
622
                $mform->addElement('hidden', 'showpresentation', 0);
623
            }
1 efrain 624
        }
1441 ariadna 625
        $mform->setType('showpresentation', PARAM_BOOL);
1 efrain 626
    }
627
 
628
    /**
629
     * Function for showing the block for setting participant roles.
630
     *
631
     * @param MoodleQuickForm $mform
632
     * @param array $participantlist
633
     * @return void
634
     */
635
    private function bigbluebuttonbn_mform_add_block_user_role_mapping(MoodleQuickForm &$mform, array $participantlist): void {
636
        global $OUTPUT;
637
        $participantselection = roles::get_participant_selection_data();
638
        $mform->addElement('header', 'permissions', get_string('mod_form_block_participants', 'bigbluebuttonbn'));
639
        $mform->setExpanded('permissions');
640
        $mform->addElement('hidden', 'participants', json_encode($participantlist));
641
        $mform->setType('participants', PARAM_TEXT);
642
        $selectiontype = new single_select(new moodle_url(qualified_me()),
643
            'bigbluebuttonbn_participant_selection_type',
644
            $participantselection['type_options'],
645
            $participantselection['type_selected']);
646
        $selectionparticipants = new single_select(new moodle_url(qualified_me()),
647
            'bigbluebuttonbn_participant_selection',
648
            $participantselection['options'],
649
            $participantselection['selected']);
650
        $action = new single_button(new moodle_url(qualified_me()),
651
            get_string('mod_form_field_participant_list_action_add', 'bigbluebuttonbn'),
652
            'post',
653
            single_button::BUTTON_SECONDARY,
654
            ['name' => 'bigbluebuttonbn_participant_selection_add']
655
        );
656
        $pformcontext = [
657
            'selectionType' => $selectiontype->export_for_template($OUTPUT),
658
            'selectionParticipant' => $selectionparticipants->export_for_template($OUTPUT),
659
            'action' => $action->export_for_template($OUTPUT),
660
        ];
661
        $html = $OUTPUT->render_from_template('mod_bigbluebuttonbn/participant_form', $pformcontext);
662
        $mform->addElement('static', 'static_participant_list',
663
            get_string('mod_form_field_participant_list', 'bigbluebuttonbn'), $html);
664
    }
665
 
666
    /**
667
     * Function to add guest acces settings to the instance
668
     *
669
     * @param MoodleQuickForm $mform
670
     * @param array $cfg
671
     * @param stdClass $current
672
     * @return void
673
     * @throws coding_exception
674
     */
675
    private function bigbluebuttonbn_mform_add_block_guest_access(MoodleQuickForm $mform, array $cfg, stdClass $current) {
676
        if (!empty($cfg['guestaccess_enabled'])) {
677
            $mform->addElement('header', 'guestaccess', get_string('mod_form_block_guestaccess', 'bigbluebuttonbn'));
678
            $mform->setExpanded('guestaccess');
679
            $mform->addElement('advcheckbox', 'guestallowed',
680
                get_string('mod_form_field_guestallowed', 'bigbluebuttonbn'));
681
            $mform->addElement('advcheckbox', 'mustapproveuser',
682
                get_string('mod_form_field_mustapproveuser', 'bigbluebuttonbn'));
683
            $mform->hideIf('mustapproveuser', 'guestallowed');
684
            if (!empty($this->_cm)) {
685
                $instance = instance::get_from_cmid($this->_cm->id);
686
                \mod_bigbluebuttonbn\form\guest_add::add_meeting_links_elements($mform);
687
                $mform->setDefault('guestjoinurl', $instance->get_guest_access_url());
688
                $mform->setDefault('guestpassword', $instance->get_guest_access_password());
689
                $mform->hideIf('guestjoinurl', 'guestallowed');
690
                $mform->hideIf('guestpassword', 'guestallowed');
691
            }
692
        } else {
693
            $mform->addElement('hidden', 'guestallowed', 0);
694
            $mform->addElement('hidden', 'mustapproveuser', 0);
695
        }
696
        $mform->setType('guestallowed', PARAM_BOOL);
697
        $mform->setType('mustapproveuser', PARAM_BOOL);
698
        $mform->setDefault('guestallowed', 0);
699
        $mform->setDefault('mustapproveuser', 1);
700
    }
701
 
702
    /**
703
     * Function for showing the block for integration with the calendar.
704
     *
705
     * @param MoodleQuickForm $mform
706
     * @param stdClass $activity
707
     * @return void
708
     */
709
    private function bigbluebuttonbn_mform_add_block_schedule(MoodleQuickForm &$mform, stdClass &$activity) {
710
        $mform->addElement('header', 'schedule', get_string('mod_form_block_schedule', 'bigbluebuttonbn'));
711
        if (!empty($activity->openingtime) || !empty($activity->closingtime)) {
712
            $mform->setExpanded('schedule');
713
        }
714
        $mform->addElement('date_time_selector', 'openingtime',
715
            get_string('mod_form_field_openingtime', 'bigbluebuttonbn'), ['optional' => true]);
716
        $mform->setDefault('openingtime', 0);
717
        $mform->addElement('date_time_selector', 'closingtime',
718
            get_string('mod_form_field_closingtime', 'bigbluebuttonbn'), ['optional' => true]);
719
        $mform->setDefault('closingtime', 0);
720
    }
721
 
722
    /**
723
     * Function for showing an element.
724
     *
725
     * @param MoodleQuickForm $mform
726
     * @param string $type
727
     * @param string $name
728
     * @param string|null $datatype
729
     * @param string|null $descriptionkey
730
     * @param mixed|null $defaultvalue
731
     * @param array|null $options
732
     * @param array|null $rule
733
     * @return void
734
     */
735
    private function bigbluebuttonbn_mform_add_element(MoodleQuickForm &$mform, string $type, string $name, ?string $datatype,
736
        ?string $descriptionkey = "", $defaultvalue = null, ?array $options = null, ?array $rule = null): void {
737
        $datatype = $datatype ?? 'hidden';
738
        if ($type === 'hidden' || $type === 'static') {
739
            $mform->addElement($type, $name, $defaultvalue);
740
            $mform->setType($name, $datatype);
741
            return;
742
        }
743
        if ($descriptionkey) {
744
            $mform->addElement($type, $name, get_string($descriptionkey, 'bigbluebuttonbn'), $options);
745
            if (get_string_manager()->string_exists($descriptionkey . '_help', 'bigbluebuttonbn')) {
746
                $mform->addHelpButton($name, $descriptionkey, 'bigbluebuttonbn');
747
            }
748
        }
749
        if (!empty($rule)) {
750
            $mform->addRule($name, $rule['message'], $rule['type'], $rule['rule'], $rule['validator']);
751
        }
752
        $mform->setDefault($name, $defaultvalue);
753
        $mform->setType($name, $datatype);
754
    }
755
 
756
    /**
757
     * Definition after data
758
     *
759
     * Here just to tweak form group in completion that should not be frozen. This avoid
760
     * unwanted warnings.
761
     */
762
    public function definition_after_data() {
763
        parent::definition_after_data();
764
        foreach ($this->formextensions as $formextension) {
765
            $formextension->definition_after_data();
766
        }
767
    }
768
 
769
    /**
770
     * Add subplugins form elements
771
     * @return void
772
     */
773
    private function add_subplugins_elements() {
774
        foreach ($this->formextensions as $formextension) {
775
            $formextension->add_fields();
776
        }
777
    }
778
}