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:
Tim Hunt 2016-02-10 19:22:17 +00:00
parent 9d5d9c64ff
commit 293f5d1b11
2 changed files with 16 additions and 2 deletions

View file

@ -90,6 +90,15 @@ class least_used_strategy implements \question_variant_selection_strategy {
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])) {
// Many many more variants exist than have been used so far.
// It will be quicker to just pick until we miss a collision.