Minor - format code

pull/2487/head
jmontoyaa 9 years ago
parent da186f0311
commit e5aa87622d
  1. 43
      main/exercise/UniqueAnswerImage.php
  2. 1
      main/exercise/annotation_user.php
  3. 10
      main/exercise/calculated_answer.class.php
  4. 58
      main/exercise/fill_blanks.class.php
  5. 45
      main/exercise/global_multiple_answer.class.php
  6. 4
      main/exercise/hotpotatoes_exercise_result.class.php
  7. 11
      main/exercise/live_stats.php
  8. 30
      main/exercise/multiple_answer.class.php
  9. 10
      main/exercise/multiple_answer_combination.class.php
  10. 10
      main/exercise/multiple_answer_combination_true_false.class.php
  11. 46
      main/exercise/multiple_answer_true_false.class.php
  12. 6
      main/exercise/oral_expression.class.php
  13. 31
      main/exercise/unique_answer.class.php
  14. 189
      main/exercise/unique_answer_no_option.class.php

@ -30,7 +30,6 @@ class UniqueAnswerImage extends UniqueAnswer
public function createAnswersForm($form) public function createAnswersForm($form)
{ {
$objExercise = Session::read('objExercise'); $objExercise = Session::read('objExercise');
$editorConfig = array( $editorConfig = array(
'ToolbarSet' => 'TestFreeAnswer', 'ToolbarSet' => 'TestFreeAnswer',
'Width' => '100%', 'Width' => '100%',
@ -129,10 +128,11 @@ class UniqueAnswerImage extends UniqueAnswer
$correct = $i; $correct = $i;
} }
$defaults['answer[' . $i . ']'] = $answer->answer[$i]; $defaults['answer['.$i.']'] = $answer->answer[$i];
$defaults['comment[' . $i . ']'] = $answer->comment[$i]; $defaults['comment['.$i.']'] = $answer->comment[$i];
$defaults['weighting[' . $i . ']'] = float_format( $defaults['weighting['.$i.']'] = float_format(
$answer->weighting[$i], 1 $answer->weighting[$i],
1
); );
$itemList = explode('@@', $answer->destination[$i]); $itemList = explode('@@', $answer->destination[$i]);
@ -143,13 +143,11 @@ class UniqueAnswerImage extends UniqueAnswer
$url = $itemList[3]; $url = $itemList[3];
$try = 0; $try = 0;
if ($try != 0) { if ($try != 0) {
$tryResult = 1; $tryResult = 1;
} }
$urlResult = ''; $urlResult = '';
if ($url != 0) { if ($url != 0) {
$urlResult = $url; $urlResult = $url;
} }
@ -169,9 +167,7 @@ class UniqueAnswerImage extends UniqueAnswer
} }
$defaults['scenario'] = $tempScenario; $defaults['scenario'] = $tempScenario;
$renderer = $form->defaultRenderer(); $renderer = $form->defaultRenderer();
$renderer->setElementTemplate( $renderer->setElementTemplate(
'<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', '<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>',
'correct' 'correct'
@ -202,9 +198,15 @@ class UniqueAnswerImage extends UniqueAnswer
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
$form->addHtmlEditor('comment[' . $i . ']', null, null, false, $editorConfig); $form->addHtmlEditor(
'comment['.$i.']',
null,
null,
false,
$editorConfig
);
// Direct feedback // Direct feedback
//Adding extra feedback fields // Adding extra feedback fields
$group = array(); $group = array();
$group['try' . $i] = $form->createElement('checkbox', 'try' . $i, null, get_lang('TryAgain')); $group['try' . $i] = $form->createElement('checkbox', 'try' . $i, null, get_lang('TryAgain'));
$group['lp' . $i] = $form->createElement( $group['lp' . $i] = $form->createElement(
@ -243,16 +245,13 @@ class UniqueAnswerImage extends UniqueAnswer
$form->addHtml('</tbody>'); $form->addHtml('</tbody>');
$form->addHtml('</table>'); $form->addHtml('</table>');
global $text, $class; global $text;
$buttonGroup = []; $buttonGroup = [];
if ($objExercise->edit_exercise_in_lp == true) { if ($objExercise->edit_exercise_in_lp == true) {
//setting the save button here and not in the question class.php //setting the save button here and not in the question class.php
$buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true); $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true);
$buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true); $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true);
$buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true); $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true);
$form->addGroup($buttonGroup); $form->addGroup($buttonGroup);
} }
@ -318,8 +317,7 @@ class UniqueAnswerImage extends UniqueAnswer
$destinationStr.=$destination_id.';'; $destinationStr.=$destination_id.';';
} */ } */
$goodAnswer = ($correct == $i) ? true : false; $goodAnswer = $correct == $i ? true : false;
if ($goodAnswer) { if ($goodAnswer) {
$nbrGoodAnswers++; $nbrGoodAnswers++;
$weighting = abs($weighting); $weighting = abs($weighting);
@ -348,7 +346,16 @@ class UniqueAnswerImage extends UniqueAnswer
//1@@1;2;@@2;4;4;@@http://www.chamilo.org //1@@1;2;@@2;4;4;@@http://www.chamilo.org
$dest = $try . '@@' . $lp . '@@' . $destination . '@@' . $url; $dest = $try . '@@' . $lp . '@@' . $destination . '@@' . $url;
$objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting, $i, null, null, $dest); $objAnswer->createAnswer(
$answer,
$goodAnswer,
$comment,
$weighting,
$i,
null,
null,
$dest
);
} }
// saves the answers into the data base // saves the answers into the data base

