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\question_action_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 extends question_action_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 protected function get_url_icon_and_label(\stdClass $question): array { 79 if (!question_has_capability_on($question, 'edit')) { 80 return [null, null, null]; 81 } 82 if ($question->status === question_version_status::QUESTION_STATUS_HIDDEN) { 83 $hiddenparams = array( 84 'unhide' => $question->id, 85 'sesskey' => sesskey()); 86 $hiddenparams = array_merge($hiddenparams, $this->returnparams); 87 $url = new \moodle_url($this->deletequestionurl, $hiddenparams); 88 return [$url, 't/restore', $this->strrestore]; 89 } else { 90 $deleteparams = array( 91 'deleteselected' => $question->id, 92 'q' . $question->id => 1, 93 'sesskey' => sesskey()); 94 $deleteparams = array_merge($deleteparams, $this->returnparams); 95 if ($this->qbank->base_url()->get_param('deleteall')) { 96 $deleteparams['deleteall'] = 1; 97 } 98 $url = new \moodle_url($this->deletequestionurl, $deleteparams); 99 return [$url, 't/delete', $this->strdelete]; 100 } 101 } 102 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body