Completed
Push — master ( e1bd88...b48e3c )
by Jesus
11:06
created

mod_bigbluebuttonbn_mod_form   C

Complexity

Total Complexity 56

Size/Duplication

Total Lines 420
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 420
rs 5.5199
c 0
b 0
f 0
wmc 56
lcom 1
cbo 1

13 Methods

Rating   Name   Duplication   Size   Complexity  
B definition() 0 59 4
A data_preprocessing() 0 15 3
B validation() 0 15 8
A bigbluebuttonbn_mform_add_block_profiles() 0 8 2
A bigbluebuttonbn_mform_add_block_general() 0 17 3
B bigbluebuttonbn_mform_add_block_room_room() 0 43 5
B bigbluebuttonbn_mform_add_block_room_recordings() 0 35 6
B bigbluebuttonbn_mform_add_block_room() 0 12 9
A bigbluebuttonbn_mform_add_block_preuploads() 0 15 2
A bigbluebuttonbn_mform_add_block_participants() 0 37 1
A bigbluebuttonbn_mform_add_block_clienttype() 0 25 4
A bigbluebuttonbn_mform_add_block_schedule() 0 13 5
A bigbluebuttonbn_mform_add_element() 0 17 4

How to fix   Complexity   

Complex Class

Complex classes like mod_bigbluebuttonbn_mod_form often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use mod_bigbluebuttonbn_mod_form, and based on these observations, apply Extract Interface, too.

1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
17
/**
18
 * Config all BigBlueButtonBN instances in this course.
19
 *
20
 * @package   mod_bigbluebuttonbn
21
 * @copyright 2010 onwards, Blindside Networks Inc
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
24
 * @author    Fred Dixon  (ffdixon [at] blindsidenetworks [dt] com)
25
 */
26
27
defined('MOODLE_INTERNAL') || die();
28
29
require_once(dirname(__FILE__).'/locallib.php');
30
require_once($CFG->dirroot.'/course/moodleform_mod.php');
31
32
/**
33
 * Moodle class for mod_form.
34
 *
35
 * @copyright 2010 onwards, Blindside Networks Inc
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class mod_bigbluebuttonbn_mod_form extends moodleform_mod {
39
40
    /**
41
     * Define (add) particular settings this activity can have.
42
     *
43
     * @return void
44
     */
