Fixed matching exercise with response random

skala
Cristian Fasanando 15 years ago
parent 0e62492b88
commit e74e31651b
  1. 17
      main/exercice/answer.class.php
  2. 38
      main/exercice/exercice_submit.php
  3. 36
      main/exercice/exercise.lib.php
  4. 26
      main/exercice/exercise_result.php
  5. 44
      main/exercice/exercise_show.php

@ -252,6 +252,23 @@ class Answer
{
return $this->answer[$id];
}
function selectAnswerByAutoId($auto_id) {
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
$auto_id = intval($auto_id);
$sql="SELECT id, answer FROM $TBL_ANSWER WHERE id_auto='$auto_id'";
$rs = Database::query($sql, __FILE__, __LINE__);
if (Database::num_rows($rs)>0) {
$row = Database::fetch_array($rs);
return $row;
}
return false;
}
/**
* returns the answer title from an answer's position
*

@ -576,19 +576,15 @@ if ($formSent) {
break;
// for matching
case MATCHING :
$numAnswer=$objAnswerTmp->selectAutoId($answerId);
if ($answerCorrect) {
if ($answerCorrect == $choice[$answerId]) {
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
$choice[$answerId] = $matching[$choice[$answerId]];
if ($answerCorrect == $choice[$numAnswer]) {
$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;
}
elseif (!$choice[$answerId]) {
$choice[$answerId] = '   ';
} else {
$choice[$answerId] = '<font color="red"><s>' . $matching[$choice[$answerId]] . '</s></font>';
}
} else {
$matching[$answerId] = $answer;
$matching[$numAnswer] = $choice[$numAnswer];
}
break;
// for hotspot with no order
@ -642,25 +638,11 @@ if ($formSent) {
}
}
elseif ($answerType == MATCHING) {
$j = sizeof($matching) + 1;
for ($i = 0; $i < sizeof($choice); $i++, $j++) {
$val = $choice[$j];
if (preg_match_all('#<font color="red"><s>([0-9a-z ]*)</s></font>#', $val, $arr1)) {
$val = $arr1[1][0];
}
$val = $val;
$val = strip_tags($val);
$sql = "select position from $table_ans where question_id='" . Database :: escape_string($questionId) . "' and answer='" . Database :: escape_string($val) . "' AND correct=0";
$res = Database::query($sql, __FILE__, __LINE__);
if (Database :: num_rows($res) > 0) {
$answer = Database :: result($res, 0, "position");
} else {
$answer = '';
}
exercise_attempt($questionScore, $answer, $quesId, $exeId, $j);
foreach ($matching as $j => $val) {
exercise_attempt($questionScore, $val, $quesId, $exeId, $j);
}
} elseif ($answerType == FREE_ANSWER) {
$answer = $choice;
exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);

@ -110,9 +110,30 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false,$current_it
// only used for the answer type "Matching"
if($answerType == MATCHING)
{
$cpt1='A';
$x = 1;
$letter = 'A';
$cpt2=1;
$Select=array();
$answer_matching = $cpt1 = array();
for($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
$answerCorrect = $objAnswerTmp->isCorrect($answerId);
$numAnswer = $objAnswerTmp->selectAutoId($answerId);
$answer=$objAnswerTmp->selectAnswer($answerId);
if(!$answerCorrect) {
// options (A, B, C, ...) that will be put into the list-box
$cpt1[$x] = $letter;
$answer_matching[$x]=$objAnswerTmp->selectAnswerByAutoId($numAnswer);
$x++;
$letter++;
}
}
foreach($answer_matching as $value) {
$Select[$value['id']]['Lettre'] = $cpt1[$value['id']];
$Select[$value['id']]['Reponse'] = $value['answer'];
}
}
elseif($answerType == FREE_ANSWER)
{
@ -236,13 +257,8 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false,$current_it
// matching // TODO: replace $answerId by $numAnswer
else {
if(!$answerCorrect) {
// options (A, B, C, ...) that will be put into the list-box
$Select[$answerId]['Lettre']=$cpt1++;
// answers that will be shown at the right side
$answer = api_parse_tex($answer);
$Select[$answerId]['Reponse']=$answer;
} else {
if ($answerCorrect) {
$s.="
<tr>
<td colspan='2'>
@ -252,7 +268,7 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false,$current_it
$s.=' <span style=\' float:left; width:5%;\'><b>'.$cpt2.'</b>.&nbsp;</span>
<span style=\' float:left; width:95%;\'>'.$answer.'</span>';
$s.="<td width='20%' valign='top' align='center'>&nbsp;&nbsp;<select name='choice[".$questionId."][".$answerId."]'>
$s.="<td width='20%' valign='top' align='center'>&nbsp;&nbsp;<select name='choice[".$questionId."][".$numAnswer."]'>
<option value='0'>--</option>";
// fills the list-box
@ -296,8 +312,6 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false,$current_it
</table>
</td>
</tr>";
$cpt2++;
} // end while()
} // end if()

@ -798,25 +798,17 @@ foreach ($questionList as $questionId) {
break;
// for matching TODO: replace $answerId id by $numAnswer
case MATCHING :
if($answerCorrect)
{
if($answerCorrect == $choice[$answerId])
{
if ($answerCorrect) {
if ($answerCorrect == $choice[$numAnswer]) {
$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;
$choice[$answerId]=$matching[$choice[$answerId]];
}
elseif(!$choice[$answerId])
{
$choice[$answerId]='&nbsp;&nbsp;&nbsp;';
}
else
{
$choice[$answerId]='<font color="red"><s>'.$matching[$choice[$answerId]].'</s></font>';
}
$choice[$numAnswer]=$matching[$choice[$numAnswer]];
} elseif(!$choice[$numAnswer]) {
$choice[$numAnswer]='&nbsp;&nbsp;&nbsp;';
} else {
$choice[$numAnswer]='<font color="red"><s>'.$matching[$choice[$numAnswer]].'</s></font>';
}
else
{
} else {
$matching[$answerId]=$answer;
}
break;
@ -917,7 +909,7 @@ foreach ($questionList as $questionId) {
echo $answer; ?>
</td>
<td width="50%">
<?php echo $choice[$answerId]; ?> / <font color="green"><b>
<?php echo $choice[$numAnswer]; ?> / <font color="green"><b>
<?php
$matching[$answerCorrect]=api_parse_tex($matching[$answerCorrect]);
echo $matching[$answerCorrect]; ?></b></font>

@ -843,16 +843,15 @@ if ($show_results) {
$objAnswerTmp=new Answer($questionId);
$table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$TBL_TRACK_ATTEMPT= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$sql_select_answer = 'SELECT id, answer, correct, position FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" AND correct<>0';
$sql_answer = 'SELECT position, answer FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" AND correct=0';
$sql_answer = 'SELECT id, answer FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" AND correct=0';
$res_answer = Database::query($sql_answer, __FILE__, __LINE__);
// getting the real answer
$real_list =array();
while ($real_answer = Database::fetch_array($res_answer)) {
$real_list[$real_answer['position']]= $real_answer['answer'];
$real_list[$real_answer['id']]= $real_answer['answer'];
}
$sql_select_answer = 'SELECT id, answer, correct, id_auto FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" AND correct<>0';
$res_answers = Database::query($sql_select_answer, __FILE__, __LINE__);
echo '<table width="100%" height="71" border="0" cellspacing="3" cellpadding="3" >';
@ -866,46 +865,37 @@ if ($show_results) {
$questionScore=0;
while ($a_answers = Database::fetch_array($res_answers)) {
$i_answer_id = $a_answers['id']; //3
$s_answer_label = $a_answers['answer']; // your dady - you mother
$i_answer_correct_answer = $a_answers['correct']; //1 - 2
$i_answer_position = $a_answers['position']; // 3 - 4
$sql_user_answer =
'SELECT answers.answer
FROM '.$TBL_TRACK_ATTEMPT.' as track_e_attempt
INNER JOIN '.$table_ans.' as answers
ON answers.position = track_e_attempt.answer
AND track_e_attempt.question_id=answers.question_id
WHERE answers.correct = 0
AND track_e_attempt.exe_id = "'.Database::escape_string($id).'"
AND track_e_attempt.question_id = "'.Database::escape_string($questionId).'"
AND track_e_attempt.position="'.Database::escape_string($i_answer_position).'"';
$i_answer_id_auto = $a_answers['id_auto']; // 3 - 4
$sql_user_answer = "SELECT answer
FROM $TBL_TRACK_ATTEMPT
WHERE exe_id = '$id' AND question_id = '$questionId' AND position='$i_answer_id_auto'";
$res_user_answer = Database::query($sql_user_answer, __FILE__, __LINE__);
if (Database::num_rows($res_user_answer)>0 ) {
$s_user_answer = Database::result($res_user_answer,0,0); // rich - good looking
} else {
$s_user_answer = '';
$s_user_answer = 0;
}
//$s_correct_answer = $s_answer_label; // your ddady - your mother
$s_correct_answer = $real_list[$i_answer_correct_answer];
$i_answerWeighting=$objAnswerTmp->selectWeighting($i_answer_id);
//if($s_user_answer == $s_correct_answer) // rich == your ddady?? wrong
//echo $s_user_answer.' - '.$real_list[$i_answer_correct_answer];
if ($s_user_answer == $real_list[$i_answer_correct_answer]) { // rich == your ddady?? wrong
$user_answer = '';
if (!empty($s_user_answer)) {
if ($s_user_answer == $i_answer_correct_answer) {
$questionScore+=$i_answerWeighting;
$totalScore+=$i_answerWeighting;
$user_answer = '<span>'.$real_list[$i_answer_correct_answer].'</span>';
} else {
$s_user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$s_user_answer.'</span>';
$user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$real_list[$s_user_answer].'</span>';
}
}
echo '<tr>';
echo '<td>'.$s_answer_label.'</td><td>'.$s_user_answer.' / <b><span style="color: #008000;">'.$s_correct_answer.'</span></b></td>';
echo '<td>'.$s_answer_label.'</td><td>'.$user_answer.' / <b><span style="color: #008000;">'.$real_list[$i_answer_correct_answer].'</span></b></td>';
echo '</tr>';
}
echo '</table>';

Loading…
Cancel
Save