ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
99 protected function writePostData($upload = false)
100 {
101 $form = $this->buildEditForm();
102 $form->setValuesByPost();
103
104 if( $upload )
105 {
106 $answersInput = $form->getItemByPostVar('kprim_answers');
107 $answersInput->setIgnoreMissingUploadsEnabled(true);
108
109 if( !$answersInput->checkUploads($_POST[$answersInput->getPostVar()]) )
110 {
111 ilUtil::sendFailure($this->lng->txt("form_input_not_valid"));
112 $this->editQuestion($form);
113 return 1;
114 }
115
116 $answersInput->collectValidFiles();
117 }
118 elseif( !$form->checkInput() )
119 {
120 $this->editQuestion($form);
121 return 1;
122 }
123
125
126 $this->writeQuestionSpecificPostData($form);
127 $this->writeAnswerSpecificPostData($form);
128
130
131 return 0;
132 }
133
137 private function buildEditForm()
138 {
139 $form = $this->buildBasicEditFormObject();
140
141 $this->addQuestionFormCommandButtons($form);
142
143 $this->addBasicQuestionFormProperties($form);
144
146 $this->populateAnswerSpecificFormPart($form);
147
148 $this->populateTaxonomyFormSection($form);
149
150 return $form;
151 }
152
158 {
159 // shuffle answers
160 $shuffleAnswers = new ilCheckboxInputGUI($this->lng->txt( "shuffle_answers" ), "shuffle_answers_enabled");
161 $shuffleAnswers->setChecked( $this->object->isShuffleAnswersEnabled() );
162 $form->addItem($shuffleAnswers);
163
164 if( !$this->object->getSelfAssessmentEditingMode() )
165 {
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 {
175 // thumb size
176 $thumbSize = new ilNumberInputGUI($this->lng->txt('thumb_size'), 'thumb_size');
177 $thumbSize->setSuffix($this->lng->txt("thumb_size_unit_pixel"));
178 $thumbSize->setInfo( $this->lng->txt('thumb_size_info') );
179 $thumbSize->setDecimals(false);
180 $thumbSize->setMinValue(20);
181 $thumbSize->setSize(6);
182 $thumbSize->setValue( $this->object->getThumbSize() );
183 $form->addItem($thumbSize);
184 }
185
186 // option label
187 $optionLabel = new ilRadioGroupInputGUI($this->lng->txt('option_label'), 'option_label');
188 $optionLabel->setInfo($this->lng->txt('option_label_info'));
189 $optionLabel->setRequired(true);
190 $optionLabel->setValue($this->object->getOptionLabel());
191 foreach($this->object->getValidOptionLabelsTranslated($this->lng) as $labelValue => $labelText)
192 {
193 $option = new ilRadioOption($labelText, $labelValue);
194 $optionLabel->addOption($option);
195
196 if( $this->object->isCustomOptionLabel($labelValue) )
197 {
198 $customLabelTrue = new ilTextInputGUI(
199 $this->lng->txt('option_label_custom_true'), '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'), 'option_label_custom_false'
206 );
207 $customLabelFalse->setValue($this->object->getCustomFalseOptionLabel());
208 $option->addSubItem($customLabelFalse);
209 }
210 }
211 $form->addItem($optionLabel);
212
213 // points
214 $points = new ilNumberInputGUI($this->lng->txt('points'), 'points');
215 $points->setRequired(true);
216 $points->setSize(3);
217 $points->allowDecimals(true);
218 $points->setMinValue(0);
219 $points->setMinvalueShouldBeGreater(true);
220 $points->setValue($this->object->getPoints());
221 $form->addItem($points);
222
223 // score partial solution
224 $scorePartialSolution = new ilCheckboxInputGUI($this->lng->txt('score_partsol_enabled'), 'score_partsol_enabled');
225 $scorePartialSolution->setInfo($this->lng->txt('score_partsol_enabled_info'));
226 $scorePartialSolution->setChecked( $this->object->isScorePartialSolutionEnabled() );
227 $form->addItem($scorePartialSolution);
228
229 return $form;
230 }
231
236 {
237 $oldAnswerType = $this->object->getAnswerType();
238
239 $this->object->setShuffleAnswersEnabled($form->getItemByPostVar('shuffle_answers_enabled')->getChecked());
240
241 if( !$this->object->getSelfAssessmentEditingMode() )
242 {
243 $this->object->setAnswerType($form->getItemByPostVar('answer_type')->getValue());
244 }
245 else
246 {
247 $this->object->setAnswerType(assKprimChoice::ANSWER_TYPE_MULTI_LINE);
248 }
249
250 if( !$this->object->getSelfAssessmentEditingMode() && $this->object->isSingleLineAnswerType($oldAnswerType) )
251 {
252 $this->object->setThumbSize($form->getItemByPostVar('thumb_size')->getValue());
253 }
254
255 $this->object->setOptionLabel($form->getItemByPostVar('option_label')->getValue());
256
257 if( $this->object->isCustomOptionLabel($this->object->getOptionLabel()) )
258 {
259 $this->object->setCustomTrueOptionLabel( strip_tags(
260 $form->getItemByPostVar('option_label_custom_true')->getValue()
261 ));
262 $this->object->setCustomFalseOptionLabel( strip_tags(
263 $form->getItemByPostVar('option_label_custom_false')->getValue()
264 ));
265 }
266
267 $this->object->setPoints($form->getItemByPostVar('points')->getValue());
268
269 $this->object->setScorePartialSolutionEnabled($form->getItemByPostVar('score_partsol_enabled')->getChecked());
270 }
271
277 {
278 require_once 'Modules/TestQuestionPool/classes/class.ilKprimChoiceWizardInputGUI.php';
279 $kprimAnswers = new ilKprimChoiceWizardInputGUI($this->lng->txt('answers'), 'kprim_answers');
280 $kprimAnswers->setInfo($this->lng->txt('kprim_answers_info'));
281 $kprimAnswers->setSize(64);
282 $kprimAnswers->setMaxLength(1000);
283 $kprimAnswers->setRequired(true);
284 $kprimAnswers->setAllowMove(true);
285 $kprimAnswers->setQuestionObject($this->object);
286 if( !$this->object->getSelfAssessmentEditingMode() )
287 {
288 $kprimAnswers->setSingleline($this->object->isSingleLineAnswerType($this->object->getAnswerType()));
289 }
290 else
291 {
292 $kprimAnswers->setSingleline(false);
293 }
294 $kprimAnswers->setValues($this->object->getAnswers());
295 $form->addItem($kprimAnswers);
296
297 return $form;
298 }
299
304 {
305 $answers = $form->getItemByPostVar('kprim_answers')->getValues();
306 $answers = $this->handleAnswerTextsSubmit($answers);
307 $files = $form->getItemByPostVar('kprim_answers')->getFiles();
308
309 $this->object->handleFileUploads($answers, $files);
310 $this->object->setAnswers($answers);
311 }
312
313 private function handleAnswerTextsSubmit($answers)
314 {
315 if( $this->object->getAnswerType() == assKprimChoice::ANSWER_TYPE_MULTI_LINE )
316 {
317 return $answers;
318 }
319
320 foreach($answers as $key => $answer)
321 {
322 $answer->setAnswerText(ilUtil::secureString($answer->getAnswerText()));
323 }
324
325 return $answers;
326 }
327
333 function getSpecificFeedbackOutput($active_id, $pass)
334 {
335 return ''; // question type supports inline answer specific feedback
336 }
337
348 $active_id,
349 $pass = NULL,
350 $is_postponed = FALSE,
351 $use_post_solutions = FALSE,
352 $showInlineFeedback = FALSE
353 )
354 {
355 // shuffle output
356 $keys = $this->getParticipantsAnswerKeySequence();
357
358 // get the solution of the user for the active pass or from the last pass if allowed
359 $user_solution = array();
360 if ($active_id)
361 {
362 $solutions = NULL;
363 include_once "./Modules/Test/classes/class.ilObjTest.php";
364 if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
365 {
366 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
367 }
368 $solutions =& $this->object->getSolutionValues($active_id, $pass);
369 foreach ($solutions as $idx => $solution_value)
370 {
371 $user_solution[$solution_value["value1"]] = $solution_value["value2"];
372 }
373 }
374
375 // generate the question output
376 include_once "./Services/UICore/classes/class.ilTemplate.php";
377 $template = new ilTemplate("tpl.il_as_qpl_mc_kprim_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
378
379 foreach ($keys as $answer_id)
380 {
381 $answer = $this->object->getAnswer($answer_id);
382 if (strlen($answer->getImageFile()))
383 {
384 if ($this->object->getThumbSize())
385 {
386 $template->setCurrentBlock("preview");
387 $template->setVariable("URL_PREVIEW", $answer->getImageWebPath());
388 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
389 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
390 $template->setVariable("ANSWER_IMAGE_URL", $answer->getThumbWebPath());
391 list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
392 $alt = $answer->getImageFile();
393 if (strlen($answer->getAnswertext()))
394 {
395 $alt = $answer->getAnswertext();
396 }
397 $alt = preg_replace("/<[^>]*?>/", "", $alt);
398 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
399 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
400 $template->parseCurrentBlock();
401 }
402 else
403 {
404 $template->setCurrentBlock("answer_image");
405 $template->setVariable("ANSWER_IMAGE_URL", $answer->getImageWebPath());
406 list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
407 $alt = $answer->getImageFile();
408 if (strlen($answer->getAnswertext()))
409 {
410 $alt = $answer->getAnswertext();
411 }
412 $alt = preg_replace("/<[^>]*?>/", "", $alt);
413 $template->setVariable("ATTR", $attr);
414 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
415 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
416 $template->parseCurrentBlock();
417 }
418 }
419
420 if( $showInlineFeedback )
421 {
422 $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
423 }
424
425 $template->setCurrentBlock("answer_row");
426 $template->setVariable("ANSWER_ID", $answer_id);
427 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
428 $template->setVariable('VALUE_TRUE', 1);
429 $template->setVariable('VALUE_FALSE', 0);
430
431 if( isset($user_solution[$answer->getPosition()]) )
432 {
433 $tplVar = $user_solution[$answer->getPosition()] ? 'CHECKED_ANSWER_TRUE' : 'CHECKED_ANSWER_FALSE';
434 $template->setVariable($tplVar, " checked=\"checked\"");
435 }
436
437 $template->parseCurrentBlock();
438 }
439
440 $questiontext = $this->object->getQuestion();
441 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
442
443 $template->setVariable("INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
444 $this->lng, $this->object->getOptionLabel()
445 ));
446
447 $template->setVariable("OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
448 $this->lng, $this->object->getOptionLabel()
449 ));
450
451 $template->setVariable("OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
452 $this->lng, $this->object->getOptionLabel()
453 ));
454
455 $questionoutput = $template->get();
456 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
457 return $pageoutput;
458 }
459
464 public function getPreview($show_question_only = FALSE, $showInlineFeedback = false)
465 {
466 $user_solution = is_object($this->getPreviewSession()) ? (array)$this->getPreviewSession()->getParticipantsSolution() : array();
467 // shuffle output
468 $keys = $this->getParticipantsAnswerKeySequence();
469
470 // generate the question output
471 include_once "./Services/UICore/classes/class.ilTemplate.php";
472 $template = new ilTemplate("tpl.il_as_qpl_mc_kprim_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
473
474 foreach ($keys as $answer_id)
475 {
476 $answer = $this->object->getAnswer($answer_id);
477 if (strlen($answer->getImageFile()))
478 {
479 if ($this->object->getThumbSize())
480 {
481 $template->setCurrentBlock("preview");
482 $template->setVariable("URL_PREVIEW", $answer->getImageWebPath());
483 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
484 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
485 $template->setVariable("ANSWER_IMAGE_URL", $answer->getThumbWebPath());
486 list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
487 $alt = $answer->getImageFile();
488 if (strlen($answer->getAnswertext()))
489 {
490 $alt = $answer->getAnswertext();
491 }
492 $alt = preg_replace("/<[^>]*?>/", "", $alt);
493 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
494 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
495 $template->parseCurrentBlock();
496 }
497 else
498 {
499 $template->setCurrentBlock("answer_image");
500 $template->setVariable("ANSWER_IMAGE_URL", $answer->getImageWebPath());
501 list($width, $height, $type, $attr) = getimagesize($answer->getImageFsPath());
502 $alt = $answer->getImageFile();
503 if (strlen($answer->getAnswertext()))
504 {
505 $alt = $answer->getAnswertext();
506 }
507 $alt = preg_replace("/<[^>]*?>/", "", $alt);
508 $template->setVariable("ATTR", $attr);
509 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
510 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
511 $template->parseCurrentBlock();
512 }
513 }
514
515 if( $showInlineFeedback )
516 {
517 $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
518 }
519
520 $template->setCurrentBlock("answer_row");
521 $template->setVariable("ANSWER_ID", $answer_id);
522 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
523 $template->setVariable('VALUE_TRUE', 1);
524 $template->setVariable('VALUE_FALSE', 0);
525
526 if( isset($user_solution[$answer->getPosition()]) )
527 {
528 $tplVar = $user_solution[$answer->getPosition()] ? 'CHECKED_ANSWER_TRUE' : 'CHECKED_ANSWER_FALSE';
529 $template->setVariable($tplVar, " checked=\"checked\"");
530 }
531
532 $template->parseCurrentBlock();
533 }
534 $questiontext = $this->object->getQuestion();
535 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
536
537 $template->setVariable("INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
538 $this->lng, $this->object->getOptionLabel()
539 ));
540
541 $template->setVariable("OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
542 $this->lng, $this->object->getOptionLabel()
543 ));
544
545 $template->setVariable("OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
546 $this->lng, $this->object->getOptionLabel()
547 ));
548
549 $questionoutput = $template->get();
550 if (!$show_question_only)
551 {
552 // get page object output
553 $questionoutput = $this->getILIASPage($questionoutput);
554 }
555 return $questionoutput;
556 }
557
569 public function getSolutionOutput(
570 $active_id,
571 $pass = NULL,
572 $graphicalOutput = FALSE,
573 $result_output = FALSE,
574 $show_question_only = TRUE,
575 $show_feedback = FALSE,
576 $show_correct_solution = FALSE,
577 $show_manual_scoring = FALSE,
578 $show_question_text = TRUE
579 )
580 {
581 // shuffle output
582 $keys = $this->getParticipantsAnswerKeySequence();
583
584 // get the solution of the user for the active pass or from the last pass if allowed
585 $user_solution = array();
586 if (($active_id > 0) && (!$show_correct_solution))
587 {
588 $solutions =& $this->object->getSolutionValues($active_id, $pass);
589 foreach ($solutions as $idx => $solution_value)
590 {
591 $user_solution[$solution_value['value1']] = $solution_value['value2'];
592 }
593 }
594 else
595 {
596 // take the correct solution instead of the user solution
597 foreach ($this->object->getAnswers() as $answer)
598 {
599 $user_solution[$answer->getPosition()] = $answer->getCorrectness();
600 }
601 }
602
603 // generate the question output
604 $template = new ilTemplate("tpl.il_as_qpl_mc_kprim_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
605
606 foreach ($keys as $answer_id)
607 {
608 $answer = $this->object->getAnswer($answer_id);
609
610 if (($active_id > 0) && (!$show_correct_solution))
611 {
612 if ($graphicalOutput)
613 {
614 // output of ok/not ok icons for user entered solutions
615
616 if( $user_solution[$answer->getPosition()] == $answer->getCorrectness() )
617 {
618 $template->setCurrentBlock("icon_ok");
619 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
620 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
621 $template->parseCurrentBlock();
622 }
623 else
624 {
625 $template->setCurrentBlock("icon_ok");
626 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
627 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
628 $template->parseCurrentBlock();
629 }
630 }
631 }
632 if (strlen($answer->getImageFile()))
633 {
634 $template->setCurrentBlock("answer_image");
635 if ($this->object->getThumbSize())
636 {
637 $template->setVariable("ANSWER_IMAGE_URL", $answer->getThumbWebPath());
638 }
639 else
640 {
641 $template->setVariable("ANSWER_IMAGE_URL", $answer->getImageWebPath());
642 }
643
644 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($answer->getImageFile()));
645 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($answer->getImageFile()));
646 $template->parseCurrentBlock();
647 }
648
649 if ($show_feedback)
650 {
651 $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
652 }
653
654 $template->setCurrentBlock("answer_row");
655 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
656
657 if( isset($user_solution[$answer->getPosition()]) )
658 {
659 if( $user_solution[$answer->getPosition()] )
660 {
661 $template->setVariable("SOLUTION_IMAGE_TRUE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_checked.png")));
662 $template->setVariable("SOLUTION_ALT_TRUE", $this->lng->txt("checked"));
663 $template->setVariable("SOLUTION_IMAGE_FALSE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
664 $template->setVariable("SOLUTION_ALT_FALSE", $this->lng->txt("unchecked"));
665 }
666 else
667 {
668 $template->setVariable("SOLUTION_IMAGE_TRUE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
669 $template->setVariable("SOLUTION_ALT_TRUE", $this->lng->txt("unchecked"));
670 $template->setVariable("SOLUTION_IMAGE_FALSE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_checked.png")));
671 $template->setVariable("SOLUTION_ALT_FALSE", $this->lng->txt("checked"));
672 }
673 }
674 else
675 {
676 $template->setVariable("SOLUTION_IMAGE_TRUE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
677 $template->setVariable("SOLUTION_ALT_TRUE", $this->lng->txt("unchecked"));
678 $template->setVariable("SOLUTION_IMAGE_FALSE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
679 $template->setVariable("SOLUTION_ALT_FALSE", $this->lng->txt("unchecked"));
680 }
681
682 $template->parseCurrentBlock();
683 }
684
685 if ($show_question_text==true)
686 {
687 $questiontext = $this->object->getQuestion();
688 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
689
690 $template->setVariable("INSTRUCTIONTEXT", $this->object->getInstructionTextTranslation(
691 $this->lng, $this->object->getOptionLabel()
692 ));
693 }
694
695 $template->setVariable("OPTION_LABEL_TRUE", $this->object->getTrueOptionLabelTranslation(
696 $this->lng, $this->object->getOptionLabel()
697 ));
698
699 $template->setVariable("OPTION_LABEL_FALSE", $this->object->getFalseOptionLabelTranslation(
700 $this->lng, $this->object->getOptionLabel()
701 ));
702
703
704 $questionoutput = $template->get();
705 $feedback = ($show_feedback) ? $this->getGenericFeedbackOutput($active_id, $pass) : "";
706
707 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
708
709 if( strlen($feedback) )
710 {
711 $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $feedback , true ));
712 }
713
714 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
715
716 $solutionoutput = $solutiontemplate->get();
717
718 if (!$show_question_only)
719 {
720 // get page object output
721 $solutionoutput = $this->getILIASPage($solutionoutput);
722 }
723 return $solutionoutput;
724 }
725
727 {
728 if( !$this->object->isShuffleAnswersEnabled() )
729 {
730 return array_keys($this->object->getAnswers());
731 }
732
733 if (strcmp($_GET["activecommand"], "directfeedback") == 0)
734 {
735 if (is_array($_SESSION["choicekeys"])) $this->choiceKeys = $_SESSION["choicekeys"];
736 }
737 if (!is_array($this->choiceKeys))
738 {
739 $this->choiceKeys = array_keys($this->object->getAnswers());
740 if ($this->object->getShuffle())
741 {
742 $this->choiceKeys = $this->object->pcArrayShuffle($this->choiceKeys);
743 }
744 }
745 $_SESSION["choicekeys"] = $this->choiceKeys;
746 return $this->choiceKeys;
747 }
748
749 private function populateSpecificFeedbackInline($user_solution, $answer_id, $template)
750 {
751 require_once 'Modules/TestQuestionPool/classes/feedback/class.ilAssConfigurableMultiOptionQuestionFeedback.php';
752
753 if($this->object->getSpecificFeedbackSetting() == ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_CHECKED)
754 {
755 if($user_solution[$answer_id])
756 {
757 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
758 if(strlen($fb))
759 {
760 $template->setCurrentBlock("feedback");
761 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
762 $template->parseCurrentBlock();
763 }
764 }
765 }
766
767 if($this->object->getSpecificFeedbackSetting() == ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_ALL)
768 {
769 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
770 if(strlen($fb))
771 {
772 $template->setCurrentBlock("feedback");
773 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
774 $template->parseCurrentBlock();
775 }
776 }
777
778 if($this->object->getSpecificFeedbackSetting() == ilAssConfigurableMultiOptionQuestionFeedback::FEEDBACK_SETTING_CORRECT)
779 {
780 $answer = $this->object->getAnswer($answer_id);
781
782 if($answer->getCorrectness())
783 {
784 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
785 if(strlen($fb))
786 {
787 $template->setCurrentBlock("feedback");
788 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
789 $template->parseCurrentBlock();
790 }
791 }
792 }
793 }
794
805 {
806 return array();
807 }
808
819 {
820 return array();
821 }
822
831 public function getAggregatedAnswersView($relevant_answers)
832 {
833 return $this->renderAggregateView(
834 $this->aggregateAnswers( $relevant_answers, $this->object->getAnswers() ) )->get();
835
836 return '<pre>'.print_r($relevant_answers, 1).'</pre>';
837 }
838
839 public function renderAggregateView($aggregate)
840 {
841 $trueOptionLabel = $this->object->getTrueOptionLabelTranslation($this->lng, $this->object->getOptionLabel());
842 $falseOptionLabel = $this->object->getFalseOptionLabelTranslation($this->lng, $this->object->getOptionLabel());
843
844 $tpl = new ilTemplate('tpl.il_as_aggregated_kprim_answers_table.html', true, true, "Modules/TestQuestionPool");
845
846 foreach( $aggregate as $lineData )
847 {
848 $tpl->setCurrentBlock('aggregaterow');
849 $tpl->setVariable('OPTION', $lineData['answertext']);
850 $tpl->setVariable('COUNT_TRUE', $lineData['count_true']);
851 $tpl->setVariable('COUNT_FALSE', $lineData['count_false']);
852 $tpl->parseCurrentBlock();
853 }
854
855 $tpl->setVariable('OPTION_HEAD', $this->lng->txt('answers'));
856 $tpl->setVariable('COUNT_TRUE_HEAD', $trueOptionLabel);
857 $tpl->setVariable('COUNT_FALSE_HEAD', $falseOptionLabel);
858
859 return $tpl;
860 }
861
862 public function aggregateAnswers($rawSolutionData, $answers)
863 {
864 $aggregate = array();
865
866 foreach( $answers as $answer )
867 {
868 $answerAgg = array(
869 'answertext' => $answer->getAnswerText(), 'count_true' => 0, 'count_false' => 0
870 );
871
872 foreach( $rawSolutionData as $solutionRecord )
873 {
874 if( $solutionRecord['value1'] == $answer->getPosition() )
875 {
876 if( $solutionRecord['value2'] )
877 {
878 $answerAgg['count_true']++;
879 }
880 else
881 {
882 $answerAgg['count_false']++;
883 }
884 }
885
886 }
887
888 $aggregate[] = $answerAgg;
889 }
890
891 return $aggregate;
892 }
893
894}
$result
$_GET["client_id"]
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=NULL, $is_postponed=FALSE, $use_post_solutions=FALSE, $showInlineFeedback=FALSE)
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
writePostData()
Evaluates a posted edit form and writes the form data in the question object.
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
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.
_getUsePreviousAnswers($active_id, $user_active_user_setting=false)
Returns if the previous results should be hidden for a learner.
_getPass($active_id)
Retrieves the actual pass of a given user for a given test.
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
$_POST['username']
Definition: cron.php:12
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
Interface ilGuiAnswerScoringAdjustable.
Interface ilGuiQuestionScoringAdjustable.