|
| 1 | +<?php |
| 2 | +// This file is part of Stack - http://stack.maths.ed.ac.uk/ |
| 3 | +// |
| 4 | +// Stack 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 | +// Stack 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 STACK. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +/** |
| 18 | + * This script lets the user bulk test quizzes for a particular question. |
| 19 | + * |
| 20 | + * @package qtype_stack |
| 21 | + * @copyright 2020 the University of Edinburgh |
| 22 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 23 | + */ |
| 24 | + |
| 25 | +require_once(__DIR__ . '/../../../config.php'); |
| 26 | +require_once($CFG->libdir . '/questionlib.php'); |
| 27 | +require_once(__DIR__ . '/locallib.php'); |
| 28 | +require_once(__DIR__ . '/stack/utils.class.php'); |
| 29 | +require_once(__DIR__ . '/stack/bulktester.class.php'); |
| 30 | +require_once(__DIR__ . '/stack/questionreport.class.php'); |
| 31 | +require_login(); |
| 32 | + |
| 33 | +// Get the parameters from the URL. |
| 34 | +$questionid = required_param('questionid', PARAM_INT); |
| 35 | +[$qversion, $questionid] = get_latest_question_version($questionid); |
| 36 | +$quizcontext = optional_param('context', null, PARAM_INT); |
| 37 | +// Load the necessary data. |
| 38 | +$questiondata = question_bank::load_question_data($questionid); |
| 39 | +if (!$questiondata) { |
| 40 | + throw new stack_exception('questiondoesnotexist'); |
| 41 | +} |
| 42 | +$question = question_bank::load_question($questionid); |
| 43 | + |
| 44 | +// Process any other URL parameters, and do require_login. |
| 45 | +[$context, $seed, $urlparams] = qtype_stack_setup_question_test_page($question); |
| 46 | + |
| 47 | +// Check permissions. |
| 48 | +question_require_capability_on($questiondata, 'view'); |
| 49 | +$canedit = question_has_capability_on($questiondata, 'edit'); |
| 50 | + |
| 51 | +// Initialise $PAGE. |
| 52 | +$PAGE->set_context($context); |
| 53 | +$PAGE->set_url('/question/type/stack/questionbulktest.php', $urlparams); |
| 54 | +$title = stack_string('bulktestquiz'); |
| 55 | +$PAGE->set_title($title); |
| 56 | +$PAGE->set_heading($title); |
| 57 | + |
| 58 | +// This layout has minimal header/footer. |
| 59 | +$PAGE->set_pagelayout('popup'); |
| 60 | + |
| 61 | +$testquestionlink = new moodle_url('/question/type/stack/questiontestrun.php', $urlparams); |
| 62 | +$qurl = qbank_previewquestion\helper::question_preview_url($questionid, null, null, null, null, $context); |
| 63 | +$editparams = $urlparams; |
| 64 | +unset($editparams['questionid']); |
| 65 | +unset($editparams['seed']); |
| 66 | +$editparams['id'] = $question->id; |
| 67 | +$questioneditlatesturl = new moodle_url('/question/type/stack/questioneditlatest.php', $editparams); |
| 68 | + |
| 69 | +// Start output. |
| 70 | +echo $OUTPUT->header(); |
| 71 | + |
| 72 | +// Get quizzes in which the question is used. |
| 73 | +// Add data for creating quiz selection dropdown. |
| 74 | +$quizzes = stack_question_report::get_relevant_quizzes($questionid, (int) $question->contextid); |
| 75 | +$quizoutput = []; |
| 76 | +foreach ($quizzes as $contextid => $quiz) { |
| 77 | + $quiz->url = new moodle_url('/question/type/stack/adminui/bulktestquiz.php', ['contextid' => $contextid]); |
| 78 | + $quiz->url = $quiz->url->out(); |
| 79 | + $quiz->active = ($contextid === $quizcontext) ? true : false; |
| 80 | + $quizoutput[] = $quiz; |
| 81 | +} |
| 82 | + |
| 83 | +$outputdata = new StdClass(); |
| 84 | +$outputdata->question = new StdClass(); |
| 85 | +$outputdata->question->version = $qversion; |
| 86 | +$outputdata->question->name = $question->name; |
| 87 | + |
| 88 | +// Add additional page creation data. |
| 89 | +$outputdata->quizzes = $quizoutput; |
| 90 | +$outputdata->general = new Stdclass(); |
| 91 | +$outputdata->general->testquestionlink = $testquestionlink->out(); |
| 92 | +$outputdata->general->previewquestionlink = $qurl->out(); |
| 93 | +$outputdata->general->editquestionlink = $questioneditlatesturl->out(); |
| 94 | + |
| 95 | +// Render report. |
| 96 | +echo $OUTPUT->render_from_template('qtype_stack/questionbulktest', $outputdata); |
| 97 | +echo $OUTPUT->footer(); |
0 commit comments