skala
Julio Montoya 14 years ago
commit 330105eeed
  1. 1
      main/exercice/answer.class.php
  2. 23
      main/exercice/exercice.php
  3. 63
      main/exercice/exercise.class.php
  4. 10
      main/exercice/exercise.lib.php
  5. 9
      main/exercice/exercise_show.php
  6. 172
      main/exercice/multiple_answer_true_false.class.php
  7. 48
      main/exercice/question.class.php
  8. 2
      main/exercice/question_list_admin.inc.php
  9. 15
      main/inc/lib/add_course.lib.inc.php
  10. 130
      main/inc/lib/database.lib.php
  11. 7
      main/inc/lib/display.lib.php
  12. 79
      main/inc/lib/exercise_show_functions.lib.php
  13. 2
      main/install/migrate-db-1.8.7-1.8.8-pre.sql

@ -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

@ -779,7 +779,6 @@ if ($show == 'test') {
//Showing exercise title
$row['title']=text_filter($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 {

@ -1661,6 +1661,15 @@ class Exercise {
$questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType();
$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,6 +1696,7 @@ class Exercise {
}
$real_answers = array();
$quiz_question_options = Question::readQuestionOption($questionId);
for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
$answer = $objAnswerTmp->selectAnswer($answerId);
@ -1735,21 +1745,21 @@ class Exercise {
$numAnswer=$objAnswerTmp->selectAutoId($answerId);
$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;
}
$questionScore +=$true_score;
} else {
if ($quiz_question_options[$studentChoice]['name'] != 'DoubtScore') {
$questionScore += $false_score;
} else {
if ($studentChoice == 0 || $studentChoice == 1) {
$questionScore +=-0.5;
$totalScore +=-0.5;
$questionScore += $doubt_score;
}
}
$questionWeighting+=$true_score;
$totalScore +=$true_score;
//echo $studentChoice.' - '.$answerCorrect.' '.$questionScore.'<br />';
break;
case MULTIPLE_ANSWER :
if ($from_database) {
@ -1785,33 +1795,44 @@ class Exercise {
$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;
} 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 ($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;
}
@ -1823,7 +1844,6 @@ class Exercise {
}
}
}
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);
@ -2208,6 +2232,12 @@ class Exercise {
}
break;
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);
@ -2287,7 +2317,8 @@ class Exercise {
</tr>';
}
}
if($origin != 'learnpath') { ?>
if($origin != 'learnpath') {
?>
<tr>
<td colspan="<?php echo $colspan; ?>" align="left">
<?php

@ -90,6 +90,8 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
$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
// done easily (suggestions and answers are in the same table), so we
@ -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 != '') {
if (!empty($weight)) {
$score = $min_note + ($max_note - $min_note) * $score /$weight;
} else {
$score = $min_note;
}
$score_rounded = round($score, 2);
$weight = $max_note;
}

@ -326,10 +326,11 @@ if ($show_results) {
$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) {
@ -371,6 +372,8 @@ if ($show_results) {
//var_dump($question_result);
$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();
@ -391,6 +394,7 @@ if ($show_results) {
<?php
$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'));
}
/**
@ -46,13 +46,43 @@ class MultipleAnswerTrueFalse extends Question {
$obj_ex = $_SESSION['objExercise'];
$html='
<div class="row">
$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">
<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('Comment').'</th>';
}
$html .= '<th>
'.get_lang('Weighting').'
</th>
</tr>';
$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;
}
}
@ -94,26 +121,43 @@ class MultipleAnswerTrueFalse extends Question {
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for($i = 1 ; $i <= $nb_answers ; ++$i) {
if(is_object($answer)) {
// 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);
$defaults['correct['.$i.']'] = $answer -> correct[$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['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);" ' );
//$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');
$options_count = $form->getSubmitValue('options_count');
$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.']'));
$correct = array();
$options = Question::readQuestionOption($this->id);
if($goodAnswer){
$weighting = abs($weighting);
if (!empty($options)) {
foreach ($options as $option_data) {
$id = $option_data['id'];
unset($option_data['id']);
Question::updateQuestionOption($id, $option_data);
}
} else {
$weighting = abs($weighting);
$weighting = -$weighting;
for ($i=1 ; $i <= 3 ; $i++) {
$last_id = Question::saveQuestionOption($this->id, $this->options[$i], $i);
$correct[$i] = $last_id;
}
if($weighting > 0)
{
$questionWeighting += $weighting;
}
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i);
$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);
@ -533,6 +535,15 @@ abstract class Question
$this->question = $title;
}
/**
Sets the title
*/
public function setExtra($extra)
{
$this->extra = $extra;
}
/**
* Moves the temporary question "tmp" to "quiz-$questionId"
@ -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,13 +639,14 @@ 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($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;
?>

@ -140,8 +140,8 @@ 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 '<div>';
echo '<p>';
echo $actions;

@ -290,6 +290,7 @@ function update_Db_course($course_db_name) {
$TABLEQUIZQUESTION = $course_db_name . 'quiz_rel_question';
$TABLEQUIZQUESTIONLIST = $course_db_name . 'quiz_question';
$TABLEQUIZANSWERSLIST = $course_db_name . 'quiz_answer';
$TABLEQUIZQUESTIONOPTION = $course_db_name . 'quiz_question_option';
// Dropbox
$TABLETOOLDROPBOXPOST = $course_db_name . 'dropbox_post';
@ -674,6 +675,20 @@ function update_Db_course($course_db_name) {
)" . $charset_clause;
Database::query($sql);
// Exercise tool - answer options
$sql = "
CREATE TABLE `".$TABLEQUIZQUESTIONOPTION . "` (
id int NOT NULL auto_increment,
question_id int NOT NULL,
name varchar(255),
position int unsigned NOT NULL,
PRIMARY KEY (id)
)" . $charset_clause;
Database::query($sql);
// Exercise tool - Test/question relations
$sql = "
CREATE TABLE `".$TABLEQUIZQUESTION . "` (

@ -179,6 +179,7 @@ define('TABLE_QUIZ_QUESTION', 'quiz_question');
define('TABLE_QUIZ_TEST', 'quiz');
define('TABLE_QUIZ_ANSWER', 'quiz_answer');
define('TABLE_QUIZ_TEST_QUESTION', 'quiz_rel_question');
define('TABLE_QUIZ_QUESTION_OPTION','quiz_question_option');
// Linked resource table
define('TABLE_LINKED_RESOURCES', 'resource');
@ -1297,63 +1298,72 @@ class Database {
}
/*
DEPRECATED METHODS
*/
/**
* @deprecated Use api_get_language_isocode($language) instead.
*/
public static function get_language_isocode($language) {
return api_get_language_isocode($language);
}
/**
* @deprecated Use Database::insert_id() instead.
New useful DB functions
*/
public static function get_last_insert_id() {
return mysql_insert_id();
}
/**
* Experimental useful database insert
* @todo lot of stuff to do here
*/
public static function insert_query($table_name, $attributes) {
public static function insert($table_name, $attributes) {
if (empty($attributes) || empty($table_name)) {
return false;
}
$filtred_attributes = array();
foreach($attributes as $key => $value) {
$filtred_attributes[$key] = self::escape_string($value);
$filtred_attributes[$key] = "'".self::escape_string($value)."'";
}
$params = array_keys($filtred_attributes); //@todo check if the field exists in the table we should use a describe of that table
$values = array_values($filtred_attributes);
if (!empty($params) && !empty($values)) {
$sql = 'INSERT INTO '.$table_name.' ('.implode(',',array_keys($params)).') VALUES ('.implode(',',$values).')';
$sql = 'INSERT INTO '.$table_name.' ('.implode(',',$params).') VALUES ('.implode(',',$values).')';
$result = self::query($sql);
return $result;
return self::get_last_insert_id();
}
return false;
}
/**
* Experimental useful database update
* Experimental useful database finder
* @todo lot of stuff to do here
*/
public static function update_query($table_name, $attributes, $where = array()) {
if (!empty($table_name) && !empty($attributes)) {
$update_sql = '';
//Cleaning attributes
foreach ($attributes as $key=>$value) {
$value = self::escape_string($value);
$update_sql .= "$key = '$value' ";
public static function find($table_name, $columns = '*' , $where_conditions = array(), $option = 'ASSOC') {
$where_return = self::parse_where_conditions($where_conditions);
$columns_filtred = '';
if (is_array($columns)) {
$columns_filtred = implode(',', $columns);
} else {
if ($columns == '*') {
$columns_filtred = '*';
}
if (!empty($update_sql)) {
if (!empty($where)) {
//Parsing and cleaning the where conditions
$where_return ='';
foreach ($where as $condition => $value_array) {
}
$sql = "SELECT $columns_filtred FROM $table_name $where_return ";
$result = self::query($sql);
$array = array();
if ($result !== false) { // For isolation from database engine's behaviour.
while ($row = self::fetch_array($result, $option)) {
if (isset($row['id'])) {
$array[$row['id']] = $row;
} else {
$array[] = $row;
}
}
}
return $array;
}
/**
* Parses where conditionsof this form: array('id = ?' =>'4')
* @todo lot of stuff to do here
*/
private function parse_where_conditions($conditions) {
if (empty($conditions)) {
return '';
}
$where_return = '';
foreach ($conditions as $condition => $value_array) {
if (is_array($value_array)) {
$clean_values = array();
foreach($value_array as $item) {
@ -1370,10 +1380,43 @@ class Database {
$where_return .= $condition;
}
}
if (!empty($clean_values)) {
$where_return =" WHERE $where_return ";
if (!empty($where_return)) {
$where_return = " WHERE $where_return ";
}
return $where_return;
}
/**
* Experimental useful database update
* @todo lot of stuff to do here
*/
public static function delete($table_name, $where_conditions) {
$result = false;
$where_return = self::parse_where_conditions($where_conditions);
$sql = "DELETE FROM $table_name $where_return ";
$result = self::query($sql);
//@todo should return affected_rows for
return $result;
}
/**
* Experimental useful database update
* @todo lot of stuff to do here
*/
public static function update_query($table_name, $attributes, $where_conditions = array()) {
if (!empty($table_name) && !empty($attributes)) {
$update_sql = '';
//Cleaning attributes
foreach ($attributes as $key=>$value) {
$value = self::escape_string($value);
$update_sql .= "$key = '$value' ";
}
if (!empty($update_sql)) {
//Parsing and cleaning the where conditions
$where_return = self::parse_where_conditions($where_conditions);
$sql = "UPDATE $table_name SET $update_sql $where_return ";
$result = self::query($sql);
return $result;
@ -1381,5 +1424,24 @@ class Database {
}
return false;
}
/*
DEPRECATED METHODS
*/
/**
* @deprecated Use api_get_language_isocode($language) instead.
*/
public static function get_language_isocode($language) {
return api_get_language_isocode($language);
}
/**
* @deprecated Use Database::insert_id() instead.
*/
public static function get_last_insert_id() {
return mysql_insert_id();
}
}
//end class Database

@ -703,6 +703,13 @@ class Display {
return $return_value;
}
public static function url($name, $url, $extra_attributes = array()) {
if (!empty($url)) {
$extra_attributes['href']= $url;
}
return self::tag('a', $name, $extra_attributes);
}
public function select($name, $values, $default = -1, $parameter_list = array(), $show_blank_item = true) {
$extra = '';
foreach($parameter_list as $key=>$parameter) {

@ -230,12 +230,83 @@ class ExerciseShowFunctions {
<tr>
<td width="5%" align="center">
<?php
//var_dump($studentChoice);
if ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) {
$question = new MultipleAnswerCombinationTrueFalse();
} else {
$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 {
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 {

@ -116,12 +116,12 @@ ALTER TABLE lp_item MODIFY COLUMN max_score FLOAT UNSIGNED DEFAULT 100;
ALTER TABLE tool MODIFY COLUMN category varchar(20) not null default 'authoring';
ALTER TABLE lp ADD COLUMN autolunch INT DEFAULT 0;
ALTER TABLE lp ADD COLUMN created_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
ALTER TABLE lp ADD COLUMN modified_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
ALTER TABLE lp ADD COLUMN expired_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
ALTER TABLE lp ADD COLUMN publicated_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
CREATE TABLE quiz_question_option (id int NOT NULL, name varchar(255), position int unsigned NOT NULL, PRIMARY KEY (id));
INSERT INTO course_setting(variable,value,category) VALUES ('enable_lp_auto_launch',0,'learning_path');
INSERT INTO course_setting(variable,value,category) VALUES ('pdf_export_watermark_text','','course');

Loading…
Cancel
Save