Browse Source

Fix fill in blanks when showing correct answers on last attemp - refs BT#11024

Angel Fernando Quiroz Campos 8 years ago
parent
commit
566a59e42b
2 changed files with 30 additions and 1 deletions
  1. 8 1
      main/exercise/exercise.class.php
  2. 22 0
      main/exercise/fill_blanks.class.php

+ 8 - 1
main/exercise/exercise.class.php

@@ -8456,7 +8456,14 @@ class Exercise
         foreach ($attempts as $attempt) {
             foreach ($attempt['question_list'] as $answer) {
                 $objAnswer = new Answer($answer['question_id']);
-                $isCorrect = $objAnswer->isCorrectByAutoId($answer['answer']);
+
+                switch ($objAnswer->getQuestionType()) {
+                    case FILL_IN_BLANKS:
+                        $isCorrect = FillBlanks::isCorrect($answer['answer']);
+                        break;
+                    default:
+                        $isCorrect = $objAnswer->isCorrectByAutoId($answer['answer']);
+                }
 
                 if ($isCorrect) {
                     $corrects[$answer['question_id']][] = $answer;

+ 22 - 0
main/exercise/fill_blanks.class.php

@@ -1169,4 +1169,26 @@ class FillBlanks extends Question
     {
         return self::getHtmlAnswer($answer, $correct, false, $resultsDisabled);
     }
+
+    /**
+     * Check if a answer is correct by its text
+     * @param string $answerText
+     * @return bool
+     */
+    public static function isCorrect($answerText)
+    {
+        $answerInfo = FillBlanks::getAnswerInfo($answerText, true);
+        $correctAnswerList = $answerInfo['tabwords'];
+        $studentAnswer = $answerInfo['studentanswer'];
+
+        $isCorrect = true;
+
+        foreach ($correctAnswerList as $i => $correctAnswer) {
+            $isGoodStudentAnswer = FillBlanks::isGoodStudentAnswer($studentAnswer[$i], $correctAnswer);
+
+            $isCorrect = $isCorrect && $isGoodStudentAnswer;
+        }
+
+        return $isCorrect;
+    }
 }