ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assImagemapQuestionGUI.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 include_once './Modules/Test/classes/inc.AssessmentConstants.php';
8 
23 class assImagemapQuestionGUI extends assQuestionGUI //implements ilGuiQuestionScoringAdjustable, ilGuiAnswerScoringAdjustable
24 {
25  private $linecolor;
26 
36  public function __construct($id = -1)
37  {
39  include_once './Modules/TestQuestionPool/classes/class.assImagemapQuestion.php';
40  $this->object = new assImagemapQuestion();
41  if ($id >= 0)
42  {
43  $this->object->loadFromDb($id);
44  }
45  $assessmentSetting = new ilSetting("assessment");
46  $this->linecolor = (strlen($assessmentSetting->get("imap_line_color"))) ? "#" . $assessmentSetting->get("imap_line_color") : "#FF0000";
47  }
48 
49  function getCommand($cmd)
50  {
51  if (isset($_POST["imagemap"]) ||
52  isset($_POST["imagemap_x"]) ||
53  isset($_POST["imagemap_y"]))
54  {
55  $this->ctrl->setCmd("getCoords");
56  $cmd = "getCoords";
57  }
58 
59  return $cmd;
60  }
61 
69  public function writePostData($always = false)
70  {
71  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
72  if (!$hasErrors)
73  {
77  $this->saveTaxonomyAssignments();
78  return 0;
79  }
80  return 1;
81  }
82 
83  public function writeAnswerSpecificPostData($always = true)
84  {
85  if (!$_POST['image_delete'])
86  {
87  $this->object->flushAnswers();
88  if (is_array( $_POST['image']['coords']['name'] ))
89  {
90  foreach ($_POST['image']['coords']['name'] as $idx => $name)
91  {
92  if( $this->object->getIsMultipleChoice() && isset($_POST['image']['coords']['points_unchecked']) )
93  {
94  $pointsUnchecked = $_POST['image']['coords']['points_unchecked'][$idx];
95  }
96  else
97  {
98  $pointsUnchecked = 0.0;
99  }
100 
101  $this->object->addAnswer(
102  $name,
103  $_POST['image']['coords']['points'][$idx],
104  $idx,
105  $_POST['image']['coords']['coords'][$idx],
106  $_POST['image']['coords']['shape'][$idx],
107  $pointsUnchecked
108  );
109  }
110  }
111  if (strlen( $_FILES['imagemapfile']['tmp_name'] ))
112  {
113  if ($this->object->getSelfAssessmentEditingMode() && $this->object->getId() < 1)
114  $this->object->createNewQuestion();
115  $this->object->uploadImagemap( $_FILES['imagemapfile']['tmp_name'] );
116  }
117  }
118  }
119 
120  public function writeQuestionSpecificPostData($always = true)
121  {
122  if ($_POST['image_delete'])
123  {
124  $this->object->deleteImage();
125  }
126  else
127  {
128  if (strlen( $_FILES['image']['tmp_name'] ) == 0)
129  {
130  $this->object->setImageFilename( $_POST["image_name"] );
131  }
132  }
133  if (strlen( $_FILES['image']['tmp_name'] ))
134  {
135  if ($this->object->getSelfAssessmentEditingMode() && $this->object->getId() < 1)
136  $this->object->createNewQuestion();
137  $this->object->setImageFilename( $_FILES['image']['name'], $_FILES['image']['tmp_name'] );
138  }
139 
140  $this->object->setIsMultipleChoice($_POST['is_multiple_choice'] == assImagemapQuestion::MODE_MULTIPLE_CHOICE);
141  }
142 
143  public function editQuestion($checkonly = FALSE)
144  {
145  $save = $this->isSaveCommand();
146  $this->getQuestionTemplate();
147 
148  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
149  $form = new ilPropertyFormGUI();
150  $form->setFormAction($this->ctrl->getFormAction($this));
151  $form->setTitle($this->outQuestionType());
152  $form->setMultipart(TRUE);
153  $form->setTableWidth("100%");
154  $form->setId("assimagemap");
155 
156  $this->addBasicQuestionFormProperties( $form );
157  $this->populateQuestionSpecificFormPart( $form );
158  // $this->populateAnswerSpecificFormPart( $form ); Nothing to do here, this line FYI. See notes in method.
159 
160  $this->populateTaxonomyFormSection($form);
161  $this->addQuestionFormCommandButtons($form);
162 
163  $errors = false;
164  if ($save)
165  {
166  $form->setValuesByPost();
167  $errors = !$form->checkInput();
168  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling
169  // and we need this if we don't want to have duplication of backslashes
170  if ($errors) $checkonly = false;
171  }
172 
173  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
174  return $errors;
175  }
176 
178  {
179  return $form; // Nothing to do here since selectable areas are handled in question-specific-form part
180  // due to their immediate dependency to the image. I decide to not break up the interfaces
181  // more just to support this very rare case. tl;dr: See the issue, ignore it.
182  }
183 
185  {
186  // is MultipleChoice?
187  $radioGroup = new ilRadioGroupInputGUI($this->lng->txt( 'tst_imap_qst_mode' ), 'is_multiple_choice');
188  $radioGroup->setValue( $this->object->getIsMultipleChoice() );
189  $modeSingleChoice = new ilRadioOption($this->lng->txt( 'tst_imap_qst_mode_sc'),
191  $modeMultipleChoice = new ilRadioOption($this->lng->txt( 'tst_imap_qst_mode_mc'),
193  $radioGroup->addOption( $modeSingleChoice );
194  $radioGroup->addOption( $modeMultipleChoice );
195  $form->addItem( $radioGroup );
196 
197  // image
198  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapFileInputGUI.php";
199  $image = new ilImagemapFileInputGUI($this->lng->txt( 'image' ), 'image');
200  $image->setPointsUncheckedFieldEnabled( $this->object->getIsMultipleChoice() );
201  $image->setRequired( true );
202 
203  if (strlen( $this->object->getImageFilename() ))
204  {
205  $image->setImage( $this->object->getImagePathWeb() . $this->object->getImageFilename() );
206  $image->setValue( $this->object->getImageFilename() );
207  $image->setAreas( $this->object->getAnswers() );
208  $assessmentSetting = new ilSetting("assessment");
209  $linecolor = (strlen( $assessmentSetting->get( "imap_line_color" )
210  )) ? "\"#" . $assessmentSetting->get( "imap_line_color" ) . "\"" : "\"#FF0000\"";
211  $image->setLineColor( $linecolor );
212  $image->setImagePath( $this->object->getImagePath() );
213  $image->setImagePathWeb( $this->object->getImagePathWeb() );
214  }
215  $form->addItem( $image );
216 
217  // imagemapfile
218  $imagemapfile = new ilFileInputGUI($this->lng->txt( 'add_imagemap' ), 'imagemapfile');
219  $imagemapfile->setRequired( false );
220  $form->addItem( $imagemapfile );
221  return $form;
222  }
223 
224  function addRect()
225  {
226  $this->areaEditor('rect');
227  }
228 
229  function addCircle()
230  {
231  $this->areaEditor('circle');
232  }
233 
234  function addPoly()
235  {
236  $this->areaEditor('poly');
237  }
238 
242  public function saveShape()
243  {
244  $coords = "";
245  switch ($_POST["shape"])
246  {
247  case "rect":
248  $coords = join($_POST['image']['mapcoords'], ",");
249  ilUtil::sendSuccess($this->lng->txt('msg_rect_added'), true);
250  break;
251  case "circle":
252  if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $_POST['image']['mapcoords'][0] . " " . $_POST['image']['mapcoords'][1], $matches))
253  {
254  $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
255  }
256  ilUtil::sendSuccess($this->lng->txt('msg_circle_added'), true);
257  break;
258  case "poly":
259  $coords = join($_POST['image']['mapcoords'], ",");
260  ilUtil::sendSuccess($this->lng->txt('msg_poly_added'), true);
261  break;
262  }
263  $this->object->addAnswer($_POST["shapetitle"], 0, count($this->object->getAnswers()), $coords, $_POST["shape"]);
264  $this->object->saveToDb();
265  $this->ctrl->redirect($this, 'editQuestion');
266  }
267 
268  public function areaEditor($shape = '')
269  {
270  $shape = (strlen($shape)) ? $shape : $_POST['shape'];
271  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
272  $this->getQuestionTemplate();
273  $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_imagemap_question.html", "Modules/TestQuestionPool");
274  $coords = array();
275  if (is_array($_POST['image']['mapcoords']))
276  {
277  foreach ($_POST['image']['mapcoords'] as $value)
278  {
279  array_push($coords, $value);
280  }
281  }
282  if (is_array($_POST['cmd']['areaEditor']['image']))
283  {
284  array_push($coords, $_POST['cmd']['areaEditor']['image'][0] . "," . $_POST['cmd']['areaEditor']['image'][1]);
285  }
286  foreach ($coords as $value)
287  {
288  $this->tpl->setCurrentBlock("hidden");
289  $this->tpl->setVariable("HIDDEN_NAME", 'image[mapcoords][]');
290  $this->tpl->setVariable("HIDDEN_VALUE", $value);
291  $this->tpl->parseCurrentBlock();
292  }
293 
294  $this->tpl->setCurrentBlock("hidden");
295  $this->tpl->setVariable("HIDDEN_NAME", 'shape');
296  $this->tpl->setVariable("HIDDEN_VALUE", $shape);
297  $this->tpl->parseCurrentBlock();
298 
299  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->getImageFilename());
300  foreach ($this->object->answers as $index => $answer)
301  {
302  $preview->addArea($index, $answer->getArea(), $answer->getCoords(), $answer->getAnswertext(), "", "", true, $this->linecolor);
303  }
304  $hidearea = false;
305  $disabled_save = " disabled=\"disabled\"";
306  $c = "";
307  switch ($shape)
308  {
309  case "rect":
310  if (count($coords) == 0)
311  {
312  ilUtil::sendInfo($this->lng->txt("rectangle_click_tl_corner"));
313  }
314  else if (count($coords) == 1)
315  {
316  ilUtil::sendInfo($this->lng->txt("rectangle_click_br_corner"));
317  $preview->addPoint($preview->getAreaCount(), join($coords, ","), TRUE, "blue");
318  }
319  else if (count($coords) == 2)
320  {
321  $c = join($coords, ",");
322  $hidearea = true;
323  $disabled_save = "";
324  }
325  break;
326  case "circle":
327  if (count($coords) == 0)
328  {
329  ilUtil::sendInfo($this->lng->txt("circle_click_center"));
330  }
331  else if (count($coords) == 1)
332  {
333  ilUtil::sendInfo($this->lng->txt("circle_click_circle"));
334  $preview->addPoint($preview->getAreaCount(), join($coords, ","), TRUE, "blue");
335  }
336  else if (count($coords) == 2)
337  {
338  if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $coords[0] . " " . $coords[1], $matches))
339  {
340  $c = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
341  }
342  $hidearea = true;
343  $disabled_save = "";
344  }
345  break;
346  case "poly":
347  if (count($coords) == 0)
348  {
349  ilUtil::sendInfo($this->lng->txt("polygon_click_starting_point"));
350  }
351  else if (count($coords) == 1)
352  {
353  ilUtil::sendInfo($this->lng->txt("polygon_click_next_point"));
354  $preview->addPoint($preview->getAreaCount(), join($coords, ","), TRUE, "blue");
355  }
356  else if (count($coords) > 1)
357  {
358  ilUtil::sendInfo($this->lng->txt("polygon_click_next_or_save"));
359  $disabled_save = "";
360  $c = join($coords, ",");
361  }
362  break;
363  }
364  if (strlen($c))
365  {
366  $preview->addArea($preview->getAreaCount(), $shape, $c, $_POST["shapetitle"], "", "", true, "blue");
367  }
368  $preview->createPreview();
369  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->getImageFilename()) . "?img=" . time();
370  if (!$hidearea)
371  {
372  $this->tpl->setCurrentBlock("maparea");
373  $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
374  $this->tpl->setVariable("IMAGEMAP_NAME", "image");
375  $this->tpl->parseCurrentBlock();
376  }
377  else
378  {
379  $this->tpl->setCurrentBlock("imagearea");
380  $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
381  $this->tpl->setVariable("ALT_IMAGE", $this->lng->txt("imagemap"));
382  $this->tpl->parseCurrentBlock();
383  }
384 
385  if (strlen($_POST['shapetitle']))
386  {
387  $this->tpl->setCurrentBlock("shapetitle");
388  $this->tpl->setVariable("VALUE_SHAPETITLE", $_POST["shapetitle"]);
389  $this->tpl->parseCurrentBlock();
390  }
391 
392  $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap"));
393  $this->tpl->setVariable("TEXT_SHAPETITLE", $this->lng->txt("name"));
394  $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
395  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
396  $this->tpl->setVariable("DISABLED_SAVE", $disabled_save);
397  switch ($shape)
398  {
399  case "rect":
400  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormaction($this, 'addRect'));
401  break;
402  case 'circle':
403  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormaction($this, 'addCircle'));
404  break;
405  case 'poly':
406  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormaction($this, 'addPoly'));
407  break;
408  }
409  }
410 
411  function removeArea()
412  {
413  $this->writePostData(true);
414  $position = key($_POST['cmd']['removeArea']['image']);
415  $this->object->deleteArea($position);
416  $this->editQuestion();
417  }
418 
419  function back()
420  {
421  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
422  $this->ctrl->redirect($this, 'editQuestion');
423  }
424 
425  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
426  {
427  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
428  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
429 
430  #$this->ctrl->setParameterByClass($this->getTargetGuiClass(), "formtimestamp", time());
431  #$formaction = $this->ctrl->getLinkTargetByClass($this->getTargetGuiClass(), "selectImagemapRegion");
432  include_once "./Modules/Test/classes/class.ilObjTest.php";
433  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
434  {
435  $pass = ilObjTest::_getPass($active_id);
436  $info =& $this->object->getSolutionValues($active_id, $pass);
437  }
438  else
439  {
440  $info =& $this->object->getSolutionValues($active_id, NULL);
441  }
442  if (count($info))
443  {
444  if (strcmp($info[0]["value1"], "") != 0)
445  {
446  $formaction .= "&selImage=" . $info[0]["value1"];
447  }
448  }
449  $this->tpl->setVariable("FORMACTION", $formaction);
450  }
451 
466  $active_id,
467  $pass = NULL,
468  $graphicalOutput = FALSE,
469  $result_output = FALSE,
470  $show_question_only = TRUE,
471  $show_feedback = FALSE,
472  $show_correct_solution = FALSE,
473  $show_manual_scoring = FALSE,
474  $show_question_text = TRUE
475  )
476  {
477  $imagepath = $this->object->getImagePathWeb() . $this->object->getImageFilename();
478  $solutions = array();
479  if (($active_id > 0) && (!$show_correct_solution))
480  {
481  include_once "./Modules/Test/classes/class.ilObjTest.php";
482  if ((!$showsolution) && !ilObjTest::_getUsePreviousAnswers($active_id, true))
483  {
484  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
485  }
486  $solutions =& $this->object->getSolutionValues($active_id, $pass);
487  }
488  else
489  {
490  if(!$this->object->getIsMultipleChoice())
491  {
492  $found_index = -1;
493  $max_points = 0;
494  foreach ($this->object->answers as $index => $answer)
495  {
496  if ($answer->getPoints() > $max_points)
497  {
498  $max_points = $answer->getPoints();
499  $found_index = $index;
500  }
501  }
502  array_push($solutions, array("value1" => $found_index));
503  }
504  else
505  {
506  // take the correct solution instead of the user solution
507  foreach($this->object->answers as $index => $answer)
508  {
509  $points_checked = $answer->getPoints();
510  $points_unchecked = $answer->getPointsUnchecked();
511  if($points_checked > $points_unchecked)
512  {
513  if($points_checked > 0)
514  {
515  array_push($solutions, array("value1" => $index));
516  }
517  }
518  }
519  }
520  }
521  $solution_id = -1;
522  if (is_array($solutions))
523  {
524  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
525  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->getImageFilename());
526  foreach ($solutions as $idx => $solution_value)
527  {
528  if (strcmp($solution_value["value1"], "") != 0)
529  {
530  $preview->addArea($solution_value["value1"], $this->object->answers[$solution_value["value1"]]->getArea(), $this->object->answers[$solution_value["value1"]]->getCoords(), $this->object->answers[$solution_value["value1"]]->getAnswertext(), "", "", true, $this->linecolor);
531  $solution_id = $solution_value["value1"];
532  }
533  }
534  $preview->createPreview();
535  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->getImageFilename());
536  }
537 
538  // generate the question output
539  include_once "./Services/UICore/classes/class.ilTemplate.php";
540  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
541  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
542  $questiontext = $this->object->getQuestion();
543  if ($show_question_text==true)
544  {
545  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
546  }
547  $template->setVariable("IMG_SRC", "$imagepath");
548  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
549  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
550  if (($active_id > 0) && (!$show_correct_solution))
551  {
552  if ($graphicalOutput)
553  {
554  // output of ok/not ok icons for user entered solutions
555  $reached_points = $this->object->getReachedPoints($active_id, $pass);
556  if ($reached_points == $this->object->getMaximumPoints())
557  {
558  $template->setCurrentBlock("icon_ok");
559  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.png"));
560  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
561  $template->parseCurrentBlock();
562  }
563  else
564  {
565  $template->setCurrentBlock("icon_ok");
566  if ($reached_points > 0)
567  {
568  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.png"));
569  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
570  }
571  else
572  {
573  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.png"));
574  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
575  }
576  $template->parseCurrentBlock();
577  }
578  }
579  }
580 
581  if ($show_feedback)
582  {
583  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
584  $this->object->getId(), $solution_id
585  );
586 
587  if (strlen($fb))
588  {
589  $template->setCurrentBlock("feedback");
590  $template->setVariable("FEEDBACK", $fb);
591  $template->parseCurrentBlock();
592  }
593  }
594 
595  $questionoutput = $template->get();
596  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
597  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
598  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
599 
600  $solutionoutput = $solutiontemplate->get();
601  if (!$show_question_only)
602  {
603  // get page object output
604  $solutionoutput = '<div class="ilc_question_Standard">'.$solutionoutput."</div>";
605  }
606  return $solutionoutput;
607  }
608 
609  function getPreview($show_question_only = FALSE)
610  {
611  $imagepath = $this->object->getImagePathWeb() . $this->object->getImageFilename();
612  // generate the question output
613  include_once "./Services/UICore/classes/class.ilTemplate.php";
614  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
615  $formaction = "#";
616  foreach ($this->object->answers as $answer_id => $answer)
617  {
618  $template->setCurrentBlock("imagemap_area");
619  $template->setVariable("HREF_AREA", $formaction);
620  $template->setVariable("SHAPE", $answer->getArea());
621  $template->setVariable("COORDS", $answer->getCoords());
622  $template->setVariable("ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
623  $template->setVariable("TITLE", ilUtil::prepareFormOutput($answer->getAnswertext()));
624  $template->parseCurrentBlock();
625  }
626  $questiontext = $this->object->getQuestion();
627  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
628  $template->setVariable("IMG_SRC", "$imagepath");
629  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
630  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
631  $questionoutput = $template->get();
632  if (!$show_question_only)
633  {
634  // get page object output
635  $questionoutput = $this->getILIASPage($questionoutput);
636  }
637  return $questionoutput;
638  }
639 
640  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
641  {
642  // get the solution of the user for the active pass or from the last pass if allowed
643  $user_solution = "";
644  if($this->object->getIsMultipleChoice())
645  {
646  $user_solution = array();
647  }
648  if ($active_id)
649  {
650  $solutions = NULL;
651  include_once "./Modules/Test/classes/class.ilObjTest.php";
652  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
653  {
654  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
655  }
656  $solutions =& $this->object->getSolutionValues($active_id, $pass);
657  foreach ($solutions as $idx => $solution_value)
658  {
659  if($this->object->getIsMultipleChoice())
660  {
661  $user_solution[] = $solution_value["value1"];
662  }
663  else
664  {
665  $user_solution = $solution_value["value1"];
666  }
667  }
668  }
669 
670  $imagepath = $this->object->getImagePathWeb() . $this->object->getImageFilename();
671  if ($active_id)
672  {
673  $solutions = NULL;
674  include_once "./Modules/Test/classes/class.ilObjTest.php";
675  if ((!$showsolution) && !ilObjTest::_getUsePreviousAnswers($active_id, true))
676  {
677  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
678  }
679  $solutions =& $this->object->getSolutionValues($active_id, $pass);
680  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
681  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->getImageFilename());
682  foreach ($solutions as $idx => $solution_value)
683  {
684  if (strcmp($solution_value["value1"], "") != 0)
685  {
686  $preview->addArea($solution_value["value1"], $this->object->answers[$solution_value["value1"]]->getArea(), $this->object->answers[$solution_value["value1"]]->getCoords(), $this->object->answers[$solution_value["value1"]]->getAnswertext(), "", "", true, $this->linecolor);
687  }
688  }
689  $preview->createPreview();
690  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->getImageFilename());
691  }
692 
693  // generate the question output
694  include_once "./Services/UICore/classes/class.ilTemplate.php";
695  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
696  $this->ctrl->setParameterByClass($this->getTargetGuiClass(), "formtimestamp", time());
697  $hrefArea = $this->ctrl->getLinkTargetByClass($this->getTargetGuiClass(), "handleQuestionAction");
698  foreach ($this->object->answers as $answer_id => $answer)
699  {
700  $template->setCurrentBlock("imagemap_area");
701  $parameter = "&amp;selImage=$answer_id";
702  if(is_array($user_solution) && in_array($answer_id, $user_solution))
703  {
704  $parameter = "&amp;remImage=$answer_id";
705  }
706  $template->setVariable("HREF_AREA", $hrefArea . $parameter);
707  $template->setVariable("SHAPE", $answer->getArea());
708  $template->setVariable("COORDS", $answer->getCoords());
709  $template->setVariable("ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
710  $template->setVariable("TITLE", ilUtil::prepareFormOutput($answer->getAnswertext()));
711  $template->parseCurrentBlock();
712  if ($show_feedback)
713  {
714  if(!$this->object->getIsMultipleChoice() && strlen($user_solution) && $user_solution == $answer_id)
715  {
716  $feedback = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
717  $this->object->getId(), $answer_id
718  );
719  if (strlen($feedback))
720  {
721  $template->setCurrentBlock("feedback");
722  $template->setVariable("FEEDBACK", $feedback);
723  $template->parseCurrentBlock();
724  }
725  }
726  }
727  }
728  $questiontext = $this->object->getQuestion();
729  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
730  $template->setVariable("IMG_SRC", "$imagepath");
731  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
732  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
733  $questionoutput = $template->get();
734  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
735  return $pageoutput;
736  }
737 
745  public function setQuestionTabs()
746  {
747  global $rbacsystem, $ilTabs;
748 
749  $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
750  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
751  $q_type = $this->object->getQuestionType();
752 
753  if (strlen($q_type))
754  {
755  $classname = $q_type . "GUI";
756  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
757  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
758  }
759 
760  if ($_GET["q_id"])
761  {
762  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
763  {
764  // edit page
765  $ilTabs->addTarget("edit_page",
766  $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
767  array("edit", "insert", "exec_pg"),
768  "", "", $force_active);
769  }
770 
771  // edit page
772  $ilTabs->addTarget("preview",
773  $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "preview"),
774  array("preview"),
775  "ilAssQuestionPageGUI", "", $force_active);
776  }
777 
778  $force_active = false;
779  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
780  {
781  $url = "";
782  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
783  if (array_key_exists("imagemap_x", $_POST))
784  {
785  $force_active = true;
786  }
787  // edit question properties
788  $ilTabs->addTarget("edit_question",
789  $url,
790  array("editQuestion", "save", "addArea", "addRect", "addCircle", "addPoly",
791  "uploadingImage", "uploadingImagemap", "areaEditor",
792  "removeArea", "saveShape", "saveEdit", "originalSyncForm"),
793  $classname, "", $force_active);
794  }
795 
796  // add tab for question feedback within common class assQuestionGUI
797  $this->addTab_QuestionFeedback($ilTabs);
798 
799  // add tab for question hint within common class assQuestionGUI
800  $this->addTab_QuestionHints($ilTabs);
801 
802  if ($_GET["q_id"])
803  {
804  $ilTabs->addTarget("solution_hint",
805  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
806  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
807  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
808  ),
809  $classname,
810  ""
811  );
812  }
813 
814  // Assessment of questions sub menu entry
815  if ($_GET["q_id"])
816  {
817  $ilTabs->addTarget("statistics",
818  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
819  array("assessment"),
820  $classname, "");
821  }
822 
823  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
824  {
825  $ref_id = $_GET["calling_test"];
826  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
827 
828  global $___test_express_mode;
829 
830  if (!$_GET['test_express_mode'] && !$___test_express_mode) {
831  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
832  }
833  else {
835  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), $link);
836  }
837  }
838  else
839  {
840  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
841  }
842  }
843 
844  function getSpecificFeedbackOutput($active_id, $pass)
845  {
846  $output = '<table class="ilTstSpecificFeedbackTable"><tbody>';
847 
848  foreach($this->object->getAnswers() as $idx => $answer)
849  {
850  $feedback = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
851  $this->object->getId(), $idx
852  );
853 
854  $output .= "<tr><td><b><i>{$answer->getAnswerText()}</i></b></td><td>{$feedback}</td></tr>";
855  }
856 
857  $output .= '</tbody></table>';
858 
859  return $this->object->prepareTextareaOutput($output, TRUE);
860  }
861 
872  {
873  return array();
874  }
875 
886  {
887  return array();
888  }
889 
898  public function getAggregatedAnswersView($relevant_answers)
899  {
900  return ''; //print_r($relevant_answers,true);
901  }
902 }