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