ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
4 require_once './Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
5 require_once './Modules/TestQuestionPool/interfaces/interface.ilGuiQuestionScoringAdjustable.php';
6 require_once './Modules/TestQuestionPool/interfaces/interface.ilGuiAnswerScoringAdjustable.php';
7 require_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';
62  $this->saveTaxonomyAssignments();
63  return 0;
64  }
65  return 1;
66  }
67 
75  protected function getEditAnswersSingleLine($checkonly = false)
76  {
77  if ($checkonly)
78  {
79  // form posting is checked
80  return ($_POST['types'] == 0) ? true : false;
81  }
82 
83  $lastChange = $this->object->getLastChange();
84  if (empty($lastChange) && !isset($_POST['types']))
85  {
86  // a new question is edited
87  return $this->object->getMultilineAnswerSetting() ? false : true;
88  }
89  else
90  {
91  // a saved question is edited
92  return $this->object->isSingleline;
93  }
94  }
95 
103  public function editQuestion($checkonly = FALSE)
104  {
105  $save = $this->isSaveCommand();
106  $this->getQuestionTemplate();
107 
108  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
109  $form = new ilPropertyFormGUI();
110  $form->setFormAction($this->ctrl->getFormAction($this));
111  $form->setTitle($this->outQuestionType());
112  $isSingleline = $this->getEditAnswersSingleLine($checkonly);
113  if ($isSingleline)
114  {
115  $form->setMultipart(TRUE);
116  }
117  else
118  {
119  $form->setMultipart(FALSE);
120  }
121  $form->setTableWidth("100%");
122  $form->setId("assmultiplechoice");
123 
124  // title, author, description, question, working time (assessment mode)
125  $this->addBasicQuestionFormProperties( $form );
126  $this->populateQuestionSpecificFormPart( $form );
127  $this->populateAnswerSpecificFormPart( $form );
128  $this->populateTaxonomyFormSection($form);
129  $this->addQuestionFormCommandButtons($form);
130 
131  $errors = false;
132 
133  if ($save)
134  {
135  $form->setValuesByPost();
136  $errors = !$form->checkInput();
137  $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
138  if ($errors) $checkonly = false;
139  }
140 
141  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
142  return $errors;
143  }
144 
146  {
147  parent::addBasicQuestionFormProperties($form);
148  $form->getItemByPostVar('question')->setInitialRteWidth('100');
149  }
150 
154  public function uploadchoice()
155  {
156  $this->writePostData(true);
157  $position = key($_POST['cmd']['uploadchoice']);
158  $this->editQuestion();
159  }
160 
164  public function removeimagechoice()
165  {
166  $this->writePostData(true);
167  $position = key($_POST['cmd']['removeimagechoice']);
168  $filename = $_POST['choice']['imagename'][$position];
169  $this->object->removeAnswerImage($position);
170  $this->editQuestion();
171  }
172 
176  public function addchoice()
177  {
178  $this->writePostData(true);
179  $position = key($_POST['cmd']['addchoice']);
180  $this->object->addAnswer("", 0, 0, $position+1);
181  $this->editQuestion();
182  }
183 
187  public function removechoice()
188  {
189  $this->writePostData(true);
190  $position = key($_POST['cmd']['removechoice']);
191  $this->object->deleteAnswer($position);
192  $this->editQuestion();
193  }
194 
211  $active_id,
212  $pass = NULL,
213  $graphicalOutput = FALSE,
214  $result_output = FALSE,
215  $show_question_only = TRUE,
216  $show_feedback = FALSE,
217  $show_correct_solution = FALSE,
218  $show_manual_scoring = FALSE,
219  $show_question_text = TRUE
220  )
221  {
222  // shuffle output
223  $keys = $this->getChoiceKeys();
224 
225  // get the solution of the user for the active pass or from the last pass if allowed
226  $user_solution = array();
227  if (($active_id > 0) && (!$show_correct_solution))
228  {
229  $solutions =& $this->object->getSolutionValues($active_id, $pass);
230  foreach ($solutions as $idx => $solution_value)
231  {
232  array_push($user_solution, $solution_value["value1"]);
233  }
234  }
235  else
236  {
237  // take the correct solution instead of the user solution
238  foreach ($this->object->answers as $index => $answer)
239  {
240  $points_checked = $answer->getPointsChecked();
241  $points_unchecked = $answer->getPointsUnchecked();
242  if ($points_checked > $points_unchecked)
243  {
244  if ($points_checked > 0)
245  {
246  array_push($user_solution, $index);
247  }
248  }
249  }
250  }
251 
252  // generate the question output
253  include_once "./Services/UICore/classes/class.ilTemplate.php";
254  $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
255  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
256  foreach ($keys as $answer_id)
257  {
258  $answer = $this->object->answers[$answer_id];
259  if (($active_id > 0) && (!$show_correct_solution))
260  {
261  if ($graphicalOutput)
262  {
263  // output of ok/not ok icons for user entered solutions
264  $ok = FALSE;
265  $checked = FALSE;
266  foreach ($user_solution as $mc_solution)
267  {
268  if (strcmp($mc_solution, $answer_id) == 0)
269  {
270  $checked = TRUE;
271  }
272  }
273  if ($checked)
274  {
275  if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
276  {
277  $ok = TRUE;
278  }
279  else
280  {
281  $ok = FALSE;
282  }
283  }
284  else
285  {
286  if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
287  {
288  $ok = FALSE;
289  }
290  else
291  {
292  $ok = TRUE;
293  }
294  }
295  if ($ok)
296  {
297  $template->setCurrentBlock("icon_ok");
298  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
299  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
300  $template->parseCurrentBlock();
301  }
302  else
303  {
304  $template->setCurrentBlock("icon_ok");
305  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
306  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
307  $template->parseCurrentBlock();
308  }
309  }
310  }
311  if (strlen($answer->getImage()))
312  {
313  $template->setCurrentBlock("answer_image");
314  if ($this->object->getThumbSize())
315  {
316  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
317  }
318  else
319  {
320  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
321  }
322  $alt = $answer->getImage();
323  if (strlen($answer->getAnswertext()))
324  {
325  $alt = $answer->getAnswertext();
326  }
327  $alt = preg_replace("/<[^>]*?>/", "", $alt);
328  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
329  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
330  $template->parseCurrentBlock();
331  }
332 
333  if ($show_feedback)
334  {
335 
336  if ($this->object->getSpecificFeedbackSetting() == 2)
337  {
338  foreach ($user_solution as $mc_solution)
339  {
340  if (strcmp($mc_solution, $answer_id) == 0)
341  {
342  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
343  $this->object->getId(), $answer_id
344  );
345  if (strlen($fb))
346  {
347  $template->setCurrentBlock("feedback");
348  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $fb, true ));
349  $template->parseCurrentBlock();
350  }
351  }
352  }
353  }
354 
355  if ($this->object->getSpecificFeedbackSetting() == 1)
356  {
357  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
358  $this->object->getId(), $answer_id
359  );
360  if (strlen($fb))
361  {
362  $template->setCurrentBlock("feedback");
363  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $fb, true ));
364  $template->parseCurrentBlock();
365  }
366  }
367 
368  if ($this->object->getSpecificFeedbackSetting() == 3)
369  {
370  $answer = $this->object->getAnswer($answer_id);
371 
372  if ($answer->getPoints() > 0)
373  {
374  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
375  $this->object->getId(), $answer_id
376  );
377  if (strlen($fb))
378  {
379  $template->setCurrentBlock("feedback");
380  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $fb, true ));
381  $template->parseCurrentBlock();
382  }
383  }
384 
385  }
386  }
387  $template->setCurrentBlock("answer_row");
388  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
389  $checked = FALSE;
390  if ($result_output)
391  {
392  $pointschecked = $this->object->answers[$answer_id]->getPointsChecked();
393  $pointsunchecked = $this->object->answers[$answer_id]->getPointsUnchecked();
394  $resulttextchecked = ($pointschecked == 1) || ($pointschecked == -1) ? "%s " . $this->lng->txt("point") : "%s " . $this->lng->txt("points");
395  $resulttextunchecked = ($pointsunchecked == 1) || ($pointsunchecked == -1) ? "%s " . $this->lng->txt("point") : "%s " . $this->lng->txt("points");
396  $template->setVariable("RESULT_OUTPUT", sprintf("(" . $this->lng->txt("checkbox_checked") . " = $resulttextchecked, " . $this->lng->txt("checkbox_unchecked") . " = $resulttextunchecked)", $pointschecked, $pointsunchecked));
397  }
398  foreach ($user_solution as $mc_solution)
399  {
400  if (strcmp($mc_solution, $answer_id) == 0)
401  {
402  if( $this->isPdfOutputMode() || $this->isContentEditingOutputMode() )
403  {
404  $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_checked.png")));
405  $template->setVariable("SOLUTION_ALT", $this->lng->txt("checked"));
406  }
407  else
408  {
409  $template->setVariable('QID', $this->object->getId());
410  $template->setVariable('SUFFIX', $show_correct_solution ? 'bestsolution' : 'usersolution');
411  $template->setVariable('SOLUTION_VALUE', $answer_id);
412  $template->setVariable('SOLUTION_CHECKED', 'checked');
413  }
414  $checked = TRUE;
415  }
416  }
417  if (!$checked)
418  {
419  if( $this->isPdfOutputMode() || $this->isContentEditingOutputMode() )
420  {
421  $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.png")));
422  $template->setVariable("SOLUTION_ALT", $this->lng->txt("unchecked"));
423  }
424  else
425  {
426  $template->setVariable('QID', $this->object->getId());
427  $template->setVariable('SUFFIX', $show_correct_solution ? 'bestsolution' : 'usersolution');
428  $template->setVariable('SOLUTION_VALUE', $answer_id);
429  }
430  }
431  $template->parseCurrentBlock();
432  }
433  $questiontext = $this->object->getQuestion();
434  if ($show_question_text==true)
435  {
436  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
437  }
438  $questionoutput = $template->get();
439  $feedback = ($show_feedback && !$this->isTestPresentationContext()) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
440 
441  if (strlen($feedback))
442  {
443  $cssClass = ( $this->hasCorrectSolution($active_id, $pass) ?
445  );
446 
447  $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
448  $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $feedback , true ));
449  }
450  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
451 
452  $solutionoutput = $solutiontemplate->get();
453  if (!$show_question_only)
454  {
455  // get page object output
456  $solutionoutput = $this->getILIASPage($solutionoutput);
457  }
458  return $solutionoutput;
459  }
460 
461  function getPreview($show_question_only = FALSE, $showInlineFeedback = false)
462  {
463  $user_solution = is_object($this->getPreviewSession()) ? (array)$this->getPreviewSession()->getParticipantsSolution() : array();
464  // shuffle output
465  $keys = $this->getChoiceKeys();
466 
467  // generate the question output
468  include_once "./Services/UICore/classes/class.ilTemplate.php";
469  $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
470  foreach ($keys as $answer_id)
471  {
472  $answer = $this->object->answers[$answer_id];
473  if (strlen($answer->getImage()))
474  {
475  if ($this->object->getThumbSize())
476  {
477  $template->setCurrentBlock("preview");
478  $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
479  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
480  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
481  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
482  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
483  $alt = $answer->getImage();
484  if (strlen($answer->getAnswertext()))
485  {
486  $alt = $answer->getAnswertext();
487  }
488  $alt = preg_replace("/<[^>]*?>/", "", $alt);
489  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
490  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
491  $template->parseCurrentBlock();
492  }
493  else
494  {
495  $template->setCurrentBlock("answer_image");
496  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
497  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
498  $alt = $answer->getImage();
499  if (strlen($answer->getAnswertext()))
500  {
501  $alt = $answer->getAnswertext();
502  }
503  $alt = preg_replace("/<[^>]*?>/", "", $alt);
504  $template->setVariable("ATTR", $attr);
505  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
506  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
507  $template->parseCurrentBlock();
508  }
509  }
510 
511  if( $showInlineFeedback )
512  {
513  $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
514  }
515 
516  $template->setCurrentBlock("answer_row");
517  $template->setVariable("ANSWER_ID", $answer_id);
518  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
519  foreach ($user_solution as $mc_solution)
520  {
521  if (strcmp($mc_solution, $answer_id) == 0)
522  {
523  $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
524  }
525  }
526  $template->parseCurrentBlock();
527  }
528  $questiontext = $this->object->getQuestion();
529  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
530  $questionoutput = $template->get();
531  if (!$show_question_only)
532  {
533  // get page object output
534  $questionoutput = $this->getILIASPage($questionoutput);
535  }
536  return $questionoutput;
537  }
538 
548  function getTestOutput(
549  $active_id,
550  // hey: prevPassSolutions - will be always available from now on
551  $pass,
552  // hey.
553  $is_postponed = FALSE,
554  $use_post_solutions = FALSE,
555  $show_feedback = FALSE
556  )
557  {
558  // shuffle output
559  $keys = $this->getChoiceKeys();
560 
561  // get the solution of the user for the active pass or from the last pass if allowed
562  $user_solution = array();
563  if ($active_id)
564  {
565  // hey: prevPassSolutions - obsolete due to central check
566  #$solutions = NULL;
567  #include_once "./Modules/Test/classes/class.ilObjTest.php";
568  #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
569  #{
570  # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
571  #}
572  $solutions = $this->getTestOutputSolutions($active_id, $pass);
573  // hey.
574  foreach ($solutions as $idx => $solution_value)
575  {
576  array_push($user_solution, $solution_value["value1"]);
577  }
578  }
579  // generate the question output
580  include_once "./Services/UICore/classes/class.ilTemplate.php";
581  $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
582  foreach ($keys as $answer_id)
583  {
584  $answer = $this->object->answers[$answer_id];
585  if (strlen($answer->getImage()))
586  {
587  if ($this->object->getThumbSize())
588  {
589  $template->setCurrentBlock("preview");
590  $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
591  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
592  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
593  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
594  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
595  $alt = $answer->getImage();
596  if (strlen($answer->getAnswertext()))
597  {
598  $alt = $answer->getAnswertext();
599  }
600  $alt = preg_replace("/<[^>]*?>/", "", $alt);
601  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
602  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
603  $template->parseCurrentBlock();
604  }
605  else
606  {
607  $template->setCurrentBlock("answer_image");
608  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
609  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
610  $alt = $answer->getImage();
611  if (strlen($answer->getAnswertext()))
612  {
613  $alt = $answer->getAnswertext();
614  }
615  $alt = preg_replace("/<[^>]*?>/", "", $alt);
616  $template->setVariable("ATTR", $attr);
617  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
618  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
619  $template->parseCurrentBlock();
620  }
621  }
622 
623  if( $show_feedback )
624  {
625  $this->populateSpecificFeedbackInline($user_solution, $answer_id, $template);
626  }
627 
628  $template->setCurrentBlock("answer_row");
629  $template->setVariable("ANSWER_ID", $answer_id);
630  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
631  foreach ($user_solution as $mc_solution)
632  {
633  if (strcmp($mc_solution, $answer_id) == 0)
634  {
635  $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
636  }
637  }
638  $template->parseCurrentBlock();
639  }
640  $questiontext = $this->object->getQuestion();
641  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
642  $questionoutput = $template->get();
643  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
644  return $pageoutput;
645  }
646 
652  public function setQuestionTabs()
653  {
654  global $rbacsystem, $ilTabs;
655 
656  $ilTabs->clearTargets();
657 
658  $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
659  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
660  $q_type = $this->object->getQuestionType();
661 
662  if (strlen($q_type))
663  {
664  $classname = $q_type . "GUI";
665  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
666  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
667  }
668 
669  if ($_GET["q_id"])
670  {
671  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
672  {
673  // edit page
674  $ilTabs->addTarget("edit_page",
675  $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
676  array("edit", "insert", "exec_pg"),
677  "", "", $force_active);
678  }
679 
680  $this->addTab_QuestionPreview($ilTabs);
681  }
682  $force_active = false;
683  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
684  {
685  $url = "";
686  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
687  $force_active = false;
688  // edit question properties
689  $ilTabs->addTarget("edit_question",
690  $url,
691  array("editQuestion", "save", "saveEdit", "addchoice", "removechoice", "removeimagechoice", "uploadchoice", "originalSyncForm"),
692  $classname, "", $force_active);
693  }
694 
695  // add tab for question feedback within common class assQuestionGUI
696  $this->addTab_QuestionFeedback($ilTabs);
697 
698  // add tab for question hint within common class assQuestionGUI
699  $this->addTab_QuestionHints($ilTabs);
700 
701  // add tab for question's suggested solution within common class assQuestionGUI
702  $this->addTab_SuggestedSolution($ilTabs, $classname);
703 
704  // Assessment of questions sub menu entry
705  if ($_GET["q_id"])
706  {
707  $ilTabs->addTarget("statistics",
708  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
709  array("assessment"),
710  $classname, "");
711  }
712 
713  $this->addBackTab($ilTabs);
714  }
715 
721  function getChoiceKeys()
722  {
723  $choiceKeys = array_keys($this->object->answers);
724 
725  if( $this->object->getShuffle() )
726  {
727  $choiceKeys = $this->object->getShuffler()->shuffle($choiceKeys);
728  }
729 
730  return $choiceKeys;
731  }
732 
733  function getSpecificFeedbackOutput($active_id, $pass)
734  {
735  // No return value, this question type supports inline specific feedback.
736  $output = "";
737  return $this->object->prepareTextareaOutput($output, TRUE);
738  }
739 
741  {
742  $this->object->setShuffle( $_POST["shuffle"] );
743 
744  $this->object->setSpecificFeedbackSetting( $_POST['feedback_setting'] );
745 
746  $this->object->setMultilineAnswerSetting( $_POST["types"] );
747  if (is_array( $_POST['choice']['imagename'] ) && $_POST["types"] == 1)
748  {
749  $this->object->isSingleline = true;
750  ilUtil::sendInfo( $this->lng->txt( 'info_answer_type_change' ), true );
751  }
752  else
753  {
754  $this->object->isSingleline = ($_POST["types"] == 0) ? true : false;
755  }
756  $this->object->setThumbSize( (strlen( $_POST["thumb_size"] )) ? $_POST["thumb_size"] : "" );
757  }
758 
760  {
761  // Delete all existing answers and create new answers from the form data
762  $this->object->flushAnswers();
763  if ($this->object->isSingleline)
764  {
765  foreach ($_POST['choice']['answer'] as $index => $answertext)
766  {
767  $answertext = ilUtil::secureString($answertext);
768 
769  $picturefile = $_POST['choice']['imagename'][$index];
770  $file_org_name = $_FILES['choice']['name']['image'][$index];
771  $file_temp_name = $_FILES['choice']['tmp_name']['image'][$index];
772 
773  if (strlen( $file_temp_name ))
774  {
775  // check suffix
776  $suffix = strtolower( array_pop( explode( ".", $file_org_name ) ) );
777  if (in_array( $suffix, array( "jpg", "jpeg", "png", "gif" ) ))
778  {
779  // upload image
780  $filename = $this->object->createNewImageFileName( $file_org_name );
781  if ($this->object->setImageFile( $filename, $file_temp_name ) == 0)
782  {
783  $picturefile = $filename;
784  }
785  }
786  }
787  $this->object->addAnswer( $answertext,
788  $_POST['choice']['points'][$index],
789  $_POST['choice']['points_unchecked'][$index],
790  $index,
791  $picturefile
792  );
793  }
794  }
795  else
796  {
797  foreach ($_POST['choice']['answer'] as $index => $answer)
798  {
799  $answertext = $answer;
800  $this->object->addAnswer( $answertext,
801  $_POST['choice']['points'][$index],
802  $_POST['choice']['points_unchecked'][$index],
803  $index
804  );
805  }
806  }
807  }
808 
810  {
811  // shuffle
812  $shuffle = new ilCheckboxInputGUI($this->lng->txt( "shuffle_answers" ), "shuffle");
813  $shuffle->setValue( 1 );
814  $shuffle->setChecked( $this->object->getShuffle() );
815  $shuffle->setRequired( FALSE );
816  $form->addItem( $shuffle );
817 
818  if ($this->object->getId())
819  {
820  $hidden = new ilHiddenInputGUI("", "ID");
821  $hidden->setValue( $this->object->getId() );
822  $form->addItem( $hidden );
823  }
824 
825  $isSingleline = $this->getEditAnswersSingleLine();
826 
827  if (!$this->object->getSelfAssessmentEditingMode())
828  {
829  // Answer types
830  $types = new ilSelectInputGUI($this->lng->txt( "answer_types" ), "types");
831  $types->setRequired( false );
832  $types->setValue( ($isSingleline) ? 0 : 1 );
833  $types->setOptions( array(
834  0 => $this->lng->txt( 'answers_singleline' ),
835  1 => $this->lng->txt( 'answers_multiline' ),
836  )
837  );
838  $form->addItem( $types );
839  }
840 
841  if ($isSingleline)
842  {
843  // thumb size
844  $thumb_size = new ilNumberInputGUI($this->lng->txt( "thumb_size" ), "thumb_size");
845  $thumb_size->setSuffix($this->lng->txt("thumb_size_unit_pixel"));
846  $thumb_size->setMinValue( 20 );
847  $thumb_size->setDecimals( 0 );
848  $thumb_size->setSize( 6 );
849  $thumb_size->setInfo( $this->lng->txt( 'thumb_size_info' ) );
850  $thumb_size->setValue( $this->object->getThumbSize() );
851  $thumb_size->setRequired( false );
852  $form->addItem( $thumb_size );
853  return $isSingleline;
854  }
855  return $isSingleline;
856  }
857 
859  {
860  // Choices
861  include_once "./Modules/TestQuestionPool/classes/class.ilMultipleChoiceWizardInputGUI.php";
862  $choices = new ilMultipleChoiceWizardInputGUI($this->lng->txt( "answers" ), "choice");
863  $choices->setRequired( true );
864  $choices->setQuestionObject( $this->object );
865  $isSingleline = $this->getEditAnswersSingleLine();
866  $choices->setSingleline( $isSingleline );
867  $choices->setAllowMove( false );
868  if ($this->object->getSelfAssessmentEditingMode())
869  {
870  $choices->setSize( 40 );
871  $choices->setMaxLength( 800 );
872  }
873  if ($this->object->getAnswerCount() == 0)
874  $this->object->addAnswer( "", 0, 0, 0 );
875  $choices->setValues( $this->object->getAnswers() );
876  $form->addItem( $choices );
877  }
878 
889  {
890  return array();
891  }
892 
903  {
904  return array();
905  }
906 
915  public function getAggregatedAnswersView($relevant_answers)
916  {
917  return $this->renderAggregateView(
918  $this->aggregateAnswers( $relevant_answers, $this->object->getAnswers() ) )->get();
919  }
920 
921  public function aggregateAnswers($relevant_answers_chosen, $answers_defined_on_question)
922  {
923  $aggregate = array();
924  foreach ($answers_defined_on_question as $answer)
925  {
926  $aggregated_info_for_answer = array();
927  $aggregated_info_for_answer['answertext'] = $answer->getAnswerText();
928  $aggregated_info_for_answer['count_checked'] = 0;
929 
930  foreach ($relevant_answers_chosen as $relevant_answer)
931  {
932  if ($relevant_answer['value1'] == $answer->getOrder())
933  {
934  $aggregated_info_for_answer['count_checked']++;
935  }
936  }
937  $aggregated_info_for_answer['count_unchecked'] =
938  ceil(count($relevant_answers_chosen) / count($answers_defined_on_question))
939  - $aggregated_info_for_answer['count_checked'];
940 
941  $aggregate[] = $aggregated_info_for_answer;
942  }
943  return $aggregate;
944  }
945 
951  public function renderAggregateView($aggregate)
952  {
953  $tpl = new ilTemplate('tpl.il_as_aggregated_answers_table.html', true, true, "Modules/TestQuestionPool");
954 
955  $tpl->setCurrentBlock('headercell');
956  $tpl->setVariable('HEADER', $this->lng->txt('tst_answer_aggr_answer_header'));
957  $tpl->parseCurrentBlock();
958 
959  $tpl->setCurrentBlock('headercell');
960  $tpl->setVariable('HEADER', $this->lng->txt('tst_answer_aggr_frequency_header'));
961  $tpl->parseCurrentBlock();
962 
963  foreach ($aggregate as $line_data)
964  {
965  $tpl->setCurrentBlock( 'aggregaterow' );
966  $tpl->setVariable( 'OPTION', $line_data['answertext'] );
967  $tpl->setVariable( 'COUNT', $line_data['count_checked'] );
968  $tpl->parseCurrentBlock();
969  }
970  return $tpl;
971  }
972 
979  private function populateSpecificFeedbackInline($user_solution, $answer_id, $template)
980  {
981  if($this->object->getSpecificFeedbackSetting() == 2)
982  {
983  foreach($user_solution as $mc_solution)
984  {
985  if(strcmp($mc_solution, $answer_id) == 0)
986  {
987  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
988  if(strlen($fb))
989  {
990  $template->setCurrentBlock("feedback");
991  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
992  $template->parseCurrentBlock();
993  }
994  }
995  }
996  }
997 
998  if($this->object->getSpecificFeedbackSetting() == 1)
999  {
1000  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
1001  if(strlen($fb))
1002  {
1003  $template->setCurrentBlock("feedback");
1004  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
1005  $template->parseCurrentBlock();
1006  }
1007  }
1008 
1009  if($this->object->getSpecificFeedbackSetting() == 3)
1010  {
1011  $answer = $this->object->getAnswer($answer_id);
1012 
1013  if($answer->getPoints() > 0)
1014  {
1015  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), $answer_id);
1016  if(strlen($fb))
1017  {
1018  $template->setCurrentBlock("feedback");
1019  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
1020  $template->parseCurrentBlock();
1021  }
1022  }
1023  }
1024  }
1025 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
hasCorrectSolution($activeId, $passIndex)
addTab_QuestionPreview(ilTabsGUI $tabsGUI)
writePostData()
Evaluates a posted edit form and writes the form data in the question object.
$_POST['username']
Definition: cron.php:12
This class represents a selection list property in a property form.
addTab_QuestionHints(ilTabsGUI $tabs)
adds the hints tab to ilTabsGUI
This class represents a property form user interface.
$_GET["client_id"]
editQuestion($checkonly=FALSE)
Creates an output of the edit form for the question.
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.
getSpecificFeedbackOutput($active_id, $pass)
getTestOutputSolutions($activeId, $pass)
getAggregatedAnswersView($relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
This class represents a checkbox property in a property form.
addItem($a_item)
Add Item (Property, SectionHeader).
$url
Definition: shib_logout.php:72
getQuestionTemplate()
get question template
getTestOutput( $active_id, $pass, $is_postponed=FALSE, $use_post_solutions=FALSE, $show_feedback=FALSE)
Class for multiple choice tests.
populateTaxonomyFormSection(ilPropertyFormGUI $form)
removeimagechoice()
Remove an image.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
This class represents a hidden form property in a property form.
populateAnswerSpecificFormPart(\ilPropertyFormGUI $form)
setQuestionTabs()
Sets the ILIAS tabs for this question type.
setSuffix($a_value)
Set suffix.
getILIASPage($html="")
Returns the ILIAS Page around a question.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
This class represents a number property in a property form.
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
Extracts the answer specific values from $_POST and applies them to the data object.
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form)
writePostData($always=false)
Evaluates a posted edit form and writes the form data in the question object.
setValue($a_value)
Set Value.
special template class to simplify handling of ITX/PEAR
addTab_QuestionFeedback(ilTabsGUI $tabs)
adds the feedback tab to ilTabsGUI
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
Basic GUI class for assessment questions.
static getHtmlPath($relative_path)
get url of path
aggregateAnswers($relevant_answers_chosen, $answers_defined_on_question)
$filename
Definition: buildRTE.php:89
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getAnswerFeedbackOutput($active_id, $pass)
Returns the answer generic feedback depending on the results of the question.
Multiple choice question GUI representation.
getEditAnswersSingleLine($checkonly=false)
Get the single/multiline editing of answers.
__construct($id=-1)
assMultipleChoiceGUI constructor
This class represents a multiple choice wizard property in a property form.
$errors
getPreview($show_question_only=FALSE, $showInlineFeedback=false)
addBackTab(ilTabsGUI $ilTabs)
static secureString($a_str, $a_strip_html=true, $a_allow="")
Remove unsecure tags.
Interface ilGuiAnswerScoringAdjustable.
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
Interface ilGuiQuestionScoringAdjustable.
populateSpecificFeedbackInline($user_solution, $answer_id, $template)
setRequired($a_required)
Set Required.
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.
addTab_SuggestedSolution(ilTabsGUI $tabs, $classname)
addQuestionFormCommandButtons($form)
Add the command buttons of a question properties form.