ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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 require_once 'Services/WebAccessChecker/classes/class.ilWACSignedPath.php';
9 
25 {
26  private $linecolor;
27 
37  public function __construct($id = -1)
38  {
39  parent::__construct();
40  include_once './Modules/TestQuestionPool/classes/class.assImagemapQuestion.php';
41  $this->object = new assImagemapQuestion();
42  if ($id >= 0)
43  {
44  $this->object->loadFromDb($id);
45  }
46  $assessmentSetting = new ilSetting("assessment");
47  $this->linecolor = (strlen($assessmentSetting->get("imap_line_color"))) ? "#" . $assessmentSetting->get("imap_line_color") : "#FF0000";
48  }
49 
50  function getCommand($cmd)
51  {
52  if (isset($_POST["imagemap"]) ||
53  isset($_POST["imagemap_x"]) ||
54  isset($_POST["imagemap_y"]))
55  {
56  $this->ctrl->setCmd("getCoords");
57  $cmd = "getCoords";
58  }
59 
60  return $cmd;
61  }
62 
63  protected function deleteImage()
64  {
65  $this->writePostData(true);
66  $this->object->saveToDb();
67  $this->ctrl->redirect($this, 'editQuestion');
68  }
69 
77  public function writePostData($always = false)
78  {
79  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
80  if (!$hasErrors)
81  {
82  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
86  $this->saveTaxonomyAssignments();
87  return 0;
88  }
89  return 1;
90  }
91 
93  {
94  if ($this->ctrl->getCmd() != 'deleteImage')
95  {
96  $this->object->flushAnswers();
97  if (is_array( $_POST['image']['coords']['name'] ))
98  {
99  foreach ($_POST['image']['coords']['name'] as $idx => $name)
100  {
101  if( $this->object->getIsMultipleChoice() && isset($_POST['image']['coords']['points_unchecked']) )
102  {
103  $pointsUnchecked = $_POST['image']['coords']['points_unchecked'][$idx];
104  }
105  else
106  {
107  $pointsUnchecked = 0.0;
108  }
109 
110  $this->object->addAnswer(
111  $name,
112  $_POST['image']['coords']['points'][$idx],
113  $idx,
114  $_POST['image']['coords']['coords'][$idx],
115  $_POST['image']['coords']['shape'][$idx],
116  $pointsUnchecked
117  );
118  }
119  }
120  if (strlen( $_FILES['imagemapfile']['tmp_name'] ))
121  {
122  if ($this->object->getSelfAssessmentEditingMode() && $this->object->getId() < 1)
123  $this->object->createNewQuestion();
124  $this->object->uploadImagemap( $_FILES['imagemapfile']['tmp_name'] );
125  }
126  }
127  }
128 
130  {
131  if ($this->ctrl->getCmd() == 'deleteImage')
132  {
133  $this->object->deleteImage();
134  }
135  else
136  {
137  if (strlen( $_FILES['image']['tmp_name'] ) == 0)
138  {
139  $this->object->setImageFilename( $_POST["image_name"] );
140  }
141  }
142  if (strlen( $_FILES['image']['tmp_name'] ))
143  {
144  if ($this->object->getSelfAssessmentEditingMode() && $this->object->getId() < 1)
145  $this->object->createNewQuestion();
146  $this->object->setImageFilename( $_FILES['image']['name'], $_FILES['image']['tmp_name'] );
147  }
148 
149  $this->object->setIsMultipleChoice($_POST['is_multiple_choice'] == assImagemapQuestion::MODE_MULTIPLE_CHOICE);
150  }
151 
152  public function editQuestion($checkonly = FALSE)
153  {
154  $save = $this->isSaveCommand();
155  $this->getQuestionTemplate();
156 
157  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
158  $form = new ilPropertyFormGUI();
159  $form->setFormAction($this->ctrl->getFormAction($this));
160  $form->setTitle($this->outQuestionType());
161  $form->setMultipart(TRUE);
162  $form->setTableWidth("100%");
163  $form->setId("assimagemap");
164 
165  $this->addBasicQuestionFormProperties( $form );
166  $this->populateQuestionSpecificFormPart( $form );
167  // $this->populateAnswerSpecificFormPart( $form ); Nothing to do here, this line FYI. See notes in method.
168 
169  $this->populateTaxonomyFormSection($form);
170  $this->addQuestionFormCommandButtons($form);
171 
172  $errors = false;
173  if ($save)
174  {
175  $form->setValuesByPost();
176  $errors = !$form->checkInput();
177  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling
178  // and we need this if we don't want to have duplication of backslashes
179  if ($errors) $checkonly = false;
180  }
181 
182  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
183  return $errors;
184  }
185 
187  {
188  return $form; // Nothing to do here since selectable areas are handled in question-specific-form part
189  // due to their immediate dependency to the image. I decide to not break up the interfaces
190  // more just to support this very rare case. tl;dr: See the issue, ignore it.
191  }
192 
194  {
195  // is MultipleChoice?
196  $radioGroup = new ilRadioGroupInputGUI($this->lng->txt( 'tst_imap_qst_mode' ), 'is_multiple_choice');
197  $radioGroup->setValue( $this->object->getIsMultipleChoice() );
198  $modeSingleChoice = new ilRadioOption($this->lng->txt( 'tst_imap_qst_mode_sc'),
200  $modeMultipleChoice = new ilRadioOption($this->lng->txt( 'tst_imap_qst_mode_mc'),
202  $radioGroup->addOption( $modeSingleChoice );
203  $radioGroup->addOption( $modeMultipleChoice );
204  $form->addItem( $radioGroup );
205 
206  // image
207  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapFileInputGUI.php";
208  $image = new ilImagemapFileInputGUI($this->lng->txt( 'image' ), 'image');
209  $image->setPointsUncheckedFieldEnabled( $this->object->getIsMultipleChoice() );
210  $image->setRequired( true );
211 
212  if (strlen( $this->object->getImageFilename() ))
213  {
214  $image->setImage( $this->object->getImagePathWeb() . $this->object->getImageFilename() );
215  $image->setValue( $this->object->getImageFilename() );
216  $image->setAreas( $this->object->getAnswers() );
217  $assessmentSetting = new ilSetting("assessment");
218  $linecolor = (strlen( $assessmentSetting->get( "imap_line_color" )
219  )) ? "\"#" . $assessmentSetting->get( "imap_line_color" ) . "\"" : "\"#FF0000\"";
220  $image->setLineColor( $linecolor );
221  $image->setImagePath( $this->object->getImagePath() );
222  $image->setImagePathWeb( $this->object->getImagePathWeb() );
223  }
224  $form->addItem( $image );
225 
226  // imagemapfile
227  $imagemapfile = new ilFileInputGUI($this->lng->txt( 'add_imagemap' ), 'imagemapfile');
228  $imagemapfile->setRequired( false );
229  $form->addItem( $imagemapfile );
230  return $form;
231  }
232 
233  function addRect()
234  {
235  $this->areaEditor('rect');
236  }
237 
238  function addCircle()
239  {
240  $this->areaEditor('circle');
241  }
242 
243  function addPoly()
244  {
245  $this->areaEditor('poly');
246  }
247 
251  public function saveShape()
252  {
253  $coords = "";
254  switch ($_POST["shape"])
255  {
256  case "rect":
257  $coords = join($_POST['image']['mapcoords'], ",");
258  ilUtil::sendSuccess($this->lng->txt('msg_rect_added'), true);
259  break;
260  case "circle":
261  if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $_POST['image']['mapcoords'][0] . " " . $_POST['image']['mapcoords'][1], $matches))
262  {
263  $coords = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
264  }
265  ilUtil::sendSuccess($this->lng->txt('msg_circle_added'), true);
266  break;
267  case "poly":
268  $coords = join($_POST['image']['mapcoords'], ",");
269  ilUtil::sendSuccess($this->lng->txt('msg_poly_added'), true);
270  break;
271  }
272  $this->object->addAnswer($_POST["shapetitle"], 0, count($this->object->getAnswers()), $coords, $_POST["shape"]);
273  $this->object->saveToDb();
274  $this->ctrl->redirect($this, 'editQuestion');
275  }
276 
277  public function areaEditor($shape = '')
278  {
279  $shape = (strlen($shape)) ? $shape : $_POST['shape'];
280  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
281  $this->getQuestionTemplate();
282  $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_imagemap_question.html", "Modules/TestQuestionPool");
283  $coords = array();
284  if (is_array($_POST['image']['mapcoords']))
285  {
286  foreach ($_POST['image']['mapcoords'] as $value)
287  {
288  array_push($coords, $value);
289  }
290  }
291  if (is_array($_POST['cmd']['areaEditor']['image']))
292  {
293  array_push($coords, $_POST['cmd']['areaEditor']['image'][0] . "," . $_POST['cmd']['areaEditor']['image'][1]);
294  }
295  foreach ($coords as $value)
296  {
297  $this->tpl->setCurrentBlock("hidden");
298  $this->tpl->setVariable("HIDDEN_NAME", 'image[mapcoords][]');
299  $this->tpl->setVariable("HIDDEN_VALUE", $value);
300  $this->tpl->parseCurrentBlock();
301  }
302 
303  $this->tpl->setCurrentBlock("hidden");
304  $this->tpl->setVariable("HIDDEN_NAME", 'shape');
305  $this->tpl->setVariable("HIDDEN_VALUE", $shape);
306  $this->tpl->parseCurrentBlock();
307 
308  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->getImageFilename());
309  foreach ($this->object->answers as $index => $answer)
310  {
311  $preview->addArea($index, $answer->getArea(), $answer->getCoords(), $answer->getAnswertext(), "", "", true, $this->linecolor);
312  }
313  $hidearea = false;
314  $disabled_save = " disabled=\"disabled\"";
315  $c = "";
316  switch ($shape)
317  {
318  case "rect":
319  if (count($coords) == 0)
320  {
321  ilUtil::sendInfo($this->lng->txt("rectangle_click_tl_corner"));
322  }
323  else if (count($coords) == 1)
324  {
325  ilUtil::sendInfo($this->lng->txt("rectangle_click_br_corner"));
326  $preview->addPoint($preview->getAreaCount(), join($coords, ","), TRUE, "blue");
327  }
328  else if (count($coords) == 2)
329  {
330  $c = join($coords, ",");
331  $hidearea = true;
332  $disabled_save = "";
333  }
334  break;
335  case "circle":
336  if (count($coords) == 0)
337  {
338  ilUtil::sendInfo($this->lng->txt("circle_click_center"));
339  }
340  else if (count($coords) == 1)
341  {
342  ilUtil::sendInfo($this->lng->txt("circle_click_circle"));
343  $preview->addPoint($preview->getAreaCount(), join($coords, ","), TRUE, "blue");
344  }
345  else if (count($coords) == 2)
346  {
347  if (preg_match("/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $coords[0] . " " . $coords[1], $matches))
348  {
349  $c = "$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
350  }
351  $hidearea = true;
352  $disabled_save = "";
353  }
354  break;
355  case "poly":
356  if (count($coords) == 0)
357  {
358  ilUtil::sendInfo($this->lng->txt("polygon_click_starting_point"));
359  }
360  else if (count($coords) == 1)
361  {
362  ilUtil::sendInfo($this->lng->txt("polygon_click_next_point"));
363  $preview->addPoint($preview->getAreaCount(), join($coords, ","), TRUE, "blue");
364  }
365  else if (count($coords) > 1)
366  {
367  ilUtil::sendInfo($this->lng->txt("polygon_click_next_or_save"));
368  $disabled_save = "";
369  $c = join($coords, ",");
370  }
371  break;
372  }
373  if (strlen($c))
374  {
375  $preview->addArea($preview->getAreaCount(), $shape, $c, $_POST["shapetitle"], "", "", true, "blue");
376  }
377  $preview->createPreview();
378  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->getImageFilename()) . "?img=" . time();
379  if (!$hidearea)
380  {
381  $this->tpl->setCurrentBlock("maparea");
382  $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
383  $this->tpl->setVariable("IMAGEMAP_NAME", "image");
384  $this->tpl->parseCurrentBlock();
385  }
386  else
387  {
388  $this->tpl->setCurrentBlock("imagearea");
389  $this->tpl->setVariable("IMAGE_SOURCE", "$imagepath");
390  $this->tpl->setVariable("ALT_IMAGE", $this->lng->txt("imagemap"));
391  $this->tpl->parseCurrentBlock();
392  }
393 
394  if (strlen($_POST['shapetitle']))
395  {
396  $this->tpl->setCurrentBlock("shapetitle");
397  $this->tpl->setVariable("VALUE_SHAPETITLE", $_POST["shapetitle"]);
398  $this->tpl->parseCurrentBlock();
399  }
400 
401  $this->tpl->setVariable("TEXT_IMAGEMAP", $this->lng->txt("imagemap"));
402  $this->tpl->setVariable("TEXT_SHAPETITLE", $this->lng->txt("ass_imap_hint"));
403  $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
404  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
405  $this->tpl->setVariable("DISABLED_SAVE", $disabled_save);
406  switch ($shape)
407  {
408  case "rect":
409  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormaction($this, 'addRect'));
410  break;
411  case 'circle':
412  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormaction($this, 'addCircle'));
413  break;
414  case 'poly':
415  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormaction($this, 'addPoly'));
416  break;
417  }
418  }
419 
420  function removeArea()
421  {
422  $this->writePostData(true);
423  $position = key($_POST['cmd']['removeArea']['image']);
424  $this->object->deleteArea($position);
425  $this->editQuestion();
426  }
427 
428  function back()
429  {
430  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
431  $this->ctrl->redirect($this, 'editQuestion');
432  }
433 
434  // hey: prevPassSolutions - max solution pass determinations allready done, pass passed for sure
435  // hey: fixedIdentifier - changed access to passed param (lower-/uppercase issues)
436  protected function completeTestOutputFormAction($formAction, $active_id, $pass)
437  {
438  #require_once './Modules/Test/classes/class.ilObjTest.php';
439  #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
440  #{
441  # $pass = ilObjTest::_getPass($active_id);
442  # $info = $this->object->getUserSolutionPreferingIntermediate($active_id, $pass);
443  #}
444  #else
445  #{
446  # $info = $this->object->getUserSolutionPreferingIntermediate($active_id, NULL);
447  #}
448 
449  $info = $this->getTestOutputSolutions($active_id, $pass);
450 
451  if (count($info))
452  {
453  if (strcmp($info[0]["value1"], "") != 0)
454  {
455  $formAction .= "&selImage=" . $info[0]["value1"];
456  }
457  }
458 
459  return $formAction;
460  }
461  // hey.
462  // hey.
463 
478  $active_id,
479  $pass = NULL,
480  $graphicalOutput = FALSE,
481  $result_output = FALSE,
482  $show_question_only = TRUE,
483  $show_feedback = FALSE,
484  $show_correct_solution = FALSE,
485  $show_manual_scoring = FALSE,
486  $show_question_text = TRUE
487  )
488  {
489  $imagepath = $this->object->getImagePathWeb() . $this->object->getImageFilename();
490  $solutions = array();
491  if (($active_id > 0) && (!$show_correct_solution))
492  {
493  include_once "./Modules/Test/classes/class.ilObjTest.php";
494  if ((!$showsolution) && !ilObjTest::_getUsePreviousAnswers($active_id, true))
495  {
496  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
497  }
498  $solutions =& $this->object->getSolutionValues($active_id, $pass);
499  }
500  else
501  {
502  if(!$this->object->getIsMultipleChoice())
503  {
504  $found_index = -1;
505  $max_points = 0;
506  foreach ($this->object->answers as $index => $answer)
507  {
508  if ($answer->getPoints() > $max_points)
509  {
510  $max_points = $answer->getPoints();
511  $found_index = $index;
512  }
513  }
514  array_push($solutions, array("value1" => $found_index));
515  }
516  else
517  {
518  // take the correct solution instead of the user solution
519  foreach($this->object->answers as $index => $answer)
520  {
521  $points_checked = $answer->getPoints();
522  $points_unchecked = $answer->getPointsUnchecked();
523  if($points_checked > $points_unchecked)
524  {
525  if($points_checked > 0)
526  {
527  array_push($solutions, array("value1" => $index));
528  }
529  }
530  }
531  }
532  }
533  $solution_id = -1;
534  if (is_array($solutions))
535  {
536  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
537  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->getImageFilename());
538  foreach ($solutions as $idx => $solution_value)
539  {
540  if (strcmp($solution_value["value1"], "") != 0)
541  {
542  $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);
543  $solution_id = $solution_value["value1"];
544  }
545  }
546  $preview->createPreview();
547  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->getImageFilename());
548  }
549 
550  // generate the question output
551  include_once "./Services/UICore/classes/class.ilTemplate.php";
552  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
553  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
554  $questiontext = $this->object->getQuestion();
555  if ($show_question_text==true)
556  {
557  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
558  }
559 
560  $template->setVariable("IMG_SRC", ilWACSignedPath::signFile($imagepath));
561  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
562  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
563  if (($active_id > 0) && (!$show_correct_solution))
564  {
565  if ($graphicalOutput)
566  {
567  // output of ok/not ok icons for user entered solutions
568  $reached_points = $this->object->getReachedPoints($active_id, $pass);
569  if ($reached_points == $this->object->getMaximumPoints())
570  {
571  $template->setCurrentBlock("icon_ok");
572  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
573  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
574  $template->parseCurrentBlock();
575  }
576  else
577  {
578  $template->setCurrentBlock("icon_ok");
579  if ($reached_points > 0)
580  {
581  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.svg"));
582  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
583  }
584  else
585  {
586  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
587  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
588  }
589  $template->parseCurrentBlock();
590  }
591  }
592  }
593 
594  if ($show_feedback)
595  {
596  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
597  $this->object->getId(), $solution_id
598  );
599 
600  if (strlen($fb))
601  {
602  $template->setCurrentBlock("feedback");
603  $template->setVariable("FEEDBACK", $fb);
604  $template->parseCurrentBlock();
605  }
606  }
607 
608  $questionoutput = $template->get();
609  $feedback = ($show_feedback && !$this->isTestPresentationContext()) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
610  if (strlen($feedback))
611  {
612  $cssClass = ( $this->hasCorrectSolution($active_id, $pass) ?
614  );
615 
616  $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
617  $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput( $feedback, true ));
618  }
619  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
620 
621  $solutionoutput = $solutiontemplate->get();
622  if (!$show_question_only)
623  {
624  // get page object output
625  $solutionoutput = $this->getILIASPage($solutionoutput);
626  }
627  return $solutionoutput;
628  }
629 
630  function getPreview($show_question_only = FALSE, $showInlineFeedback = false)
631  {
632  if( is_object($this->getPreviewSession()) )
633  {
634  $user_solution = array();
635 
636  if( is_array($this->getPreviewSession()->getParticipantsSolution()) )
637  {
638  $user_solution = array_values($this->getPreviewSession()->getParticipantsSolution());
639  }
640 
641  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
642  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->getImageFilename());
643  foreach ($user_solution as $idx => $solution_value)
644  {
645  if (strcmp($solution_value, "") != 0)
646  {
647  $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);
648  }
649  }
650  $preview->createPreview();
651  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->getImageFilename());
652  }
653  else
654  {
655  $user_solution = array();
656  $imagepath = $this->object->getImagePathWeb() . $this->object->getImageFilename();
657  }
658 
659  // generate the question output
660  include_once "./Services/UICore/classes/class.ilTemplate.php";
661  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
662 
663  if($this->getQuestionActionCmd() && strlen($this->getTargetGuiClass()))
664  {
665  $hrefArea = $this->ctrl->getLinkTargetByClass($this->getTargetGuiClass(), $this->getQuestionActionCmd());
666  }
667  else
668  {
669  $hrefArea = null;
670  }
671 
672  foreach ($this->object->answers as $answer_id => $answer)
673  {
674  $parameter = "&amp;selImage=$answer_id";
675  if(is_array($user_solution) && in_array($answer_id, $user_solution))
676  {
677  $parameter = "&amp;remImage=$answer_id";
678  }
679 
680  if($hrefArea)
681  {
682  $template->setCurrentBlock("imagemap_area_href");
683  $template->setVariable("HREF_AREA", $hrefArea . $parameter);
684  $template->parseCurrentBlock();
685  }
686 
687  $template->setCurrentBlock("imagemap_area");
688  $template->setVariable("SHAPE", $answer->getArea());
689  $template->setVariable("COORDS", $answer->getCoords());
690  $template->setVariable("ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
691  $template->setVariable("TITLE", ilUtil::prepareFormOutput($answer->getAnswertext()));
692  $template->parseCurrentBlock();
693  }
694  $questiontext = $this->object->getQuestion();
695  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
696  $template->setVariable("IMG_SRC", ilWACSignedPath::signFile($imagepath));
697  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
698  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
699  $questionoutput = $template->get();
700  if (!$show_question_only)
701  {
702  // get page object output
703  $questionoutput = $this->getILIASPage($questionoutput);
704  }
705  return $questionoutput;
706  }
707 
708  // hey: prevPassSolutions - pass will be always available from now on
709  function getTestOutput($active_id, $pass, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
710  // hey.
711  {
712  // get the solution of the user for the active pass or from the last pass if allowed
713  $user_solution = "";
714  if($this->object->getIsMultipleChoice())
715  {
716  $user_solution = array();
717  }
718  if ($active_id)
719  {
720  // hey: prevPassSolutions - obsolete due to central check
721  #$solutions = NULL;
722  #include_once "./Modules/Test/classes/class.ilObjTest.php";
723  #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
724  #{
725  # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
726  #}
727  $solutions = $this->getTestOutputSolutions($active_id, $pass);
728  // hey.
729  foreach ($solutions as $idx => $solution_value)
730  {
731  if($this->object->getIsMultipleChoice())
732  {
733  $user_solution[] = $solution_value["value1"];
734  }
735  else
736  {
737  $user_solution = $solution_value["value1"];
738  }
739  }
740  }
741 
742  $imagepath = $this->object->getImagePathWeb() . $this->object->getImageFilename();
743  if ($active_id)
744  {
745  $solutions = NULL;
746  include_once "./Modules/Test/classes/class.ilObjTest.php";
747  if ((!$showsolution) && !ilObjTest::_getUsePreviousAnswers($active_id, true))
748  {
749  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
750  }
751  $solutions = $this->object->getUserSolutionPreferingIntermediate($active_id, $pass);
752  include_once "./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
753  $preview = new ilImagemapPreview($this->object->getImagePath().$this->object->getImageFilename());
754  foreach ($solutions as $idx => $solution_value)
755  {
756  if (strcmp($solution_value["value1"], "") != 0)
757  {
758  $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);
759  }
760  }
761  $preview->createPreview();
762  $imagepath = $this->object->getImagePathWeb() . $preview->getPreviewFilename($this->object->getImagePath(), $this->object->getImageFilename());
763  }
764 
765  // generate the question output
766  include_once "./Services/UICore/classes/class.ilTemplate.php";
767  $template = new ilTemplate("tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
768  $this->ctrl->setParameterByClass($this->getTargetGuiClass(), "formtimestamp", time());
769  $hrefArea = $this->ctrl->getLinkTargetByClass($this->getTargetGuiClass(), $this->getQuestionActionCmd());
770  foreach ($this->object->answers as $answer_id => $answer)
771  {
772  $template->setCurrentBlock("imagemap_area");
773  $parameter = "&amp;selImage=$answer_id";
774  if(is_array($user_solution) && in_array($answer_id, $user_solution))
775  {
776  $parameter = "&amp;remImage=$answer_id";
777  }
778  $template->setVariable("HREF_AREA", $hrefArea . $parameter);
779  $template->setVariable("SHAPE", $answer->getArea());
780  $template->setVariable("COORDS", $answer->getCoords());
781  $template->setVariable("ALT", ilUtil::prepareFormOutput($answer->getAnswertext()));
782  $template->setVariable("TITLE", ilUtil::prepareFormOutput($answer->getAnswertext()));
783  $template->parseCurrentBlock();
784  if ($show_feedback)
785  {
786  if(!$this->object->getIsMultipleChoice() && strlen($user_solution) && $user_solution == $answer_id)
787  {
788  $feedback = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
789  $this->object->getId(), $answer_id
790  );
791  if (strlen($feedback))
792  {
793  $template->setCurrentBlock("feedback");
794  $template->setVariable("FEEDBACK", $feedback);
795  $template->parseCurrentBlock();
796  }
797  }
798  }
799  }
800  $questiontext = $this->object->getQuestion();
801  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
802  $template->setVariable("IMG_SRC", ilWACSignedPath::signFile($imagepath));
803  $template->setVariable("IMG_ALT", $this->lng->txt("imagemap"));
804  $template->setVariable("IMG_TITLE", $this->lng->txt("imagemap"));
805  $questionoutput = $template->get();
806  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
807  return $pageoutput;
808  }
809 
817  public function setQuestionTabs()
818  {
819  global $rbacsystem, $ilTabs;
820 
821  $ilTabs->clearTargets();
822 
823  $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
824  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
825  $q_type = $this->object->getQuestionType();
826 
827  if (strlen($q_type))
828  {
829  $classname = $q_type . "GUI";
830  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
831  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
832  }
833 
834  if ($_GET["q_id"])
835  {
836  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
837  {
838  // edit page
839  $ilTabs->addTarget("edit_page",
840  $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
841  array("edit", "insert", "exec_pg"),
842  "", "", $force_active);
843  }
844 
845  $this->addTab_QuestionPreview($ilTabs);
846  }
847 
848  $force_active = false;
849  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
850  {
851  $url = "";
852  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
853  if (array_key_exists("imagemap_x", $_POST))
854  {
855  $force_active = true;
856  }
857  // edit question properties
858  $ilTabs->addTarget("edit_question",
859  $url,
860  array("editQuestion", "save", "addArea", "addRect", "addCircle", "addPoly",
861  "uploadingImage", "uploadingImagemap", "areaEditor",
862  "removeArea", "saveShape", "saveEdit", "originalSyncForm"),
863  $classname, "", $force_active);
864  }
865 
866  // add tab for question feedback within common class assQuestionGUI
867  $this->addTab_QuestionFeedback($ilTabs);
868 
869  // add tab for question hint within common class assQuestionGUI
870  $this->addTab_QuestionHints($ilTabs);
871 
872  // add tab for question's suggested solution within common class assQuestionGUI
873  $this->addTab_SuggestedSolution($ilTabs, $classname);
874 
875  // Assessment of questions sub menu entry
876  if ($_GET["q_id"])
877  {
878  $ilTabs->addTarget("statistics",
879  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
880  array("assessment"),
881  $classname, "");
882  }
883 
884  $this->addBackTab($ilTabs);
885  }
886 
887  function getSpecificFeedbackOutput($active_id, $pass)
888  {
889  if( !$this->object->feedbackOBJ->specificAnswerFeedbackExists(array_values($this->object->getAnswers())) )
890  {
891  return '';
892  }
893 
894  $output = '<table class="test_specific_feedback"><tbody>';
895 
896  foreach($this->object->getAnswers() as $idx => $answer)
897  {
898  $feedback = $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
899  $this->object->getId(), $idx
900  );
901 
902  $output .= "<tr><td>{$answer->getAnswerText()}</td><td>{$feedback}</td></tr>";
903  }
904 
905  $output .= '</tbody></table>';
906 
907  return $this->object->prepareTextareaOutput($output, TRUE);
908  }
909 
920  {
921  return array();
922  }
923 
934  {
935  return array();
936  }
937 
938  protected function renderAggregateView($answeringFequencies)
939  {
940  $tpl = new ilTemplate('tpl.il_as_aggregated_answers_table.html', true, true, "Modules/TestQuestionPool");
941 
942  $tpl->setCurrentBlock('headercell');
943  $tpl->setVariable('HEADER', $this->lng->txt('tst_answer_aggr_answer_header'));
944  $tpl->parseCurrentBlock();
945 
946  $tpl->setCurrentBlock('headercell');
947  $tpl->setVariable('HEADER', $this->lng->txt('tst_answer_aggr_frequency_header'));
948  $tpl->parseCurrentBlock();
949 
950  foreach($answeringFequencies as $answerIndex => $answeringFrequency)
951  {
952  $tpl->setCurrentBlock('aggregaterow');
953  $tpl->setVariable('OPTION', $this->object->getAnswer($answerIndex)->getAnswerText());
954  $tpl->setVariable('COUNT', $answeringFrequency);
955  $tpl->parseCurrentBlock();
956  }
957 
958  return $tpl->get();
959  }
960 
961  protected function aggregateAnswers($givenSolutionRows, $existingAnswerOptions)
962  {
963  $answeringFequencies = array();
964 
965  foreach($existingAnswerOptions as $answerIndex => $answerOption)
966  {
967  $answeringFequencies[$answerIndex] = 0;
968  }
969 
970  foreach($givenSolutionRows as $solutionRow)
971  {
972  $answeringFequencies[$solutionRow['value1']]++;
973  }
974 
975  return $answeringFequencies;
976  }
977 
986  public function getAggregatedAnswersView($relevant_answers)
987  {
988  return $this->renderAggregateView(
989  $this->aggregateAnswers( $relevant_answers, $this->object->getAnswers() )
990  );
991  }
992 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
hasCorrectSolution($activeId, $passIndex)
addTab_QuestionPreview(ilTabsGUI $tabsGUI)
This class represents an option in a radio group.
ILIAS Setting Class.
renderAggregateView($answeringFequencies)
completeTestOutputFormAction($formAction, $active_id, $pass)
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form)
writePostData()
Evaluates a posted edit form and writes the form data in the question object.
addBasicQuestionFormProperties($form)
Add basic question form properties: assessment: title, author, description, question, working time.
$_POST['username']
Definition: cron.php:12
addTab_QuestionHints(ilTabsGUI $tabs)
adds the hints tab to ilTabsGUI
getSolutionOutput( $active_id, $pass=NULL, $graphicalOutput=FALSE, $result_output=FALSE, $show_question_only=TRUE, $show_feedback=FALSE, $show_correct_solution=FALSE, $show_manual_scoring=FALSE, $show_question_text=TRUE)
Get the question solution output.
saveShape()
Saves a shape of the area editor.
This class represents a property form user interface.
$_GET["client_id"]
_getPass($active_id)
Retrieves the actual pass of a given user for a given test.
This class represents a file property in a property form.
$preview
getTestOutput($active_id, $pass, $is_postponed=FALSE, $use_post_solutions=FALSE, $show_feedback=FALSE)
$cmd
Definition: sahs_server.php:35
getTestOutputSolutions($activeId, $pass)
populateAnswerSpecificFormPart(\ilPropertyFormGUI $form)
addItem($a_item)
Add Item (Property, SectionHeader).
$url
Definition: shib_logout.php:72
getQuestionTemplate()
get question template
$coords
Definition: example_030.php:88
populateTaxonomyFormSection(ilPropertyFormGUI $form)
Image map image preview creator.
getSpecificFeedbackOutput($active_id, $pass)
setQuestionTabs()
Sets the ILIAS tabs for this question type.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
getAggregatedAnswersView($relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
This class represents an image map file property in a property form.
$info
Definition: example_052.php:80
This class represents a property in a property form.
aggregateAnswers($givenSolutionRows, $existingAnswerOptions)
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
Extracts the answer specific values from $_POST and applies them to the data object.
getILIASPage($html="")
Returns the ILIAS Page around a question.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
Class for image map questions.
addTab_QuestionFeedback(ilTabsGUI $tabs)
adds the feedback tab to ilTabsGUI
static signFile($path_to_file)
getPreview($show_question_only=FALSE, $showInlineFeedback=false)
Basic GUI class for assessment questions.
_getUsePreviousAnswers($active_id, $user_active_user_setting=false)
Returns if the previous results should be hidden for a learner.
getAnswerFeedbackOutput($active_id, $pass)
Returns the answer generic feedback depending on the results of the question.
writePostData($always=false)
Evaluates a posted edit form and writes the form data in the question object.
$errors
Image map question GUI representation.
addBackTab(ilTabsGUI $ilTabs)
Interface ilGuiAnswerScoringAdjustable.
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="")
output question page
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getAfterParticipationSuppressionAnswerPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
__construct($id=-1)
assImagemapQuestionGUI constructor
Interface ilGuiQuestionScoringAdjustable.
setPointsUncheckedFieldEnabled($pointsUncheckedFieldEnabled)
setRequired($a_required)
Set Required.
addTab_SuggestedSolution(ilTabsGUI $tabs, $classname)
addQuestionFormCommandButtons($form)
Add the command buttons of a question properties form.