Adding new question types see BT#1913, BT#1913, BT#1914, BT#1915

skala
Julio Montoya 14 years ago
parent 1e938ab086
commit 05cce79c19
  1. 20
      main/exercice/admin.php
  2. 12
      main/exercice/exercice.php
  3. 10
      main/exercice/exercise.class.php
  4. 57
      main/exercice/exercise.lib.php
  5. 2
      main/exercice/exercise_show.php
  6. 13
      main/exercice/multiple_answer_combination.class.php
  7. 219
      main/exercice/multiple_answer_true_false.class.php
  8. 35
      main/exercice/question.class.php
  9. 437
      main/exercice/unique_answer_no_option.class.php

@ -290,6 +290,24 @@ $htmlHeadXtra[] = '<link rel="stylesheet" href="'.api_get_path(WEB_LIBRARY_PATH)
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-1.4.4.min.js" type="text/javascript" language="javascript"></script>'; //jQuery
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/cupertino/jquery-ui-1.8.7.custom.min.js" type="text/javascript" language="javascript"></script>'; //jQuery
$htmlHeadXtra[] = '<script type="text/javascript">
function multiple_answer_true_false_onchange(variable) {
var result = variable.value;
var id = variable.id;
var weight_id = "weighting_" + id;
var array_result=new Array(); array_result[1]="1"; array_result[0]= "-0.50"; array_result[-1]= "0";
document.getElementById(weight_id).value = array_result[result];
}
</script>';
$htmlHeadXtra[] = "<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
<script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
<script language=\"JavaScript\" type=\"text/javascript\">
@ -448,7 +466,7 @@ if ($newQuestion || $editQuestion) {
$type = $_REQUEST['answerType'];
?><input type="hidden" name="Type" value="<?php echo $type; ?>" />
<?php
require 'question_admin.inc.php';
require 'question_admin.inc.php';
}
if(isset($_GET['hotspotadmin'])) {

@ -707,10 +707,12 @@ if ($show == 'test') {
/* Vertical Tabs */
.ui-tabs-vertical { width: 99%; }
.ui-tabs-vertical .ui-tabs-nav { padding: .2em .1em .2em .2em; float: left; width: 20%; }
.ui-tabs-vertical .ui-tabs-nav li { clear: left; width: 100%; border-bottom-width: 1px !important; border-right-width: 0 !important; margin: 0 -1px .2em 0; }
.ui-tabs-vertical .ui-tabs-nav li { clear: left; width: 100%; border-bottom-width: 1px !important; border-right-width: 0 !important; margin: 0 -1px .2em 0; white-space:normal;}
.ui-tabs-vertical .ui-tabs-nav li a { display:block; width:100%; }
.ui-tabs-vertical .ui-tabs-nav li.ui-tabs-selected { padding-bottom: 0; padding-right: .1em; border-right-width: 1px; border-right-width: 1px; }
.ui-tabs-vertical .ui-tabs-panel { padding: 1em; float: left; width: 40em;}
</style>
@ -799,7 +801,8 @@ if ($show == 'test') {
if ($session_id == $row['session_id']) {
//Settings
//echo Display::tag('a', Display::return_icon('settings.png', get_lang('Edit')), array('href'=>'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']));
echo Display::tag('a', Display::return_icon('settings.png',get_lang('Edit'), array('width'=>'22px'))." ".get_lang('Edit'), array('href'=>'exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$row['id']));
//Export
echo Display::tag('a', Display::return_icon('cd.gif', get_lang('CopyExercise')), array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToCopy'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id']));
//Clean exercise
@ -825,8 +828,9 @@ if ($show == 'test') {
echo '<br />'.get_count_exam_results($row['id']).' '.get_lang('Attempts');
//Special buttons
echo '<div class="operations">';
echo Display::tag('a', Display::return_icon('settings.png',get_lang('EditQuestions'), array('width'=>'22px'))." ".get_lang('Edit'), array('href'=>'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']));
echo '<div class="operations">';
echo Display::tag('a', Display::return_icon('quiz.gif',get_lang('Questions'), array('width'=>'22px'))." ".get_lang('Questions'), array('href'=>'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']));
echo ' ';
echo Display::tag('a', Display::return_icon('preview.gif',get_lang('Preview'), array('width'=>'22px'))." ".get_lang('Preview'), array('href'=>'exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id']));
echo ' ';

@ -1719,7 +1719,8 @@ class Exercise {
}
break;
// for multiple answers
case MULTIPLE_ANSWER :
case MULTIPLE_ANSWER_TRUE_FALSE :
case MULTIPLE_ANSWER_ :
if ($from_database) {
$choice=array();
$queryans = "SELECT * FROM ".$TBL_TRACK_ATTEMPT." where exe_id = '".$exeId."' and question_id= '".$questionId."'";
@ -2082,7 +2083,7 @@ class Exercise {
if ($from == 'exercise_result') {
//display answers (if not matching type, or if the answer is correct)
if ($answerType != MATCHING || $answerCorrect) {
if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION) {
if (in_array($answerType, array(UNIQUE_ANSWER, MULTIPLE_ANSWER, MULTIPLE_ANSWER_COMBINATION, MULTIPLE_ANSWER_TRUE_FALSE))) {
if ($origin!='learnpath') {
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,0,0);
}
@ -2114,7 +2115,8 @@ class Exercise {
} else {
switch($answerType) {
case UNIQUE_ANSWER :
case MULTIPLE_ANSWER :
case MULTIPLE_ANSWER :
case MULTIPLE_ANSWER_TRUE_FALSE :
case MULTIPLE_ANSWER_COMBINATION :
if ($answerId==1) {
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId);
@ -2227,7 +2229,7 @@ class Exercise {
if (empty ($choice)) {
$choice = 0;
}
if ($answerType == MULTIPLE_ANSWER) {
if ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
if ($choice != 0) {
$reply = array_keys($choice);
for ($i = 0; $i < sizeof($reply); $i++) {

@ -35,9 +35,6 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
return false;
}
$answerType = $objQuestionTmp->selectType();
$pictureName = $objQuestionTmp->selectPicture();
@ -160,11 +157,15 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
}
.question_item {
height:50px;
height:50px;
padding:5px;
margin:10px 0px 10px 0px;
}
.option_item {
width:150px;
width:150px;
padding:3px;
margin:10px;
}
@ -189,7 +190,7 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
hoverClass: "ui-state-active",
drop: function( event, ui ) {
$( this ).addClass( "ui-state-highlight" );
//$( this ).addClass( "ui-state-highlight" );
}
});
@ -200,7 +201,7 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
accept: "#options div",
hoverClass: "ui-state-active",
drop: function( event, ui ) {
$( this ).addClass( "ui-state-highlight" );
//$( this ).addClass( "ui-state-highlight" );
}
});
@ -235,7 +236,7 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
}
// Unique answer
if ($answerType == UNIQUE_ANSWER) {
if ($answerType == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) {
// set $debug_mark_answer to true at function start to
// show the correct answer with a suffix '-x'
$help = $selected = '';
@ -254,7 +255,8 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
$answer.
'</div></div></td></tr>';
} elseif ($answerType == MULTIPLE_ANSWER) {
} elseif ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
// multiple answers
// set $debug_mark_answer to true at function start to
// show the correct answer with a suffix '-x'
@ -265,6 +267,7 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
$selected = 'checked="checked"';
}
}
$answer = text_filter($answer);
$answer = Security::remove_XSS($answer, STUDENT);
$s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />'.
@ -357,24 +360,26 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
}
} // end for()
//Adding divs for the new MATCHING interface
echo '<div id="questions">';
echo Display::tag('h2','Questions');
$i = 1;
foreach ($question_list as $key=>$val) {
echo Display::tag('div', Display::tag('p',$val), array('id'=>'question_'.$i, 'class'=>'question_item ui-widget-header'));
$i++;
}
echo '</div>';
echo Display::tag('h2','Options');
echo '<div id="options" class=" ui-widget-header">';
foreach ($select_items as $key=>$val) {
echo Display::tag('div', Display::tag('p',$val['answer']), array('id'=>'option_'.$i, 'class'=>'option_item ui-widget-content'));
if ($answerType == MATCHING && !$freeze) {
echo '<div id="questions">';
echo Display::tag('h2','Questions');
$i = 1;
foreach ($question_list as $key=>$val) {
echo Display::tag('div', Display::tag('p',$val), array('id'=>'question_'.$i, 'class'=>'question_item ui-widget-header'));
$i++;
}
echo '</div>';
echo Display::tag('h2','Options');
echo '<div id="options" class=" ui-widget-header">';
foreach ($select_items as $key=>$val) {
echo Display::tag('div', Display::tag('p',$val['answer']), array('id'=>'option_'.$i, 'class'=>'option_item ui-widget-content'));
}
echo '</ul>';
}
echo '</ul>';
$s .= '</table>';
@ -766,7 +771,7 @@ function get_count_exam_results($exercise_id = null) {
*/
function get_exam_results_data($from, $number_of_items, $column, $direction) {
global $is_allowedToEdit, $is_tutor,$_cid,$_user,$TBL_USER, $TBL_EXERCICES,$TBL_TRACK_EXERCICES, $TBL_TRACK_ATTEMPT_RECORDING,$filter_by_not_revised,$filter_by_revised,$documentPath;
global $is_allowedToEdit, $is_tutor,$_cid,$_user,$TBL_USER, $TBL_EXERCICES,$TBL_TRACK_EXERCICES, $TBL_TRACK_ATTEMPT_RECORDING,$filter_by_not_revised,$filter_by_revised,$documentPath,$filter;
$session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
if ($is_allowedToEdit || $is_tutor) {
$user_id_and = '';

@ -345,7 +345,7 @@ if ($show_results) {
echo $questionDescription;
echo '</div>';
if ($answerType == MULTIPLE_ANSWER) {
if ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
?>
<table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>

@ -116,7 +116,10 @@ class MultipleAnswerCombination extends Question {
$answer_number=$form->addElement('text', null,null,'value="'.$i.'"');
$answer_number->freeze();
$form->addElement('checkbox', 'correct['.$i.']', null, null, 'class="checkbox" style="margin-left: 0em;"');
//$form->addElement('checkbox', 'correct['.$i.']', null, null, 'class="checkbox" style="margin-left: 0em;"');
$options = array('1'=>get_lang('True'),'0' =>get_lang('False'), '2' =>get_lang('Nothing'));
$form->addElement('select', 'correct['.$i.']',null, $options);
$boxes_names[] = 'correct['.$i.']';
$form->addElement('html_editor', 'answer['.$i.']',null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
@ -151,15 +154,11 @@ class MultipleAnswerCombination extends Question {
$form->addElement('submit','submitQuestion',$text, 'class="'.$class.'"');
$form->addElement('submit', 'moreAnswers', get_lang('PlusAnswer'),'class="plus"');
$form->addElement('submit', 'lessAnswers', get_lang('LessAnswer'),'class="minus"');
} else {
$form->addElement('style_submit_button','submitQuestion',$text, 'class="'.$class.'"');
$form->addElement('style_submit_button', 'lessAnswers', get_lang('LessAnswer'),'style="float:right"; class="minus"');
$form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'),'style="float:right"; class="plus"');
// setting the save button here and not in the question class.php
$form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'),'style="float:right"; class="plus"');
// setting the save button here and not in the question class.php
}
}
$renderer->setElementTemplate('{element}&nbsp;','lessAnswers');

@ -0,0 +1,219 @@
<?php
/* For licensing terms, see /license.txt */
/**
* File containing the MultipleAnswer class.
* @package dokeos.exercise
* @author Eric Marguin
*/
if(!class_exists('MultipleAnswerTrueFalse')):
/**
CLASS MultipleAnswer
*
* This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER),
* extending the class question
*
* @author Eric Marguin
* @package dokeos.exercise
**/
class MultipleAnswerTrueFalse extends Question {
static $typePicture = 'mcma.gif';
static $explanationLangVar = 'MultipleAnswerTrueFalseSelect';
/**
* Constructor
*/
function MultipleAnswerTrueFalse(){
parent::question();
$this -> type = MULTIPLE_ANSWER_TRUE_FALSE;
$this -> isContent = $this-> getIsContent();
}
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
* @param the answers number to display
*/
function createAnswersForm ($form) {
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4; // The previous default value was 2. See task #1759.
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0));
$obj_ex = $_SESSION['objExercise'];
$html='
<div class="row">
<div class="label">
'.get_lang('Answers').'<br /><img src="../img/fill_field.png">
</div>
<div class="formw">
<table class="data_table">
<tr style="text-align: center;">
<th>
'.get_lang('Number').'
</th>
<th>
'.get_lang('True').'
</th>
<th>
'.get_lang('Answer').'
</th>';
// show column comment when feedback is enable
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM ) {
$html .='<th>
'.get_lang('Comment').'
</th>';
}
$html .= '<th>
'.get_lang('Weighting').'
</th>
</tr>';
$form -> addElement ('html', $html);
$defaults = array();
$correct = 0;
if(!empty($this -> id)) {
$answer = new Answer($this -> id);
$answer -> read();
if(count($answer->nbrAnswers)>0 && !$form->isSubmitted()) {
$nb_answers = $answer->nbrAnswers;
}
}
$form -> addElement('hidden', 'nb_answers');
$boxes_names = array();
if ($nb_answers < 1) {
$nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for($i = 1 ; $i <= $nb_answers ; ++$i) {
if(is_object($answer)) {
$defaults['answer['.$i.']'] = $answer -> answer[$i];
$defaults['comment['.$i.']'] = $answer -> comment[$i];
$defaults['weighting['.$i.']'] = float_format($answer -> weighting[$i], 1);
$defaults['correct['.$i.']'] = $answer -> correct[$i];
} else {
$defaults['answer['.$i.']'] = '';
$defaults['comment['.$i.']'] = '';
$defaults['weighting['.$i.']'] = '1';
$defaults['correct['.$i.']'] = '';
}
$renderer = & $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>');
$answer_number=$form->addElement('text', null,null,'value="'.$i.'"');
$answer_number->freeze();
//$form->addElement('checkbox', 'correct['.$i.']', null, null, 'class="checkbox" style="margin-left: 0em;"');
$options = array('1'=>get_lang('True'),'0' =>get_lang('False'), '2' =>get_lang('Nothing'));
$form->addElement('select', 'correct['.$i.']',null, $options, array('id'=>$i,'onchange'=>'multiple_answer_true_false_onchange(this)'));
//$boxes_names[] = 'correct['.$i.']';
$form->addElement('html_editor', 'answer['.$i.']',null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
// show comment when feedback is enable
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
$form->addElement('html_editor', 'comment['.$i.']',null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
}
$form->addElement('text', 'weighting['.$i.']',null, array('id'=>'weighting_'.$i,'style'=>'vertical-align:middle;margin-left: 0em', 'size'=>"5",'value'=>"0"));
$form -> addElement ('html', '</tr>');
}
$form -> addElement ('html', '</table>');
$form -> addElement ('html', '<br />');
$form -> add_multiple_required_rule ($boxes_names , get_lang('ChooseAtLeastOneCheckbox') , 'multiple_required');
$navigator_info = api_get_navigator();
global $text, $class, $show_quiz_edition;
if ($show_quiz_edition) {
//ie6 fix
if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') {
$form->addElement('submit','submitQuestion',$text, 'class="'.$class.'"');
$form->addElement('submit', 'moreAnswers', get_lang('PlusAnswer'),'class="plus"');
$form->addElement('submit', 'lessAnswers', get_lang('LessAnswer'),'class="minus"');
} else {
// setting the save button here and not in the question class.php
$form->addElement('style_submit_button','submitQuestion',$text, 'class="'.$class.'"');
$form->addElement('style_submit_button', 'lessAnswers', get_lang('LessAnswer'),'style="float:right"; class="minus"');
$form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'),'style="float:right"; class="plus"');
}
}
$renderer->setElementTemplate('{element}&nbsp;','lessAnswers');
$renderer->setElementTemplate('{element}&nbsp;','submitQuestion');
$renderer->setElementTemplate('{element}','moreAnswers');
$form -> addElement ('html', '</div></div>');
$defaults['correct'] = $correct;
if (!empty($this -> id)) {
$form -> setDefaults($defaults);
} else {
//if ($this -> isContent == 1) {
$form -> setDefaults($defaults);
//}
}
$form->setConstants(array('nb_answers' => $nb_answers));
}
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance
* @param the answers number to display
*/
function processAnswersCreation($form) {
$questionWeighting = $nbrGoodAnswers = 0;
$objAnswer = new Answer($this->id);
$nb_answers = $form -> getSubmitValue('nb_answers');
for($i=1 ; $i <= $nb_answers ; $i++)
{
$answer = trim($form -> getSubmitValue('answer['.$i.']'));
$comment = trim($form -> getSubmitValue('comment['.$i.']'));
$weighting = trim($form -> getSubmitValue('weighting['.$i.']'));
$goodAnswer = trim($form -> getSubmitValue('correct['.$i.']'));
if($goodAnswer){
$weighting = abs($weighting);
} else {
$weighting = abs($weighting);
$weighting = -$weighting;
}
if($weighting > 0)
{
$questionWeighting += $weighting;
}
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i);
}
// saves the answers into the data base
$objAnswer -> save();
// sets the total weighting of the question
$this -> updateWeighting($questionWeighting);
$this -> save();
}
}
endif;
?>

@ -21,6 +21,8 @@ define('HOT_SPOT', 6);
define('HOT_SPOT_ORDER', 7);
define('HOT_SPOT_DELINEATION', 8);
define('MULTIPLE_ANSWER_COMBINATION', 9);
define('UNIQUE_ANSWER_NO_OPTION', 10);
define('MULTIPLE_ANSWER_TRUE_FALSE', 11);
/**
QUESTION CLASS
@ -53,6 +55,9 @@ abstract class Question
FREE_ANSWER => array('freeanswer.class.php' , 'FreeAnswer'),
HOT_SPOT => array('hotspot.class.php' , 'HotSpot'),
MULTIPLE_ANSWER_COMBINATION => array('multiple_answer_combination.class.php' , 'MultipleAnswerCombination'),
UNIQUE_ANSWER_NO_OPTION => array('unique_answer_no_option.class.php' , 'UniqueAnswerNoOption'),
MULTIPLE_ANSWER_TRUE_FALSE => array('multiple_answer_true_false.class.php' , 'MultipleAnswerTrueFalse'),
);
/**
@ -96,8 +101,7 @@ abstract class Question
$result=Database::query($sql);
// if the question has been found
if($object=Database::fetch_object($result))
{
if($object=Database::fetch_object($result)) {
$objQuestion = Question::getInstance($object->type);
$objQuestion->id = $id;
$objQuestion->question = $object->question;
@ -115,7 +119,6 @@ abstract class Question
while($object=Database::fetch_object($result)) {
$objQuestion->exerciseList[]=$object->exercice_id;
}
return $objQuestion;
}
@ -129,8 +132,7 @@ abstract class Question
* @author - Olivier Brouckaert
* @return - integer - question ID
*/
function selectId()
{
function selectId() {
return $this->id;
}
@ -140,8 +142,7 @@ abstract class Question
* @author - Olivier Brouckaert
* @return - string - question title
*/
function selectTitle()
{
function selectTitle() {
$this->question=text_filter($this->question);
return $this->question;
}
@ -152,8 +153,7 @@ abstract class Question
* @author - Olivier Brouckaert
* @return - string - question description
*/
function selectDescription()
{
function selectDescription() {
$this->description=text_filter($this->description);
return $this->description;
}
@ -306,16 +306,13 @@ abstract class Question
* @author - Olivier Brouckaert
* @param - integer $type - answer type
*/
function updateType($type)
{
function updateType($type) {
global $TBL_REPONSES;
// if we really change the type
if($type != $this->type)
{
if($type != $this->type) {
// if we don't change from "unique answer" to "multiple answers" (or conversely)
if(!in_array($this->type,array(UNIQUE_ANSWER,MULTIPLE_ANSWER)) || !in_array($type,array(UNIQUE_ANSWER,MULTIPLE_ANSWER)))
{
if(!in_array($this->type,array(UNIQUE_ANSWER,MULTIPLE_ANSWER)) || !in_array($type,array(UNIQUE_ANSWER,MULTIPLE_ANSWER))) {
// removes old answers
$sql="DELETE FROM $TBL_REPONSES WHERE question_id='".Database::escape_string($this->id)."'";
Database::query($sql);
@ -333,8 +330,7 @@ abstract class Question
* @param - string $PictureName - Name of the picture
* @return - boolean - true if uploaded, otherwise false
*/
function uploadPicture($Picture,$PictureName)
{
function uploadPicture($Picture,$PictureName) {
global $picturePath, $_course, $_user;
if (!file_exists($picturePath)) {
@ -1113,8 +1109,7 @@ abstract class Question
/**
* Displays the menu of question types
*/
static function display_type_menu ($feedbacktype = 0)
{
static function display_type_menu ($feedbacktype = 0) {
global $exerciseId;
// 1. by default we show all the question types
$question_type_custom_list = self::$questionTypes;
@ -1149,6 +1144,7 @@ abstract class Question
echo '<li>';
echo '<div class="icon_image_content">';
if ($show_quiz_edition) {
echo '<a href="admin.php?'.api_get_cidreq().'&newQuestion=yes&answerType='.$i.'">'.Display::return_icon($img, $explanation).'</a>';
echo '<br>';
echo '<a href="admin.php?'.api_get_cidreq().'&newQuestion=yes&answerType='.$i.'">'.$explanation.'</a>';
@ -1157,6 +1153,7 @@ abstract class Question
$img = $img['filename'];
echo ''.Display::return_icon($img.'_na.gif',$explanation).'';
echo '<br>';
echo ''.$explanation.'';
}
echo '</div>';

@ -0,0 +1,437 @@
<?php
/* For licensing terms, see /license.txt */
/**
* File containing the UNIQUE_ANSWER class.
* @package chamilo.exercise
* @author Eric Marguin
*/
if(!class_exists('UniqueAnswerNoOption')):
/**
CLASS UNIQUE_ANSWER
*
* This class allows to instantiate an object of type UNIQUE_ANSWER (MULTIPLE CHOICE, UNIQUE ANSWER),
* extending the class question
*
* @author Eric Marguin
* @author Julio Montoya
* @package chamilo.exercise
**/
class UniqueAnswerNoOption extends Question {
static $typePicture = 'mcua.gif';
static $explanationLangVar = 'UniqueAnswerNoOptionSelect';
/**
* Constructor
*/
function UniqueAnswerNoOption(){
//this is highly important
parent::question();
$this -> type = UNIQUE_ANSWER_NO_OPTION;
$this -> isContent = $this-> getIsContent();
}
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
* @param the answers number to display
*/
function createAnswersForm ($form) {
// getting the exercise list
$obj_ex =$_SESSION['objExercise'];
$editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
//this line define how many question by default appear when creating a choice question
$nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 3; // The previous default value was 2. See task #1759.
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0));
/*
Types of Feedback
$feedback_option[0]=get_lang('Feedback');
$feedback_option[1]=get_lang('DirectFeedback');
$feedback_option[2]=get_lang('NoFeedback');
*/
$feedback_title='';
$comment_title='';
if ($obj_ex->selectFeedbackType()==0) {
$comment_title = '<th>'.get_lang('Comment').'</th>';
} elseif ($obj_ex->selectFeedbackType()==1) {
$editor_config['Width'] = '250';
$editor_config['Height'] = '110';
$comment_title = '<th width="500" >'.get_lang('Comment').'</th>';
$feedback_title = '<th width="350px" >'.get_lang('Scenario').'</th>';
}
$html='
<div class="row">
<div class="label">
'.get_lang('Answers').' <br /> <img src="../img/fill_field.png">
</div>
<div class="formw">
<table class="data_table">
<tr style="text-align: center;">
<th width="10px">
'.get_lang('Number').'
</th>
<th width="10px" >
'.get_lang('True').'
</th>
<th width="45%">
'.get_lang('Answer').'
</th>
'.$comment_title.'
'.$feedback_title.'
<th width="20px">
'.get_lang('Weighting').'
</th>
</tr>';
$form -> addElement ('html', $html);
$defaults = array();
$correct = 0;
if(!empty($this -> id)) {
$answer = new Answer($this -> id);
$answer -> read();
if(count($answer->nbrAnswers)>0 && !$form->isSubmitted()) {
$nb_answers = $answer->nbrAnswers;
}
}
$form -> addElement('hidden', 'nb_answers');
//Feedback SELECT
//Not needed right now
/*
$question_list=$obj_ex->selectQuestionList();
$select_question=array();
$select_question[0]=get_lang('SelectTargetQuestion');
require_once '../newscorm/learnpathList.class.php';
if (is_array($question_list)) {
foreach ($question_list as $key=>$questionid) {
//To avoid warning messages
if (!is_numeric($questionid)) {
continue;
}
$question = Question::read($questionid);
$select_question[$questionid]='Q'.$key.' :'.cut($question->selectTitle(),20);
}
}
$select_question[-1]=get_lang('ExitTest');
$list = new LearnpathList(api_get_user_id());
$flat_list = $list->get_flat_list();
$select_lp_id=array();
$select_lp_id[0]=get_lang('SelectTargetLP');
foreach ($flat_list as $id => $details) {
$select_lp_id[$id] = cut($details['lp_name'],20);
}*/
$temp_scenario = array();
if ($nb_answers < 1) {
$nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for($i = 1 ; $i <= $nb_answers ; ++$i) {
$form -> addElement ('html', '<tr>');
if (is_object($answer)) {
if ($answer -> correct[$i]) {
$correct = $i;
}
$answer_result = $answer -> answer[$i];
$weight_result = float_format($answer -> weighting[$i], 1);
if ($nb_answers == $i) {
$weight_result = '0';
}
$defaults['answer['.$i.']'] = $answer_result;
$defaults['comment['.$i.']'] = $answer -> comment[$i];
$defaults['weighting['.$i.']'] = $weight_result;
$item_list=explode('@@',$answer -> destination[$i]);
$try = $item_list[0];
$lp = $item_list[1];
$list_dest = $item_list[2];
$url = $item_list[3];
if ($try==0)
$try_result=0;
else
$try_result=1;
if ($url==0)
$url_result='';
else
$url_result=$url;
$temp_scenario['url'.$i] = $url_result;
$temp_scenario['try'.$i] = $try_result;
$temp_scenario['lp'.$i] = $lp;
$temp_scenario['destination'.$i]= $list_dest;
/*$pre_list_destination=explode(';',$list_dest);
$list_destination=array();
foreach($pre_list_destination as $value)
{
$list_destination[]=$value;
}
$defaults['destination'.$i]=$list_destination;
*/
//$defaults['destination'.$i] = $list_destination;
} else {
/* if ($nb_answers == $i) {
$defaults['answer['.$i.']'] = get_lang('DontKnow');
$defaults['weighting['.$i.']'] = 0;
$temp_scenario['destination'.$i] = array('0');
$temp_scenario['lp'.$i] = array('0');
} else {
$temp_scenario['destination'.$i] = array('0');
$temp_scenario['lp'.$i] = array('0');
//$defaults['scenario']
}*/
}
$defaults['scenario']=$temp_scenario;
$renderer = & $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>','html');
$answer_number=$form->addElement('text', null,null,'value="'.$i.'"');
$answer_number->freeze();
$form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"');
$form->addElement('html_editor', 'answer['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) {
// feedback
$form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
} elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
/*
// direct feedback
$form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
//Adding extra feedback fields
$group = array();
$group['try'.$i] =&$form->createElement('checkbox', 'try'.$i,get_lang('TryAgain').': ' );
$group['lp'.$i] =&$form->createElement('select', 'lp'.$i,get_lang('SeeTheory').': ',$select_lp_id);
$group['destination'.$i]=&$form->createElement('select', 'destination'.$i, get_lang('GoToQuestion').': ' ,$select_question);
$group['url'.$i] =&$form->createElement('text', 'url'.$i,get_lang('Other').': ',array('size'=>'25px'));
$form -> addGroup($group, 'scenario', 'scenario');
$renderer->setGroupElementTemplate('<div class="exercise_scenario_label">{label}</div><div class="exercise_scenario_element">{element}</div>','scenario');*/
}
//$form->addElement('select', 'destination'.$i, get_lang('SelectQuestion').' : ',$select_question,'multiple');
$form->addElement('text', 'weighting['.$i.']', null, 'style="vertical-align:middle;margin-left: 0em;" size="5" value="0"');
$form->addElement('html', '</tr>');
}
//Adding I don't know question option
$i = 666;
$form -> addElement ('html', '<tr>');
$defaults['answer['.$i.']'] = get_lang('DontKnow');
$defaults['weighting['.$i.']'] = 0;
$defaults['scenario']=$temp_scenario;
$renderer = & $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>','html');
$answer_number=$form->addElement('text', null,null,'value="-"');
$answer_number->freeze();
$form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"');
$form->addElement('html_editor', 'answer['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) {
// feedback
$form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
} elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
/* // direct feedback
$form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
//Adding extra feedback fields
$group = array();
$group['try'.$i] =&$form->createElement('checkbox', 'try'.$i,get_lang('TryAgain').': ' );
$group['lp'.$i] =&$form->createElement('select', 'lp'.$i,get_lang('SeeTheory').': ',$select_lp_id);
$group['destination'.$i]=&$form->createElement('select', 'destination'.$i, get_lang('GoToQuestion').': ' ,$select_question);
$group['url'.$i] =&$form->createElement('text', 'url'.$i,get_lang('Other').': ',array('size'=>'25px'));
$form -> addGroup($group, 'scenario', 'scenario');
$renderer->setGroupElementTemplate('<div class="exercise_scenario_label">{label}</div><div class="exercise_scenario_element">{element}</div>','scenario');*/
}
//$form->addElement('select', 'destination'.$i, get_lang('SelectQuestion').' : ',$select_question,'multiple');
$form->addElement('text', 'weighting['.$i.']', null, 'style="vertical-align:middle;margin-left: 0em;" size="5" value="0" readonly="readonly" ');
$form->addElement ('html', '</tr>');
$form -> addElement ('html', '</table>');
$form -> addElement ('html', '<br />');
$navigator_info = api_get_navigator();
global $text, $class, $show_quiz_edition;
//ie6 fix
if ($show_quiz_edition) {
if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') {
$form->addElement('submit','submitQuestion',$text, 'class="'.$class.'"');
$form->addElement('submit', 'moreAnswers', get_lang('PlusAnswer'),'class="plus"');
$form->addElement('submit', 'lessAnswers', get_lang('LessAnswer'),'class="minus"');
} else {
//setting the save button here and not in the question class.php
$form->addElement('style_submit_button','submitQuestion',$text, 'class="'.$class.'"');
$form->addElement('style_submit_button', 'lessAnswers', get_lang('LessAnswer'),'style="float:right"; class="minus"');
$form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'),'style="float:right"; class="plus"');
}
}
$renderer->setElementTemplate('{element}','submitQuestion');
$renderer->setElementTemplate('{element}&nbsp;','lessAnswers');
$renderer->setElementTemplate('{element}','moreAnswers');
$form -> addElement ('html', '</div></div>');
//We check the first radio button to be sure a radio button will be check
if ($correct==0) {
$correct=1;
}
$defaults['correct'] = $correct;
if (!empty($this -> id)) {
$form -> setDefaults($defaults);
} else {
//if ($this -> isContent == 1) {
$form -> setDefaults($defaults);
//}
}
$form->setConstants(array('nb_answers' => $nb_answers));
}
/**
* abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance
* @param the answers number to display
*/
function processAnswersCreation($form) {
$questionWeighting = $nbrGoodAnswers = 0;
$correct = $form -> getSubmitValue('correct');
$objAnswer = new Answer($this->id);
$nb_answers = $form -> getSubmitValue('nb_answers');
for($i=1 ; $i <= $nb_answers ; $i++)
{
$answer = trim($form -> getSubmitValue('answer['.$i.']'));
$comment = trim($form -> getSubmitValue('comment['.$i.']'));
$weighting = trim($form -> getSubmitValue('weighting['.$i.']'));
$scenario= $form -> getSubmitValue('scenario');
echo '<pre>';
//$list_destination = $form -> getSubmitValue('destination'.$i);
//$destination_str = $form -> getSubmitValue('destination'.$i);
$try = $scenario['try'.$i];
$lp= $scenario['lp'.$i];
$destination = $scenario['destination'.$i];
$url = trim($scenario['url'.$i]);
/*
How we are going to parse the destination value
here we parse the destination value which is a string
1@@3@@2;4;4;@@http://www.dokeos.com
where: try_again@@lp_id@@selected_questions@@url
try_again = is 1 || 0
lp_id = id of a learning path (0 if dont select)
selected_questions= ids of questions
url= an url
*/
/*
$destination_str='';
foreach ($list_destination as $destination_id)
{
$destination_str.=$destination_id.';';
}*/
$goodAnswer= ($correct == $i) ? true : false;
if($goodAnswer)
{
$nbrGoodAnswers++;
$weighting = abs($weighting);
if($weighting > 0)
{
$questionWeighting += $weighting;
}
}
if (empty($try))
$try=0;
if (empty($lp))
{
$lp=0;
}
if (empty($destination))
{
$destination=0;
}
if ($url=='')
{
$url=0;
}
//1@@1;2;@@2;4;4;@@http://www.dokeos.com
$dest= $try.'@@'.$lp.'@@'.$destination.'@@'.$url;
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i,NULL,NULL,$dest);
}
// saves the answers into the data base
$objAnswer -> save();
// sets the total weighting of the question
$this -> updateWeighting($questionWeighting);
$this -> save();
}
}
endif;
?>
Loading…
Cancel
Save