Adding more improvements for the new kind of questions see Bt#1914

skala
Julio Montoya 16 years ago
parent 72a83f6e00
commit 4090a2fbe9
  1. 1
      main/exercice/answer.class.php
  2. 25
      main/exercice/exercice.php
  3. 101
      main/exercice/exercise.class.php
  4. 12
      main/exercice/exercise.lib.php
  5. 17
      main/exercice/exercise_show.php
  6. 222
      main/exercice/multiple_answer_true_false.class.php
  7. 50
      main/exercice/question.class.php
  8. 4
      main/exercice/question_list_admin.inc.php
  9. 87
      main/inc/lib/exercise_show_functions.lib.php

@ -484,6 +484,7 @@ class Answer
'$weighting','$position','$hotspot_coordinates','$hotspot_type','$destination'),";
}
$sql = api_substr($sql,0,-1);
var_dump($sql);
Database::query($sql);
// moves $new_* arrays

@ -778,8 +778,7 @@ if ($show == 'test') {
//Showing exercise title
$row['title']=text_filter($row['title']);
echo Display::tag('h1',$row['title']);
echo Display::tag('h1',$row['title']);
echo '<p>';
echo $session_img;
$exid = $row['id'];
@ -801,28 +800,28 @@ if ($show == 'test') {
if ($session_id == $row['session_id']) {
//Settings
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']));
echo Display::url(Display::return_icon('settings.png',get_lang('Edit'), array('width'=>'22px'))." ".get_lang('Edit'), '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']));
echo Display::url(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
echo Display::tag('a', Display::return_icon('clean_group.png', get_lang('CleanStudentResults')),array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDeleteResults'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=clean_results&sec_token='.$token.'&exerciseId='.$row['id']));
echo Display::url(Display::return_icon('clean_group.png', get_lang('CleanStudentResults')),'', array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDeleteResults'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=clean_results&sec_token='.$token.'&exerciseId='.$row['id']));
//Visible / invisible
if ($row['active']) {
echo Display::tag('a', Display::return_icon('visible.gif', get_lang('Deactivate')) , array('href'=>'exercice.php?'.api_get_cidreq().'&choice=disable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']));
echo Display::url(Display::return_icon('visible.gif', get_lang('Deactivate')) , 'exercice.php?'.api_get_cidreq().'&choice=disable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']);
} else { // else if not active
echo Display::tag('a', Display::return_icon('invisible.gif', get_lang('Activate')) , array('href'=>'exercice.php?'.api_get_cidreq().'&choice=enable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']));
echo Display::url(Display::return_icon('invisible.gif', get_lang('Activate')) , 'exercice.php?'.api_get_cidreq().'&choice=enable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']);
}
// Export qti ...
echo Display::tag('a', Display::return_icon('export_db.png', 'IMS/QTI'), array('href'=>'exercice.php?choice=exportqti2&exerciseId='.$row['id']));
echo Display::url(Display::return_icon('export_db.png', 'IMS/QTI'), 'exercice.php?choice=exportqti2&exerciseId='.$row['id']);
} else { // not session resource
echo Display::return_icon('wizard_gray_small.gif', get_lang('ExerciseEditionNotAvailableInSession'));
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']));
echo Display::url(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']));
}
//Delete
if ($session_id == $row['session_id']) {
echo Display::tag('a', Display::return_icon('delete.png', get_lang('Delete')),array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDelete'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=delete&sec_token='.$token.'&exerciseId='.$row['id']));
echo Display::url(Display::return_icon('delete.png', get_lang('Delete')), '', array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDelete'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=delete&sec_token='.$token.'&exerciseId='.$row['id']));
}
//Attempts
echo '<br />'.get_count_exam_results($row['id']).' '.get_lang('Attempts');
@ -830,11 +829,11 @@ if ($show == 'test') {
//Special buttons
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 Display::url(Display::return_icon('quiz.gif',get_lang('Questions'), array('width'=>'22px'))." ".get_lang('Questions'),'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 Display::url(Display::return_icon('preview.gif',get_lang('Preview'), array('width'=>'22px'))." ".get_lang('Preview'), 'exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id']);
echo ' ';
echo Display::tag('a', Display::return_icon('show_test_results.gif',get_lang('Results'), array('width'=>'22px'))." ".get_lang('Results'), array('href'=>'exercice.php?'.api_get_cidreq().'&show=result&exerciseId='.$row['id']));
echo Display::url(Display::return_icon('show_test_results.gif',get_lang('Results'), array('width'=>'22px'))." ".get_lang('Results'), 'exercice.php?'.api_get_cidreq().'&show=result&exerciseId='.$row['id']);
echo '</div>';
} else {

@ -1658,9 +1658,18 @@ class Exercise {
$questionName = $objQuestionTmp->selectTitle();
$questionDescription = $objQuestionTmp->selectDescription();
$questionWeighting = $objQuestionTmp->selectWeighting();
$questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType();
$quesId = $objQuestionTmp->selectId();
$quesId = $objQuestionTmp->selectId();
$extra = $objQuestionTmp->extra;
//Extra information of the question
if (!empty($extra)){
$extra = explode(':', $extra);
$true_score = $extra[0];
$false_score = $extra[1];
$doubt_score = $extra[2];
}
$totalWeighting = 0;
$totalScore = 0;
@ -1687,7 +1696,8 @@ class Exercise {
}
$real_answers = array();
$quiz_question_options = Question::readQuestionOption($questionId);
for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
$answer = $objAnswerTmp->selectAnswer($answerId);
$answerComment = $objAnswerTmp->selectComment($answerId);
@ -1720,36 +1730,36 @@ class Exercise {
}
break;
// for multiple answers
case MULTIPLE_ANSWER_TRUE_FALSE :
case MULTIPLE_ANSWER_TRUE_FALSE :
if ($from_database) {
$choice=array();
$queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." where exe_id = '".$exeId."' and question_id= '".$questionId."'";
$resultans = Database::query($queryans);
while ($row = Database::fetch_array($resultans)) {
$ind = $row['answer'];
$result = explode(':',$ind);
$ind = $row['answer'];
$result = explode(':',$ind);
$my_answer_id = $result[0];
$option = $result[1];
$choice[$my_answer_id] = $option;
}
$numAnswer=$objAnswerTmp->selectAutoId($answerId);
$studentChoice =$choice[$numAnswer];
$studentChoice =$choice[$numAnswer];
} else {
$studentChoice =$choice[$numAnswer]; // 0, 1 or 2
//echo $studentChoice.' - '.$answerCorrect.'<br />';
}
$studentChoice =$choice[$numAnswer];
}
if ($studentChoice == $answerCorrect ) {
if ($studentChoice == 1) {
$questionScore +=1;
$totalScore +=1;
}
} else {
if ($studentChoice == 0 || $studentChoice == 1) {
$questionScore +=-0.5;
$totalScore +=-0.5;
if ($studentChoice == $answerCorrect ) {
$questionScore +=$true_score;
} else {
if ($quiz_question_options[$studentChoice]['name'] != 'DoubtScore') {
$questionScore += $false_score;
} else {
$questionScore += $doubt_score;
}
}
}
$questionWeighting+=$true_score;
$totalScore +=$true_score;
//echo $studentChoice.' - '.$answerCorrect.' '.$questionScore.'<br />';
break;
case MULTIPLE_ANSWER :
if ($from_database) {
@ -1784,34 +1794,45 @@ class Exercise {
$my_answer_id = $result[0];
$option = $result[1];
$choice[$my_answer_id] = $option;
}
}
$numAnswer=$objAnswerTmp->selectAutoId($answerId);
$studentChoice=$choice[$numAnswer];
//echo $studentChoice.' - '.$answerCorrect.'<br /> ';
if ($answerCorrect == 1) {
if ($studentChoice) {
if ($studentChoice == 1) { //true value see MultipleAnswerCombinationTrueFalse class
$real_answers[$answerId] = true;
} else {
} elseif ($studentChoice == 2) { //false value
$real_answers[$answerId] = false;
} else {
$real_answers[$answerId] = false;
}
} else {
if ($studentChoice) {
if ($studentChoice == 1) { //true value
$real_answers[$answerId] = false;
} elseif ($studentChoice == 2) { //false value see MultipleAnswerCombinationTrueFalse class
$real_answers[$answerId] = true;
} else {
$real_answers[$answerId] = true;
}
}
}
} else {
$studentChoice=$choice[$numAnswer];
if ($answerCorrect == 1) {
if ($studentChoice) {
if ($answerCorrect == 1) {
if ($studentChoice == 1) { //true value see MultipleAnswerCombinationTrueFalse class
$real_answers[$answerId] = true;
} elseif ($studentChoice == 2) { //false value
$real_answers[$answerId] = false;
} else {
$real_answers[$answerId] = false;
}
} else {
if ($studentChoice) {
if ($studentChoice == 1) { //true value
$real_answers[$answerId] = false;
} elseif ($studentChoice == 2) { //false value see MultipleAnswerCombinationTrueFalse class
$real_answers[$answerId] = true;
} else {
$real_answers[$answerId] = true;
}
@ -1822,8 +1843,7 @@ class Exercise {
$final_answer = false;
}
}
}
}
break;
case MULTIPLE_ANSWER_COMBINATION:
if ($from_database) {
@ -2166,10 +2186,14 @@ class Exercise {
if ($origin!='learnpath') {
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,0,0);
}
} elseif($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) {
} elseif($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
if ($origin!='learnpath') {
ExerciseShowFunctions::display_multiple_answer_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,0,0);
}
} elseif($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) {
if ($origin!='learnpath') {
ExerciseShowFunctions::display_multiple_answer_combination_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,0,0);
}
} elseif($answerType == FILL_IN_BLANKS) {
if ($origin!='learnpath') {
ExerciseShowFunctions::display_fill_in_blanks_answer($answer,0,0);
@ -2207,13 +2231,19 @@ class Exercise {
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,"");
}
break;
case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
if ($answerId==1) {
ExerciseShowFunctions::display_multiple_answer_combination_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId);
} else {
ExerciseShowFunctions::display_multiple_answer_combination_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,"");
}
break;
case MULTIPLE_ANSWER_TRUE_FALSE :
if ($answerId==1) {
ExerciseShowFunctions::display_multiple_answer_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId);
} else {
ExerciseShowFunctions::display_multiple_answer_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,"");
}
}
break;
case FILL_IN_BLANKS:
echo '<tr><td>';
@ -2287,7 +2317,8 @@ class Exercise {
</tr>';
}
}
if($origin != 'learnpath') { ?>
if($origin != 'learnpath') {
?>
<tr>
<td colspan="<?php echo $colspan; ?>" align="left">
<?php

@ -89,6 +89,8 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
// construction of the Answer object (also gets all answers details)
$objAnswerTmp=new Answer($questionId);
$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$quiz_question_options = Question::readQuestionOption($questionId);
// For "matching" type here, we need something a little bit special
// because the match between the suggestions and the answers cannot be
@ -299,8 +301,8 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
$options = array('type'=>'radio','name'=>'choice['.$questionId.']['.$numAnswer.']', 'class'=>'checkbox');
$s .='<tr>';
$s .= Display::tag('td', $answer);
foreach ($objQuestionTmp->options as $key=>$item) {
$options['value'] = $key;
foreach ($quiz_question_options as $id=>$item) {
$options['value'] = $id;
$s .= Display::tag('td', Display::tag('input','',$options ));
}
$s.='<tr>';
@ -1075,7 +1077,11 @@ function show_score($score, $weight, $show_porcentage = true) {
$max_note = api_get_setting('exercise_max_note');
$min_note = api_get_setting('exercise_min_note');
if ($max_note != '' && $min_note != '') {
$score = $min_note + ($max_note - $min_note) * $score /$weight;
if (!empty($weight)) {
$score = $min_note + ($max_note - $min_note) * $score /$weight;
} else {
$score = $min_note;
}
$score_rounded = round($score, 2);
$weight = $max_note;
}

@ -325,11 +325,12 @@ if ($show_results) {
$questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType();
$quesId = $objQuestionTmp->selectId(); //added by priya saini
// destruction of the Question object
unset($objQuestionTmp);
if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
$colspan=2;
}
if($answerType == MATCHING || $answerType == FREE_ANSWER) {
@ -367,10 +368,12 @@ if ($show_results) {
<?php
// construction of the Answer object
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);
//var_dump($question_result);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
$questionWeighting += $question_result['weight'];
echo '</table>';
} elseif ($answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
$choice=array();
@ -390,7 +393,8 @@ if ($show_results) {
</tr>
<?php
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true);
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
@ -579,12 +583,11 @@ if ($show_results) {
unset($objAnswerTmp);
$i++;
$totalWeighting+=$questionWeighting;
} // end of large foreach on questions
} //end of condition if $show_results
if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
//$query = "update ".$TBL_TRACK_EXERCICES." set exe_result = $totalScore where exe_id = '$id'";
//Database::query($query);
if ($show_results) {
echo '<div id="question_score">'.get_lang('YourTotalScore')." ";

@ -29,9 +29,9 @@ class MultipleAnswerTrueFalse extends Question {
*/
function MultipleAnswerTrueFalse(){
parent::question();
$this -> type = MULTIPLE_ANSWER_TRUE_FALSE;
$this -> isContent = $this-> getIsContent();
$this->options = array('1'=>get_lang('True'),'0' =>get_lang('False'), '2' =>get_lang('Nothing'));
$this->type = MULTIPLE_ANSWER_TRUE_FALSE;
$this->isContent = $this-> getIsContent();
$this->options = array(1=>get_lang('True'),2 =>get_lang('False'), 3 =>get_lang('DoubtScore'));
}
/**
@ -41,18 +41,48 @@ class MultipleAnswerTrueFalse extends Question {
*/
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['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">
$html.='<div class="row">
<div class="label">
'.get_lang('Answers').'<br /><img src="../img/fill_field.png">
</div>
<div class="formw">';
$html2 ='<div class="row">
<div class="label">
</div>
<div class="formw">';
$form -> addElement ('html', $html2);
$form -> addElement ('html', '<table><tr>');
$renderer = & $form->defaultRenderer();
$defaults = array();
if (!empty($this->extra)) {
$scores = explode(':',$this->extra);
if (!empty($scores)) {
for ($i = 1; $i <=3; $i++) {
$defaults['option['.$i.']'] = $scores[$i-1];
}
}
}
// 3 scores
$form->addElement('text', 'option[1]',get_lang('True'), array('size'=>'5','value'=>'1'));
$form->addElement('text', 'option[2]',get_lang('False'), array('size'=>'5','value'=>'-0.5'));
$form->addElement('text', 'option[3]',get_lang('DoubtScore'),array('size'=>'5','value'=>'0'));
$form -> addElement('hidden', 'options_count', 3);
$form -> addElement ('html', '</tr></table>');
$form -> addElement ('html', '</div></div>');
$html.='<table class="data_table">
<tr style="text-align: center;">
<th>
'.get_lang('Number').'
@ -60,28 +90,25 @@ class MultipleAnswerTrueFalse extends Question {
<th>
'.get_lang('True').'
</th>
<th>
'.get_lang('False').'
</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>';
// show column comment when feedback is enable
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM ) {
$html .='<th>'.get_lang('Comment').'</th>';
}
$html .= '</tr>';
$form -> addElement ('html', $html);
$defaults = array();
$correct = 0;
if(!empty($this -> id)) {
if (!empty($this -> id)) {
$answer = new Answer($this -> id);
$answer -> read();
if(count($answer->nbrAnswers)>0 && !$form->isSubmitted()) {
$answer->read();
if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
$nb_answers = $answer->nbrAnswers;
}
}
@ -93,27 +120,44 @@ class MultipleAnswerTrueFalse extends Question {
$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, 'id="'.$i.'" class="checkbox" style="margin-left: 0em;" onchange="multiple_answer_true_false_onchange(this);" ' );
// Can be more options
$option_data = Question::readQuestionOption($this->id);
for ($i = 1 ; $i <= $nb_answers ; ++$i) {
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{label} &nbsp;&nbsp;{element}</td>');
$answer_number=$form->addElement('text', null,null,'value="'.$i.'"');
$answer_number->freeze();
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);
$correct = $answer->correct[$i];
var_dump($correct);
//$this->options
$defaults['correct['.$i.']'] = $correct;
$j = 1;
if (!empty($option_data)) {
foreach ($option_data as $id=>$data) {
$form->addElement('radio', 'correct['.$i.']', null, null,$id);
$j++;
if ($j == 3) {
break;
}
}
}
} else {
$form->addElement('radio', 'correct['.$i.']', null, null, 1);
$form->addElement('radio', 'correct['.$i.']', null, null, 2);
$defaults['answer['.$i.']'] = '';
$defaults['comment['.$i.']'] = '';
$defaults['correct['.$i.']'] = '';
}
//$form->addElement('select', 'correct['.$i.']',null, $this->options, array('id'=>$i,'onchange'=>'multiple_answer_true_false_onchange(this)'));
@ -126,14 +170,12 @@ class MultipleAnswerTrueFalse extends Question {
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', '</tr>');
}
$form -> addElement ('html', '</table>');
$form -> addElement ('html', '<br />');
$form -> add_multiple_required_rule ($boxes_names , get_lang('ChooseAtLeastOneCheckbox') , 'multiple_required');
//$form -> add_multiple_required_rule ($boxes_names , get_lang('ChooseAtLeastOneCheckbox') , 'multiple_required');
$navigator_info = api_get_navigator();
@ -176,44 +218,64 @@ class MultipleAnswerTrueFalse extends Question {
* @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 = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers');
$options_count = $form->getSubmitValue('options_count');
$correct = array();
$options = Question::readQuestionOption($this->id);
if (!empty($options)) {
foreach ($options as $option_data) {
$id = $option_data['id'];
unset($option_data['id']);
Question::updateQuestionOption($id, $option_data);
}
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i);
} else {
for ($i=1 ; $i <= 3 ; $i++) {
$last_id = Question::saveQuestionOption($this->id, $this->options[$i], $i);
$correct[$i] = $last_id;
}
}
$new_options = Question::readQuestionOption($this->id);
$sorted_by_position = array();
foreach($new_options as $item) {
$sorted_by_position[$item['position']] = $item;
}
//Saving quiz_question.extra values
$extra_values = array();
for ($i=1 ; $i <= 3 ; $i++) {
$score = trim($form -> getSubmitValue('option['.$i.']'));
$extra_values[]= $score;
}
$this->setExtra(implode(':',$extra_values));
for ($i=1 ; $i <= $nb_answers ; $i++) {
$answer = trim($form -> getSubmitValue('answer['.$i.']'));
$comment = trim($form -> getSubmitValue('comment['.$i.']'));
$goodAnswer = trim($form -> getSubmitValue('correct['.$i.']'));
if (empty($options)) {
//new
$goodAnswer = $sorted_by_position[$goodAnswer]['id'];
}
$questionWeighting += $correct[1];
$objAnswer->createAnswer($answer, $goodAnswer, $comment,'',$i);
}
// saves the answers into the data base
$objAnswer -> save();
// sets the total weighting of the question
$this -> updateWeighting($questionWeighting);
$this -> save();
}
}
endif;

@ -76,6 +76,7 @@ abstract class Question
$this->position=1;
$this->picture='';
$this->level = 1;
$this->extra='';
$this->exerciseList=array();
}
@ -99,7 +100,7 @@ abstract class Question
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$sql="SELECT question,description,ponderation,position,type,picture,level FROM $TBL_QUESTIONS WHERE id='".Database::escape_string($id)."'";
$sql="SELECT question,description,ponderation,position,type,picture,level,extra FROM $TBL_QUESTIONS WHERE id='".Database::escape_string($id)."'";
$result=Database::query($sql);
@ -114,6 +115,7 @@ abstract class Question
$objQuestion->type = $object->type;
$objQuestion->picture = $object->picture;
$objQuestion->level = (int) $object->level;
$objQuestion->extra = $object->extra;
$sql="SELECT exercice_id FROM $TBL_EXERCICE_QUESTION WHERE question_id='".intval($id)."'";
$result=Database::query($sql);
@ -532,6 +534,15 @@ abstract class Question
{
$this->question = $title;
}
/**
Sets the title
*/
public function setExtra($extra)
{
$this->extra = $extra;
}
/**
@ -591,6 +602,7 @@ abstract class Question
$type=$this->type;
$picture=$this->picture;
$level=$this->level;
$extra=$this->extra;
// question already exists
if(!empty($id)) {
@ -601,6 +613,7 @@ abstract class Question
position ='".Database::escape_string($position)."',
type ='".Database::escape_string($type)."',
picture ='".Database::escape_string($picture)."',
extra ='".Database::escape_string($extra)."',
level ='".Database::escape_string($level)."'
WHERE id='".Database::escape_string($id)."'";
Database::query($sql);
@ -626,14 +639,15 @@ abstract class Question
$this -> updatePosition($current_position+1);
$position = $this -> position;
$sql="INSERT INTO $TBL_QUESTIONS(question,description,ponderation,position,type,picture,level) VALUES(
$sql="INSERT INTO $TBL_QUESTIONS(question,description,ponderation,position,type,picture,extra, level) VALUES(
'".Database::escape_string($question)."',
'".Database::escape_string($description)."',
'".Database::escape_string($weighting)."',
'".Database::escape_string($position)."',
'".Database::escape_string($type)."',
'".Database::escape_string($picture)."',
'".Database::escape_string($level)."'
'".Database::escape_string($extra)."',
'".Database::escape_string($level)."'
)";
Database::query($sql);
@ -644,10 +658,8 @@ abstract class Question
// If hotspot, create first answer
if ($type == HOT_SPOT || $type == HOT_SPOT_ORDER) {
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
$sql="INSERT INTO $TBL_ANSWERS (`id` , `question_id` , `answer` , `correct` , `comment` , `ponderation` , `position` , `hotspot_coordinates` , `hotspot_type` ) VALUES ('1', '".Database::escape_string($this->id)."', '', NULL , '', '10' , '1', '0;0|0|0', 'square')";
Database::query($sql);
}
if (api_get_setting('search_enabled')=='true') {
@ -1192,6 +1204,34 @@ abstract class Question
{
return self::$questionTypes;
}
static function saveQuestionOption($question_id, $name, $position = 0) {
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$params['question_id'] = intval($question_id);
$params['name'] = $name;
$params['position'] = $position;
$result = self::readQuestionOption($question_id);
$last_id = Database::insert($TBL_EXERCICE_QUESTION_OPTION, $params);
return $last_id;
}
static function deleteAllQuestionOptions($question_id) {
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
Database::delete($TBL_EXERCICE_QUESTION_OPTION, array('question_id = ?'=> $question_id));
}
static function updateQuestionOption($id, $params) {
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$result = Database::update_query($TBL_EXERCICE_QUESTION_OPTION, $params, array('id = ?'=>$id));
return $result;
}
static function readQuestionOption($question_id) {
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$result = Database::find($TBL_EXERCICE_QUESTION_OPTION, '*', array('question_id = ?' =>$question_id));
return $result;
}
}
endif;
?>

@ -139,9 +139,9 @@ if ($nbrQuestions) {
echo '<div id="question_id_list_'.$id.'" >';
$move = Display::return_icon('move.png',get_lang('Move'), array('class'=>'moved'));
echo Display::tag('h3','<a href="#">'.$move.' '.$objQuestionTmp->selectTitle().'</a>');
echo Display::tag('h3','<a href="#">'.$move.' '.$objQuestionTmp->selectTitle().'</a>');
echo '<div>';
echo '<p>';
echo $actions;

@ -224,22 +224,93 @@ class ExerciseShowFunctions {
* @param boolean Whether to show the answer comment or not
* @return void
*/
function display_multiple_answer_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) {
function display_multiple_answer_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) {
global $feedback_type;
?>
<tr>
<td width="5%" align="center">
<?php
//var_dump($studentChoice);
if ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) {
$question = new MultipleAnswerCombinationTrueFalse();
$question = new MultipleAnswerTrueFalse();
$new_options = Question::readQuestionOption($questionId);
if (isset($new_options[$studentChoice])) {
echo get_lang($new_options[$studentChoice]['name']);
} else {
echo '-';
}
?>
</td>
<td width="5%" align="center">
<?php
if (isset($new_options[$answerCorrect])) {
echo get_lang($new_options[$answerCorrect]['name']);
} else {
$question = new MultipleAnswerTrueFalse();
}
echo '-';
}
?>
</td>
<td width="40%" style="border-bottom: 1px solid #4171B5;">
<?php
$answer=text_filter($answer);
echo $answer;
?>
</td>
<?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
<td width="20%" style="border-bottom: 1px solid #4171B5;">
<?php
$answerComment=text_filter($answerComment);
if($studentChoice) {
if(!$answerCorrect) {
echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
} else {
echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
}
} else {
echo '&nbsp;';
}
?>
</td>
<?php
if ($ans==1) {
$comm = get_comments($id,$questionId);
}
?>
<?php } else { ?>
<td>&nbsp;</td>
<?php } ?>
</tr>
<?php
}
/**
* Display the answers to a multiple choice question
*
* @param integer Answer type
* @param integer Student choice
* @param string Textual answer
* @param string Comment on answer
* @param string Correct answer comment
* @param integer Exercise ID
* @param integer Question ID
* @param boolean Whether to show the answer comment or not
* @return void
*/
function display_multiple_answer_combination_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans) {
global $feedback_type;
?>
<tr>
<td width="5%" align="center">
<?php
//var_dump($studentChoice);
$question = new MultipleAnswerCombinationTrueFalse();
if (isset($question->options[$studentChoice])) {
echo $question->options[$studentChoice];
} else {
echo $question->options[2];
echo $question->options[2];
}
?>
</td>
@ -286,5 +357,5 @@ class ExerciseShowFunctions {
<?php } ?>
</tr>
<?php
}
}
}
Loading…
Cancel
Save