Fixed bug storing results in quiz in single answer (fixes5148)

skala
Yannick Warnier 16 years ago
parent b86b066c6d
commit 406d53c8b1
  1. 22
      main/exercice/answer.class.php
  2. 6
      main/exercice/exercice_submit.php
  3. 17
      main/exercice/exercise_result.php
  4. 3
      main/exercice/hotpotatoes.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;
}
/**

@ -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();
}
}

@ -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])) {

@ -227,9 +227,6 @@ if((api_is_allowed_to_edit()) && (($finish == 0) || ($finish == 2)))
}
Display::display_header($nameTools,"Exercise");
?>
<?php
if ($finish==2) //if we are in the img upload process
{

Loading…
Cancel
Save