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 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\event;
  18  
  19  use coding_exception;
  20  use moodle_url;
  21  
  22  /**
  23   * The mod_bigbluebuttonbn abstract base event class. Most mod_bigbluebuttonbn events can extend this class.
  24   *
  25   * @package   mod_bigbluebuttonbn
  26   * @copyright 2010 onwards, Blindside Networks Inc
  27   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   */
  29  abstract class base extends \core\event\base {
  30  
  31      /**
  32       * Object Id Mapping.
  33       *
  34       * @var array
  35       */
  36      protected static $objectidmapping = ['db' => 'bigbluebuttonbn', 'restore' => 'bigbluebuttonbn'];
  37  
  38      /** @var $bigbluebuttonbn */
  39      protected $bigbluebuttonbn;
  40  
  41      /**
  42       * Description.
  43       *
  44       * @var string
  45       */
  46      protected $description;
  47  
  48      /**
  49       * Legacy log data.
  50       *
  51       * @var array
  52       */
  53      protected $legacylogdata;
  54  
  55      /**
  56       * Returns description of what happened.
  57       *
  58       * @return string
  59       */
  60      public function get_description() {
  61          $vars = [
  62              'userid' => $this->userid,
  63              'courseid' => $this->courseid,
  64              'objectid' => $this->objectid,
  65              'contextinstanceid' => $this->contextinstanceid,
  66              'other' => $this->other
  67          ];
  68          $string = $this->description;
  69          foreach ($vars as $key => $value) {
  70              $string = str_replace("##" . $key, $value, $string);
  71          }
  72          return $string;
  73      }
  74  
  75      /**
  76       * Returns relevant URL.
  77       *
  78       * @return moodle_url
  79       */
  80      public function get_url() {
  81          return new moodle_url('/mod/bigbluebuttonbn/view.php', ['id' => $this->contextinstanceid]);
  82      }
  83  
  84      /**
  85       * Init method.
  86       *
  87       * @param string $crud
  88       * @param int $edulevel
  89       */
  90      protected function init($crud = 'r', $edulevel = self::LEVEL_PARTICIPATING) {
  91          $this->data['crud'] = $crud;
  92          $this->data['edulevel'] = $edulevel;
  93          $this->data['objecttable'] = 'bigbluebuttonbn';
  94      }
  95  
  96      /**
  97       * Return legacy data for add_to_log().
  98       *
  99       * @return array
 100       */
 101      protected function get_legacy_logdata() {
 102          if (isset($this->legacylogdata)) {
 103              return $this->legacylogdata;
 104          }
 105  
 106          return null;
 107      }
 108  
 109      /**
 110       * Sets the legacy event log data.
 111       *
 112       * @param string $action The current action
 113       * @param string $info A detailed description of the change. But no more than 255 characters.
 114       * @param string $url The url to the assign module instance.
 115       */
 116      public function set_legacy_logdata($action = '', $info = '', $url = '') {
 117          $fullurl = 'view.php?id=' . $this->contextinstanceid;
 118          if ($url != '') {
 119              $fullurl .= '&' . $url;
 120          }
 121  
 122          $this->legacylogdata = [$this->courseid, 'bigbluebuttonbn', $action, $fullurl, $info, $this->contextinstanceid];
 123      }
 124  
 125      /**
 126       * Custom validation.
 127       *
 128       * @throws coding_exception
 129       */
 130      protected function validate_data() {
 131          parent::validate_data();
 132  
 133          if ($this->contextlevel != CONTEXT_MODULE) {
 134              throw new coding_exception('Context level must be CONTEXT_MODULE.');
 135          }
 136      }
 137  }