Completed
Pull Request — master (#90)
by Jesus
03:34 queued 01:36
created

mod_bigbluebuttonbn_mod_form   D

Complexity

Total Complexity 58

Size/Duplication

Total Lines 434
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 58
lcom 1
cbo 1
dl 0
loc 434
rs 4.5599
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
B definition() 0 67 5
A data_preprocessing() 0 15 3
B validation() 0 15 8
A bigbluebuttonbn_mform_add_block_profiles() 0 7 2
A bigbluebuttonbn_mform_add_block_general() 0 17 3
B bigbluebuttonbn_mform_add_block_room_room() 0 50 6
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
        // Get only those that are allowed.
75
        $jsvars['instanceTypeProfiles'] = bigbluebuttonbn_get_instance_type_profiles_create_allowed(
76
            has_capability('mod/bigbluebuttonbn:room'), has_capability('mod/bigbluebuttonbn:recording', $context));
77
        $jsvars['instanceTypeDefault'] = array_keys($jsvars['instanceTypeProfiles'])[0];
78
        // If none is allowed, fail and return
79
        if (empty($jsvars['instanceTypeProfiles'])) {
80
            print_error('general_error_not_allowed_to_create_instances)', 'bigbluebuttonbn',
81
                $CFG->wwwroot.'/admin/settings.php?section=modsettingbigbluebuttonbn');
82
            return;
83
        }
84
        $this->bigbluebuttonbn_mform_add_block_profiles($mform, $jsvars['instanceTypeProfiles']);
85
        // Data for participant selection.
86
        $participantlist = bigbluebuttonbn_get_participant_list($bigbluebuttonbn, $context);
87
        // Add block 'General'.
88
        $this->bigbluebuttonbn_mform_add_block_general($mform, $cfg);
89
        // Add block 'Room'.
90
        $this->bigbluebuttonbn_mform_add_block_room($mform, $cfg);
91
        // Add block 'Preuploads'.
92
        $this->bigbluebuttonbn_mform_add_block_preuploads($mform, $cfg);
93
        // Add block 'Participant List'.
94
        $this->bigbluebuttonbn_mform_add_block_participants($mform, $participantlist);
95
        // Add block 'Schedule'.
96
        $this->bigbluebuttonbn_mform_add_block_schedule($mform, $this->current);
97
        // Add block 'client Type'.
98
        $this->bigbluebuttonbn_mform_add_block_clienttype($mform, $cfg);
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
        // JavaScript for locales.
104
        $PAGE->requires->strings_for_js(array_keys(bigbluebuttonbn_get_strings_for_js()), 'bigbluebuttonbn');
105
        $jsvars['participantData'] = bigbluebuttonbn_get_participant_data($context);
106
        $jsvars['participantList'] = $participantlist;
107
        $jsvars['iconsEnabled'] = (boolean)$cfg['recording_icons_enabled'];
108
        $jsvars['pixIconDelete'] = (string)$OUTPUT->pix_icon('t/delete', get_string('delete'), 'moodle');
109
        $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-modform',
110
            'M.mod_bigbluebuttonbn.modform.init', array($jsvars));
111
    }
112
113
    /**
114
     * Prepare the attachment for being stored.
115
     *
116
     * @param array $defaultvalues
117
     * @return void
118
     */
119
    public function data_preprocessing(&$defaultvalues) {
120
        if ($this->current->instance) {
121
            // Editing existing instance - copy existing files into draft area.
122
            try {
123
                $draftitemid = file_get_submitted_draft_itemid('presentation');
124
                file_prepare_draft_area($draftitemid, $this->context->id, 'mod_bigbluebuttonbn', 'presentation', 0,
125
                    array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1, 'mainfile' => true)
126
                );
127
                $defaultvalues['presentation'] = $draftitemid;
128
            } catch (Exception $e) {
129
                debugging('Presentation could not be loaded: '.$e->getMessage(), DEBUG_DEVELOPER);
130
                return;
131
            }
132
        }
133
    }
134
135
    /**
136
     * Validates the data processed by the form.
137
     *
138
     * @param array $data
139
     * @param array $files
140
     * @return void
141
     */
