Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

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

   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, ENT_COMPAT);
  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      }
 116  
 117      /**
 118       * Runs process for wipping common settings when 'recordings only'.
 119       *
 120       * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
 121       **/
 122      protected static function process_pre_save_common(stdClass $bigbluebuttonbn): void {
 123          // Make sure common settings are removed when 'recordings only'.
 124          if ($bigbluebuttonbn->type == instance::TYPE_RECORDING_ONLY) {
 125              $bigbluebuttonbn->groupmode = 0;
 126              $bigbluebuttonbn->groupingid = 0;
 127          }
 128      }
 129  
 130      /**
 131       * Runs any processes that must be run after a bigbluebuttonbn insert/update.
 132       *
 133       * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
 134       **/
 135      public static function process_post_save(stdClass $bigbluebuttonbn): void {
 136          self::process_post_save_event($bigbluebuttonbn);
 137          self::process_post_save_completion($bigbluebuttonbn);
 138      }
 139  
 140      /**
 141       * Generates an event after a bigbluebuttonbn insert/update.
 142       *
 143       * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
 144       **/
 145      protected static function process_post_save_event(stdClass $bigbluebuttonbn): void {
 146          global $CFG, $DB;
 147  
 148          require_once($CFG->dirroot . '/calendar/lib.php');
 149          $eventid = $DB->get_field('event', 'id', [
 150              'modulename' => 'bigbluebuttonbn',
 151              'instance' => $bigbluebuttonbn->id,
 152              'eventtype' => logger::EVENT_MEETING_START
 153          ]);
 154  
 155          // Delete the event from calendar when/if openingtime is NOT set.
 156          if (!isset($bigbluebuttonbn->openingtime) || !$bigbluebuttonbn->openingtime) {
 157              if ($eventid) {
 158                  $calendarevent = calendar_event::load($eventid);
 159                  $calendarevent->delete();
 160              }
 161              return;
 162          }
 163  
 164          // Add event to the calendar as openingtime is set.
 165          $event = (object) [
 166              'eventtype' => logger::EVENT_MEETING_START,
 167              'type' => CALENDAR_EVENT_TYPE_ACTION,
 168              'name' => get_string('calendarstarts', 'bigbluebuttonbn', $bigbluebuttonbn->name),
 169              'description' => format_module_intro('bigbluebuttonbn', $bigbluebuttonbn, $bigbluebuttonbn->coursemodule, false),
 170              'format' => FORMAT_HTML,
 171              'courseid' => $bigbluebuttonbn->course,
 172              'groupid' => 0,
 173              'userid' => 0,
 174              'modulename' => 'bigbluebuttonbn',
 175              'instance' => $bigbluebuttonbn->id,
 176              'timestart' => $bigbluebuttonbn->openingtime,
 177              'timeduration' => 0,
 178              'timesort' => $bigbluebuttonbn->openingtime,
 179              'visible' => instance_is_visible('bigbluebuttonbn', $bigbluebuttonbn),
 180              'priority' => null,
 181          ];
 182  
 183          // Update the event in calendar when/if eventid was found.
 184          if ($eventid) {
 185              $event->id = $eventid;
 186              $calendarevent = calendar_event::load($eventid);
 187              $calendarevent->update($event);
 188              return;
 189          }
 190          calendar_event::create($event);
 191      }
 192  
 193      /**
 194       * Generates an event after a bigbluebuttonbn activity is completed.
 195       *
 196       * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
 197       **/
 198      protected static function process_post_save_completion(stdClass $bigbluebuttonbn): void {
 199          if (empty($bigbluebuttonbn->completionexpected)) {
 200              return;
 201          }
 202          \core_completion\api::update_completion_date_event(
 203              $bigbluebuttonbn->coursemodule,
 204              'bigbluebuttonbn',
 205              $bigbluebuttonbn->id,
 206              $bigbluebuttonbn->completionexpected
 207          );
 208      }
 209  }