Randomize test answers consistently per attempt
This commit is contained in:
@@ -85,6 +85,14 @@ $resolveImageUrl = static function ($path) {
|
||||
<?php if ($this->items) : ?>
|
||||
<form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8'); ?>" method="post" id="test-form">
|
||||
<?php foreach ($this->items as $number => $item) : ?>
|
||||
<?php
|
||||
$answerOrder = $this->results && !empty($this->results['items'][$item->id]['answer_order'])
|
||||
? $this->results['items'][$item->id]['answer_order']
|
||||
: [1, 2, 3, 4];
|
||||
if (!$this->results && $item->question_type === 'closed') {
|
||||
shuffle($answerOrder);
|
||||
}
|
||||
?>
|
||||
<article class="testquestion mb-4">
|
||||
<div class="pyt"><div class="question-header"><span class="question-number"><?php echo ($number + 1) . '.'; ?></span><div class="question-text"><?php echo $item->question; ?></div></div></div>
|
||||
<?php if ($item->image) : ?><div class="foto_pyt"><img src="<?php echo htmlspecialchars($resolveImageUrl($item->image), ENT_QUOTES, 'UTF-8'); ?>" alt="" loading="lazy"></div><?php endif; ?>
|
||||
@@ -99,12 +107,14 @@ $resolveImageUrl = static function ($path) {
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<?php if (!$this->results) : ?><input type="hidden" name="answer_order[<?php echo (int) $item->id; ?>]" value="<?php echo htmlspecialchars(implode(',', $answerOrder), ENT_QUOTES, 'UTF-8'); ?>"><?php endif; ?>
|
||||
<ol type="A" class="answer-list">
|
||||
<?php foreach (['answer_a', 'answer_b', 'answer_c', 'answer_d'] as $answerIndex => $answerField) : ?>
|
||||
<?php $isSelected = $this->results && $this->results['items'][$item->id]['selected'] === (string) ($answerIndex + 1); ?>
|
||||
<?php $isCorrectAnswer = $this->results && (string) $item->correct_answer === (string) ($answerIndex + 1); ?>
|
||||
<?php foreach ($answerOrder as $displayIndex => $optionValue) : ?>
|
||||
<?php $answerField = 'answer_' . chr(96 + (int) $optionValue); ?>
|
||||
<?php $isSelected = $this->results && $this->results['items'][$item->id]['selected'] === (string) $optionValue; ?>
|
||||
<?php $isCorrectAnswer = $this->results && (string) $item->correct_answer === (string) $optionValue; ?>
|
||||
<li class="<?php echo $isSelected && $this->results['items'][$item->id]['correct'] ? 'odpup' : ($isSelected ? 'odpu' : ($isCorrectAnswer ? 'odpp' : 'odp')); ?>">
|
||||
<label><input type="radio" name="answers[<?php echo (int) $item->id; ?>]" value="<?php echo $answerIndex + 1; ?>" <?php echo $isSelected ? 'checked' : ''; ?>><strong><?php echo chr(65 + $answerIndex); ?>.</strong> <span class="answer-text"><?php echo $item->$answerField; ?></span></label>
|
||||
<label><input type="radio" name="answers[<?php echo (int) $item->id; ?>]" value="<?php echo (int) $optionValue; ?>" <?php echo $isSelected ? 'checked' : ''; ?>><strong><?php echo chr(65 + $displayIndex); ?>.</strong> <span class="answer-text"><?php echo $item->$answerField; ?></span></label>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
|
||||
Reference in New Issue
Block a user