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  namespace mod_bigbluebuttonbn\local;
  18  
  19  use mod_bigbluebuttonbn\instance;
  20  use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
  21  use mod_bigbluebuttonbn\recording;
  22  
  23  /**
  24   * Handles the global configuration based on config.php.
  25   *
  26   * @package   mod_bigbluebuttonbn
  27   * @copyright 2010 onwards, Blindside Networks Inc
  28   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
  30   */
  31  class config {
  32  
  33      /** @var string Default bigbluebutton server url */
  34      public const DEFAULT_SERVER_URL = 'https://test-moodle.blindsidenetworks.com/bigbluebutton/';
  35  
  36      /** @var string Default bigbluebutton server shared secret */
  37      public const DEFAULT_SHARED_SECRET = '0b21fcaf34673a8c3ec8ed877d76ae34';
  38  
  39      /** @var string Default bigbluebutton data processing agreement url */
  40      public const DEFAULT_DPA_URL = 'https://blindsidenetworks.com/dpa-moodle-free-tier';
  41  
  42      /**
  43       * Returns moodle version.
  44       *
  45       * @return string
  46       */
  47      protected static function get_moodle_version_major(): string {
  48          global $CFG;
  49          $versionarray = explode('.', $CFG->version);
  50          return $versionarray[0];
  51      }
  52  
  53      /**
  54       * Returns configuration default values.
  55       *
  56       * @return array
  57       */
  58      protected static function defaultvalues(): array {
  59          return [
  60              'server_url' => self::DEFAULT_SERVER_URL,
  61              'shared_secret' => self::DEFAULT_SHARED_SECRET,
  62              'voicebridge_editable' => false,
  63              'importrecordings_enabled' => false,
  64              'importrecordings_from_deleted_enabled' => false,
  65              'waitformoderator_default' => false,
  66              'waitformoderator_editable' => true,
  67              'waitformoderator_ping_interval' => '10',
  68              'waitformoderator_cache_ttl' => '60',
  69              'userlimit_default' => '0',
  70              'userlimit_editable' => false,
  71              'preuploadpresentation_editable' => false,
  72              'recordingready_enabled' => false,
  73              'recordingstatus_enabled' => false,
  74              'meetingevents_enabled' => false,
  75              'participant_moderator_default' => '0',
  76              'scheduled_pre_opening' => '10',
  77              'recordings_enabled' => true,
  78              'recordings_deleted_default' => false,
  79              'recordings_deleted_editable' => false,
  80              'recordings_imported_default' => false,
  81              'recordings_imported_editable' => false,
  82              'recordings_preview_default' => true,
  83              'recordings_preview_editable' => false,
  84              'recording_default' => true,
  85              'recording_editable' => true,
  86              'recording_refresh_period' => recording::RECORDING_REFRESH_DEFAULT_PERIOD,
  87              'recording_all_from_start_default' => false,
  88              'recording_all_from_start_editable' => false,
  89              'recording_hide_button_default' => false,
  90              'recording_hide_button_editable' => false,
  91              'recording_protect_editable' => true,
  92              'general_warning_message' => '',
  93              'general_warning_roles' => 'editingteacher,teacher',
  94              'general_warning_box_type' => 'info',
  95              'general_warning_button_text' => '',
  96              'general_warning_button_href' => '',
  97              'general_warning_button_class' => '',
  98              'muteonstart_default' => false,
  99              'muteonstart_editable' => false,
 100              'disablecam_default' => false,
 101              'disablecam_editable' => true,
 102              'disablemic_default' => false,
 103              'disablemic_editable' => true,
 104              'disableprivatechat_default' => false,
 105              'disableprivatechat_editable' => true,
 106              'disablepublicchat_default' => false,
 107              'disablepublicchat_editable' => true,
 108              'disablenote_default' => false,
 109              'disablenote_editable' => true,
 110              'hideuserlist_default' => false,
 111              'hideuserlist_editable' => true,
 112              'welcome_default' => '',
 113              'welcome_editable' => true,
 114              'default_dpa_accepted' => false,
 115              'poll_interval' => bigbluebutton_proxy::DEFAULT_POLL_INTERVAL,
 116          ];
 117      }
 118  
 119      /**
 120       * Returns default value for an specific setting.
 121       *
 122       * @param string $setting
 123       * @return string|null
 124       */
 125      public static function defaultvalue(string $setting): ?string {
 126          $defaultvalues = self::defaultvalues();
 127          if (!array_key_exists($setting, $defaultvalues)) {
 128              return null;
 129          }
 130          return $defaultvalues[$setting];
 131      }
 132  
 133      /**
 134       * Returns value for an specific setting.
 135       *
 136       * @param string $setting
 137       * @return string
 138       */
 139      public static function get(string $setting): string {
 140          global $CFG;
 141          if (isset($CFG->bigbluebuttonbn[$setting])) {
 142              return (string) $CFG->bigbluebuttonbn[$setting];
 143          }
 144          if (isset($CFG->{'bigbluebuttonbn_' . $setting})) {
 145              return (string) $CFG->{'bigbluebuttonbn_' . $setting};
 146          }
 147          return (string) self::defaultvalue($setting);
 148      }
 149  
 150      /**
 151       * Validates if recording settings are enabled.
 152       *
 153       * @return bool
 154       */
 155      public static function recordings_enabled(): bool {
 156          return (boolean) self::get('recordings_enabled');
 157      }
 158  
 159      /**
 160       * Validates if imported recording settings are enabled.
 161       *
 162       * @return bool
 163       */
 164      public static function importrecordings_enabled(): bool {
 165          return (boolean) self::get('importrecordings_enabled');
 166      }
 167  
 168      /**
 169       * Wraps current settings in an array.
 170       *
 171       * @return array
 172       */
 173      public static function get_options(): array {
 174          return [
 175              'version_major' => self::get_moodle_version_major(),
 176              'voicebridge_editable' => self::get('voicebridge_editable'),
 177              'importrecordings_enabled' => self::get('importrecordings_enabled'),
 178              'importrecordings_from_deleted_enabled' => self::get('importrecordings_from_deleted_enabled'),
 179              'waitformoderator_default' => self::get('waitformoderator_default'),
 180              'waitformoderator_editable' => self::get('waitformoderator_editable'),
 181              'userlimit_default' => self::get('userlimit_default'),
 182              'userlimit_editable' => self::get('userlimit_editable'),
 183              'preuploadpresentation_editable' => self::get('preuploadpresentation_editable'),
 184              'recordings_enabled' => self::get('recordings_enabled'),
 185              'meetingevents_enabled' => self::get('meetingevents_enabled'),
 186              'recordings_deleted_default' => self::get('recordings_deleted_default'),
 187              'recordings_deleted_editable' => self::get('recordings_deleted_editable'),
 188              'recordings_imported_default' => self::get('recordings_imported_default'),
 189              'recordings_imported_editable' => self::get('recordings_imported_editable'),
 190              'recordings_preview_default' => self::get('recordings_preview_default'),
 191              'recordings_preview_editable' => self::get('recordings_preview_editable'),
 192              'recording_default' => self::get('recording_default'),
 193              'recording_editable' => self::get('recording_editable'),
 194              'recording_refresh_period' => self::get('recording_refresh_period'),
 195              'recording_all_from_start_default' => self::get('recording_all_from_start_default'),
 196              'recording_all_from_start_editable' => self::get('recording_all_from_start_editable'),
 197              'recording_hide_button_default' => self::get('recording_hide_button_default'),
 198              'recording_hide_button_editable' => self::get('recording_hide_button_editable'),
 199              'recording_protect_editable' => self::get('recording_protect_editable'),
 200              'general_warning_message' => self::get('general_warning_message'),
 201              'general_warning_box_type' => self::get('general_warning_box_type'),
 202              'general_warning_button_text' => self::get('general_warning_button_text'),
 203              'general_warning_button_href' => self::get('general_warning_button_href'),
 204              'general_warning_button_class' => self::get('general_warning_button_class'),
 205              'muteonstart_editable' => self::get('muteonstart_editable'),
 206              'muteonstart_default' => self::get('muteonstart_default'),
 207              'disablecam_editable' => self::get('disablecam_editable'),
 208              'disablecam_default' => self::get('disablecam_default'),
 209              'disablemic_editable' => self::get('disablemic_editable'),
 210              'disablemic_default' => self::get('disablemic_default'),
 211              'disableprivatechat_editable' => self::get('disableprivatechat_editable'),
 212              'disableprivatechat_default' => self::get('disableprivatechat_default'),
 213              'disablepublicchat_editable' => self::get('disablepublicchat_editable'),
 214              'disablepublicchat_default' => self::get('disablepublicchat_default'),
 215              'disablenote_editable' => self::get('disablenote_editable'),
 216              'disablenote_default' => self::get('disablenote_default'),
 217              'hideuserlist_editable' => self::get('hideuserlist_editable'),
 218              'hideuserlist_default' => self::get('hideuserlist_default'),
 219              'welcome_default' => self::get('welcome_default'),
 220              'welcome_editable' => self::get('welcome_editable'),
 221              'poll_interval' => self::get('poll_interval'),
 222              'guestaccess_enabled' => self::get('guestaccess_enabled'),
 223          ];
 224      }
 225  
 226      /**
 227       * Helper function returns an array with enabled features for an specific profile type.
 228       *
 229       * @param array $typeprofiles
 230       * @param string|null $type
 231       *
 232       * @return array
 233       */
 234      public static function get_enabled_features(array $typeprofiles, ?string $type = null): array {
 235          $enabledfeatures = [];
 236          $features = $typeprofiles[instance::TYPE_ALL]['features'];
 237          if (!is_null($type) && key_exists($type, $typeprofiles)) {
 238              $features = $typeprofiles[$type]['features'];
 239          }
 240          $enabledfeatures['showroom'] = (in_array('all', $features) || in_array('showroom', $features));
 241          // Evaluates if recordings are enabled for the Moodle site.
 242          $enabledfeatures['showrecordings'] = false;
 243          if (self::recordings_enabled()) {
 244              $enabledfeatures['showrecordings'] = (in_array('all', $features) || in_array('showrecordings', $features));
 245          }
 246          $enabledfeatures['importrecordings'] = false;
 247          if (self::importrecordings_enabled()) {
 248              $enabledfeatures['importrecordings'] = (in_array('all', $features) || in_array('importrecordings', $features));
 249          }
 250          return $enabledfeatures;
 251      }
 252  }