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