mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +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();
|
$transaction = $DB->start_delegated_transaction();
|
||||||
|
|
||||||
|
// Choose the replacement question.
|
||||||
$questiondata = $DB->get_record('question',
|
$questiondata = $DB->get_record('question',
|
||||||
array('id' => $this->slots[$slot]->questionid));
|
array('id' => $this->slots[$slot]->questionid));
|
||||||
if ($questiondata->qtype != 'random') {
|
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);
|
$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) {
|
if ($newquestion->get_num_variants() == 1) {
|
||||||
$variant = 1;
|
$variant = 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1813,8 +1818,8 @@ class quiz_attempt {
|
||||||
$newquestion->get_variants_selection_seed());
|
$newquestion->get_variants_selection_seed());
|
||||||
}
|
}
|
||||||
|
|
||||||
$newslot = $this->quba->add_question_in_place_of_other($slot, $newquestion);
|
// Start the question.
|
||||||
$this->quba->start_question($slot);
|
$this->quba->start_question($slot, $variant);
|
||||||
$this->quba->set_max_mark($newslot, 0);
|
$this->quba->set_max_mark($newslot, 0);
|
||||||
$this->quba->set_question_attempt_metadata($newslot, 'originalslot', $slot);
|
$this->quba->set_question_attempt_metadata($newslot, 'originalslot', $slot);
|
||||||
question_engine::save_questions_usage_by_activity($this->quba);
|
question_engine::save_questions_usage_by_activity($this->quba);
|
||||||
|
|
|
@ -90,6 +90,15 @@ class least_used_strategy implements \question_variant_selection_strategy {
|
||||||
return $this->selectedvariant[$seed];
|
return $this->selectedvariant[$seed];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Catch a possible programming error, and make the problem clear.
|
||||||
|
if (!isset($this->variantsusecounts[$seed])) {
|
||||||
|
debugging('Variant requested for unknown seed ' . $seed . '. ' .
|
||||||
|
'You must add all questions to the usage before creating the least_used_strategy. ' .
|
||||||
|
'Continuing, but the variant choses may not actually be least used.',
|
||||||
|
DEBUG_DEVELOPER);
|
||||||
|
$this->variantsusecounts[$seed] = array();
|
||||||
|
}
|
||||||
|
|
||||||
if ($maxvariants > 2 * count($this->variantsusecounts[$seed])) {
|
if ($maxvariants > 2 * count($this->variantsusecounts[$seed])) {
|
||||||
// Many many more variants exist than have been used so far.
|
// Many many more variants exist than have been used so far.
|
||||||
// It will be quicker to just pick until we miss a collision.
|
// It will be quicker to just pick until we miss a collision.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue