forked from blindsidenetworks-ps/moodle-mod_bigbluebuttonbn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_form.php
465 lines (445 loc) · 22 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
<?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-2017 Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com)
* @author Fred Dixon (ffdixon [at] blindsidenetworks [dt] com)
*/
defined('MOODLE_INTERNAL') || die();
require_once(dirname(__FILE__).'/locallib.php');
require_once($CFG->dirroot.'/course/moodleform_mod.php');
/**
* Moodle class for mod_form.
*
* @copyright 2010-2017 Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
*/
class mod_bigbluebuttonbn_mod_form extends moodleform_mod {
/**
* Define (add) particular settings this activity can have.
*
* @return void
*/
public function definition() {
global $CFG, $DB, $OUTPUT, $PAGE;
// Validates if the BigBlueButton server is running.
$serverversion = bigbluebuttonbn_get_server_version();
if (is_null($serverversion)) {
print_error('general_error_unable_connect', 'bigbluebuttonbn',
$CFG->wwwroot.'/admin/settings.php?section=modsettingbigbluebuttonbn');
return;
}
// Context.
$bigbluebuttonbn = null;
$course = null;
$courseid = optional_param('course', 0, PARAM_INT);
if ($courseid) {
$course = get_course($courseid);
}
if (!$course) {
$cm = get_coursemodule_from_id('bigbluebuttonbn',
optional_param('update', 0, PARAM_INT), 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course),
'*', MUST_EXIST);
$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn',
array('id' => $cm->instance), '*', MUST_EXIST);
}
$context = context_course::instance($course->id);
// UI configuration options.
$cfg = \mod_bigbluebuttonbn\locallib\config::get_options();
$mform = &$this->_form;
$jsvars = array();
$jsvars['instanceTypeRoomOnly'] = BIGBLUEBUTTONBN_TYPE_ROOM_ONLY;
$jsvars['instanceTypeProfiles'] = bigbluebuttonbn_get_instance_type_profiles();
$this->bigbluebuttonbn_mform_add_block_profiles($mform, $jsvars['instanceTypeProfiles']);
// Data for participant selection.
$participantlist = bigbluebuttonbn_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 'Preuploads'.
$this->bigbluebuttonbn_mform_add_block_preuploads($mform, $cfg);
// Add block 'Participant List'.
$this->bigbluebuttonbn_mform_add_block_participants($mform, $participantlist);
// Add block 'Schedule'.
$this->bigbluebuttonbn_mform_add_block_schedule($mform, $this->current);
// Add block 'client Type'.
$this->bigbluebuttonbn_mform_add_block_clienttype($mform, $cfg);
// Add standard elements, common to all modules.
$this->standard_coursemodule_elements();
// Add standard buttons, common to all modules.
$this->add_action_buttons();
// JavaScript for locales.
$PAGE->requires->strings_for_js(array_keys(bigbluebuttonbn_get_strings_for_js()), 'bigbluebuttonbn');
$jsvars['participantData'] = bigbluebuttonbn_get_participant_data($context);
$jsvars['participantList'] = $participantlist;
$jsvars['iconsEnabled'] = (boolean)$cfg['recording_icons_enabled'];
$jsvars['pixIconDelete'] = (string)$OUTPUT->pix_icon('t/delete', get_string('delete'), 'moodle');
$PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-modform',
'M.mod_bigbluebuttonbn.modform.init', array($jsvars));
}
/**
* Prepare the attachment for being stored.
*
* @param array $defaultvalues
* @return void
*/
public function data_preprocessing(&$defaultvalues) {
if ($this->current->instance) {
// Editing existing instance - 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,
array('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;
}
}
}
/**
* Validates the data processed by the form.
*
* @param array $data
* @param array $files
* @return void
*/
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 (!bigbluebuttonbn_voicebridge_unique($data['instance'], $data['voicebridge'])) {
$errors['voicebridge'] = get_string('mod_form_field_voicebridge_notunique_error', 'bigbluebuttonbn');
}
}
return $errors;
}
/**
* Function for showing the block for selecting profiles.
*
* @param object $mform
* @param array $profiles
* @return void
*/
private function bigbluebuttonbn_mform_add_block_profiles(&$mform, $profiles) {
if ((boolean)\mod_bigbluebuttonbn\locallib\config::recordings_enabled()) {
$mform->addElement('select', 'type', get_string('mod_form_field_instanceprofiles', 'bigbluebuttonbn'),
bigbluebuttonbn_get_instance_profiles_array($profiles),
array('onchange' => 'M.mod_bigbluebuttonbn.modform.updateInstanceTypeProfile(this);'));
$mform->addHelpButton('type', 'mod_form_field_instanceprofiles', 'bigbluebuttonbn');
}
}
/**
* Function for showing the block for general settings.
*
* @param object $mform
* @param array $cfg
* @return void
*/
private function bigbluebuttonbn_mform_add_block_general(&$mform, $cfg) {
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');
if ($cfg['version_major'] < '2015051100') {
// This is valid before v2.9.
$this->add_intro_editor(false, get_string('mod_form_field_intro', 'bigbluebuttonbn'));
} else {
// This is valid after v2.9.
$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 object $mform
* @param array $cfg
* @return void
*/
private function bigbluebuttonbn_mform_add_block_room_room(&$mform, $cfg) {
$field = ['type' => 'textarea', 'name' => 'welcome', 'data_type' => PARAM_TEXT,
'description_key' => 'mod_form_field_welcome'];
$this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
$field['description_key'], '', ['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']);
}
/**
* Function for showing details of the recording settings for the room.
*
* @param object $mform
* @param array $cfg
* @return void
*/
private function bigbluebuttonbn_mform_add_block_room_recordings(&$mform, $cfg) {
$field = ['type' => 'hidden', 'name' => 'recordings_html', 'data_type' => PARAM_INT,
'description_key' => null];
if ($cfg['recordings_html_editable']) {
$field['type'] = 'checkbox';
$field['description_key'] = 'mod_form_field_recordings_html';
}
$this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
$field['description_key'], $cfg['recordings_html_default']);
$field = ['type' => 'hidden', 'name' => 'recordings_deleted', 'data_type' => PARAM_INT,
'description_key' => null];
if ($cfg['recordings_deleted_editable']) {
$field['type'] = 'checkbox';
$field['description_key'] = 'mod_form_field_recordings_deleted';
}
$this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
$field['description_key'], $cfg['recordings_deleted_default']);
$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';
}
$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';
}
$this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
$field['description_key'], $cfg['recordings_preview_default']);
}
/**
* Function for showing the block for room settings.
*
* @param object $mform
* @param array $cfg
* @return void
*/
private function bigbluebuttonbn_mform_add_block_room(&$mform, $cfg) {
if ($cfg['voicebridge_editable'] || $cfg['waitformoderator_editable'] ||
$cfg['userlimit_editable'] || $cfg['recording_editable']) {
$mform->addElement('header', 'room', get_string('mod_form_block_room', 'bigbluebuttonbn'));
$this->bigbluebuttonbn_mform_add_block_room_room($mform, $cfg);
}
if ($cfg['recordings_html_editable'] || $cfg['recordings_deleted_editable'] ||
$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 object $mform
* @param array $cfg
* @return void
*/
private function bigbluebuttonbn_mform_add_block_preuploads(&$mform, $cfg) {
if ($cfg['preuploadpresentation_enabled']) {
$mform->addElement('header', 'preuploadpresentation',
get_string('mod_form_block_presentation', 'bigbluebuttonbn'));
$mform->setExpanded('preuploadpresentation');
$filemanageroptions = array();
$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 object $mform
* @param string $participantlist
* @return void
*/
private function bigbluebuttonbn_mform_add_block_participants(&$mform, $participantlist) {
$participantselection = bigbluebuttonbn_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);
// Render elements for participant selection.
$htmlselectiontype = html_writer::select($participantselection['type_options'],
'bigbluebuttonbn_participant_selection_type', $participantselection['type_selected'], array(),
array('id' => 'bigbluebuttonbn_participant_selection_type',
'onchange' => 'M.mod_bigbluebuttonbn.modform.participantSelectionSet(); return 0;'));
$htmlselectionoptions = html_writer::select($participantselection['options'], 'bigbluebuttonbn_participant_selection',
$participantselection['selected'], array(),
array('id' => 'bigbluebuttonbn_participant_selection', 'disabled' => 'disabled'));
$htmlselectioninput = html_writer::tag('input', '', array('id' => 'id_addselectionid',
'type' => 'button', 'class' => 'btn btn-secondary',
'value' => get_string('mod_form_field_participant_list_action_add', 'bigbluebuttonbn'),
'onclick' => 'M.mod_bigbluebuttonbn.modform.participantAdd(); return 0;'
));
$htmladdparticipant = html_writer::tag('div',
$htmlselectiontype . ' ' . $htmlselectionoptions . ' ' . $htmlselectioninput, null);
$mform->addElement('html', "\n\n");
$mform->addElement('static', 'static_add_participant',
get_string('mod_form_field_participant_add', 'bigbluebuttonbn'), $htmladdparticipant);
$mform->addElement('html', "\n\n");
// Declare the table.
$htmltable = new html_table();
$htmltable->align = array('left', 'left', 'left', 'left');
$htmltable->id = 'participant_list_table';
$htmltable->data = array(array());
// Render elements for participant list.
$htmlparticipantlist = html_writer::table($htmltable);
$mform->addElement('html', "\n\n");
$mform->addElement('static', 'static_participant_list',
get_string('mod_form_field_participant_list', 'bigbluebuttonbn'), $htmlparticipantlist);
$mform->addElement('html', "\n\n");
}
/**
* Function for showing the client type
*
* @param object $mform
* @param object $cfg
* @return void
*/
private function bigbluebuttonbn_mform_add_block_clienttype(&$mform, &$cfg) {
// Validates if clienttype capability is enabled.
if (!$cfg['clienttype_enabled']) {
return;
}
// Validates if the html5client is supported by the BigBlueButton Server.
if (!bigbluebuttonbn_has_html5_client()) {
return;
}
$field = ['type' => 'hidden', 'name' => 'clienttype', 'data_type' => PARAM_INT,
'description_key' => null];
if ($cfg['clienttype_editable']) {
$field['type'] = 'select';
$field['data_type'] = PARAM_TEXT;
$field['description_key'] = 'mod_form_field_block_clienttype';
$choices = array(BIGBLUEBUTTON_CLIENTTYPE_FLASH => get_string('mod_form_block_clienttype_flash', 'bigbluebuttonbn'),
BIGBLUEBUTTON_CLIENTTYPE_HTML5 => get_string('mod_form_block_clienttype_html5', 'bigbluebuttonbn'));
$mform->addElement('header', 'clienttypeselection', get_string('mod_form_block_clienttype', 'bigbluebuttonbn'));
$this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
$field['description_key'], $cfg['clienttype_default'], $choices);
return;
}
$this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
null, $cfg['clienttype_default']);
}
/**
* Function for showing the block for integration with the calendar.
*
* @param object $mform
* @param object $activity
* @return void
*/
private function bigbluebuttonbn_mform_add_block_schedule(&$mform, &$activity) {
$mform->addElement('header', 'schedule', get_string('mod_form_block_schedule', 'bigbluebuttonbn'));
if (isset($activity->openingtime) && $activity->openingtime != 0 ||
isset($activity->closingtime) && $activity->closingtime != 0) {
$mform->setExpanded('schedule');
}
$mform->addElement('date_time_selector', 'openingtime',
get_string('mod_form_field_openingtime', 'bigbluebuttonbn'), array('optional' => true));
$mform->setDefault('openingtime', 0);
$mform->addElement('date_time_selector', 'closingtime',
get_string('mod_form_field_closingtime', 'bigbluebuttonbn'), array('optional' => true));
$mform->setDefault('closingtime', 0);
}
/**
* Function for showing an element.
*
* @param object $mform
* @param string $type
* @param string $name
* @param string $datatype
* @param string $descriptionkey
* @param string $defaultvalue
* @param array $options
* @param string $rule
* @return void
*/
private function bigbluebuttonbn_mform_add_element(&$mform, $type, $name, $datatype,
$descriptionkey, $defaultvalue = null, $options = null, $rule = null) {
if ($type === 'hidden') {
$mform->addElement($type, $name, $defaultvalue);
$mform->setType($name, $datatype);
return;
}
$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);
}
}