Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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 core_question\local\bank;
  18  
  19  /**
  20   * Class bulk_action_base is the base class for bulk actions ui.
  21   *
  22   * Every plugin wants to implement a bulk action, should extend this class, add appropriate values to the methods
  23   * and finally pass this object via plugin_feature class.
  24   *
  25   * @package    core_question
  26   * @copyright  2021 Catalyst IT Australia Pty Ltd
  27   * @author     Safat Shahin <safatshahin@catalyst-au.net>
  28   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  abstract class bulk_action_base {
  31  
  32      /**
  33       * Title of the bulk action.
  34       * Every bulk action will have a string to show in the list.
  35       *
  36       * @return string
  37       */
  38      abstract public function get_bulk_action_title(): string;
  39  
  40      /**
  41       * A unique key for the bulk action, this will be used in the api to identify the action data.
  42       * Every bulk must have a unique key to perform the action as a part of the form post in the base view.
  43       * When questions are selected, it will post according to the key its selected from the dropdown.
  44       *
  45       * @return string
  46       */
  47      public function get_bulk_action_key(): string {
  48          return '';
  49      }
  50  
  51      /**
  52       * URL of the bulk action redirect page.
  53       * Bulk action can be performed by redirecting to a page and doing the appropriate selection
  54       * and finally doing the action. The url will be url of the page where users will be redirected to
  55       * select what to do with the selected questions.
  56       *
  57       * @return \moodle_url
  58       */
  59      abstract public function get_bulk_action_url(): \moodle_url;
  60  
  61      /**
  62       * Get the capabilities for the bulk action.
  63       * The bulk actions might have some capabilities to action them as a user.
  64       * This method helps to get those caps which will be used by the base view before actioning the bulk action.
  65       * For ex: ['moodle/question:moveall', 'moodle/question:add']
  66       * At least one of the cap need to be true for the user to use this action.
  67       *
  68       * @return array|null
  69       */
  70      public function get_bulk_action_capabilities(): ?array {
  71          return null;
  72      }
  73  
  74  
  75      /**
  76       * A unique key for the bulk action, this will be used in the api to identify the action data.
  77       * Every bulk must have a unique key to perform the action as a part of the form post in the base view.
  78       * When questions are selected, it will post according to the key its selected from the dropdown.
  79       *
  80       * Note: This method is the first towards moving from get_bulk_action_key() to get_key().
  81       *
  82       * @return string
  83       */
  84      public function get_key(): string {
  85          if (!empty($this->get_bulk_action_key())) {
  86              return $this->get_bulk_action_key();
  87          }
  88          throw new \coding_exception('Bulk actions must implement the get_key() or get_bulk_action_key() method. ' .
  89              'In Moodle 4.1, get_bulk_action_key() is being deprecated and replaced by get_key().');
  90      }
  91  }