142
    public function validation($data, $files) {
143
        $errors = parent::validation($data, $files);
144
        if (isset($data['openingtime']) && isset($data['closingtime'])) {
145
            if ($data['openingtime'] != 0 && $data['closingtime'] != 0 &&
146
                $data['closingtime'] < $data['openingtime']) {
147
                $errors['closingtime'] = get_string('bbbduetimeoverstartingtime', 'bigbluebuttonbn');
148
            }
149
        }
150
        if (isset($data['voicebridge'])) {
151
            if (!bigbluebuttonbn_voicebridge_unique($data['instance'], $data['voicebridge'])) {
152
                $errors['voicebridge'] = get_string('mod_form_field_voicebridge_notunique_error', 'bigbluebuttonbn');
153
            }
154
        }
155
        return $errors;
156
    }
157
158
    /**
159
     * Function for showing the block for selecting profiles.
160
     *
161
     * @param object $mform
162
     * @param array $profiles
163
     * @return void
164
     */
165
    private function bigbluebuttonbn_mform_add_block_profiles(&$mform, $profiles) {
166
        if ((boolean)\mod_bigbluebuttonbn\locallib\config::recordings_enabled()) {
167
            $mform->addElement('select', 'type', get_string('mod_form_field_instanceprofiles', 'bigbluebuttonbn'),
168
                $profiles, array('onchange' => 'M.mod_bigbluebuttonbn.modform.updateInstanceTypeProfile(this);'));
169
            $mform->addHelpButton('type', 'mod_form_field_instanceprofiles', 'bigbluebuttonbn');
170
        }
171
    }
172
173
    /**
174
     * Function for showing the block for general settings.
175
     *
176
     * @param object $mform
177
     * @param array $cfg
178
     * @return void
179
     */
180
    private function bigbluebuttonbn_mform_add_block_general(&$mform, $cfg) {
181
        global $CFG;
182
        $mform->addElement('header', 'general', get_string('mod_form_block_general', 'bigbluebuttonbn'));
183
        $mform->addElement('text', 'name', get_string('mod_form_field_name', 'bigbluebuttonbn'),
184
            'maxlength="64" size="32"');
185
        $mform->setType('name', empty($CFG->formatstringstriptags) ? PARAM_CLEANHTML : PARAM_TEXT);
186
        $mform->addRule('name', null, 'required', null, 'client');
187
        $this->standard_intro_elements(get_string('mod_form_field_intro', 'bigbluebuttonbn'));
188
        $mform->setAdvanced('introeditor');
189
        $mform->setAdvanced('showdescription');
190
        if ($cfg['sendnotifications_enabled']) {
191
            $field = ['type' => 'checkbox', 'name' => 'notification', 'data_type' => PARAM_INT,
192
                'description_key' => 'mod_form_field_notification'];
193
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
194
                $field['description_key'], 0);
195
        }
196
    }
197
198
    /**
199
     * Function for showing details of the room settings for the room.
200
     *
201
     * @param object $mform
202
     * @param array $cfg
203
     * @return void
204
     */
205
    private function bigbluebuttonbn_mform_add_block_room_room(&$mform, $cfg) {
206
        $field = ['type' => 'textarea', 'name' => 'welcome', 'data_type' => PARAM_TEXT,
207
            'description_key' => 'mod_form_field_welcome'];
208
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
209
            $field['description_key'], '', ['wrap' => 'virtual', 'rows' => 5, 'cols' => '60']);
210
        $field = ['type' => 'hidden', 'name' => 'voicebridge', 'data_type' => PARAM_INT,
211
            'description_key' => null];
212
        if ($cfg['voicebridge_editable']) {
213
            $field['type'] = 'text';
214
            $field['data_type'] = PARAM_TEXT;
215
            $field['description_key'] = 'mod_form_field_voicebridge';
216
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
217
                $field['description_key'], 0, ['maxlength' => 4, 'size' => 6],
218
                ['message' => get_string('mod_form_field_voicebridge_format_error', 'bigbluebuttonbn'),
219
                 'type' => 'numeric', 'rule' => '####', 'validator' => 'server']
220
              );
221
        } else {
222
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
223
                $field['description_key'], 0, ['maxlength' => 4, 'size' => 6]);
224
        }