45
    public function definition() {
46
        global $CFG, $DB, $OUTPUT, $PAGE;
47
        // Validates if the BigBlueButton server is running.
48
        $serverversion = bigbluebuttonbn_get_server_version();
49
        if (is_null($serverversion)) {
50
            print_error('general_error_unable_connect', 'bigbluebuttonbn',
51
                $CFG->wwwroot.'/admin/settings.php?section=modsettingbigbluebuttonbn');
52
            return;
53
        }
54
        // Context.
55
        $bigbluebuttonbn = null;
56
        $course = null;
57
        $courseid = optional_param('course', 0, PARAM_INT);
58
        if ($courseid) {
59
            $course = get_course($courseid);
60
        }
61
        if (!$course) {
62
            $cm = get_coursemodule_from_id('bigbluebuttonbn',
63
                optional_param('update', 0, PARAM_INT), 0, false, MUST_EXIST);
64
            $course = $DB->get_record('course', array('id' => $cm->course),
65
                '*', MUST_EXIST);
66
            $bigbluebuttonbn = $DB->get_record('bigbluebuttonbn',
67
                array('id' => $cm->instance), '*', MUST_EXIST);
68
        }
69
        $context = context_course::instance($course->id);
70
        // UI configuration options.
71
        $cfg = \mod_bigbluebuttonbn\locallib\config::get_options();
72
        $mform = &$this->_form;
73
        $jsvars = array();
74
        $jsvars['instanceTypeRoomOnly'] = BIGBLUEBUTTONBN_TYPE_ROOM_ONLY;
75
        $jsvars['instanceTypeProfiles'] = bigbluebuttonbn_get_instance_type_profiles();
76
        $this->bigbluebuttonbn_mform_add_block_profiles($mform, $jsvars['instanceTypeProfiles']);
77
        // Data for participant selection.
78
        $participantlist = bigbluebuttonbn_get_participant_list($bigbluebuttonbn, $context);
79
        // Add block 'General'.
80
        $this->bigbluebuttonbn_mform_add_block_general($mform, $cfg);
81
        // Add block 'Room'.
82
        $this->bigbluebuttonbn_mform_add_block_room($mform, $cfg);
83
        // Add block 'Preuploads'.
84
        $this->bigbluebuttonbn_mform_add_block_preuploads($mform, $cfg);
85
        // Add block 'Participant List'.
86
        $this->bigbluebuttonbn_mform_add_block_participants($mform, $participantlist);
87
        // Add block 'Schedule'.
88
        $this->bigbluebuttonbn_mform_add_block_schedule($mform, $this->current);
89
        // Add block 'client Type'.
90
        $this->bigbluebuttonbn_mform_add_block_clienttype($mform, $cfg);
91
        // Add standard elements, common to all modules.
92
        $this->standard_coursemodule_elements();
93
        // Add standard buttons, common to all modules.
94
        $this->add_action_buttons();
95
        // JavaScript for locales.
96
        $PAGE->requires->strings_for_js(array_keys(bigbluebuttonbn_get_strings_for_js()), 'bigbluebuttonbn');
97
        $jsvars['participantData'] = bigbluebuttonbn_get_participant_data($context);
98
        $jsvars['participantList'] = $participantlist;
99
        $jsvars['iconsEnabled'] = (boolean)$cfg['recording_icons_enabled'];
100
        $jsvars['pixIconDelete'] = (string)$OUTPUT->pix_icon('t/delete', get_string('delete'), 'moodle');
101
        $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-modform',
102
            'M.mod_bigbluebuttonbn.modform.init', array($jsvars));
103
    }
104
105
    /**
106
     * Prepare the attachment for being stored.
107
     *
108
     * @param array $defaultvalues
109
     * @return void
110
     */
111
    public function data_preprocessing(&$defaultvalues) {
112
        if ($this->current->instance) {
113
            // Editing existing instance - copy existing files into draft area.
114
            try {
115
                $draftitemid = file_get_submitted_draft_itemid('presentation');
116
                file_prepare_draft_area($draftitemid, $this->context->id, 'mod_bigbluebuttonbn', 'presentation', 0,
117
                    array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1, 'mainfile' => true)
118
                );
119
                $defaultvalues['presentation'] = $draftitemid;
120
            } catch (Exception $e) {
121
                debugging('Presentation could not be loaded: '.$e->getMessage(), DEBUG_DEVELOPER);
122
                return;
123
            }
124
        }
125
    }
126
127
    /**
128
     * Validates the data processed by the form.
129
     *
130
     * @param array $data
131
     * @param array $files
132
     * @return void
133
     */
134
    public function validation($data, $files) {
135
        $errors = parent::validation($data, $files);
136
        if (isset($data['openingtime']) && isset($data['closingtime'])) {
137
            if ($data['openingtime'] != 0 && $data['closingtime'] != 0 &&
138
                $data['closingtime'] < $data['openingtime']) {
139
                $errors['closingtime'] = get_string('bbbduetimeoverstartingtime', 'bigbluebuttonbn');
140
            }
141
        }
142
        if (isset($data['voicebridge'])) {
143
            if (!bigbluebuttonbn_voicebridge_unique($data['instance'], $data['voicebridge'])) {
144
                $errors['voicebridge'] = get_string('mod_form_field_voicebridge_notunique_error', 'bigbluebuttonbn');
145
            }
146
        }
147
        return $errors;
148
    }
149
150
    /**
151
     * Function for showing the block for selecting profiles.
152
     *
153
     * @param object $mform
154
     * @param array $profiles
155
     * @return void
156
     */
