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  namespace core\event;
  18  
  19  /**
  20   * Question bank plugin event.
  21   *
  22   * This describes an administrative event relating to a question bank plugin, in the system context.
  23   * The pluginname will be stored in the other property, and userid will be the user who performed the action on the plugin.
  24   *
  25   * @package   core
  26   * @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net}
  27   * @author    Mark Johnson <mark.johnson@catalyst-eu.net>
  28   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  abstract class qbank_plugin_base extends base {
  31  
  32      protected function init() {
  33          $this->data['edulevel'] = self::LEVEL_OTHER;
  34          $this->data['crud'] = 'u';
  35          $this->context = \context_system::instance();
  36      }
  37  
  38      protected function validate_data() {
  39          if (!str_starts_with($this->data['other']['pluginname'], 'qbank_')) {
  40              throw new \coding_exception('You must provide the full frankenstyle name of a qbank plugin (e.g. qbank_usage)');
  41          }
  42      }
  43  
  44      /**
  45       * Return an event instance with $this->other['pluginname'] set to the provided plugin name.
  46       *
  47       * @param string $pluginname
  48       * @return base
  49       * @throws \coding_exception
  50       */
  51      public static function create_for_plugin(string $pluginname): base {
  52          return self::create([
  53              'other' => ['pluginname' => $pluginname],
  54          ]);
  55      }
  56  }