225
        $field = ['type' => 'hidden', 'name' => 'wait', 'data_type' => PARAM_INT, 'description_key' => null];
226
        if ($cfg['waitformoderator_editable']) {
227
            $field['type'] = 'checkbox';
228
            $field['description_key'] = 'mod_form_field_wait';
229
        }
230
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
231
            $field['description_key'], $cfg['waitformoderator_default']);
232
        $field = ['type' => 'hidden', 'name' => 'userlimit', 'data_type' => PARAM_INT, 'description_key' => null];
233
        if ($cfg['userlimit_editable']) {
234
            $field['type'] = 'text';
235
            $field['data_type'] = PARAM_TEXT;
236
            $field['description_key'] = 'mod_form_field_userlimit';
237
        }
238
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
239
            $field['description_key'], $cfg['userlimit_default']);
240
        $field = ['type' => 'hidden', 'name' => 'record', 'data_type' => PARAM_INT, 'description_key' => null];
241
        if ($cfg['recording_editable']) {
242
            $field['type'] = 'checkbox';
243
            $field['description_key'] = 'mod_form_field_record';
244
        }
245
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
246
            $field['description_key'], $cfg['recording_default']);
247
        $field = ['type' => 'hidden', 'name' => 'muteonstart', 'data_type' => PARAM_INT, 'description_key' => null];
248
        if ($cfg['muteonstart_editable']) {
249
            $field['type'] = 'checkbox';
250
            $field['description_key'] = 'mod_form_field_muteonstart';
251
        }
252
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
253
            $field['description_key'], $cfg['muteonstart_default']);
254
    }
255
256
    /**
257
     * Function for showing details of the recording settings for the room.
258
     *
259
     * @param object $mform
260
     * @param array $cfg
261
     * @return void
262
     */
263
    private function bigbluebuttonbn_mform_add_block_room_recordings(&$mform, $cfg) {
264
        $field = ['type' => 'hidden', 'name' => 'recordings_html', 'data_type' => PARAM_INT,
265
                  'description_key' => null];
266
        if ($cfg['recordings_html_editable']) {
267
            $field['type'] = 'checkbox';
268
            $field['description_key'] = 'mod_form_field_recordings_html';
269
        }
270
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
271
            $field['description_key'], $cfg['recordings_html_default']);
272
        $field = ['type' => 'hidden', 'name' => 'recordings_deleted', 'data_type' => PARAM_INT,
273
                  'description_key' => null];
274
        if ($cfg['recordings_deleted_editable']) {
275
            $field['type'] = 'checkbox';
276
            $field['description_key'] = 'mod_form_field_recordings_deleted';
277
        }
278
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
279
            $field['description_key'], $cfg['recordings_deleted_default']);
280
        $field = ['type' => 'hidden', 'name' => 'recordings_imported', 'data_type' => PARAM_INT,
281
                  'description_key' => null];
282
        if ($cfg['importrecordings_enabled'] && $cfg['recordings_imported_editable']) {
283
            $field['type'] = 'checkbox';
284
            $field['description_key'] = 'mod_form_field_recordings_imported';
285
        }
286
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
287
            $field['description_key'], $cfg['recordings_imported_default']);
288
        $field = ['type' => 'hidden', 'name' => 'recordings_preview', 'data_type' => PARAM_INT,
289
                  'description_key' => null];
290
        if ($cfg['recordings_preview_editable']) {
291
            $field['type'] = 'checkbox';
292
            $field['description_key'] = 'mod_form_field_recordings_preview';
293
        }
294
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
295
            $field['description_key'], $cfg['recordings_preview_default']);
296
297
    }
298
299
    /**
300
     * Function for showing the block for room settings.
301
     *
302
     * @param object $mform
303
     * @param array $cfg
304
     * @return void
305
     */
