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 400 and 401]

   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  /**
  18   * Action to delete (or hide) a question, or restore a previously hidden question.
  19   *
  20   * @package   qbank_deletequestion
  21   * @copyright 2009 Tim Hunt
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace qbank_deletequestion;
  26  
  27  use core_question\local\bank\question_version_status;
  28  use core_question\local\bank\menu_action_column_base;
  29  
  30  /**
  31   * Action to delete (or hide) a question, or restore a previously hidden question.
  32   *
  33   * @package   qbank_deletequestion
  34   * @copyright 2009 Tim Hunt
  35   * @author    2021 Safat Shahin <safatshahin@catalyst-au.net>
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class delete_action_column extends menu_action_column_base {
  39  
  40      /**
  41       * @var string $strdelete
  42       */
  43      protected $strdelete;
  44  
  45      /**
  46       * @var string $strrestore
  47       */
  48      protected $strrestore;
  49  
  50      /**
  51       * Contains the url of the delete question page.
  52       * @var \moodle_url|string
  53       */
  54      public $deletequestionurl;
  55  
  56      /**
  57       * Array of the return parameters.
  58       * @var array $returnparams
  59       */
  60      protected $returnparams;
  61  
  62      public function init(): void {
  63          parent::init();
  64          $this->strdelete = get_string('delete');
  65          $this->strrestore = get_string('restore');
  66          $this->deletequestionurl = new \moodle_url('/question/bank/deletequestion/delete.php');
  67          if (!empty($this->qbank->cm->id)) {
  68              $this->returnparams['cmid'] = $this->qbank->cm->id;
  69          }
  70          if (!empty($this->qbank->course->id)) {
  71              $this->returnparams['courseid'] = $this->qbank->course->id;
  72          }
  73          if (!empty($this->qbank->returnurl)) {
  74              $this->returnparams['returnurl'] = $this->qbank->returnurl;
  75          }
  76      }
  77  
  78      public function get_name(): string {
  79          return 'deleteaction';
  80      }
  81  
  82      protected function get_url_icon_and_label(\stdClass $question): array {
  83          if (!question_has_capability_on($question, 'edit')) {
  84              return [null, null, null];
  85          }
  86          if ($question->status === question_version_status::QUESTION_STATUS_HIDDEN) {
  87              $hiddenparams = array(
  88                      'unhide' => $question->id,
  89                      'sesskey' => sesskey());
  90              $hiddenparams = array_merge($hiddenparams, $this->returnparams);
  91              $url = new \moodle_url($this->deletequestionurl, $hiddenparams);
  92              return [$url, 't/restore', $this->strrestore];
  93          } else {
  94              $deleteparams = array(
  95                      'deleteselected' => $question->id,
  96                      'q' . $question->id => 1,
  97                      'sesskey' => sesskey());
  98              $deleteparams = array_merge($deleteparams, $this->returnparams);
  99              if ($this->qbank->base_url()->get_param('deleteall')) {
 100                  $deleteparams['deleteall'] = 1;
 101              }
 102              $url = new \moodle_url($this->deletequestionurl, $deleteparams);
 103              return [$url, 't/delete', $this->strdelete];
 104          }
 105      }
 106  
 107      public function get_required_fields(): array {
 108          $required = parent::get_required_fields();
 109          return $required;
 110      }
 111  }