Fix matching update

1.10.x
Julio Montoya 10 years ago
parent 4b2daf2800
commit 6723fefdf5
  1. 29
      main/exercice/answer.class.php
  2. 12
      main/exercice/matching.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) {
if (isset($answerList[$correct])) {
$correct = $answerList[$correct];
}
$sql = "UPDATE $answerTable
SET correct = $autoId
SET correct = $correct
WHERE
correct = $correct AND
c_id = $c_id AND
question_id = $questionId
id_auto = $autoId
";
Database::query($sql);
}
}
}*/
/*if (!empty($answerList)) {
foreach ($answerList as $autoId => $counterId) {

@ -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;
}
/**

Loading…
Cancel
Save