306
    private function bigbluebuttonbn_mform_add_block_room(&$mform, $cfg) {
307
        if ($cfg['voicebridge_editable'] || $cfg['waitformoderator_editable'] ||
308
            $cfg['userlimit_editable'] || $cfg['recording_editable']) {
309
            $mform->addElement('header', 'room', get_string('mod_form_block_room', 'bigbluebuttonbn'));
310
            $this->bigbluebuttonbn_mform_add_block_room_room($mform, $cfg);
311
        }
312
        if ($cfg['recordings_html_editable'] || $cfg['recordings_deleted_editable'] ||
313
            $cfg['recordings_imported_editable'] || $cfg['recordings_preview_editable']) {
314
            $mform->addElement('header', 'recordings', get_string('mod_form_block_recordings', 'bigbluebuttonbn'));
315
            $this->bigbluebuttonbn_mform_add_block_room_recordings($mform, $cfg);
316
        }
317
    }
318
319
    /**
320
     * Function for showing the block for preuploaded presentation.
321
     *
322
     * @param object $mform
323
     * @param array $cfg
324
     * @return void
325
     */
326
    private function bigbluebuttonbn_mform_add_block_preuploads(&$mform, $cfg) {
327
        if ($cfg['preuploadpresentation_enabled']) {
328
            $mform->addElement('header', 'preuploadpresentation',
329
                get_string('mod_form_block_presentation', 'bigbluebuttonbn'));
330
            $mform->setExpanded('preuploadpresentation');
331
            $filemanageroptions = array();
332
            $filemanageroptions['accepted_types'] = '*';
333
            $filemanageroptions['maxbytes'] = 0;
334
            $filemanageroptions['subdirs'] = 0;
335
            $filemanageroptions['maxfiles'] = 1;
336
            $filemanageroptions['mainfile'] = true;
337
            $mform->addElement('filemanager', 'presentation', get_string('selectfiles'),
338
                null, $filemanageroptions);
339
        }
340
    }
341
342
    /**
343
     * Function for showing the block for setting participant roles.
344
     *
345
     * @param object $mform
346
     * @param string $participantlist
347
     * @return void
348
     */
349
    private function bigbluebuttonbn_mform_add_block_participants(&$mform, $participantlist) {
350
        $participantselection = bigbluebuttonbn_get_participant_selection_data();
351
        $mform->addElement('header', 'permissions', get_string('mod_form_block_participants', 'bigbluebuttonbn'));
352
        $mform->setExpanded('permissions');
353
        $mform->addElement('hidden', 'participants', json_encode($participantlist));
354
        $mform->setType('participants', PARAM_TEXT);
355
        // Render elements for participant selection.
356
        $htmlselectiontype = html_writer::select($participantselection['type_options'],
357
            'bigbluebuttonbn_participant_selection_type', $participantselection['type_selected'], array(),
358
            array('id' => 'bigbluebuttonbn_participant_selection_type',
359
                  'onchange' => 'M.mod_bigbluebuttonbn.modform.participantSelectionSet(); return 0;'));
360
        $htmlselectionoptions = html_writer::select($participantselection['options'], 'bigbluebuttonbn_participant_selection',
361
            $participantselection['selected'], array(),
362
            array('id' => 'bigbluebuttonbn_participant_selection', 'disabled' => 'disabled'));
363
        $htmlselectioninput = html_writer::tag('input', '', array('id' => 'id_addselectionid',
364
            'type' => 'button', 'class' => 'btn btn-secondary',
365
            'value' => get_string('mod_form_field_participant_list_action_add', 'bigbluebuttonbn'),
366
            'onclick' => 'M.mod_bigbluebuttonbn.modform.participantAdd(); return 0;'
367
          ));
368
        $htmladdparticipant = html_writer::tag('div',
369
            $htmlselectiontype . '&nbsp;&nbsp;' . $htmlselectionoptions . '&nbsp;&nbsp;' . $htmlselectioninput, null);
370
        $mform->addElement('html', "\n\n");
371
        $mform->addElement('static', 'static_add_participant',
372
            get_string('mod_form_field_participant_add', 'bigbluebuttonbn'), $htmladdparticipant);
373
        $mform->addElement('html', "\n\n");
374
        // Declare the table.
375
        $htmltable = new html_table();
376
        $htmltable->align = array('left', 'left', 'left', 'left');
377
        $htmltable->id = 'participant_list_table';
378
        $htmltable->data = array(array());
379
        // Render elements for participant list.
380
        $htmlparticipantlist = html_writer::table($htmltable);
381
        $mform->addElement('html', "\n\n");
382
        $mform->addElement('static', 'static_participant_list',
383
            get_string('mod_form_field_participant_list', 'bigbluebuttonbn'), $htmlparticipantlist);
384
        $mform->addElement('html', "\n\n");
385
    }
