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

pull/4077/head
Angel Fernando Quiroz Campos 5 years ago
parent 3cab0bbd8a
commit 93291dac8d
  1. 7
      main/exercise/exercise.class.php
  2. 20
      main/exercise/fill_blanks.class.php

@ -4408,7 +4408,8 @@ class Exercise
if (FillBlanks::isStudentAnswerGood(
$studentAnswer,
$correctAnswer,
$from_database
$from_database,
true
)) {
$questionScore += $answerWeighting[$i];
$totalScore += $answerWeighting[$i];
@ -4422,7 +4423,9 @@ class Exercise
$listMenu = FillBlanks::getFillTheBlankMenuAnswers($correctAnswer, false);
if (!empty($studentAnswer)) {
foreach ($listMenu as $key => $item) {
if ($key == $correctAnswer) {
if ((!$found && $key == $j)
|| ($found && sha1($item) === $studentAnswer)
) {
$studentAnswerToShow = $item;
break;
}

@ -684,14 +684,19 @@ class FillBlanks extends Question
* it is not as simple as equality, because of the type of Fill The Blank question
* eg : studentAnswer = 'Un' and correctAnswer = 'Un||1||un'.
*
* @param string $studentAnswer [student_answer] of the info array of the answer field
* @param string $correctAnswer [words] of the info array of the answer field
* @param bool $fromDatabase
* @param string $studentAnswer [student_answer] of the info array of the answer field
* @param string $correctAnswer [words] of the info array of the answer field
* @param bool $fromDatabase Optional
* @param bool $studentAnswerIsHash Optional.
*
* @return bool
*/
public static function isStudentAnswerGood($studentAnswer, $correctAnswer, $fromDatabase = false)
{
public static function isStudentAnswerGood(
string $studentAnswer,
string $correctAnswer,
bool $fromDatabase = false,
bool $studentAnswerIsHash = false
): bool {
$result = false;
switch (self::getFillTheBlankAnswerType($correctAnswer)) {
case self::FILL_THE_BLANK_MENU:
@ -701,7 +706,10 @@ class FillBlanks extends Question
$item = $listMenu[0];
if (!$fromDatabase) {
$item = sha1($item);
$studentAnswer = sha1($studentAnswer);
if (!$studentAnswerIsHash) {
$studentAnswer = sha1($studentAnswer);
}
}
if ($item === $studentAnswer) {
$result = true;

Loading…
Cancel
Save