ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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  {
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  public function hasInlineFeedback()
46  {
47  return $this->object->feedbackOBJ->isSpecificAnswerFeedbackAvailable($this->object->getId());
48  }
49 
53  protected function writePostData($always = false)
54  {
55  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
56  if (!$hasErrors) {
57  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
61  $this->saveTaxonomyAssignments();
62  return 0;
63  }
64  return 1;
65  }
66 
74  protected function getEditAnswersSingleLine($checkonly = false)
75  {
76  if ($checkonly) {
77  // form posting is checked
78  return ($_POST['types'] == 0) ? true : false;
79  }
80 
81  $lastChange = $this->object->getLastChange();
82  if (empty($lastChange) && !isset($_POST['types'])) {
83  // a new question is edited
84  return $this->object->getMultilineAnswerSetting() ? false : true;
85  } else {
86  // a saved question is edited
87  return $this->object->isSingleline;
88  }
89  }
90 
95  public function editQuestion($checkonly = false)
96  {
97  $save = $this->isSaveCommand();
98  $this->getQuestionTemplate();
99 
100  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
101  $form = new ilPropertyFormGUI();
102  $this->editForm = $form;
103 
104  $form->setFormAction($this->ctrl->getFormAction($this));
105  $form->setTitle($this->outQuestionType());
106  $isSingleline = $this->getEditAnswersSingleLine($checkonly);
107  if ($isSingleline) {
108  $form->setMultipart(true);
109  } else {
110  $form->setMultipart(false);
111  }
112  $form->setTableWidth("100%");
113  $form->setId("asssinglechoice");
114 
115  $this->addBasicQuestionFormProperties($form);
116  $this->populateQuestionSpecificFormPart($form);
117  $this->populateAnswerSpecificFormPart($form);
118 
119 
120  $this->populateTaxonomyFormSection($form);
121 
122  $this->addQuestionFormCommandButtons($form);
123 
124  $errors = false;
125 
126  if ($save) {
127  $form->setValuesByPost();
128  $errors = !$form->checkInput();
129  $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
130  if ($errors) {
131  $checkonly = false;
132  }
133  }
134 
135  if (!$checkonly) {
136  $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
137  }
138  return $errors;
139  }
140 
144  public function uploadchoice()
145  {
146  $this->writePostData(true);
147  $position = key($_POST['cmd']['uploadchoice']);
148  $this->editQuestion();
149  }
150 
154  public function removeimagechoice()
155  {
156  $this->writePostData(true);
157  $position = key($_POST['cmd']['removeimagechoice']);
158  $filename = $_POST['choice']['imagename'][$position];
159  $this->object->removeAnswerImage($position);
160  $this->editQuestion();
161  }
162 
166  public function addchoice()
167  {
168  $this->writePostData(true);
169  $position = key($_POST['cmd']['addchoice']);
170  $this->object->addAnswer("", 0, $position + 1);
171  $this->editQuestion();
172  }
173 
177  public function removechoice()
178  {
179  $this->writePostData(true);
180  $position = key($_POST['cmd']['removechoice']);
181  $this->object->deleteAnswer($position);
182  $this->editQuestion();
183  }
184 
191  {
192  return true;
193  }
194 
208  public function getSolutionOutput(
209  $active_id,
210  $pass = null,
211  $graphicalOutput = false,
212  $result_output = false,
213  $show_question_only = true,
214  $show_feedback = false,
215  $show_correct_solution = false,
216  $show_manual_scoring = false,
217  $show_question_text = true
218  ) {
219  // shuffle output
220  $keys = $this->getChoiceKeys();
221 
222  // get the solution of the user for the active pass or from the last pass if allowed
223  $user_solution = "";
224  if (($active_id > 0) && (!$show_correct_solution)) {
225  $solutions = $this->object->getSolutionValues($active_id, $pass, !$this->getUseIntermediateSolution());
226  foreach ($solutions as $idx => $solution_value) {
227  $user_solution = $solution_value["value1"];
228  }
229  } else {
230  $found_index = -1;
231  $max_points = 0;
232  foreach ($this->object->answers as $index => $answer) {
233  if ($answer->getPoints() > $max_points) {
234  $max_points = $answer->getPoints();
235  $found_index = $index;
236  }
237  }
238  $user_solution = $found_index;
239  }
240  // generate the question output
241  include_once "./Services/UICore/classes/class.ilTemplate.php";
242  $template = new ilTemplate("tpl.il_as_qpl_mc_sr_output_solution.html", true, true, "Modules/TestQuestionPool");
243  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "Modules/TestQuestionPool");
244  foreach ($keys as $answer_id) {
245  $answer = $this->object->answers[$answer_id];
246  if (($active_id > 0) && (!$show_correct_solution)) {
247  if ($graphicalOutput) {
248  // output of ok/not ok icons for user entered solutions
249  $ok = false;
250  if (strcmp($user_solution, $answer_id) == 0) {
251  if ($answer->getPoints() == $this->object->getMaximumPoints()) {
252  $ok = true;
253  } else {
254  $ok = false;
255  }
256  if ($ok) {
257  $template->setCurrentBlock("icon_ok");
258  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
259  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
260  $template->parseCurrentBlock();
261  } else {
262  $template->setCurrentBlock("icon_not_ok");
263  if ($answer->getPoints() > 0) {
264  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.svg"));
265  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
266  } else {
267  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
268  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
269  }
270  $template->parseCurrentBlock();
271  }
272  }
273  if (strlen($user_solution) == 0) {
274  $template->setCurrentBlock("icon_not_ok");
275  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
276  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
277  $template->parseCurrentBlock();
278  }
279  }
280  }
281  if (strlen($answer->getImage())) {
282  $template->setCurrentBlock("answer_image");
283  if ($this->object->getThumbSize()) {
284  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
285  } else {
286  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
287  }
288  $alt = $answer->getImage();
289  if (strlen($answer->getAnswertext())) {
290  $alt = $answer->getAnswertext();
291  }
292  $alt = preg_replace("/<[^>]*?>/", "", $alt);
293  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
294  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
295  $template->parseCurrentBlock();
296  }
297  if ($show_feedback) {
298  $this->populateInlineFeedback($template, $answer_id, $user_solution);
299  }
300  $template->setCurrentBlock("answer_row");
301  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), true));
302 
303  if ($this->renderPurposeSupportsFormHtml() || $this->isRenderPurposePrintPdf()) {
304  if (strcmp($user_solution, $answer_id) == 0) {
305  $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_checked.png")));
306  $template->setVariable("SOLUTION_ALT", $this->lng->txt("checked"));
307  } else {
308  $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
309  $template->setVariable("SOLUTION_ALT", $this->lng->txt("unchecked"));
310  }
311  } else {
312  $template->setVariable('QID', $this->object->getId());
313  $template->setVariable('SUFFIX', $show_correct_solution ? 'bestsolution' : 'usersolution');
314  $template->setVariable('SOLUTION_VALUE', $answer_id);
315  if (strcmp($user_solution, $answer_id) == 0) {
316  $template->setVariable('SOLUTION_CHECKED', 'checked');
317  }
318  }
319 
320  if ($result_output) {
321  $points = $this->object->answers[$answer_id]->getPoints();
322  $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
323  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
324  }
325  $template->parseCurrentBlock();
326  }
327  $questiontext = $this->object->getQuestionForHTMLOutput();
328  if ($show_feedback && $this->hasInlineFeedback()) {
329  $questiontext .= $this->buildFocusAnchorHtml();
330  }
331  if ($show_question_text == true) {
332  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, true));
333  }
334  $questionoutput = $template->get();
335  $feedback = ($show_feedback && !$this->isTestPresentationContext()) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
336  if (strlen($feedback)) {
337  $cssClass = (
338  $this->hasCorrectSolution($active_id, $pass) ?
340  );
341 
342  $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
343  $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, true));
344  }
345  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
346 
347  $solutionoutput = $solutiontemplate->get();
348 
349  if (!$show_question_only) {
350  // get page object output
351  $solutionoutput = $this->getILIASPage($solutionoutput);
352  }
353  return $solutionoutput;
354  }
355 
356  public function getPreview($show_question_only = false, $showInlineFeedback = false)
357  {
358  $keys = $this->getChoiceKeys();
359 
360  // generate the question output
361  include_once "./Services/UICore/classes/class.ilTemplate.php";
362  $template = new ilTemplate("tpl.il_as_qpl_mc_sr_output.html", true, true, "Modules/TestQuestionPool");
363  foreach ($keys as $answer_id) {
364  $answer = $this->object->answers[$answer_id];
365  if (strlen($answer->getImage())) {
366  if ($this->object->getThumbSize()) {
367  $template->setCurrentBlock("preview");
368  $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
369  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
370  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
371  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
372  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
373  $alt = $answer->getImage();
374  if (strlen($answer->getAnswertext())) {
375  $alt = $answer->getAnswertext();
376  }
377  $alt = preg_replace("/<[^>]*?>/", "", $alt);
378  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
379  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
380  $template->parseCurrentBlock();
381  } else {
382  $template->setCurrentBlock("answer_image");
383  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
384  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
385  $alt = $answer->getImage();
386  if (strlen($answer->getAnswertext())) {
387  $alt = $answer->getAnswertext();
388  }
389  $alt = preg_replace("/<[^>]*?>/", "", $alt);
390  $template->setVariable("ATTR", $attr);
391  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
392  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
393  $template->parseCurrentBlock();
394  }
395  }
396  if ($showInlineFeedback && is_object($this->getPreviewSession())) {
397  $this->populateInlineFeedback($template, $answer_id, $this->getPreviewSession()->getParticipantsSolution());
398  }
399  $template->setCurrentBlock("answer_row");
400  $template->setVariable("QID", $this->object->getId() . 'ID');
401  $template->setVariable("ANSWER_ID", $answer_id);
402  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), true));
403 
404  if (is_object($this->getPreviewSession())) {
405  $user_solution = $this->getPreviewSession()->getParticipantsSolution();
406  if (strcmp($user_solution, $answer_id) == 0) {
407  $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
408  }
409  }
410 
411  $template->parseCurrentBlock();
412  }
413  $questiontext = $this->object->getQuestionForHTMLOutput();
414  if ($showInlineFeedback && $this->hasInlineFeedback()) {
415  $questiontext .= $this->buildFocusAnchorHtml();
416  }
417  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, true));
418  $questionoutput = $template->get();
419  if (!$show_question_only) {
420  // get page object output
421  $questionoutput = $this->getILIASPage($questionoutput);
422  }
423  return $questionoutput;
424  }
425 
426  // hey: prevPassSolutions - pass will be always available from now on
427  public function getTestOutput($active_id, $pass, $is_postponed = false, $use_post_solutions = false, $show_feedback = false)
428  // hey.
429  {
430  $keys = $this->getChoiceKeys();
431 
432  // get the solution of the user for the active pass or from the last pass if allowed
433  $user_solution = "";
434  if ($active_id) {
435  // hey: prevPassSolutions - obsolete due to central check
436  #$solutions = NULL;
437  #include_once "./Modules/Test/classes/class.ilObjTest.php";
438  #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
439  #{
440  # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
441  #}
442  // hey.
443  $solutions = $this->object->getTestOutputSolutions($active_id, $pass);
444  foreach ($solutions as $idx => $solution_value) {
445  $user_solution = $solution_value["value1"];
446  }
447  }
448 
449  // generate the question output
450  include_once "./Services/UICore/classes/class.ilTemplate.php";
451  $template = new ilTemplate("tpl.il_as_qpl_mc_sr_output.html", true, true, "Modules/TestQuestionPool");
452  foreach ($keys as $answer_id) {
453  $answer = $this->object->answers[$answer_id];
454  if (strlen($answer->getImage())) {
455  if ($this->object->getThumbSize()) {
456  $template->setCurrentBlock("preview");
457  $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
458  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
459  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.svg'));
460  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
461  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
462  $alt = $answer->getImage();
463  if (strlen($answer->getAnswertext())) {
464  $alt = $answer->getAnswertext();
465  }
466  $alt = preg_replace("/<[^>]*?>/", "", $alt);
467  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
468  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
469  $template->parseCurrentBlock();
470  } else {
471  $template->setCurrentBlock("answer_image");
472  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
473  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
474  $alt = $answer->getImage();
475  if (strlen($answer->getAnswertext())) {
476  $alt = $answer->getAnswertext();
477  }
478  $alt = preg_replace("/<[^>]*?>/", "", $alt);
479  $template->setVariable("ATTR", $attr);
480  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
481  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
482  $template->parseCurrentBlock();
483  }
484  }
485  if ($show_feedback) {
486  $feedbackOutputRequired = false;
487 
488  switch ($this->object->getSpecificFeedbackSetting()) {
489  case 1:
490  $feedbackOutputRequired = true;
491  break;
492 
493  case 2:
494  if (strcmp($user_solution, $answer_id) == 0) {
495  $feedbackOutputRequired = true;
496  }
497  break;
498 
499  case 3:
500  if ($this->object->getAnswer($answer_id)->getPoints() > 0) {
501  $feedbackOutputRequired = true;
502  }
503  break;
504  }
505 
506  if ($feedbackOutputRequired) {
507  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
508  $this->object->getId(),
509  0,
510  $answer_id
511  );
512  if (strlen($fb)) {
513  $template->setCurrentBlock("feedback");
514  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
515  $template->parseCurrentBlock();
516  }
517  }
518  }
519  $template->setCurrentBlock("answer_row");
520  $template->setVariable("ANSWER_ID", $answer_id);
521  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), true));
522  if (strcmp($user_solution, $answer_id) == 0) {
523  $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
524  }
525  $template->parseCurrentBlock();
526  }
527  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
528  $questionoutput = $template->get();
529  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput, $show_feedback);
530  return $pageoutput;
531  }
532 
533  /*
534  * Create the key index numbers for the array of choices
535  *
536  * @return array
537  */
538  public function getChoiceKeys()
539  {
540  $choiceKeys = array_keys($this->object->answers);
541 
542  if ($this->object->getShuffle()) {
543  $choiceKeys = $this->object->getShuffler()->shuffle($choiceKeys);
544  }
545 
546  return $choiceKeys;
547  }
548 
549  public function getSpecificFeedbackOutput($userSolution)
550  {
551  // No return value, this question type supports inline specific feedback.
552  $output = "";
553  return $this->object->prepareTextareaOutput($output, true);
554  }
555 
557  {
558  $this->object->setShuffle($_POST["shuffle"]);
559  $this->object->setMultilineAnswerSetting($_POST["types"]);
560  if (is_array($_POST['choice']['imagename']) && $_POST["types"] == 1) {
561  $this->object->isSingleline = true;
562  ilUtil::sendInfo($this->lng->txt('info_answer_type_change'), true);
563  } else {
564  $this->object->isSingleline = ($_POST["types"] == 0) ? true : false;
565  }
566  $this->object->setThumbSize((strlen($_POST["thumb_size"])) ? $_POST["thumb_size"] : "");
567  }
568 
570  {
571  $isSingleline = $this->getEditAnswersSingleLine();
572  // shuffle
573  $shuffle = new ilCheckboxInputGUI($this->lng->txt("shuffle_answers"), "shuffle");
574  $shuffle->setValue(1);
575  $shuffle->setChecked($this->object->getShuffle());
576  $shuffle->setRequired(false);
577  $form->addItem($shuffle);
578 
579  if ($this->object->getId()) {
580  $hidden = new ilHiddenInputGUI("", "ID");
581  $hidden->setValue($this->object->getId());
582  $form->addItem($hidden);
583  }
584 
585  if (!$this->object->getSelfAssessmentEditingMode()) {
586  // Answer types
587  $types = new ilSelectInputGUI($this->lng->txt("answer_types"), "types");
588  $types->setRequired(false);
589  $types->setValue(($isSingleline) ? 0 : 1);
590  $types->setOptions(
591  array(
592  0 => $this->lng->txt('answers_singleline'),
593  1 => $this->lng->txt('answers_multiline'),
594  )
595  );
596  $form->addItem($types);
597  }
598 
599  if ($isSingleline) {
600  // thumb size
601  $thumb_size = new ilNumberInputGUI($this->lng->txt("thumb_size"), "thumb_size");
602  $thumb_size->setSuffix($this->lng->txt("thumb_size_unit_pixel"));
603  $thumb_size->setMinValue(20);
604  $thumb_size->setDecimals(0);
605  $thumb_size->setSize(6);
606  $thumb_size->setInfo($this->lng->txt('thumb_size_info'));
607  $thumb_size->setValue($this->object->getThumbSize());
608  $thumb_size->setRequired(false);
609  $form->addItem($thumb_size);
610  }
611  return $form;
612  }
613 
624  {
625  return array();
626  }
627 
629  {
630  // Delete all existing answers and create new answers from the form data
631  $this->object->flushAnswers();
632  if ($this->object->isSingleline) {
633  foreach ($_POST['choice']['answer'] as $index => $answertext) {
634  $answertext = ilUtil::secureString(htmlentities($answertext));
635  $picturefile = $_POST['choice']['imagename'][$index];
636  $file_org_name = $_FILES['choice']['name']['image'][$index];
637  $file_temp_name = $_FILES['choice']['tmp_name']['image'][$index];
638 
639  if (strlen($file_temp_name)) {
640  // check suffix
641  $suffix = strtolower(array_pop(explode(".", $file_org_name)));
642  if (in_array($suffix, array( "jpg", "jpeg", "png", "gif" ))) {
643  // upload image
644  $filename = $this->object->buildHashedImageFilename($file_org_name);
645  if ($this->object->setImageFile($filename, $file_temp_name) == 0) {
646  $picturefile = $filename;
647  }
648  }
649  }
650  $this->object->addAnswer($answertext, $_POST['choice']['points'][$index], $index, $picturefile, $_POST['choice']['answer_id'][$index]);
651  }
652  } else {
653  foreach ($_POST['choice']['answer'] as $index => $answer) {
654  $answertext = $answer;
655  $this->object->addAnswer($answertext, $_POST['choice']['points'][$index], $index, "", $_POST['choice']['answer_id'][$index]);
656  }
657  }
658  }
659 
661  {
662  $isSingleline = $this->getEditAnswersSingleLine();
663 
664  // Choices
665  include_once "./Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php";
666  $choices = new ilSingleChoiceWizardInputGUI($this->lng->txt("answers"), "choice");
667  $choices->setRequired(true);
668  $choices->setQuestionObject($this->object);
669  $choices->setSingleline($isSingleline);
670  $choices->setAllowMove(false);
671  if ($this->object->getSelfAssessmentEditingMode()) {
672  $choices->setSize(40);
673  }
674  $choices->setMaxLength(800);
675  if ($this->object->getAnswerCount() == 0) {
676  $this->object->addAnswer("", 0, 0);
677  }
678  $choices->setValues(array_map(
679  function (ASS_AnswerBinaryStateImage $value) {
680  $value->setAnswerText(html_entity_decode($value->getAnswerText()));
681  return $value;
682  },
683  $this->object->getAnswers()
684  ));
685  $form->addItem($choices);
686  }
687 
698  {
699  return array();
700  }
701 
710  public function getAggregatedAnswersView($relevant_answers)
711  {
712  return $this->renderAggregateView(
713  $this->aggregateAnswers($relevant_answers, $this->object->getAnswers())
714  )->get();
715  }
716 
717  public function aggregateAnswers($relevant_answers_chosen, $answers_defined_on_question)
718  {
719  $aggregate = array();
720  foreach ($answers_defined_on_question as $answer) {
721  $aggregated_info_for_answer = array();
722  $aggregated_info_for_answer['answertext'] = $answer->getAnswerText();
723  $aggregated_info_for_answer['count_checked'] = 0;
724 
725  foreach ($relevant_answers_chosen as $relevant_answer) {
726  if ($relevant_answer['value1'] == $answer->getOrder()) {
727  $aggregated_info_for_answer['count_checked']++;
728  }
729  }
730  $aggregated_info_for_answer['count_unchecked'] =
731  ceil(count($relevant_answers_chosen) / count($answers_defined_on_question))
732  - $aggregated_info_for_answer['count_checked'];
733 
734  $aggregate[] = $aggregated_info_for_answer;
735  }
736  return $aggregate;
737  }
738 
744  public function renderAggregateView($aggregate)
745  {
746  $tpl = new ilTemplate('tpl.il_as_aggregated_answers_table.html', true, true, "Modules/TestQuestionPool");
747 
748  $tpl->setCurrentBlock('headercell');
749  $tpl->setVariable('HEADER', $this->lng->txt('tst_answer_aggr_answer_header'));
750  $tpl->parseCurrentBlock();
751 
752  $tpl->setCurrentBlock('headercell');
753  $tpl->setVariable('HEADER', $this->lng->txt('tst_answer_aggr_frequency_header'));
754  $tpl->parseCurrentBlock();
755 
756  foreach ($aggregate as $line_data) {
757  $tpl->setCurrentBlock('aggregaterow');
758  $tpl->setVariable('OPTION', $line_data['answertext']);
759  $tpl->setVariable('COUNT', $line_data['count_checked']);
760  $tpl->parseCurrentBlock();
761  }
762  return $tpl;
763  }
764 
765  private function populateInlineFeedback($template, $answer_id, $user_solution)
766  {
767  $feedbackOutputRequired = false;
768 
769  switch ($this->object->getSpecificFeedbackSetting()) {
770  case 1:
771  $feedbackOutputRequired = true;
772  break;
773 
774  case 2:
775  if (strcmp($user_solution, $answer_id) == 0) {
776  $feedbackOutputRequired = true;
777  }
778  break;
779 
780  case 3:
781  if ($this->object->getAnswer($answer_id)->getPoints() > 0) {
782  $feedbackOutputRequired = true;
783  }
784  break;
785  }
786 
787  if ($feedbackOutputRequired) {
788  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), 0, $answer_id);
789  if (strlen($fb)) {
790  $template->setCurrentBlock("feedback");
791  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
792  $template->parseCurrentBlock();
793  }
794  }
795  }
796 
797  public function getAnswersFrequency($relevantAnswers, $questionIndex)
798  {
799  $agg = $this->aggregateAnswers($relevantAnswers, $this->object->getAnswers());
800 
801  $answers = array();
802 
803  foreach ($agg as $ans) {
804  $answers[] = array(
805  'answer' => $ans['answertext'],
806  'frequency' => $ans['count_checked']
807  );
808  }
809 
810  return $answers;
811  }
812 
814  {
815  require_once 'Modules/TestQuestionPool/classes/forms/class.ilAssSingleChoiceCorrectionsInputGUI.php';
816  $choices = new ilAssSingleChoiceCorrectionsInputGUI($this->lng->txt("answers"), "choice");
817  $choices->setRequired(true);
818  $choices->setQuestionObject($this->object);
819  $choices->setValues($this->object->getAnswers());
820  $form->addItem($choices);
821  }
822 
827  {
828  $points = $form->getInput('choice')['points'];
829 
830  foreach ($this->object->getAnswers() as $index => $answer) {
831  /* @var ASS_AnswerMultipleResponseImage $answer */
832  $answer->setPoints((float) $points[$index]);
833  }
834  }
835 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
hasCorrectSolution($activeId, $passIndex)
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)
{}
$errors
Definition: imgupload.php:49
This class represents a property form user interface.
$type
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
Extracts the answer specific values from $_POST and applies them to the data object.
Class for answers with a binary state indicator.
populateInlineFeedback($template, $answer_id, $user_solution)
supportsIntermediateSolutionOutput()
Question type specific support of intermediate solution output The function getSolutionOutput respect...
This class represents a checkbox property in a property form.
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form)
addItem($a_item)
Add Item (Property, SectionHeader).
getQuestionTemplate()
get question template
getAnswersFrequency($relevantAnswers, $questionIndex)
populateTaxonomyFormSection(ilPropertyFormGUI $form)
getUseIntermediateSolution()
Get if intermediate solution should be used for solution output.
$index
Definition: metadata.php:128
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
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.
getSpecificFeedbackOutput($userSolution)
$keys
Definition: metadata.php:187
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.
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
removechoice()
Remove an answer.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
Basic GUI class for assessment questions.
static getHtmlPath($relative_path)
get url of path
$filename
Definition: buildRTE.php:89
getAnswerFeedbackOutput($active_id, $pass)
Returns the answer generic feedback depending on the results of the question.
populateAnswerSpecificFormPart(\ilPropertyFormGUI $form)
populateCorrectionsFormProperties(ilPropertyFormGUI $form)
addchoice()
Add a new answer.
This class represents a single choice wizard property in a property form.
saveCorrectionsFormProperties(ilPropertyFormGUI $form)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
output question page
__construct(Container $dic, ilPlugin $plugin)
static secureString($a_str, $a_strip_html=true, $a_allow="")
Remove unsecure tags.
Interface ilGuiAnswerScoringAdjustable.
Single choice question GUI representation.
__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.
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.