*/ class UniqueAnswerImage extends UniqueAnswer { public static $typePicture = 'uaimg.png'; public static $explanationLangVar = 'UniqueAnswerImage'; /** * UniqueAnswerImage constructor. */ public function __construct() { parent::__construct(); $this->type = UNIQUE_ANSWER_IMAGE; $this->isContent = $this->getIsContent(); } /** * {@inheritdoc} * * @throws Exception */ public function createAnswersForm($form) { $objExercise = Session::read('objExercise'); $editorConfig = [ 'ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125', ]; //this line defines how many questions by default appear when creating a choice question // The previous default value was 2. See task #1759. $numberAnswers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 4; $numberAnswers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0)); $feedbackTitle = ''; switch ($objExercise->getFeedbackType()) { case EXERCISE_FEEDBACK_TYPE_DIRECT: // Scenario $commentTitle = '
'.get_lang('Number').' | '.get_lang('True').' | '.get_lang('Answer').' | '.$commentTitle.' '.$feedbackTitle.''.get_lang('Weighting').' | |
---|---|---|---|---|
{error} {element} | ',
'correct'
);
$renderer->setElementTemplate(
'{error} {element} | ',
'counter['.$i.']'
);
$renderer->setElementTemplate(
'{error} {element} | ',
'answer['.$i.']'
);
$renderer->setElementTemplate(
'{error} {element} | ',
'comment['.$i.']'
);
$renderer->setElementTemplate(
'{error} {element} | ',
'weighting['.$i.']'
);
$answerNumber = $form->addElement('text', 'counter['.$i.']', null, ' value = "'.$i.'"');
$answerNumber->freeze();
$form->addElement('radio', 'correct', null, null, $i, 'class="checkbox"');
$form->addHtmlEditor('answer['.$i.']', null, null, false, $editorConfig);
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
switch ($objExercise->getFeedbackType()) {
case EXERCISE_FEEDBACK_TYPE_DIRECT:
$this->setDirectOptions($i, $form, $renderer, $selectLpId, $selectQuestion);
break;
case EXERCISE_FEEDBACK_TYPE_POPUP:
default:
$form->addHtmlEditor('comment['.$i.']', null, null, false, $editorConfig);
break;
}
$form->addText('weighting['.$i.']', null, null, ['class' => 'col-md-1', 'value' => '0']);
$form->addHtml('
', '
'], '', $form->getSubmitValue('answer['.$i.']'))); $comment = trim(str_replace(['', '
'], '', $form->getSubmitValue('comment['.$i.']'))); $weighting = trim($form->getSubmitValue('weighting['.$i.']')); $scenario = $form->getSubmitValue('scenario'); //$listDestination = $form -> getSubmitValue('destination'.$i); //$destinationStr = $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 $destinationStr=''; foreach ($listDestination as $destination_id) { $destinationStr.=$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($lp)) { $lp = 0; } if (empty($destination)) { $destination = 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 ); } // 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 = []) { if ($exercise->showExpectedChoice()) { $header = ''.get_lang('Choice').' | '; if ($exercise->showExpectedChoiceColumn()) { $header .= ''.get_lang('ExpectedChoice').' | '; } $header .= ''.get_lang('Answer').' | '; $header .= ''.get_lang('Status').' | '; $header .= ''.get_lang('Comment').' | '; $header .= '
---|