From e5aa87622ddbb4441aa60dddc2571b1166ffef3e Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 28 Mar 2017 09:12:24 +0200 Subject: [PATCH] Minor - format code --- main/exercise/UniqueAnswerImage.php | 43 ++-- main/exercise/annotation_user.php | 1 - main/exercise/calculated_answer.class.php | 10 +- main/exercise/fill_blanks.class.php | 58 ++++-- .../exercise/global_multiple_answer.class.php | 45 ++++- .../hotpotatoes_exercise_result.class.php | 4 +- main/exercise/live_stats.php | 11 +- main/exercise/multiple_answer.class.php | 30 ++- .../multiple_answer_combination.class.php | 10 +- ...le_answer_combination_true_false.class.php | 10 +- .../multiple_answer_true_false.class.php | 46 ++--- main/exercise/oral_expression.class.php | 6 +- main/exercise/unique_answer.class.php | 31 ++- .../unique_answer_no_option.class.php | 189 ++++++++++-------- 14 files changed, 301 insertions(+), 193 deletions(-) diff --git a/main/exercise/UniqueAnswerImage.php b/main/exercise/UniqueAnswerImage.php index ddd42de5ae..72f7806f84 100644 --- a/main/exercise/UniqueAnswerImage.php +++ b/main/exercise/UniqueAnswerImage.php @@ -30,7 +30,6 @@ class UniqueAnswerImage extends UniqueAnswer public function createAnswersForm($form) { $objExercise = Session::read('objExercise'); - $editorConfig = array( 'ToolbarSet' => 'TestFreeAnswer', 'Width' => '100%', @@ -129,10 +128,11 @@ class UniqueAnswerImage extends UniqueAnswer $correct = $i; } - $defaults['answer[' . $i . ']'] = $answer->answer[$i]; - $defaults['comment[' . $i . ']'] = $answer->comment[$i]; - $defaults['weighting[' . $i . ']'] = float_format( - $answer->weighting[$i], 1 + $defaults['answer['.$i.']'] = $answer->answer[$i]; + $defaults['comment['.$i.']'] = $answer->comment[$i]; + $defaults['weighting['.$i.']'] = float_format( + $answer->weighting[$i], + 1 ); $itemList = explode('@@', $answer->destination[$i]); @@ -143,13 +143,11 @@ class UniqueAnswerImage extends UniqueAnswer $url = $itemList[3]; $try = 0; - if ($try != 0) { $tryResult = 1; } $urlResult = ''; - if ($url != 0) { $urlResult = $url; } @@ -169,9 +167,7 @@ class UniqueAnswerImage extends UniqueAnswer } $defaults['scenario'] = $tempScenario; - $renderer = $form->defaultRenderer(); - $renderer->setElementTemplate( '{error}
{element}', 'correct' @@ -202,9 +198,15 @@ class UniqueAnswerImage extends UniqueAnswer $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); 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 - //Adding extra feedback fields + // Adding extra feedback fields $group = array(); $group['try' . $i] = $form->createElement('checkbox', 'try' . $i, null, get_lang('TryAgain')); $group['lp' . $i] = $form->createElement( @@ -243,16 +245,13 @@ class UniqueAnswerImage extends UniqueAnswer $form->addHtml(''); $form->addHtml(''); - global $text, $class; - + global $text; $buttonGroup = []; - if ($objExercise->edit_exercise_in_lp == true) { //setting the save button here and not in the question class.php $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true); $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true); $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true); - $form->addGroup($buttonGroup); } @@ -318,8 +317,7 @@ class UniqueAnswerImage extends UniqueAnswer $destinationStr.=$destination_id.';'; } */ - $goodAnswer = ($correct == $i) ? true : false; - + $goodAnswer = $correct == $i ? true : false; if ($goodAnswer) { $nbrGoodAnswers++; $weighting = abs($weighting); @@ -348,7 +346,16 @@ class UniqueAnswerImage extends UniqueAnswer //1@@1;2;@@2;4;4;@@http://www.chamilo.org $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 diff --git a/main/exercise/annotation_user.php b/main/exercise/annotation_user.php index 0a3407f4fa..f7dfc49f16 100644 --- a/main/exercise/annotation_user.php +++ b/main/exercise/annotation_user.php @@ -54,7 +54,6 @@ if (!empty($attemptList) && isset($attemptList[$questionId])) { $data['answers']['paths'][] = $points; break; case 'T': - $text = [ 'text' => array_shift($parts) ]; diff --git a/main/exercise/calculated_answer.class.php b/main/exercise/calculated_answer.class.php index bb312cd5f3..6468f03e29 100644 --- a/main/exercise/calculated_answer.class.php +++ b/main/exercise/calculated_answer.class.php @@ -158,7 +158,11 @@ class CalculatedAnswer extends Question $form->setDefaults(array('weighting' => '10')); $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')); global $text; @@ -199,12 +203,12 @@ class CalculatedAnswer extends Question $this->weighting = $form->getSubmitValue('weighting'); // Create as many answers as $answerVariations - for ($j=0 ; $j < $answerVariations; $j++) { + for ($j = 0; $j < $answerVariations; $j++) { $auxAnswer = $answer; $auxFormula = $formula; $nb = preg_match_all('/\[[^\]]*\]/', $auxAnswer, $blanks); if ($nb > 0) { - for ($i=0 ; $i < $nb; ++$i) { + for ($i = 0; $i < $nb; ++$i) { $blankItem = $blanks[0][$i]; $replace = array("[", "]"); $newBlankItem = str_replace($replace, "", $blankItem); diff --git a/main/exercise/fill_blanks.class.php b/main/exercise/fill_blanks.class.php index b5b76b7205..4d7e99e80d 100755 --- a/main/exercise/fill_blanks.class.php +++ b/main/exercise/fill_blanks.class.php @@ -2,11 +2,11 @@ /* For licensing terms, see /license.txt */ /** - * Class FillBlanks + * Class FillBlanks * - * @author Eric Marguin - * @author Julio Montoya multiple fill in blank option added - * @package chamilo.exercise + * @author Eric Marguin + * @author Julio Montoya multiple fill in blank option added + * @package chamilo.exercise **/ class FillBlanks extends Question { @@ -430,7 +430,7 @@ class FillBlanks extends Question // input width $answer .= ":"; - for ($i=0; $i < $nb; ++$i) { + for ($i = 0; $i < $nb; ++$i) { // enter the width of input for word $i $answer .= $form->getSubmitValue('sizeofinput['.$i.']'); // not the last word, add "," @@ -1165,8 +1165,14 @@ class FillBlanks extends Question * @param bool $showTotalScoreAndUserChoices * @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; if ($feedbackType == 0 && ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ONLY)) { $hideExpectedAnswer = true; @@ -1191,7 +1197,7 @@ class FillBlanks extends Question $listPossibleAnswers = self::getFillTheBlankMenuAnswers($correct, false); $correctAnswerHtml .= "".$listPossibleAnswers[0].""; $correctAnswerHtml .= " ("; - for ($i=1; $i < count($listPossibleAnswers); $i++) { + for ($i = 1; $i < count($listPossibleAnswers); $i++) { $correctAnswerHtml .= $listPossibleAnswers[$i]; if ($i != count($listPossibleAnswers) - 1) { $correctAnswerHtml .= " | "; @@ -1233,9 +1239,21 @@ class FillBlanks extends Question * * @return string */ - public static function getHtmlRightAnswer($answer, $correct, $feedbackType, $resultsDisabled = false, $showTotalScoreAndUserChoices = false) - { - return self::getHtmlAnswer($answer, $correct, true, $feedbackType, $resultsDisabled, $showTotalScoreAndUserChoices); + public static function getHtmlRightAnswer( + $answer, + $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 */ - public static function getHtmlWrongAnswer($answer, $correct, $feedbackType, $resultsDisabled = false, $showTotalScoreAndUserChoices = false) - { - return self::getHtmlAnswer($answer, $correct, false, $feedbackType, $resultsDisabled, $showTotalScoreAndUserChoices); + public static function getHtmlWrongAnswer( + $answer, + $correct, + $feedbackType, + $resultsDisabled = false, + $showTotalScoreAndUserChoices = false + ) { + return self::getHtmlAnswer( + $answer, + $correct, + false, + $feedbackType, + $resultsDisabled, + $showTotalScoreAndUserChoices + ); } /** diff --git a/main/exercise/global_multiple_answer.class.php b/main/exercise/global_multiple_answer.class.php index 5ff496232e..dc642ddd44 100755 --- a/main/exercise/global_multiple_answer.class.php +++ b/main/exercise/global_multiple_answer.class.php @@ -12,7 +12,7 @@ class GlobalMultipleAnswer extends Question public static $explanationLangVar = 'GlobalMultipleAnswer'; /** - * + * GlobalMultipleAnswer constructor. */ public function __construct() { @@ -107,26 +107,51 @@ class GlobalMultipleAnswer extends Question $renderer->setElementTemplate('{error}
{element}', 'comment['.$i.']'); //$renderer->setElementTemplate('{error}
{element}', '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(); $form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox"'); $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->addElement('html_editor', 'comment[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')); + $form->addElement( + 'html_editor', + 'comment['.$i.']', + null, + array(), + array( + 'ToolbarSet' => 'TestProposedAnswer', + 'Width' => '100%', + 'Height' => '100', + ) + ); $form->addElement('html', ''); } //--------- Mise en variable du score global lors d'une modification de la question/r�ponse $defaults['weighting[1]'] = (round($scoreG)); - $form->addElement('html', ''); - - //$form -> addElement ('html', '
'); - $form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required'); + $form->add_multiple_required_rule( + $boxes_names, + get_lang('ChooseAtLeastOneCheckbox'), + 'multiple_required' + ); //only 1 answer the all deal ... $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� $form->addRule('weighting[1]', get_lang('ThisFieldIsRequired'), 'required'); - global $text, $class; + global $text; if ($obj_ex->edit_exercise_in_lp == true) { $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers'); diff --git a/main/exercise/hotpotatoes_exercise_result.class.php b/main/exercise/hotpotatoes_exercise_result.class.php index cd6ce11cb2..6417754fe2 100755 --- a/main/exercise/hotpotatoes_exercise_result.class.php +++ b/main/exercise/hotpotatoes_exercise_result.class.php @@ -26,8 +26,8 @@ class HotpotatoesExerciseResult $TBL_USER = Database::get_main_table(TABLE_MAIN_USER); $TBL_TRACK_HOTPOTATOES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); - $cid = api_get_course_id(); - $course_id = api_get_course_int_id(); + $cid = api_get_course_id(); + $course_id = api_get_course_int_id(); //$user_id = intval($user_id); $user_id = null; $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' '; diff --git a/main/exercise/live_stats.php b/main/exercise/live_stats.php index 7f407a9e6f..9d4d6f46df 100755 --- a/main/exercise/live_stats.php +++ b/main/exercise/live_stats.php @@ -93,7 +93,16 @@ function refreshGrid() { $(function() { refreshGrid(); }); diff --git a/main/exercise/multiple_answer.class.php b/main/exercise/multiple_answer.class.php index fff5fbd9fd..a77ca493b9 100755 --- a/main/exercise/multiple_answer.class.php +++ b/main/exercise/multiple_answer.class.php @@ -123,9 +123,14 @@ class MultipleAnswer extends Question $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"'); $answer_number->freeze(); - $form->addElement('checkbox', 'correct[' . $i . ']', null, null, - 'class="checkbox" style="margin-left: 0em;"'); - $boxes_names[] = 'correct[' . $i . ']'; + $form->addElement( + 'checkbox', + 'correct['.$i.']', + null, + null, + 'class="checkbox" style="margin-left: 0em;"' + ); + $boxes_names[] = 'correct['.$i.']'; $form->addHtmlEditor("answer[$i]", null, null, true, $editorConfig); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); @@ -139,10 +144,13 @@ class MultipleAnswer extends Question $form->addHtml(''); $form->addHtml(''); - $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 = []; - global $text; if ($obj_ex->edit_exercise_in_lp == true) { // 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); $nb_answers = $form->getSubmitValue('nb_answers'); - for($i=1 ; $i <= $nb_answers ; $i++) { + for ($i = 1; $i <= $nb_answers; $i++) { $answer = trim(str_replace(['

