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('N°').' | '.get_lang('True').' | '.get_lang('Answer').' | '.get_lang('Comment').' | '.get_lang('Score').' |
---|---|---|---|---|
{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('Required field'), '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 $exercise, $counter = null, $score = []) { $header = parent::return_header($exercise, $counter, $score); $header .= ''.get_lang('Your choice').' | '; if ($exercise->showExpectedChoiceColumn()) { $header .= ''.get_lang('ExpectedYour choice').' | '; } $header .= ''.get_lang('Answer').' | '; if ($exercise->showExpectedChoice()) { $header .= ''.get_lang('Status').' | '; } $header .= ''.get_lang('Comment').' | '; $header .= '
---|