ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assMultipleChoiceGUI.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
25 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
26 
39 {
41 
50  function __construct($id = -1)
51  {
53  include_once "./Modules/TestQuestionPool/classes/class.assMultipleChoice.php";
54  $this->object = new assMultipleChoice();
55  if ($id >= 0)
56  {
57  $this->object->loadFromDb($id);
58  }
59  }
60 
61  function getCommand($cmd)
62  {
63  return $cmd;
64  }
65 
72  function writePostData($always = false)
73  {
74  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
75  if (!$hasErrors)
76  {
77  $this->object->setTitle($_POST["title"]);
78  $this->object->setAuthor($_POST["author"]);
79  $this->object->setComment($_POST["comment"]);
80  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
81  $questiontext = $_POST["question"];
82  $this->object->setQuestion($questiontext);
83  $this->object->setShuffle($_POST["shuffle"]);
84  $this->object->setEstimatedWorkingTime(
85  $_POST["Estimated"]["hh"],
86  $_POST["Estimated"]["mm"],
87  $_POST["Estimated"]["ss"]
88  );
89 
90  $this->object->setFeedbackSetting($_POST['feedback_setting']);
91  if ($this->getSelfAssessmentEditingMode())
92  {
93  $this->object->setNrOfTries($_POST['nr_of_tries']);
94  }
95  $this->object->setMultilineAnswerSetting($_POST["types"]);
96  if (is_array($_POST['choice']['imagename']) && $_POST["types"] == 1)
97  {
98  $this->object->isSingleline = true;
99  ilUtil::sendInfo($this->lng->txt('info_answer_type_change'), true);
100  }
101  else
102  {
103  $this->object->isSingleline = ($_POST["types"] == 0) ? true : false;
104  }
105  $this->object->setThumbSize((strlen($_POST["thumb_size"])) ? $_POST["thumb_size"] : "");
106 
107  // Delete all existing answers and create new answers from the form data
108  $this->object->flushAnswers();
109  if ($this->object->isSingleline)
110  {
111  foreach ($_POST['choice']['answer'] as $index => $answertext)
112  {
113  $picturefile = $_POST['choice']['imagename'][$index];
114  $file_org_name = $_FILES['choice']['name']['image'][$index];
115  $file_temp_name = $_FILES['choice']['tmp_name']['image'][$index];
116 
117  if (strlen($file_temp_name))
118  {
119  // check suffix
120  $suffix = strtolower(array_pop(explode(".", $file_org_name)));
121  if(in_array($suffix, array("jpg", "jpeg", "png", "gif")))
122  {
123  // upload image
124  $filename = $this->object->createNewImageFileName($file_org_name);
125  if ($this->object->setImageFile($filename, $file_temp_name) == 0)
126  {
127  $picturefile = $filename;
128  }
129  }
130  }
131  $this->object->addAnswer($answertext, $_POST['choice']['points'][$index], $_POST['choice']['points_unchecked'][$index], $index, $picturefile);
132  }
133  }
134  else
135  {
136  foreach ($_POST['choice']['answer'] as $index => $answer)
137  {
138  $answertext = $answer;
139  $this->object->addAnswer($answertext, $_POST['choice']['points'][$index], $_POST['choice']['points_unchecked'][$index], $index);
140  }
141  }
142  return 0;
143  }
144  else
145  {
146  return 1;
147  }
148  }
149 
155  public function editQuestion($checkonly = FALSE)
156  {
157  $save = $this->isSaveCommand();
158  $this->getQuestionTemplate();
159 
160  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
161  $form = new ilPropertyFormGUI();
162  $form->setFormAction($this->ctrl->getFormAction($this));
163  $form->setTitle($this->outQuestionType());
164  $isSingleline = ($this->object->lastChange == 0 && !array_key_exists('types', $_POST)) ? (($this->object->getMultilineAnswerSetting()) ? false : true) : $this->object->isSingleline;
165  if ($checkonly) $isSingleline = ($_POST['types'] == 0) ? true : false;
166  if ($isSingleline)
167  {
168  $form->setMultipart(TRUE);
169  }
170  else
171  {
172  $form->setMultipart(FALSE);
173  }
174  $form->setTableWidth("100%");
175  $form->setId("assmultiplechoice");
176 
177  // title, author, description, question, working time (assessment mode)
178  $this->addBasicQuestionFormProperties($form);
179 
180  // shuffle
181  $shuffle = new ilCheckboxInputGUI($this->lng->txt("shuffle_answers"), "shuffle");
182  $shuffle->setValue(1);
183  $shuffle->setChecked($this->object->getShuffle());
184  $shuffle->setRequired(FALSE);
185  $form->addItem($shuffle);
186 
187  if ($this->object->getId())
188  {
189  $hidden = new ilHiddenInputGUI("", "ID");
190  $hidden->setValue($this->object->getId());
191  $form->addItem($hidden);
192  }
193 
194  if(!$this->getSelfAssessmentEditingMode())
195  {
196  // Answer types
197  $types = new ilSelectInputGUI($this->lng->txt("answer_types"), "types");
198  $types->setRequired(false);
199  $types->setValue(($isSingleline) ? 0 : 1);
200  $types->setOptions(array(
201  0 => $this->lng->txt('answers_singleline'),
202  1 => $this->lng->txt('answers_multiline'),
203  ));
204  $form->addItem($types);
205  }
206 
207  if ($isSingleline)
208  {
209  // thumb size
210  $thumb_size = new ilNumberInputGUI($this->lng->txt("thumb_size"), "thumb_size");
211  $thumb_size->setSuffix($this->lng->txt("thumb_size_unit_pixel"));
212  $thumb_size->setMinValue(20);
213  $thumb_size->setDecimals(0);
214  $thumb_size->setSize(6);
215  $thumb_size->setInfo($this->lng->txt('thumb_size_info'));
216  $thumb_size->setValue($this->object->getThumbSize());
217  $thumb_size->setRequired(false);
218  $form->addItem($thumb_size);
219  }
220 
221  // Choices
222  include_once "./Modules/TestQuestionPool/classes/class.ilMultipleChoiceWizardInputGUI.php";
223  $choices = new ilMultipleChoiceWizardInputGUI($this->lng->txt("answers"), "choice");
224  $choices->setRequired(true);
225  $choices->setQuestionObject($this->object);
226  $choices->setSingleline($isSingleline);
227  $choices->setAllowMove(false);
228  if ($this->getSelfAssessmentEditingMode())
229  {
230  $choices->setSize(40);
231  $choices->setMaxLength(800);
232  }
233  if ($this->object->getAnswerCount() == 0) $this->object->addAnswer("", 0, 0, 0);
234  $choices->setValues($this->object->getAnswers());
235  $form->addItem($choices);
236 
237  $this->addQuestionFormCommandButtons($form);
238 
239  $errors = false;
240 
241  if ($save)
242  {
243 
244  $form->setValuesByPost();
245  $errors = !$form->checkInput();
246  $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
247  if ($errors) $checkonly = false;
248  }
249 
250  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
251  return $errors;
252  }
253 
257  public function uploadchoice()
258  {
259  $this->writePostData(true);
260  $position = key($_POST['cmd']['uploadchoice']);
261  $this->editQuestion();
262  }
263 
267  public function removeimagechoice()
268  {
269  $this->writePostData(true);
270  $position = key($_POST['cmd']['removeimagechoice']);
271  $filename = $_POST['choice']['imagename'][$position];
272  $this->object->removeAnswerImage($position);
273  $this->editQuestion();
274  }
275 
279  public function addchoice()
280  {
281  $this->writePostData(true);
282  $position = key($_POST['cmd']['addchoice']);
283  $this->object->addAnswer("", 0, 0, $position+1);
284  $this->editQuestion();
285  }
286 
290  public function removechoice()
291  {
292  $this->writePostData(true);
293  $position = key($_POST['cmd']['removechoice']);
294  $this->object->deleteAnswer($position);
295  $this->editQuestion();
296  }
297 
298  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_question_postponed = FALSE,
299  $user_post_solutions = FALSE, $show_specific_inline_feedback = FALSE)
300  {
301  $test_output = $this->getTestOutput(
302  $active_id,
303  $pass,
304  $is_question_postponed,
305  $user_post_solutions,
306  $show_specific_inline_feedback
307  );
308 
309  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
310  $this->tpl->setVariable("FORMACTION", $formaction);
311  }
312 
327  $active_id,
328  $pass = NULL,
329  $graphicalOutput = FALSE,
330  $result_output = FALSE,
331  $show_question_only = TRUE,
332  $show_feedback = FALSE,
333  $show_correct_solution = FALSE,
334  $show_manual_scoring = FALSE,
335  $show_question_text = TRUE
336  )
337  {
338  // shuffle output
339  $keys = $this->getChoiceKeys();
340 
341  // get the solution of the user for the active pass or from the last pass if allowed
342  $user_solution = array();
343  if (($active_id > 0) && (!$show_correct_solution))
344  {
345  $solutions =& $this->object->getSolutionValues($active_id, $pass);
346  foreach ($solutions as $idx => $solution_value)
347  {
348  array_push($user_solution, $solution_value["value1"]);
349  }
350  }
351  else
352  {
353  // take the correct solution instead of the user solution
354  foreach ($this->object->answers as $index => $answer)
355  {
356  $points_checked = $answer->getPointsChecked();
357  $points_unchecked = $answer->getPointsUnchecked();
358  if ($points_checked > $points_unchecked)
359  {
360  if ($points_checked > 0)
361  {
362  array_push($user_solution, $index);
363  }
364  }
365  }
366  }
367 
368  // generate the question output
369  include_once "./Services/UICore/classes/class.ilTemplate.php";
370  $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
371  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
372  foreach ($keys as $answer_id)
373  {
374  $answer = $this->object->answers[$answer_id];
375  if (($active_id > 0) && (!$show_correct_solution))
376  {
377  if ($graphicalOutput)
378  {
379  // output of ok/not ok icons for user entered solutions
380  $ok = FALSE;
381  $checked = FALSE;
382  foreach ($user_solution as $mc_solution)
383  {
384  if (strcmp($mc_solution, $answer_id) == 0)
385  {
386  $checked = TRUE;
387  }
388  }
389  if ($checked)
390  {
391  if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
392  {
393  $ok = TRUE;
394  }
395  else
396  {
397  $ok = FALSE;
398  }
399  }
400  else
401  {
402  if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
403  {
404  $ok = FALSE;
405  }
406  else
407  {
408  $ok = TRUE;
409  }
410  }
411  if ($ok)
412  {
413  $template->setCurrentBlock("icon_ok");
414  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.png"));
415  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
416  $template->parseCurrentBlock();
417  }
418  else
419  {
420  $template->setCurrentBlock("icon_ok");
421  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.png"));
422  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
423  $template->parseCurrentBlock();
424  }
425  }
426  }
427  if (strlen($answer->getImage()))
428  {
429  $template->setCurrentBlock("answer_image");
430  if ($this->object->getThumbSize())
431  {
432  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
433  }
434  else
435  {
436  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
437  }
438  $alt = $answer->getImage();
439  if (strlen($answer->getAnswertext()))
440  {
441  $alt = $answer->getAnswertext();
442  }
443  $alt = preg_replace("/<[^>]*?>/", "", $alt);
444  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
445  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
446  $template->parseCurrentBlock();
447  }
448 
449  if ($show_feedback)
450  {
451 
452  if ($this->object->getFeedbackSetting() == 2)
453  {
454  foreach ($user_solution as $mc_solution)
455  {
456  if (strcmp($mc_solution, $answer_id) == 0)
457  {
458  $fb = $this->object->getFeedbackSingleAnswer($answer_id);
459  if (strlen($fb))
460  {
461  $template->setCurrentBlock("feedback");
462  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
463  $template->parseCurrentBlock();
464  }
465  }
466  }
467  }
468 
469  if ($this->object->getFeedbackSetting() == 1)
470  {
471  $fb = $this->object->getFeedbackSingleAnswer($answer_id);
472  if (strlen($fb))
473  {
474  $template->setCurrentBlock("feedback");
475  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
476  $template->parseCurrentBlock();
477  }
478  }
479 
480  if ($this->object->getFeedbackSetting() == 3)
481  {
482  $answer = $this->object->getAnswer($answer_id);
483 
484  if ($answer->getPoints() > 0)
485  {
486  $fb = $this->object->getFeedbackSingleAnswer($answer_id);
487  if (strlen($fb))
488  {
489  $template->setCurrentBlock("feedback");
490  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
491  $template->parseCurrentBlock();
492  }
493  }
494 
495  }
496  }
497  $template->setCurrentBlock("answer_row");
498  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
499  $checked = FALSE;
500  if ($result_output)
501  {
502  $pointschecked = $this->object->answers[$answer_id]->getPointsChecked();
503  $pointsunchecked = $this->object->answers[$answer_id]->getPointsUnchecked();
504  $resulttextchecked = ($pointschecked == 1) || ($pointschecked == -1) ? "%s " . $this->lng->txt("point") : "%s " . $this->lng->txt("points");
505  $resulttextunchecked = ($pointsunchecked == 1) || ($pointsunchecked == -1) ? "%s " . $this->lng->txt("point") : "%s " . $this->lng->txt("points");
506  $template->setVariable("RESULT_OUTPUT", sprintf("(" . $this->lng->txt("checkbox_checked") . " = $resulttextchecked, " . $this->lng->txt("checkbox_unchecked") . " = $resulttextunchecked)", $pointschecked, $pointsunchecked));
507  }
508  foreach ($user_solution as $mc_solution)
509  {
510  if (strcmp($mc_solution, $answer_id) == 0)
511  {
512  $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_checked.png")));
513  $template->setVariable("SOLUTION_ALT", $this->lng->txt("checked"));
514  $checked = TRUE;
515  }
516  }
517  if (!$checked)
518  {
519  $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.png")));
520  $template->setVariable("SOLUTION_ALT", $this->lng->txt("unchecked"));
521  }
522  $template->parseCurrentBlock();
523  }
524  $questiontext = $this->object->getQuestion();
525  if ($show_question_text==true)
526  {
527  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
528  }
529  $questionoutput = $template->get();
530  #$feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
531  #if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
532  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
533 
534  $solutionoutput = $solutiontemplate->get();
535  if (!$show_question_only)
536  {
537  // get page object output
538  $solutionoutput = '<div class="ilc_question_Standard">'.$solutionoutput."</div>";
539  }
540  return $solutionoutput;
541  }
542 
543  function getPreview($show_question_only = FALSE)
544  {
545  // shuffle output
546  $keys = $this->getChoiceKeys();
547 
548  // generate the question output
549  include_once "./Services/UICore/classes/class.ilTemplate.php";
550  $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
551  foreach ($keys as $answer_id)
552  {
553  $answer = $this->object->answers[$answer_id];
554  if (strlen($answer->getImage()))
555  {
556  if ($this->object->getThumbSize())
557  {
558  $template->setCurrentBlock("preview");
559  $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
560  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
561  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.png'));
562  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
563  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
564  $alt = $answer->getImage();
565  if (strlen($answer->getAnswertext()))
566  {
567  $alt = $answer->getAnswertext();
568  }
569  $alt = preg_replace("/<[^>]*?>/", "", $alt);
570  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
571  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
572  $template->parseCurrentBlock();
573  }
574  else
575  {
576  $template->setCurrentBlock("answer_image");
577  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
578  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
579  $alt = $answer->getImage();
580  if (strlen($answer->getAnswertext()))
581  {
582  $alt = $answer->getAnswertext();
583  }
584  $alt = preg_replace("/<[^>]*?>/", "", $alt);
585  $template->setVariable("ATTR", $attr);
586  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
587  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
588  $template->parseCurrentBlock();
589  }
590  }
591  $template->setCurrentBlock("answer_row");
592  $template->setVariable("ANSWER_ID", $answer_id);
593  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
594  $template->parseCurrentBlock();
595  }
596  $questiontext = $this->object->getQuestion();
597  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
598  $questionoutput = $template->get();
599  if (!$show_question_only)
600  {
601  // get page object output
602  $questionoutput = $this->getILIASPage($questionoutput);
603  }
604  return $questionoutput;
605  }
606 
607  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
608  {
609  // shuffle output
610  $keys = $this->getChoiceKeys();
611 
612  // get the solution of the user for the active pass or from the last pass if allowed
613  $user_solution = array();
614  if ($active_id)
615  {
616  $solutions = NULL;
617  include_once "./Modules/Test/classes/class.ilObjTest.php";
618  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
619  {
620  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
621  }
622  $solutions =& $this->object->getSolutionValues($active_id, $pass);
623  foreach ($solutions as $idx => $solution_value)
624  {
625  array_push($user_solution, $solution_value["value1"]);
626  }
627  }
628  // generate the question output
629  include_once "./Services/UICore/classes/class.ilTemplate.php";
630  $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
631  foreach ($keys as $answer_id)
632  {
633  $answer = $this->object->answers[$answer_id];
634  if (strlen($answer->getImage()))
635  {
636  if ($this->object->getThumbSize())
637  {
638  $template->setCurrentBlock("preview");
639  $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
640  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
641  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.png'));
642  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
643  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
644  $alt = $answer->getImage();
645  if (strlen($answer->getAnswertext()))
646  {
647  $alt = $answer->getAnswertext();
648  }
649  $alt = preg_replace("/<[^>]*?>/", "", $alt);
650  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
651  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
652  $template->parseCurrentBlock();
653  }
654  else
655  {
656  $template->setCurrentBlock("answer_image");
657  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
658  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
659  $alt = $answer->getImage();
660  if (strlen($answer->getAnswertext()))
661  {
662  $alt = $answer->getAnswertext();
663  }
664  $alt = preg_replace("/<[^>]*?>/", "", $alt);
665  $template->setVariable("ATTR", $attr);
666  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
667  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
668  $template->parseCurrentBlock();
669  }
670  }
671  if ($show_feedback && $this->object->getFeedbackSetting() == 2)
672  {
673  foreach ($user_solution as $mc_solution)
674  {
675  if (strcmp($mc_solution, $answer_id) == 0)
676  {
677  $fb = $this->object->getFeedbackSingleAnswer($answer_id);
678  if (strlen($fb))
679  {
680  $template->setCurrentBlock("feedback");
681  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
682  $template->parseCurrentBlock();
683  }
684  }
685  }
686  }
687 
688  if ($show_feedback && $this->object->getFeedbackSetting() == 1)
689  {
690  $fb = $this->object->getFeedbackSingleAnswer($answer_id);
691  if (strlen($fb))
692  {
693  $template->setCurrentBlock("feedback");
694  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($fb, true));
695  $template->parseCurrentBlock();
696  }
697  }
698 
699  if ($show_feedback && $this->object->getFeedbackSetting() == 3)
700  {
701  $answer = $this->object->getAnswer($answer_id);
702 
703  if ($answer->getPoints() > 0)
704  {
705  $fb = $this->object->getFeedbackSingleAnswer($answer_id);
706  if (strlen($fb))
707  {
708  $template->setCurrentBlock("feedback");
709  $template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $fb, true));
710  $template->parseCurrentBlock();
711  }
712  }
713 
714  }
715 
716 
717  $template->setCurrentBlock("answer_row");
718  $template->setVariable("ANSWER_ID", $answer_id);
719  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
720  foreach ($user_solution as $mc_solution)
721  {
722  if (strcmp($mc_solution, $answer_id) == 0)
723  {
724  $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
725  }
726  }
727  $template->parseCurrentBlock();
728  }
729  $questiontext = $this->object->getQuestion();
730  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
731  $questionoutput = $template->get();
732  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
733  return $pageoutput;
734  }
735 
741  function saveFeedback()
742  {
743  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
744  $errors = $this->feedback(true);
745  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
746  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
747  $this->object->saveFeedbackSetting($_POST['feedback_setting']);
748  foreach ($this->object->answers as $index => $answer)
749  {
750  $this->object->saveFeedbackSingleAnswer($index, $_POST["feedback_answer_$index"]);
751  }
752  $this->object->cleanupMediaObjectUsage();
754  }
755 
761  function feedback($checkonly = false)
762  {
763  $save = (strcmp($this->ctrl->getCmd(), "saveFeedback") == 0) ? TRUE : FALSE;
764  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
765  $form = new ilPropertyFormGUI();
766  $form->setFormAction($this->ctrl->getFormAction($this));
767  $form->setTitle($this->lng->txt('feedback_answers'));
768  $form->setTableWidth("100%");
769  $form->setId("feedback");
770 
771  $complete = new ilTextAreaInputGUI($this->lng->txt("feedback_complete_solution"), "feedback_complete");
772  $complete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
773  $complete->setRequired(false);
774  $complete->setRows(10);
775  $complete->setCols(80);
776  if (!$this->getPreventRteUsage())
777  {
778  $complete->setUseRte(true);
779  }
780  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
781  $complete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
782  $complete->addPlugin("latex");
783  $complete->addButton("latex");
784  $complete->addButton("pastelatex");
785  $complete->setRTESupport($this->object->getId(), "qpl", "assessment", null, false, '3.4.7');
786  $form->addItem($complete);
787 
788  $incomplete = new ilTextAreaInputGUI($this->lng->txt("feedback_incomplete_solution"), "feedback_incomplete");
789  $incomplete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
790  $incomplete->setRequired(false);
791  $incomplete->setRows(10);
792  $incomplete->setCols(80);
793  if (!$this->getPreventRteUsage())
794  {
795  $incomplete->setUseRte(true);
796  }
797  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
798  $incomplete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
799  $incomplete->addPlugin("latex");
800  $incomplete->addButton("latex");
801  $incomplete->addButton("pastelatex");
802  $incomplete->setRTESupport($this->object->getId(), "qpl", "assessment", null, false, '3.4.7');
803  $form->addItem($incomplete);
804 
805  require_once './Services/Form/classes/class.ilRadioGroupInputGUI.php';
806  require_once './Services/Form/classes/class.ilRadioOption.php';
807 
808  $feedback = new ilRadioGroupInputGUI($this->lng->txt('feedback_setting'), 'feedback_setting');
809  $feedback->addOption(new ilRadioOption($this->lng->txt('feedback_all'), 1), true);
810  $feedback->addOption(new ilRadioOption($this->lng->txt('feedback_checked'), 2));
811  $feedback->addOption(new ilRadioOption($this->lng->txt('feedback_correct'), 3));
812  $feedback->setValue($this->object->getFeedbackSetting());
813  $form->addItem($feedback);
814 
815  if (!$this->getSelfAssessmentEditingMode())
816  {
817  foreach ($this->object->answers as $index => $answer)
818  {
819  $answerobj = new ilTextAreaInputGUI($this->object->prepareTextareaOutput($answer->getAnswertext(), true), "feedback_answer_$index");
820  $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
821  $answerobj->setRequired(false);
822  $answerobj->setRows(10);
823  $answerobj->setCols(80);
824  $answerobj->setUseRte(true);
825  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
826  $answerobj->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
827  $answerobj->addPlugin("latex");
828  $answerobj->addButton("latex");
829  $answerobj->addButton("pastelatex");
830  $answerobj->setRTESupport($this->object->getId(), "qpl", "assessment", null, false, '3.4.7');
831  $form->addItem($answerobj);
832  }
833  }
834 
835  global $ilAccess;
836  if ($ilAccess->checkAccess("write", "", $_GET['ref_id']) || $this->getSelfAssessmentEditingMode())
837  {
838  $form->addCommandButton("saveFeedback", $this->lng->txt("save"));
839  }
840  if ($save)
841  {
842  $form->setValuesByPost();
843  $errors = !$form->checkInput();
844  $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
845  }
846  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
847  return $errors;
848  }
849 
857  function setQuestionTabs()
858  {
859  global $rbacsystem, $ilTabs;
860 
861  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
862  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
863  $q_type = $this->object->getQuestionType();
864 
865  if (strlen($q_type))
866  {
867  $classname = $q_type . "GUI";
868  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
869  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
870  }
871 
872  if ($_GET["q_id"])
873  {
874  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
875  {
876  // edit page
877  $ilTabs->addTarget("edit_page",
878  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
879  array("edit", "insert", "exec_pg"),
880  "", "", $force_active);
881  }
882 
883  // edit page
884  $ilTabs->addTarget("preview",
885  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
886  array("preview"),
887  "ilPageObjectGUI", "", $force_active);
888  }
889  $force_active = false;
890  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
891  {
892  $url = "";
893  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
894  $force_active = false;
895  // edit question properties
896  $ilTabs->addTarget("edit_question",
897  $url,
898  array("editQuestion", "save", "saveEdit", "addchoice", "removechoice", "removeimagechoice", "uploadchoice", "originalSyncForm"),
899  $classname, "", $force_active);
900  }
901 
902  if ($_GET["q_id"])
903  {
904  $ilTabs->addTarget("feedback",
905  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
906  array("feedback", "saveFeedback"),
907  $classname, "");
908  }
909 
910  // add tab for question hint within common class assQuestionGUI
911  $this->addTab_QuestionHints($ilTabs);
912 
913  if ($_GET["q_id"])
914  {
915  $ilTabs->addTarget("solution_hint",
916  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
917  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
918  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
919  ),
920  $classname,
921  ""
922  );
923  }
924 
925  // Assessment of questions sub menu entry
926  if ($_GET["q_id"])
927  {
928  $ilTabs->addTarget("statistics",
929  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
930  array("assessment"),
931  $classname, "");
932  }
933 
934  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
935  {
936  $ref_id = $_GET["calling_test"];
937  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
938 
939  global $___test_express_mode;
940 
941  if (!$_GET['test_express_mode'] && !$___test_express_mode) {
942  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
943  }
944  else {
946  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), $link);
947  }
948  }
949  else
950  {
951  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
952  }
953  }
954 
955  /*
956  * Create the key index numbers for the array of choices
957  *
958  * @return array
959  */
960  function getChoiceKeys()
961  {
962  if (strcmp($_GET["activecommand"], "directfeedback") == 0)
963  {
964  if (is_array($_SESSION["choicekeys"])) $this->choiceKeys = $_SESSION["choicekeys"];
965  }
966  if (!is_array($this->choiceKeys))
967  {
968  $this->choiceKeys = array_keys($this->object->answers);
969  if ($this->object->getShuffle())
970  {
971  $this->choiceKeys = $this->object->pcArrayShuffle($this->choiceKeys);
972  }
973  }
974  $_SESSION["choicekeys"] = $this->choiceKeys;
975  return $this->choiceKeys;
976  }
977 
978  function getSpecificFeedbackOutput($active_id, $pass)
979  {
980  // No return value, this question type supports inline specific feedback.
981  $output = "";
982  return $this->object->prepareTextareaOutput($output, TRUE);
983  }
984 }
985 ?>