mirror of
https://github.com/moodle/moodle.git
synced 2025-04-23 09:23:09 +02:00
MDL-71696 qbank_preview: previewquestion plugin update
This commit implements versioning and associated features in the previewquestion plugin. There have been some major changes in the random question and version selection for questions. This commit made those changes as well as added some more features in the preview for version selection and adds more behat coverage.
This commit is contained in:
parent
111951d861
commit
b1ad75aef5
lib
mod/quiz
question
bank/previewquestion
classes/local/bank
type
description/tests/behat
essay/tests/behat
match/tests/behat
multichoice/tests/behat
numerical/tests/behat
truefalse/tests/behat
@ -1117,7 +1117,15 @@ function question_sort_tags($tagobjects, $categorycontext, $filtercourses = null
|
||||
*/
|
||||
function print_question_icon($question): string {
|
||||
global $PAGE;
|
||||
return $PAGE->get_renderer('question', 'bank')->qtype_icon($question->qtype);
|
||||
|
||||
if (gettype($question->qtype) == 'object') {
|
||||
$qtype = $question->qtype->name();
|
||||
} else {
|
||||
// Assume string.
|
||||
$qtype = $question->qtype;
|
||||
}
|
||||
|
||||
return $PAGE->get_renderer('question', 'bank')->qtype_icon($qtype);
|
||||
}
|
||||
|
||||
// CATEGORY FUNCTIONS.
|
||||
|
@ -28,6 +28,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
use mod_quiz\question\bank\qbank_helper;
|
||||
use \mod_quiz\structure;
|
||||
use \html_writer;
|
||||
use \qbank_previewquestion\helper;
|
||||
use renderable;
|
||||
|
||||
/**
|
||||
|
@ -1361,6 +1361,7 @@ function quiz_attempt_state_name($state) {
|
||||
* @param object $question the question.
|
||||
* @param string $returnurl url to return to after action is done.
|
||||
* @param int $variant which question variant to preview (optional).
|
||||
* @param bool $random if question is random, true.
|
||||
* @return string html for a number of icons linked to action pages for a
|
||||
* question - preview and edit / view icons depending on user capabilities.
|
||||
*/
|
||||
@ -1448,9 +1449,10 @@ function quiz_question_preview_url($quiz, $question, $variant = null) {
|
||||
* @param object $question the question
|
||||
* @param bool $label if true, show the preview question label after the icon
|
||||
* @param int $variant which question variant to preview (optional).
|
||||
* @param bool $random if question is random, true.
|
||||
* @return the HTML for a preview question icon.
|
||||
*/
|
||||
function quiz_question_preview_button($quiz, $question, $label = false, $variant = null) {
|
||||
function quiz_question_preview_button($quiz, $question, $label = false, $variant = null, $random = null) {
|
||||
global $PAGE;
|
||||
if (!question_has_capability_on($question, 'use')) {
|
||||
return '';
|
||||
|
@ -202,8 +202,12 @@ class quiz_statistics_table extends flexible_table {
|
||||
if ($this->is_calculated_question_summary($questionstat)) {
|
||||
return '';
|
||||
} else {
|
||||
$random = null;
|
||||
if ($questionstat->question->qtype === 'random') {
|
||||
$random = true;
|
||||
}
|
||||
return quiz_question_action_icons($this->quiz, $this->cmid,
|
||||
$questionstat->question, $this->baseurl, $questionstat->variant);
|
||||
$questionstat->question, $this->baseurl, $questionstat->variant, $random);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ Feature: Basic use of the Statistics report
|
||||
| 1 | False |
|
||||
| 2 | False |
|
||||
| 3 | False |
|
||||
And I press "Go back"
|
||||
And I am on the "Quiz 1" "quiz activity" page logged in as teacher1
|
||||
And I navigate to "Results > Statistics" in current page administration
|
||||
And I press "Show report"
|
||||
Then I should not see "No questions have been attempted yet"
|
||||
|
@ -1,2 +1,2 @@
|
||||
define ("qbank_previewquestion/preview",["exports","jquery"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);a.init=function init(a){if(!a){var b=document.getElementById("close-previewquestion-page");b.onclick=function(){window.close()}}c("responseform")};var c=function(a){var b=document.getElementById(a);if(b){d(b);e(b);f(".questionflagsavebutton",b);g(b)}},d=function(a){a.setAttribute("autocomplete","off")},e=function(a){a.addEventListener("submit",function(){(0,b.default)(this).submit(function(){return!1});return!0})},f=function(a,b){b.querySelectorAll(a).forEach(function(a){return a.remove()})},g=function(a){var b=window.location.href.match(/^.*[?&]scrollpos=(\d*)(?:&|$|#).*$/,"$1");if(b){window.scrollTo(0,b[1]);a.addEventListener("DOMContentLoaded",function(){window.scrollTo(0,b[1])})}}});
|
||||
define ("qbank_previewquestion/preview",["exports","jquery"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);a.init=function init(a,b){if(!a){var d=document.getElementById("close-previewquestion-page");d.onclick=function(){if(null===window.opener){location.href=b}else{window.close()}}}c("responseform")};var c=function(a){var b=document.getElementById(a);if(b){d(b);e(b);f(".questionflagsavebutton",b);g(b)}},d=function(a){a.setAttribute("autocomplete","off")},e=function(a){a.addEventListener("submit",function(){(0,b.default)(this).submit(function(){return!1});return!0})},f=function(a,b){b.querySelectorAll(a).forEach(function(a){return a.remove()})},g=function(a){var b=window.location.href.match(/^.*[?&]scrollpos=(\d*)(?:&|$|#).*$/,"$1");if(b){window.scrollTo(0,b[1]);a.addEventListener("DOMContentLoaded",function(){window.scrollTo(0,b[1])})}}});
|
||||
//# sourceMappingURL=preview.min.js.map
|
||||
|
File diff suppressed because one or more lines are too long
@ -29,12 +29,17 @@ import $ from 'jquery';
|
||||
*
|
||||
* @method init
|
||||
* @param {bool} redirect Redirect.
|
||||
* @param {string} url url to redirect.
|
||||
*/
|
||||
export const init = (redirect) => {
|
||||
export const init = (redirect, url) => {
|
||||
if (!redirect) {
|
||||
let closeButton = document.getElementById('close-previewquestion-page');
|
||||
closeButton.onclick = () => {
|
||||
window.close();
|
||||
if (window.opener === null) {
|
||||
location.href = url;
|
||||
} else {
|
||||
window.close();
|
||||
}
|
||||
};
|
||||
}
|
||||
// Set up the form to be displayed.
|
||||
|
@ -42,8 +42,12 @@ class preview_options_form extends moodleform {
|
||||
question_display_options::VISIBLE => get_string('shown', 'question'),
|
||||
];
|
||||
|
||||
$mform->addElement('header', 'attemptoptionsheader', get_string('attemptoptions', 'question'));
|
||||
|
||||
$mform->addElement('header', 'attemptoptionsheader', get_string('previewoptions', 'qbank_previewquestion'));
|
||||
$mform->setExpanded('attemptoptionsheader', false);
|
||||
$versions = $this->_customdata['versions'];
|
||||
$currentversion = $this->_customdata['questionversion'];
|
||||
$select = $mform->addElement('select', 'version', get_string('questionversion', 'qbank_previewquestion'), $versions);
|
||||
$select->setSelected($currentversion);
|
||||
$behaviours = question_engine::get_behaviour_options(
|
||||
$this->_customdata['quba']->get_preferred_behaviour());
|
||||
$mform->addElement('select', 'behaviour',
|
||||
@ -63,6 +67,7 @@ class preview_options_form extends moodleform {
|
||||
get_string('restartwiththeseoptions', 'question'));
|
||||
|
||||
$mform->addElement('header', 'displayoptionsheader', get_string('displayoptions', 'question'));
|
||||
$mform->setExpanded('displayoptionsheader', false);
|
||||
|
||||
$mform->addElement('select', 'correctness', get_string('whethercorrect', 'question'),
|
||||
$hiddenorvisible);
|
||||
|
@ -16,8 +16,21 @@
|
||||
|
||||
namespace qbank_previewquestion;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/question/editlib.php');
|
||||
|
||||
use action_menu;
|
||||
use comment;
|
||||
use context_module;
|
||||
use context;
|
||||
use core\plugininfo\qbank;
|
||||
use core_question\local\bank\edit_menu_column;
|
||||
use core_question\local\bank\view;
|
||||
use core_question\lib\question_edit_contexts;
|
||||
use moodle_url;
|
||||
use question_bank;
|
||||
use question_definition;
|
||||
use question_display_options;
|
||||
use question_engine;
|
||||
use stdClass;
|
||||
@ -44,7 +57,7 @@ class helper {
|
||||
* @param int $slot the relevant slot within the usage.
|
||||
* @param array $args the remaining bits of the file path.
|
||||
* @param bool $forcedownload whether the user must be forced to download the file.
|
||||
* @param array $fileoptions
|
||||
* @param array $fileoptions options for the stored files
|
||||
* @return void false if file not found, does not return if found - justsend the file
|
||||
*/
|
||||
public static function question_preview_question_pluginfile($course, $context, $component,
|
||||
@ -85,11 +98,11 @@ class helper {
|
||||
/**
|
||||
* The the URL to use for actions relating to this preview.
|
||||
*
|
||||
* @param int $questionid the question being previewed.
|
||||
* @param int $qubaid the id of the question usage for this preview.
|
||||
* @param question_preview_options $options the options in use.
|
||||
* @param context $context
|
||||
* @param moodle_url $returnurl
|
||||
* @param int $questionid the question being previewed
|
||||
* @param int $qubaid the id of the question usage for this preview
|
||||
* @param question_preview_options $options the options in use
|
||||
* @param context $context context for the question preview
|
||||
* @param moodle_url $returnurl url of the page to return to
|
||||
* @return moodle_url
|
||||
*/
|
||||
public static function question_preview_action_url($questionid, $qubaid,
|
||||
@ -112,10 +125,11 @@ class helper {
|
||||
|
||||
/**
|
||||
* The the URL to use for actions relating to this preview.
|
||||
* @param int $questionid the question being previewed.
|
||||
* @param context $context the current moodle context.
|
||||
* @param int $previewid optional previewid to sign post saved previewed answers.
|
||||
* @param moodle_url $returnurl
|
||||
*
|
||||
* @param int $questionid the question being previewed
|
||||
* @param context $context the current moodle context
|
||||
* @param int $previewid optional previewid to sign post saved previewed answers
|
||||
* @param moodle_url $returnurl url of the page to return to
|
||||
* @return moodle_url
|
||||
*/
|
||||
public static function question_preview_form_url($questionid, $context, $previewid = null, $returnurl = null): moodle_url {
|
||||
@ -138,13 +152,16 @@ class helper {
|
||||
|
||||
/**
|
||||
* Delete the current preview, if any, and redirect to start a new preview.
|
||||
* @param int $previewid
|
||||
* @param int $questionid
|
||||
* @param object $displayoptions
|
||||
* @param object $context
|
||||
* @param moodle_url $returnurl
|
||||
*
|
||||
* @param int $previewid id of the preview while restarting it
|
||||
* @param int $questionid id of the question in preview
|
||||
* @param object $displayoptions display options for the question in preview
|
||||
* @param object $context context of the question for preview
|
||||
* @param moodle_url $returnurl url of the page to return to
|
||||
* @param int|null $version version of the question in preview
|
||||
*/
|
||||
public static function restart_preview($previewid, $questionid, $displayoptions, $context, $returnurl = null): void {
|
||||
public static function restart_preview($previewid, $questionid, $displayoptions, $context,
|
||||
$returnurl = null, $version = null): void {
|
||||
global $DB;
|
||||
|
||||
if ($previewid) {
|
||||
@ -153,27 +170,33 @@ class helper {
|
||||
$transaction->allow_commit();
|
||||
}
|
||||
redirect(self::question_preview_url($questionid, $displayoptions->behaviour,
|
||||
$displayoptions->maxmark, $displayoptions, $displayoptions->variant, $context, $returnurl));
|
||||
$displayoptions->maxmark, $displayoptions, $displayoptions->variant, $context, $returnurl, $version));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the URL for starting a new preview of a given question with the given options.
|
||||
* @param integer $questionid the question to preview.
|
||||
* @param string $preferredbehaviour the behaviour to use for the preview.
|
||||
* @param float $maxmark the maximum to mark the question out of.
|
||||
* @param question_display_options $displayoptions the display options to use.
|
||||
*
|
||||
* @param integer $questionid the question to preview
|
||||
* @param string $preferredbehaviour the behaviour to use for the preview
|
||||
* @param float $maxmark the maximum to mark the question out of
|
||||
* @param question_display_options $displayoptions the display options to use
|
||||
* @param int $variant the variant of the question to preview. If null, one will
|
||||
* be picked randomly.
|
||||
* be picked randomly
|
||||
* @param object $context context to run the preview in (affects things like
|
||||
* filter settings, theme, lang, etc.) Defaults to $PAGE->context.
|
||||
* @param moodle_url $returnurl
|
||||
* @return moodle_url the URL.
|
||||
* filter settings, theme, lang, etc.) Defaults to $PAGE->context
|
||||
* @param moodle_url $returnurl url of the page to return to
|
||||
* @param int $version version of the question
|
||||
* @return moodle_url the URL
|
||||
*/
|
||||
public static function question_preview_url($questionid, $preferredbehaviour = null,
|
||||
$maxmark = null, $displayoptions = null, $variant = null, $context = null, $returnurl = null): moodle_url {
|
||||
$maxmark = null, $displayoptions = null, $variant = null, $context = null, $returnurl = null,
|
||||
$version = null): moodle_url {
|
||||
|
||||
$params = ['id' => $questionid];
|
||||
|
||||
if (!is_null($version)) {
|
||||
$params['id'] = $version;
|
||||
}
|
||||
if (is_null($context)) {
|
||||
global $PAGE;
|
||||
$context = $PAGE->context;
|
||||
@ -215,6 +238,7 @@ class helper {
|
||||
|
||||
/**
|
||||
* Popup params for the question preview.
|
||||
*
|
||||
* @return array that can be passed as $params to the {@see popup_action} constructor.
|
||||
*/
|
||||
public static function question_preview_popup_params(): array {
|
||||
@ -227,11 +251,11 @@ class helper {
|
||||
/**
|
||||
* Get the extra elements for preview from qbank plugins.
|
||||
*
|
||||
* @param \question_definition $question
|
||||
* @param int $courseid
|
||||
* @param question_definition $question question definition object
|
||||
* @param int $courseid id of the course
|
||||
* @return array
|
||||
*/
|
||||
public static function get_preview_extra_elements(\question_definition $question, int $courseid): array {
|
||||
public static function get_preview_extra_elements(question_definition $question, int $courseid): array {
|
||||
$plugintype = 'qbank';
|
||||
$functionname = 'preview_display';
|
||||
$extrahtml = [];
|
||||
@ -247,4 +271,46 @@ class helper {
|
||||
}
|
||||
return [$comment, $extrahtml];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if question is the latest version.
|
||||
*
|
||||
* @param string $version Question version to check
|
||||
* @param string $questionbankentryid Entry to check against
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_latest(string $version, string $questionbankentryid) : bool {
|
||||
global $DB;
|
||||
|
||||
$sql = 'SELECT MAX(version) AS max
|
||||
FROM {question_versions}
|
||||
WHERE questionbankentryid = ?';
|
||||
$latestversion = $DB->get_record_sql($sql, [$questionbankentryid]);
|
||||
|
||||
if (isset($latestversion->max)) {
|
||||
return ($version === $latestversion->max) ? true : false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads question version ids for current question.
|
||||
*
|
||||
* @param string $questionbankentryid Question bank entry id
|
||||
* @return array $questionids Array containing question id as key and version as value.
|
||||
*/
|
||||
public static function load_versions(string $questionbankentryid) : array {
|
||||
global $DB;
|
||||
|
||||
$questionids = [];
|
||||
$sql = 'SELECT version, questionid
|
||||
FROM {question_versions}
|
||||
WHERE questionbankentryid = ?';
|
||||
|
||||
$versions = $DB->get_records_sql($sql, [$questionbankentryid]);
|
||||
foreach ($versions as $key => $version) {
|
||||
$questionids[$version->questionid] = $key;
|
||||
}
|
||||
return $questionids;
|
||||
}
|
||||
}
|
||||
|
@ -25,3 +25,14 @@
|
||||
|
||||
$string['pluginname'] = 'Preview question';
|
||||
$string['privacy:metadata'] = 'The Preview question question bank plugin does not store any personal data.';
|
||||
// Tag related errors.
|
||||
$string['tagclosebutton'] = 'Close';
|
||||
$string['tagerror'] = 'No question was found with following tags: {$a}. Please change or remove tags filtering.';
|
||||
$string['tagsnotfound'] = 'Tags not found';
|
||||
// Form string(s).
|
||||
$string['previewoptions'] = 'Preview options';
|
||||
$string['questionversion'] = 'Question version';
|
||||
// Preview title.
|
||||
$string['versiontitle'] = 'Version {$a}';
|
||||
$string['versiontitlelatest'] = 'Version {$a} (latest)';
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
require_once(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/questionlib.php');
|
||||
|
||||
use \core\notification;
|
||||
use qbank_previewquestion\form\preview_options_form;
|
||||
use qbank_previewquestion\question_preview_options;
|
||||
use qbank_previewquestion\helper;
|
||||
@ -48,6 +49,7 @@ define('QUESTION_PREVIEW_MAX_VARIANTS', 100);
|
||||
// Get and validate question id.
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$returnurl = optional_param('returnurl', null, PARAM_RAW);
|
||||
|
||||
$question = question_bank::load_question($id);
|
||||
|
||||
if ($returnurl) {
|
||||
@ -132,8 +134,10 @@ $options->behaviour = $quba->get_preferred_behaviour();
|
||||
$options->maxmark = $quba->get_question_max_mark($slot);
|
||||
|
||||
// Create the settings form, and initialise the fields.
|
||||
$optionsform = new preview_options_form(helper::question_preview_form_url($question->id, $context, $previewid, $returnurl),
|
||||
['quba' => $quba, 'maxvariant' => $maxvariant]);
|
||||
$versionids = helper::load_versions($question->questionbankentryid);
|
||||
$optionsform = new preview_options_form(helper::
|
||||
question_preview_form_url($question->id, $context, $previewid, $returnurl),
|
||||
['quba' => $quba, 'maxvariant' => $maxvariant, 'versions' => $versionids, 'questionversion' => $id]);
|
||||
$optionsform->set_data($options);
|
||||
|
||||
// Process change of settings, if that was requested.
|
||||
@ -144,7 +148,7 @@ if ($newoptions = $optionsform->get_submitted_data()) {
|
||||
$newoptions->variant = $options->variant;
|
||||
}
|
||||
if (isset($newoptions->saverestart)) {
|
||||
helper::restart_preview($previewid, $question->id, $newoptions, $context, $returnurl);
|
||||
helper::restart_preview($previewid, $question->id, $newoptions, $context, $returnurl, $newoptions->version);
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,6 +253,17 @@ $PAGE->set_heading($title);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
$previewdata = [];
|
||||
|
||||
$previewdata['questionicon'] = print_question_icon($question);
|
||||
$previewdata['questionidumber'] = $question->idnumber;
|
||||
$previewdata['questiontitle'] = $question->name;
|
||||
$islatestversion = is_latest($question->version, $question->questionbankentryid);
|
||||
if ($islatestversion) {
|
||||
$previewdata['versiontitle'] = get_string('versiontitlelatest', 'qbank_previewquestion', $question->version);
|
||||
} else {
|
||||
$previewdata['versiontitle'] = get_string('versiontitle', 'qbank_previewquestion', $question->version);
|
||||
}
|
||||
|
||||
$previewdata['actionurl'] = $actionurl;
|
||||
$previewdata['session'] = sesskey();
|
||||
$previewdata['slot'] = $slot;
|
||||
@ -265,21 +280,6 @@ foreach ($technical as $info) {
|
||||
}
|
||||
$previewdata['techinfo'] .= print_collapsible_region_end(true);
|
||||
|
||||
// Output a link to export this single question.
|
||||
if (question_has_capability_on($question, 'view')) {
|
||||
if (class_exists('qbank_exporttoxml\\helper')) {
|
||||
if (\core\plugininfo\qbank::is_plugin_enabled('qbank_exporttoxml')) {
|
||||
$exportfunction = '\\qbank_exporttoxml\\helper::question_get_export_single_question_url';
|
||||
$previewdata['exporttoxml'] = html_writer::link($exportfunction($question),
|
||||
get_string('exportonequestion', 'question'));
|
||||
}
|
||||
} else {
|
||||
$exportfunction = 'question_get_export_single_question_url';
|
||||
$previewdata['exporttoxml'] = html_writer::link($exportfunction($question),
|
||||
get_string('exportonequestion', 'question'));
|
||||
}
|
||||
}
|
||||
|
||||
// Display the settings form.
|
||||
$previewdata['options'] = $optionsform->render();
|
||||
|
||||
@ -304,16 +304,12 @@ if (!is_null($returnurl)) {
|
||||
$previewdata['redirect'] = true;
|
||||
$previewdata['redirecturl'] = $returnurl;
|
||||
}
|
||||
|
||||
$closeurl = new moodle_url('/question/edit.php', ['courseid' => $COURSE->id]);
|
||||
echo $PAGE->get_renderer('qbank_previewquestion')->render_preview_page($previewdata);
|
||||
|
||||
// Log the preview of this question.
|
||||
$event = \core\event\question_viewed::create_from_question_instance($question, $context);
|
||||
$event->trigger();
|
||||
|
||||
$PAGE->requires->js_call_amd('qbank_previewquestion/preview', 'init', [$previewdata['redirect']]);
|
||||
$PAGE->requires->js_call_amd('core_form/changechecker', 'watchFormById', ['responseform']);
|
||||
$PAGE->requires->js_call_amd('core_form/submit', 'init', ['id_save_question_preview']);
|
||||
$PAGE->requires->js_call_amd('core_form/submit', 'init', ['id_finish_question_preview']);
|
||||
$PAGE->requires->js_call_amd('core_form/submit', 'init', ['id_restart_question_preview']);
|
||||
$PAGE->requires->js_call_amd('qbank_previewquestion/preview', 'init', [$previewdata['redirect'], $closeurl->__toString()]);
|
||||
echo $OUTPUT->footer();
|
||||
|
@ -22,6 +22,10 @@
|
||||
* session - Moodle session
|
||||
* slot - The identifying number of the first question that was added to this usage
|
||||
* question - The html of the actual question from the engine
|
||||
* questionicon - The icon of the question type
|
||||
* questiontitle - The name of the question
|
||||
* versiontitle - The string for displaying the version
|
||||
* questionidumber - The idnumber of the question
|
||||
* restartdisabled - The attributes to enable or disable the button, same for finishdisabled and filldisabled
|
||||
* techinfo - Technical information like fraction, state, behaviour etc
|
||||
* exporttoxml - Link to export the question to xml
|
||||
@ -31,25 +35,39 @@
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"previewdata": [
|
||||
{
|
||||
"actionurl": "/",
|
||||
"session": "E2PwCfrnzz",
|
||||
"slot": "1",
|
||||
"question": "<div>question html</div>",
|
||||
"restartdisabled": "disabled='disabled'",
|
||||
"finishdisabled": "disabled='disabled'",
|
||||
"filldisabled": "disabled='disabled'",
|
||||
"techinfo": "<div>Behaviour being used: Deferred feedback</div>",
|
||||
"redirecturl": "/",
|
||||
"exporttoxml": "Download this question in Moodle XML format",
|
||||
"comments": "html from comments api",
|
||||
"extrapreviewelements": "<div>callback to get html from plugins need to show info in preview</div>"
|
||||
}
|
||||
]
|
||||
"actionurl": "/",
|
||||
"session": "E2PwCfrnzz",
|
||||
"slot": "1",
|
||||
"question": "<div>question html</div>",
|
||||
"questionicon": "<i class='icon fa fa-search-plus fa-fw' title='Preview question' aria-label='Preview question'></i>",
|
||||
"questiontitle": "Question title",
|
||||
"versiontitle": "Version 3 (latest)",
|
||||
"questionidumber": "qidnumber1",
|
||||
"restartdisabled": "disabled='disabled'",
|
||||
"finishdisabled": "disabled='disabled'",
|
||||
"filldisabled": "disabled='disabled'",
|
||||
"techinfo": "<div>Behaviour being used: Deferred feedback</div>",
|
||||
"redirecturl": "/",
|
||||
"exporttoxml": "Download this question in Moodle XML format",
|
||||
"comments": "html from comments api",
|
||||
"extrapreviewelements": "<div>callback to get html from plugins need to show info in preview</div>"
|
||||
}
|
||||
}}
|
||||
<form id="responseform" method="post" action="{{{actionurl}}}" enctype="multipart/form-data" autocomplete="off">
|
||||
<div class="d-flex">
|
||||
<h2 class="mt-2">{{{questionicon}}}</h2>
|
||||
<h2 class="ml-2 mt-2"> {{questiontitle}}</h2>
|
||||
<h3 class="px-2 py-1 ml-2 mt-2">
|
||||
<span class="badge bg-primary text-light">{{versiontitle}}</span>
|
||||
</h3>
|
||||
</div>
|
||||
<div class="d-flex">
|
||||
<div class="badge-primary h-50 px-2 mt-n2">
|
||||
<span class="accesshide">ID number</span>
|
||||
{{questionidumber}}
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<div>
|
||||
<input type="hidden" name="sesskey" value="{{session}}">
|
||||
<input type="hidden" name="slots" value="{{slot}}">
|
||||
@ -69,21 +87,21 @@
|
||||
{{/redirect}}
|
||||
</div>
|
||||
</form>
|
||||
{{{techinfo}}}
|
||||
{{{exporttoxml}}}
|
||||
<br>
|
||||
{{#comments}}
|
||||
<div class="row">
|
||||
<div class="col-6 text-left">
|
||||
{{{options}}}
|
||||
</div>
|
||||
<div class="col-6 question-comment-view">
|
||||
{{{comments}}}
|
||||
</div>
|
||||
<a data-toggle="collapse" href="#commentcollapse" role="button" aria-expanded="false" aria-controls="commentcollapse">
|
||||
{{#pix}} t/collapsed, core {{/pix}}
|
||||
{{#str}} commentplural, qbank_comment{{/str}}
|
||||
</a>
|
||||
<div class="collapse" id="commentcollapse">
|
||||
{{{comments}}}
|
||||
</div>
|
||||
{{{options}}}
|
||||
{{/comments}}
|
||||
{{^comments}}
|
||||
{{{options}}}
|
||||
{{/comments}}
|
||||
{{{techinfo}}}
|
||||
{{#extrapreviewelements}}
|
||||
{{{extrapreviewelements}}}
|
||||
{{/extrapreviewelements}}
|
||||
|
@ -43,13 +43,6 @@ Feature: A teacher can preview questions in the question bank
|
||||
And I should see "Version"
|
||||
And I click on "Preview options" "link"
|
||||
And I should see "Question version"
|
||||
And "action-menu-toggle-0" "link" should exist
|
||||
And I click on "action-menu-toggle-0" "link"
|
||||
And I should see "Edit question"
|
||||
And I should see "Duplicate"
|
||||
And I should see "Manage tags"
|
||||
And I should see "Delete"
|
||||
And I should see "Export as Moodle XML"
|
||||
|
||||
Scenario: Preview lets the teacher see what happens when an answer is saved
|
||||
When I set the field "Answer:" to "1"
|
||||
@ -94,33 +87,20 @@ Feature: A teacher can preview questions in the question bank
|
||||
When I press "Fill in correct responses"
|
||||
Then the field "Answer:" matches value "3.14"
|
||||
|
||||
Scenario: Preview has an option to export the individual quesiton.
|
||||
When I open the action menu in "action-menu-0-menubar" "region"
|
||||
Then following "Export as Moodle XML" should download between "1000" and "2500" bytes
|
||||
|
||||
Scenario: Preview a question with very small grade
|
||||
When I press "Preview options"
|
||||
And I set the field "Marked out of" to "0.00000123456789"
|
||||
And I press "Start again with these options"
|
||||
Then the field "Marked out of" matches value "0.00000123456789"
|
||||
|
||||
Scenario: Question preview has an action menu
|
||||
When I open the action menu in "action-menu-0-menubar" "region"
|
||||
Then I should see "Edit question"
|
||||
And I should see "Duplicate"
|
||||
And I should see "Manage tags"
|
||||
And I should see "Delete"
|
||||
And I should see "Export as Moodle XML"
|
||||
|
||||
Scenario: Question version is updated when edited and teacher can change question version
|
||||
When I open the action menu in "action-menu-0-menubar" "region"
|
||||
And I choose "Edit question" in the open action menu
|
||||
And I should see "Version 1"
|
||||
And I press "Close preview"
|
||||
And I choose "Edit question" action for "Test question to be previewed" in the question bank
|
||||
And I set the field "Question name" to "New version"
|
||||
And I set the field "Question text" to "New text version"
|
||||
And I click on "submitbutton" "button"
|
||||
And I press "Preview options"
|
||||
And I set the field "Question version" to "2"
|
||||
And I press "Start again with these options"
|
||||
And I choose "Preview" action for "New version" in the question bank
|
||||
Then I should see "Version 2"
|
||||
And I should see "(latest)"
|
||||
And I should see "New version"
|
||||
@ -129,9 +109,6 @@ Feature: A teacher can preview questions in the question bank
|
||||
And I should not see "Version 1"
|
||||
|
||||
Scenario: Question preview can be closed
|
||||
When I open the action menu in "action-menu-0-menubar" "region"
|
||||
And I choose "Edit question" in the open action menu
|
||||
And I click on "cancel" "button"
|
||||
And I press "Close preview"
|
||||
Then I should not see "(latest)"
|
||||
And I should see "Course 1"
|
||||
|
@ -16,7 +16,13 @@
|
||||
|
||||
namespace qbank_previewquestion;
|
||||
|
||||
use context_course;
|
||||
use moodle_url;
|
||||
use core\plugininfo\qbank;
|
||||
use \core_question\lib\question_edit_contexts;
|
||||
use question_bank;
|
||||
use question_engine;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Helper tests for question preview.
|
||||
@ -67,17 +73,17 @@ class helper_test extends \advanced_testcase {
|
||||
$questiongenerator = $generator->get_plugin_generator('core_question');
|
||||
// Create a course.
|
||||
$course = $generator->create_course();
|
||||
$this->context = \context_course::instance($course->id);
|
||||
$this->context = context_course::instance($course->id);
|
||||
// Create a question in the default category.
|
||||
$contexts = new \core_question\lib\question_edit_contexts($this->context);
|
||||
$cat = question_make_default_categories($contexts->all());
|
||||
$this->questiondata = $questiongenerator->create_question('numerical', null,
|
||||
['name' => 'Example question', 'category' => $cat->id]);
|
||||
$this->quba = \question_engine::make_questions_usage_by_activity('core_question_preview', \context_user::instance($USER->id));
|
||||
$this->quba = question_engine::make_questions_usage_by_activity('core_question_preview', \context_user::instance($USER->id));
|
||||
$this->options = new question_preview_options($this->questiondata);
|
||||
$this->options->load_user_defaults();
|
||||
$this->options->set_from_request();
|
||||
$this->returnurl = new \moodle_url('/question/edit.php');
|
||||
$this->returnurl = new moodle_url('/question/edit.php');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,7 +101,7 @@ class helper_test extends \advanced_testcase {
|
||||
'courseid' => $this->context->instanceid
|
||||
];
|
||||
$params = array_merge($params, $this->options->get_url_params());
|
||||
$expectedurl = new \moodle_url('/question/bank/previewquestion/preview.php', $params);
|
||||
$expectedurl = new moodle_url('/question/bank/previewquestion/preview.php', $params);
|
||||
$this->assertEquals($expectedurl, $actionurl);
|
||||
}
|
||||
|
||||
@ -112,7 +118,7 @@ class helper_test extends \advanced_testcase {
|
||||
'returnurl' => $this->returnurl,
|
||||
'courseid' => $this->context->instanceid
|
||||
];
|
||||
$expectedurl = new \moodle_url('/question/bank/previewquestion/preview.php', $params);
|
||||
$expectedurl = new moodle_url('/question/bank/previewquestion/preview.php', $params);
|
||||
$this->assertEquals($expectedurl, $formurl);
|
||||
}
|
||||
|
||||
@ -138,7 +144,7 @@ class helper_test extends \advanced_testcase {
|
||||
$params['generalfeedback'] = (bool) $this->options->generalfeedback;
|
||||
$params['rightanswer'] = (bool) $this->options->rightanswer;
|
||||
$params['history'] = (bool) $this->options->history;
|
||||
$expectedurl = new \moodle_url('/question/bank/previewquestion/preview.php', $params);
|
||||
$expectedurl = new moodle_url('/question/bank/previewquestion/preview.php', $params);
|
||||
$this->assertEquals($expectedurl, $previewurl);
|
||||
}
|
||||
|
||||
@ -159,4 +165,27 @@ class helper_test extends \advanced_testcase {
|
||||
$this->assertEquals('', $comment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method load_versions().
|
||||
*
|
||||
* @covers ::load_versions
|
||||
*/
|
||||
public function test_load_versions() {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
||||
$qcat1 = $generator->create_question_category(['name' => 'My category', 'sortorder' => 1, 'idnumber' => 'myqcat']);
|
||||
$questiongenerated = $generator->create_question('description', null, ['name' => 'q1', 'category' => $qcat1->id]);
|
||||
$qtypeobj = question_bank::get_qtype($questiongenerated->qtype);
|
||||
$question = question_bank::load_question($questiongenerated->id);
|
||||
$versionids = helper::load_versions($question->questionbankentryid);
|
||||
$this->assertCount(1, $versionids);
|
||||
$fromform = new stdClass();
|
||||
$fromform->name = 'Name edited';
|
||||
$fromform->category = $qcat1->id;
|
||||
$qtypeobj->save_question($questiongenerated, $fromform);
|
||||
$versionids = helper::load_versions($question->questionbankentryid);
|
||||
$this->assertCount(2, $versionids);
|
||||
}
|
||||
}
|
@ -98,4 +98,12 @@ class edit_menu_column extends column_base {
|
||||
return ['q.qtype'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get menuable actions.
|
||||
*
|
||||
* @return menuable_action Menuable actions.
|
||||
*/
|
||||
public function get_actions(): array {
|
||||
return $this->actions;
|
||||
}
|
||||
}
|
||||
|
@ -1225,4 +1225,20 @@ class view {
|
||||
$this->searchconditions[] = $searchcondition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets visible columns.
|
||||
* @return array $this->visiblecolumns Visible columns.
|
||||
*/
|
||||
public function get_visiblecolumns(): array {
|
||||
return $this->visiblecolumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get required columns.
|
||||
*
|
||||
* @return array Required columns.
|
||||
*/
|
||||
public function get_requiredcolumns(): array {
|
||||
return $this->requiredcolumns;
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ Feature: Preview a Description question
|
||||
@javascript @_switch_window
|
||||
Scenario: Preview a Description question and submit a correct response.
|
||||
When I choose "Preview" action for "description-001" in the question bank
|
||||
And I press "Preview options"
|
||||
And I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I should see "Here is some information about the questions you are about to attempt."
|
||||
|
@ -29,6 +29,7 @@ Feature: Preview Essay questions
|
||||
@javascript @_switch_window
|
||||
Scenario: Preview an Essay question that uses the HTML editor.
|
||||
When I choose "Preview" action for "essay-001" in the question bank
|
||||
And I press "Preview options"
|
||||
And I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I should see "Please write a story about a frog."
|
||||
@ -37,6 +38,7 @@ Feature: Preview Essay questions
|
||||
@javascript @_switch_window
|
||||
Scenario: Preview an Essay question that uses the HTML editor with embedded files.
|
||||
When I choose "Preview" action for "essay-002" in the question bank
|
||||
And I press "Preview options"
|
||||
And I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I should see "Please write a story about a frog."
|
||||
@ -46,6 +48,7 @@ Feature: Preview Essay questions
|
||||
@javascript @_switch_window
|
||||
Scenario: Preview an Essay question that uses a plain text area.
|
||||
When I choose "Preview" action for "essay-003" in the question bank
|
||||
And I press "Preview options"
|
||||
And I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I should see "Please write a story about a frog."
|
||||
|
@ -31,6 +31,7 @@ Feature: Preview a Matching question
|
||||
| Shuffle | 0 |
|
||||
And I press "id_submitbutton"
|
||||
When I choose "Preview" action for "matching-001" in the question bank
|
||||
And I press "Preview options"
|
||||
And I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I set the field with xpath "//table[@class='answer']//td[@class='control']//select[contains(@id, '1_sub0')]" to "amphibian"
|
||||
@ -48,6 +49,7 @@ Feature: Preview a Matching question
|
||||
| Shuffle | 0 |
|
||||
And I press "id_submitbutton"
|
||||
When I choose "Preview" action for "matching-001" in the question bank
|
||||
And I press "Preview options"
|
||||
And I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I set the field with xpath "//table[@class='answer']//td[@class='control']//select[contains(@id, '1_sub0')]" to "amphibian"
|
||||
@ -65,6 +67,7 @@ Feature: Preview a Matching question
|
||||
| Shuffle | 0 |
|
||||
And I press "id_submitbutton"
|
||||
When I choose "Preview" action for "matching-001" in the question bank
|
||||
And I press "Preview options"
|
||||
And I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I set the field with xpath "//table[@class='answer']//td[@class='control']//select[contains(@id, '1_sub0')]" to "mammal"
|
||||
|
@ -28,6 +28,7 @@ Feature: Preview a Multiple choice question
|
||||
@javascript @_switch_window
|
||||
Scenario: Preview a Multiple choice question and submit a partially correct response.
|
||||
When I choose "Preview" action for "Multi-choice-001" in the question bank
|
||||
And I press "Preview options"
|
||||
And I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I click on "One" "qtype_multichoice > Answer"
|
||||
@ -42,6 +43,7 @@ Feature: Preview a Multiple choice question
|
||||
@javascript @_switch_window
|
||||
Scenario: Preview a Multiple choice question and submit a correct response.
|
||||
When I choose "Preview" action for "Multi-choice-001" in the question bank
|
||||
And I press "Preview options"
|
||||
And I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I click on "One" "qtype_multichoice > Answer"
|
||||
@ -58,6 +60,7 @@ Feature: Preview a Multiple choice question
|
||||
@javascript @_switch_window
|
||||
Scenario: Preview a Multiple choice question and submit a correct response.
|
||||
When I choose "Preview" action for "Multi-choice-002" in the question bank
|
||||
And I press "Preview options"
|
||||
And I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I click on "One" "qtype_multichoice > Answer"
|
||||
@ -71,6 +74,7 @@ Feature: Preview a Multiple choice question
|
||||
@javascript @_switch_window
|
||||
Scenario: Preview a multiple choice question (single response) and clear a previous selected option.
|
||||
When I choose "Preview" action for "Multi-choice-002" in the question bank
|
||||
And I press "Preview options"
|
||||
And I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I click on "One" "qtype_multichoice > Answer"
|
||||
|
@ -32,6 +32,7 @@ Feature: Preview a Numerical question
|
||||
Scenario: Preview a Numerical question and submit a correct response.
|
||||
When I choose "Preview" action for "Numerical-001" in the question bank
|
||||
Then I should see "What is pi to two d.p.?"
|
||||
And I press "Preview options"
|
||||
When I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I set the field with xpath "//span[@class='answer']//input[contains(@id, '1_answer')]" to "3.14"
|
||||
|
@ -27,6 +27,7 @@ Feature: Preview a Trtue/False question
|
||||
@javascript @_switch_window
|
||||
Scenario: Preview a True/False question and submit a correct response.
|
||||
When I choose "Preview" action for "true-false-001" in the question bank
|
||||
And I press "Preview options"
|
||||
And I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I click on "True" "radio"
|
||||
@ -38,6 +39,7 @@ Feature: Preview a Trtue/False question
|
||||
@javascript @_switch_window
|
||||
Scenario: Preview a True/False question and submit an incorrect response.
|
||||
When I choose "Preview" action for "true-false-001" in the question bank
|
||||
And I press "Preview options"
|
||||
And I set the field "How questions behave" to "Immediate feedback"
|
||||
And I press "Start again with these options"
|
||||
And I click on "False" "radio"
|
||||
|
Loading…
x
Reference in New Issue
Block a user