Use iid instead auto_id when updating answers

pull/2487/head
Angel Fernando Quiroz Campos 9 years ago
parent 9814449bb2
commit 45438d383a
  1. 30
      main/exercice/answer.class.php

@ -36,6 +36,7 @@ class Answer
public $new_nbrAnswers; public $new_nbrAnswers;
public $new_destination; // id of the next question if feedback option is set to Directfeedback public $new_destination; // id of the next question if feedback option is set to Directfeedback
public $course; //Course information public $course; //Course information
public $iid;
/** /**
* constructor of the class * constructor of the class
@ -128,6 +129,7 @@ class Answer
$this->hotspot_type[$i] = $object->hotspot_type; $this->hotspot_type[$i] = $object->hotspot_type;
$this->destination[$i] = $object->destination; $this->destination[$i] = $object->destination;
$this->autoId[$i] = $object->id_auto; $this->autoId[$i] = $object->id_auto;
$this->iid[$i] = $object->iid;
$i++; $i++;
} }
$this->nbrAnswers = $i-1; $this->nbrAnswers = $i-1;
@ -224,7 +226,8 @@ class Answer
hotspot_coordinates, hotspot_coordinates,
hotspot_type, hotspot_type,
destination, destination,
id_auto id_auto,
iid
FROM $TBL_ANSWER FROM $TBL_ANSWER
WHERE WHERE
c_id = {$this->course_id} AND c_id = {$this->course_id} AND
@ -249,6 +252,7 @@ class Answer
$this->hotspot_type[$i] = $object->hotspot_type; $this->hotspot_type[$i] = $object->hotspot_type;
$this->destination[$i] = $object->destination; $this->destination[$i] = $object->destination;
$this->autoId[$i] = $object->id_auto; $this->autoId[$i] = $object->id_auto;
$this->iid[$i] = $object->iid;
$i++; $i++;
} }
@ -262,6 +266,7 @@ class Answer
$this->hotspot_type[$i] = $object->hotspot_type; $this->hotspot_type[$i] = $object->hotspot_type;
$this->destination[$i] = $doubt_data->destination; $this->destination[$i] = $doubt_data->destination;
$this->autoId[$i] = $doubt_data->id_auto; $this->autoId[$i] = $doubt_data->id_auto;
$this->iid[$i] = $doubt_data->iid;
$i++; $i++;
} }
$this->nbrAnswers = $i-1; $this->nbrAnswers = $i-1;
@ -545,7 +550,7 @@ class Answer
* Updates an answer * Updates an answer
* *
* @author Toon Keppens * @author Toon Keppens
* * @param int $iid
* @param string $answer * @param string $answer
* @param string $comment * @param string $comment
* @param string $correct * @param string $correct
@ -556,7 +561,7 @@ class Answer
* @param string $hotspot_type * @param string $hotspot_type
*/ */
public function updateAnswers( public function updateAnswers(
$autoId, $iid,
$answer, $answer,
$comment, $comment,
$correct, $correct,
@ -567,7 +572,6 @@ class Answer
$hotspot_type $hotspot_type
) { ) {
$answerTable = Database :: get_course_table(TABLE_QUIZ_ANSWER); $answerTable = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$autoId = intval($autoId);
$params = [ $params = [
'answer' => $answer, 'answer' => $answer,
@ -578,10 +582,9 @@ class Answer
'destination' => $destination, 'destination' => $destination,
'hotspot_coordinates' => $hotspot_coordinates, 'hotspot_coordinates' => $hotspot_coordinates,
'hotspot_type' => $hotspot_type 'hotspot_type' => $hotspot_type
]; ];
Database::update($answerTable, $params, ['id_auto = ?' => $autoId]); Database::update($answerTable, $params, ['iid = ?' => intval($iid)]);
} }
/** /**
@ -608,6 +611,7 @@ class Answer
$hotspot_type = $this->new_hotspot_type[$i]; $hotspot_type = $this->new_hotspot_type[$i];
$destination = $this->new_destination[$i]; $destination = $this->new_destination[$i];
$autoId = $this->selectAutoId($i); $autoId = $this->selectAutoId($i);
$iid = isset($this->iid[$i]) ? $this->iid[$i] : 0;
if (!isset($this->position[$i])) { if (!isset($this->position[$i])) {
$params = [ $params = [
@ -623,9 +627,9 @@ class Answer
'hotspot_type' => $hotspot_type, 'hotspot_type' => $hotspot_type,
'destination' => $destination 'destination' => $destination
]; ];
$autoId = Database::insert($answerTable, $params); $iid = Database::insert($answerTable, $params);
if ($autoId) { if ($iid) {
$sql = "UPDATE $answerTable SET id = iid, id_auto = iid WHERE iid = $autoId"; $sql = "UPDATE $answerTable SET id = iid, id_auto = iid WHERE iid = $iid";
Database::query($sql); Database::query($sql);
$questionType = $this->getQuestionType(); $questionType = $this->getQuestionType();
@ -643,7 +647,7 @@ class Answer
Database::update( Database::update(
$answerTable, $answerTable,
['correct' => $correctAnswerAutoId ? $correctAnswerAutoId : 0], ['correct' => $correctAnswerAutoId ? $correctAnswerAutoId : 0],
['iid = ?' => $autoId] ['iid = ?' => $iid]
); );
} }
} }
@ -653,7 +657,7 @@ class Answer
// Feed function updateAnswers with none escaped strings // Feed function updateAnswers with none escaped strings
$this->updateAnswers( $this->updateAnswers(
$autoId, $iid,
$this->new_answer[$i], $this->new_answer[$i],
$this->new_comment[$i], $this->new_comment[$i],
$this->new_correct[$i], $this->new_correct[$i],
@ -665,10 +669,10 @@ class Answer
); );
} }
$answerList[$i] = $autoId; $answerList[$i] = $iid;
if ($correct) { if ($correct) {
$correctList[$autoId] = true; $correctList[$iid] = true;
} }
} }

Loading…
Cancel
Save