ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.assSingleChoiceGUI.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';
7require_once './Modules/Test/classes/inc.AssessmentConstants.php';
8
24{
32 public function __construct($id = -1)
33 {
34 parent::__construct();
35 include_once "./Modules/TestQuestionPool/classes/class.assSingleChoice.php";
36 $this->object = new assSingleChoice();
37 if ($id >= 0)
38 {
39 $this->object->loadFromDb($id);
40 }
41 }
42
46 protected function writePostData($always = false)
47 {
48 $hasErrors = (!$always) ? $this->editQuestion(true) : false;
49 if (!$hasErrors)
50 {
51 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
56 return 0;
57 }
58 return 1;
59 }
60
68 protected function getEditAnswersSingleLine($checkonly = false)
69 {
70 if ($checkonly)
71 {
72 // form posting is checked
73 return ($_POST['types'] == 0) ? true : false;
74 }
75
76 $lastChange = $this->object->getLastChange();
77 if (empty($lastChange) && !isset($_POST['types']))
78 {
79 // a new question is edited
80 return $this->object->getMultilineAnswerSetting() ? false : true;
81 }
82 else
83 {
84 // a saved question is edited
85 return $this->object->isSingleline;
86 }
87 }
88
93 public function editQuestion($checkonly = FALSE)
94 {
95 $save = $this->isSaveCommand();
96 $this->getQuestionTemplate();
97
98 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
99 $form = new ilPropertyFormGUI();
100 $this->editForm = $form;
101
102 $form->setFormAction($this->ctrl->getFormAction($this));
103 $form->setTitle($this->outQuestionType());
104 $isSingleline = $this->getEditAnswersSingleLine($checkonly);
105 if ($isSingleline)
106 {
107 $form->setMultipart(TRUE);
108 }
109 else
110 {
111 $form->setMultipart(FALSE);
112 }
113 $form->setTableWidth("100%");
114 $form->setId("asssinglechoice");
115
116 $this->addBasicQuestionFormProperties( $form );
117 $this->populateQuestionSpecificFormPart( $form );
118 $this->populateAnswerSpecificFormPart( $form );
119
120
121 $this->populateTaxonomyFormSection($form);
122
123 $this->addQuestionFormCommandButtons($form);
124
125 $errors = false;
126
127 if ($save)
128 {
129 $form->setValuesByPost();
130 $errors = !$form->checkInput();
131 $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes
132 if ($errors) $checkonly = false;
133 }
134
135 if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
136 return $errors;
137 }
138
142 public function uploadchoice()
143 {
144 $this->writePostData(true);
145 $position = key($_POST['cmd']['uploadchoice']);
146 $this->editQuestion();
147 }
148
152 public function removeimagechoice()
153 {
154 $this->writePostData(true);
155 $position = key($_POST['cmd']['removeimagechoice']);
156 $filename = $_POST['choice']['imagename'][$position];
157 $this->object->removeAnswerImage($position);
158 $this->editQuestion();
159 }
160
164 public function addchoice()
165 {
166 $this->writePostData(true);
167 $position = key($_POST['cmd']['addchoice']);
168 $this->object->addAnswer("", 0, $position+1);
169 $this->editQuestion();
170 }
171
175 public function removechoice()
176 {
177 $this->writePostData(true);
178 $position = key($_POST['cmd']['removechoice']);
179 $this->object->deleteAnswer($position);
180 $this->editQuestion();
181 }
182
197 $active_id,
198 $pass = NULL,
199 $graphicalOutput = FALSE,
200 $result_output = FALSE,
201 $show_question_only = TRUE,
202 $show_feedback = FALSE,
203 $show_correct_solution = FALSE,
204 $show_manual_scoring = FALSE,
205 $show_question_text = TRUE
206 )
207 {
208 // shuffle output
209 $keys = $this->getChoiceKeys();
210
211 // get the solution of the user for the active pass or from the last pass if allowed
212 $user_solution = "";
213 if (($active_id > 0) && (!$show_correct_solution))
214 {
215 $solutions =& $this->object->getSolutionValues($active_id, $pass);
216 foreach ($solutions as $idx => $solution_value)
217 {
218 $user_solution = $solution_value["value1"];
219 }
220 }
221 else
222 {
223 $found_index = -1;
224 $max_points = 0;
225 foreach ($this->object->answers as $index => $answer)
226 {
227 if ($answer->getPoints() > $max_points)
228 {
229 $max_points = $answer->getPoints();
230 $found_index = $index;
231 }
232 }
233 $user_solution = $found_index;
234 }
235 // generate the question output
236 include_once "./Services/UICore/classes/class.ilTemplate.php";
237 $template = new ilTemplate("tpl.il_as_qpl_mc_sr_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
238 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
239 foreach ($keys as $answer_id)
240 {
241 $answer = $this->object->answers[$answer_id];
242 if (($active_id > 0) && (!$show_correct_solution))
243 {
244 if ($graphicalOutput)
245 {
246 // output of ok/not ok icons for user entered solutions
247 $ok = FALSE;
248 if (strcmp($user_solution, $answer_id) == 0)
249 {
250 if ($answer->getPoints() == $this->object->getMaximumPoints())
251 {
252 $ok = TRUE;
253 }
254 else
255 {
256 $ok = FALSE;
257 }
258 if ($ok)
259 {
260 $template->setCurrentBlock("icon_ok");
261 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
262 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
263 $template->parseCurrentBlock();
264 }
265 else
266 {
267 $template->setCurrentBlock("icon_not_ok");
268 if ($answer->getPoints() > 0)
269 {
270 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.svg"));
271 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
272 }
273 else
274 {
275 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
276 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
277 }
278 $template->parseCurrentBlock();
279 }
280 }
281 if (strlen($user_solution) == 0)
282 {
283 $template->setCurrentBlock("icon_not_ok");
284 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
285 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
286 $template->parseCurrentBlock();
287 }
288 }
289 }
290 if (strlen($answer->getImage()))
291 {
292 $template->setCurrentBlock("answer_image");
293 if ($this->object->getThumbSize())
294 {
295 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
296 }
297 else
298 {
299 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
300 }
301 $alt = $answer->getImage();
302 if (strlen($answer->getAnswertext()))
303 {
304 $alt = $answer->getAnswertext();
305 }
306 $alt = preg_replace("/<[^>]*?>/", "", $alt);
307 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
308 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
309 $template->parseCurrentBlock();
310 }
311 if ($show_feedback)
312 {
313 $this->populateInlineFeedback($template, $answer_id, $user_solution);
314 }
315 $template->setCurrentBlock("answer_row");
316 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
317
319 {
320 if (strcmp($user_solution, $answer_id) == 0)
321 {
322 $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_checked.png")));
323 $template->setVariable("SOLUTION_ALT", $this->lng->txt("checked"));
324 }
325 else
326 {
327 $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
328 $template->setVariable("SOLUTION_ALT", $this->lng->txt("unchecked"));
329 }
330 }
331 else
332 {
333 $template->setVariable('QID', $this->object->getId());
334 $template->setVariable('SUFFIX', $show_correct_solution ? 'bestsolution' : 'usersolution');
335 $template->setVariable('SOLUTION_VALUE', $answer_id);
336 if (strcmp($user_solution, $answer_id) == 0)
337 {
338 $template->setVariable('SOLUTION_CHECKED', 'checked');
339 }
340 }
341
342 if ($result_output)
343 {
344 $points = $this->object->answers[$answer_id]->getPoints();
345 $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
346 $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
347 }
348 $template->parseCurrentBlock();
349 }
350 $questiontext = $this->object->getQuestion();
351 if ($show_question_text==true)
352 {
353 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
354 }
355 $questionoutput = $template->get();
356 $feedback = ($show_feedback && !$this->isTestPresentationContext()) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
357 if (strlen($feedback))
358 {
359 $cssClass = ( $this->hasCorrectSolution($active_id, $pass) ?
361 );
362
363 $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
364 $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $feedback, true ));
365 }
366 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
367
368 $solutionoutput = $solutiontemplate->get();
369 if (!$show_question_only)
370 {
371 // get page object output
372 $solutionoutput = $this->getILIASPage($solutionoutput);
373 }
374 return $solutionoutput;
375 }
376
377 public function getPreview($show_question_only = FALSE, $showInlineFeedback = false)
378 {
379 $keys = $this->getChoiceKeys();
380
381 // generate the question output
382 include_once "./Services/UICore/classes/class.ilTemplate.php";
383 $template = new ilTemplate("tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
384 foreach ($keys as $answer_id)
385 {
386 $answer = $this->object->answers[$answer_id];
387 if (strlen($answer->getImage()))
388 {
389 if ($this->object->getThumbSize())
390 {
391 $template->setCurrentBlock("preview");
392 $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
393 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
394 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
395 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
396 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
397 $alt = $answer->getImage();
398 if (strlen($answer->getAnswertext()))
399 {
400 $alt = $answer->getAnswertext();
401 }
402 $alt = preg_replace("/<[^>]*?>/", "", $alt);
403 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
404 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
405 $template->parseCurrentBlock();
406 }
407 else
408 {
409 $template->setCurrentBlock("answer_image");
410 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
411 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
412 $alt = $answer->getImage();
413 if (strlen($answer->getAnswertext()))
414 {
415 $alt = $answer->getAnswertext();
416 }
417 $alt = preg_replace("/<[^>]*?>/", "", $alt);
418 $template->setVariable("ATTR", $attr);
419 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
420 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
421 $template->parseCurrentBlock();
422 }
423 }
424 if( $showInlineFeedback && is_object($this->getPreviewSession()) )
425 {
426 $this->populateInlineFeedback($template, $answer_id, $this->getPreviewSession()->getParticipantsSolution());
427 }
428 $template->setCurrentBlock("answer_row");
429 $template->setVariable("QID", $this->object->getId().'ID');
430 $template->setVariable("ANSWER_ID", $answer_id);
431 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
432
433 if( is_object($this->getPreviewSession()) )
434 {
435 $user_solution = $this->getPreviewSession()->getParticipantsSolution();
436 if (strcmp($user_solution, $answer_id) == 0)
437 {
438 $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
439 }
440 }
441
442 $template->parseCurrentBlock();
443 }
444 $questiontext = $this->object->getQuestion();
445 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
446 $questionoutput = $template->get();
447 if (!$show_question_only)
448 {
449 // get page object output
450 $questionoutput = $this->getILIASPage($questionoutput);
451 }
452 return $questionoutput;
453 }
454
455 // hey: prevPassSolutions - pass will be always available from now on
456 function getTestOutput($active_id, $pass, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
457 // hey.
458 {
459 $keys = $this->getChoiceKeys();
460
461 // get the solution of the user for the active pass or from the last pass if allowed
462 $user_solution = "";
463 if ($active_id)
464 {
465 // hey: prevPassSolutions - obsolete due to central check
466 #$solutions = NULL;
467 #include_once "./Modules/Test/classes/class.ilObjTest.php";
468 #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
469 #{
470 # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
471 #}
472 // hey.
473 $solutions = $this->object->getTestOutputSolutions($active_id, $pass);
474 foreach ($solutions as $idx => $solution_value)
475 {
476 $user_solution = $solution_value["value1"];
477 }
478 }
479
480 // generate the question output
481 include_once "./Services/UICore/classes/class.ilTemplate.php";
482 $template = new ilTemplate("tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
483 foreach ($keys as $answer_id)
484 {
485 $answer = $this->object->answers[$answer_id];
486 if (strlen($answer->getImage()))
487 {
488 if ($this->object->getThumbSize())
489 {
490 $template->setCurrentBlock("preview");
491 $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
492 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
493 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
494 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
495 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
496 $alt = $answer->getImage();
497 if (strlen($answer->getAnswertext()))
498 {
499 $alt = $answer->getAnswertext();
500 }
501 $alt = preg_replace("/<[^>]*?>/", "", $alt);
502 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
503 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
504 $template->parseCurrentBlock();
505 }
506 else
507 {
508 $template->setCurrentBlock("answer_image");
509 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
510 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
511 $alt = $answer->getImage();
512 if (strlen($answer->getAnswertext()))
513 {
514 $alt = $answer->getAnswertext();
515 }
516 $alt = preg_replace("/<[^>]*?>/", "", $alt);
517 $template->setVariable("ATTR", $attr);
518 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
519 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
520 $template->parseCurrentBlock();
521 }
522 }
523 if ($show_feedback)
524 {
525 $feedbackOutputRequired = false;
526
527 switch( $this->object->getSpecificFeedbackSetting() )
528 {
529 case 1:
530 $feedbackOutputRequired = true;
531 break;
532
533 case 2:
534 if (strcmp($user_solution, $answer_id) == 0)
535 {
536 $feedbackOutputRequired = true;
537 }
538 break;
539
540 case 3:
541 if ($this->object->getAnswer($answer_id)->getPoints() > 0)
542 {
543 $feedbackOutputRequired = true;
544 }
545 break;
546 }
547
548 if($feedbackOutputRequired)
549 {
550 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
551 $this->object->getId(), $answer_id
552 );
553 if (strlen($fb))
554 {
555 $template->setCurrentBlock("feedback");
556 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $fb, true ));
557 $template->parseCurrentBlock();
558 }
559 }
560 }
561 $template->setCurrentBlock("answer_row");
562 $template->setVariable("ANSWER_ID", $answer_id);
563 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
564 if (strcmp($user_solution, $answer_id) == 0)
565 {
566 $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
567 }
568 $template->parseCurrentBlock();
569 }
570 $questiontext = $this->object->getQuestion();
571 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
572 $questionoutput = $template->get();
573 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
574 return $pageoutput;
575 }
576
585 {
586 global $rbacsystem, $ilTabs;
587
588 $ilTabs->clearTargets();
589
590 $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
591 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
592 $q_type = $this->object->getQuestionType();
593
594 if (strlen($q_type))
595 {
596 $classname = $q_type . "GUI";
597 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
598 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
599 }
600
601 if ($_GET["q_id"])
602 {
603 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
604 {
605 // edit page
606 $ilTabs->addTarget("edit_page",
607 $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
608 array("edit", "insert", "exec_pg"),
609 "", "", $force_active);
610 }
611
612 $this->addTab_QuestionPreview($ilTabs);
613 }
614
615 $force_active = false;
616 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
617 {
618 $url = "";
619 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
620 // edit question properties
621 $ilTabs->addTarget("edit_question",
622 $url,
623 array("editQuestion", "save", "saveEdit", "addchoice", "removechoice", "removeimagechoice", "uploadchoice", "originalSyncForm"),
624 $classname, "", $force_active);
625 }
626
627 // add tab for question feedback within common class assQuestionGUI
628 $this->addTab_QuestionFeedback($ilTabs);
629
630 // add tab for question hint within common class assQuestionGUI
631 $this->addTab_QuestionHints($ilTabs);
632
633 // add tab for question's suggested solution within common class assQuestionGUI
634 $this->addTab_SuggestedSolution($ilTabs, $classname);
635
636 // Assessment of questions sub menu entry
637 if ($_GET["q_id"])
638 {
639 $ilTabs->addTarget("statistics",
640 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
641 array("assessment"),
642 $classname, "");
643 }
644
645 $this->addBackTab($ilTabs);
646 }
647
648 /*
649 * Create the key index numbers for the array of choices
650 *
651 * @return array
652 */
653 function getChoiceKeys()
654 {
655 $choiceKeys = array_keys($this->object->answers);
656
657 if( $this->object->getShuffle() )
658 {
659 $choiceKeys = $this->object->getShuffler()->shuffle($choiceKeys);
660 }
661
662 return $choiceKeys;
663 }
664
665 function getSpecificFeedbackOutput($active_id, $pass)
666 {
667 // No return value, this question type supports inline specific feedback.
668 $output = "";
669 return $this->object->prepareTextareaOutput($output, TRUE);
670 }
671
673 {
674 $this->object->setShuffle( $_POST["shuffle"] );
675 $this->object->setMultilineAnswerSetting( $_POST["types"] );
676 if (is_array( $_POST['choice']['imagename'] ) && $_POST["types"] == 1)
677 {
678 $this->object->isSingleline = true;
679 ilUtil::sendInfo( $this->lng->txt( 'info_answer_type_change' ), true );
680 }
681 else
682 {
683 $this->object->isSingleline = ($_POST["types"] == 0) ? true : false;
684 }
685 $this->object->setThumbSize( (strlen( $_POST["thumb_size"] )) ? $_POST["thumb_size"] : "" );
686 }
687
689 {
690 $isSingleline = $this->getEditAnswersSingleLine();
691 // shuffle
692 $shuffle = new ilCheckboxInputGUI($this->lng->txt( "shuffle_answers" ), "shuffle");
693 $shuffle->setValue( 1 );
694 $shuffle->setChecked( $this->object->getShuffle() );
695 $shuffle->setRequired( FALSE );
696 $form->addItem( $shuffle );
697
698 if ($this->object->getId())
699 {
700 $hidden = new ilHiddenInputGUI("", "ID");
701 $hidden->setValue( $this->object->getId() );
702 $form->addItem( $hidden );
703 }
704
705 if (!$this->object->getSelfAssessmentEditingMode())
706 {
707 // Answer types
708 $types = new ilSelectInputGUI($this->lng->txt( "answer_types" ), "types");
709 $types->setRequired( false );
710 $types->setValue( ($isSingleline) ? 0 : 1 );
711 $types->setOptions( array(
712 0 => $this->lng->txt( 'answers_singleline' ),
713 1 => $this->lng->txt( 'answers_multiline' ),
714 )
715 );
716 $form->addItem( $types );
717 }
718
719 if ($isSingleline)
720 {
721 // thumb size
722 $thumb_size = new ilNumberInputGUI($this->lng->txt( "thumb_size" ), "thumb_size");
723 $thumb_size->setSuffix($this->lng->txt("thumb_size_unit_pixel"));
724 $thumb_size->setMinValue( 20 );
725 $thumb_size->setDecimals( 0 );
726 $thumb_size->setSize( 6 );
727 $thumb_size->setInfo( $this->lng->txt( 'thumb_size_info' ) );
728 $thumb_size->setValue( $this->object->getThumbSize() );
729 $thumb_size->setRequired( false );
730 $form->addItem( $thumb_size );
731 }
732 return $form;
733 }
734
745 {
746 return array();
747 }
748
750 {
751 // Delete all existing answers and create new answers from the form data
752 $this->object->flushAnswers();
753 if ($this->object->isSingleline)
754 {
755 foreach ($_POST['choice']['answer'] as $index => $answertext)
756 {
757 $answertext = ilUtil::secureString($answertext);
758
759 $picturefile = $_POST['choice']['imagename'][$index];
760 $file_org_name = $_FILES['choice']['name']['image'][$index];
761 $file_temp_name = $_FILES['choice']['tmp_name']['image'][$index];
762
763 if (strlen( $file_temp_name ))
764 {
765 // check suffix
766 $suffix = strtolower( array_pop( explode( ".", $file_org_name ) ) );
767 if (in_array( $suffix, array( "jpg", "jpeg", "png", "gif" ) ))
768 {
769 // upload image
770 $filename = $this->object->buildHashedImageFilename( $file_org_name );
771 if ($this->object->setImageFile( $filename, $file_temp_name ) == 0)
772 {
773 $picturefile = $filename;
774 }
775 }
776 }
777
778 $this->object->addAnswer( $answertext, $_POST['choice']['points'][$index], $index, $picturefile );
779 }
780 }
781 else
782 {
783 foreach ($_POST['choice']['answer'] as $index => $answer)
784 {
785 $answertext = $answer;
786 $this->object->addAnswer( $answertext, $_POST['choice']['points'][$index], $index );
787 }
788 }
789 }
790
792 {
793 $isSingleline = $this->getEditAnswersSingleLine();
794
795 // Choices
796 include_once "./Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php";
797 $choices = new ilSingleChoiceWizardInputGUI($this->lng->txt( "answers" ), "choice");
798 $choices->setRequired( true );
799 $choices->setQuestionObject( $this->object );
800 $choices->setSingleline( $isSingleline );
801 $choices->setAllowMove( false );
802 if ($this->object->getSelfAssessmentEditingMode())
803 {
804 $choices->setSize( 40 );
805 }
806 $choices->setMaxLength( 800 );
807 if ($this->object->getAnswerCount() == 0)
808 $this->object->addAnswer( "", 0, 0 );
809 $choices->setValues( $this->object->getAnswers() );
810 $form->addItem( $choices );
811 }
812
823 {
824 return array();
825 }
826
835 public function getAggregatedAnswersView($relevant_answers)
836 {
837 return $this->renderAggregateView(
838 $this->aggregateAnswers( $relevant_answers, $this->object->getAnswers() ) )->get();
839 }
840
841 public function aggregateAnswers($relevant_answers_chosen, $answers_defined_on_question)
842 {
843 $aggregate = array();
844 foreach ($answers_defined_on_question as $answer)
845 {
846 $aggregated_info_for_answer = array();
847 $aggregated_info_for_answer['answertext'] = $answer->getAnswerText();
848 $aggregated_info_for_answer['count_checked'] = 0;
849
850 foreach ($relevant_answers_chosen as $relevant_answer)
851 {
852 if ($relevant_answer['value1'] == $answer->getOrder())
853 {
854 $aggregated_info_for_answer['count_checked']++;
855 }
856 }
857 $aggregated_info_for_answer['count_unchecked'] =
858 ceil(count($relevant_answers_chosen) / count($answers_defined_on_question))
859 - $aggregated_info_for_answer['count_checked'];
860
861 $aggregate[] = $aggregated_info_for_answer;
862 }
863 return $aggregate;
864 }
865
871 public function renderAggregateView($aggregate)
872 {
873 $tpl = new ilTemplate('tpl.il_as_aggregated_answers_table.html', true, true, "Modules/TestQuestionPool");
874
875 $tpl->setCurrentBlock('headercell');
876 $tpl->setVariable('HEADER', $this->lng->txt('tst_answer_aggr_answer_header'));
877 $tpl->parseCurrentBlock();
878
879 $tpl->setCurrentBlock('headercell');
880 $tpl->setVariable('HEADER', $this->lng->txt('tst_answer_aggr_frequency_header'));
881 $tpl->parseCurrentBlock();
882
883 foreach ($aggregate as $line_data)
884 {
885 $tpl->setCurrentBlock( 'aggregaterow' );
886 $tpl->setVariable( 'OPTION', $line_data['answertext'] );
887 $tpl->setVariable( 'COUNT', $line_data['count_checked'] );
888 $tpl->parseCurrentBlock();
889 }
890 return $tpl;
891 }
892
893 private function populateInlineFeedback($template, $answer_id, $user_solution)
894 {
895 $feedbackOutputRequired = false;
896
897 switch($this->object->getSpecificFeedbackSetting())
898 {
899 case 1:
900 $feedbackOutputRequired = true;
901 break;
902
903 case 2:
904 if(strcmp($user_solution, $answer_id) == 0)
905 {
906 $feedbackOutputRequired = true;
907 }
908 break;
909
910 case 3:
911 if($this->object->getAnswer($answer_id)->getPoints() > 0)
912 {
913 $feedbackOutputRequired = true;
914 }
915 break;
916 }
917
918 if($feedbackOutputRequired)
919 {
920 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
921 if(strlen($fb))
922 {
923 $template->setCurrentBlock("feedback");
924 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
925 $template->parseCurrentBlock();
926 }
927 }
928 }
929}
sprintf('%.4f', $callTime)
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Basic GUI class for assessment questions.
populateTaxonomyFormSection(ilPropertyFormGUI $form)
addTab_QuestionHints(ilTabsGUI $tabs)
adds the hints tab to ilTabsGUI
addQuestionFormCommandButtons($form)
Add the command buttons of a question properties form.
getILIASPage($html="")
Returns the ILIAS Page around a question.
getQuestionTemplate()
get question template
addTab_SuggestedSolution(ilTabsGUI $tabs, $classname)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
addBackTab(ilTabsGUI $ilTabs)
hasCorrectSolution($activeId, $passIndex)
addTab_QuestionFeedback(ilTabsGUI $tabs)
adds the feedback tab to ilTabsGUI
addBasicQuestionFormProperties($form)
Add basic question form properties: assessment: title, author, description, question,...
addTab_QuestionPreview(ilTabsGUI $tabsGUI)
getAnswerFeedbackOutput($active_id, $pass)
Returns the answer generic feedback depending on the results of the question.
Single choice question GUI representation.
removeimagechoice()
Remove an image.
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
Extracts the answer specific values from $_POST and applies them to the data object.
populateAnswerSpecificFormPart(\ilPropertyFormGUI $form)
getEditAnswersSingleLine($checkonly=false)
Get the single/multiline editing of answers.
getAggregatedAnswersView($relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
populateInlineFeedback($template, $answer_id, $user_solution)
getAfterParticipationSuppressionAnswerPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
getPreview($show_question_only=FALSE, $showInlineFeedback=false)
addchoice()
Add a new answer.
removechoice()
Remove an answer.
editQuestion($checkonly=FALSE)
Creates an output of the edit form for the question.
writePostData($always=false)
{Evaluates a posted edit form and writes the form data in the question object.integer A positive valu...
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
__construct($id=-1)
assSingleChoiceGUI constructor
aggregateAnswers($relevant_answers_chosen, $answers_defined_on_question)
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)
Get the question solution output.
setQuestionTabs()
Sets the ILIAS tabs for this question type.
getTestOutput($active_id, $pass, $is_postponed=FALSE, $use_post_solutions=FALSE, $show_feedback=FALSE)
getSpecificFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form)
uploadchoice()
Upload an image.
Class for single choice questions.
This class represents a checkbox property in a property form.
This class represents a hidden form 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).
This class represents a selection list property in a property form.
This class represents a single choice wizard property in a property form.
special template class to simplify handling of ITX/PEAR
static secureString($a_str, $a_strip_html=true, $a_allow="")
Remove unsecure tags.
static getHtmlPath($relative_path)
get url of path
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
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
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
Interface ilGuiAnswerScoringAdjustable.
Interface ilGuiQuestionScoringAdjustable.
$url
Definition: shib_logout.php:72
$errors