Ver Fonte

Fix all Stats report for fill Blanks - Refs #8077

José Loguercio há 9 anos atrás
pai
commit
7004bc146d

+ 4 - 5
main/exercice/fill_blanks.class.php

@@ -756,8 +756,7 @@ class FillBlanks extends Question
 
        $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
        $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
-       $tblCQuizAnswer = Database::get_course_table(TABLE_QUIZ_ANSWER);
-       $courseCode = api_get_course_id();
+       $courseId = api_get_course_int_id();
 
        require_once api_get_path(SYS_PATH).'main/exercice/fill_blanks.class.php';
 
@@ -771,10 +770,10 @@ class FillBlanks extends Question
 
            LEFT JOIN '.$tblTrackEExercise.' tee
            ON tee.exe_id = tea.exe_id
-           AND tea.c_id = "'.$courseCode.'"
+           AND tea.c_id = '.$courseId.'
            AND exe_exo_id = '.$testId.'
 
-           WHERE course_code = "'.$courseCode.'"
+           WHERE tee.c_id = '.$courseId.'
            AND question_id = '.$questionId.'
            AND tea.user_id IN ('.implode(',', $studentsIdList).')
            AND tea.tms >= "'.$startDate.'"
@@ -795,7 +794,7 @@ class FillBlanks extends Question
                if ($tabAnswer['studentanswer'][$bracketNumber] != '') {
                    // student has answered this bracket, cool
                    switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) {
-                       case FILL_THE_BLANK_MENU :
+                       case self::FILL_THE_BLANK_MENU :
                            // get the indice of the choosen answer in the menu
                            // we know that the right answer is the first entry of the menu, ie 0
                            // (remember, menu entries are shuffled when taking the test)

+ 5 - 12
main/exercice/stats.php

@@ -146,26 +146,19 @@ if (!empty($question_list)) {
 
                         $answer_item = api_substr($answer_item, 1);
                         $answer_item = api_substr($answer_item, 0, api_strlen($answer_item) -1);
+                        
+                        $data[$id]['answer'] 	= $answer_item;
 
                         $data[$id]['correct'] 	= '-';
 
-                        $count = ExerciseLib::get_number_students_answer_count(
-                            $real_answer_id,
-                            $question_id,
-                            $exercise_id,
-                            $courseCode,
-                            $sessionId,
-                            FILL_IN_BLANKS,
-                            $answer_info_db,
-                            $answer_item
-                        );
-
+                        $count = ExerciseLib::getNumberStudentsFillBlanksAnwserCount($question_id, $exercise_id);
+                        $count = $count[$counter];
+                        
                         $percentange = 0;
                         if (!empty($count_students)) {
                             $percentange = $count/$count_students*100;
                         }
                         $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
-
                         $id++;
                         $counter++;
                     }

+ 71 - 5
main/inc/lib/exercise.lib.php

@@ -2864,6 +2864,53 @@ HOTSPOT;
 
         return $return;
     }
+    
+    /**
+     * Get the correct answer count for a fill blanks question
+     * 
+     * @param int $question_id
+     * @param int $exercise_id
+     * @return int
+     */
+    public static function getNumberStudentsFillBlanksAnwserCount(
+        $question_id,
+        $exercise_id
+    ) {
+        $listStudentsId = [];
+            $listAllStudentInfo = CourseManager::get_student_list_from_course_code(
+                api_get_course_id(),
+                true
+            );
+            foreach ($listAllStudentInfo as $i => $listStudentInfo) {
+                $listStudentsId[] = $listStudentInfo['user_id'];
+            }
+
+            $listFillTheBlankResult = FillBlanks::getFillTheBlankTabResult(
+                $exercise_id,
+                $question_id,
+                $listStudentsId,
+                '1970-01-01',
+                '3000-01-01'
+            );
+
+            $arrayCount = [];
+
+            foreach ($listFillTheBlankResult as $resultCount) {
+                foreach ($resultCount as $index => $count) {
+                    //this is only for declare the array index per answer
+                    $arrayCount[$index] = 0;
+                }
+            }
+
+            foreach ($listFillTheBlankResult as $resultCount) {
+                foreach ($resultCount as $index => $count) {
+                    $count = ($count === 0) ? 1 : 0;
+                    $arrayCount[$index] += $count;
+                }
+            }
+            
+            return $arrayCount;
+    }
 
     /**
      * @param int $question_id
@@ -3126,7 +3173,8 @@ HOTSPOT;
                     while ($row = Database::fetch_array($result, 'ASSOC')) {
                         $fill_blank = self::check_fill_in_blanks(
                             $correct_answer,
-                            $row['answer']
+                            $row['answer'],
+                            $current_answer
                         );
                         if (isset($fill_blank[$current_answer]) && $fill_blank[$current_answer] == 1) {
                             $good_answers++;
@@ -3151,7 +3199,7 @@ HOTSPOT;
      * @param string $user_answer
      * @return array
      */
-    public static function check_fill_in_blanks($answer, $user_answer)
+    public static function check_fill_in_blanks($answer, $user_answer, $current_answer)
     {
         // the question is encoded like this
         // [A] B [C] D [E] F::10,10,10@1
@@ -3208,10 +3256,28 @@ HOTSPOT;
 
             preg_match_all('#\[([^[]*)\]#', $str, $arr);
             $str = str_replace('\r\n', '', $str);
-            $choice = $arr[1];
-
+            $choices = $arr[1];
+            $choice = [];
+            $check = false;
+            $i = 0;
+            foreach ($choices as $item) {
+                if ($current_answer === $item) {
+                    $check = true;
+                }
+                if ($check) {
+                    $choice[] = $item;
+                    $i++;
+                }
+                if ($i == 3) {
+                    break;
+                }
+            }
             $tmp = api_strrpos($choice[$j], ' / ');
-            $choice[$j] = api_substr($choice[$j], 0, $tmp);
+            
+            if ($tmp !== false) {
+                $choice[$j] = api_substr($choice[$j], 0, $tmp);
+            }
+            
             $choice[$j] = trim($choice[$j]);
 
             //Needed to let characters ' and " to work as part of an answer