Use iid instead auto_id when updating answers

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent 79078610bb
commit 3f49cdf44b
  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
@ -127,6 +128,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;
@ -223,7 +225,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
@ -248,6 +251,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++;
} }
@ -261,6 +265,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;
@ -544,7 +549,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
@ -555,7 +560,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,
@ -566,7 +571,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,
@ -577,10 +581,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)]);
} }
/** /**
@ -607,6 +610,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 = [
@ -622,9 +626,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();
@ -642,7 +646,7 @@ class Answer
Database::update( Database::update(
$answerTable, $answerTable,
['correct' => $correctAnswerAutoId ? $correctAnswerAutoId : 0], ['correct' => $correctAnswerAutoId ? $correctAnswerAutoId : 0],
['iid = ?' => $autoId] ['iid = ?' => $iid]
); );
} }
} }
@ -652,7 +656,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],
@ -664,10 +668,10 @@ class Answer
); );
} }
$answerList[$i] = $autoId; $answerList[$i] = $iid;
if ($correct) { if ($correct) {
$correctList[$autoId] = true; $correctList[$iid] = true;
} }
} }

Loading…
Cancel
Save