Julio Montoya преди 10 години
родител
ревизия
6723fefdf5
променени са 2 файла, в които са добавени 30 реда и са изтрити 19 реда
  1. 21 16
      main/exercice/answer.class.php
  2. 9 3
      main/exercice/matching.class.php

+ 21 - 16
main/exercice/answer.class.php

@@ -567,12 +567,10 @@ class Answer
                     'hotspot_type' => $hotspot_type,
                     'destination' => $destination
                 ];
-			    $id = Database::insert($answerTable, $params);
-                if ($id) {
-                    $sql = "UPDATE $answerTable SET id = id_auto WHERE id_auto = $id";
+                $autoId = Database::insert($answerTable, $params);
+                if ($autoId) {
+                    $sql = "UPDATE $answerTable SET id = id_auto WHERE id_auto = $autoId";
                     Database::query($sql);
-                    $correctList[$id] = array('id' => $i, 'correct' => $correct);
-                    $answerList[$id] = $i;
                 }
             } else {
                 // https://support.chamilo.org/issues/6558
@@ -590,23 +588,30 @@ class Answer
                     $this->new_hotspot_type[$i]
                 );
             }
+
+            $answerList[$i] = $autoId;
+            if ($correct) {
+                $correctList[$autoId] = array('id' => $i, 'correct' => $correct);
+            }
         }
 
-        /*if (!empty($correctList)) {
+        if (!empty($correctList)) {
             foreach ($correctList as $autoId => $data) {
                 $correct = $data['correct'];
-                if ($correct) {
-                    $sql = "UPDATE $answerTable
-                            SET correct = $autoId
-                            WHERE
-                                correct = $correct AND
-                                c_id = $c_id AND
-                                question_id = $questionId
-                            ";
-                    Database::query($sql);
+
+                if (isset($answerList[$correct])) {
+                    $correct = $answerList[$correct];
                 }
+
+                $sql = "UPDATE $answerTable
+                        SET correct = $correct
+                        WHERE
+                            id_auto = $autoId
+                        ";
+                Database::query($sql);
+
             }
-        }*/
+        }
 
         /*if (!empty($answerList)) {
             foreach ($answerList as $autoId => $counterId) {

+ 9 - 3
main/exercice/matching.class.php

@@ -23,7 +23,7 @@ class Matching extends Question
     {
         parent::__construct();
         $this->type = MATCHING;
-        $this->isContent = $this-> getIsContent();
+        $this->isContent = $this->getIsContent();
     }
 
     /**
@@ -37,13 +37,13 @@ class Matching extends Question
         $matches = array();
 
         $answer = null;
+        $counter = 1;
 
         if (isset($this->id)) {
             $answer = new Answer($this->id);
             $answer->read();
 
             if (count($answer->nbrAnswers) > 0) {
-                $counter = 1;
                 for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
                     $correct = $answer->isCorrect($i);
                     if (empty($correct)) {
@@ -97,6 +97,11 @@ class Matching extends Question
                 // 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);
+            }
         }
 
         $form->addElement('hidden', 'nb_matches', $nb_matches);
@@ -129,10 +134,12 @@ class Matching extends Question
                 '<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>',
                 "answer[$i]"
             );
+
             $renderer->setElementTemplate(
                 '<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>',
                 "matches[$i]"
             );
+
             $renderer->setElementTemplate(
                 '<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>',
                 "weighting[$i]"
@@ -258,7 +265,6 @@ class Matching extends Question
 
         $objAnswer->save();
         $this->save();
-        exit;
     }
 
     /**