157
    private function bigbluebuttonbn_mform_add_block_profiles(&$mform, $profiles) {
158
        if ((boolean)\mod_bigbluebuttonbn\locallib\config::recordings_enabled()) {
159
            $mform->addElement('select', 'type', get_string('mod_form_field_instanceprofiles', 'bigbluebuttonbn'),
160
                bigbluebuttonbn_get_instance_profiles_array($profiles),
161
                array('onchange' => 'M.mod_bigbluebuttonbn.modform.updateInstanceTypeProfile(this);'));
162
            $mform->addHelpButton('type', 'mod_form_field_instanceprofiles', 'bigbluebuttonbn');
163
        }
164
    }
165
166
    /**
167
     * Function for showing the block for general settings.
168
     *
169
     * @param object $mform
170
     * @param array $cfg
171
     * @return void
172
     */
173
    private function bigbluebuttonbn_mform_add_block_general(&$mform, $cfg) {
174
        global $CFG;
175
        $mform->addElement('header', 'general', get_string('mod_form_block_general', 'bigbluebuttonbn'));
176
        $mform->addElement('text', 'name', get_string('mod_form_field_name', 'bigbluebuttonbn'),
177
            'maxlength="64" size="32"');
178
        $mform->setType('name', empty($CFG->formatstringstriptags) ? PARAM_CLEANHTML : PARAM_TEXT);
179
        $mform->addRule('name', null, 'required', null, 'client');
180
        $this->standard_intro_elements(get_string('mod_form_field_intro', 'bigbluebuttonbn'));
181
        $mform->setAdvanced('introeditor');
182
        $mform->setAdvanced('showdescription');
183
        if ($cfg['sendnotifications_enabled']) {
184
            $field = ['type' => 'checkbox', 'name' => 'notification', 'data_type' => PARAM_INT,
185
                'description_key' => 'mod_form_field_notification'];
186
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
187
                $field['description_key'], 0);
188
        }
189
    }
190
191
    /**
192
     * Function for showing details of the room settings for the room.
193
     *
194
     * @param object $mform
195
     * @param array $cfg
196
     * @return void
197
     */
198
    private function bigbluebuttonbn_mform_add_block_room_room(&$mform, $cfg) {
199
        $field = ['type' => 'textarea', 'name' => 'welcome', 'data_type' => PARAM_TEXT,
200
            'description_key' => 'mod_form_field_welcome'];
201
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
202
            $field['description_key'], '', ['wrap' => 'virtual', 'rows' => 5, 'cols' => '60']);
203
        $field = ['type' => 'hidden', 'name' => 'voicebridge', 'data_type' => PARAM_INT,
204
            'description_key' => null];
205
        if ($cfg['voicebridge_editable']) {
206
            $field['type'] = 'text';
207
            $field['data_type'] = PARAM_TEXT;
208
            $field['description_key'] = 'mod_form_field_voicebridge';
209
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
210
                $field['description_key'], 0, ['maxlength' => 4, 'size' => 6],
211
                ['message' => get_string('mod_form_field_voicebridge_format_error', 'bigbluebuttonbn'),
212
                 'type' => 'numeric', 'rule' => '####', 'validator' => 'server']
213
              );
214
        } else {
215
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
216
                $field['description_key'], 0, ['maxlength' => 4, 'size' => 6]);
217
        }
218
        $field = ['type' => 'hidden', 'name' => 'wait', 'data_type' => PARAM_INT, 'description_key' => null];
219
        if ($cfg['waitformoderator_editable']) {
220
            $field['type'] = 'checkbox';
221
            $field['description_key'] = 'mod_form_field_wait';
222
        }
223
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
224
            $field['description_key'], $cfg['waitformoderator_default']);
225
        $field = ['type' => 'hidden', 'name' => 'userlimit', 'data_type' => PARAM_INT, 'description_key' => null];
