type = MULTIPLE_ANSWER; $this->isContent = $this->getIsContent(); } /** * {@inheritdoc} */ public function createAnswersForm($form) { $editorConfig = [ 'ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125', ]; // The previous default value was 2. See task #1759. $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4; $nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0)); $obj_ex = Session::read('objExercise'); $form->addHeader(get_lang('Answers')); $html = '
'.get_lang('Number').' | '.get_lang('True').' | '.get_lang('Answer').' | '.get_lang('Comment').' | '.get_lang('Weighting').' |
---|---|---|---|---|
{error} {element} | ',
'correct['.$i.']'
);
$renderer->setElementTemplate(
'{error} {element} | ',
'counter['.$i.']'
);
$renderer->setElementTemplate(
'{error} {element} | ',
'answer['.$i.']'
);
$renderer->setElementTemplate(
'{error} {element} | ',
'comment['.$i.']'
);
$renderer->setElementTemplate(
'{error} {element} | ',
'weighting['.$i.']'
);
$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->addHtmlEditor("answer[$i]", null, null, false, $editorConfig);
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
$form->addHtmlEditor("comment[$i]", null, null, false, $editorConfig);
$form->addElement('text', 'weighting['.$i.']', null, ['style' => "width: 60px;", 'value' => '0']);
$form->addHtml('
', '
'], '', $form->getSubmitValue('answer['.$i.']'))); $comment = trim(str_replace(['', '
'], '', $form->getSubmitValue('comment['.$i.']'))); $weighting = trim($form->getSubmitValue('weighting['.$i.']')); $goodAnswer = trim($form->getSubmitValue('correct['.$i.']')); if ($goodAnswer) { $weighting = abs($weighting); } else { $weighting = abs($weighting); $weighting = -$weighting; } if ($weighting > 0) { $questionWeighting += $weighting; } $objAnswer->createAnswer( $answer, $goodAnswer, $comment, $weighting, $i ); } // saves the answers into the data base $objAnswer->save(); // sets the total weighting of the question $this->updateWeighting($questionWeighting); $this->save($exercise); } /** * {@inheritdoc} */ public function return_header($exercise, $counter = null, $score = null) { $header = parent::return_header($exercise, $counter, $score); $header .= ''.get_lang('Choice').' | '; if (!in_array($exercise->results_disabled, [ RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER, //RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING, ]) ) { $header .= ''.get_lang('ExpectedChoice').' | '; } $header .= ''.get_lang('Answer').' | '; if ($exercise->showExpectedChoice()) { $header .= ''.get_lang('Status').' | '; } $header .= ''.get_lang('Comment').' | '; $header .= '
---|