From 6723fefdf56622ce735c589db15432351c17c111 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 15 Apr 2015 13:53:18 +0200 Subject: [PATCH] Fix matching update --- main/exercice/answer.class.php | 37 ++++++++++++++++++-------------- main/exercice/matching.class.php | 12 ++++++++--- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/main/exercice/answer.class.php b/main/exercice/answer.class.php index 9f488c5b5e..b1a7ebc1be 100755 --- a/main/exercice/answer.class.php +++ b/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) { diff --git a/main/exercice/matching.class.php b/main/exercice/matching.class.php index cea939df7a..66b7e52812 100755 --- a/main/exercice/matching.class.php +++ b/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 '{error}{element}', "answer[$i]" ); + $renderer->setElementTemplate( '{error}{element}', "matches[$i]" ); + $renderer->setElementTemplate( '{error}{element}', "weighting[$i]" @@ -258,7 +265,6 @@ class Matching extends Question $objAnswer->save(); $this->save(); - exit; } /**