diff --git a/main/exercice/answer.class.php b/main/exercice/answer.class.php index 211dfd3bd0..8fa2d13012 100644 --- a/main/exercice/answer.class.php +++ b/main/exercice/answer.class.php @@ -114,7 +114,7 @@ class Answer $questionId=$this->questionId; //$answerType=$this->selectType(); - $sql="SELECT answer,correct,comment,ponderation, position, hotspot_coordinates, hotspot_type, destination FROM + $sql="SELECT id,answer,correct,comment,ponderation, position, hotspot_coordinates, hotspot_type, destination FROM $TBL_ANSWER WHERE question_id ='".Database::escape_string($questionId)."' ORDER BY position"; $result=api_sql_query($sql,__FILE__,__LINE__); @@ -124,6 +124,7 @@ class Answer // while a record is found while($object=mysql_fetch_object($result)) { + $this->id[$i]=$object->id; $this->answer[$i]=$object->answer; $this->correct[$i]=$object->correct; $this->comment[$i]=$object->comment; @@ -216,8 +217,8 @@ class Answer { return $this->destination[$id]; } - - /** + +/** * returns the answer title * * @author - Olivier Brouckaert @@ -227,6 +228,21 @@ class Answer function selectAnswer($id) { return $this->answer[$id]; + } + /** + * returns the answer title from an answer's position + * + * @author - Yannick Warnier + * @param - integer $id - answer ID + * @return - string - answer title + */ + function selectAnswerIdByPosition($pos) + { + foreach ($this->position as $k => $v) { + if ($v != $pos) { continue; } + return $k; + } + return false; } /** diff --git a/main/exercice/exercice_submit.php b/main/exercice/exercice_submit.php index de7ffdf795..2f0877245f 100644 --- a/main/exercice/exercice_submit.php +++ b/main/exercice/exercice_submit.php @@ -580,9 +580,7 @@ if ($formSent) { $answer = $choice; exercise_attempt($questionScore, $answer, $quesId, $exeId, 0); } elseif ($answerType == UNIQUE_ANSWER) { - $sql = "select id from $table_ans where question_id='" . Database :: escape_string($questionId) . "' and position='" . Database :: escape_string($choice) . "'"; - $res = api_sql_query($sql, __FILE__, __LINE__); - $answer = Database :: result($res, 0, "id"); + $answer = $choice; exercise_attempt($questionScore, $answer, $quesId, $exeId, 0); } elseif ($answerType == HOT_SPOT) { exercise_attempt($questionScore, $answer, $quesId, $exeId, 0); @@ -1102,4 +1100,4 @@ if ($_configuration['live_exercise_tracking'] == true && $exerciseFeedbackType ! if ($origin != 'learnpath') { //so we are not in learnpath tool Display :: display_footer(); -} \ No newline at end of file +} diff --git a/main/exercice/exercise_result.php b/main/exercice/exercise_result.php index d9b8297cfa..a37802cb7d 100644 --- a/main/exercice/exercise_result.php +++ b/main/exercice/exercise_result.php @@ -600,8 +600,10 @@ foreach ($questionList as $questionId) { $nbrAnswers = 1; } + // We're inside *one* question. Go through each possible answer for this question for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) { + //select answer of *position*=$answerId $answer=$objAnswerTmp->selectAnswer($answerId); $answerComment=$objAnswerTmp->selectComment($answerId); $answerCorrect=$objAnswerTmp->isCorrect($answerId); @@ -609,6 +611,10 @@ foreach ($questionList as $questionId) { switch ($answerType) { // for unique answer case UNIQUE_ANSWER : + // if the student choice is equal to the answer ID + // then give him the corresponding score + // (maybe a negative score, positive score or 0) + // Positive score should only be given when we are going over the right answer $studentChoice=($choice == $answerId)?1:0; if($studentChoice) { $questionScore+=$answerWeighting; @@ -999,14 +1005,9 @@ foreach ($questionList as $questionId) { exercise_attempt($questionScore,$answer,$quesId,$exeId,0); } elseif ($answerType==UNIQUE_ANSWER) { - $sql = "SELECT id FROM $table_ans WHERE question_id='".Database::escape_string($questionId)."' and position='".Database::escape_string($choice)."'"; - $res = api_sql_query($sql, __FILE__, __LINE__); - if (Database::num_rows($res)>0) { - $answer = Database::result($res,0,"id"); - exercise_attempt($questionScore,$answer,$quesId,$exeId,0); - } else { - exercise_attempt($questionScore,0 ,$quesId,$exeId,0); - } + // exercise_attempt($questionScore,$answer,$quesId,$exeId,0); + // In fact, we are not storing the results by answer ID, but by *position*, which is stored in $choice + exercise_attempt($questionScore,$choice,$quesId,$exeId,0); } elseif ($answerType == HOT_SPOT) { exercise_attempt($questionScore, $answer, $quesId, $exeId, 0); if (is_array($exerciseResultCoordinates[$quesId])) { diff --git a/main/exercice/hotpotatoes.php b/main/exercice/hotpotatoes.php index 76ff9ad42b..d5d7266d86 100644 --- a/main/exercice/hotpotatoes.php +++ b/main/exercice/hotpotatoes.php @@ -227,9 +227,6 @@ if((api_is_allowed_to_edit()) && (($finish == 0) || ($finish == 2))) } Display::display_header($nameTools,"Exercise"); - ?> - -