New type of question: Multiple answer \"combination\" requires testing

skala
Julio Montoya 16 years ago
parent 6613395de2
commit f44d0aea1e
  1. 27
      main/exercice/answer_admin.inc.php
  2. 38
      main/exercice/exercice_submit.php
  3. 64
      main/exercice/exercise_result.php
  4. 43
      main/exercice/exercise_show.php
  5. 1
      main/exercice/export/qti2/qti2_classes.php
  6. 6
      main/exercice/export/scorm/scorm_classes.php

@ -77,7 +77,7 @@ if($modifyIn)
$objAnswer=new Answer($questionId);
}
if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION)
{
$correct=unserialize($correct);
$reponse=unserialize($reponse);
@ -128,13 +128,11 @@ if($modifyIn)
if($submitAnswers || $buttonBack)
{
if($debug>0){echo '$submitAnswers or $buttonBack was set'."<br />\n";}
if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
{
if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION) {
if($debug>0){echo '&nbsp;&nbsp;$answerType is UNIQUE_ANSWER or MULTIPLE_ANSWER'."<br />\n";}
$questionWeighting=$nbrGoodAnswers=0;
for($i=1;$i <= $nbrAnswers;$i++)
{
for($i=1;$i <= $nbrAnswers;$i++) {
$reponse[$i]=trim($reponse[$i]);
$comment[$i]=trim($comment[$i]);
$weighting[$i]=intval($weighting[$i]);
@ -161,14 +159,11 @@ if($submitAnswers || $buttonBack)
{
$questionWeighting+=$weighting[$i];
}
}
elseif($answerType == MULTIPLE_ANSWER)
{
} elseif($answerType == MULTIPLE_ANSWER) {
if($debug>0){echo str_repeat('&nbsp;',4).'$answerType is MULTIPLE_ANSWER'."<br />\n";}
// a bad answer can't have a positive weighting
$weighting[$i]=0-abs($weighting[$i]);
}
// checks if field is empty
if(empty($reponse[$i]) && $reponse[$i] != '0')
{
@ -178,9 +173,7 @@ if($submitAnswers || $buttonBack)
$objAnswer->cancel();
break;
}
else
{
} else {
// adds the answer into the object
$objAnswer->createAnswer($reponse[$i],$goodAnswer,$comment[$i],$weighting[$i],$i);
//added
@ -883,19 +876,11 @@ if($modifyAnswers)
{
if($debug>0){echo str_repeat('&nbsp;',2).'$usedInSeveralExercises is untrue'."<br />\n";}
if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION)
{
if($debug>0){echo str_repeat('&nbsp;',4).'$answerType is UNIQUE_ANSWER or MULTIPLE_ANSWER'."<br />\n";}
?>
<h3>
<?php echo $questionName; ?>
</h3>

@ -29,16 +29,7 @@ require_once 'exercise.lib.php';
// debug var. Set to 0 to hide all debug display. Set to 1 to display debug messages.
$debug = 0;
/*
// answer types
define('UNIQUE_ANSWER', 1);
define('MULTIPLE_ANSWER', 2);
define('FILL_IN_BLANKS', 3);
define('MATCHING', 4);
define('FREE_ANSWER', 5);
define('HOT_SPOT', 6);
define('HOT_SPOT_ORDER', 7);
*/
// name of the language file that needs to be included
$language_file = 'exercice';
@ -417,7 +408,15 @@ if ($formSent) {
if ($studentChoice) {
$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;
} break;
}
break;
case MULTIPLE_ANSWER_COMBINATION:
$studentChoice=$choice[$numAnswer];
if ($studentChoice) {
$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;
}
break;
// for fill in the blanks
case FILL_IN_BLANKS :
@ -618,22 +617,27 @@ if ($formSent) {
if ($answerType == MULTIPLE_ANSWER) {
if ($choice != 0) {
$reply = array_keys($choice);
for ($i = 0; $i < sizeof($reply); $i++) {
$ans = $reply[$i];
exercise_attempt($questionScore, $ans, $quesId, $exeId, $i);
}
} else {
exercise_attempt($questionScore, 0, $quesId, $exeId, 0);
}
}
elseif ($answerType == MATCHING) {
} elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) {
if ($choice != 0) {
$reply = array_keys($choice);
for ($i = 0; $i < sizeof($reply); $i++) {
$ans = $reply[$i];
exercise_attempt($questionScore, $ans, $quesId, $exeId, $i);
}
} else {
exercise_attempt($questionScore, 0, $quesId, $exeId, 0);
}
} elseif ($answerType == MATCHING) {
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);

@ -498,7 +498,7 @@ foreach ($questionList as $questionId) {
unset($objQuestionTmp);
// decide how many columns we want to use to show the results of each type
if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION) {
$colspan=4;
} elseif($answerType == MATCHING || $answerType == FREE_ANSWER) {
$colspan=2;
@ -522,7 +522,7 @@ foreach ($questionList as $questionId) {
</td>
</tr>
<?php
if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION ) {
?>
<tr>
<td width="5%" valign="top" align="center" nowrap="nowrap">
@ -618,7 +618,8 @@ foreach ($questionList as $questionId) {
while ($real_answer = Database::fetch_array($res_answer)) {
$answer_matching[$real_answer['id']]= $real_answer['answer'];
}
$real_answers = array();
// We're inside *one* question. Go through each possible answer for this question
for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
@ -644,12 +645,29 @@ foreach ($questionList as $questionId) {
break;
// for multiple answers
case MULTIPLE_ANSWER :
$studentChoice=$choice[$numAnswer];
if($studentChoice) {
$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;
$studentChoice=$choice[$numAnswer];
if($studentChoice) {
$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;
}
break;
case MULTIPLE_ANSWER_COMBINATION :
$studentChoice=$choice[$numAnswer];
if ($answerCorrect == 1) {
if ($studentChoice) {
$real_answers[$answerId] = true;
} else {
$real_answers[$answerId] = false;
}
break;
} else {
if ($studentChoice) {
$real_answers[$answerId] = false;
} else {
$real_answers[$answerId] = true;
}
}
break;
// for fill in the blanks
case FILL_IN_BLANKS :
// the question is encoded like this
@ -810,8 +828,6 @@ foreach ($questionList as $questionId) {
$questionScore=-1;
$totalScore+=0;
}
break;
// for matching
case MATCHING :
@ -854,7 +870,7 @@ foreach ($questionList as $questionId) {
//display answers (if not matching type, or if the answer is correct)
if ($answerType != MATCHING || $answerCorrect) {
if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION) {
if ($origin!='learnpath') {
display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect);
}
@ -894,6 +910,22 @@ foreach ($questionList as $questionId) {
}
}
} // end for that loops over all answers of the current question
//
if ($answerType == MULTIPLE_ANSWER_COMBINATION) {
$final_answer = true;
foreach($real_answers as $my_answer) {
if (!$my_answer) {
$final_answer = false;
}
}
if ($final_answer) {
//getting only the first score where we save the weight of all the question
$answerWeighting=$objAnswerTmp->selectWeighting(1);
$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;
}
}
// if answer is hotspot. To the difference of exercise_show.php, we use the results from the session (from_db=0)
// TODO Change this, because it is wrong to show the user some results that haven't been stored in the database yet
@ -952,6 +984,16 @@ foreach ($questionList as $questionId) {
} else {
exercise_attempt($questionScore, 0 ,$quesId,$exeId,0);
}
} elseif ($answerType==MULTIPLE_ANSWER_COMBINATION ) {
if ($choice != 0) {
$reply = array_keys($choice);
for ($i=0;$i<sizeof($reply);$i++) {
$ans = $reply[$i];
exercise_attempt($questionScore,$ans,$quesId,$exeId,$i);
}
} else {
exercise_attempt($questionScore, 0 ,$quesId,$exeId,0);
}
} elseif ($answerType==MATCHING) {
foreach ($matching as $j => $val) {
exercise_attempt($questionScore, $val, $quesId, $exeId, $j);

@ -673,7 +673,7 @@ if ($show_results) {
$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$questionScore=0;
$real_answer = true;
$real_answers = array();
for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
$answer=$objAnswerTmp->selectAnswer($answerId);
@ -686,17 +686,23 @@ if ($show_results) {
$ind = $row['answer'];
$choice[$ind] = 1;
}
$numAnswer=$objAnswerTmp->selectAutoId($answerId);
$studentChoice=$choice[$numAnswer];
var_dump($studentChoice);
if (!$studentChoice) {
$real_answer = false;
/*$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;*/
$numAnswer=$objAnswerTmp->selectAutoId($answerId);
$studentChoice=$choice[$numAnswer];
if ($answerCorrect == 1) {
if ($studentChoice) {
$real_answers[$answerId] = true;
} else {
$real_answers[$answerId] = false;
}
} else {
if ($studentChoice) {
$real_answers[$answerId] = false;
} else {
$real_answers[$answerId] = true;
}
}
echo '<tr><td>';
if ($answerId==1) {
display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
@ -706,12 +712,19 @@ if ($show_results) {
echo '</td></tr>';
$i++;
}
var_dump($real_answer);
if ($real_answer) {
$final_answer = true;
foreach($real_answers as $my_answer) {
if (!$my_answer) {
$final_answer = false;
}
}
if ($final_answer) {
//getting only the first score where we save the weight of all the question
$answerWeighting=$objAnswerTmp->selectWeighting(1);
$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;
}
}
echo '</table>';

@ -25,6 +25,7 @@ require_once(api_get_path(SYS_CODE_PATH).'/exercice/answer.class.php');
require_once(api_get_path(SYS_CODE_PATH).'/exercice/hotspot.class.php');
require_once(api_get_path(SYS_CODE_PATH).'/exercice/unique_answer.class.php');
require_once(api_get_path(SYS_CODE_PATH).'/exercice/multiple_answer.class.php');
//require_once(api_get_path(SYS_CODE_PATH).'/exercice/multiple_answer_combination.class.php');
require_once(api_get_path(SYS_CODE_PATH).'/exercice/matching.class.php');
require_once(api_get_path(SYS_CODE_PATH).'/exercice/freeanswer.class.php');
require_once(api_get_path(SYS_CODE_PATH).'/exercice/fill_blanks.class.php');

@ -14,6 +14,7 @@ require_once(api_get_path(SYS_CODE_PATH).'exercice/question.class.php');
require_once(api_get_path(SYS_CODE_PATH).'exercice/answer.class.php');
require_once(api_get_path(SYS_CODE_PATH).'exercice/unique_answer.class.php');
require_once(api_get_path(SYS_CODE_PATH).'exercice/multiple_answer.class.php');
require_once(api_get_path(SYS_CODE_PATH).'exercice/multiple_answer_combination.class.php');
require_once(api_get_path(SYS_CODE_PATH).'exercice/fill_blanks.class.php');
require_once(api_get_path(SYS_CODE_PATH).'exercice/freeanswer.class.php');
require_once(api_get_path(SYS_CODE_PATH).'exercice/hotspot.class.php');
@ -32,6 +33,11 @@ define('MATCHING', 4);
define('FREE_ANSWER', 5);
define('HOTSPOT', 6);
define('HOT_SPOT_ORDER', 7);
define('HOT_SPOT_DELINEATION', 8);
define('MULTIPLE_ANSWER_COMBINATION', 9);
/**
* The ScormQuestion class is a gateway to getting the answers exported
* (the question is just an HTML text, while the answers are the most important).

Loading…
Cancel
Save