226
        if ($cfg['userlimit_editable']) {
227
            $field['type'] = 'text';
228
            $field['data_type'] = PARAM_TEXT;
229
            $field['description_key'] = 'mod_form_field_userlimit';
230
        }
231
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
232
            $field['description_key'], $cfg['userlimit_default']);
233
        $field = ['type' => 'hidden', 'name' => 'record', 'data_type' => PARAM_INT, 'description_key' => null];
234
        if ($cfg['recording_editable']) {
235
            $field['type'] = 'checkbox';
236
            $field['description_key'] = 'mod_form_field_record';
237
        }
238
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
239
            $field['description_key'], $cfg['recording_default']);
240
    }
241
242
    /**
243
     * Function for showing details of the recording settings for the room.
244
     *
245
     * @param object $mform
246
     * @param array $cfg
247
     * @return void
248
     */
249
    private function bigbluebuttonbn_mform_add_block_room_recordings(&$mform, $cfg) {
250
        $field = ['type' => 'hidden', 'name' => 'recordings_html', 'data_type' => PARAM_INT,
251
                  'description_key' => null];
252
        if ($cfg['recordings_html_editable']) {
253
            $field['type'] = 'checkbox';
254
            $field['description_key'] = 'mod_form_field_recordings_html';
255
        }
256
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
257
            $field['description_key'], $cfg['recordings_html_default']);
258
        $field = ['type' => 'hidden', 'name' => 'recordings_deleted', 'data_type' => PARAM_INT,
259
                  'description_key' => null];
260
        if ($cfg['recordings_deleted_editable']) {
261
            $field['type'] = 'checkbox';
262
            $field['description_key'] = 'mod_form_field_recordings_deleted';
263
        }
264
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
265
            $field['description_key'], $cfg['recordings_deleted_default']);
266
        $field = ['type' => 'hidden', 'name' => 'recordings_imported', 'data_type' => PARAM_INT,
267
                  'description_key' => null];
268
        if ($cfg['importrecordings_enabled'] && $cfg['recordings_imported_editable']) {
269
            $field['type'] = 'checkbox';
270
            $field['description_key'] = 'mod_form_field_recordings_imported';
271
        }
272
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
273
            $field['description_key'], $cfg['recordings_imported_default']);
274
        $field = ['type' => 'hidden', 'name' => 'recordings_preview', 'data_type' => PARAM_INT,
275
                  'description_key' => null];
276
        if ($cfg['recordings_preview_editable']) {
277
            $field['type'] = 'checkbox';
278
            $field['description_key'] = 'mod_form_field_recordings_preview';
279
        }
280
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
281
            $field['description_key'], $cfg['recordings_preview_default']);
282
283
    }
284
285
    /**
286
     * Function for showing the block for room settings.
287
     *
288
     * @param object $mform
289
     * @param array $cfg
290
     * @return void
291
     */
292
    private function bigbluebuttonbn_mform_add_block_room(&$mform, $cfg) {
293
        if ($cfg['voicebridge_editable'] || $cfg['waitformoderator_editable'] ||
294
            $cfg['userlimit_editable'] || $cfg['recording_editable']) {
295
            $mform->addElement('header', 'room', get_string('mod_form_block_room', 'bigbluebuttonbn'));
296
            $this->bigbluebuttonbn_mform_add_block_room_room($mform, $cfg);
297
        }
298
        if ($cfg['recordings_html_editable'] || $cfg['recordings_deleted_editable'] ||
299
            $cfg['recordings_imported_editable'] || $cfg['recordings_preview_editable']) {
300
            $mform->addElement('header', 'recordings', get_string('mod_form_block_recordings', 'bigbluebuttonbn'));
301
            $this->bigbluebuttonbn_mform_add_block_room_recordings($mform, $cfg);
302
        }
303
    }