@ -54,7 +54,6 @@ if (!empty($attemptList) && isset($attemptList[$questionId])) {
$data['answers']['paths'][] = $points; $data['answers']['paths'][] = $points;
break; break;
case 'T': case 'T':
$text = [ $text = [
'text' => array_shift($parts) 'text' => array_shift($parts)
]; ];

@ -158,7 +158,11 @@ class CalculatedAnswer extends Question
$form->setDefaults(array('weighting' => '10')); $form->setDefaults(array('weighting' => '10'));
$form->addElement('text', 'answerVariations', get_lang('AnswerVariations')); $form->addElement('text', 'answerVariations', get_lang('AnswerVariations'));
$form->addRule('answerVariations', get_lang('GiveAnswerVariations'),'required'); $form->addRule(
'answerVariations',
get_lang('GiveAnswerVariations'),
'required'
);
$form->setDefaults(array('answerVariations' => '1')); $form->setDefaults(array('answerVariations' => '1'));
global $text; global $text;
@ -199,12 +203,12 @@ class CalculatedAnswer extends Question
$this->weighting = $form->getSubmitValue('weighting'); $this->weighting = $form->getSubmitValue('weighting');
// Create as many answers as $answerVariations // Create as many answers as $answerVariations
for ($j=0 ; $j < $answerVariations; $j++) { for ($j = 0; $j < $answerVariations; $j++) {
$auxAnswer = $answer; $auxAnswer = $answer;
$auxFormula = $formula; $auxFormula = $formula;
$nb = preg_match_all('/\[[^\]]*\]/', $auxAnswer, $blanks); $nb = preg_match_all('/\[[^\]]*\]/', $auxAnswer, $blanks);
if ($nb > 0) { if ($nb > 0) {
for ($i=0 ; $i < $nb; ++$i) { for ($i = 0; $i < $nb; ++$i) {
$blankItem = $blanks[0][$i]; $blankItem = $blanks[0][$i];
$replace = array("[", "]"); $replace = array("[", "]");
$newBlankItem = str_replace($replace, "", $blankItem); $newBlankItem = str_replace($replace, "", $blankItem);

@ -2,11 +2,11 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Class FillBlanks * Class FillBlanks
* *
* @author Eric Marguin * @author Eric Marguin
* @author Julio Montoya multiple fill in blank option added * @author Julio Montoya multiple fill in blank option added
* @package chamilo.exercise * @package chamilo.exercise
**/ **/
class FillBlanks extends Question class FillBlanks extends Question
{ {
@ -430,7 +430,7 @@ class FillBlanks extends Question
// input width // input width
$answer .= ":"; $answer .= ":";
for ($i=0; $i < $nb; ++$i) { for ($i = 0; $i < $nb; ++$i) {
// enter the width of input for word $i // enter the width of input for word $i
$answer .= $form->getSubmitValue('sizeofinput['.$i.']'); $answer .= $form->getSubmitValue('sizeofinput['.$i.']');
// not the last word, add "," // not the last word, add ","
@ -1165,8 +1165,14 @@ class FillBlanks extends Question
* @param bool $showTotalScoreAndUserChoices * @param bool $showTotalScoreAndUserChoices
* @return string * @return string
*/ */
public static function getHtmlAnswer($answer, $correct, $right, $feedbackType, $resultsDisabled = false, $showTotalScoreAndUserChoices = false) public static function getHtmlAnswer(
{ $answer,
$correct,
$right,
$feedbackType,
$resultsDisabled = false,
$showTotalScoreAndUserChoices = false
) {
$hideExpectedAnswer = false; $hideExpectedAnswer = false;
if ($feedbackType == 0 && ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ONLY)) { if ($feedbackType == 0 && ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ONLY)) {
$hideExpectedAnswer = true; $hideExpectedAnswer = true;
@ -1191,7 +1197,7 @@ class FillBlanks extends Question
$listPossibleAnswers = self::getFillTheBlankMenuAnswers($correct, false); $listPossibleAnswers = self::getFillTheBlankMenuAnswers($correct, false);
$correctAnswerHtml .= "<span style='color: green'>".$listPossibleAnswers[0]."</span>"; $correctAnswerHtml .= "<span style='color: green'>".$listPossibleAnswers[0]."</span>";
$correctAnswerHtml .= " <span style='font-weight:normal'>("; $correctAnswerHtml .= " <span style='font-weight:normal'>(";
for ($i=1; $i < count($listPossibleAnswers); $i++) { for ($i = 1; $i < count($listPossibleAnswers); $i++) {
$correctAnswerHtml .= $listPossibleAnswers[$i]; $correctAnswerHtml .= $listPossibleAnswers[$i];
if ($i != count($listPossibleAnswers) - 1) { if ($i != count($listPossibleAnswers) - 1) {
$correctAnswerHtml .= " | "; $correctAnswerHtml .= " | ";
@ -1233,9 +1239,21 @@ class FillBlanks extends Question
* *
* @return string * @return string
*/ */
public static function getHtmlRightAnswer($answer, $correct, $feedbackType, $resultsDisabled = false, $showTotalScoreAndUserChoices = false) public static function getHtmlRightAnswer(
{ $answer,
return self::getHtmlAnswer($answer, $correct, true, $feedbackType, $resultsDisabled, $showTotalScoreAndUserChoices); $correct,
$feedbackType,
$resultsDisabled = false,
$showTotalScoreAndUserChoices = false
) {
return self::getHtmlAnswer(
$answer,
$correct,
true,
$feedbackType,
$resultsDisabled,
$showTotalScoreAndUserChoices
);
} }
/** /**
@ -1246,9 +1264,21 @@ class FillBlanks extends Question
* *
* @return string * @return string
*/ */
public static function getHtmlWrongAnswer($answer, $correct, $feedbackType, $resultsDisabled = false, $showTotalScoreAndUserChoices = false) public static function getHtmlWrongAnswer(
{ $answer,
return self::getHtmlAnswer($answer, $correct, false, $feedbackType, $resultsDisabled, $showTotalScoreAndUserChoices); $correct,
$feedbackType,
$resultsDisabled = false,
$showTotalScoreAndUserChoices = false
) {
return self::getHtmlAnswer(
$answer,
$correct,
false,
$feedbackType,
$resultsDisabled,
$showTotalScoreAndUserChoices
);
} }
/** /**

@ -12,7 +12,7 @@ class GlobalMultipleAnswer extends Question
public static $explanationLangVar = 'GlobalMultipleAnswer'; public static $explanationLangVar = 'GlobalMultipleAnswer';
/** /**
* * GlobalMultipleAnswer constructor.
*/ */
public function __construct() public function __construct()
{ {
@ -107,26 +107,51 @@ class GlobalMultipleAnswer extends Question
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment['.$i.']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment['.$i.']');
//$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting['.$i.']'); //$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting['.$i.']');
$answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"'); $answer_number = $form->addElement(
'text',
'counter['.$i.']',
null,
'value="'.$i.'"'
);
$answer_number->freeze(); $answer_number->freeze();
$form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox"'); $form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox"');
$boxes_names[] = 'correct[' . $i . ']'; $boxes_names[] = 'correct[' . $i . ']';
$form->addElement('html_editor', 'answer[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')); $form->addElement(
'html_editor',
'answer['.$i.']',
null,
array(),
array(
'ToolbarSet' => 'TestProposedAnswer',
'Width' => '100%',
'Height' => '100',
)
);
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement(
$form->addElement('html_editor', 'comment[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')); 'html_editor',
'comment['.$i.']',
null,
array(),
array(
'ToolbarSet' => 'TestProposedAnswer',
'Width' => '100%',
'Height' => '100',
)
);
$form->addElement('html', '</tr>'); $form->addElement('html', '</tr>');
} }
//--------- Mise en variable du score global lors d'une modification de la question/r<EFBFBD>ponse //--------- Mise en variable du score global lors d'une modification de la question/r<EFBFBD>ponse
$defaults['weighting[1]'] = (round($scoreG)); $defaults['weighting[1]'] = (round($scoreG));
$form->addElement('html', '</div></div></table>'); $form->addElement('html', '</div></div></table>');
$form->add_multiple_required_rule(
//$form -> addElement ('html', '<br />'); $boxes_names,
$form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required'); get_lang('ChooseAtLeastOneCheckbox'),
'multiple_required'
);
//only 1 answer the all deal ... //only 1 answer the all deal ...
$form->addElement('text', 'weighting[1]', get_lang('Score')); $form->addElement('text', 'weighting[1]', get_lang('Score'));
@ -138,7 +163,7 @@ class GlobalMultipleAnswer extends Question
// Affiche un message si le score n'est pas renseign<EFBFBD> // Affiche un message si le score n'est pas renseign<EFBFBD>
$form->addRule('weighting[1]', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('weighting[1]', get_lang('ThisFieldIsRequired'), 'required');
global $text, $class; global $text;
if ($obj_ex->edit_exercise_in_lp == true) { if ($obj_ex->edit_exercise_in_lp == true) {
$form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers'); $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers');

@ -26,8 +26,8 @@ class HotpotatoesExerciseResult
$TBL_USER = Database::get_main_table(TABLE_MAIN_USER); $TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
$TBL_TRACK_HOTPOTATOES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); $TBL_TRACK_HOTPOTATOES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
$cid = api_get_course_id(); $cid = api_get_course_id();
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
//$user_id = intval($user_id); //$user_id = intval($user_id);
$user_id = null; $user_id = null;
$session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' '; $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';

@ -93,7 +93,16 @@ function refreshGrid() {
$(function() { $(function() {
<?php <?php
echo Display::grid_js('live_stats', $url, $columns, $column_model, $extra_params, array(), null, true); echo Display::grid_js(
'live_stats',
$url,
$columns,
$column_model,
$extra_params,
array(),
null,
true
);
?> ?>
refreshGrid(); refreshGrid();
}); });

@ -123,9 +123,14 @@ class MultipleAnswer extends Question
$answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
$answer_number->freeze(); $answer_number->freeze();
$form->addElement('checkbox', 'correct[' . $i . ']', null, null, $form->addElement(
'class="checkbox" style="margin-left: 0em;"'); 'checkbox',
$boxes_names[] = 'correct[' . $i . ']'; 'correct['.$i.']',
null,
null,
'class="checkbox" style="margin-left: 0em;"'
);
$boxes_names[] = 'correct['.$i.']';
$form->addHtmlEditor("answer[$i]", null, null, true, $editorConfig); $form->addHtmlEditor("answer[$i]", null, null, true, $editorConfig);
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
@ -139,10 +144,13 @@ class MultipleAnswer extends Question
$form->addHtml('</tbody>'); $form->addHtml('</tbody>');
$form->addHtml('</table>'); $form->addHtml('</table>');
$form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required'); $form->add_multiple_required_rule(
$boxes_names,
get_lang('ChooseAtLeastOneCheckbox'),
'multiple_required'
);
$buttonGroup = []; $buttonGroup = [];
global $text; global $text;
if ($obj_ex->edit_exercise_in_lp == true) { if ($obj_ex->edit_exercise_in_lp == true) {
// setting the save button here and not in the question class.php // setting the save button here and not in the question class.php
@ -177,7 +185,7 @@ class MultipleAnswer extends Question
$objAnswer = new Answer($this->id); $objAnswer = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers'); $nb_answers = $form->getSubmitValue('nb_answers');
for($i=1 ; $i <= $nb_answers ; $i++) { for ($i = 1; $i <= $nb_answers; $i++) {
$answer = trim(str_replace(['<p>', '</p>'], '', $form -> getSubmitValue('answer['.$i.']'))); $answer = trim(str_replace(['<p>', '</p>'], '', $form -> getSubmitValue('answer['.$i.']')));
$comment = trim(str_replace(['<p>', '</p>'], '', $form -> getSubmitValue('comment['.$i.']'))); $comment = trim(str_replace(['<p>', '</p>'], '', $form -> getSubmitValue('comment['.$i.']')));
$weighting = trim($form -> getSubmitValue('weighting['.$i.']')); $weighting = trim($form -> getSubmitValue('weighting['.$i.']'));
@ -189,10 +197,16 @@ class MultipleAnswer extends Question
$weighting = abs($weighting); $weighting = abs($weighting);
$weighting = -$weighting; $weighting = -$weighting;
} }
if($weighting > 0) { if ($weighting > 0) {
$questionWeighting += $weighting; $questionWeighting += $weighting;
} }
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i); $objAnswer->createAnswer(
$answer,
$goodAnswer,
$comment,
$weighting,
$i
);
} }
// saves the answers into the data base // saves the answers into the data base

@ -112,8 +112,9 @@ class MultipleAnswerCombination extends Question
$answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
$answer_number->freeze(); $answer_number->freeze();
$form->addElement('checkbox', $form->addElement(
'correct[' . $i . ']', 'checkbox',
'correct['.$i.']',
null, null,
null, null,
'class="checkbox" style="margin-left: 0em;"' 'class="checkbox" style="margin-left: 0em;"'
@ -141,7 +142,6 @@ class MultipleAnswerCombination extends Question
} }
$form->addElement('html', '</tbody></table>'); $form->addElement('html', '</tbody></table>');
$form->add_multiple_required_rule( $form->add_multiple_required_rule(
$boxes_names, $boxes_names,
get_lang('ChooseAtLeastOneCheckbox'), get_lang('ChooseAtLeastOneCheckbox'),
@ -152,9 +152,7 @@ class MultipleAnswerCombination extends Question
$form->addText('weighting[1]', get_lang('Score'), false, ['value' => 10]); $form->addText('weighting[1]', get_lang('Score'), false, ['value' => 10]);
global $text; global $text;
//ie6 fix
if ($obj_ex->edit_exercise_in_lp == true) { if ($obj_ex->edit_exercise_in_lp == true) {
// setting the save button here and not in the question class.php // setting the save button here and not in the question class.php
$buttonGroup = [ $buttonGroup = [
$form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true), $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true),
@ -222,7 +220,7 @@ class MultipleAnswerCombination extends Question
// sets the total weighting of the question // sets the total weighting of the question
$this->updateWeighting($questionWeighting); $this->updateWeighting($questionWeighting);
$this->save(); $this->save();
} }
function return_header($feedback_type = null, $counter = null, $score = null) function return_header($feedback_type = null, $counter = null, $score = null)
{ {

@ -2,13 +2,13 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Class MultipleAnswerCombinationTrueFalse * Class MultipleAnswerCombinationTrueFalse
* *
* This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER), * This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER),
* extending the class question * extending the class question
* *
* @author Eric Marguin * @author Eric Marguin
* @package chamilo.exercise * @package chamilo.exercise
**/ **/
class MultipleAnswerCombinationTrueFalse extends MultipleAnswerCombination class MultipleAnswerCombinationTrueFalse extends MultipleAnswerCombination
{ {

@ -75,8 +75,6 @@ class MultipleAnswerTrueFalse extends Question
} }
$form->addElement('hidden', 'nb_answers'); $form->addElement('hidden', 'nb_answers');
$boxes_names = array();
if ($nb_answers < 1) { if ($nb_answers < 1) {
$nb_answers = 1; $nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
@ -139,8 +137,6 @@ class MultipleAnswerTrueFalse extends Question
$defaults['correct[' . $i . ']'] = ''; $defaults['correct[' . $i . ']'] = '';
} }
$boxes_names[] = 'correct[' . $i . ']';
$form->addHtmlEditor( $form->addHtmlEditor(
"answer[$i]", "answer[$i]",
get_lang('ThisFieldIsRequired'), get_lang('ThisFieldIsRequired'),
@ -221,7 +217,6 @@ class MultipleAnswerTrueFalse extends Question
} }
global $text; global $text;
if ($obj_ex->edit_exercise_in_lp == true) { if ($obj_ex->edit_exercise_in_lp == true) {
// setting the save button here and not in the question class.php // setting the save button here and not in the question class.php
$buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true); $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true);
@ -234,9 +229,7 @@ class MultipleAnswerTrueFalse extends Question
if (!empty($this->id)) { if (!empty($this->id)) {
$form->setDefaults($defaults); $form->setDefaults($defaults);
} else { } else {
//if ($this -> isContent == 1) {
$form->setDefaults($defaults); $form->setDefaults($defaults);
//}
} }
$form->setConstants(array('nb_answers' => $nb_answers)); $form->setConstants(array('nb_answers' => $nb_answers));
} }
@ -263,14 +256,14 @@ class MultipleAnswerTrueFalse extends Question
Question::updateQuestionOption($id, $optionData, $course_id); Question::updateQuestionOption($id, $optionData, $course_id);
} }
} else { } else {
for ($i=1 ; $i <= 3 ; $i++) { for ($i = 1; $i <= 3; $i++) {
$last_id = Question::saveQuestionOption( $last_id = Question::saveQuestionOption(
$this->id, $this->id,
$this->options[$i], $this->options[$i],
$course_id, $course_id,
$i $i
); );
$correct[$i] = $last_id; $correct[$i] = $last_id;
} }
} }
@ -278,7 +271,6 @@ class MultipleAnswerTrueFalse extends Question
it's possible that there are more options in the future */ it's possible that there are more options in the future */
$new_options = Question::readQuestionOption($this->id, $course_id); $new_options = Question::readQuestionOption($this->id, $course_id);
$sorted_by_position = array(); $sorted_by_position = array();
foreach ($new_options as $item) { foreach ($new_options as $item) {
$sorted_by_position[$item['position']] = $item; $sorted_by_position[$item['position']] = $item;
@ -288,13 +280,13 @@ class MultipleAnswerTrueFalse extends Question
the true, false, doubt options registered in this format the true, false, doubt options registered in this format
XX:YY:ZZZ where XX is a float score value.*/ XX:YY:ZZZ where XX is a float score value.*/
$extra_values = array(); $extra_values = array();
for ($i=1 ; $i <= 3 ; $i++) { for ($i = 1; $i <= 3; $i++) {
$score = trim($form -> getSubmitValue('option['.$i.']')); $score = trim($form -> getSubmitValue('option['.$i.']'));
$extra_values[]= $score; $extra_values[]= $score;
} }
$this->setExtra(implode(':', $extra_values)); $this->setExtra(implode(':', $extra_values));
for ($i = 1; $i <= $nb_answers; $i++) { for ($i = 1; $i <= $nb_answers; $i++) {
$answer = trim($form->getSubmitValue('answer['.$i.']')); $answer = trim($form->getSubmitValue('answer['.$i.']'));
$comment = trim($form->getSubmitValue('comment['.$i.']')); $comment = trim($form->getSubmitValue('comment['.$i.']'));
$goodAnswer = trim($form->getSubmitValue('correct['.$i.']')); $goodAnswer = trim($form->getSubmitValue('correct['.$i.']'));
@ -304,17 +296,15 @@ class MultipleAnswerTrueFalse extends Question
$goodAnswer = $sorted_by_position[$goodAnswer]['id']; $goodAnswer = $sorted_by_position[$goodAnswer]['id'];
} }
$questionWeighting += $extra_values[0]; //By default 0 has the correct answers $questionWeighting += $extra_values[0]; //By default 0 has the correct answers
$objAnswer->createAnswer($answer, $goodAnswer, $comment, '', $i);
$objAnswer->createAnswer($answer, $goodAnswer, $comment,'',$i);
} }
// saves the answers into the data base // saves the answers into the database
$objAnswer->save(); $objAnswer->save();
// sets the total weighting of the question // sets the total weighting of the question
$this->updateWeighting($questionWeighting); $this->updateWeighting($questionWeighting);
$this->save(); $this->save();
} }
/** /**
* @param int $feedback_type * @param int $feedback_type
@ -325,17 +315,17 @@ class MultipleAnswerTrueFalse extends Question
function return_header($feedback_type = null, $counter = null, $score = null) function return_header($feedback_type = null, $counter = null, $score = null)
{ {
$header = parent::return_header($feedback_type, $counter, $score); $header = parent::return_header($feedback_type, $counter, $score);
$header .= '<table class="'.$this->question_table_class .'"> $header .= '<table class="'.$this->question_table_class .'">
<tr> <tr>
<th>'.get_lang("Choice").'</th> <th>'.get_lang("Choice").'</th>
<th>'. get_lang("ExpectedChoice").'</th> <th>'. get_lang("ExpectedChoice").'</th>
<th>'. get_lang("Answer").'</th>'; <th>'. get_lang("Answer").'</th>';
if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) {
$header .= '<th>'.get_lang("Comment").'</th>'; $header .= '<th>'.get_lang("Comment").'</th>';
} else { } else {
$header .= '<th>&nbsp;</th>'; $header .= '<th>&nbsp;</th>';
} }
$header .= '</tr>'; $header .= '</tr>';
return $header; return $header;
} }
} }

@ -42,14 +42,14 @@ class OralExpression extends Question
get_lang('Weighting'), get_lang('Weighting'),
array('class' => 'span1') array('class' => 'span1')
); );
global $text, $class; global $text;
// setting the save button here and not in the question class.php // setting the save button here and not in the question class.php
$form->addButtonSave($text, 'submitQuestion'); $form->addButtonSave($text, 'submitQuestion');
if (!empty($this->id)) { if (!empty($this->id)) {
$form -> setDefaults(array('weighting' => float_format($this->weighting, 1))); $form -> setDefaults(array('weighting' => float_format($this->weighting, 1)));
} else { } else {
if ($this -> isContent == 1) { if ($this->isContent == 1) {
$form -> setDefaults(array('weighting' => '10')); $form->setDefaults(array('weighting' => '10'));
} }
} }
} }

@ -198,21 +198,37 @@ class UniqueAnswer extends Question
); );
$answer_number = $form->addElement( $answer_number = $form->addElement(
'text', 'counter[' . $i . ']', null, ' value = "' . $i . '"' 'text',
'counter['.$i.']',
null,
' value = "'.$i.'"'
); );
$answer_number->freeze(); $answer_number->freeze();
$form->addElement( $form->addElement(
'radio', 'correct', null, null, $i, 'class="checkbox"' 'radio',
'correct',
null,
null,
$i,
'class="checkbox"'
); );
$form->addHtmlEditor('answer[' . $i . ']', null, null, true, $editor_config); $form->addHtmlEditor('answer[' . $i . ']', null, null, true, $editor_config);
$form->addRule( $form->addRule(
'answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required' 'answer['.$i.']',
get_lang('ThisFieldIsRequired'),
'required'
); );
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
$form->addHtmlEditor('comment[' . $i . ']', null, null, false, $editor_config); $form->addHtmlEditor(
'comment['.$i.']',
null,
null,
false,
$editor_config
);
// Direct feedback // Direct feedback
//Adding extra feedback fields //Adding extra feedback fields
$group = array(); $group = array();
@ -260,16 +276,13 @@ class UniqueAnswer extends Question
$form->addHtml('</table>'); $form->addHtml('</table>');
global $text; global $text;
$buttonGroup = []; $buttonGroup = [];
//ie6 fix //ie6 fix
if ($obj_ex->edit_exercise_in_lp == true) { if ($obj_ex->edit_exercise_in_lp == true) {
//setting the save button here and not in the question class.php //setting the save button here and not in the question class.php
$buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true); $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true);
$buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true); $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true);
$buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true); $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true);
$form->addGroup($buttonGroup); $form->addGroup($buttonGroup);
} }
@ -440,8 +453,8 @@ class UniqueAnswer extends Question
$sql = "SELECT max(position) as max_position $sql = "SELECT max(position) as max_position
FROM $tbl_quiz_answer FROM $tbl_quiz_answer
WHERE WHERE
c_id = $course_id AND c_id = $course_id AND
question_id = $question_id"; question_id = $question_id";
$rs_max = Database::query($sql); $rs_max = Database::query($sql);
$row_max = Database::fetch_object($rs_max); $row_max = Database::fetch_object($rs_max);
$position = $row_max->max_position + 1; $position = $row_max->max_position + 1;

@ -49,7 +49,6 @@ class UniqueAnswerNoOption extends Question
$feedback_title = ''; $feedback_title = '';
$comment_title = ''; $comment_title = '';
if ($obj_ex->selectFeedbackType() == 1) { if ($obj_ex->selectFeedbackType() == 1) {
$editor_config['Width'] = '250'; $editor_config['Width'] = '250';
$editor_config['Height'] = '110'; $editor_config['Height'] = '110';
@ -86,7 +85,6 @@ class UniqueAnswerNoOption extends Question
} }
$temp_scenario = array(); $temp_scenario = array();
if ($nb_answers < 1) { if ($nb_answers < 1) {
$nb_answers = 1; $nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
@ -119,7 +117,6 @@ class UniqueAnswerNoOption extends Question
foreach ($new_list as $key) { foreach ($new_list as $key) {
$i = $key; $i = $key;
$form->addElement('html', '<tr>'); $form->addElement('html', '<tr>');
if (is_object($answer)) { if (is_object($answer)) {
if ($answer->position[$i] == 666) { if ($answer->position[$i] == 666) {
//we set nothing //we set nothing
@ -144,15 +141,17 @@ class UniqueAnswerNoOption extends Question
$list_dest = $item_list[2]; $list_dest = $item_list[2];
$url = $item_list[3]; $url = $item_list[3];
if ($try == 0) if ($try == 0) {
$try_result = 0; $try_result = 0;
else } else {
$try_result = 1; $try_result = 1;
}
if ($url == 0) if ($url == 0) {
$url_result = ''; $url_result = '';
else } else {
$url_result = $url; $url_result = $url;
}
$temp_scenario['url' . $i] = $url_result; $temp_scenario['url' . $i] = $url_result;
$temp_scenario['try' . $i] = $try_result; $temp_scenario['try' . $i] = $try_result;
@ -257,7 +256,7 @@ class UniqueAnswerNoOption extends Question
$buttonGroup = []; $buttonGroup = [];
global $text, $class; global $text;
//ie6 fix //ie6 fix
if ($obj_ex->edit_exercise_in_lp == true) { if ($obj_ex->edit_exercise_in_lp == true) {
//setting the save button here and not in the question class.php //setting the save button here and not in the question class.php
@ -291,96 +290,115 @@ class UniqueAnswerNoOption extends Question
*/ */
function processAnswersCreation($form) function processAnswersCreation($form)
{ {
$questionWeighting = $nbrGoodAnswers = 0; $questionWeighting = $nbrGoodAnswers = 0;
$correct = $form -> getSubmitValue('correct'); $correct = $form->getSubmitValue('correct');
$objAnswer = new Answer($this->id); $objAnswer = new Answer($this->id);
$nb_answers = $form -> getSubmitValue('nb_answers'); $nb_answers = $form->getSubmitValue('nb_answers');
$minus = 1; $minus = 1;
if ($form -> getSubmitValue('new_question')) { if ($form -> getSubmitValue('new_question')) {
$minus = 0; $minus = 0;
} }
for ($i=1 ; $i <= $nb_answers - $minus; $i++) { for ($i = 1; $i <= $nb_answers - $minus; $i++) {
$position = trim($form -> getSubmitValue('position['.$i.']')); $position = trim($form->getSubmitValue('position['.$i.']'));
$answer = trim($form -> getSubmitValue('answer['.$i.']')); $answer = trim($form->getSubmitValue('answer['.$i.']'));
$comment = trim($form -> getSubmitValue('comment['.$i.']')); $comment = trim($form->getSubmitValue('comment['.$i.']'));
$weighting = trim($form -> getSubmitValue('weighting['.$i.']')); $weighting = trim($form->getSubmitValue('weighting['.$i.']'));
$scenario = $form -> getSubmitValue('scenario'); $scenario = $form->getSubmitValue('scenario');
//$list_destination = $form -> getSubmitValue('destination'.$i); //$list_destination = $form -> getSubmitValue('destination'.$i);
//$destination_str = $form -> getSubmitValue('destination'.$i); //$destination_str = $form -> getSubmitValue('destination'.$i);
$try = $scenario['try'.$i]; $try = $scenario['try'.$i];
$lp = $scenario['lp'.$i]; $lp = $scenario['lp'.$i];
$destination = $scenario['destination'.$i]; $destination = $scenario['destination'.$i];
$url = trim($scenario['url'.$i]); $url = trim($scenario['url'.$i]);
/* /*
How we are going to parse the destination value How we are going to parse the destination value
here we parse the destination value which is a string here we parse the destination value which is a string
1@@3@@2;4;4;@@http://www.chamilo.org 1@@3@@2;4;4;@@http://www.chamilo.org
where: try_again@@lp_id@@selected_questions@@url where: try_again@@lp_id@@selected_questions@@url
try_again = is 1 || 0 try_again = is 1 || 0
lp_id = id of a learning path (0 if dont select) lp_id = id of a learning path (0 if dont select)
selected_questions= ids of questions selected_questions= ids of questions
url= an url url= an url
*/ */
/* /*
$destination_str=''; $destination_str='';
foreach ($list_destination as $destination_id) foreach ($list_destination as $destination_id)
{ {
$destination_str.=$destination_id.';'; $destination_str.=$destination_id.';';
}*/ }*/
$goodAnswer= ($correct == $i) ? true : false; $goodAnswer= ($correct == $i) ? true : false;
if ($goodAnswer) { if ($goodAnswer) {
$nbrGoodAnswers++; $nbrGoodAnswers++;
$weighting = abs($weighting); $weighting = abs($weighting);
if($weighting > 0) { if ($weighting > 0) {
$questionWeighting += $weighting; $questionWeighting += $weighting;
} }
} }
if (empty($try)) if (empty($try)) {
$try=0; $try = 0;
}
if (empty($lp)) { if (empty($lp)) {
$lp=0; $lp = 0;
} }
if (empty($destination)) { if (empty($destination)) {
$destination=0; $destination = 0;
} }
if ($url=='') { if ($url == '') {
$url=0; $url = 0;
} }
//1@@1;2;@@2;4;4;@@http://www.chamilo.org //1@@1;2;@@2;4;4;@@http://www.chamilo.org
$dest= $try.'@@'.$lp.'@@'.$destination.'@@'.$url; $dest= $try.'@@'.$lp.'@@'.$destination.'@@'.$url;
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i,NULL,NULL,$dest); $objAnswer->createAnswer(
$answer,
$goodAnswer,
$comment,
$weighting,
$i,
null,
null,
$dest
);
} }
//Create 666 answer //Create 666 answer
$i = 666; $i = 666;
$answer = trim($form -> getSubmitValue('answer['.$i.']')); $answer = trim($form->getSubmitValue('answer['.$i.']'));
$comment = trim($form -> getSubmitValue('comment['.$i.']')); $comment = trim($form->getSubmitValue('comment['.$i.']'));
$weighting = trim($form -> getSubmitValue('weighting['.$i.']')); $weighting = trim($form->getSubmitValue('weighting['.$i.']'));
$goodAnswer= ($correct == $i) ? true : false; $goodAnswer = $correct == $i ? true : false;
$dest = ''; $dest = '';
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i,NULL,NULL,$dest); $objAnswer->createAnswer(
$answer,
$goodAnswer,
$comment,
$weighting,
$i,
null,
null,
$dest
);
// saves the answers into the data base // saves the answers into the data base
$objAnswer -> save(); $objAnswer->save();
// sets the total weighting of the question // sets the total weighting of the question
$this -> updateWeighting($questionWeighting); $this->updateWeighting($questionWeighting);
$this -> save(); $this->save();
} }
function return_header($feedback_type = null, $counter = null, $score = null) function return_header($feedback_type = null, $counter = null, $score = null)
@ -393,6 +411,7 @@ class UniqueAnswerNoOption extends Question
<th>'. get_lang("Answer").'</th>'; <th>'. get_lang("Answer").'</th>';
$header .= '<th>'.get_lang("Comment").'</th>'; $header .= '<th>'.get_lang("Comment").'</th>';
$header .= '</tr>'; $header .= '</tr>';
return $header; return $header;
} }
} }

Loading…
Cancel
Save