[svn r15719] "Multiple answers" in fill in blank option added (see FS#2683)

skala
Julio Montoya 18 years ago
parent 6869273fdd
commit 77b9d1542e
  1. 41
      main/exercice/exercice_submit.php
  2. 27
      main/exercice/exercise_result.class.php
  3. 211
      main/exercice/exercise_result.php
  4. 192
      main/exercice/exercise_show.php
  5. 76
      main/exercice/fill_blanks.class.php

@ -1,20 +1,23 @@
<?php <?php
/* /*
DOKEOS - elearning and course management software ==============================================================================
Dokeos - elearning and course management software
For a full list of contributors, see documentation/credits.html Copyright (c) 2008 Dokeos SPRL
This program is free software; you can redistribute it and/or For a full list of contributors, see "credits.txt".
modify it under the terms of the GNU General Public License The full license can be read in "license.txt".
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
Contact: This program is free software; you can redistribute it and/or
Dokeos modify it under the terms of the GNU General Public License
Rue du Corbeau, 108 as published by the Free Software Foundation; either version 2
B-1030 Brussels - Belgium of the License, or (at your option) any later version.
info@dokeos.com
See the GNU General Public License for more details.
Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
Mail: info@dokeos.com
==============================================================================
*/ */
/** /**
* Exercise submission * Exercise submission
@ -33,7 +36,8 @@
* the administrator * the administrator
* @package dokeos.exercise * @package dokeos.exercise
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @version $Id: exercice_submit.php 15412 2008-05-26 13:56:24Z elixir_inter $ * @author Julio Montoya multiple fill in blank option added
* @version $Id: exercice_submit.php 15719 2008-07-04 00:50:44Z juliomontoya $
*/ */
@ -124,7 +128,8 @@ if($buttonCancel)
exit(); exit();
} }
if ($origin=='builder') { if ($origin=='builder')
{
/*******************************/ /*******************************/
/* Clears the exercise session */ /* Clears the exercise session */
/*******************************/ /*******************************/
@ -150,7 +155,7 @@ if($formSent)
// if the user has answered at least one question // if the user has answered at least one question
if(is_array($choice)) if(is_array($choice))
{ {
if($debug>0){echo str_repeat('&nbsp;',0).'$choice is an array'."<br />\n";} if($debug>0){echo str_repeat('&nbsp;',0).'$choice is an array'."<br />\n";}
if($exerciseType == 1) if($exerciseType == 1)
@ -190,7 +195,7 @@ if($formSent)
// if it is the last question (only for a sequential exercise) // if it is the last question (only for a sequential exercise)
if($exerciseType == 1 || $questionNum >= $nbrQuestions) if($exerciseType == 1 || $questionNum >= $nbrQuestions)
{ {
if($debug>0){echo str_repeat('&nbsp;',0).'Redirecting to exercise_result.php - Remove debug option to let this happen'."<br />\n";} if($debug>0){echo str_repeat('&nbsp;',0).'Redirecting to exercise_result.php - Remove debug option to let this happen'."<br />\n";}
// goes to the script that will show the result of the exercise // goes to the script that will show the result of the exercise
header("Location: exercise_result.php?origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id"); header("Location: exercise_result.php?origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
@ -206,7 +211,7 @@ if(!isset($_SESSION['objExercise']) || $origin == 'learnpath' || $_SESSION['objE
// construction of Exercise // construction of Exercise
$objExercise=new Exercise(); $objExercise=new Exercise();
unset($_SESSION['questionList']); unset($_SESSION['questionList']);
// if the specified exercise doesn't exist or is disabled // if the specified exercise doesn't exist or is disabled
if(!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() && !$is_allowedToEdit && ($origin != 'learnpath') )) if(!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() && !$is_allowedToEdit && ($origin != 'learnpath') ))
{ {
@ -444,7 +449,7 @@ else
$number_of_hotspot_questions = 0; $number_of_hotspot_questions = 0;
$onsubmit = ''; $onsubmit = '';
$i=0; $i=0;
foreach($questionList as $questionId) foreach($questionList as $questionId)
{ {
$i++; $i++;

@ -1,20 +1,23 @@
<?php <?php
/* /*
DOKEOS - elearning and course management software ==============================================================================
Dokeos - elearning and course management software
For a full list of contributors, see documentation/credits.html Copyright (c) 2004-2008 Dokeos SPRL
This program is free software; you can redistribute it and/or For a full list of contributors, see "credits.txt".
modify it under the terms of the GNU General Public License The full license can be read in "license.txt".
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
Contact: This program is free software; you can redistribute it and/or
Dokeos modify it under the terms of the GNU General Public License
Rue du Corbeau, 108 as published by the Free Software Foundation; either version 2
B-1030 Brussels - Belgium of the License, or (at your option) any later version.
info@dokeos.com
See the GNU General Public License for more details.
Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
Mail: info@dokeos.com
==============================================================================
*/ */
/** /**
* ExerciseResult class: This class allows to instantiate an object of type ExerciseResult * ExerciseResult class: This class allows to instantiate an object of type ExerciseResult

@ -1,20 +1,23 @@
<?php <?php
/* /*
DOKEOS - elearning and course management software ==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2008 Dokeos SPRL
For a full list of contributors, see documentation/credits.html For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
Contact: See the GNU General Public License for more details.
Dokeos
Rue du Corbeau, 108 Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
B-1030 Brussels - Belgium Mail: info@dokeos.com
info@dokeos.com ==============================================================================
*/ */
/** /**
* Exercise result * Exercise result
@ -25,7 +28,8 @@
* @package dokeos.exercise * @package dokeos.exercise
* @author Olivier Brouckaert, main author * @author Olivier Brouckaert, main author
* @author Roan Embrechts, some refactoring * @author Roan Embrechts, some refactoring
* @version $Id: exercise_result.php 15602 2008-06-18 08:52:24Z pcool $ * @author Julio Montoya multiple fill in blank option added
* @version $Id: exercise_result.php 15719 2008-07-04 00:50:44Z juliomontoya $
* *
* @todo split more code up in functions, move functions to library? * @todo split more code up in functions, move functions to library?
*/ */
@ -486,10 +490,25 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
break; break;
// for fill in the blanks // for fill in the blanks
case FILL_IN_BLANKS : // splits text and weightings that are joined with the character '::' case FILL_IN_BLANKS :
list($answer,$answerWeighting)=explode('::',$answer); // the question is encoded like this
// [A] B [C] D [E] F::10,10,10@1
// number 1 before the "@" means that is a multiple fill in blank question
// [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
// means that is a normal fill blank question
$multiple_answer_array =explode('@',$answer);
// is multiple fill blank or not
$multiple_answer_set=false;
if ($multiple_answer_array[1]==1)
{
$multiple_answer_set=true;
}
// splits text and weightings that are joined with the character '::'
list($answer,$answerWeighting)=explode('::',$multiple_answer_array[0]);
// splits weightings that are joined with a comma // splits weightings that are joined with a comma
$answerWeighting=explode(',',$answerWeighting); $answerWeighting=explode(',',$answerWeighting);
@ -499,66 +518,183 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
// TeX parsing // TeX parsing
// 1. find everything between the [tex] and [/tex] tags // 1. find everything between the [tex] and [/tex] tags
$startlocations=strpos($temp,'[tex]'); $startlocations=strpos($temp,'[tex]');
$endlocations=strpos($temp,'[/tex]'); $endlocations=strpos($temp,'[/tex]');
if($startlocations !== false && $endlocations !== false) if($startlocations !== false && $endlocations !== false)
{ {
$texstring=substr($temp,$startlocations,$endlocations-$startlocations+6); $texstring=substr($temp,$startlocations,$endlocations-$startlocations+6);
// 2. replace this by {texcode} // 2. replace this by {texcode}
$temp=str_replace($texstring,'{texcode}',$temp); $temp=str_replace($texstring,'{texcode}',$temp);
} }
$answer=''; $answer='';
$j=0; $j=0;
$user_tags[]=array();
$correct_tags[]=array();
$real_text=array();
// the loop will stop at the end of the text // the loop will stop at the end of the text
while(1) while(1)
{ {
// quits the loop if there are no more blanks // quits the loop if there are no more blanks
if(($pos = strpos($temp,'[')) === false) if(($pos = strpos($temp,'[')) === false)
{ {
// adds the end of the text // adds the end of the text
$answer.=$temp; $answer.=$temp;
// TeX parsing // TeX parsing
$texstring = api_parse_tex($texstring); $texstring = api_parse_tex($texstring);
$answer=str_replace("{texcode}",$texstring,$answer); $answer=str_replace("{texcode}",$texstring,$answer);
break; break;
} }
// adds the piece of text that is before the blank and ended by [ // adds the piece of text that is before the blank and ended by [
$real_text[]=substr($temp,0,$pos+1);
$answer.=substr($temp,0,$pos+1); $answer.=substr($temp,0,$pos+1);
$temp=substr($temp,$pos+1); $temp=substr($temp,$pos+1);
// quits the loop if there are no more blanks // quits the loop if there are no more blanks
if(($pos = strpos($temp,']')) === false) if(($pos = strpos($temp,']')) === false)
{ {
// adds the end of the text // adds the end of the text
$answer.=$temp; $answer.=$temp;
break; break;
} }
$choice[$j]=trim($choice[$j]); $choice[$j]=trim($choice[$j]);
$user_tags[]=stripslashes(strtolower($choice[$j]));
// if the word entered by the student IS the same as the one defined by the professor $correct_tags[]=strtolower(substr($temp,0,$pos));
if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j]))) $j++;
$temp=substr($temp,$pos+1);
}
/*
echo $answer;
echo "<pre>";
print_r($user_tags);
echo "<br>";
print_r($correct_tags);
print_r($real_text);
echo "</pre>";
*/
$answer='';
$real_correct_tags = $correct_tags;
$chosen_list=array();
for($i=1;$i<count($real_correct_tags);$i++)
{
if ($i==1)
{
$answer.=$real_text[0];
}
if (!$multiple_answer_set)
{
if ($correct_tags[$i]==$user_tags[$i])
{
// gives the related weighting to the student
$questionScore+=$answerWeighting[$i-1];
// increments total score
$totalScore+=$answerWeighting[$i-1];
// adds the word in green at the end of the string
$answer.=stripslashes($correct_tags[$i]);
}
// else if the word entered by the student IS NOT the same as the one defined by the professor
elseif(!empty($user_tags[$i]))
{
// adds the word in red at the end of the string, and strikes it
$answer.='<font color="red"><s>'.stripslashes($user_tags[$i]).'</s></font>';
}
else
{
// adds a tabulation if no word has been typed by the student
$answer.='&nbsp;&nbsp;&nbsp;';
}
}
else
{ // multiple fill in blank magic
if (in_array($user_tags[$i],$correct_tags))
{
$chosen_list[]=$user_tags[$i];
$correct_tags=array_diff($correct_tags,$chosen_list);
// gives the related weighting to the student
$questionScore+=$answerWeighting[$i-1];
// increments total score
$totalScore+=$answerWeighting[$i-1];
// adds the word in green at the end of the string
$answer.=stripslashes($user_tags[$i]);
} // else if the word entered by the student IS NOT the same as the one defined by the professor
elseif(!empty($user_tags[$i]))
{
// adds the word in red at the end of the string, and strikes it
$answer.='<font color="red"><s>'.stripslashes($user_tags[$i]).'</s></font>';
}
else
{
// adds a tabulation if no word has been typed by the student
$answer.='&nbsp;&nbsp;&nbsp;';
}
}
// adds the correct word, followed by ] to close the blank
$answer.=' / <font color="green"><b>'.$real_correct_tags[$i].'</b></font>]';
$answer.=$real_text[$i];
}
/*
$answer='';
// the loop will stop at the end of the text
while(1)
{
// quits the loop if there are no more blanks
if(($pos = strpos($temp,'[')) === false)
{ {
// gives the related weighting to the student // adds the end of the text
$questionScore+=$answerWeighting[$j]; $answer.=$temp;
// TeX parsing
$texstring = api_parse_tex($texstring);
$answer=str_replace("{texcode}",$texstring,$answer);
break;
}
// increments total score // adds the piece of text that is before the blank and ended by [
$totalScore+=$answerWeighting[$j]; $answer.=substr($temp,0,$pos+1);
$temp=substr($temp,$pos+1);
// adds the word in green at the end of the string // quits the loop if there are no more blanks
$answer.=stripslashes($choice[$j]); if(($pos = strpos($temp,']')) === false)
{
// adds the end of the text
$answer.=$temp;
break;
} }
// else if the word entered by the student IS NOT the same as the one defined by the professor
elseif(!empty($choice[$j])) $choice[$j]=trim($choice[$j]);
if (!$multiple_answer_set)
{
// if the word entered by the student IS the same as the one defined by the professor
if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j])))
{
// gives the related weighting to the student
$questionScore+=$answerWeighting[$j];
// increments total score
$totalScore+=$answerWeighting[$j];
// adds the word in green at the end of the string
$answer.=stripslashes($choice[$j]);
}
}
else
{
}
// else if the word entered by the student IS NOT the same as the one defined by the professor
if(!empty($choice[$j]))
{ {
// adds the word in red at the end of the string, and strikes it // adds the word in red at the end of the string, and strikes it
$answer.='<font color="red"><s>'.stripslashes($choice[$j]).'</s></font>'; $answer.='<font color="red"><s>'.stripslashes($choice[$j]).'</s></font>';
@ -576,6 +712,7 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
$temp=substr($temp,$pos+1); $temp=substr($temp,$pos+1);
} }
*/
break; break;
// for free answer // for free answer

@ -1,27 +1,30 @@
<?php <?php
/* /*
DOKEOS - elearning and course management software ==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2004-2008 Dokeos SPRL
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
For a full list of contributors, see documentation/credits.html This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is free software; you can redistribute it and/or See the GNU General Public License for more details.
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
Contact: Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
Dokeos Mail: info@dokeos.com
Rue des Palais 44 Paleizenstraat ==============================================================================
B-1030 Brussels - Belgium
Tel. +32 (2) 211 34 56
*/ */
/** /**
* *
* @package dokeos.exercise * @package dokeos.exercise
* @author * @author Julio Montoya multiple fill in blank option added
* @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $ * @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
* *
* @todo remove the debug code and use the general debug library * @todo remove the debug code and use the general debug library
@ -391,6 +394,7 @@ $result =api_sql_query($query, __FILE__, __LINE__);
$questionList[] = $row['question_id']; $questionList[] = $row['question_id'];
$exerciseResult[] = $row['answer']; $exerciseResult[] = $row['answer'];
} }
foreach($questionList as $questionId) foreach($questionList as $questionId)
{ {
$counter++; $counter++;
@ -405,7 +409,7 @@ $result =api_sql_query($query, __FILE__, __LINE__);
$quesId =$objQuestionTmp->selectId(); //added by priya saini $quesId =$objQuestionTmp->selectId(); //added by priya saini
// destruction of the Question object // destruction of the Question object
unset($objQuestionTmp); unset($objQuestionTmp);
@ -551,74 +555,162 @@ $result =api_sql_query($query, __FILE__, __LINE__);
$objAnswerTmp=new Answer($questionId); $objAnswerTmp=new Answer($questionId);
$nbrAnswers=$objAnswerTmp->selectNbrAnswers(); $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$questionScore=0; $questionScore=0;
for($answerId=1;$answerId <= $nbrAnswers;$answerId++) for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
{ {
$answer=$objAnswerTmp->selectAnswer($answerId); $answer=$objAnswerTmp->selectAnswer($answerId);
$answerComment=$objAnswerTmp->selectComment($answerId); $answerComment=$objAnswerTmp->selectComment($answerId);
$answerCorrect=$objAnswerTmp->isCorrect($answerId); $answerCorrect=$objAnswerTmp->isCorrect($answerId);
$answerWeighting=$objAnswerTmp->selectWeighting($answerId); $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
list($answer,$answerWeighting)=explode('::',$answer);
// the question is encoded like this
// [A] B [C] D [E] F::10,10,10@1
// number 1 before the "@" means that is a multiple fill in blank question
// [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
// means that is a normal fill blank question
$multiple=explode('@',$answer);
// is multiple fill blank or not
$multiple_answer_set=false;
if ($multiple[1]==1)
{
$multiple_answer_set=true;
}
list($answer,$answerWeighting)=explode('::',$multiple[0]);
// splits weightings that are joined with a comma // splits weightings that are joined with a comma
$answerWeighting=explode(',',$answerWeighting); $answerWeighting=explode(',',$answerWeighting);
// we save the answer because it will be modified // we save the answer because it will be modified
$temp=$answer; $temp=$answer;
// TeX parsing // TeX parsing
// 1. find everything between the [tex] and [/tex] tags // 1. find everything between the [tex] and [/tex] tags
$startlocations=strpos($temp,'[tex]'); $startlocations=strpos($temp,'[tex]');
$endlocations=strpos($temp,'[/tex]'); $endlocations=strpos($temp,'[/tex]');
if($startlocations !== false && $endlocations !== false) if($startlocations !== false && $endlocations !== false)
{ {
$texstring=substr($temp,$startlocations,$endlocations-$startlocations+6); $texstring=substr($temp,$startlocations,$endlocations-$startlocations+6);
// 2. replace this by {texcode} // 2. replace this by {texcode}
$temp=str_replace($texstring,'{texcode}',$temp); $temp=str_replace($texstring,'{texcode}',$temp);
} }
$j=0; $j=0;
// the loop will stop at the end of the text // the loop will stop at the end of the text
$i=0; $i=0;
while(1) //normal fill in blank
if (!$multiple_answer_set)
{
while(1)
{ {
// quits the loop if there are no more blanks // quits the loop if there are no more blanks
if(($pos = strpos($temp,'[')) === false) if(($pos = strpos($temp,'[')) === false)
{ {
// adds the end of the text // adds the end of the text
$answer.=$temp; $answer.=$temp;
// TeX parsing // TeX parsing
$texstring = api_parse_tex($texstring); $texstring = api_parse_tex($texstring);
break; break;
} }
$temp=substr($temp,$pos+1); $temp=substr($temp,$pos+1);
// quits the loop if there are no more blanks // quits the loop if there are no more blanks
if(($pos = strpos($temp,']')) === false) if(($pos = strpos($temp,']')) === false)
{ {
break; break;
} }
$queryfill = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
$resfill = api_sql_query($queryfill, __FILE__, __LINE__); $queryfill = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
$str=mysql_result($resfill,0,"answer"); $resfill = api_sql_query($queryfill, __FILE__, __LINE__);
preg_match_all ('#\[([^[/]*)/#', $str, $arr); $str=mysql_result($resfill,0,"answer");
$choice = $arr[1]; preg_match_all ('#\[([^[/]*)/#', $str, $arr);
$choice[$j]=trim($choice[$j]);
// if the word entered by the student IS the same as the one defined by the professor $choice = $arr[1];
if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j]))) $choice[$j]=trim($choice[$j]);
// if the word entered by the student IS the same as the one defined by the professor
if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j])))
{ {
// gives the related weighting to the student // gives the related weighting to the student
$questionScore+=$answerWeighting[$j]; $questionScore+=$answerWeighting[$j];
// increments total score // increments total score
$totalScore+=$answerWeighting[$j]; $totalScore+=$answerWeighting[$j];
} }
// else if the word entered by the student IS NOT the same as the one defined by the professor // else if the word entered by the student IS NOT the same as the one defined by the professor
$j++; $j++;
$temp=substr($temp,$pos+1); $temp=substr($temp,$pos+1);
$i=$i+1; $i=$i+1;
} $answer = $str; }
$answer = $str;
}
else
{ //multiple fill in blank
while(1)
{
// quits the loop if there are no more blanks
if(($pos = strpos($temp,'[')) === false)
{
// adds the end of the text
$answer.=$temp;
// TeX parsing
$texstring = api_parse_tex($texstring);
//$answer=str_replace("{texcode}",$texstring,$answer);
break;
}
// adds the piece of text that is before the blank and ended by [
$real_text[]=substr($temp,0,$pos+1);
$answer.=substr($temp,0,$pos+1);
$temp=substr($temp,$pos+1);
// quits the loop if there are no more blanks
if(($pos = strpos($temp,']')) === false)
{
// adds the end of the text
//$answer.=$temp;
break;
}
$queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
$resfill = api_sql_query($queryfill, __FILE__, __LINE__);
$str=mysql_result($resfill,0,"answer");
preg_match_all ('#\[([^[/]*)/#', $str, $arr);
$choice = $arr[1];
$choice[$j]=trim($choice[$j]);
$user_tags[]=stripslashes(strtolower($choice[$j]));
$correct_tags[]=strtolower(substr($temp,0,$pos));
$j++;
$temp=substr($temp,$pos+1);
$i=$i+1;
}
/*
echo "<pre>";
print_r($user_tags);
echo "<br>";
print_r($correct_tags);
print_r($answerWeighting);
echo "</pre>";
*/
$answer='';
for($i=0;$i<count($correct_tags);$i++)
{
if (in_array($user_tags[$i],$correct_tags))
{
// gives the related weighting to the student
$questionScore+=$answerWeighting[$i];
// increments total score
$totalScore+=$answerWeighting[$i];
}
}
$answer = $str;
}
//echo $questionScore."-".$totalScore;
?> ?>
<tr> <tr>
<td> <?php display_fill_in_blanks_answer($answer,$id,$questionId); ?> </td> <td> <?php display_fill_in_blanks_answer($answer,$id,$questionId); ?> </td>
</tr><?php </tr><?php
$i++; $i++;
}
?>
}?>
</table> </table>
<?php } <?php }
elseif($answerType == FREE_ANSWER) elseif($answerType == FREE_ANSWER)

@ -1,20 +1,23 @@
<?php <?php
/* /*
DOKEOS - elearning and course management software ==============================================================================
Dokeos - elearning and course management software
For a full list of contributors, see documentation/credits.html Copyright (c) 2004-2008 Dokeos SPRL
This program is free software; you can redistribute it and/or For a full list of contributors, see "credits.txt".
modify it under the terms of the GNU General Public License The full license can be read in "license.txt".
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
Contact: This program is free software; you can redistribute it and/or
Dokeos modify it under the terms of the GNU General Public License
Rue des Palais 44 Paleizenstraat as published by the Free Software Foundation; either version 2
B-1030 Brussels - Belgium of the License, or (at your option) any later version.
Tel. +32 (2) 211 34 56
See the GNU General Public License for more details.
Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
Mail: info@dokeos.com
==============================================================================
*/ */
@ -35,18 +38,20 @@ if(!class_exists('FillBlanks')):
* extending the class question * extending the class question
* *
* @author Eric Marguin * @author Eric Marguin
* @author Julio Montoya multiple fill in blank option added
* @package dokeos.exercise * @package dokeos.exercise
**/ **/
class FillBlanks extends Question { class FillBlanks extends Question
{
static $typePicture = 'fill_in_blanks.gif'; static $typePicture = 'fill_in_blanks.gif';
static $explanationLangVar = 'FillBlanks'; static $explanationLangVar = 'FillBlanks';
/** /**
* Constructor * Constructor
*/ */
function FillBlanks(){ function FillBlanks()
{
parent::question(); parent::question();
$this -> type = FILL_IN_BLANKS; $this -> type = FILL_IN_BLANKS;
} }
@ -55,21 +60,35 @@ class FillBlanks extends Question {
* function which redifines Question::createAnswersForm * function which redifines Question::createAnswersForm
* @param the formvalidator instance * @param the formvalidator instance
*/ */
function createAnswersForm ($form) { function createAnswersForm ($form)
{
$defaults = array(); $defaults = array();
if(!empty($this->id)) if(!empty($this->id))
{ {
$objAnswer = new answer($this->id); $objAnswer = new answer($this->id);
$a_answer = explode('::', $objAnswer->selectAnswer(1));
// the question is encoded like this
// [A] B [C] D [E] F::10,10,10@1
// number 1 before the "@" means that is a multiple fill in blank question
// [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
// means that is a normal fill blank question
$is_set_multiple = explode('@', $objAnswer->selectAnswer(1));
if ($is_set_multiple[1])
{
$defaults['multiple_answer']=1;
}
else
{
$defaults['multiple_answer']=0;
}
$a_answer = explode('::', $is_set_multiple[0]);
$defaults['answer'] = $a_answer[0]; $defaults['answer'] = $a_answer[0];
$a_weightings = explode(',',$a_answer[1]); $a_weightings = explode(',',$a_answer[1]);
} }
else else
{ {
$defaults['answer'] = get_lang('DefaultTextInBlanks'); $defaults['answer'] = get_lang('DefaultTextInBlanks');
} }
@ -103,7 +122,6 @@ class FillBlanks extends Question {
foreach($a_weightings as $i=>$weighting) foreach($a_weightings as $i=>$weighting)
{ {
echo 'document.getElementById("weighting['.$i.']").value = "'.$weighting.'";'; echo 'document.getElementById("weighting['.$i.']").value = "'.$weighting.'";';
} }
} }
echo '} echo '}
@ -118,10 +136,13 @@ class FillBlanks extends Question {
$form -> addElement ('textarea', 'answer',get_lang('Answer'),'id="answer" cols="65" rows="6" onkeyup="updateBlanks(this)"'); $form -> addElement ('textarea', 'answer',get_lang('Answer'),'id="answer" cols="65" rows="6" onkeyup="updateBlanks(this)"');
$form -> addRule ('answer',get_lang('GiveText'),'required'); $form -> addRule ('answer',get_lang('GiveText'),'required');
$form -> addRule ('answer',get_lang('DefineBlanks'),'regex','/\[.*\]/'); $form -> addRule ('answer',get_lang('DefineBlanks'),'regex','/\[.*\]/');
//added multiple answers
$form -> addElement ('checkbox','multiple_answer','', get_lang('FillInBlankMultiple'));
$form -> addElement('html','<div id="blanks_weighting"></div>'); $form -> addElement('html','<div id="blanks_weighting"></div>');
$form -> setDefaults($defaults); $form -> setDefaults($defaults);
} }
@ -140,9 +161,11 @@ class FillBlanks extends Question {
// get the blanks weightings // get the blanks weightings
$nb = preg_match_all('/\[[^\]]*\]/', $answer, $blanks); $nb = preg_match_all('/\[[^\]]*\]/', $answer, $blanks);
if(isset($_GET['editQuestion'])){ if(isset($_GET['editQuestion']))
{
$this -> weighting = 0; $this -> weighting = 0;
} }
if($nb>0) if($nb>0)
{ {
$answer .= '::'; $answer .= '::';
@ -153,6 +176,9 @@ class FillBlanks extends Question {
} }
$answer = substr($answer,0,-1); $answer = substr($answer,0,-1);
} }
$is_multiple = $form -> getSubmitValue('multiple_answer');
$answer.='@'.$is_multiple;
$this -> save(); $this -> save();
$objAnswer = new answer($this->id); $objAnswer = new answer($this->id);
$objAnswer->createAnswer($answer,0,'',0,''); $objAnswer->createAnswer($answer,0,'',0,'');

Loading…
Cancel
Save