瀏覽代碼

Merge pull request #352 from ilosada/BT8659

Correct scoring issue - refs BT#8659
Yannick Warnier 10 年之前
父節點
當前提交
e7899702c2
共有 2 個文件被更改,包括 15 次插入2 次删除
  1. 5 0
      main/exercice/exercise.lib.php
  2. 10 2
      main/exercice/upload_exercise.php

+ 5 - 0
main/exercice/exercise.lib.php

@@ -2323,6 +2323,11 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu
             if (empty($result)) {
             if (empty($result)) {
                 continue;
                 continue;
             }
             }
+            
+            // In case of global score, make sure the calculated total score is integer
+            if (!is_int($result['score'])) {
+                $result['score'] = round($result['score']);
+            }
 
 
             $total_score += $result['score'];
             $total_score += $result['score'];
             $total_weight += $result['weight'];
             $total_weight += $result['weight'];

+ 10 - 2
main/exercice/upload_exercise.php

@@ -324,7 +324,14 @@ function lp_upload_quiz_action_handling() {
                     $globalScore = null;
                     $globalScore = null;
                     $objAnswer = new Answer($question_id, $courseId);
                     $objAnswer = new Answer($question_id, $courseId);
                     $globalScore = $score_list[$i][3];
                     $globalScore = $score_list[$i][3];
-                    var_dump('global -> '.$globalScore);
+                    
+                    // Calculate the number of correct answers to divide the score between them when importing from CSV
+                    $numberRightAnswers = 0;
+                    foreach ($answers_data as $answer_data) {
+                        if (strtolower($answer_data[3]) == 'x') {
+                            $numberRightAnswers++;
+                        }
+                    }                    
                     foreach ($answers_data as $answer_data) {
                     foreach ($answers_data as $answer_data) {
                         $answerValue = $answer_data[2];
                         $answerValue = $answer_data[2];
                         $correct = 0;
                         $correct = 0;
@@ -341,7 +348,7 @@ function lp_upload_quiz_action_handling() {
                             }
                             }
                         }
                         }
 
 
-                        var_dump($answerValue);
+                        //var_dump($answerValue);
 
 
 
 
                         if ($useCustomScore) {
                         if ($useCustomScore) {
@@ -355,6 +362,7 @@ function lp_upload_quiz_action_handling() {
                         // Fixing scores:
                         // Fixing scores:
                         switch ($detectQuestionType) {
                         switch ($detectQuestionType) {
                             case GLOBAL_MULTIPLE_ANSWER:
                             case GLOBAL_MULTIPLE_ANSWER:
+                                $score /= $numberRightAnswers;
                                 break;
                                 break;
                             case UNIQUE_ANSWER:
                             case UNIQUE_ANSWER:
                                 break;
                                 break;