Skip to content

Commit

Permalink
Exercises - Fix answer list BT#18584
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Mar 17, 2021
1 parent 3c3529e commit 75fd5b7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions main/exercise/exercise.class.php
Expand Up @@ -4569,8 +4569,10 @@ public function manage_answer(
ORDER BY id_auto";
$result = Database::query($sql);
$options = [];
$correctAnswers = [];
while ($row = Database::fetch_array($result, 'ASSOC')) {
$options[] = $row;
$correctAnswers[$row['correct']] = $row['answer'];
}

$questionScore = 0;
Expand Down Expand Up @@ -4602,16 +4604,16 @@ public function manage_answer(
$questionScore += $i_answerWeighting;
$totalScore += $i_answerWeighting;
$user_answer = Display::label(get_lang('Correct'), 'success');

if ($this->showExpectedChoice()) {
if ($this->showExpectedChoice() &&!empty($i_answer_id_auto)) {
$user_answer = $answerMatching[$i_answer_id_auto];
}
$status = Display::label(get_lang('Correct'), 'success');
} else {
$user_answer = Display::label(get_lang('Incorrect'), 'danger');
if ($this->showExpectedChoice()) {
$data = $options[$real_list[$s_user_answer] - 1];
$user_answer = $data['answer'];
if ($this->showExpectedChoice() && !empty($s_user_answer)) {
/*$data = $options[$real_list[$s_user_answer] - 1];
$user_answer = $data['answer'];*/
$user_answer = $correctAnswers[$s_user_answer] ?? '';
}
}
} else {
Expand Down

0 comments on commit 75fd5b7

Please sign in to comment.