mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 10:26:40 +02:00
MDL-53065 quiz redo question: avoid PHP notice in edge case
When selecting the variant of the new question, we need to add the new question to the usage before trying to select a variant. Also, we need to acutally use the selected variant number!
This commit is contained in:
parent
9d5d9c64ff
commit
293f5d1b11
2 changed files with 16 additions and 2 deletions
|
@ -1789,6 +1789,7 @@ class quiz_attempt {
|
|||
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
// Choose the replacement question.
|
||||
$questiondata = $DB->get_record('question',
|
||||
array('id' => $this->slots[$slot]->questionid));
|
||||
if ($questiondata->qtype != 'random') {
|
||||
|
@ -1803,7 +1804,11 @@ class quiz_attempt {
|
|||
}
|
||||
}
|
||||
|
||||
// Add the question to the usage. It is important we do this before we choose a variant.
|
||||
$newquestion = question_bank::load_question($newqusetionid);
|
||||
$newslot = $this->quba->add_question_in_place_of_other($slot, $newquestion);
|
||||
|
||||
// Choose the variant.
|
||||
if ($newquestion->get_num_variants() == 1) {
|
||||
$variant = 1;
|
||||
} else {
|
||||
|
@ -1813,8 +1818,8 @@ class quiz_attempt {
|
|||
$newquestion->get_variants_selection_seed());
|
||||
}
|
||||
|
||||
$newslot = $this->quba->add_question_in_place_of_other($slot, $newquestion);
|
||||
$this->quba->start_question($slot);
|
||||
// Start the question.
|
||||
$this->quba->start_question($slot, $variant);
|
||||
$this->quba->set_max_mark($newslot, 0);
|
||||
$this->quba->set_question_attempt_metadata($newslot, 'originalslot', $slot);
|
||||
question_engine::save_questions_usage_by_activity($this->quba);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue