Browse Source

Fix resolve the question and show results - refs #7612

Angel Fernando Quiroz Campos 10 years ago
parent
commit
ed2fac0f63

+ 5 - 26
main/exercice/Draggable.php

@@ -35,22 +35,6 @@ class Draggable extends Question
         $matches = array();
 
         $answer = null;
-        $counter = 1;
-
-        if (isset($this->id)) {
-            $answer = new Answer($this->id);
-            $answer->read();
-
-            if (count($answer->nbrAnswers) > 0) {
-                for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
-                    $correct = $answer->isCorrect($i);
-                    if (empty($correct)) {
-                        $matches[$answer->selectAutoId($i)] = chr(64 + $counter);
-                        $counter++;
-                    }
-                }
-            }
-        }
 
         if ($form->isSubmitted()) {
             $nb_matches = $form->getSubmitValue('nb_matches');
@@ -72,6 +56,9 @@ class Draggable extends Question
                 $nb_options++;
             }
         } else if (!empty($this->id)) {
+            $answer = new Answer($this->id);
+            $answer->read();
+
             if (count($answer->nbrAnswers) > 0) {
                 $nb_matches = $nb_options = 0;
                 
@@ -95,16 +82,8 @@ class Draggable extends Question
             $defaults['option[2]'] = get_lang('DefaultMatchingOptB');
         }
 
-        if (empty($matches)) {
-            for ($i = 1; $i <= $nb_options; ++$i) {
-                // fill the array with A, B, C.....
-                $matches[$i] = chr(64 + $i);
-            }
-        } else {
-            for ($i = $counter; $i <= $nb_options; ++$i) {
-                // fill the array with A, B, C.....
-                $matches[$i] = chr(64 + $i);
-            }
+        for ($i = 1; $i <= $nb_matches; ++$i) {
+            $matches[$i] = $i;
         }
 
         $form->addElement('hidden', 'nb_matches', $nb_matches);

+ 6 - 7
main/exercice/exercise.class.php

@@ -2812,12 +2812,12 @@ class Exercise
                                 if ($s_user_answer == $i_answer_correct_answer) {
                                     $questionScore += $i_answerWeighting;
                                     $totalScore += $i_answerWeighting;
+                                    if ($answerType == DRAGGABLE) {
+                                        $user_answer = Display::label(get_lang('Correct'), 'success');
+                                    } else {
                                     if (isset($real_list[$i_answer_id])) {
-                                        if ($answerType == DRAGGABLE) {
-                                            $user_answer = Display::label(get_lang('Correct'), 'success');
-                                        } else {
                                         $user_answer = '<span>'.$real_list[$i_answer_id].'</span>';
-                                        }
+                                    }
                                     }
                                 } else {
                                     if ($answerType == DRAGGABLE) {
@@ -2834,9 +2834,11 @@ class Exercise
                                 echo '<tr>';
                                 echo '<td>'.$s_answer_label.'</td>';
                                 echo '<td>'.$user_answer;
+                                if ($answerType == MATCHING) {
                                 if (isset($real_list[$i_answer_correct_answer])) {
                                     echo ' <b><span style="color: #008000;">'.$real_list[$i_answer_correct_answer].'</span></b> ';
                                 }
+                                }
                                 echo '</td>';
                                 echo '</tr>';
                             }
@@ -2956,9 +2958,6 @@ class Exercise
                         ) ||
                         $answerCorrect
                     ) {
-                        
-                    }
-                    if ($answerType != MATCHING || $answerCorrect) {
                         if (
                             in_array(
                                 $answerType,

+ 2 - 1
main/inc/lib/exercise.lib.php

@@ -955,7 +955,8 @@ class ExerciseLib
                                 'id' => "window_{$windowId}_select",
                                 'class' => 'select_option',
                                 'style' => 'display: none;'
-                            ]
+                            ],
+                            false
                         );
 
                         if (!empty($answerCorrect) && !empty($selectedValue)) {

+ 2 - 2
main/template/default/exercise/submit.js.tpl

@@ -18,8 +18,8 @@
                     value = dropedOnId.split('_')[2];
 
                 $('#' + originSelectId + ' option')
-                    .filter(function () {
-                        return $(this).val() == value;
+                    .filter(function (index) {
+                        return index === parseInt(value);
                     })
                     .attr("selected", true);