*/ class UniqueAnswerImage extends UniqueAnswer { static $typePicture = 'uaimg.png'; static $explanationLangVar = 'UniqueAnswerImage'; public function __construct() { //this is highly important parent::__construct(); $this->type = UNIQUE_ANSWER_IMAGE; $this->isContent = $this->getIsContent(); } public function createAnswersForm($form) { $objExercise = $_SESSION['objExercise']; $editorConfig = array( 'ToolbarSet' => 'TestFreeAnswer', '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 = ''; if ($objExercise->selectFeedbackType() == 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, true, $editorConfig);
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
$form->addHtmlEditor('comment[' . $i . ']', null, null, false, $editorConfig);
// Direct feedback
//Adding extra feedback fields
$group = array();
$group['try' . $i] = $form->createElement('checkbox', 'try' . $i, null, get_lang('TryAgain'));
$group['lp' . $i] = $form->createElement(
'select',
'lp' . $i,
get_lang('SeeTheory') . ': ',
$selectLpId
);
$group['destination' . $i] = $form->createElement(
'select',
'destination' . $i,
get_lang('GoToQuestion') . ': ',
$selectQuestion
);
$group['url' . $i] = $form->createElement(
'text', 'url' . $i,
get_lang('Other') . ': ',
array(
'class' => 'col-md-2',
'placeholder' => get_lang('Other')
)
);
$form->addGroup($group, 'scenario');
$renderer->setElementTemplate(
'{error} {element}', 'scenario' ); } else { $form->addHtmlEditor('comment[' . $i . ']', null, null, false, $editorConfig); } $form->addText('weighting[' . $i . ']', null, null, array('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(); } public function return_header($feedback_type = null, $counter = null, $score = null) { return parent::return_header($feedback_type, $counter, $score); } }