386
387
    /**
388
     * Function for showing the client type
389
     *
390
     * @param object $mform
391
     * @param object $cfg
392
     * @return void
393
     */
394
    private function bigbluebuttonbn_mform_add_block_clienttype(&$mform, &$cfg) {
395
        // Validates if clienttype capability is enabled.
396
        if (!$cfg['clienttype_enabled']) {
397
            return;
398
        }
399
        // Validates if the html5client is supported by the BigBlueButton Server.
400
        if (!bigbluebuttonbn_has_html5_client()) {
401
            return;
402
        }
403
        $field = ['type' => 'hidden', 'name' => 'clienttype', 'data_type' => PARAM_INT,
404
            'description_key' => null];
405
        if ($cfg['clienttype_editable']) {
406
            $field['type'] = 'select';
407
            $field['data_type'] = PARAM_TEXT;
408
            $field['description_key'] = 'mod_form_field_block_clienttype';
409
             $choices = array(BIGBLUEBUTTON_CLIENTTYPE_FLASH => get_string('mod_form_block_clienttype_flash', 'bigbluebuttonbn'),
410
                             BIGBLUEBUTTON_CLIENTTYPE_HTML5 => get_string('mod_form_block_clienttype_html5', 'bigbluebuttonbn'));
411
             $mform->addElement('header', 'clienttypeselection', get_string('mod_form_block_clienttype', 'bigbluebuttonbn'));
412
            $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
413
                                    $field['description_key'], $cfg['clienttype_default'], $choices);
414
            return;
415
        }
416
        $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'],
417
                                null, $cfg['clienttype_default']);
418
    }
419
420
    /**
421
     * Function for showing the block for integration with the calendar.
422
     *
423
     * @param object $mform
424
     * @param object $activity
425
     * @return void
426
     */
427
    private function bigbluebuttonbn_mform_add_block_schedule(&$mform, &$activity) {
428
        $mform->addElement('header', 'schedule', get_string('mod_form_block_schedule', 'bigbluebuttonbn'));
429
        if (isset($activity->openingtime) && $activity->openingtime != 0 ||
430
            isset($activity->closingtime) && $activity->closingtime != 0) {
431
            $mform->setExpanded('schedule');
432
        }
433
        $mform->addElement('date_time_selector', 'openingtime',
434
            get_string('mod_form_field_openingtime', 'bigbluebuttonbn'), array('optional' => true));
435
        $mform->setDefault('openingtime', 0);
436
        $mform->addElement('date_time_selector', 'closingtime',
437
            get_string('mod_form_field_closingtime', 'bigbluebuttonbn'), array('optional' => true));
438
        $mform->setDefault('closingtime', 0);
439
    }
440
441
    /**
442
     * Function for showing an element.
443
     *
444
     * @param object $mform
445
     * @param string $type
446
     * @param string $name
447
     * @param string $datatype
448
     * @param string $descriptionkey
449
     * @param string $defaultvalue
450
     * @param array $options
451
     * @param string $rule
452
     * @return void
453
     */
454
    private function bigbluebuttonbn_mform_add_element(&$mform, $type, $name, $datatype,
455
            $descriptionkey, $defaultvalue = null, $options = null, $rule = null) {
456
        if ($type === 'hidden') {
457
            $mform->addElement($type, $name, $defaultvalue);
458
            $mform->setType($name, $datatype);
459
            return;
460
        }
461
        $mform->addElement($type, $name, get_string($descriptionkey, 'bigbluebuttonbn'), $options);
462
        if (get_string_manager()->string_exists($descriptionkey.'_help', 'bigbluebuttonbn')) {
463
            $mform->addHelpButton($name, $descriptionkey, 'bigbluebuttonbn');
464
        }
465
        if (!empty($rule)) {
466
            $mform->addRule($name, $rule['message'], $rule['type'], $rule['rule'], $rule['validator']);
467
        }
468
        $mform->setDefault($name, $defaultvalue);
469
        $mform->setType($name, $datatype);
470
    }
471
}
472