type = MULTIPLE_ANSWER; $this->isContent = $this->getIsContent(); } /** * @inheritdoc */ public function createAnswersForm($form) { $editorConfig = array( 'ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125' ); $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4; // The previous default value was 2. See task #1759. $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, true, $editorConfig);
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
$form->addHtmlEditor("comment[$i]", null, null, true, $editorConfig);
$form->addElement('text', 'weighting['.$i.']', null, array('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").' | '. get_lang("ExpectedChoice").' | '. get_lang("Answer").' | '; $header .= ''.get_lang("Status").' | '; $header .= ''.get_lang("Comment").' | '; $header .= '
---|