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 |
* Move questions page.
|
|
|
19 |
*
|
|
|
20 |
* @package qbank_bulkmove
|
|
|
21 |
* @copyright 2021 Catalyst IT Australia Pty Ltd
|
|
|
22 |
* @author Safat Shahin <safatshahin@catalyst-au.net>
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
require_once(__DIR__ . '/../../../config.php');
|
|
|
27 |
require_once(__DIR__ . '/../../editlib.php');
|
|
|
28 |
|
|
|
29 |
global $DB, $OUTPUT, $PAGE, $COURSE;
|
|
|
30 |
|
|
|
31 |
$moveselected = optional_param('move', false, PARAM_BOOL);
|
|
|
32 |
$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
|
|
|
33 |
$cmid = optional_param('cmid', 0, PARAM_INT);
|
|
|
34 |
$courseid = optional_param('courseid', 0, PARAM_INT);
|
|
|
35 |
$category = optional_param('category', null, PARAM_SEQUENCE);
|
|
|
36 |
$confirm = optional_param('confirm', '', PARAM_ALPHANUM);
|
|
|
37 |
$movequestionselected = optional_param('movequestionsselected', null, PARAM_RAW);
|
|
|
38 |
|
|
|
39 |
if ($returnurl) {
|
|
|
40 |
$returnurl = new moodle_url($returnurl);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
\core_question\local\bank\helper::require_plugin_enabled('qbank_bulkmove');
|
|
|
44 |
|
|
|
45 |
if ($cmid) {
|
|
|
46 |
list($module, $cm) = get_module_from_cmid($cmid);
|
|
|
47 |
require_login($cm->course, false, $cm);
|
|
|
48 |
$thiscontext = context_module::instance($cmid);
|
|
|
49 |
} else if ($courseid) {
|
|
|
50 |
require_login($courseid, false);
|
|
|
51 |
$thiscontext = context_course::instance($courseid);
|
|
|
52 |
} else {
|
|
|
53 |
throw new moodle_exception('missingcourseorcmid', 'question');
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
$contexts = new core_question\local\bank\question_edit_contexts($thiscontext);
|
|
|
57 |
$url = new moodle_url('/question/bank/bulkmove/move.php');
|
|
|
58 |
|
|
|
59 |
$PAGE->set_url($url);
|
|
|
60 |
$streditingquestions = get_string('movequestions', 'qbank_bulkmove');
|
|
|
61 |
$PAGE->set_title($streditingquestions);
|
|
|
62 |
$PAGE->set_heading($COURSE->fullname);
|
|
|
63 |
$PAGE->activityheader->disable();
|
|
|
64 |
$PAGE->set_secondary_active_tab("questionbank");
|
|
|
65 |
|
|
|
66 |
if ($category) {
|
|
|
67 |
list($tocategoryid, $contextid) = explode(',', $category);
|
|
|
68 |
if (! $tocategory = $DB->get_record('question_categories',
|
|
|
69 |
['id' => $tocategoryid, 'contextid' => $contextid])) {
|
|
|
70 |
throw new \moodle_exception('cannotfindcate', 'question');
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
if ($movequestionselected && $confirm && confirm_sesskey()) {
|
|
|
75 |
if ($confirm == md5($movequestionselected)) {
|
|
|
76 |
\qbank_bulkmove\helper::bulk_move_questions($movequestionselected, $tocategory);
|
|
|
77 |
}
|
|
|
78 |
$returnfilters = \core_question\local\bank\filter_condition_manager::update_filter_param_to_category(
|
|
|
79 |
$returnurl->param('filter'),
|
|
|
80 |
$tocategoryid,
|
|
|
81 |
);
|
|
|
82 |
redirect(new moodle_url($returnurl, ['filter' => $returnfilters]));
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
echo $OUTPUT->header();
|
|
|
86 |
|
|
|
87 |
if ($moveselected) {
|
|
|
88 |
$rawquestions = $_REQUEST;
|
|
|
89 |
list($questionids, $questionlist) = \qbank_bulkmove\helper::process_question_ids($rawquestions);
|
|
|
90 |
// No questions were selected.
|
|
|
91 |
if (!$questionids) {
|
|
|
92 |
redirect($returnurl);
|
|
|
93 |
}
|
|
|
94 |
// Create the urls.
|
|
|
95 |
$moveparam = [
|
|
|
96 |
'movequestionsselected' => $questionlist,
|
|
|
97 |
'confirm' => md5($questionlist),
|
|
|
98 |
'sesskey' => sesskey(),
|
|
|
99 |
'returnurl' => $returnurl,
|
|
|
100 |
'cmid' => $cmid,
|
|
|
101 |
'courseid' => $courseid,
|
|
|
102 |
];
|
|
|
103 |
$moveurl = new \moodle_url($url, $moveparam);
|
|
|
104 |
|
|
|
105 |
$addcontexts = $contexts->having_cap('moodle/question:add');
|
|
|
106 |
$displaydata = \qbank_bulkmove\helper::get_displaydata($addcontexts, $moveurl, $returnurl);
|
|
|
107 |
echo $PAGE->get_renderer('qbank_bulkmove')->render_bulk_move_form($displaydata);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
echo $OUTPUT->footer();
|