ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.assMultipleChoiceGUI.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{
26
35 function __construct($id = -1)
36 {
37 parent::__construct();
38 include_once "./Modules/TestQuestionPool/classes/class.assMultipleChoice.php";
39 $this->object = new assMultipleChoice();
40 if ($id >= 0)
41 {
42 $this->object->loadFromDb($id);
43 }
44 }
45
53 public function writePostData($always = false)
54 {
55 $hasErrors = (!$always) ? $this->editQuestion(true) : false;
56 if (!$hasErrors)
57 {
58 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
63 return 0;
64 }
65 return 1;
66 }
67
75 public function editQuestion($checkonly = FALSE)
76 {
77 $save = $this->isSaveCommand();
78 $this->getQuestionTemplate();
79
80 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
81 $form = new ilPropertyFormGUI();
82 $form->setFormAction($this->ctrl->getFormAction($this));
83 $form->setTitle($this->outQuestionType());
84 $isSingleline = ($this->object->lastChange == 0 && !array_key_exists('types', $_POST)) ? (($this->object->getMultilineAnswerSetting()) ? false : true) : $this->object->isSingleline;
85 if ($checkonly) $isSingleline = ($_POST['types'] == 0) ? true : false;
86 if ($isSingleline)
87 {
88 $form->setMultipart(TRUE);
89 }
90 else
91 {
92 $form->setMultipart(FALSE);
93 }
94 $form->setTableWidth("100%");
95 $form->setId("assmultiplechoice");
96
97 // title, author, description, question, working time (assessment mode)
98 $this->addBasicQuestionFormProperties( $form );
100 $this->populateAnswerSpecificFormPart( $form );
101 $this->populateTaxonomyFormSection($form);
102 $this->addQuestionFormCommandButtons($form);
103
104 $errors = false;
105
106 if ($save)
107 {
108 $form->setValuesByPost();
109 $errors = !$form->checkInput();
110 $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
111 if ($errors) $checkonly = false;
112 }
113
114 if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
115 return $errors;
116 }
117
119 {
120 parent::addBasicQuestionFormProperties($form);
121 $form->getItemByPostVar('question')->setInitialRteWidth('100');
122 }
123
127 public function uploadchoice()
128 {
129 $this->writePostData(true);
130 $position = key($_POST['cmd']['uploadchoice']);
131 $this->editQuestion();
132 }
133
137 public function removeimagechoice()
138 {
139 $this->writePostData(true);
140 $position = key($_POST['cmd']['removeimagechoice']);
141 $filename = $_POST['choice']['imagename'][$position];
142 $this->object->removeAnswerImage($position);
143 $this->editQuestion();
144 }
145
149 public function addchoice()
150 {
151 $this->writePostData(true);
152 $position = key($_POST['cmd']['addchoice']);
153 $this->object->addAnswer("", 0, 0, $position+1);
154 $this->editQuestion();
155 }
156
160 public function removechoice()
161 {
162 $this->writePostData(true);
163 $position = key($_POST['cmd']['removechoice']);
164 $this->object->deleteAnswer($position);
165 $this->editQuestion();
166 }
167
184 $active_id,
185 $pass = NULL,
186 $graphicalOutput = FALSE,
187 $result_output = FALSE,
188 $show_question_only = TRUE,
189 $show_feedback = FALSE,
190 $show_correct_solution = FALSE,
191 $show_manual_scoring = FALSE,
192 $show_question_text = TRUE
193 )
194 {
195 // shuffle output
196 $keys = $this->getChoiceKeys();
197
198 // get the solution of the user for the active pass or from the last pass if allowed
199 $user_solution = array();
200 if (($active_id > 0) && (!$show_correct_solution))
201 {
202 $solutions =& $this->object->getSolutionValues($active_id, $pass);
203 foreach ($solutions as $idx => $solution_value)
204 {
205 array_push($user_solution, $solution_value["value1"]);
206 }
207 }
208 else
209 {
210 // take the correct solution instead of the user solution
211 foreach ($this->object->answers as $index => $answer)
212 {
213 $points_checked = $answer->getPointsChecked();
214 $points_unchecked = $answer->getPointsUnchecked();
215 if ($points_checked > $points_unchecked)
216 {
217 if ($points_checked > 0)
218 {
219 array_push($user_solution, $index);
220 }
221 }
222 }
223 }
224
225 // generate the question output
226 include_once "./Services/UICore/classes/class.ilTemplate.php";
227 $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
228 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
229 foreach ($keys as $answer_id)
230 {
231 $answer = $this->object->answers[$answer_id];
232 if (($active_id > 0) && (!$show_correct_solution))
233 {
234 if ($graphicalOutput)
235 {
236 // output of ok/not ok icons for user entered solutions
237 $ok = FALSE;
238 $checked = FALSE;
239 foreach ($user_solution as $mc_solution)
240 {
241 if (strcmp($mc_solution, $answer_id) == 0)
242 {
243 $checked = TRUE;
244 }
245 }
246 if ($checked)
247 {
248 if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
249 {
250 $ok = TRUE;
251 }
252 else
253 {
254 $ok = FALSE;
255 }
256 }
257 else
258 {
259 if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
260 {
261 $ok = FALSE;
262 }
263 else
264 {
265 $ok = TRUE;
266 }
267 }
268 if ($ok)
269 {
270 $template->setCurrentBlock("icon_ok");
271 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
272 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
273 $template->parseCurrentBlock();
274 }
275 else
276 {
277 $template->setCurrentBlock("icon_ok");
278 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
279 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
280 $template->parseCurrentBlock();
281 }
282 }
283 }
284 if (strlen($answer->getImage()))
285 {
286 $template->setCurrentBlock("answer_image");
287 if ($this->object->getThumbSize())
288 {
289 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
290 }
291 else
292 {
293 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
294 }
295 $alt = $answer->getImage();
296 if (strlen($answer->getAnswertext()))
297 {
298 $alt = $answer->getAnswertext();
299 }
300 $alt = preg_replace("/<[^>]*?>/", "", $alt);
301 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
302 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
303 $template->parseCurrentBlock();
304 }
305
306 if ($show_feedback)
307 {
308
309 if ($this->object->getSpecificFeedbackSetting() == 2)
310 {
311 foreach ($user_solution as $mc_solution)
312 {
313 if (strcmp($mc_solution, $answer_id) == 0)
314 {
315 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
316 $this->object->getId(), $answer_id
317 );
318 if (strlen($fb))
319 {
320 $template->setCurrentBlock("feedback");
321 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $fb, true ));
322 $template->parseCurrentBlock();
323 }
324 }
325 }
326 }
327
328 if ($this->object->getSpecificFeedbackSetting() == 1)
329 {
330 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
331 $this->object->getId(), $answer_id
332 );
333 if (strlen($fb))
334 {
335 $template->setCurrentBlock("feedback");
336 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $fb, true ));
337 $template->parseCurrentBlock();
338 }
339 }
340
341 if ($this->object->getSpecificFeedbackSetting() == 3)
342 {
343 $answer = $this->object->getAnswer($answer_id);
344
345 if ($answer->getPoints() > 0)
346 {
347 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
348 $this->object->getId(), $answer_id
349 );
350 if (strlen($fb))
351 {
352 $template->setCurrentBlock("feedback");
353 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $fb, true ));
354 $template->parseCurrentBlock();
355 }
356 }
357
358 }
359 }
360 $template->setCurrentBlock("answer_row");
361 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
362 $checked = FALSE;
363 if ($result_output)
364 {
365 $pointschecked = $this->object->answers[$answer_id]->getPointsChecked();
366 $pointsunchecked = $this->object->answers[$answer_id]->getPointsUnchecked();
367 $resulttextchecked = ($pointschecked == 1) || ($pointschecked == -1) ? "%s " . $this->lng->txt("point") : "%s " . $this->lng->txt("points");
368 $resulttextunchecked = ($pointsunchecked == 1) || ($pointsunchecked == -1) ? "%s " . $this->lng->txt("point") : "%s " . $this->lng->txt("points");
369 $template->setVariable("RESULT_OUTPUT", sprintf("(" . $this->lng->txt("checkbox_checked") . " = $resulttextchecked, " . $this->lng->txt("checkbox_unchecked") . " = $resulttextunchecked)", $pointschecked, $pointsunchecked));
370 }
371 foreach ($user_solution as $mc_solution)
372 {
373 if (strcmp($mc_solution, $answer_id) == 0)
374 {
375 $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_checked.png")));
376 $template->setVariable("SOLUTION_ALT", $this->lng->txt("checked"));
377 $checked = TRUE;
378 }
379 }
380 if (!$checked)
381 {
382 $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.png")));
383 $template->setVariable("SOLUTION_ALT", $this->lng->txt("unchecked"));
384 }
385 $template->parseCurrentBlock();
386 }
387 $questiontext = $this->object->getQuestion();
388 if ($show_question_text==true)
389 {
390 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
391 }
392 $questionoutput = $template->get();
393 $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
394
395 if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $feedback , true ));
396 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
397
398 $solutionoutput = $solutiontemplate->get();
399 if (!$show_question_only)
400 {
401 // get page object output
402 $solutionoutput = $this->getILIASPage($solutionoutput);
403 }
404 return $solutionoutput;
405 }
406
407 function getPreview($show_question_only = FALSE, $showInlineFeedback = false)
408 {
409 $user_solution = is_object($this->getPreviewSession()) ? (array)$this->getPreviewSession()->getParticipantsSolution() : array();
410 // shuffle output
411 $keys = $this->getChoiceKeys();
412
413 // generate the question output
414 include_once "./Services/UICore/classes/class.ilTemplate.php";
415 $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
416 foreach ($keys as $answer_id)
417 {
418 $answer = $this->object->answers[$answer_id];
419 if (strlen($answer->getImage()))
420 {
421 if ($this->object->getThumbSize())
422 {
423 $template->setCurrentBlock("preview");
424 $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
425 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
426 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
427 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
428 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
429 $alt = $answer->getImage();
430 if (strlen($answer->getAnswertext()))
431 {
432 $alt = $answer->getAnswertext();
433 }
434 $alt = preg_replace("/<[^>]*?>/", "", $alt);
435 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
436 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
437 $template->parseCurrentBlock();
438 }
439 else
440 {
441 $template->setCurrentBlock("answer_image");
442 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
443 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
444 $alt = $answer->getImage();
445 if (strlen($answer->getAnswertext()))
446 {
447 $alt = $answer->getAnswertext();
448 }
449 $alt = preg_replace("/<[^>]*?>/", "", $alt);
450 $template->setVariable("ATTR", $attr);
451 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
452 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
453 $template->parseCurrentBlock();
454 }
455 }
456
457 if( $showInlineFeedback )
458 {
459 $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
460 }
461
462 $template->setCurrentBlock("answer_row");
463 $template->setVariable("ANSWER_ID", $answer_id);
464 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
465 foreach ($user_solution as $mc_solution)
466 {
467 if (strcmp($mc_solution, $answer_id) == 0)
468 {
469 $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
470 }
471 }
472 $template->parseCurrentBlock();
473 }
474 $questiontext = $this->object->getQuestion();
475 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
476 $questionoutput = $template->get();
477 if (!$show_question_only)
478 {
479 // get page object output
480 $questionoutput = $this->getILIASPage($questionoutput);
481 }
482 return $questionoutput;
483 }
484
495 $active_id,
496 $pass = NULL,
497 $is_postponed = FALSE,
498 $use_post_solutions = FALSE,
499 $show_feedback = FALSE
500 )
501 {
502 // shuffle output
503 $keys = $this->getChoiceKeys();
504
505 // get the solution of the user for the active pass or from the last pass if allowed
506 $user_solution = array();
507 if ($active_id)
508 {
509 $solutions = NULL;
510 include_once "./Modules/Test/classes/class.ilObjTest.php";
511 if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
512 {
513 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
514 }
515 $solutions =& $this->object->getSolutionValues($active_id, $pass);
516 foreach ($solutions as $idx => $solution_value)
517 {
518 array_push($user_solution, $solution_value["value1"]);
519 }
520 }
521 // generate the question output
522 include_once "./Services/UICore/classes/class.ilTemplate.php";
523 $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
524 foreach ($keys as $answer_id)
525 {
526 $answer = $this->object->answers[$answer_id];
527 if (strlen($answer->getImage()))
528 {
529 if ($this->object->getThumbSize())
530 {
531 $template->setCurrentBlock("preview");
532 $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
533 $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
534 $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
535 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
536 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
537 $alt = $answer->getImage();
538 if (strlen($answer->getAnswertext()))
539 {
540 $alt = $answer->getAnswertext();
541 }
542 $alt = preg_replace("/<[^>]*?>/", "", $alt);
543 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
544 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
545 $template->parseCurrentBlock();
546 }
547 else
548 {
549 $template->setCurrentBlock("answer_image");
550 $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
551 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
552 $alt = $answer->getImage();
553 if (strlen($answer->getAnswertext()))
554 {
555 $alt = $answer->getAnswertext();
556 }
557 $alt = preg_replace("/<[^>]*?>/", "", $alt);
558 $template->setVariable("ATTR", $attr);
559 $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
560 $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
561 $template->parseCurrentBlock();
562 }
563 }
564
565 if( $show_feedback )
566 {
567 $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
568 }
569
570 $template->setCurrentBlock("answer_row");
571 $template->setVariable("ANSWER_ID", $answer_id);
572 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
573 foreach ($user_solution as $mc_solution)
574 {
575 if (strcmp($mc_solution, $answer_id) == 0)
576 {
577 $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
578 }
579 }
580 $template->parseCurrentBlock();
581 }
582 $questiontext = $this->object->getQuestion();
583 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
584 $questionoutput = $template->get();
585 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
586 return $pageoutput;
587 }
588
594 public function setQuestionTabs()
595 {
596 global $rbacsystem, $ilTabs;
597
598 $ilTabs->clearTargets();
599
600 $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
601 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
602 $q_type = $this->object->getQuestionType();
603
604 if (strlen($q_type))
605 {
606 $classname = $q_type . "GUI";
607 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
608 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
609 }
610
611 if ($_GET["q_id"])
612 {
613 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
614 {
615 // edit page
616 $ilTabs->addTarget("edit_page",
617 $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
618 array("edit", "insert", "exec_pg"),
619 "", "", $force_active);
620 }
621
622 $this->addTab_QuestionPreview($ilTabs);
623 }
624 $force_active = false;
625 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
626 {
627 $url = "";
628 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
629 $force_active = false;
630 // edit question properties
631 $ilTabs->addTarget("edit_question",
632 $url,
633 array("editQuestion", "save", "saveEdit", "addchoice", "removechoice", "removeimagechoice", "uploadchoice", "originalSyncForm"),
634 $classname, "", $force_active);
635 }
636
637 // add tab for question feedback within common class assQuestionGUI
638 $this->addTab_QuestionFeedback($ilTabs);
639
640 // add tab for question hint within common class assQuestionGUI
641 $this->addTab_QuestionHints($ilTabs);
642
643 // add tab for question's suggested solution within common class assQuestionGUI
644 $this->addTab_SuggestedSolution($ilTabs, $classname);
645
646 // Assessment of questions sub menu entry
647 if ($_GET["q_id"])
648 {
649 $ilTabs->addTarget("statistics",
650 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
651 array("assessment"),
652 $classname, "");
653 }
654
655 $this->addBackTab($ilTabs);
656 }
657
663 function getChoiceKeys()
664 {
665 if (strcmp($_GET["activecommand"], "directfeedback") == 0)
666 {
667 if (is_array($_SESSION["choicekeys"])) $this->choiceKeys = $_SESSION["choicekeys"];
668 }
669 if (!is_array($this->choiceKeys))
670 {
671 $this->choiceKeys = array_keys($this->object->answers);
672 if ($this->object->getShuffle())
673 {
674 $this->choiceKeys = $this->object->pcArrayShuffle($this->choiceKeys);
675 }
676 }
677 $_SESSION["choicekeys"] = $this->choiceKeys;
678 return $this->choiceKeys;
679 }
680
681 function getSpecificFeedbackOutput($active_id, $pass)
682 {
683 // No return value, this question type supports inline specific feedback.
684 $output = "";
685 return $this->object->prepareTextareaOutput($output, TRUE);
686 }
687
689 {
690 $this->object->setShuffle( $_POST["shuffle"] );
691
692 $this->object->setSpecificFeedbackSetting( $_POST['feedback_setting'] );
693
694 $this->object->setMultilineAnswerSetting( $_POST["types"] );
695 if (is_array( $_POST['choice']['imagename'] ) && $_POST["types"] == 1)
696 {
697 $this->object->isSingleline = true;
698 ilUtil::sendInfo( $this->lng->txt( 'info_answer_type_change' ), true );
699 }
700 else
701 {
702 $this->object->isSingleline = ($_POST["types"] == 0) ? true : false;
703 }
704 $this->object->setThumbSize( (strlen( $_POST["thumb_size"] )) ? $_POST["thumb_size"] : "" );
705 }
706
708 {
709 // Delete all existing answers and create new answers from the form data
710 $this->object->flushAnswers();
711 if ($this->object->isSingleline)
712 {
713 foreach ($_POST['choice']['answer'] as $index => $answertext)
714 {
715 $answertext = ilUtil::secureString($answertext);
716
717 $picturefile = $_POST['choice']['imagename'][$index];
718 $file_org_name = $_FILES['choice']['name']['image'][$index];
719 $file_temp_name = $_FILES['choice']['tmp_name']['image'][$index];
720
721 if (strlen( $file_temp_name ))
722 {
723 // check suffix
724 $suffix = strtolower( array_pop( explode( ".", $file_org_name ) ) );
725 if (in_array( $suffix, array( "jpg", "jpeg", "png", "gif" ) ))
726 {
727 // upload image
728 $filename = $this->object->createNewImageFileName( $file_org_name );
729 if ($this->object->setImageFile( $filename, $file_temp_name ) == 0)
730 {
731 $picturefile = $filename;
732 }
733 }
734 }
735 $this->object->addAnswer( $answertext,
736 $_POST['choice']['points'][$index],
737 $_POST['choice']['points_unchecked'][$index],
738 $index,
739 $picturefile
740 );
741 }
742 }
743 else
744 {
745 foreach ($_POST['choice']['answer'] as $index => $answer)
746 {
747 $answertext = $answer;
748 $this->object->addAnswer( $answertext,
749 $_POST['choice']['points'][$index],
750 $_POST['choice']['points_unchecked'][$index],
751 $index
752 );
753 }
754 }
755 }
756
758 {
759 // shuffle
760 $shuffle = new ilCheckboxInputGUI($this->lng->txt( "shuffle_answers" ), "shuffle");
761 $shuffle->setValue( 1 );
762 $shuffle->setChecked( $this->object->getShuffle() );
763 $shuffle->setRequired( FALSE );
764 $form->addItem( $shuffle );
765
766 if ($this->object->getId())
767 {
768 $hidden = new ilHiddenInputGUI("", "ID");
769 $hidden->setValue( $this->object->getId() );
770 $form->addItem( $hidden );
771 }
772
773 if (!$this->object->getSelfAssessmentEditingMode())
774 {
775 $isSingleline = ($this->object->lastChange == 0 && !array_key_exists( 'types',
776 $_POST
777 )) ? (($this->object->getMultilineAnswerSetting()) ? false : true) : $this->object->isSingleline;
778 // Answer types
779 $types = new ilSelectInputGUI($this->lng->txt( "answer_types" ), "types");
780 $types->setRequired( false );
781 $types->setValue( ($isSingleline) ? 0 : 1 );
782 $types->setOptions( array(
783 0 => $this->lng->txt( 'answers_singleline' ),
784 1 => $this->lng->txt( 'answers_multiline' ),
785 )
786 );
787 $form->addItem( $types );
788 }
789
790 if ($isSingleline)
791 {
792 // thumb size
793 $thumb_size = new ilNumberInputGUI($this->lng->txt( "thumb_size" ), "thumb_size");
794 $thumb_size->setSuffix($this->lng->txt("thumb_size_unit_pixel"));
795 $thumb_size->setMinValue( 20 );
796 $thumb_size->setDecimals( 0 );
797 $thumb_size->setSize( 6 );
798 $thumb_size->setInfo( $this->lng->txt( 'thumb_size_info' ) );
799 $thumb_size->setValue( $this->object->getThumbSize() );
800 $thumb_size->setRequired( false );
801 $form->addItem( $thumb_size );
802 return $isSingleline;
803 }
804 return $isSingleline;
805 }
806
808 {
809 // Choices
810 include_once "./Modules/TestQuestionPool/classes/class.ilMultipleChoiceWizardInputGUI.php";
811 $choices = new ilMultipleChoiceWizardInputGUI($this->lng->txt( "answers" ), "choice");
812 $choices->setRequired( true );
813 $choices->setQuestionObject( $this->object );
814 $isSingleline = ($this->object->lastChange == 0 && !array_key_exists( 'types',
815 $_POST
816 )) ? (($this->object->getMultilineAnswerSetting()) ? false : true) : $this->object->isSingleline;
817 $choices->setSingleline( $isSingleline );
818 $choices->setAllowMove( false );
819 if ($this->object->getSelfAssessmentEditingMode())
820 {
821 $choices->setSize( 40 );
822 $choices->setMaxLength( 800 );
823 }
824 if ($this->object->getAnswerCount() == 0)
825 $this->object->addAnswer( "", 0, 0, 0 );
826 $choices->setValues( $this->object->getAnswers() );
827 $form->addItem( $choices );
828 }
829
840 {
841 return array();
842 }
843
854 {
855 return array();
856 }
857
866 public function getAggregatedAnswersView($relevant_answers)
867 {
868 return $this->renderAggregateView(
869 $this->aggregateAnswers( $relevant_answers, $this->object->getAnswers() ) )->get();
870 }
871
872 public function aggregateAnswers($relevant_answers_chosen, $answers_defined_on_question)
873 {
874 $aggregate = array();
875 foreach ($answers_defined_on_question as $answer)
876 {
877 $aggregated_info_for_answer = array();
878 $aggregated_info_for_answer['answertext'] = $answer->getAnswerText();
879 $aggregated_info_for_answer['count_checked'] = 0;
880
881 foreach ($relevant_answers_chosen as $relevant_answer)
882 {
883 if ($relevant_answer['value1'] == $answer->getOrder())
884 {
885 $aggregated_info_for_answer['count_checked']++;
886 }
887 }
888 $aggregated_info_for_answer['count_unchecked'] =
889 ceil(count($relevant_answers_chosen) / count($answers_defined_on_question))
890 - $aggregated_info_for_answer['count_checked'];
891
892 $aggregate[] = $aggregated_info_for_answer;
893 }
894 return $aggregate;
895 }
896
902 public function renderAggregateView($aggregate)
903 {
904 $tpl = new ilTemplate('tpl.il_as_aggregated_answers_table.html', true, true, "Modules/TestQuestionPool");
905
906 foreach ($aggregate as $line_data)
907 {
908 $tpl->setCurrentBlock( 'aggregaterow' );
909 $tpl->setVariable( 'OPTION', $line_data['answertext'] );
910 $tpl->setVariable( 'COUNT', $line_data['count_checked'] );
911 $tpl->parseCurrentBlock();
912 }
913 return $tpl;
914 }
915
922 private function populateSpecificFeedbackInline($user_solution, $answer_id, $template)
923 {
924 if($this->object->getSpecificFeedbackSetting() == 2)
925 {
926 foreach($user_solution as $mc_solution)
927 {
928 if(strcmp($mc_solution, $answer_id) == 0)
929 {
930 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
931 if(strlen($fb))
932 {
933 $template->setCurrentBlock("feedback");
934 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
935 $template->parseCurrentBlock();
936 }
937 }
938 }
939 }
940
941 if($this->object->getSpecificFeedbackSetting() == 1)
942 {
943 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
944 if(strlen($fb))
945 {
946 $template->setCurrentBlock("feedback");
947 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
948 $template->parseCurrentBlock();
949 }
950 }
951
952 if($this->object->getSpecificFeedbackSetting() == 3)
953 {
954 $answer = $this->object->getAnswer($answer_id);
955
956 if($answer->getPoints() > 0)
957 {
958 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
959 if(strlen($fb))
960 {
961 $template->setCurrentBlock("feedback");
962 $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
963 $template->parseCurrentBlock();
964 }
965 }
966 }
967 }
968}
$filename
Definition: buildRTE.php:89
$_GET["client_id"]
Multiple choice question GUI representation.
getAggregatedAnswersView($relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
getTestOutput( $active_id, $pass=NULL, $is_postponed=FALSE, $use_post_solutions=FALSE, $show_feedback=FALSE)
getAfterParticipationSuppressionAnswerPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getChoiceKeys()
Create the key index numbers for the array of choices.
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
aggregateAnswers($relevant_answers_chosen, $answers_defined_on_question)
populateSpecificFeedbackInline($user_solution, $answer_id, $template)
editQuestion($checkonly=FALSE)
Creates an output of the edit form for the question.
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
Extracts the answer specific values from $_POST and applies them to the data object.
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form)
__construct($id=-1)
assMultipleChoiceGUI constructor
getSpecificFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
getPreview($show_question_only=FALSE, $showInlineFeedback=false)
populateAnswerSpecificFormPart(\ilPropertyFormGUI $form)
addBasicQuestionFormProperties(ilPropertyFormGUI $form)
setQuestionTabs()
Sets the ILIAS tabs for this question type.
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
writePostData($always=false)
Evaluates a posted edit form and writes the form data in the question object.
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.
Class for multiple choice tests.
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)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
addBackTab(ilTabsGUI $ilTabs)
addTab_QuestionFeedback(ilTabsGUI $tabs)
adds the feedback tab to ilTabsGUI
addTab_QuestionPreview(ilTabsGUI $tabsGUI)
getAnswerFeedbackOutput($active_id, $pass)
Returns the answer generic feedback depending on the results of the question.
This class represents a checkbox property in a property form.
setRequired($a_required)
Set Required.
This class represents a hidden form property in a property form.
This class represents a multiple choice wizard 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 selection list 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(!file_exists(getcwd().'/ilias.ini.php')) if(isset( $_GET["client_id"]))
registration confirmation script for ilias
Definition: confirmReg.php:20
$_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.
$errors