Randomize test answers consistently per attempt
This commit is contained in:
@@ -51,6 +51,7 @@ class HtmlView extends BaseHtmlView
|
||||
}
|
||||
|
||||
$answers = (array) $input->post->get('answers', [], 'array');
|
||||
$submittedAnswerOrder = (array) $input->post->get('answer_order', [], 'array');
|
||||
$results = [];
|
||||
$correct = 0;
|
||||
|
||||
@@ -70,6 +71,14 @@ class HtmlView extends BaseHtmlView
|
||||
$isCorrect = (string) $item->correct_answer === $selected;
|
||||
}
|
||||
|
||||
$answerOrder = array_map('intval', explode(',', (string) ($submittedAnswerOrder[$item->id] ?? '')));
|
||||
sort($answerOrder);
|
||||
if ($item->question_type !== 'closed' || $answerOrder !== [1, 2, 3, 4]) {
|
||||
$answerOrder = [1, 2, 3, 4];
|
||||
} else {
|
||||
$answerOrder = array_map('intval', explode(',', (string) $submittedAnswerOrder[$item->id]));
|
||||
}
|
||||
|
||||
if ($isCorrect) {
|
||||
$correct++;
|
||||
}
|
||||
@@ -78,6 +87,7 @@ class HtmlView extends BaseHtmlView
|
||||
'selected' => $selected,
|
||||
'correct' => $isCorrect,
|
||||
'points' => (int) ($item->points ?? 0),
|
||||
'answer_order' => $answerOrder,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user