304
305
    /**
306
     * Function for showing the block for preuploaded presentation.
307
     *
308
     * @param object $mform
309
     * @param array $cfg
310
     * @return void
311
     */
312
    private function bigbluebuttonbn_mform_add_block_preuploads(&$mform, $cfg) {
313
        if ($cfg['preuploadpresentation_enabled']) {
314
            $mform->addElement('header', 'preuploadpresentation',
315
                get_string('mod_form_block_presentation', 'bigbluebuttonbn'));
316
            $mform->setExpanded('preuploadpresentation');
317
            $filemanageroptions = array();
318
            $filemanageroptions['accepted_types'] = '*';
319
            $filemanageroptions['maxbytes'] = 0;
320
            $filemanageroptions['subdirs'] = 0;
321
            $filemanageroptions['maxfiles'] = 1;
322
            $filemanageroptions['mainfile'] = true;
323
            $mform->addElement('filemanager', 'presentation', get_string('selectfiles'),
324
                null, $filemanageroptions);
325
        }
326
    }
327
328
    /**
329
     * Function for showing the block for setting participant roles.
330
     *
331
     * @param object $mform
332
     * @param string $participantlist
333
     * @return void
334
     */
335
    private function bigbluebuttonbn_mform_add_block_participants(&$mform, $participantlist) {
336
        $participantselection = bigbluebuttonbn_get_participant_selection_data();
337
        $mform->addElement('header', 'permissions', get_string('mod_form_block_participants', 'bigbluebuttonbn'));
338
        $mform->setExpanded('permissions');
339
        $mform->addElement('hidden', 'participants', json_encode($participantlist));
340
        $mform->setType('participants', PARAM_TEXT);
341
        // Render elements for participant selection.
342
        $htmlselectiontype = html_writer::select($participantselection['type_options'],
343
            'bigbluebuttonbn_participant_selection_type', $participantselection['type_selected'], array(),
344
            array('id' => 'bigbluebuttonbn_participant_selection_type',
345
                  'onchange' => 'M.mod_bigbluebuttonbn.modform.participantSelectionSet(); return 0;'));
346
        $htmlselectionoptions = html_writer::select($participantselection['options'], 'bigbluebuttonbn_participant_selection',
347
            $participantselection['selected'], array(),
348
            array('id' => 'bigbluebuttonbn_participant_selection', 'disabled' => 'disabled'));
349
        $htmlselectioninput = html_writer::tag('input', '', array('id' => 'id_addselectionid',
350
            'type' => 'button', 'class' => 'btn btn-secondary',
351
            'value' => get_string('mod_form_field_participant_list_action_add', 'bigbluebuttonbn'),
352
            'onclick' => 'M.mod_bigbluebuttonbn.modform.participantAdd(); return 0;'
353
          ));
354
        $htmladdparticipant = html_writer::tag('div',
355
            $htmlselectiontype . '&nbsp;&nbsp;' . $htmlselectionoptions . '&nbsp;&nbsp;' . $htmlselectioninput, null);
356
        $mform->addElement('html', "\n\n");
357
        $mform->addElement('static', 'static_add_participant',
358
            get_string('mod_form_field_participant_add', 'bigbluebuttonbn'), $htmladdparticipant);
359
        $mform->addElement('html', "\n\n");
360
        // Declare the table.
361
        $htmltable = new html_table();
362
        $htmltable->align = array('left', 'left', 'left', 'left');
363
        $htmltable->id = 'participant_list_table';
364
        $htmltable->data = array(array());
365
        // Render elements for participant list.
366
        $htmlparticipantlist = html_writer::table($htmltable);
367
        $mform->addElement('html', "\n\n");
368
        $mform->addElement('static', 'static_participant_list',
369
            get_string('mod_form_field_participant_list', 'bigbluebuttonbn'), $htmlparticipantlist);
370
        $mform->addElement('html', "\n\n");
371
    }
372
373
    /**
374
     * Function for showing the client type
375
     *
376
     * @param object $mform
377
     * @param object $cfg
378
     * @return void
379
     */
