Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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\helpers;
  18  
  19  use calendar_event;
  20  use mod_bigbluebuttonbn\instance;
  21  use mod_bigbluebuttonbn\logger;
  22  use mod_bigbluebuttonbn\plugin;
  23  use stdClass;
  24  
  25  /**
  26   * Utility class for all instance (module) routines helper.
  27   *
  28   * @package   mod_bigbluebuttonbn
  29   * @copyright 2021 onwards, Blindside Networks Inc
  30   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31   * @author    Laurent David  (laurent [at] call-learning [dt] fr)
  32   */
  33  class mod_helper {
  34  
  35      /**
  36       * Runs any processes that must run before a bigbluebuttonbn insert/update.
  37       *
  38       * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
  39       **/
  40      public static function process_pre_save(stdClass $bigbluebuttonbn) {
  41          self::process_pre_save_instance($bigbluebuttonbn);
  42          self::process_pre_save_checkboxes($bigbluebuttonbn);
  43          self::process_pre_save_common($bigbluebuttonbn);
  44          $bigbluebuttonbn->participants = htmlspecialchars_decode($bigbluebuttonbn->participants);
  45      }
  46  
  47      /**
  48       * Runs process for defining the instance (insert/update).
  49       *
  50       * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
  51       **/
  52      protected static function process_pre_save_instance(stdClass $bigbluebuttonbn): void {
  53          $bigbluebuttonbn->timemodified = time();
  54          if ((integer) $bigbluebuttonbn->instance == 0) {
  55              $bigbluebuttonbn->meetingid = 0;
  56              $bigbluebuttonbn->timecreated = time();
  57              $bigbluebuttonbn->timemodified = 0;
  58              // As it is a new activity, assign passwords.
  59              $bigbluebuttonbn->moderatorpass = plugin::random_password(12);
  60              $bigbluebuttonbn->viewerpass = plugin::random_password(12, $bigbluebuttonbn->moderatorpass);
  61          }
  62      }
  63  
  64      /**
  65       * Runs process for assigning default value to checkboxes.
  66       *
  67       * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
  68       **/
  69      protected static function process_pre_save_checkboxes($bigbluebuttonbn) {
  70          if (!isset($bigbluebuttonbn->wait)) {
  71              $bigbluebuttonbn->wait = 0;
  72          }
  73          if (!isset($bigbluebuttonbn->record)) {
  74              $bigbluebuttonbn->record = 0;
  75          }
  76          if (!isset($bigbluebuttonbn->recordallfromstart)) {
  77              $bigbluebuttonbn->recordallfromstart = 0;
  78          }
  79          if (!isset($bigbluebuttonbn->recordhidebutton)) {
  80              $bigbluebuttonbn->recordhidebutton = 0;
  81          }
  82          if (!isset($bigbluebuttonbn->recordings_html)) {
  83              $bigbluebuttonbn->recordings_html = 0;
  84          }
  85          if (!isset($bigbluebuttonbn->recordings_deleted)) {
  86              $bigbluebuttonbn->recordings_deleted = 0;
  87          }
  88          if (!isset($bigbluebuttonbn->recordings_imported)) {
  89              $bigbluebuttonbn->recordings_imported = 0;
  90          }
  91          if (!isset($bigbluebuttonbn->recordings_preview)) {
  92              $bigbluebuttonbn->recordings_preview = 0;
  93          }
  94          if (!isset($bigbluebuttonbn->muteonstart)) {
  95              $bigbluebuttonbn->muteonstart = 0;
  96          }
  97          if (!isset($bigbluebuttonbn->disablecam)) {
  98              $bigbluebuttonbn->disablecam = 0;
  99          }
 100          if (!isset($bigbluebuttonbn->disablemic)) {
 101              $bigbluebuttonbn->disablemic = 0;
 102          }
 103          if (!isset($bigbluebuttonbn->disableprivatechat)) {
 104              $bigbluebuttonbn->disableprivatechat = 0;
 105          }
 106          if (!isset($bigbluebuttonbn->disablepublicchat)) {
 107              $bigbluebuttonbn->disablepublicchat = 0;
 108          }
 109          if (!isset($bigbluebuttonbn->disablenote)) {
 110              $bigbluebuttonbn->disablenote = 0;
 111          }
 112          if (!isset($bigbluebuttonbn->hideuserlist)) {
 113              $bigbluebuttonbn->hideuserlist = 0;
 114          }
 115          if (!isset($bigbluebuttonbn->lockedlayout)) {
 116              $bigbluebuttonbn->lockedlayout = 0;
 117          }
 118          if (!isset($bigbluebuttonbn->lockonjoin)) {
 119              $bigbluebuttonbn->lockonjoin = 0;
 120          }
 121      }
 122  
 123      /**
 124       * Runs process for wipping common settings when 'recordings only'.
 125       *
 126       * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
 127       **/
 128      protected static function process_pre_save_common(stdClass $bigbluebuttonbn): void {
 129          // Make sure common settings are removed when 'recordings only'.
 130          if ($bigbluebuttonbn->type == instance::TYPE_RECORDING_ONLY) {
 131              $bigbluebuttonbn->groupmode = 0;
 132              $bigbluebuttonbn->groupingid = 0;
 133          }
 134      }
 135  
 136      /**
 137       * Runs any processes that must be run after a bigbluebuttonbn insert/update.
 138       *
 139       * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
 140       **/
 141      public static function process_post_save(stdClass $bigbluebuttonbn): void {
 142          self::process_post_save_event($bigbluebuttonbn);
 143          self::process_post_save_completion($bigbluebuttonbn);
 144      }
 145  
 146      /**
 147       * Generates an event after a bigbluebuttonbn insert/update.
 148       *
 149       * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
 150       **/
 151      protected static function process_post_save_event(stdClass $bigbluebuttonbn): void {
 152          global $CFG, $DB;
 153  
 154          require_once($CFG->dirroot . '/calendar/lib.php');
 155          $eventid = $DB->get_field('event', 'id', [
 156              'modulename' => 'bigbluebuttonbn',
 157              'instance' => $bigbluebuttonbn->id,
 158              'eventtype' => logger::EVENT_MEETING_START
 159          ]);
 160  
 161          // Delete the event from calendar when/if openingtime is NOT set.
 162          if (!isset($bigbluebuttonbn->openingtime) || !$bigbluebuttonbn->openingtime) {
 163              if ($eventid) {
 164                  $calendarevent = calendar_event::load($eventid);
 165                  $calendarevent->delete();
 166              }
 167              return;
 168          }
 169  
 170          // Add event to the calendar as openingtime is set.
 171          $event = (object) [
 172              'eventtype' => logger::EVENT_MEETING_START,
 173              'type' => CALENDAR_EVENT_TYPE_ACTION,
 174              'name' => get_string('calendarstarts', 'bigbluebuttonbn', $bigbluebuttonbn->name),
 175              'description' => format_module_intro('bigbluebuttonbn', $bigbluebuttonbn, $bigbluebuttonbn->coursemodule, false),
 176              'format' => FORMAT_HTML,
 177              'courseid' => $bigbluebuttonbn->course,
 178              'groupid' => 0,
 179              'userid' => 0,
 180              'modulename' => 'bigbluebuttonbn',
 181              'instance' => $bigbluebuttonbn->id,
 182              'timestart' => $bigbluebuttonbn->openingtime,
 183              'timeduration' => 0,
 184              'timesort' => $bigbluebuttonbn->openingtime,
 185              'visible' => instance_is_visible('bigbluebuttonbn', $bigbluebuttonbn),
 186              'priority' => null,
 187          ];
 188  
 189          // Update the event in calendar when/if eventid was found.
 190          if ($eventid) {
 191              $event->id = $eventid;
 192              $calendarevent = calendar_event::load($eventid);
 193              $calendarevent->update($event);
 194              return;
 195          }
 196          calendar_event::create($event);
 197      }
 198  
 199      /**
 200       * Generates an event after a bigbluebuttonbn activity is completed.
 201       *
 202       * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
 203       **/
 204      protected static function process_post_save_completion(stdClass $bigbluebuttonbn): void {
 205          if (empty($bigbluebuttonbn->completionexpected)) {
 206              return;
 207          }
 208          \core_completion\api::update_completion_date_event(
 209              $bigbluebuttonbn->coursemodule,
 210              'bigbluebuttonbn',
 211              $bigbluebuttonbn->id,
 212              $bigbluebuttonbn->completionexpected
 213          );
 214      }
 215  }