1 |
efrain |
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 |
public function get_menu_position(): int {
|
|
|
79 |
return 400;
|
|
|
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 |
}
|