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