ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
4require_once 'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
5require_once 'Modules/TestQuestionPool/interfaces/interface.ilGuiQuestionScoringAdjustable.php';
6require_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 {
35 $this->object->loadFromDb($qId);
36 }
37 }
38
40 {
41 return array('uploadImage', 'removeImage');
42 }
43
44 protected function editQuestion(ilPropertyFormGUI $form = null)
45 {
46 if( $form === null )
47 {
48 $form = $this->buildEditForm();
49 }
50
51 $this->getQuestionTemplate();
52 $this->tpl->addCss('Modules/Test/templates/default/ta.css');
53
54 $this->tpl->setVariable("QUESTION_DATA", $this->ctrl->getHTML($form));
55 }
56
57 protected function uploadImage()
58 {
59 $result = $this->writePostData(true);
60
61 if( $result == 0 )
62 {
63 $this->object->saveToDb();
64 $this->editQuestion();
65 }
66 }
67
68 public function removeImage()
69 {
70 $position = key($_POST['cmd']['removeImage']);
71 $this->object->removeAnswerImage($position);
72
73 $this->object->saveToDb();
74 $this->editQuestion();
75 }
76
77 public function downkprim_answers()
78 {
79 if( isset($_POST['cmd'][__FUNCTION__]) && count($_POST['cmd'][__FUNCTION__]) )
80 {
81 $this->object->moveAnswerDown( key($_POST['cmd'][__FUNCTION__]) );
82 $this->object->saveToDb();
83 }
84
85 $this->editQuestion();
86 }
87
88 public function upkprim_answers()
89 {
90 if( isset($_POST['cmd'][__FUNCTION__]) && count($_POST['cmd'][__FUNCTION__]) )
91 {
92 $this->object->moveAnswerUp( key($_POST['cmd'][__FUNCTION__]) );
93 $this->object->saveToDb();
94 }
95
96 $this->editQuestion();
97 }
98
102 protected function writePostData($upload = false)
103 {
104 $form = $this->buildEditForm();
105 $form->setValuesByPost();
106
107 if( $upload )
108 {
109 $answersInput = $form->getItemByPostVar('kprim_answers');
110 $answersInput->setIgnoreMissingUploadsEnabled(true);
111
112 if( !$answersInput->checkUploads($_POST[$answersInput->getPostVar()]) )
113 {
114 ilUtil::sendFailure($this->lng->txt("form_input_not_valid"));
115 $this->editQuestion($form);
116 return 1;
117 }
118
119 $answersInput->collectValidFiles();
120 }
121 elseif( !$form->checkInput() )
122 {
123 $this->editQuestion($form);
124 return 1;
125 }
126
128
129 $this->writeQuestionSpecificPostData($form);
130 $this->writeAnswerSpecificPostData($form);
131
133
134 return 0;
135 }
136
140 protected function buildEditForm()
141 {
142 $form = $this->buildBasicEditFormObject();
143
144 $this->addQuestionFormCommandButtons($form);
145
146 $this->addBasicQuestionFormProperties($form);
147
149 $this->populateAnswerSpecificFormPart($form);
150
151 $this->populateTaxonomyFormSection($form);
152
153 return $form;
154 }
155
161 {
162 // shuffle answers
163 $shuffleAnswers = new ilCheckboxInputGUI($this->lng->txt( "shuffle_answers" ), "shuffle_answers_enabled");
164 $shuffleAnswers->setChecked( $this->object->isShuffleAnswersEnabled() );
165 $form->addItem($shuffleAnswers);
166
167 if( !$this->object->getSelfAssessmentEditingMode() )
168 {
169 // answer mode (single-/multi-line)
170 $answerType = new ilSelectInputGUI($this->lng->txt('answer_types'), 'answer_type');
171 $answerType->setOptions($this->object->getAnswerTypeSelectOptions($this->lng));
172 $answerType->setValue( $this->object->getAnswerType() );
173 $form->addItem($answerType);
174 }
175
176 if( !$this->object->getSelfAssessmentEditingMode() && $this->object->isSingleLineAnswerType($this->object->getAnswerType()) )
177 {
178 // thumb size
179 $thumbSize = new ilNumberInputGUI($this->lng->txt('thumb_size'), 'thumb_size');
180 $thumbSize->setSuffix($this->lng->txt("thumb_size_unit_pixel"));
181 $thumbSize->setInfo( $this->lng->txt('thumb_size_info') );
182 $thumbSize->setDecimals(false);
183 $thumbSize->setMinValue(20);
184 $thumbSize->setSize(6);
185 $thumbSize->setValue( $this->object->getThumbSize() );
186 $form->addItem($thumbSize);
187 }
188
189 // option label
190 $optionLabel = new ilRadioGroupInputGUI($this->lng->txt('option_label'), 'option_label');
191 $optionLabel->setInfo($this->lng->txt('option_label_info'));
192 $optionLabel->setRequired(true);
193 $optionLabel->setValue($this->object->getOptionLabel());
194 foreach($this->object->getValidOptionLabelsTranslated($this->lng) as $labelValue => $labelText)
195 {
196 $option = new ilRadioOption($labelText, $labelValue);
197 $optionLabel->addOption($option);
198
199 if( $this->object->isCustomOptionLabel($labelValue) )
200 {
201 $customLabelTrue = new ilTextInputGUI(
202 $this->lng->txt('option_label_custom_true'), 'option_label_custom_true'
203 );
204 $customLabelTrue->setValue($this->object->getCustomTrueOptionLabel());
205 $option->addSubItem($customLabelTrue);
206
207 $customLabelFalse = new ilTextInputGUI(
208 $this->lng->txt('option_label_custom_false'), 'option_label_custom_false'
209 );
210 $customLabelFalse->setValue($this->object->getCustomFalseOptionLabel());
211 $option->addSubItem($customLabelFalse);
212 }
213 }
214 $form->addItem($optionLabel);
215
216 // points
217 $points = new ilNumberInputGUI($this->lng->txt('points'), 'points');
218 $points->setRequired(true);
219 $points->setSize(3);
220 $points->allowDecimals(true);
221 $points->setMinValue(0);
222 $points->setMinvalueShouldBeGreater(true);
223 $points->setValue($this->object->getPoints());
224 $form->addItem($points);
225
226 // score partial solution
227 $scorePartialSolution = new ilCheckboxInputGUI($this->lng->txt('score_partsol_enabled'), 'score_partsol_enabled');
228 $scorePartialSolution->setInfo($this->lng->txt('score_partsol_enabled_info'));
229 $scorePartialSolution->setChecked( $this->object->isScorePartialSolutionEnabled() );
230 $form->addItem($scorePartialSolution);
231
232 return $form;
233 }
234
239 {
240 $oldAnswerType = $this->object->getAnswerType();
241
242 $this->object->setShuffleAnswersEnabled($form->getItemByPostVar('shuffle_answers_enabled')->getChecked());
243
244 if( !$this->object->getSelfAssessmentEditingMode() )
245 {
246 $this->object->setAnswerType($form->getItemByPostVar('answer_type')->getValue());
247 }
248 else
249 {
250 $this->object->setAnswerType(assKprimChoice::ANSWER_TYPE_MULTI_LINE);
251 }
252
253 if( !$this->object->getSelfAssessmentEditingMode() && $this->object->isSingleLineAnswerType($oldAnswerType) )
254 {
255 $this->object->setThumbSize($form->getItemByPostVar('thumb_size')->getValue());
256 }
257
258 $this->object->setOptionLabel($form->getItemByPostVar('option_label')->getValue());
259
260 if( $this->object->isCustomOptionLabel($this->object->getOptionLabel()) )
261 {
262 $this->object->setCustomTrueOptionLabel( strip_tags(
263 $form->getItemByPostVar('option_label_custom_true')->getValue()
264 ));
265 $this->object->setCustomFalseOptionLabel( strip_tags(
266 $form->getItemByPostVar('option_label_custom_false')->getValue()
267 ));
268 }
269
270 $this->object->setPoints($form->getItemByPostVar('points')->getValue());
271
272 $this->object->setScorePartialSolutionEnabled($form->getItemByPostVar('score_partsol_enabled')->getChecked());
273 }
274
280 {
281 require_once 'Modules/TestQuestionPool/classes/class.ilKprimChoiceWizardInputGUI.php';
282 $kprimAnswers = new ilKprimChoiceWizardInputGUI($this->lng->txt('answers'), 'kprim_answers');
283 $kprimAnswers->setInfo($this->lng->txt('kprim_answers_info'));
284 $kprimAnswers->setSize(64);
285 $kprimAnswers->setMaxLength(1000);
286 $kprimAnswers->setRequired(true);
287 $kprimAnswers->setAllowMove(true);
288 $kprimAnswers->setQuestionObject($this->object);
289 if( !$this->object->getSelfAssessmentEditingMode() )
290 {
291 $kprimAnswers->setSingleline($this->object->isSingleLineAnswerType($this->object->getAnswerType()));
292 }
293 else
294 {
295 $kprimAnswers->setSingleline(false);
296 }
297 $kprimAnswers->setValues($this->object->getAnswers());
298 $form->addItem($kprimAnswers);
299
300 return $form;
301 }
302
307 {
308 $answers = $form->getItemByPostVar('kprim_answers')->getValues();
309 $answers = $this->handleAnswerTextsSubmit($answers);
310 $files = $form->getItemByPostVar('kprim_answers')->getFiles();
311
312 $this->object->handleFileUploads($answers, $files);
313 $this->object->setAnswers($answers);
314 }
315
316 private function handleAnswerTextsSubmit($answers)
317 {
318 if( $this->object->getAnswerType() == assKprimChoice::ANSWER_TYPE_MULTI_LINE )
319 {
320 return $answers;
321 }
322
323 foreach($answers as $key => $answer)
324 {
325 $answer->setAnswerText(ilUtil::secureString($answer->getAnswerText()));
326 }
327
328 return $answers;
329 }
330
336 function getSpecificFeedbackOutput($active_id, $pass)
337 {
338 return ''; // question type supports inline answer specific feedback
339 }
340
351 $active_id,
352 // hey: prevPassSolutions - will be always available from now on
353 $pass,
354 // hey.
355 $is_postponed = FALSE,
356 $use_post_solutions = FALSE,
357 $showInlineFeedback = FALSE
358 )
359 {
360 // shuffle output
361 $keys = $this->getParticipantsAnswerKeySequence();
362
363 // get the solution of the user for the active pass or from the last pass if allowed
364 $user_solution = array();
365 if ($active_id)
366 {
367 // hey: prevPassSolutions - obsolete due to central check
368 #$solutions = NULL;
369 #include_once "./Modules/Test/classes/class.ilObjTest.php";
370 #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
371 #{
372 # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
373 #}
374 $solutions = $this->object->getTestOutputSolutions($active_id, $pass);
375 // hey.
376 foreach ($solutions as $idx => $solution_value)
377 {
378 $user_solution[$solution_value["value1"]] = $solution_value["value2"];
379 }
380 }
381
382 // generate the question output
383 include_once "./Services/UICore/classes/class.ilTemplate.php";
384 $template = new ilTemplate("tpl.il_as_qpl_mc_kprim_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
385
386 foreach ($keys as $answer_id)
387 {
388 $answer = $this->object->getAnswer($answer_id);
389 if (strlen($answer->getImageFile()))
390 {
391 if ($this->object->getThumbSize())
392 {
393 $template->setCurrentBlock("preview");
394 $template->setVariable("URL_PREVIEW", $answer->getImageWebPath());
395 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
396 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
397 $template->setVariable("ANSWER_IMAGE_URL", $answer->getThumbWebPath());
398 list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
399 $alt = $answer->getImageFile();
400 if (strlen($answer->getAnswertext()))
401 {
402 $alt = $answer->getAnswertext();
403 }
404 $alt = preg_replace("/<[^>]*?>/", "", $alt);
405 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
406 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
407 $template->parseCurrentBlock();
408 }
409 else
410 {
411 $template->setCurrentBlock("answer_image");
412 $template->setVariable("ANSWER_IMAGE_URL", $answer->getImageWebPath());
413 list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
414 $alt = $answer->getImageFile();
415 if (strlen($answer->getAnswertext()))
416 {
417 $alt = $answer->getAnswertext();
418 }
419 $alt = preg_replace("/<[^>]*?>/", "", $alt);
420 $template->setVariable("ATTR", $attr);
421 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
422 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
423 $template->parseCurrentBlock();
424 }
425 }
426
427 if( $showInlineFeedback )
428 {
429 $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
430 }
431
432 $template->setCurrentBlock("answer_row");
433 $template->setVariable("ANSWER_ID", $answer_id);
434 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
435 $template->setVariable('VALUE_TRUE', 1);
436 $template->setVariable('VALUE_FALSE', 0);
437
438 if( isset($user_solution[$answer->getPosition()]) )
439 {
440 $tplVar = $user_solution[$answer->getPosition()] ? 'CHECKED_ANSWER_TRUE' : 'CHECKED_ANSWER_FALSE';
441 $template->setVariable($tplVar, " checked=\"checked\"");
442 }
443
444 $template->parseCurrentBlock();
445 }
446
447 $questiontext = $this->object->getQuestion();
448 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
449
450 $template->setVariable("INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
451 $this->lng, $this->object->getOptionLabel()
452 ));
453
454 $template->setVariable("OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
455 $this->lng, $this->object->getOptionLabel()
456 ));
457
458 $template->setVariable("OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
459 $this->lng, $this->object->getOptionLabel()
460 ));
461
462 $questionoutput = $template->get();
463 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
464 return $pageoutput;
465 }
466
471 public function getPreview($show_question_only = FALSE, $showInlineFeedback = false)
472 {
473 $user_solution = is_object($this->getPreviewSession()) ? (array)$this->getPreviewSession()->getParticipantsSolution() : array();
474 // shuffle output
475 $keys = $this->getParticipantsAnswerKeySequence();
476
477 // generate the question output
478 include_once "./Services/UICore/classes/class.ilTemplate.php";
479 $template = new ilTemplate("tpl.il_as_qpl_mc_kprim_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
480
481 foreach ($keys as $answer_id)
482 {
483 $answer = $this->object->getAnswer($answer_id);
484 if (strlen($answer->getImageFile()))
485 {
486 if ($this->object->getThumbSize())
487 {
488 $template->setCurrentBlock("preview");
489 $template->setVariable("URL_PREVIEW", $answer->getImageWebPath());
490 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
491 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
492 $template->setVariable("ANSWER_IMAGE_URL", $answer->getThumbWebPath());
493 list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
494 $alt = $answer->getImageFile();
495 if (strlen($answer->getAnswertext()))
496 {
497 $alt = $answer->getAnswertext();
498 }
499 $alt = preg_replace("/<[^>]*?>/", "", $alt);
500 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
501 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
502 $template->parseCurrentBlock();
503 }
504 else
505 {
506 $template->setCurrentBlock("answer_image");
507 $template->setVariable("ANSWER_IMAGE_URL", $answer->getImageWebPath());
508 list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
509 $alt = $answer->getImageFile();
510 if (strlen($answer->getAnswertext()))
511 {
512 $alt = $answer->getAnswertext();
513 }
514 $alt = preg_replace("/<[^>]*?>/", "", $alt);
515 $template->setVariable("ATTR", $attr);
516 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
517 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
518 $template->parseCurrentBlock();
519 }
520 }
521
522 if( $showInlineFeedback )
523 {
524 $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
525 }
526
527 $template->setCurrentBlock("answer_row");
528 $template->setVariable("ANSWER_ID", $answer_id);
529 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
530 $template->setVariable('VALUE_TRUE', 1);
531 $template->setVariable('VALUE_FALSE', 0);
532
533 if( isset($user_solution[$answer->getPosition()]) )
534 {
535 $tplVar = $user_solution[$answer->getPosition()] ? 'CHECKED_ANSWER_TRUE' : 'CHECKED_ANSWER_FALSE';
536 $template->setVariable($tplVar, " checked=\"checked\"");
537 }
538
539 $template->parseCurrentBlock();
540 }
541 $questiontext = $this->object->getQuestion();
542 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
543
544 $template->setVariable("INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
545 $this->lng, $this->object->getOptionLabel()
546 ));
547
548 $template->setVariable("OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
549 $this->lng, $this->object->getOptionLabel()
550 ));
551
552 $template->setVariable("OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
553 $this->lng, $this->object->getOptionLabel()
554 ));
555
556 $questionoutput = $template->get();
557 if (!$show_question_only)
558 {
559 // get page object output
560 $questionoutput = $this->getILIASPage($questionoutput);
561 }
562 return $questionoutput;
563 }
564
576 public function getSolutionOutput(
577 $active_id,
578 $pass = NULL,
579 $graphicalOutput = FALSE,
580 $result_output = FALSE,
581 $show_question_only = TRUE,
582 $show_feedback = FALSE,
583 $show_correct_solution = FALSE,
584 $show_manual_scoring = FALSE,
585 $show_question_text = TRUE
586 )
587 {
588 // shuffle output
589 $keys = $this->getParticipantsAnswerKeySequence();
590
591 // get the solution of the user for the active pass or from the last pass if allowed
592 $user_solution = array();
593 if (($active_id > 0) && (!$show_correct_solution))
594 {
595 $solutions =& $this->object->getSolutionValues($active_id, $pass);
596 foreach ($solutions as $idx => $solution_value)
597 {
598 $user_solution[$solution_value['value1']] = $solution_value['value2'];
599 }
600 }
601 else
602 {
603 // take the correct solution instead of the user solution
604 foreach ($this->object->getAnswers() as $answer)
605 {
606 $user_solution[$answer->getPosition()] = $answer->getCorrectness();
607 }
608 }
609
610 // generate the question output
611 $template = new ilTemplate("tpl.il_as_qpl_mc_kprim_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
612
613 foreach ($keys as $answer_id)
614 {
615 $answer = $this->object->getAnswer($answer_id);
616
617 if (($active_id > 0) && (!$show_correct_solution))
618 {
619 if ($graphicalOutput)
620 {
621 // output of ok/not ok icons for user entered solutions
622
623 if( $user_solution[$answer->getPosition()] == $answer->getCorrectness() )
624 {
625 $template->setCurrentBlock("icon_ok");
626 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
627 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
628 $template->parseCurrentBlock();
629 }
630 else
631 {
632 $template->setCurrentBlock("icon_ok");
633 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
634 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
635 $template->parseCurrentBlock();
636 }
637 }
638 }
639 if (strlen($answer->getImageFile()))
640 {
641 $template->setCurrentBlock("answer_image");
642 if ($this->object->getThumbSize())
643 {
644 $template->setVariable("ANSWER_IMAGE_URL", $answer->getThumbWebPath());
645 }
646 else
647 {
648 $template->setVariable("ANSWER_IMAGE_URL", $answer->getImageWebPath());
649 }
650
651 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($answer->getImageFile()));
652 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($answer->getImageFile()));
653 $template->parseCurrentBlock();
654 }
655
656 if ($show_feedback)
657 {
658 $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
659 }
660
661 $template->setCurrentBlock("answer_row");
662 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
663
665 {
666 if( isset($user_solution[$answer->getPosition()]) )
667 {
668 if( $user_solution[$answer->getPosition()] )
669 {
670 $template->setVariable("SOLUTION_IMAGE_TRUE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_checked.png")));
671 $template->setVariable("SOLUTION_ALT_TRUE", $this->lng->txt("checked"));
672 $template->setVariable("SOLUTION_IMAGE_FALSE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
673 $template->setVariable("SOLUTION_ALT_FALSE", $this->lng->txt("unchecked"));
674 }
675 else
676 {
677 $template->setVariable("SOLUTION_IMAGE_TRUE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
678 $template->setVariable("SOLUTION_ALT_TRUE", $this->lng->txt("unchecked"));
679 $template->setVariable("SOLUTION_IMAGE_FALSE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_checked.png")));
680 $template->setVariable("SOLUTION_ALT_FALSE", $this->lng->txt("checked"));
681 }
682 }
683 else
684 {
685 $template->setVariable("SOLUTION_IMAGE_TRUE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
686 $template->setVariable("SOLUTION_ALT_TRUE", $this->lng->txt("unchecked"));
687 $template->setVariable("SOLUTION_IMAGE_FALSE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
688 $template->setVariable("SOLUTION_ALT_FALSE", $this->lng->txt("unchecked"));
689 }
690 }
691 else
692 {
693 $template->setVariable('SOL_QID', $this->object->getId());
694 $template->setVariable('SOL_SUFFIX', $show_correct_solution ? 'bestsolution' : 'usersolution');
695 $template->setVariable('SOL_POSITION', $answer->getPosition());
696
697 $template->setVariable('SOL_TRUE_VALUE', 1);
698 $template->setVariable('SOL_FALSE_VALUE', 0);
699
700 if( isset($user_solution[$answer->getPosition()]) )
701 {
702 if( $user_solution[$answer->getPosition()] )
703 {
704 $template->setVariable('SOL_TRUE_CHECKED', 'checked');
705 }
706 else
707 {
708 $template->setVariable('SOL_FALSE_CHECKED', 'checked');
709 }
710 }
711 }
712
713 $template->parseCurrentBlock();
714 }
715
716 if ($show_question_text==true)
717 {
718 $questiontext = $this->object->getQuestion();
719 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
720
721 $template->setVariable("INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
722 $this->lng, $this->object->getOptionLabel()
723 ));
724 }
725
726 $template->setVariable("OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
727 $this->lng, $this->object->getOptionLabel()
728 ));
729
730 $template->setVariable("OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
731 $this->lng, $this->object->getOptionLabel()
732 ));
733
734
735 $questionoutput = $template->get();
736 $feedback = ($show_feedback && !$this->isTestPresentationContext()) ? $this->getGenericFeedbackOutput($active_id, $pass) : "";
737
738 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
739
740 if (strlen($feedback))
741 {
742 $cssClass = ( $this->hasCorrectSolution($active_id, $pass) ?
744 );
745
746 $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
747 $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $feedback, true ));
748 }
749
750 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
751
752 $solutionoutput = $solutiontemplate->get();
753
754 if (!$show_question_only)
755 {
756 // get page object output
757 $solutionoutput = $this->getILIASPage($solutionoutput);
758 }
759 return $solutionoutput;
760 }
761
763 {
764 $choiceKeys = array_keys($this->object->getAnswers());
765
766 if( $this->object->isShuffleAnswersEnabled() )
767 {
768 $choiceKeys = $this->object->getShuffler()->shuffle($choiceKeys);
769 }
770
771 return $choiceKeys;
772 }
773
774 private function populateSpecificFeedbackInline($user_solution, $answer_id, $template)
775 {
776 require_once 'Modules/TestQuestionPool/classes/feedback/class.ilAssConfigurableMultiOptionQuestionFeedback.php';
777
778 if($this->object->getSpecificFeedbackSetting() == ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_CHECKED)
779 {
780 if($user_solution[$answer_id])
781 {
782 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
783 if(strlen($fb))
784 {
785 $template->setCurrentBlock("feedback");
786 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
787 $template->parseCurrentBlock();
788 }
789 }
790 }
791
792 if($this->object->getSpecificFeedbackSetting() == ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_ALL)
793 {
794 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
795 if(strlen($fb))
796 {
797 $template->setCurrentBlock("feedback");
798 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
799 $template->parseCurrentBlock();
800 }
801 }
802
803 if($this->object->getSpecificFeedbackSetting() == ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_CORRECT)
804 {
805 $answer = $this->object->getAnswer($answer_id);
806
807 if($answer->getCorrectness())
808 {
809 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
810 if(strlen($fb))
811 {
812 $template->setCurrentBlock("feedback");
813 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
814 $template->parseCurrentBlock();
815 }
816 }
817 }
818 }
819
830 {
831 return array();
832 }
833
844 {
845 return array();
846 }
847
856 public function getAggregatedAnswersView($relevant_answers)
857 {
858 return $this->renderAggregateView(
859 $this->aggregateAnswers( $relevant_answers, $this->object->getAnswers() ) )->get();
860
861 return '<pre>'.print_r($relevant_answers, 1).'</pre>';
862 }
863
864 public function renderAggregateView($aggregate)
865 {
866 $trueOptionLabel = $this->object->getTrueOptionLabelTranslation($this->lng, $this->object->getOptionLabel());
867 $falseOptionLabel = $this->object->getFalseOptionLabelTranslation($this->lng, $this->object->getOptionLabel());
868
869 $tpl = new ilTemplate('tpl.il_as_aggregated_kprim_answers_table.html', true, true, "Modules/TestQuestionPool");
870
871 foreach( $aggregate as $lineData )
872 {
873 $tpl->setCurrentBlock('aggregaterow');
874 $tpl->setVariable('OPTION', $lineData['answertext']);
875 $tpl->setVariable('COUNT_TRUE', $lineData['count_true']);
876 $tpl->setVariable('COUNT_FALSE', $lineData['count_false']);
877 $tpl->parseCurrentBlock();
878 }
879
880 $tpl->setVariable('OPTION_HEAD', $this->lng->txt('answers'));
881 $tpl->setVariable('COUNT_TRUE_HEAD', $trueOptionLabel);
882 $tpl->setVariable('COUNT_FALSE_HEAD', $falseOptionLabel);
883
884 return $tpl;
885 }
886
887 public function aggregateAnswers($rawSolutionData, $answers)
888 {
889 $aggregate = array();
890
891 foreach( $answers as $answer )
892 {
893 $answerAgg = array(
894 'answertext' => $answer->getAnswerText(), 'count_true' => 0, 'count_false' => 0
895 );
896
897 foreach( $rawSolutionData as $solutionRecord )
898 {
899 if( $solutionRecord['value1'] == $answer->getPosition() )
900 {
901 if( $solutionRecord['value2'] )
902 {
903 $answerAgg['count_true']++;
904 }
905 else
906 {
907 $answerAgg['count_false']++;
908 }
909 }
910
911 }
912
913 $aggregate[] = $answerAgg;
914 }
915
916 return $aggregate;
917 }
918
919}
$result
$files
Definition: add-vimline.php:18
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
populateSpecificFeedbackInline($user_solution, $answer_id, $template)
getPreview($show_question_only=FALSE, $showInlineFeedback=false)
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
getAfterParticipationSuppressionAnswerPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getTestOutput( $active_id, $pass, $is_postponed=FALSE, $use_post_solutions=FALSE, $showInlineFeedback=FALSE)
writePostData($upload=false)
{Evaluates a posted edit form and writes the form data in the question object.integer A positive valu...
getAggregatedAnswersView($relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
editQuestion(ilPropertyFormGUI $form=null)
getSpecificFeedbackOutput($active_id, $pass)
aggregateAnswers($rawSolutionData, $answers)
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)
populateAnswerSpecificFormPart(ilPropertyFormGUI $form)
populateQuestionSpecificFormPart(ilPropertyFormGUI $form)
Basic GUI class for assessment questions.
populateTaxonomyFormSection(ilPropertyFormGUI $form)
addQuestionFormCommandButtons($form)
Add the command buttons of a question properties form.
getILIASPage($html="")
Returns the ILIAS Page around a question.
getQuestionTemplate()
get question template
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
hasCorrectSolution($activeId, $passIndex)
addBasicQuestionFormProperties($form)
Add basic question form properties: assessment: title, author, description, question,...
getGenericFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
This class represents a checkbox property in a property form.
This class represents a number property in a property form.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getItemByPostVar($a_post_var)
Get Item by POST variable.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static secureString($a_str, $a_strip_html=true, $a_allow="")
Remove unsecure tags.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static getHtmlPath($relative_path)
get url of path
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
Interface ilGuiAnswerScoringAdjustable.
Interface ilGuiQuestionScoringAdjustable.