ILIAS  eassessment Revision 61809
 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 
38 {
40 
49  function __construct($id = -1)
50  {
52  include_once "./Modules/TestQuestionPool/classes/class.assMultipleChoice.php";
53  $this->object = new assMultipleChoice();
54  if ($id >= 0)
55  {
56  $this->object->loadFromDb($id);
57  }
58  }
59 
60  function getCommand($cmd)
61  {
62  return $cmd;
63  }
64 
71  function writePostData($always = false)
72  {
73  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
74  if (!$hasErrors)
75  {
76  $this->object->setTitle($_POST["title"]);
77  $this->object->setAuthor($_POST["author"]);
78  $this->object->setComment($_POST["comment"]);
79  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
80  $questiontext = $_POST["question"];
81  $this->object->setQuestion($questiontext);
82  $this->object->setShuffle($_POST["shuffle"]);
83  $this->object->setEstimatedWorkingTime(
84  $_POST["Estimated"]["hh"],
85  $_POST["Estimated"]["mm"],
86  $_POST["Estimated"]["ss"]
87  );
88  if ($this->getSelfAssessmentEditingMode())
89  {
90  $this->object->setNrOfTries($_POST['nr_of_tries']);
91  }
92  $this->object->setMultilineAnswerSetting($_POST["types"]);
93  if (is_array($_POST['choice']['imagename']) && $_POST["types"] == 1)
94  {
95  $this->object->isSingleline = true;
96  ilUtil::sendInfo($this->lng->txt('info_answer_type_change'), true);
97  }
98  else
99  {
100  $this->object->isSingleline = ($_POST["types"] == 0) ? true : false;
101  }
102  $this->object->setThumbSize((strlen($_POST["thumb_size"])) ? $_POST["thumb_size"] : "");
103 
104  // Delete all existing answers and create new answers from the form data
105  $this->object->flushAnswers();
106  if ($this->object->isSingleline)
107  {
108  foreach ($_POST['choice']['answer'] as $index => $answer)
109  {
110  $filename = $_POST['choice']['imagename'][$index];
111  if (strlen($_FILES['choice']['name']['image'][$index]))
112  {
113  // upload image
114  $filename = $this->object->createNewImageFileName($_FILES['choice']['name']['image'][$index]);
115  $upload_result = $this->object->setImageFile($filename, $_FILES['choice']['tmp_name']['image'][$index]);
116  if ($upload_result != 0)
117  {
118  $filename = "";
119  }
120  }
121  $answertext = $answer;
122  $this->object->addAnswer($answertext, $_POST['choice']['points'][$index], $_POST['choice']['points_unchecked'][$index], $index, $filename);
123  }
124  }
125  else
126  {
127  foreach ($_POST['choice']['answer'] as $index => $answer)
128  {
129  $answertext = $answer;
130  $this->object->addAnswer($answertext, $_POST['choice']['points'][$index], $_POST['choice']['points_unchecked'][$index], $index);
131  }
132  }
133  return 0;
134  }
135  else
136  {
137  return 1;
138  }
139  }
140 
146  public function editQuestion($checkonly = FALSE)
147  {
148  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
149  $this->getQuestionTemplate();
150 
151  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
152  $form = new ilPropertyFormGUI();
153  $form->setFormAction($this->ctrl->getFormAction($this));
154  $form->setTitle($this->outQuestionType());
155  $isSingleline = ($this->object->lastChange == 0 && !array_key_exists('types', $_POST)) ? (($this->object->getMultilineAnswerSetting()) ? false : true) : $this->object->isSingleline;
156  if ($checkonly) $isSingleline = ($_POST['types'] == 0) ? true : false;
157  if ($isSingleline)
158  {
159  $form->setMultipart(TRUE);
160  }
161  else
162  {
163  $form->setMultipart(FALSE);
164  }
165  $form->setTableWidth("100%");
166  $form->setId("assmultiplechoice");
167 
168  // title, author, description, question, working time (assessment mode)
169  $this->addBasicQuestionFormProperties($form);
170 
171  // shuffle
172  $shuffle = new ilCheckboxInputGUI($this->lng->txt("shuffle_answers"), "shuffle");
173  $shuffle->setValue(1);
174  $shuffle->setChecked($this->object->getShuffle());
175  $shuffle->setRequired(FALSE);
176  $form->addItem($shuffle);
177 
178  if ($this->object->getId())
179  {
180  $hidden = new ilHiddenInputGUI("", "ID");
181  $hidden->setValue($this->object->getId());
182  $form->addItem($hidden);
183  }
184 
185  if (!$this->getSelfAssessmentEditingMode())
186  {
187  // Answer types
188  $types = new ilSelectInputGUI($this->lng->txt("answer_types"), "types");
189  $types->setRequired(false);
190  $types->setValue(($isSingleline) ? 0 : 1);
191  $types->setOptions(array(
192  0 => $this->lng->txt('answers_singleline'),
193  1 => $this->lng->txt('answers_multiline'),
194  ));
195  $form->addItem($types);
196  }
197 
198  if (($isSingleline) && (!$this->getSelfAssessmentEditingMode()))
199  {
200  // thumb size
201  $thumb_size = new ilNumberInputGUI($this->lng->txt("thumb_size"), "thumb_size");
202  $thumb_size->setMinValue(20);
203  $thumb_size->setDecimals(0);
204  $thumb_size->setSize(6);
205  $thumb_size->setInfo($this->lng->txt('thumb_size_info'));
206  $thumb_size->setValue($this->object->getThumbSize());
207  $thumb_size->setRequired(false);
208  $form->addItem($thumb_size);
209  }
210 
211  // Choices
212  include_once "./Modules/TestQuestionPool/classes/class.ilMultipleChoiceWizardInputGUI.php";
213  $choices = new ilMultipleChoiceWizardInputGUI($this->lng->txt("answers"), "choice");
214  if ($this->getSelfAssessmentEditingMode()) $choices->setHideImages(true);
215  $choices->setRequired(true);
216  $choices->setQuestionObject($this->object);
217  $choices->setSingleline($isSingleline);
218  $choices->setAllowMove(false);
219  if ($this->object->getAnswerCount() == 0) $this->object->addAnswer("", 0, 0, 0);
220  $choices->setValues($this->object->getAnswers());
221  $form->addItem($choices);
222 
223  $this->addQuestionFormCommandButtons($form);
224 
225  $errors = false;
226  //additional characters
227  include_once("./Services/Form/classes/class.ilAdditionalCharactersGUI.php");
228  $form->addItem(new ilAdditionalCharactersGUI());
229  if ($save)
230  {
231  $form->setValuesByPost();
232  $errors = !$form->checkInput();
233  $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
234  if ($errors) $checkonly = false;
235  }
236 
237  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
238  return $errors;
239  }
240 
244  public function uploadchoice()
245  {
246  $this->writePostData(true);
247  $position = key($_POST['cmd']['uploadchoice']);
248  $this->editQuestion();
249  }
250 
254  public function removeimagechoice()
255  {
256  $this->writePostData(true);
257  $position = key($_POST['cmd']['removeimagechoice']);
258  $filename = $_POST['choice']['imagename'][$position];
259  $this->object->removeAnswerImage($position);
260  $this->editQuestion();
261  }
262 
266  public function addchoice()
267  {
268  $this->writePostData(true);
269  $position = key($_POST['cmd']['addchoice']);
270  $this->object->addAnswer("", 0, 0, $position+1);
271  $this->editQuestion();
272  }
273 
277  public function removechoice()
278  {
279  $this->writePostData(true);
280  $position = key($_POST['cmd']['removechoice']);
281  $this->object->deleteAnswer($position);
282  $this->editQuestion();
283  }
284 
285  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
286  {
287  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
288  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
289  $this->tpl->setVariable("FORMACTION", $formaction);
290  }
291 
306  $active_id,
307  $pass = NULL,
308  $graphicalOutput = FALSE,
309  $result_output = FALSE,
310  $show_question_only = TRUE,
311  $show_feedback = FALSE,
312  $show_correct_solution = FALSE,
313  $show_manual_scoring = FALSE
314  )
315  {
316  // shuffle output
317  $keys = $this->getChoiceKeys();
318 
319  // get the solution of the user for the active pass or from the last pass if allowed
320  $user_solution = array();
321  if (($active_id > 0) && (!$show_correct_solution))
322  {
323  $solutions =& $this->object->getSolutionValues($active_id, $pass);
324  foreach ($solutions as $idx => $solution_value)
325  {
326  array_push($user_solution, $solution_value["value1"]);
327  }
328  }
329  else
330  {
331  // take the correct solution instead of the user solution
332  foreach ($this->object->answers as $index => $answer)
333  {
334  $points_checked = $answer->getPointsChecked();
335  $points_unchecked = $answer->getPointsUnchecked();
336  if ($points_checked > $points_unchecked)
337  {
338  if ($points_checked > 0)
339  {
340  array_push($user_solution, $index);
341  }
342  }
343  }
344  }
345 
346  // generate the question output
347  include_once "./classes/class.ilTemplate.php";
348  $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
349  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
350  foreach ($keys as $answer_id)
351  {
352  $answer = $this->object->answers[$answer_id];
353  if (($active_id > 0) && (!$show_correct_solution))
354  {
355  if ($graphicalOutput)
356  {
357  // output of ok/not ok icons for user entered solutions
358  $ok = FALSE;
359  $checked = FALSE;
360  foreach ($user_solution as $mc_solution)
361  {
362  if (strcmp($mc_solution, $answer_id) == 0)
363  {
364  $checked = TRUE;
365  }
366  }
367  if ($checked)
368  {
369  if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
370  {
371  $ok = TRUE;
372  }
373  else
374  {
375  $ok = FALSE;
376  }
377  }
378  else
379  {
380  if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
381  {
382  $ok = FALSE;
383  }
384  else
385  {
386  $ok = TRUE;
387  }
388  }
389  if ($ok)
390  {
391  $template->setCurrentBlock("icon_ok");
392  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
393  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
394  $template->parseCurrentBlock();
395  }
396  else
397  {
398  $template->setCurrentBlock("icon_ok");
399  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
400  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
401  $template->parseCurrentBlock();
402  }
403  }
404  }
405  if (strlen($answer->getImage()))
406  {
407  $template->setCurrentBlock("answer_image");
408  if ($this->object->getThumbSize())
409  {
410  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
411  }
412  else
413  {
414  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
415  }
416  $alt = $answer->getImage();
417  if (strlen($answer->getAnswertext()))
418  {
419  $alt = $answer->getAnswertext();
420  }
421  $alt = preg_replace("/<[^>]*?>/", "", $alt);
422  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
423  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
424  $template->parseCurrentBlock();
425  }
426  if ($show_feedback)
427  {
428  foreach ($user_solution as $mc_solution)
429  {
430  if (strcmp($mc_solution, $answer_id) == 0)
431  {
432  $fb = $this->object->getFeedbackSingleAnswer($answer_id);
433  if (strlen($fb))
434  {
435  $template->setCurrentBlock("feedback");
436  $template->setVariable("FEEDBACK", $fb);
437  $template->parseCurrentBlock();
438  }
439  }
440  }
441  }
442  $template->setCurrentBlock("answer_row");
443  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
444  $checked = FALSE;
445  if ($result_output)
446  {
447  $pointschecked = $this->object->answers[$answer_id]->getPointsChecked();
448  $pointsunchecked = $this->object->answers[$answer_id]->getPointsUnchecked();
449  $resulttextchecked = ($pointschecked == 1) || ($pointschecked == -1) ? "%s " . $this->lng->txt("point") : "%s " . $this->lng->txt("points");
450  $resulttextunchecked = ($pointsunchecked == 1) || ($pointsunchecked == -1) ? "%s " . $this->lng->txt("point") : "%s " . $this->lng->txt("points");
451  $template->setVariable("RESULT_OUTPUT", sprintf("(" . $this->lng->txt("checkbox_checked") . " = $resulttextchecked, " . $this->lng->txt("checkbox_unchecked") . " = $resulttextunchecked)", $pointschecked, $pointsunchecked));
452  }
453  foreach ($user_solution as $mc_solution)
454  {
455  if (strcmp($mc_solution, $answer_id) == 0)
456  {
457  $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_checked.gif")));
458  $template->setVariable("SOLUTION_ALT", $this->lng->txt("checked"));
459  $checked = TRUE;
460  }
461  }
462  if (!$checked)
463  {
464  $template->setVariable("SOLUTION_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.gif")));
465  $template->setVariable("SOLUTION_ALT", $this->lng->txt("unchecked"));
466  }
467  $template->parseCurrentBlock();
468  }
469  $questiontext = $this->object->getQuestion();
470  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
471  $questionoutput = $template->get();
472  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
473  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
474  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
475 
476  $solutionoutput = $solutiontemplate->get();
477  if (!$show_question_only)
478  {
479  // get page object output
480  $solutionoutput = $this->getILIASPage($solutionoutput);
481  }
482  return $solutionoutput;
483  }
484 
485  function getPreview($show_question_only = FALSE)
486  {
487  // shuffle output
488  $keys = $this->getChoiceKeys();
489 
490  // generate the question output
491  include_once "./classes/class.ilTemplate.php";
492  $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
493  foreach ($keys as $answer_id)
494  {
495  $answer = $this->object->answers[$answer_id];
496  if (strlen($answer->getImage()))
497  {
498  if ($this->object->getThumbSize())
499  {
500  $template->setCurrentBlock("preview");
501  $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
502  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
503  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
504  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
505  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
506  $alt = $answer->getImage();
507  if (strlen($answer->getAnswertext()))
508  {
509  $alt = $answer->getAnswertext();
510  }
511  $alt = preg_replace("/<[^>]*?>/", "", $alt);
512  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
513  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
514  $template->parseCurrentBlock();
515  }
516  else
517  {
518  $template->setCurrentBlock("answer_image");
519  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
520  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
521  $alt = $answer->getImage();
522  if (strlen($answer->getAnswertext()))
523  {
524  $alt = $answer->getAnswertext();
525  }
526  $alt = preg_replace("/<[^>]*?>/", "", $alt);
527  $template->setVariable("ATTR", $attr);
528  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
529  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
530  $template->parseCurrentBlock();
531  }
532  }
533  $template->setCurrentBlock("answer_row");
534  $template->setVariable("ANSWER_ID", $answer_id);
535  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
536  $template->parseCurrentBlock();
537  }
538  $questiontext = $this->object->getQuestion();
539  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
540  $questionoutput = $template->get();
541  if (!$show_question_only)
542  {
543  // get page object output
544  $questionoutput = $this->getILIASPage($questionoutput);
545  }
546  return $questionoutput;
547  }
548 
549  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
550  {
551  // shuffle output
552  $keys = $this->getChoiceKeys();
553 
554  // get the solution of the user for the active pass or from the last pass if allowed
555  $user_solution = array();
556  if ($active_id)
557  {
558  $solutions = NULL;
559  include_once "./Modules/Test/classes/class.ilObjTest.php";
560  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
561  {
562  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
563  }
564  $solutions =& $this->object->getSolutionValues($active_id, $pass);
565  foreach ($solutions as $idx => $solution_value)
566  {
567  array_push($user_solution, $solution_value["value1"]);
568  }
569  }
570  // generate the question output
571  include_once "./classes/class.ilTemplate.php";
572  $template = new ilTemplate("tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
573  foreach ($keys as $answer_id)
574  {
575  $answer = $this->object->answers[$answer_id];
576  if (strlen($answer->getImage()))
577  {
578  if ($this->object->getThumbSize())
579  {
580  $template->setCurrentBlock("preview");
581  $template->setVariable("URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
582  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
583  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
584  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $answer->getImage());
585  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
586  $alt = $answer->getImage();
587  if (strlen($answer->getAnswertext()))
588  {
589  $alt = $answer->getAnswertext();
590  }
591  $alt = preg_replace("/<[^>]*?>/", "", $alt);
592  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
593  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
594  $template->parseCurrentBlock();
595  }
596  else
597  {
598  $template->setCurrentBlock("answer_image");
599  $template->setVariable("ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
600  list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
601  $alt = $answer->getImage();
602  if (strlen($answer->getAnswertext()))
603  {
604  $alt = $answer->getAnswertext();
605  }
606  $alt = preg_replace("/<[^>]*?>/", "", $alt);
607  $template->setVariable("ATTR", $attr);
608  $template->setVariable("ANSWER_IMAGE_ALT", ilUtil::prepareFormOutput($alt));
609  $template->setVariable("ANSWER_IMAGE_TITLE", ilUtil::prepareFormOutput($alt));
610  $template->parseCurrentBlock();
611  }
612  }
613 
614  foreach ($user_solution as $mc_solution)
615  {
616  if (strcmp($mc_solution, $answer_id) == 0)
617  {
618  if ($show_feedback)
619  {
620  $feedback = $this->object->getFeedbackSingleAnswer($answer_id);
621  if (strlen($feedback))
622  {
623  $template->setCurrentBlock("feedback");
624  $template->setVariable("FEEDBACK", $feedback);
625  $template->parseCurrentBlock();
626  }
627  }
628  }
629  }
630 
631  $template->setCurrentBlock("answer_row");
632  $template->setVariable("ANSWER_ID", $answer_id);
633  $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
634  foreach ($user_solution as $mc_solution)
635  {
636  if (strcmp($mc_solution, $answer_id) == 0)
637  {
638  $template->setVariable("CHECKED_ANSWER", " checked=\"checked\"");
639  }
640  }
641  $template->parseCurrentBlock();
642  }
643  $questiontext = $this->object->getQuestion();
644  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
645  $questionoutput = $template->get();
646  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
647  return $pageoutput;
648  }
649 
655  function saveFeedback()
656  {
657  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
658  $errors = $this->feedback(true);
659  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
660  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
661  foreach ($this->object->answers as $index => $answer)
662  {
663  $this->object->saveFeedbackSingleAnswer($index, $_POST["feedback_answer_$index"]);
664  }
665  $this->object->cleanupMediaObjectUsage();
667  }
668 
674  function feedback($checkonly = false)
675  {
676  $save = (strcmp($this->ctrl->getCmd(), "saveFeedback") == 0) ? TRUE : FALSE;
677  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
678  $form = new ilPropertyFormGUI();
679  $form->setFormAction($this->ctrl->getFormAction($this));
680  $form->setTitle($this->lng->txt('feedback_answers'));
681  $form->setTableWidth("100%");
682  $form->setId("feedback");
683 
684  $complete = new ilTextAreaInputGUI($this->lng->txt("feedback_complete_solution"), "feedback_complete");
685  $complete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
686  $complete->setRequired(false);
687  $complete->setRows(10);
688  $complete->setCols(80);
689  if (!$this->getPreventRteUsage())
690  {
691  $complete->setUseRte(true);
692  }
693  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
694  $complete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
695  $complete->addPlugin("latex");
696  $complete->addButton("latex");
697  $complete->addButton("pastelatex");
698  $complete->setRTESupport($this->object->getId(), "qpl", "assessment");
699  $form->addItem($complete);
700 
701  $incomplete = new ilTextAreaInputGUI($this->lng->txt("feedback_incomplete_solution"), "feedback_incomplete");
702  $incomplete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
703  $incomplete->setRequired(false);
704  $incomplete->setRows(10);
705  $incomplete->setCols(80);
706  if (!$this->getPreventRteUsage())
707  {
708  $incomplete->setUseRte(true);
709  }
710  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
711  $incomplete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
712  $incomplete->addPlugin("latex");
713  $incomplete->addButton("latex");
714  $incomplete->addButton("pastelatex");
715  $incomplete->setRTESupport($this->object->getId(), "qpl", "assessment");
716  $form->addItem($incomplete);
717 
718  if (!$this->getSelfAssessmentEditingMode())
719  {
720  foreach ($this->object->answers as $index => $answer)
721  {
722  $answerobj = new ilTextAreaInputGUI($this->object->prepareTextareaOutput($answer->getAnswertext(), true), "feedback_answer_$index");
723  $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
724  $answerobj->setRequired(false);
725  $answerobj->setRows(10);
726  $answerobj->setCols(80);
727  $answerobj->setUseRte(true);
728  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
729  $answerobj->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
730  $answerobj->addPlugin("latex");
731  $answerobj->addButton("latex");
732  $answerobj->addButton("pastelatex");
733  $answerobj->setRTESupport($this->object->getId(), "qpl", "assessment");
734  $form->addItem($answerobj);
735  }
736  }
737 
738  global $ilAccess;
739  if ($ilAccess->checkAccess("write", "", $_GET['ref_id']) || $this->getSelfAssessmentEditingMode())
740  {
741  $form->addCommandButton("saveFeedback", $this->lng->txt("save"));
742  }
743  if ($save)
744  {
745  $form->setValuesByPost();
746  $errors = !$form->checkInput();
747  $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
748  }
749  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
750  return $errors;
751  }
752 
758  function setQuestionTabs()
759  {
760  global $rbacsystem, $ilTabs;
761 
762  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
763  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
764  $q_type = $this->object->getQuestionType();
765 
766  if (strlen($q_type))
767  {
768  $classname = $q_type . "GUI";
769  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
770  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
771  }
772 
773  if ($_GET["q_id"])
774  {
775  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
776  {
777  // edit page
778  $ilTabs->addTarget("edit_content",
779  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
780  array("edit", "insert", "exec_pg"),
781  "", "", $force_active);
782  }
783 
784  // edit page
785  $ilTabs->addTarget("preview",
786  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
787  array("preview"),
788  "ilPageObjectGUI", "", $force_active);
789  }
790  $force_active = false;
791  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
792  {
793  $url = "";
794  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
795  $force_active = false;
796  // edit question properties
797  $ilTabs->addTarget("edit_properties",
798  $url,
799  array("editQuestion", "save", "saveEdit", "addchoice", "removechoice", "removeimagechoice", "uploadchoice", "originalSyncForm"),
800  $classname, "", $force_active);
801  }
802 
803  if ($_GET["q_id"])
804  {
805  $ilTabs->addTarget("feedback",
806  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
807  array("feedback", "saveFeedback"),
808  $classname, "");
809  }
810 
811  if ($_GET["q_id"])
812  {
813  $ilTabs->addTarget("solution_hint",
814  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
815  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
816  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
817  ),
818  $classname,
819  ""
820  );
821  }
822 
823  // Assessment of questions sub menu entry
824  if ($_GET["q_id"])
825  {
826  $ilTabs->addTarget("statistics",
827  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
828  array("assessment"),
829  $classname, "");
830  }
831 
832  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
833  {
834  $ref_id = $_GET["calling_test"];
835  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
836  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
837  }
838  else
839  {
840  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
841  }
842  }
843 
844  /*
845  * Create the key index numbers for the array of choices
846  *
847  * @return array
848  */
849  function getChoiceKeys()
850  {
851  if (strcmp($_GET["activecommand"], "directfeedback") == 0)
852  {
853  if (is_array($_SESSION["choicekeys"])) $this->choiceKeys = $_SESSION["choicekeys"];
854  }
855  if (!is_array($this->choiceKeys))
856  {
857  $this->choiceKeys = array_keys($this->object->answers);
858  if ($this->object->getShuffle())
859  {
860  $this->choiceKeys = $this->object->pcArrayShuffle($this->choiceKeys);
861  }
862  }
863  $_SESSION["choicekeys"] = $this->choiceKeys;
864  return $this->choiceKeys;
865  }
866 }
867 ?>