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