380
    private function bigbluebuttonbn_mform_add_block_clienttype(&$mform, &$cfg) {
381
        // Validates if clienttype capability is enabled.
382
        if (!$cfg['clienttype_enabled']) {
383
            return;
384
        }
385
        // Validates if the html5client is supported by the BigBlueButton Server.
386
        if (!bigbluebuttonbn_has_html5_client()) {
387
            return;
388
        }
389
        $field = ['type' => 'hidden', 'name' => 'clienttype', 'data_type' => PARAM_INT,
390
            'description_key' => null];
391
        if ($cfg['clienttype_editable']) {
392
            $field['type'] = 'select';
393
            $field['data_type'] = PARAM_TEXT;
394
            $field['description_key'] = 'mod_form_field_block_clienttype';
395
             $choices = array(BIGBLUEBUTTON_CLIENTTYPE_FLASH => get_string('mod_form_block_clienttype_flash', 'bigbluebuttonbn'),
396
                             BIGBLUEBUTTON_CLIENTTYPE_HTML5 => get_string('mod_form_block_clienttype_html5', 'bigbluebuttonbn'));
397
             $mform->addElement('header', 'clienttypeselection', get_string('mod_form_block_clienttype', 'bigbluebuttonbn'));
398
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
399
                                    $field['description_key'], $cfg['clienttype_default'], $choices);
400
            return;
401
        }
402
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
403
                                null, $cfg['clienttype_default']);
404
    }
405
406
    /**
407
     * Function for showing the block for integration with the calendar.
408
     *
409
     * @param object $mform
410
     * @param object $activity
411
     * @return void
412
     */
413
    private function bigbluebuttonbn_mform_add_block_schedule(&$mform, &$activity) {
414
        $mform->addElement('header', 'schedule', get_string('mod_form_block_schedule', 'bigbluebuttonbn'));
415
        if (isset($activity->openingtime) && $activity->openingtime != 0 ||
416
            isset($activity->closingtime) && $activity->closingtime != 0) {
417
            $mform->setExpanded('schedule');
418
        }
419
        $mform->addElement('date_time_selector', 'openingtime',
420
            get_string('mod_form_field_openingtime', 'bigbluebuttonbn'), array('optional' => true));
421
        $mform->setDefault('openingtime', 0);
422
        $mform->addElement('date_time_selector', 'closingtime',
423
            get_string('mod_form_field_closingtime', 'bigbluebuttonbn'), array('optional' => true));
424
        $mform->setDefault('closingtime', 0);
425
    }
426
427
    /**
428
     * Function for showing an element.
429
     *
430
     * @param object $mform
431
     * @param string $type
432
     * @param string $name
433
     * @param string $datatype
434
     * @param string $descriptionkey
435
     * @param string $defaultvalue
436
     * @param array $options
437
     * @param string $rule
438
     * @return void
439
     */
440
    private function bigbluebuttonbn_mform_add_element(&$mform, $type, $name, $datatype,
441
            $descriptionkey, $defaultvalue = null, $options = null, $rule = null) {
442
        if ($type === 'hidden') {
443
            $mform->addElement($type, $name, $defaultvalue);
444
            $mform->setType($name, $datatype);
445
            return;
446
        }
447
        $mform->addElement($type, $name, get_string($descriptionkey, 'bigbluebuttonbn'), $options);
448
        if (get_string_manager()->string_exists($descriptionkey.'_help', 'bigbluebuttonbn')) {
449
            $mform->addHelpButton($name, $descriptionkey, 'bigbluebuttonbn');
450
        }
451
        if (!empty($rule)) {
452
            $mform->addRule($name, $rule['message'], $rule['type'], $rule['rule'], $rule['validator']);
453
        }
454
        $mform->setDefault($name, $defaultvalue);
455
        $mform->setType($name, $datatype);
456
    }
457
}
458