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  /**
  17   * The mod_bigbluebuttonbn resetting instance helper
  18   *
  19   * @package   mod_bigbluebuttonbn
  20   * @copyright 2021 onwards, Blindside Networks Inc
  21   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   * @author    Laurent David  (laurent [at] call-learning [dt] fr)
  23   */
  24  
  25  namespace mod_bigbluebuttonbn\local\helpers;
  26  
  27  use context_module;
  28  use core_tag_tag;
  29  use mod_bigbluebuttonbn\local\config;
  30  use mod_bigbluebuttonbn\recording;
  31  
  32  /**
  33   * Utility class for resetting instance routines helper
  34   *
  35   * @package mod_bigbluebuttonbn
  36   * @copyright 2021 onwards, Blindside Networks Inc
  37   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class reset {
  40  
  41      /**
  42       * Used by the reset_course_userdata for deleting recordings
  43       *
  44       * This will delete recordings in the database and not in the remote BBB server.
  45       *
  46       * @param int $courseid
  47       */
  48      public static function reset_recordings(int $courseid): void {
  49          // Criteria for search : courseid or bigbluebuttonbn=null or subset=false or includedeleted=true.
  50          $recordings = recording::get_recordings_for_course(
  51              $courseid,
  52              [], // Exclude itself.
  53              false,
  54              true
  55          );
  56          if ($recordings) {
  57              // Remove all the recordings.
  58              foreach ($recordings as $recording) {
  59                  $recording->delete();
  60              }
  61          }
  62      }
  63  
  64      /**
  65       * Used by the reset_course_userdata for deleting tags linked to bigbluebuttonbn instances in the course.
  66       *
  67       * @param int $courseid
  68       */
  69      public static function reset_tags(int $courseid): void {
  70          global $DB;
  71          // Remove all the tags linked to the room/activities in this course.
  72          if ($bigbluebuttonbns = $DB->get_records('bigbluebuttonbn', ['course' => $courseid])) {
  73              foreach ($bigbluebuttonbns as $bigbluebuttonbn) {
  74                  if (!$cm = get_coursemodule_from_instance('bigbluebuttonbn', $bigbluebuttonbn->id, $courseid)) {
  75                      continue;
  76                  }
  77                  $context = context_module::instance($cm->id);
  78                  core_tag_tag::delete_instances('mod_bigbluebuttonbn', null, $context->id);
  79              }
  80          }
  81      }
  82  
  83      /**
  84       * Used by the reset_course_userdata for deleting events linked to bigbluebuttonbn instances in the course.
  85       *
  86       * @param string $courseid
  87       * @return bool status
  88       */
  89      public static function reset_events($courseid) {
  90          global $DB;
  91          // Remove all the events.
  92          return $DB->delete_records('event', ['modulename' => 'bigbluebuttonbn', 'courseid' => $courseid]);
  93      }
  94  
  95      /**
  96       * Returns status used on every defined reset action.
  97       *
  98       * @param string $item
  99       * @return array status array
 100       */
 101      public static function reset_getstatus(string $item): array {
 102          return ['component' => get_string('modulenameplural', 'bigbluebuttonbn'),
 103              'item' => get_string("removed{$item}", 'bigbluebuttonbn'),
 104              'error' => false];
 105      }
 106  
 107      /**
 108       * Define items to be reset by course/reset.php
 109       *
 110       * @return array
 111       */
 112      public static function reset_course_items(): array {
 113          $items = ["events" => 0, "tags" => 0, "logs" => 0];
 114          // Include recordings only if enabled.
 115          if ((boolean) config::recordings_enabled()) {
 116              $items["recordings"] = 0;
 117          }
 118          return $items;
 119      }
 120  
 121      /**
 122       * Reset logs for each BBB instance of this course
 123       *
 124       * @param int $courseid
 125       * @return bool status
 126       */
 127      public static function reset_logs(int $courseid) {
 128          global $DB;
 129          return $DB->delete_records('bigbluebuttonbn_logs', ['courseid' => $courseid]);
 130      }
 131  }