Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

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