ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.assKprimChoiceGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
5 require_once 'Modules/TestQuestionPool/interfaces/interface.ilGuiQuestionScoringAdjustable.php';
6 require_once 'Modules/TestQuestionPool/interfaces/interface.ilGuiAnswerScoringAdjustable.php';
7 
17 {
21  public $object;
22 
26  public function __construct($qId = -1)
27  {
28  parent::__construct();
29 
30  require_once 'Modules/TestQuestionPool/classes/class.assKprimChoice.php';
31  $this->object = new assKprimChoice();
32 
33  if ($qId > 0) {
34  $this->object->loadFromDb($qId);
35  }
36  }
37 
41  public function hasInlineFeedback()
42  {
43  return $this->object->feedbackOBJ->isSpecificAnswerFeedbackAvailable($this->object->getId());
44  }
45 
46  protected function getAdditionalEditQuestionCommands()
47  {
48  return array('uploadImage', 'removeImage');
49  }
50 
51  protected function editQuestion(ilPropertyFormGUI $form = null)
52  {
53  if ($form === null) {
54  $form = $this->buildEditForm();
55  }
56 
57  $this->getQuestionTemplate();
58  $this->tpl->addCss('Modules/Test/templates/default/ta.css');
59 
60  $this->tpl->setVariable("QUESTION_DATA", $this->ctrl->getHTML($form));
61  }
62 
63  protected function uploadImage()
64  {
65  $result = $this->writePostData(true);
66 
67  if ($result == 0) {
68  $this->object->saveToDb();
69  $this->editQuestion();
70  }
71  }
72 
73  public function removeImage()
74  {
75  $position = key($_POST['cmd']['removeImage']);
76  $this->object->removeAnswerImage($position);
77 
78  $this->object->saveToDb();
79  $this->editQuestion();
80  }
81 
82  public function downkprim_answers()
83  {
84  if (isset($_POST['cmd'][__FUNCTION__]) && count($_POST['cmd'][__FUNCTION__])) {
85  $this->object->moveAnswerDown(key($_POST['cmd'][__FUNCTION__]));
86  $this->object->saveToDb();
87  }
88 
89  $this->editQuestion();
90  }
91 
92  public function upkprim_answers()
93  {
94  if (isset($_POST['cmd'][__FUNCTION__]) && count($_POST['cmd'][__FUNCTION__])) {
95  $this->object->moveAnswerUp(key($_POST['cmd'][__FUNCTION__]));
96  $this->object->saveToDb();
97  }
98 
99  $this->editQuestion();
100  }
101 
105  protected function writePostData($upload = false)
106  {
107  $form = $this->buildEditForm();
108  $form->setValuesByPost();
109 
110  if ($upload) {
111  $answersInput = $form->getItemByPostVar('kprim_answers');
112  $answersInput->setIgnoreMissingUploadsEnabled(true);
113 
114  if (!$answersInput->checkUploads($_POST[$answersInput->getPostVar()])) {
115  ilUtil::sendFailure($this->lng->txt("form_input_not_valid"));
116  $this->editQuestion($form);
117  return 1;
118  }
119 
120  $answersInput->collectValidFiles();
121  } elseif (!$form->checkInput()) {
122  $this->editQuestion($form);
123  return 1;
124  }
125 
127 
130 
131  $this->saveTaxonomyAssignments();
132 
133  return 0;
134  }
135 
139  protected function buildEditForm()
140  {
141  $form = $this->buildBasicEditFormObject();
142 
144 
146 
149 
151 
152  return $form;
153  }
154 
160  {
161  // shuffle answers
162  $shuffleAnswers = new ilCheckboxInputGUI($this->lng->txt("shuffle_answers"), "shuffle_answers_enabled");
163  $shuffleAnswers->setChecked($this->object->isShuffleAnswersEnabled());
164  $form->addItem($shuffleAnswers);
165 
166  if (!$this->object->getSelfAssessmentEditingMode()) {
167  // answer mode (single-/multi-line)
168  $answerType = new ilSelectInputGUI($this->lng->txt('answer_types'), 'answer_type');
169  $answerType->setOptions($this->object->getAnswerTypeSelectOptions($this->lng));
170  $answerType->setValue($this->object->getAnswerType());
171  $form->addItem($answerType);
172  }
173 
174  if (!$this->object->getSelfAssessmentEditingMode() && $this->object->isSingleLineAnswerType($this->object->getAnswerType())) {
175  // thumb size
176  $thumbSize = new ilNumberInputGUI($this->lng->txt('thumb_size'), 'thumb_size');
177  $thumbSize->setSuffix($this->lng->txt("thumb_size_unit_pixel"));
178  $thumbSize->setInfo($this->lng->txt('thumb_size_info'));
179  $thumbSize->setDecimals(false);
180  $thumbSize->setMinValue(20);
181  $thumbSize->setSize(6);
182  if ($this->object->getThumbSize() > 0) {
183  $thumbSize->setValue($this->object->getThumbSize());
184  }
185  $form->addItem($thumbSize);
186  }
187 
188  // option label
189  $optionLabel = new ilRadioGroupInputGUI($this->lng->txt('option_label'), 'option_label');
190  $optionLabel->setInfo($this->lng->txt('option_label_info'));
191  $optionLabel->setRequired(true);
192  $optionLabel->setValue($this->object->getOptionLabel());
193  foreach ($this->object->getValidOptionLabelsTranslated($this->lng) as $labelValue => $labelText) {
194  $option = new ilRadioOption($labelText, $labelValue);
195  $optionLabel->addOption($option);
196 
197  if ($this->object->isCustomOptionLabel($labelValue)) {
198  $customLabelTrue = new ilTextInputGUI(
199  $this->lng->txt('option_label_custom_true'),
200  'option_label_custom_true'
201  );
202  $customLabelTrue->setValue($this->object->getCustomTrueOptionLabel());
203  $option->addSubItem($customLabelTrue);
204 
205  $customLabelFalse = new ilTextInputGUI(
206  $this->lng->txt('option_label_custom_false'),
207  'option_label_custom_false'
208  );
209  $customLabelFalse->setValue($this->object->getCustomFalseOptionLabel());
210  $option->addSubItem($customLabelFalse);
211  }
212  }
213  $form->addItem($optionLabel);
214 
215  // points
216  $points = new ilNumberInputGUI($this->lng->txt('points'), 'points');
217  $points->setRequired(true);
218  $points->setSize(3);
219  $points->allowDecimals(true);
220  $points->setMinValue(0);
221  $points->setMinvalueShouldBeGreater(true);
222  $points->setValue($this->object->getPoints());
223  $form->addItem($points);
224 
225  // score partial solution
226  $scorePartialSolution = new ilCheckboxInputGUI($this->lng->txt('score_partsol_enabled'), 'score_partsol_enabled');
227  $scorePartialSolution->setInfo($this->lng->txt('score_partsol_enabled_info'));
228  $scorePartialSolution->setChecked($this->object->isScorePartialSolutionEnabled());
229  $form->addItem($scorePartialSolution);
230 
231  return $form;
232  }
233 
238  {
239  $oldAnswerType = $this->object->getAnswerType();
240 
241  $this->object->setShuffleAnswersEnabled($form->getItemByPostVar('shuffle_answers_enabled')->getChecked());
242 
243  if (!$this->object->getSelfAssessmentEditingMode()) {
244  $this->object->setAnswerType($form->getItemByPostVar('answer_type')->getValue());
245  } else {
246  $this->object->setAnswerType(assKprimChoice::ANSWER_TYPE_MULTI_LINE);
247  }
248 
249  if (!$this->object->getSelfAssessmentEditingMode() && $this->object->isSingleLineAnswerType($oldAnswerType)) {
250  $this->object->setThumbSize($form->getItemByPostVar('thumb_size')->getValue());
251  }
252 
253  $this->object->setOptionLabel($form->getItemByPostVar('option_label')->getValue());
254 
255  if ($this->object->isCustomOptionLabel($this->object->getOptionLabel())) {
256  $this->object->setCustomTrueOptionLabel(strip_tags(
257  $form->getItemByPostVar('option_label_custom_true')->getValue()
258  ));
259  $this->object->setCustomFalseOptionLabel(strip_tags(
260  $form->getItemByPostVar('option_label_custom_false')->getValue()
261  ));
262  }
263 
264  $this->object->setPoints($form->getItemByPostVar('points')->getValue());
265 
266  $this->object->setScorePartialSolutionEnabled($form->getItemByPostVar('score_partsol_enabled')->getChecked());
267  }
268 
274  {
275  require_once 'Modules/TestQuestionPool/classes/class.ilKprimChoiceWizardInputGUI.php';
276  $kprimAnswers = new ilKprimChoiceWizardInputGUI($this->lng->txt('answers'), 'kprim_answers');
277  $kprimAnswers->setInfo($this->lng->txt('kprim_answers_info'));
278  $kprimAnswers->setSize(64);
279  $kprimAnswers->setMaxLength(1000);
280  $kprimAnswers->setRequired(true);
281  $kprimAnswers->setAllowMove(true);
282  $kprimAnswers->setQuestionObject($this->object);
283  if (!$this->object->getSelfAssessmentEditingMode()) {
284  $kprimAnswers->setSingleline($this->object->isSingleLineAnswerType($this->object->getAnswerType()));
285  } else {
286  $kprimAnswers->setSingleline(false);
287  }
288  $kprimAnswers->setValues($this->object->getAnswers());
289  $form->addItem($kprimAnswers);
290 
291  return $form;
292  }
293 
298  {
299  $answers = $form->getItemByPostVar('kprim_answers')->getValues();
300  $answers = $this->handleAnswerTextsSubmit($answers);
301  $files = $form->getItemByPostVar('kprim_answers')->getFiles();
302 
303  $this->object->handleFileUploads($answers, $files);
304  $this->object->setAnswers($answers);
305  }
306 
307  private function handleAnswerTextsSubmit($answers)
308  {
309  if ($this->object->getAnswerType() == assKprimChoice::ANSWER_TYPE_MULTI_LINE) {
310  return $answers;
311  }
312 
313  foreach ($answers as $key => $answer) {
314  $answer->setAnswerText(ilUtil::secureString($answer->getAnswerText()));
315  }
316 
317  return $answers;
318  }
319 
325  public function getSpecificFeedbackOutput($userSolution)
326  {
327  return ''; // question type supports inline answer specific feedback
328  }
329 
339  public function getTestOutput(
340  $active_id,
341  // hey: prevPassSolutions - will be always available from now on
342  $pass,
343  // hey.
344  $is_postponed = false,
345  $use_post_solutions = false,
346  $showInlineFeedback = false
347  ) {
348  // shuffle output
350 
351  // get the solution of the user for the active pass or from the last pass if allowed
352  $user_solution = array();
353  if ($active_id) {
354  // hey: prevPassSolutions - obsolete due to central check
355  #$solutions = NULL;
356  #include_once "./Modules/Test/classes/class.ilObjTest.php";
357  #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
358  #{
359  # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
360  #}
361  $solutions = $this->object->getTestOutputSolutions($active_id, $pass);
362  // hey.
363  foreach ($solutions as $idx => $solution_value) {
364  $user_solution[$solution_value["value1"]] = $solution_value["value2"];
365  }
366  }
367 
368  // generate the question output
369  include_once "./Services/UICore/classes/class.ilTemplate.php";
370  $template = new ilTemplate("tpl.il_as_qpl_mc_kprim_output.html", true, true, "Modules/TestQuestionPool");
371 
372  foreach ($keys as $answer_id) {
373  $answer = $this->object->getAnswer($answer_id);
374  if (strlen($answer->getImageFile())) {
375  if ($this->object->getThumbSize()) {
376  $template->setCurrentBlock("preview");
377  $template->setVariable("URL_PREVIEW", $answer->getImageWebPath());
378  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
379  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
380  $template->setVariable("ANSWER_IMAGE_URL", $answer->getThumbWebPath());
381  list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
382  $alt = $answer->getImageFile();
383  if (strlen($answer->getAnswertext())) {
384  $alt = $answer->getAnswertext();
385  }
386  $alt = preg_replace("/<[^>]*?>/", "", $alt);
387  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
388  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
389  $template->parseCurrentBlock();
390  } else {
391  $template->setCurrentBlock("answer_image");
392  $template->setVariable("ANSWER_IMAGE_URL", $answer->getImageWebPath());
393  list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
394  $alt = $answer->getImageFile();
395  if (strlen($answer->getAnswertext())) {
396  $alt = $answer->getAnswertext();
397  }
398  $alt = preg_replace("/<[^>]*?>/", "", $alt);
399  $template->setVariable("ATTR", $attr);
400  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
401  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
402  $template->parseCurrentBlock();
403  }
404  }
405 
406  if ($showInlineFeedback) {
407  $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
408  }
409 
410  $template->setCurrentBlock("answer_row");
411  $template->setVariable("ANSWER_ID", $answer_id);
412  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), true));
413  $template->setVariable('VALUE_TRUE', 1);
414  $template->setVariable('VALUE_FALSE', 0);
415 
416  if (isset($user_solution[$answer->getPosition()])) {
417  $tplVar = $user_solution[$answer->getPosition()] ? 'CHECKED_ANSWER_TRUE' : 'CHECKED_ANSWER_FALSE';
418  $template->setVariable($tplVar, " checked=\"checked\"");
419  }
420 
421  $template->parseCurrentBlock();
422  }
423 
424  $questiontext = $this->object->getQuestion();
425  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, true));
426 
427  $template->setVariable("INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
428  $this->lng,
429  $this->object->getOptionLabel()
430  ));
431 
432  $template->setVariable("OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
433  $this->lng,
434  $this->object->getOptionLabel()
435  ));
436 
437  $template->setVariable("OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
438  $this->lng,
439  $this->object->getOptionLabel()
440  ));
441 
442  $questionoutput = $template->get();
443  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput, $showInlineFeedback);
444  return $pageoutput;
445  }
446 
451  public function getPreview($show_question_only = false, $showInlineFeedback = false)
452  {
453  $user_solution = is_object($this->getPreviewSession()) ? (array) $this->getPreviewSession()->getParticipantsSolution() : array();
454  // shuffle output
456 
457  // generate the question output
458  include_once "./Services/UICore/classes/class.ilTemplate.php";
459  $template = new ilTemplate("tpl.il_as_qpl_mc_kprim_output.html", true, true, "Modules/TestQuestionPool");
460 
461  foreach ($keys as $answer_id) {
462  $answer = $this->object->getAnswer($answer_id);
463  if (strlen($answer->getImageFile())) {
464  if ($this->object->getThumbSize()) {
465  $template->setCurrentBlock("preview");
466  $template->setVariable("URL_PREVIEW", $answer->getImageWebPath());
467  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
468  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
469  $template->setVariable("ANSWER_IMAGE_URL", $answer->getThumbWebPath());
470  list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
471  $alt = $answer->getImageFile();
472  if (strlen($answer->getAnswertext())) {
473  $alt = $answer->getAnswertext();
474  }
475  $alt = preg_replace("/<[^>]*?>/", "", $alt);
476  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
477  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
478  $template->parseCurrentBlock();
479  } else {
480  $template->setCurrentBlock("answer_image");
481  $template->setVariable("ANSWER_IMAGE_URL", $answer->getImageWebPath());
482  list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
483  $alt = $answer->getImageFile();
484  if (strlen($answer->getAnswertext())) {
485  $alt = $answer->getAnswertext();
486  }
487  $alt = preg_replace("/<[^>]*?>/", "", $alt);
488  $template->setVariable("ATTR", $attr);
489  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
490  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
491  $template->parseCurrentBlock();
492  }
493  }
494 
495  if ($showInlineFeedback) {
496  $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
497  }
498 
499  $template->setCurrentBlock("answer_row");
500  $template->setVariable("ANSWER_ID", $answer_id);
501  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), true));
502  $template->setVariable('VALUE_TRUE', 1);
503  $template->setVariable('VALUE_FALSE', 0);
504 
505  if (isset($user_solution[$answer->getPosition()])) {
506  $tplVar = $user_solution[$answer->getPosition()] ? 'CHECKED_ANSWER_TRUE' : 'CHECKED_ANSWER_FALSE';
507  $template->setVariable($tplVar, " checked=\"checked\"");
508  }
509 
510  $template->parseCurrentBlock();
511  }
512  $questiontext = $this->object->getQuestion();
513  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, true));
514 
515  $template->setVariable("INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
516  $this->lng,
517  $this->object->getOptionLabel()
518  ));
519 
520  $template->setVariable("OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
521  $this->lng,
522  $this->object->getOptionLabel()
523  ));
524 
525  $template->setVariable("OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
526  $this->lng,
527  $this->object->getOptionLabel()
528  ));
529 
530  $questionoutput = $template->get();
531  if (!$show_question_only) {
532  // get page object output
533  $questionoutput = $this->getILIASPage($questionoutput);
534  }
535  return $questionoutput;
536  }
537 
544  {
545  return true;
546  }
547 
548 
560  public function getSolutionOutput(
561  $active_id,
562  $pass = null,
563  $graphicalOutput = false,
564  $result_output = false,
565  $show_question_only = true,
566  $show_feedback = false,
567  $show_correct_solution = false,
568  $show_manual_scoring = false,
569  $show_question_text = true
570  ) {
571  // shuffle output
573 
574  // get the solution of the user for the active pass or from the last pass if allowed
575  $user_solution = array();
576  if (($active_id > 0) && (!$show_correct_solution)) {
577  $solutions = $this->object->getSolutionValues($active_id, $pass, !$this->getUseIntermediateSolution());
578  foreach ($solutions as $idx => $solution_value) {
579  $user_solution[$solution_value['value1']] = $solution_value['value2'];
580  }
581  } else {
582  // take the correct solution instead of the user solution
583  foreach ($this->object->getAnswers() as $answer) {
584  $user_solution[$answer->getPosition()] = $answer->getCorrectness();
585  }
586  }
587 
588  // generate the question output
589  $template = new ilTemplate("tpl.il_as_qpl_mc_kprim_output_solution.html", true, true, "Modules/TestQuestionPool");
590 
591  foreach ($keys as $answer_id) {
592  $answer = $this->object->getAnswer($answer_id);
593 
594  if (($active_id > 0) && (!$show_correct_solution)) {
595  if ($graphicalOutput) {
596  // output of ok/not ok icons for user entered solutions
597 
598  if ($user_solution[$answer->getPosition()] == $answer->getCorrectness()) {
599  $template->setCurrentBlock("icon_ok");
600  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
601  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
602  $template->parseCurrentBlock();
603  } else {
604  $template->setCurrentBlock("icon_ok");
605  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
606  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
607  $template->parseCurrentBlock();
608  }
609  }
610  }
611  if (strlen($answer->getImageFile())) {
612  $template->setCurrentBlock("answer_image");
613  if ($this->object->getThumbSize()) {
614  $template->setVariable("ANSWER_IMAGE_URL", $answer->getThumbWebPath());
615  } else {
616  $template->setVariable("ANSWER_IMAGE_URL", $answer->getImageWebPath());
617  }
618 
619  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($answer->getImageFile()));
620  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($answer->getImageFile()));
621  $template->parseCurrentBlock();
622  }
623 
624  if ($show_feedback) {
625  $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
626  }
627 
628  $template->setCurrentBlock("answer_row");
629  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), true));
630 
631  if ($this->renderPurposeSupportsFormHtml() || $this->isRenderPurposePrintPdf()) {
632  if (isset($user_solution[$answer->getPosition()])) {
633  if ($user_solution[$answer->getPosition()]) {
634  $template->setVariable("SOLUTION_IMAGE_TRUE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_checked.png")));
635  $template->setVariable("SOLUTION_ALT_TRUE", $this->lng->txt("checked"));
636  $template->setVariable("SOLUTION_IMAGE_FALSE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
637  $template->setVariable("SOLUTION_ALT_FALSE", $this->lng->txt("unchecked"));
638  } else {
639  $template->setVariable("SOLUTION_IMAGE_TRUE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
640  $template->setVariable("SOLUTION_ALT_TRUE", $this->lng->txt("unchecked"));
641  $template->setVariable("SOLUTION_IMAGE_FALSE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_checked.png")));
642  $template->setVariable("SOLUTION_ALT_FALSE", $this->lng->txt("checked"));
643  }
644  } else {
645  $template->setVariable("SOLUTION_IMAGE_TRUE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
646  $template->setVariable("SOLUTION_ALT_TRUE", $this->lng->txt("unchecked"));
647  $template->setVariable("SOLUTION_IMAGE_FALSE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
648  $template->setVariable("SOLUTION_ALT_FALSE", $this->lng->txt("unchecked"));
649  }
650  } else {
651  $template->setVariable('SOL_QID', $this->object->getId());
652  $template->setVariable('SOL_SUFFIX', $show_correct_solution ? 'bestsolution' : 'usersolution');
653  $template->setVariable('SOL_POSITION', $answer->getPosition());
654 
655  $template->setVariable('SOL_TRUE_VALUE', 1);
656  $template->setVariable('SOL_FALSE_VALUE', 0);
657 
658  if (isset($user_solution[$answer->getPosition()])) {
659  if ($user_solution[$answer->getPosition()]) {
660  $template->setVariable('SOL_TRUE_CHECKED', 'checked');
661  } else {
662  $template->setVariable('SOL_FALSE_CHECKED', 'checked');
663  }
664  }
665  }
666 
667  $template->parseCurrentBlock();
668  }
669 
670  if ($show_question_text == true) {
671  $questiontext = $this->object->getQuestion();
672  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, true));
673 
674  $template->setVariable("INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
675  $this->lng,
676  $this->object->getOptionLabel()
677  ));
678  }
679 
680  $template->setVariable("OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
681  $this->lng,
682  $this->object->getOptionLabel()
683  ));
684 
685  $template->setVariable("OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
686  $this->lng,
687  $this->object->getOptionLabel()
688  ));
689 
690 
691  $questionoutput = $template->get();
692  $feedback = ($show_feedback && !$this->isTestPresentationContext()) ? $this->getGenericFeedbackOutput($active_id, $pass) : "";
693 
694  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "Modules/TestQuestionPool");
695 
696  if (strlen($feedback)) {
697  $cssClass = (
698  $this->hasCorrectSolution($active_id, $pass) ?
700  );
701 
702  $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
703  $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, true));
704  }
705 
706  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
707 
708  $solutionoutput = $solutiontemplate->get();
709 
710  if ($show_feedback && $this->hasInlineFeedback()) {
711  $solutionoutput = $this->buildFocusAnchorHtml() . $solutionoutput;
712  }
713 
714  if (!$show_question_only) {
715  // get page object output
716  $solutionoutput = $this->getILIASPage($solutionoutput);
717  }
718  return $solutionoutput;
719  }
720 
721  protected function getParticipantsAnswerKeySequence()
722  {
723  $choiceKeys = array_keys($this->object->getAnswers());
724 
725  if ($this->object->isShuffleAnswersEnabled()) {
726  $choiceKeys = $this->object->getShuffler()->shuffle($choiceKeys);
727  }
728 
729  return $choiceKeys;
730  }
731 
732  private function populateSpecificFeedbackInline($user_solution, $answer_id, $template)
733  {
734  require_once 'Modules/TestQuestionPool/classes/feedback/class.ilAssConfigurableMultiOptionQuestionFeedback.php';
735 
736  if ($this->object->getSpecificFeedbackSetting() == ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_CHECKED) {
737  if ($user_solution[$answer_id]) {
738  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), 0, $answer_id);
739  if (strlen($fb)) {
740  $template->setCurrentBlock("feedback");
741  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
742  $template->parseCurrentBlock();
743  }
744  }
745  }
746 
747  if ($this->object->getSpecificFeedbackSetting() == ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_ALL) {
748  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), 0, $answer_id);
749  if (strlen($fb)) {
750  $template->setCurrentBlock("feedback");
751  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
752  $template->parseCurrentBlock();
753  }
754  }
755 
756  if ($this->object->getSpecificFeedbackSetting() == ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_CORRECT) {
757  $answer = $this->object->getAnswer($answer_id);
758 
759  if ($answer->getCorrectness()) {
760  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), 0, $answer_id);
761  if (strlen($fb)) {
762  $template->setCurrentBlock("feedback");
763  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
764  $template->parseCurrentBlock();
765  }
766  }
767  }
768  }
769 
780  {
781  return array();
782  }
783 
794  {
795  return array();
796  }
797 
806  public function getAggregatedAnswersView($relevant_answers)
807  {
808  return $this->renderAggregateView(
809  $this->aggregateAnswers($relevant_answers, $this->object->getAnswers())
810  )->get();
811 
812  return '<pre>' . print_r($relevant_answers, 1) . '</pre>';
813  }
814 
815  public function renderAggregateView($aggregate)
816  {
817  $trueOptionLabel = $this->object->getTrueOptionLabelTranslation($this->lng, $this->object->getOptionLabel());
818  $falseOptionLabel = $this->object->getFalseOptionLabelTranslation($this->lng, $this->object->getOptionLabel());
819 
820  $tpl = new ilTemplate('tpl.il_as_aggregated_kprim_answers_table.html', true, true, "Modules/TestQuestionPool");
821 
822  foreach ($aggregate as $lineData) {
823  $tpl->setCurrentBlock('aggregaterow');
824  $tpl->setVariable('OPTION', $lineData['answertext']);
825  $tpl->setVariable('COUNT_TRUE', $lineData['count_true']);
826  $tpl->setVariable('COUNT_FALSE', $lineData['count_false']);
827  $tpl->parseCurrentBlock();
828  }
829 
830  $tpl->setVariable('OPTION_HEAD', $this->lng->txt('answers'));
831  $tpl->setVariable('COUNT_TRUE_HEAD', $trueOptionLabel);
832  $tpl->setVariable('COUNT_FALSE_HEAD', $falseOptionLabel);
833 
834  return $tpl;
835  }
836 
837  public function aggregateAnswers($rawSolutionData, $answers)
838  {
839  $aggregate = array();
840 
841  foreach ($answers as $answer) {
842  $answerAgg = array(
843  'answertext' => $answer->getAnswerText(), 'count_true' => 0, 'count_false' => 0
844  );
845 
846  foreach ($rawSolutionData as $solutionRecord) {
847  if ($solutionRecord['value1'] == $answer->getPosition()) {
848  if ($solutionRecord['value2']) {
849  $answerAgg['count_true']++;
850  } else {
851  $answerAgg['count_false']++;
852  }
853  }
854  }
855 
856  $aggregate[] = $answerAgg;
857  }
858 
859  return $aggregate;
860  }
861 
862  public function getAnswersFrequency($relevantAnswers, $questionIndex)
863  {
864  $agg = $this->aggregateAnswers($relevantAnswers, $this->object->getAnswers());
865 
866  $answers = array();
867 
868  foreach ($agg as $ans) {
869  $answers[] = array(
870  'answer' => $ans['answertext'],
871  'frequency_true' => $ans['count_true'],
872  'frequency_false' => $ans['count_false']
873  );
874  }
875 
876  return $answers;
877  }
878 
886  public function getAnswerFrequencyTableGUI($parentGui, $parentCmd, $relevantAnswers, $questionIndex)
887  {
888  require_once 'Modules/TestQuestionPool/classes/tables/class.ilKprimChoiceAnswerFreqStatTableGUI.php';
889 
890  $table = new ilKprimChoiceAnswerFreqStatTableGUI($parentGui, $parentCmd, $this->object);
891  $table->setQuestionIndex($questionIndex);
892  $table->setData($this->getAnswersFrequency($relevantAnswers, $questionIndex));
893  $table->initColumns();
894 
895  return $table;
896  }
897 
899  {
900  // points
901  $points = new ilNumberInputGUI($this->lng->txt('points'), 'points');
902  $points->setRequired(true);
903  $points->setSize(3);
904  $points->allowDecimals(true);
905  $points->setMinValue(0);
906  $points->setMinvalueShouldBeGreater(true);
907  $points->setValue($this->object->getPoints());
908  $form->addItem($points);
909 
910  // score partial solution
911  $scorePartialSolution = new ilCheckboxInputGUI($this->lng->txt('score_partsol_enabled'), 'score_partsol_enabled');
912  $scorePartialSolution->setInfo($this->lng->txt('score_partsol_enabled_info'));
913  $scorePartialSolution->setChecked($this->object->isScorePartialSolutionEnabled());
914  $form->addItem($scorePartialSolution);
915 
916  // answers
917  require_once 'Modules/TestQuestionPool/classes/forms/class.ilKprimChoiceCorrectionsInputGUI.php';
918  $kprimAnswers = new ilKprimChoiceCorrectionsInputGUI($this->lng->txt('answers'), 'kprim_answers');
919  $kprimAnswers->setInfo($this->lng->txt('kprim_answers_info'));
920  $kprimAnswers->setSize(64);
921  $kprimAnswers->setMaxLength(1000);
922  $kprimAnswers->setRequired(true);
923  $kprimAnswers->setQuestionObject($this->object);
924  $kprimAnswers->setValues($this->object->getAnswers());
925  $form->addItem($kprimAnswers);
926 
927  return $form;
928  }
929 
934  {
935  $this->object->setPoints(
936  (float) $form->getInput('points')
937  );
938 
939  $this->object->setScorePartialSolutionEnabled(
940  (bool) $form->getInput('score_partsol_enabled')
941  );
942 
943  $this->object->setAnswers(
944  $form->getItemByPostVar('kprim_answers')->getValues()
945  );
946  }
947 }
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
hasCorrectSolution($activeId, $passIndex)
This class represents an option in a radio group.
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getAnswerFrequencyTableGUI($parentGui, $parentCmd, $relevantAnswers, $questionIndex)
saveCorrectionsFormProperties(ilPropertyFormGUI $form)
addBasicQuestionFormProperties($form)
Add basic question form properties: assessment: title, author, description, question, working time.
$files
Definition: metarefresh.php:49
getItemByPostVar($a_post_var)
Get Item by POST variable.
This class represents a selection list property in a property form.
$result
$template
This class represents a property form user interface.
$type
This class represents a checkbox property in a property form.
addItem($a_item)
Add Item (Property, SectionHeader).
populateAnswerSpecificFormPart(ilPropertyFormGUI $form)
getQuestionTemplate()
get question template
$keys
getPreview($show_question_only=false, $showInlineFeedback=false)
populateTaxonomyFormSection(ilPropertyFormGUI $form)
getUseIntermediateSolution()
Get if intermediate solution should be used for solution output.
setInfo($a_info)
Set Information Text.
setChecked($a_checked)
Set Checked.
This class represents a property in a property form.
writePostData($upload=false)
{}
setSuffix($a_value)
Set suffix.
getTestOutput( $active_id, $pass, $is_postponed=false, $use_post_solutions=false, $showInlineFeedback=false)
if(isset($_POST['submit'])) $form
getILIASPage($html="")
Returns the ILIAS Page around a question.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
This class represents a number property in a property form.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
setOptions($a_options)
Set Options.
Basic GUI class for assessment questions.
static getHtmlPath($relative_path)
get url of path
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
getAggregatedAnswersView($relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
getAfterParticipationSuppressionAnswerPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
output question page
editQuestion(ilPropertyFormGUI $form=null)
static secureString($a_str, $a_strip_html=true, $a_allow="")
Remove unsecure tags.
Interface ilGuiAnswerScoringAdjustable.
populateCorrectionsFormProperties(ilPropertyFormGUI $form)
if(empty($password)) $table
Definition: pwgen.php:24
aggregateAnswers($rawSolutionData, $answers)
getGenericFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
Interface ilGuiQuestionScoringAdjustable.
setValue($a_value)
Set Value.
getSolutionOutput( $active_id, $pass=null, $graphicalOutput=false, $result_output=false, $show_question_only=true, $show_feedback=false, $show_correct_solution=false, $show_manual_scoring=false, $show_question_text=true)
supportsIntermediateSolutionOutput()
Question type specific support of intermediate solution output The function getSolutionOutput respect...
$key
Definition: croninfo.php:18
$_POST["username"]
populateSpecificFeedbackInline($user_solution, $answer_id, $template)
getAnswersFrequency($relevantAnswers, $questionIndex)
setRequired($a_required)
Set Required.
addQuestionFormCommandButtons($form)
Add the command buttons of a question properties form.
getSpecificFeedbackOutput($userSolution)
populateQuestionSpecificFormPart(ilPropertyFormGUI $form)