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