Exercise: Fix fill blank question with switchable options - refs BT#19057

pull/4080/head
Angel Fernando Quiroz Campos 4 years ago
parent 87a575809b
commit e944e773e6
  1. 46
      main/exercise/exercise.class.php
  2. 6
      main/exercise/fill_blanks.class.php

@ -4404,32 +4404,30 @@ class Exercise
for ($j = 0; $j < count($listTeacherAnswerTemp); $j++) {
$correctAnswer = $listTeacherAnswerTemp[$j];
if (!$found) {
if (FillBlanks::isStudentAnswerGood(
$studentAnswer,
$correctAnswer,
$from_database,
true
)) {
$questionScore += $answerWeighting[$i];
$totalScore += $answerWeighting[$i];
$listTeacherAnswerTemp[$j] = '';
$found = true;
}
if (empty($correctAnswer)) {
continue;
}
$type = FillBlanks::getFillTheBlankAnswerType($correctAnswer);
if ($type == FillBlanks::FILL_THE_BLANK_MENU) {
$listMenu = FillBlanks::getFillTheBlankMenuAnswers($correctAnswer, false);
if (!empty($studentAnswer)) {
foreach ($listMenu as $key => $item) {
if ((!$found && $key == $j)
|| ($found && sha1($item) === $studentAnswer)
) {
$studentAnswerToShow = $item;
break;
}
}
if (FillBlanks::isStudentAnswerGood(
$studentAnswer,
$correctAnswer,
$from_database,
true
)) {
$questionScore += $answerWeighting[$i];
$totalScore += $answerWeighting[$i];
$listTeacherAnswerTemp[$j] = null;
$found = true;
}
if (FillBlanks::FILL_THE_BLANK_MENU != $listCorrectAnswers['words_types'][$j]) {
continue;
}
$listMenu = FillBlanks::getFillTheBlankMenuAnswers($correctAnswer, false);
foreach ($listMenu as $item) {
if (sha1($item) === $studentAnswer) {
$studentAnswerToShow = $item;
}
}
}

@ -885,6 +885,12 @@ class FillBlanks extends Question
$commonWords = api_preg_replace("/::::::/", '::', $commonWords);
}
$listAnswerResults['common_words'] = explode('::', $commonWords);
$listAnswerResults['words_types'] = array_map(
function ($word): int {
return FillBlanks::getFillTheBlankAnswerType($word);
},
$listAnswerResults['words']
);
return $listAnswerResults;
}

Loading…
Cancel
Save