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