Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported 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  namespace bbbext_simple\bigbluebuttonbn;
  17  
  18  use stdClass;
  19  
  20  /**
  21   * Class defining a way to deal with instance save/update/delete in extension
  22   *
  23   * @package   mod_bigbluebuttonbn
  24   * @copyright 2023 onwards, Blindside Networks Inc
  25   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   * @author    Laurent David (laurent@call-learning.fr)
  27   */
  28  class mod_instance_helper extends \mod_bigbluebuttonbn\local\extension\mod_instance_helper {
  29      /**
  30       * Runs any processes that must run before a bigbluebuttonbn insert/update.
  31       *
  32       * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
  33       **/
  34      public function add_instance(stdClass $bigbluebuttonbn) {
  35          global $DB;
  36          $DB->insert_record('bbbext_simple', (object) [
  37              'bigbluebuttonbnid' => $bigbluebuttonbn->id,
  38              'newfield' => $bigbluebuttonbn->newfield ?? ''
  39          ]);
  40      }
  41  
  42      /**
  43       * Runs any processes that must be run after a bigbluebuttonbn insert/update.
  44       *
  45       * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
  46       **/
  47      public function update_instance(stdClass $bigbluebuttonbn): void {
  48          global $DB;
  49          $record = $DB->get_record('bbbext_simple', [
  50              'bigbluebuttonbnid' => $bigbluebuttonbn->id,
  51          ]);
  52          // Just in case the instance was created before the extension was installed.
  53          if (empty($record)) {
  54              $record = new stdClass();
  55              $record->bigbluebuttonbnid = $bigbluebuttonbn->id;
  56              $record->newfield = $bigbluebuttonbn->newfield ?? '';
  57              $DB->insert_record('bbbext_simple', $record);
  58          } else {
  59              $record->newfield = $bigbluebuttonbn->newfield ?? '';
  60              $DB->update_record('bbbext_simple', $record);
  61          }
  62      }
  63  
  64      /**
  65       * Runs any processes that must be run after a bigbluebuttonbn delete.
  66       *
  67       * @param int $id
  68       */
  69      public function delete_instance(int $id): void {
  70          global $DB;
  71          $DB->delete_records('bbbext_simple', [
  72              'bigbluebuttonbnid' => $id,
  73          ]);
  74      }
  75  
  76      /**
  77       * Get any join table name that is used to store additional data for the instance.
  78       * @return string[]
  79       */
  80      public function get_join_tables(): array {
  81          return ['bbbext_simple'];
  82      }
  83  }