mirror of
https://github.com/moodle/moodle.git
synced 2025-04-17 06:25:33 +02:00
MDL-75301 quiz: Use "always latest" option for question previews
This will set the "alwayslatest" option when previewing a question from the quiz according to the version setting used in the quiz slot.
This commit is contained in:
parent
23630ece3d
commit
96bada8495
@ -28,6 +28,7 @@ use core_question\local\bank\question_version_status;
|
||||
use mod_quiz\question\bank\qbank_helper;
|
||||
use \mod_quiz\structure;
|
||||
use \html_writer;
|
||||
use qbank_previewquestion\question_preview_options;
|
||||
use renderable;
|
||||
|
||||
/**
|
||||
@ -837,11 +838,12 @@ class edit_renderer extends \plugin_renderer_base {
|
||||
public function get_action_icon(structure $structure, int $slot, \moodle_url $pageurl) : string {
|
||||
// Action icons.
|
||||
$qtype = $structure->get_question_type_for_slot($slot);
|
||||
$slotinfo = $structure->get_slot_by_number($slot);
|
||||
$questionicons = '';
|
||||
if ($qtype !== 'random') {
|
||||
$questionicons .= $this->question_preview_icon($structure->get_quiz(),
|
||||
$structure->get_question_in_slot($slot),
|
||||
null, null, $qtype);
|
||||
null, null, $slotinfo->requestedversion ?: question_preview_options::ALWAYS_LATEST);
|
||||
}
|
||||
if ($structure->can_be_edited() && $structure->has_use_capability($slot)) {
|
||||
$questionicons .= $this->question_remove_icon($structure, $slot, $pageurl);
|
||||
@ -885,16 +887,17 @@ class edit_renderer extends \plugin_renderer_base {
|
||||
* If ->questionid is set, that is used instead of ->id.
|
||||
* @param bool $label if true, show the preview question label after the icon
|
||||
* @param int $variant which question variant to preview (optional).
|
||||
* @param int $restartversion version to use when restarting the preview
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function question_preview_icon($quiz, $questiondata, $label = null, $variant = null) {
|
||||
public function question_preview_icon($quiz, $questiondata, $label = null, $variant = null, $restartversion = null) {
|
||||
$question = clone($questiondata);
|
||||
if (isset($question->questionid)) {
|
||||
|
||||
$question->id = $question->questionid;
|
||||
}
|
||||
|
||||
$url = quiz_question_preview_url($quiz, $question, $variant);
|
||||
$url = quiz_question_preview_url($quiz, $question, $variant, $restartversion);
|
||||
|
||||
// Do we want a label?
|
||||
$strpreviewlabel = '';
|
||||
|
@ -1049,9 +1049,10 @@ function quiz_question_edit_button($cmid, $question, $returnurl, $contentafteric
|
||||
* @param stdClass $quiz the quiz settings
|
||||
* @param stdClass $question the question
|
||||
* @param int $variant which question variant to preview (optional).
|
||||
* @param int $restartversion version of the question to use when restarting the preview.
|
||||
* @return moodle_url to preview this question with the options from this quiz.
|
||||
*/
|
||||
function quiz_question_preview_url($quiz, $question, $variant = null) {
|
||||
function quiz_question_preview_url($quiz, $question, $variant = null, $restartversion = null) {
|
||||
// Get the appropriate display options.
|
||||
$displayoptions = display_options::make_from_quiz($quiz,
|
||||
display_options::DURING);
|
||||
@ -1063,7 +1064,7 @@ function quiz_question_preview_url($quiz, $question, $variant = null) {
|
||||
|
||||
// Work out the correcte preview URL.
|
||||
return \qbank_previewquestion\helper::question_preview_url($question->id, $quiz->preferredbehaviour,
|
||||
$maxmark, $displayoptions, $variant);
|
||||
$maxmark, $displayoptions, $variant, null, null, $restartversion);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1079,7 +1080,10 @@ function quiz_question_preview_button($quiz, $question, $label = false, $variant
|
||||
if (!question_has_capability_on($question, 'use')) {
|
||||
return '';
|
||||
}
|
||||
return $PAGE->get_renderer('mod_quiz', 'edit')->question_preview_icon($quiz, $question, $label, $variant, null);
|
||||
$slotinfo = quiz_settings::create($quiz->id)->get_structure()->get_slot_by_number($question->slot);
|
||||
return $PAGE->get_renderer('mod_quiz', 'edit')
|
||||
->question_preview_icon($quiz, $question, $label, $variant,
|
||||
$slotinfo->requestedversion ?: \qbank_previewquestion\question_preview_options::ALWAYS_LATEST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,3 +121,19 @@ Feature: Quiz question versioning
|
||||
And I set the field "question_status_dropdown" in the "First question" "table_row" to "Draft"
|
||||
When I am on the "Quiz 1" "mod_quiz > Edit" page
|
||||
Then I should see "This question has all versions in Draft status. The quiz will not work with this question in place."
|
||||
|
||||
@javascript
|
||||
Scenario: Previewing a question set to use always latest version will set the preview to always latest version
|
||||
When I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher"
|
||||
And the field "version" in the "First question" "list_item" matches value "Always latest"
|
||||
When I follow "Preview question"
|
||||
And I expand all fieldsets
|
||||
Then the field "Question version" matches value "Always latest"
|
||||
|
||||
@javascript
|
||||
Scenario: Previewing a question set to use a specific version will set the preview to that version
|
||||
When I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher"
|
||||
And I set the field "version" to "v1 (latest)"
|
||||
When I follow "Preview question"
|
||||
And I expand all fieldsets
|
||||
Then the field "Question version" matches value "1"
|
||||
|
Loading…
x
Reference in New Issue
Block a user