', '

'], '', $form -> getSubmitValue('answer['.$i.']'))); $comment = trim(str_replace(['

', '

'], '', $form -> getSubmitValue('comment['.$i.']'))); $weighting = trim($form -> getSubmitValue('weighting['.$i.']')); @@ -189,10 +197,16 @@ class MultipleAnswer extends Question $weighting = abs($weighting); $weighting = -$weighting; } - if($weighting > 0) { + if ($weighting > 0) { $questionWeighting += $weighting; } - $objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i); + $objAnswer->createAnswer( + $answer, + $goodAnswer, + $comment, + $weighting, + $i + ); } // saves the answers into the data base diff --git a/main/exercise/multiple_answer_combination.class.php b/main/exercise/multiple_answer_combination.class.php index e7e8b0b695..b5f1baa361 100755 --- a/main/exercise/multiple_answer_combination.class.php +++ b/main/exercise/multiple_answer_combination.class.php @@ -112,8 +112,9 @@ class MultipleAnswerCombination extends Question $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"'); $answer_number->freeze(); - $form->addElement('checkbox', - 'correct[' . $i . ']', + $form->addElement( + 'checkbox', + 'correct['.$i.']', null, null, 'class="checkbox" style="margin-left: 0em;"' @@ -141,7 +142,6 @@ class MultipleAnswerCombination extends Question } $form->addElement('html', ''); - $form->add_multiple_required_rule( $boxes_names, get_lang('ChooseAtLeastOneCheckbox'), @@ -152,9 +152,7 @@ class MultipleAnswerCombination extends Question $form->addText('weighting[1]', get_lang('Score'), false, ['value' => 10]); global $text; - //ie6 fix if ($obj_ex->edit_exercise_in_lp == true) { - // setting the save button here and not in the question class.php $buttonGroup = [ $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true), @@ -222,7 +220,7 @@ class MultipleAnswerCombination extends Question // sets the total weighting of the question $this->updateWeighting($questionWeighting); $this->save(); - } + } function return_header($feedback_type = null, $counter = null, $score = null) { diff --git a/main/exercise/multiple_answer_combination_true_false.class.php b/main/exercise/multiple_answer_combination_true_false.class.php index cfe81b23fd..c14d529d97 100755 --- a/main/exercise/multiple_answer_combination_true_false.class.php +++ b/main/exercise/multiple_answer_combination_true_false.class.php @@ -2,13 +2,13 @@ /* 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), - * extending the class question + * This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER), + * extending the class question * - * @author Eric Marguin - * @package chamilo.exercise + * @author Eric Marguin + * @package chamilo.exercise **/ class MultipleAnswerCombinationTrueFalse extends MultipleAnswerCombination { diff --git a/main/exercise/multiple_answer_true_false.class.php b/main/exercise/multiple_answer_true_false.class.php index 02972bd061..b335595013 100755 --- a/main/exercise/multiple_answer_true_false.class.php +++ b/main/exercise/multiple_answer_true_false.class.php @@ -75,8 +75,6 @@ class MultipleAnswerTrueFalse extends Question } $form->addElement('hidden', 'nb_answers'); - $boxes_names = array(); - if ($nb_answers < 1) { $nb_answers = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); @@ -139,8 +137,6 @@ class MultipleAnswerTrueFalse extends Question $defaults['correct[' . $i . ']'] = ''; } - $boxes_names[] = 'correct[' . $i . ']'; - $form->addHtmlEditor( "answer[$i]", get_lang('ThisFieldIsRequired'), @@ -221,7 +217,6 @@ class MultipleAnswerTrueFalse extends Question } global $text; - if ($obj_ex->edit_exercise_in_lp == true) { // setting the save button here and not in the question class.php $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true); @@ -234,9 +229,7 @@ class MultipleAnswerTrueFalse extends Question if (!empty($this->id)) { $form->setDefaults($defaults); } else { - //if ($this -> isContent == 1) { $form->setDefaults($defaults); - //} } $form->setConstants(array('nb_answers' => $nb_answers)); } @@ -263,14 +256,14 @@ class MultipleAnswerTrueFalse extends Question Question::updateQuestionOption($id, $optionData, $course_id); } } else { - for ($i=1 ; $i <= 3 ; $i++) { + for ($i = 1; $i <= 3; $i++) { $last_id = Question::saveQuestionOption( $this->id, $this->options[$i], $course_id, $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 */ $new_options = Question::readQuestionOption($this->id, $course_id); - $sorted_by_position = array(); foreach ($new_options as $item) { $sorted_by_position[$item['position']] = $item; @@ -288,13 +280,13 @@ class MultipleAnswerTrueFalse extends Question the true, false, doubt options registered in this format XX:YY:ZZZ where XX is a float score value.*/ $extra_values = array(); - for ($i=1 ; $i <= 3 ; $i++) { + 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++) { + 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.']')); @@ -304,17 +296,15 @@ class MultipleAnswerTrueFalse extends Question $goodAnswer = $sorted_by_position[$goodAnswer]['id']; } $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(); - // sets the total weighting of the question $this->updateWeighting($questionWeighting); $this->save(); - } + } /** * @param int $feedback_type @@ -325,17 +315,17 @@ class MultipleAnswerTrueFalse extends Question function return_header($feedback_type = null, $counter = null, $score = null) { $header = parent::return_header($feedback_type, $counter, $score); - $header .= ' - - - - '; - if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { - $header .= ''; - } else { - $header .= ''; - } + $header .= '
'.get_lang("Choice").''. get_lang("ExpectedChoice").''. get_lang("Answer").''.get_lang("Comment").' 
+ + + + '; + if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { + $header .= ''; + } else { + $header .= ''; + } $header .= ''; return $header; - } + } } diff --git a/main/exercise/oral_expression.class.php b/main/exercise/oral_expression.class.php index 5a7b843dfd..b913a5ff92 100755 --- a/main/exercise/oral_expression.class.php +++ b/main/exercise/oral_expression.class.php @@ -42,14 +42,14 @@ class OralExpression extends Question get_lang('Weighting'), array('class' => 'span1') ); - global $text, $class; + global $text; // setting the save button here and not in the question class.php $form->addButtonSave($text, 'submitQuestion'); if (!empty($this->id)) { $form -> setDefaults(array('weighting' => float_format($this->weighting, 1))); } else { - if ($this -> isContent == 1) { - $form -> setDefaults(array('weighting' => '10')); + if ($this->isContent == 1) { + $form->setDefaults(array('weighting' => '10')); } } } diff --git a/main/exercise/unique_answer.class.php b/main/exercise/unique_answer.class.php index 4f148774b7..bc76e327af 100755 --- a/main/exercise/unique_answer.class.php +++ b/main/exercise/unique_answer.class.php @@ -198,21 +198,37 @@ class UniqueAnswer extends Question ); $answer_number = $form->addElement( - 'text', 'counter[' . $i . ']', null, ' value = "' . $i . '"' + 'text', + 'counter['.$i.']', + null, + ' value = "'.$i.'"' ); $answer_number->freeze(); $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->addRule( - 'answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required' + 'answer['.$i.']', + get_lang('ThisFieldIsRequired'), + 'required' ); 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 //Adding extra feedback fields $group = array(); @@ -260,16 +276,13 @@ class UniqueAnswer extends Question $form->addHtml('
'.get_lang("Choice").''. get_lang("ExpectedChoice").''. get_lang("Answer").''.get_lang("Comment").' 
'); global $text; - $buttonGroup = []; //ie6 fix if ($obj_ex->edit_exercise_in_lp == true) { - //setting the save button here and not in the question class.php $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true); $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true); $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true); - $form->addGroup($buttonGroup); } @@ -440,8 +453,8 @@ class UniqueAnswer extends Question $sql = "SELECT max(position) as max_position FROM $tbl_quiz_answer WHERE - c_id = $course_id AND - question_id = $question_id"; + c_id = $course_id AND + question_id = $question_id"; $rs_max = Database::query($sql); $row_max = Database::fetch_object($rs_max); $position = $row_max->max_position + 1; diff --git a/main/exercise/unique_answer_no_option.class.php b/main/exercise/unique_answer_no_option.class.php index f9474c026e..d466e9f4dc 100755 --- a/main/exercise/unique_answer_no_option.class.php +++ b/main/exercise/unique_answer_no_option.class.php @@ -49,7 +49,6 @@ class UniqueAnswerNoOption extends Question $feedback_title = ''; $comment_title = ''; - if ($obj_ex->selectFeedbackType() == 1) { $editor_config['Width'] = '250'; $editor_config['Height'] = '110'; @@ -86,7 +85,6 @@ class UniqueAnswerNoOption extends Question } $temp_scenario = array(); - if ($nb_answers < 1) { $nb_answers = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); @@ -119,7 +117,6 @@ class UniqueAnswerNoOption extends Question foreach ($new_list as $key) { $i = $key; $form->addElement('html', ''); - if (is_object($answer)) { if ($answer->position[$i] == 666) { //we set nothing @@ -144,15 +141,17 @@ class UniqueAnswerNoOption extends Question $list_dest = $item_list[2]; $url = $item_list[3]; - if ($try == 0) + if ($try == 0) { $try_result = 0; - else + } else { $try_result = 1; + } - if ($url == 0) + if ($url == 0) { $url_result = ''; - else + } else { $url_result = $url; + } $temp_scenario['url' . $i] = $url_result; $temp_scenario['try' . $i] = $try_result; @@ -257,7 +256,7 @@ class UniqueAnswerNoOption extends Question $buttonGroup = []; - global $text, $class; + global $text; //ie6 fix if ($obj_ex->edit_exercise_in_lp == true) { //setting the save button here and not in the question class.php @@ -291,96 +290,115 @@ class UniqueAnswerNoOption extends Question */ function processAnswersCreation($form) { - $questionWeighting = $nbrGoodAnswers = 0; - $correct = $form -> getSubmitValue('correct'); - $objAnswer = new Answer($this->id); - $nb_answers = $form -> getSubmitValue('nb_answers'); - $minus = 1; - if ($form -> getSubmitValue('new_question')) { - $minus = 0; - } - - for ($i=1 ; $i <= $nb_answers - $minus; $i++) { - $position = trim($form -> getSubmitValue('position['.$i.']')); - $answer = trim($form -> getSubmitValue('answer['.$i.']')); - $comment = trim($form -> getSubmitValue('comment['.$i.']')); - $weighting = trim($form -> getSubmitValue('weighting['.$i.']')); - $scenario = $form -> getSubmitValue('scenario'); - - //$list_destination = $form -> getSubmitValue('destination'.$i); - //$destination_str = $form -> getSubmitValue('destination'.$i); - - $try = $scenario['try'.$i]; - $lp = $scenario['lp'.$i]; - $destination = $scenario['destination'.$i]; - $url = trim($scenario['url'.$i]); - - /* - How we are going to parse the destination value - - here we parse the destination value which is a string - 1@@3@@2;4;4;@@http://www.chamilo.org - - where: try_again@@lp_id@@selected_questions@@url - - try_again = is 1 || 0 - lp_id = id of a learning path (0 if dont select) - selected_questions= ids of questions - url= an url - */ - /* - $destination_str=''; - foreach ($list_destination as $destination_id) - { - $destination_str.=$destination_id.';'; - }*/ - - $goodAnswer= ($correct == $i) ? true : false; - - if ($goodAnswer) { - $nbrGoodAnswers++; - $weighting = abs($weighting); - if($weighting > 0) { + $questionWeighting = $nbrGoodAnswers = 0; + $correct = $form->getSubmitValue('correct'); + $objAnswer = new Answer($this->id); + $nb_answers = $form->getSubmitValue('nb_answers'); + $minus = 1; + if ($form -> getSubmitValue('new_question')) { + $minus = 0; + } + + for ($i = 1; $i <= $nb_answers - $minus; $i++) { + $position = trim($form->getSubmitValue('position['.$i.']')); + $answer = trim($form->getSubmitValue('answer['.$i.']')); + $comment = trim($form->getSubmitValue('comment['.$i.']')); + $weighting = trim($form->getSubmitValue('weighting['.$i.']')); + $scenario = $form->getSubmitValue('scenario'); + + //$list_destination = $form -> getSubmitValue('destination'.$i); + //$destination_str = $form -> getSubmitValue('destination'.$i); + + $try = $scenario['try'.$i]; + $lp = $scenario['lp'.$i]; + $destination = $scenario['destination'.$i]; + $url = trim($scenario['url'.$i]); + + /* + How we are going to parse the destination value + + here we parse the destination value which is a string + 1@@3@@2;4;4;@@http://www.chamilo.org + + where: try_again@@lp_id@@selected_questions@@url + + try_again = is 1 || 0 + lp_id = id of a learning path (0 if dont select) + selected_questions= ids of questions + url= an url + */ + /* + $destination_str=''; + foreach ($list_destination as $destination_id) + { + $destination_str.=$destination_id.';'; + }*/ + + $goodAnswer= ($correct == $i) ? true : false; + + if ($goodAnswer) { + $nbrGoodAnswers++; + $weighting = abs($weighting); + if ($weighting > 0) { $questionWeighting += $weighting; } - } + } - if (empty($try)) - $try=0; + if (empty($try)) { + $try = 0; + } - if (empty($lp)) { - $lp=0; - } + if (empty($lp)) { + $lp = 0; + } - if (empty($destination)) { - $destination=0; - } + if (empty($destination)) { + $destination = 0; + } - if ($url=='') { - $url=0; - } + if ($url == '') { + $url = 0; + } - //1@@1;2;@@2;4;4;@@http://www.chamilo.org - $dest= $try.'@@'.$lp.'@@'.$destination.'@@'.$url; - $objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i,NULL,NULL,$dest); + //1@@1;2;@@2;4;4;@@http://www.chamilo.org + $dest= $try.'@@'.$lp.'@@'.$destination.'@@'.$url; + $objAnswer->createAnswer( + $answer, + $goodAnswer, + $comment, + $weighting, + $i, + null, + null, + $dest + ); } //Create 666 answer $i = 666; - $answer = trim($form -> getSubmitValue('answer['.$i.']')); - $comment = trim($form -> getSubmitValue('comment['.$i.']')); - $weighting = trim($form -> getSubmitValue('weighting['.$i.']')); - $goodAnswer= ($correct == $i) ? true : false; - $dest = ''; - - $objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i,NULL,NULL,$dest); + $answer = trim($form->getSubmitValue('answer['.$i.']')); + $comment = trim($form->getSubmitValue('comment['.$i.']')); + $weighting = trim($form->getSubmitValue('weighting['.$i.']')); + $goodAnswer = $correct == $i ? true : false; + $dest = ''; + + $objAnswer->createAnswer( + $answer, + $goodAnswer, + $comment, + $weighting, + $i, + null, + null, + $dest + ); - // saves the answers into the data base - $objAnswer -> save(); + // saves the answers into the data base + $objAnswer->save(); // sets the total weighting of the question - $this -> updateWeighting($questionWeighting); - $this -> save(); + $this->updateWeighting($questionWeighting); + $this->save(); } function return_header($feedback_type = null, $counter = null, $score = null) @@ -393,6 +411,7 @@ class UniqueAnswerNoOption extends Question '. get_lang("Answer").''; $header .= ''.get_lang("Comment").''; $header .= ''; + return $header; - } + } }