ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
38  protected function getAdditionalEditQuestionCommands()
39  {
40  return array('uploadImage', 'removeImage');
41  }
42 
43  protected function editQuestion(ilPropertyFormGUI $form = null)
44  {
45  if ($form === null) {
46  $form = $this->buildEditForm();
47  }
48 
49  $this->getQuestionTemplate();
50  $this->tpl->addCss('Modules/Test/templates/default/ta.css');
51 
52  $this->tpl->setVariable("QUESTION_DATA", $this->ctrl->getHTML($form));
53  }
54 
55  protected function uploadImage()
56  {
57  $result = $this->writePostData(true);
58 
59  if ($result == 0) {
60  $this->object->saveToDb();
61  $this->editQuestion();
62  }
63  }
64 
65  public function removeImage()
66  {
67  $position = key($_POST['cmd']['removeImage']);
68  $this->object->removeAnswerImage($position);
69 
70  $this->object->saveToDb();
71  $this->editQuestion();
72  }
73 
74  public function downkprim_answers()
75  {
76  if (isset($_POST['cmd'][__FUNCTION__]) && count($_POST['cmd'][__FUNCTION__])) {
77  $this->object->moveAnswerDown(key($_POST['cmd'][__FUNCTION__]));
78  $this->object->saveToDb();
79  }
80 
81  $this->editQuestion();
82  }
83 
84  public function upkprim_answers()
85  {
86  if (isset($_POST['cmd'][__FUNCTION__]) && count($_POST['cmd'][__FUNCTION__])) {
87  $this->object->moveAnswerUp(key($_POST['cmd'][__FUNCTION__]));
88  $this->object->saveToDb();
89  }
90 
91  $this->editQuestion();
92  }
93 
97  protected function writePostData($upload = false)
98  {
99  $form = $this->buildEditForm();
100  $form->setValuesByPost();
101 
102  if ($upload) {
103  $answersInput = $form->getItemByPostVar('kprim_answers');
104  $answersInput->setIgnoreMissingUploadsEnabled(true);
105 
106  if (!$answersInput->checkUploads($_POST[$answersInput->getPostVar()])) {
107  ilUtil::sendFailure($this->lng->txt("form_input_not_valid"));
108  $this->editQuestion($form);
109  return 1;
110  }
111 
112  $answersInput->collectValidFiles();
113  } elseif (!$form->checkInput()) {
114  $this->editQuestion($form);
115  return 1;
116  }
117 
119 
122 
123  $this->saveTaxonomyAssignments();
124 
125  return 0;
126  }
127 
131  protected function buildEditForm()
132  {
133  $form = $this->buildBasicEditFormObject();
134 
136 
138 
141 
143 
144  return $form;
145  }
146 
152  {
153  // shuffle answers
154  $shuffleAnswers = new ilCheckboxInputGUI($this->lng->txt("shuffle_answers"), "shuffle_answers_enabled");
155  $shuffleAnswers->setChecked($this->object->isShuffleAnswersEnabled());
156  $form->addItem($shuffleAnswers);
157 
158  if (!$this->object->getSelfAssessmentEditingMode()) {
159  // answer mode (single-/multi-line)
160  $answerType = new ilSelectInputGUI($this->lng->txt('answer_types'), 'answer_type');
161  $answerType->setOptions($this->object->getAnswerTypeSelectOptions($this->lng));
162  $answerType->setValue($this->object->getAnswerType());
163  $form->addItem($answerType);
164  }
165 
166  if (!$this->object->getSelfAssessmentEditingMode() && $this->object->isSingleLineAnswerType($this->object->getAnswerType())) {
167  // thumb size
168  $thumbSize = new ilNumberInputGUI($this->lng->txt('thumb_size'), 'thumb_size');
169  $thumbSize->setSuffix($this->lng->txt("thumb_size_unit_pixel"));
170  $thumbSize->setInfo($this->lng->txt('thumb_size_info'));
171  $thumbSize->setDecimals(false);
172  $thumbSize->setMinValue(20);
173  $thumbSize->setSize(6);
174  $thumbSize->setValue($this->object->getThumbSize());
175  $form->addItem($thumbSize);
176  }
177 
178  // option label
179  $optionLabel = new ilRadioGroupInputGUI($this->lng->txt('option_label'), 'option_label');
180  $optionLabel->setInfo($this->lng->txt('option_label_info'));
181  $optionLabel->setRequired(true);
182  $optionLabel->setValue($this->object->getOptionLabel());
183  foreach ($this->object->getValidOptionLabelsTranslated($this->lng) as $labelValue => $labelText) {
184  $option = new ilRadioOption($labelText, $labelValue);
185  $optionLabel->addOption($option);
186 
187  if ($this->object->isCustomOptionLabel($labelValue)) {
188  $customLabelTrue = new ilTextInputGUI(
189  $this->lng->txt('option_label_custom_true'),
190  'option_label_custom_true'
191  );
192  $customLabelTrue->setValue($this->object->getCustomTrueOptionLabel());
193  $option->addSubItem($customLabelTrue);
194 
195  $customLabelFalse = new ilTextInputGUI(
196  $this->lng->txt('option_label_custom_false'),
197  'option_label_custom_false'
198  );
199  $customLabelFalse->setValue($this->object->getCustomFalseOptionLabel());
200  $option->addSubItem($customLabelFalse);
201  }
202  }
203  $form->addItem($optionLabel);
204 
205  // points
206  $points = new ilNumberInputGUI($this->lng->txt('points'), 'points');
207  $points->setRequired(true);
208  $points->setSize(3);
209  $points->allowDecimals(true);
210  $points->setMinValue(0);
211  $points->setMinvalueShouldBeGreater(true);
212  $points->setValue($this->object->getPoints());
213  $form->addItem($points);
214 
215  // score partial solution
216  $scorePartialSolution = new ilCheckboxInputGUI($this->lng->txt('score_partsol_enabled'), 'score_partsol_enabled');
217  $scorePartialSolution->setInfo($this->lng->txt('score_partsol_enabled_info'));
218  $scorePartialSolution->setChecked($this->object->isScorePartialSolutionEnabled());
219  $form->addItem($scorePartialSolution);
220 
221  return $form;
222  }
223 
228  {
229  $oldAnswerType = $this->object->getAnswerType();
230 
231  $this->object->setShuffleAnswersEnabled($form->getItemByPostVar('shuffle_answers_enabled')->getChecked());
232 
233  if (!$this->object->getSelfAssessmentEditingMode()) {
234  $this->object->setAnswerType($form->getItemByPostVar('answer_type')->getValue());
235  } else {
236  $this->object->setAnswerType(assKprimChoice::ANSWER_TYPE_MULTI_LINE);
237  }
238 
239  if (!$this->object->getSelfAssessmentEditingMode() && $this->object->isSingleLineAnswerType($oldAnswerType)) {
240  $this->object->setThumbSize($form->getItemByPostVar('thumb_size')->getValue());
241  }
242 
243  $this->object->setOptionLabel($form->getItemByPostVar('option_label')->getValue());
244 
245  if ($this->object->isCustomOptionLabel($this->object->getOptionLabel())) {
246  $this->object->setCustomTrueOptionLabel(strip_tags(
247  $form->getItemByPostVar('option_label_custom_true')->getValue()
248  ));
249  $this->object->setCustomFalseOptionLabel(strip_tags(
250  $form->getItemByPostVar('option_label_custom_false')->getValue()
251  ));
252  }
253 
254  $this->object->setPoints($form->getItemByPostVar('points')->getValue());
255 
256  $this->object->setScorePartialSolutionEnabled($form->getItemByPostVar('score_partsol_enabled')->getChecked());
257  }
258 
264  {
265  require_once 'Modules/TestQuestionPool/classes/class.ilKprimChoiceWizardInputGUI.php';
266  $kprimAnswers = new ilKprimChoiceWizardInputGUI($this->lng->txt('answers'), 'kprim_answers');
267  $kprimAnswers->setInfo($this->lng->txt('kprim_answers_info'));
268  $kprimAnswers->setSize(64);
269  $kprimAnswers->setMaxLength(1000);
270  $kprimAnswers->setRequired(true);
271  $kprimAnswers->setAllowMove(true);
272  $kprimAnswers->setQuestionObject($this->object);
273  if (!$this->object->getSelfAssessmentEditingMode()) {
274  $kprimAnswers->setSingleline($this->object->isSingleLineAnswerType($this->object->getAnswerType()));
275  } else {
276  $kprimAnswers->setSingleline(false);
277  }
278  $kprimAnswers->setValues($this->object->getAnswers());
279  $form->addItem($kprimAnswers);
280 
281  return $form;
282  }
283 
288  {
289  $answers = $form->getItemByPostVar('kprim_answers')->getValues();
290  $answers = $this->handleAnswerTextsSubmit($answers);
291  $files = $form->getItemByPostVar('kprim_answers')->getFiles();
292 
293  $this->object->handleFileUploads($answers, $files);
294  $this->object->setAnswers($answers);
295  }
296 
297  private function handleAnswerTextsSubmit($answers)
298  {
299  if ($this->object->getAnswerType() == assKprimChoice::ANSWER_TYPE_MULTI_LINE) {
300  return $answers;
301  }
302 
303  foreach ($answers as $key => $answer) {
304  $answer->setAnswerText(ilUtil::secureString($answer->getAnswerText()));
305  }
306 
307  return $answers;
308  }
309 
315  public function getSpecificFeedbackOutput($active_id, $pass)
316  {
317  return ''; // question type supports inline answer specific feedback
318  }
319 
329  public function getTestOutput(
330  $active_id,
331  // hey: prevPassSolutions - will be always available from now on
332  $pass,
333  // hey.
334  $is_postponed = false,
335  $use_post_solutions = false,
336  $showInlineFeedback = false
337  ) {
338  // shuffle output
340 
341  // get the solution of the user for the active pass or from the last pass if allowed
342  $user_solution = array();
343  if ($active_id) {
344  // hey: prevPassSolutions - obsolete due to central check
345  #$solutions = NULL;
346  #include_once "./Modules/Test/classes/class.ilObjTest.php";
347  #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
348  #{
349  # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
350  #}
351  $solutions = $this->object->getTestOutputSolutions($active_id, $pass);
352  // hey.
353  foreach ($solutions as $idx => $solution_value) {
354  $user_solution[$solution_value["value1"]] = $solution_value["value2"];
355  }
356  }
357 
358  // generate the question output
359  include_once "./Services/UICore/classes/class.ilTemplate.php";
360  $template = new ilTemplate("tpl.il_as_qpl_mc_kprim_output.html", true, true, "Modules/TestQuestionPool");
361 
362  foreach ($keys as $answer_id) {
363  $answer = $this->object->getAnswer($answer_id);
364  if (strlen($answer->getImageFile())) {
365  if ($this->object->getThumbSize()) {
366  $template->setCurrentBlock("preview");
367  $template->setVariable("URL_PREVIEW", $answer->getImageWebPath());
368  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
369  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
370  $template->setVariable("ANSWER_IMAGE_URL", $answer->getThumbWebPath());
371  list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
372  $alt = $answer->getImageFile();
373  if (strlen($answer->getAnswertext())) {
374  $alt = $answer->getAnswertext();
375  }
376  $alt = preg_replace("/<[^>]*?>/", "", $alt);
377  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
378  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
379  $template->parseCurrentBlock();
380  } else {
381  $template->setCurrentBlock("answer_image");
382  $template->setVariable("ANSWER_IMAGE_URL", $answer->getImageWebPath());
383  list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
384  $alt = $answer->getImageFile();
385  if (strlen($answer->getAnswertext())) {
386  $alt = $answer->getAnswertext();
387  }
388  $alt = preg_replace("/<[^>]*?>/", "", $alt);
389  $template->setVariable("ATTR", $attr);
390  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
391  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
392  $template->parseCurrentBlock();
393  }
394  }
395 
396  if ($showInlineFeedback) {
397  $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
398  }
399 
400  $template->setCurrentBlock("answer_row");
401  $template->setVariable("ANSWER_ID", $answer_id);
402  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), true));
403  $template->setVariable('VALUE_TRUE', 1);
404  $template->setVariable('VALUE_FALSE', 0);
405 
406  if (isset($user_solution[$answer->getPosition()])) {
407  $tplVar = $user_solution[$answer->getPosition()] ? 'CHECKED_ANSWER_TRUE' : 'CHECKED_ANSWER_FALSE';
408  $template->setVariable($tplVar, " checked=\"checked\"");
409  }
410 
411  $template->parseCurrentBlock();
412  }
413 
414  $questiontext = $this->object->getQuestion();
415  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, true));
416 
417  $template->setVariable("INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
418  $this->lng,
419  $this->object->getOptionLabel()
420  ));
421 
422  $template->setVariable("OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
423  $this->lng,
424  $this->object->getOptionLabel()
425  ));
426 
427  $template->setVariable("OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
428  $this->lng,
429  $this->object->getOptionLabel()
430  ));
431 
432  $questionoutput = $template->get();
433  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
434  return $pageoutput;
435  }
436 
441  public function getPreview($show_question_only = false, $showInlineFeedback = false)
442  {
443  $user_solution = is_object($this->getPreviewSession()) ? (array) $this->getPreviewSession()->getParticipantsSolution() : array();
444  // shuffle output
446 
447  // generate the question output
448  include_once "./Services/UICore/classes/class.ilTemplate.php";
449  $template = new ilTemplate("tpl.il_as_qpl_mc_kprim_output.html", true, true, "Modules/TestQuestionPool");
450 
451  foreach ($keys as $answer_id) {
452  $answer = $this->object->getAnswer($answer_id);
453  if (strlen($answer->getImageFile())) {
454  if ($this->object->getThumbSize()) {
455  $template->setCurrentBlock("preview");
456  $template->setVariable("URL_PREVIEW", $answer->getImageWebPath());
457  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
458  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
459  $template->setVariable("ANSWER_IMAGE_URL", $answer->getThumbWebPath());
460  list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
461  $alt = $answer->getImageFile();
462  if (strlen($answer->getAnswertext())) {
463  $alt = $answer->getAnswertext();
464  }
465  $alt = preg_replace("/<[^>]*?>/", "", $alt);
466  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
467  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
468  $template->parseCurrentBlock();
469  } else {
470  $template->setCurrentBlock("answer_image");
471  $template->setVariable("ANSWER_IMAGE_URL", $answer->getImageWebPath());
472  list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
473  $alt = $answer->getImageFile();
474  if (strlen($answer->getAnswertext())) {
475  $alt = $answer->getAnswertext();
476  }
477  $alt = preg_replace("/<[^>]*?>/", "", $alt);
478  $template->setVariable("ATTR", $attr);
479  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
480  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
481  $template->parseCurrentBlock();
482  }
483  }
484 
485  if ($showInlineFeedback) {
486  $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
487  }
488 
489  $template->setCurrentBlock("answer_row");
490  $template->setVariable("ANSWER_ID", $answer_id);
491  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), true));
492  $template->setVariable('VALUE_TRUE', 1);
493  $template->setVariable('VALUE_FALSE', 0);
494 
495  if (isset($user_solution[$answer->getPosition()])) {
496  $tplVar = $user_solution[$answer->getPosition()] ? 'CHECKED_ANSWER_TRUE' : 'CHECKED_ANSWER_FALSE';
497  $template->setVariable($tplVar, " checked=\"checked\"");
498  }
499 
500  $template->parseCurrentBlock();
501  }
502  $questiontext = $this->object->getQuestion();
503  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, true));
504 
505  $template->setVariable("INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
506  $this->lng,
507  $this->object->getOptionLabel()
508  ));
509 
510  $template->setVariable("OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
511  $this->lng,
512  $this->object->getOptionLabel()
513  ));
514 
515  $template->setVariable("OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
516  $this->lng,
517  $this->object->getOptionLabel()
518  ));
519 
520  $questionoutput = $template->get();
521  if (!$show_question_only) {
522  // get page object output
523  $questionoutput = $this->getILIASPage($questionoutput);
524  }
525  return $questionoutput;
526  }
527 
539  public function getSolutionOutput(
540  $active_id,
541  $pass = null,
542  $graphicalOutput = false,
543  $result_output = false,
544  $show_question_only = true,
545  $show_feedback = false,
546  $show_correct_solution = false,
547  $show_manual_scoring = false,
548  $show_question_text = true
549  ) {
550  // shuffle output
552 
553  // get the solution of the user for the active pass or from the last pass if allowed
554  $user_solution = array();
555  if (($active_id > 0) && (!$show_correct_solution)) {
556  $solutions =&$this->object->getSolutionValues($active_id, $pass);
557  foreach ($solutions as $idx => $solution_value) {
558  $user_solution[$solution_value['value1']] = $solution_value['value2'];
559  }
560  } else {
561  // take the correct solution instead of the user solution
562  foreach ($this->object->getAnswers() as $answer) {
563  $user_solution[$answer->getPosition()] = $answer->getCorrectness();
564  }
565  }
566 
567  // generate the question output
568  $template = new ilTemplate("tpl.il_as_qpl_mc_kprim_output_solution.html", true, true, "Modules/TestQuestionPool");
569 
570  foreach ($keys as $answer_id) {
571  $answer = $this->object->getAnswer($answer_id);
572 
573  if (($active_id > 0) && (!$show_correct_solution)) {
574  if ($graphicalOutput) {
575  // output of ok/not ok icons for user entered solutions
576 
577  if ($user_solution[$answer->getPosition()] == $answer->getCorrectness()) {
578  $template->setCurrentBlock("icon_ok");
579  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
580  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
581  $template->parseCurrentBlock();
582  } else {
583  $template->setCurrentBlock("icon_ok");
584  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
585  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
586  $template->parseCurrentBlock();
587  }
588  }
589  }
590  if (strlen($answer->getImageFile())) {
591  $template->setCurrentBlock("answer_image");
592  if ($this->object->getThumbSize()) {
593  $template->setVariable("ANSWER_IMAGE_URL", $answer->getThumbWebPath());
594  } else {
595  $template->setVariable("ANSWER_IMAGE_URL", $answer->getImageWebPath());
596  }
597 
598  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($answer->getImageFile()));
599  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($answer->getImageFile()));
600  $template->parseCurrentBlock();
601  }
602 
603  if ($show_feedback) {
604  $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
605  }
606 
607  $template->setCurrentBlock("answer_row");
608  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), true));
609 
610  if ($this->renderPurposeSupportsFormHtml() || $this->isRenderPurposePrintPdf()) {
611  if (isset($user_solution[$answer->getPosition()])) {
612  if ($user_solution[$answer->getPosition()]) {
613  $template->setVariable("SOLUTION_IMAGE_TRUE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_checked.png")));
614  $template->setVariable("SOLUTION_ALT_TRUE", $this->lng->txt("checked"));
615  $template->setVariable("SOLUTION_IMAGE_FALSE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
616  $template->setVariable("SOLUTION_ALT_FALSE", $this->lng->txt("unchecked"));
617  } else {
618  $template->setVariable("SOLUTION_IMAGE_TRUE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
619  $template->setVariable("SOLUTION_ALT_TRUE", $this->lng->txt("unchecked"));
620  $template->setVariable("SOLUTION_IMAGE_FALSE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_checked.png")));
621  $template->setVariable("SOLUTION_ALT_FALSE", $this->lng->txt("checked"));
622  }
623  } else {
624  $template->setVariable("SOLUTION_IMAGE_TRUE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
625  $template->setVariable("SOLUTION_ALT_TRUE", $this->lng->txt("unchecked"));
626  $template->setVariable("SOLUTION_IMAGE_FALSE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
627  $template->setVariable("SOLUTION_ALT_FALSE", $this->lng->txt("unchecked"));
628  }
629  } else {
630  $template->setVariable('SOL_QID', $this->object->getId());
631  $template->setVariable('SOL_SUFFIX', $show_correct_solution ? 'bestsolution' : 'usersolution');
632  $template->setVariable('SOL_POSITION', $answer->getPosition());
633 
634  $template->setVariable('SOL_TRUE_VALUE', 1);
635  $template->setVariable('SOL_FALSE_VALUE', 0);
636 
637  if (isset($user_solution[$answer->getPosition()])) {
638  if ($user_solution[$answer->getPosition()]) {
639  $template->setVariable('SOL_TRUE_CHECKED', 'checked');
640  } else {
641  $template->setVariable('SOL_FALSE_CHECKED', 'checked');
642  }
643  }
644  }
645 
646  $template->parseCurrentBlock();
647  }
648 
649  if ($show_question_text==true) {
650  $questiontext = $this->object->getQuestion();
651  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, true));
652 
653  $template->setVariable("INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
654  $this->lng,
655  $this->object->getOptionLabel()
656  ));
657  }
658 
659  $template->setVariable("OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
660  $this->lng,
661  $this->object->getOptionLabel()
662  ));
663 
664  $template->setVariable("OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
665  $this->lng,
666  $this->object->getOptionLabel()
667  ));
668 
669 
670  $questionoutput = $template->get();
671  $feedback = ($show_feedback && !$this->isTestPresentationContext()) ? $this->getGenericFeedbackOutput($active_id, $pass) : "";
672 
673  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "Modules/TestQuestionPool");
674 
675  if (strlen($feedback)) {
676  $cssClass = (
677  $this->hasCorrectSolution($active_id, $pass) ?
679  );
680 
681  $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
682  $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, true));
683  }
684 
685  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
686 
687  $solutionoutput = $solutiontemplate->get();
688 
689  if (!$show_question_only) {
690  // get page object output
691  $solutionoutput = $this->getILIASPage($solutionoutput);
692  }
693  return $solutionoutput;
694  }
695 
696  protected function getParticipantsAnswerKeySequence()
697  {
698  $choiceKeys = array_keys($this->object->getAnswers());
699 
700  if ($this->object->isShuffleAnswersEnabled()) {
701  $choiceKeys = $this->object->getShuffler()->shuffle($choiceKeys);
702  }
703 
704  return $choiceKeys;
705  }
706 
707  private function populateSpecificFeedbackInline($user_solution, $answer_id, $template)
708  {
709  require_once 'Modules/TestQuestionPool/classes/feedback/class.ilAssConfigurableMultiOptionQuestionFeedback.php';
710 
711  if ($this->object->getSpecificFeedbackSetting() == ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_CHECKED) {
712  if ($user_solution[$answer_id]) {
713  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
714  if (strlen($fb)) {
715  $template->setCurrentBlock("feedback");
716  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
717  $template->parseCurrentBlock();
718  }
719  }
720  }
721 
722  if ($this->object->getSpecificFeedbackSetting() == ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_ALL) {
723  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
724  if (strlen($fb)) {
725  $template->setCurrentBlock("feedback");
726  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
727  $template->parseCurrentBlock();
728  }
729  }
730 
731  if ($this->object->getSpecificFeedbackSetting() == ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_CORRECT) {
732  $answer = $this->object->getAnswer($answer_id);
733 
734  if ($answer->getCorrectness()) {
735  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
736  if (strlen($fb)) {
737  $template->setCurrentBlock("feedback");
738  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
739  $template->parseCurrentBlock();
740  }
741  }
742  }
743  }
744 
755  {
756  return array();
757  }
758 
769  {
770  return array();
771  }
772 
781  public function getAggregatedAnswersView($relevant_answers)
782  {
783  return $this->renderAggregateView(
784  $this->aggregateAnswers($relevant_answers, $this->object->getAnswers())
785  )->get();
786 
787  return '<pre>' . print_r($relevant_answers, 1) . '</pre>';
788  }
789 
790  public function renderAggregateView($aggregate)
791  {
792  $trueOptionLabel = $this->object->getTrueOptionLabelTranslation($this->lng, $this->object->getOptionLabel());
793  $falseOptionLabel = $this->object->getFalseOptionLabelTranslation($this->lng, $this->object->getOptionLabel());
794 
795  $tpl = new ilTemplate('tpl.il_as_aggregated_kprim_answers_table.html', true, true, "Modules/TestQuestionPool");
796 
797  foreach ($aggregate as $lineData) {
798  $tpl->setCurrentBlock('aggregaterow');
799  $tpl->setVariable('OPTION', $lineData['answertext']);
800  $tpl->setVariable('COUNT_TRUE', $lineData['count_true']);
801  $tpl->setVariable('COUNT_FALSE', $lineData['count_false']);
802  $tpl->parseCurrentBlock();
803  }
804 
805  $tpl->setVariable('OPTION_HEAD', $this->lng->txt('answers'));
806  $tpl->setVariable('COUNT_TRUE_HEAD', $trueOptionLabel);
807  $tpl->setVariable('COUNT_FALSE_HEAD', $falseOptionLabel);
808 
809  return $tpl;
810  }
811 
812  public function aggregateAnswers($rawSolutionData, $answers)
813  {
814  $aggregate = array();
815 
816  foreach ($answers as $answer) {
817  $answerAgg = array(
818  'answertext' => $answer->getAnswerText(), 'count_true' => 0, 'count_false' => 0
819  );
820 
821  foreach ($rawSolutionData as $solutionRecord) {
822  if ($solutionRecord['value1'] == $answer->getPosition()) {
823  if ($solutionRecord['value2']) {
824  $answerAgg['count_true']++;
825  } else {
826  $answerAgg['count_false']++;
827  }
828  }
829  }
830 
831  $aggregate[] = $answerAgg;
832  }
833 
834  return $aggregate;
835  }
836 }
$files
Definition: add-vimline.php:18
getSpecificFeedbackOutput($active_id, $pass)
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...
addBasicQuestionFormProperties($form)
Add basic question form properties: assessment: title, author, description, question, working time.
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)
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)
setOptions($a_options)
Set Options.
Basic GUI class for assessment questions.
static getHtmlPath($relative_path)
get url of path
Create styles array
The data for the language used.
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...
Create new PHPExcel object
obj_idprivate
editQuestion(ilPropertyFormGUI $form=null)
static secureString($a_str, $a_strip_html=true, $a_allow="")
Remove unsecure tags.
Interface ilGuiAnswerScoringAdjustable.
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
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)
$key
Definition: croninfo.php:18
$_POST["username"]
populateSpecificFeedbackInline($user_solution, $answer_id, $template)
setRequired($a_required)
Set Required.
addQuestionFormCommandButtons($form)
Add the command buttons of a question properties form.
populateQuestionSpecificFormPart(ilPropertyFormGUI $form)