ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilImageMapEditorGUI.php
Go to the documentation of this file.
1 <?php
2 
21 
28 {
29  protected \ILIAS\COPage\Xsl\XslManager $xsl;
32  protected ImageMapManager $map;
33  protected ilTemplate $tpl;
35  protected ilCtrl $ctrl;
36  protected ilLanguage $lng;
38 
39  public function __construct(
40  ilObjMediaObject $a_media_object
41  ) {
42  global $DIC;
43 
44  $this->ctrl = $DIC->ctrl();
45  $this->main_tpl = $DIC->ui()->mainTemplate();
46  $this->lng = $DIC->language();
47  $this->toolbar = $DIC->toolbar();
48  $this->media_object = $a_media_object;
49 
50  $this->map = $DIC->mediaObjects()
51  ->internal()
52  ->domain()
53  ->imageMap();
54 
55  $this->request = $DIC->mediaObjects()
56  ->internal()
57  ->gui()
58  ->imageMap()
59  ->request();
60  $this->xsl = $DIC->copage()->internal()->domain()->xsl();
61  }
62 
67  public function executeCommand()
68  {
69  $ilCtrl = $this->ctrl;
70 
71  $next_class = $ilCtrl->getNextClass($this);
72  $cmd = $ilCtrl->getCmd();
73 
74  switch ($next_class) {
75  case "ilinternallinkgui":
76  $link_gui = new ilInternalLinkGUI("Media_Media", 0);
77  $link_gui->setSetLinkTargetScript(
78  $ilCtrl->getLinkTarget(
79  $this,
80  "setInternalLink"
81  )
82  );
83  $link_gui->filterLinkType("File");
84  $ret = $ilCtrl->forwardCommand($link_gui);
85  break;
86 
87  default:
89  if ($this->request->getX() != "" &&
90  $this->request->getY() != "") {
91  $cmd = "editImagemapForward";
92  }
93  $ret = $this->$cmd();
94  break;
95  }
96  return $ret;
97  }
98 
99  public function editMapAreas(): string
100  {
101  $ilCtrl = $this->ctrl;
102 
103  $this->map->setTargetScript(
104  $ilCtrl->getLinkTarget(
105  $this,
106  "addArea",
107  "",
108  false,
109  false
110  )
111  );
112  $this->handleMapParameters();
113 
114  $this->tpl = new ilTemplate("tpl.map_edit.html", true, true, "Services/MediaObjects");
115  $this->tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
116 
117  // create/update imagemap work copy
118  $this->makeMapWorkCopy();
119 
120  $output = $this->getImageMapOutput();
121  $this->tpl->setVariable("IMAGE_MAP", $output);
122 
123  $this->tpl->setVariable("TOOLBAR", $this->getToolbar()->getHTML());
124 
125  // table
126  $this->tpl->setVariable("MAP_AREA_TABLE", $this->getImageMapTableHTML());
127 
128  return $this->tpl->get();
129  }
130 
131  public function getToolbar(): ilToolbarGUI
132  {
133  $ilCtrl = $this->ctrl;
134  $lng = $this->lng;
135 
136  // toolbar
137  $tb = new ilToolbarGUI();
138  $tb->setFormAction($ilCtrl->getFormAction($this));
139  $options = array(
140  "WholePicture" => $lng->txt("cont_WholePicture"),
141  "Rect" => $lng->txt("cont_Rect"),
142  "Circle" => $lng->txt("cont_Circle"),
143  "Poly" => $lng->txt("cont_Poly"),
144  );
145  $si = new ilSelectInputGUI($lng->txt("cont_shape"), "shape");
146  $si->setOptions($options);
147  $tb->addInputItem($si, true);
148  $tb->addFormButton($lng->txt("cont_add_area"), "addNewArea");
149 
150  return $tb;
151  }
152 
153  public function getEditorTitle(): string
154  {
155  $lng = $this->lng;
156  return $lng->txt("cont_imagemap");
157  }
158 
159 
160  public function getImageMapTableHTML(): string
161  {
162  $image_map_table = new ilImageMapTableGUI($this, "editMapAreas", $this->media_object);
163  return $image_map_table->getHTML();
164  }
165 
166  public function handleMapParameters(): void
167  {
168  if ($this->request->getRefId() > 0) {
169  $this->map->setRefId($this->request->getRefId());
170  }
171 
172  if ($this->request->getObjId() > 0) {
173  $this->map->setObjId($this->request->getObjId());
174  }
175 
176  if ($this->request->getHierId() != "") {
177  $this->map->setHierId($this->request->getHierId());
178  }
179 
180  if ($this->request->getPCId() != "") {
181  $this->map->setPCId($this->request->getPCId());
182  }
183  }
184 
185  public function showImageMap(): void
186  {
187  $item = new ilMediaItem($this->request->getItemId());
188  $item->outputMapWorkCopy();
189  }
190 
191  public function updateAreas(): void
192  {
193  $lng = $this->lng;
194  $ilCtrl = $this->ctrl;
195 
196  $st_item = $this->media_object->getMediaItem("Standard");
197  $max = ilMapArea::_getMaxNr($st_item->getId());
198  for ($i = 1; $i <= $max; $i++) {
199  $area = new ilMapArea($st_item->getId(), $i);
200  $area->setTitle(
201  $this->request->getAreaTitle($i)
202  );
203  $area->setHighlightMode(
204  $this->request->getAreaHighlightMode($i)
205  );
206  $area->setHighlightClass(
207  $this->request->getAreaHighlightClass($i)
208  );
209  $area->update();
210  }
211 
212  $this->main_tpl->setOnScreenMessage('success', $lng->txt("cont_saved_map_data"), true);
213  $ilCtrl->redirect($this, "editMapAreas");
214  }
215 
216  public function addNewArea(): string
217  {
218  switch ($this->request->getAreaShape()) {
219  case "WholePicture": return $this->linkWholePicture();
220  case "Rect": return $this->addRectangle();
221  case "Circle": return $this->addCircle();
222  case "Poly": return $this->addPolygon();
223  }
224  return "";
225  }
226 
227  public function linkWholePicture(): string
228  {
229  $this->clearSessionVars();
230  $this->map->setAreaType("WholePicture");
231 
232  return $this->editMapArea(false, false, true);
233  }
234 
235  public function addRectangle(): string
236  {
237  $this->clearSessionVars();
238  $this->map->setAreaType("Rect");
239  return $this->addArea(false);
240  }
241 
242  public function addCircle(): string
243  {
244  $this->clearSessionVars();
245  $this->map->setAreaType("Circle");
246  return $this->addArea(false);
247  }
248 
249  public function addPolygon(): string
250  {
251  $this->clearSessionVars();
252  $this->map->setAreaType("Poly");
253  return $this->addArea(false);
254  }
255 
256  public function clearSessionVars(): void
257  {
258  $this->map->clear();
259  }
260 
261  public function addArea(
262  bool $a_handle = true
263  ): string {
264  // handle map parameters
265  if ($a_handle) {
266  $this->handleMapParameters();
267  }
268 
269  $area_type = $this->map->getAreaType();
270  $coords = $this->map->getCoords();
271  $cnt_coords = ilMapArea::countCoords($coords);
272 
273  // decide what to do next
274  switch ($area_type) {
275  // Rectangle
276  case "Rect":
277  if ($cnt_coords < 2) {
278  $html = $this->editMapArea(true, false, false);
279  return $html;
280  } elseif ($cnt_coords == 2) {
281  return $this->editMapArea(false, true, true);
282  }
283  break;
284 
285  // Circle
286  case "Circle":
287  if ($cnt_coords <= 1) {
288  return $this->editMapArea(true, false, false);
289  } else {
290  if ($cnt_coords == 2) {
291  $c = explode(",", $coords);
292  $coords = $c[0] . "," . $c[1] . ","; // determine radius
293  $coords .= round(sqrt(pow(abs($c[3] - $c[1]), 2) + pow(abs($c[2] - $c[0]), 2)));
294  }
295  $this->map->setCoords($coords);
296 
297  return $this->editMapArea(false, true, true);
298  }
299 
300  // Polygon
301  // no break
302  case "Poly":
303  if ($cnt_coords < 1) {
304  return $this->editMapArea(true, false, false);
305  } elseif ($cnt_coords < 3) {
306  return $this->editMapArea(true, true, false);
307  } else {
308  return $this->editMapArea(true, true, true);
309  }
310 
311  // Whole picture
312  // no break
313  case "WholePicture":
314  return $this->editMapArea(false, false, true);
315  }
316  return "";
317  }
318 
328  public function editMapArea(
329  bool $a_get_next_coordinate = false,
330  bool $a_output_new_area = false,
331  bool $a_save_form = false,
332  string $a_edit_property = "",
333  int $a_area_nr = 0
334  ): string {
335  $ilCtrl = $this->ctrl;
336  $lng = $this->lng;
337 
338  $area_type = $this->map->getAreaType();
339  $coords = $this->map->getCoords();
340  $cnt_coords = ilMapArea::countCoords($coords);
341 
342  $this->tpl = new ilTemplate("tpl.map_edit.html", true, true, "Services/MediaObjects");
343 
344  $this->tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
345 
346  if ($a_edit_property != "link") {
347  switch ($area_type) {
348  // rectangle
349  case "Rect":
350  if ($cnt_coords == 0) {
351  $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_tl_corner"));
352  }
353  if ($cnt_coords == 1) {
354  $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_br_corner"));
355  }
356  break;
357 
358  // circle
359  case "Circle":
360  if ($cnt_coords == 0) {
361  $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_center"));
362  }
363  if ($cnt_coords == 1) {
364  $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_circle"));
365  }
366  break;
367 
368  // polygon
369  case "Poly":
370  if ($cnt_coords == 0) {
371  $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_starting_point"));
372  } elseif ($cnt_coords < 3) {
373  $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_next_point"));
374  } else {
375  $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_next_or_save"));
376  }
377  break;
378  }
379  }
380 
381 
382  // map properties input fields (name and link)
383  if ($a_save_form) {
384  if ($a_edit_property != "shape") {
385  // prepare link gui
386  $ilCtrl->setParameter($this, "linkmode", "map");
387  $this->tpl->setCurrentBlock("int_link_prep");
388  $this->tpl->setVariable("INT_LINK_PREP", ilInternalLinkGUI::getInitHTML(
389  $ilCtrl->getLinkTargetByClass(
390  "ilinternallinkgui",
391  "",
392  false,
393  true,
394  false
395  )
396  ));
397  $this->tpl->parseCurrentBlock();
398  }
399  $form = $this->initAreaEditingForm($a_edit_property);
400  $this->tpl->setVariable("FORM", $form->getHTML());
401  }
402 
403  $this->makeMapWorkCopy(
404  $a_edit_property,
405  $a_area_nr,
406  $a_output_new_area,
407  $area_type,
408  $coords
409  );
410 
411  $edit_mode = ($a_get_next_coordinate)
412  ? "get_coords"
413  : (($a_output_new_area)
414  ? "new_area"
415  : "");
416  $output = $this->getImageMapOutput($edit_mode);
417  $this->tpl->setVariable("IMAGE_MAP", $output);
418 
419  return $this->tpl->get();
420  }
421 
422  public function initAreaEditingForm(
423  string $a_edit_property
424  ): ilPropertyFormGUI {
425  $lng = $this->lng;
426 
427  $form = new ilPropertyFormGUI();
428  $form->setOpenTag(false);
429  $form->setCloseTag(false);
430 
431  // link
432  if ($a_edit_property != "shape") {
433  //
434  $radg = new ilRadioGroupInputGUI($lng->txt("cont_link"), "area_link_type");
435  if ($this->map->getLinkType() != "int") {
436  if ($this->map->getExternalLink() == "") {
437  $radg->setValue("no");
438  } else {
439  $radg->setValue("ext");
440  }
441  } else {
442  $radg->setValue("int");
443  }
444 
445  // external link
446  $ext = new ilRadioOption($lng->txt("cont_link_ext"), "ext");
447  $radg->addOption($ext);
448 
449  $ti = new ilTextInputGUI("", "area_link_ext");
450  $ti->setMaxLength(800);
451  $ti->setSize(50);
452  if ($this->map->getExternalLink() != "") {
453  $ti->setValue($this->map->getExternalLink());
454  } else {
455  $ti->setValue("https://");
456  }
457  $ext->addSubItem($ti);
458 
459  // internal link
460  $int = new ilRadioOption($lng->txt("cont_link_int"), "int");
461  $radg->addOption($int);
462 
463  $ne = new ilNonEditableValueGUI("", "", true);
464  $link_str = "";
465  $int_link = $this->map->getInternalLink();
466  if ($int_link["target"] != "") {
467  $link_str = $this->getMapAreaLinkString(
468  $int_link["target"],
469  $int_link["type"],
470  $int_link["target_frame"]
471  );
472  }
473  $ne->setValue(
474  $link_str .
475  '&nbsp;<a id="iosEditInternalLinkTrigger" href="#">' .
476  "[" . $lng->txt("cont_get_link") . "]" .
477  '</a>'
478  );
479  $int->addSubItem($ne);
480 
481  // no link
482  $no = new ilRadioOption($lng->txt("cont_link_no"), "no");
483  $radg->addOption($no);
484 
485  $form->addItem($radg);
486  }
487 
488 
489  // name
490  if ($a_edit_property != "link" && $a_edit_property != "shape") {
491  $ti = new ilTextInputGUI($lng->txt("cont_name"), "area_name");
492  $ti->setMaxLength(200);
493  $ti->setSize(20);
494  $form->addItem($ti);
495  }
496 
497  // save and cancel commands
498  $form->setTitle($lng->txt("cont_new_area"));
499  $form->addCommandButton("saveArea", $lng->txt("save"));
500 
501  // $form->setFormAction($ilCtrl->getFormAction($this));
502 
503  return $form;
504  }
505 
509  public function makeMapWorkCopy(
510  string $a_edit_property = "",
511  int $a_area_nr = 0,
512  bool $a_output_new_area = false,
513  string $a_area_type = "",
514  string $a_coords = ""
515  ): void {
516  // create/update imagemap work copy
517  $st_item = $this->media_object->getMediaItem("Standard");
518 
519  if ($a_edit_property == "shape") {
520  $st_item->makeMapWorkCopy($a_area_nr, true); // exclude area currently being edited
521  } else {
522  $st_item->makeMapWorkCopy($a_area_nr, false);
523  }
524 
525  if ($a_output_new_area) {
526  $st_item->addAreaToMapWorkCopy($a_area_type, $a_coords);
527  }
528  }
529 
533  public function getImageMapOutput(
534  string $a_map_edit_mode = ""
535  ): string {
536  $ilCtrl = $this->ctrl;
537 
538  $st_item = $this->media_object->getMediaItem("Standard");
539 
540  // output image map
541  $xml = "<dummy>";
542  $xml .= $this->getAliasXML();
543  $xml .= $this->media_object->getXML(IL_MODE_OUTPUT);
544  $xml .= $this->getAdditionalPageXML();
545  $xml .= "</dummy>";
546 
547  $wb_path = ilFileUtils::getWebspaceDir("output") . "/";
548  $mode = "media";
549  //echo htmlentities($ilCtrl->getLinkTarget($this, "showImageMap"));
550 
551  $random = new \ilRandom();
552  $params = array('map_edit_mode' => $a_map_edit_mode,
553  'map_item' => $st_item->getId(),
554  'map_mob_id' => $this->media_object->getId(),
555  'mode' => $mode,
556  'media_mode' => 'enable',
557  'image_map_link' => $ilCtrl->getLinkTarget($this, "showImageMap", "", false, false),
558  'link_params' => "ref_id=" . $this->request->getRefId() . "&rand=" . $random->int(1, 999999),
559  'ref_id' => $this->request->getRefId(),
560  'pg_frame' => "",
561  'enlarge_path' => ilUtil::getImagePath("media/enlarge.svg"),
562  'webspace_path' => $wb_path);
563  $output = $this->xsl->process($xml, $params);
564 
565  $output = $this->outputPostProcessing($output);
566 
567  return $output;
568  }
569 
574  public function getAdditionalPageXML(): string
575  {
576  return "";
577  }
578 
579  public function outputPostProcessing(
580  string $a_output
581  ): string {
582  return $a_output;
583  }
584 
585  public function getAliasXML(): string
586  {
587  return $this->media_object->getXML(IL_MODE_ALIAS);
588  }
589 
596  public function getMapAreaLinkString(
597  string $a_target,
598  string $a_type,
599  string $a_frame
600  ): string {
601  $lng = $this->lng;
602  $frame_str = "";
603  $link_str = "";
604  $t_arr = explode("_", $a_target);
605  if ($a_frame != "") {
606  $frame_str = " (" . $a_frame . " Frame)";
607  }
608  switch ($a_type) {
609  case "StructureObject":
610  $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
611  $link_str = $lng->txt("chapter") .
612  ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
613  break;
614 
615  case "PageObject":
616  $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
617  $link_str = $lng->txt("page") .
618  ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
619  break;
620 
621  case "GlossaryItem":
622  $term = new ilGlossaryTerm($t_arr[count($t_arr) - 1]);
623  $link_str = $lng->txt("term") .
624  ": " . $term->getTerm() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
625  break;
626 
627  case "MediaObject":
628  $mob = new ilObjMediaObject($t_arr[count($t_arr) - 1]);
629  $link_str = $lng->txt("mob") .
630  ": " . $mob->getTitle() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
631  break;
632 
633  case "RepositoryItem":
634  if (trim($a_target) !== "") {
635  $title = ilObject::_lookupTitle(
636  ilObject::_lookupObjId((int) $t_arr[count($t_arr) - 1])
637  );
638  $link_str = $lng->txt("obj_" . $t_arr[count($t_arr) - 2]) .
639  ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
640  } else {
641  $title = "";
642  $link_str = "";
643  }
644  break;
645 
646  case "WikiPage":
647  $wpg = new ilWikiPage($t_arr[count($t_arr) - 1]);
648  $link_str = $lng->txt("cont_wiki_page") .
649  ": " . $wpg->getTitle() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
650  break;
651 
652  }
653 
654  return $link_str;
655  }
656 
660  public function editImagemapForward(): void
661  {
663 
664  $coords = $this->map->getCoords();
665  if ($coords != "") {
666  $coords .= ",";
667  }
668 
669  $this->map->setCoords($coords . $this->request->getX() . "," .
670  $this->request->getY());
671 
672  // call editing script
673  ilUtil::redirect($this->map->getTargetScript());
674  }
675 
679  public static function _recoverParameters(): void
680  {
681  global $DIC;
682 
683  $map = $DIC->mediaObjects()->internal()->domain()->imageMap();
684  /*
685  $_GET["ref_id"] = $map->getRefId();
686  $_GET["obj_id"] = $map->getObjId();
687  $_GET["hier_id"] = $map->getHierId();
688  $_GET["pc_id"] = $map->getPCId();*/
689  }
690 
694  public function saveArea(): string
695  {
696  $lng = $this->lng;
697  $ilCtrl = $this->ctrl;
698 
699  switch ($this->map->getMode()) {
700  // save edited link
701  case "edit_link":
702  $st_item = $this->media_object->getMediaItem("Standard");
703  $max = ilMapArea::_getMaxNr($st_item->getId());
704  $area = new ilMapArea($st_item->getId(), $this->map->getAreaNr());
705 
706  if ($this->request->getAreaLinkType() == IL_INT_LINK) {
707  $area->setLinkType(IL_INT_LINK);
708  $int_link = $this->map->getInternalLink();
709  $area->setType($int_link["type"] ?? "");
710  $area->setTarget($int_link["target"] ?? "");
711  $area->setTargetFrame($int_link["target_frame"] ?? "");
712  } else {
713  $area->setLinkType(IL_EXT_LINK);
714  if ($this->request->getAreaLinkType() != IL_NO_LINK) {
715  $area->setHref(
716  $this->request->getExternalLink()
717  );
718  } else {
719  $area->setHref("");
720  }
721  }
722  $area->update();
723  break;
724 
725  // save edited shape
726  case "edit_shape":
727  $st_item = $this->media_object->getMediaItem("Standard");
728  $max = ilMapArea::_getMaxNr($st_item->getId());
729  $area = new ilMapArea(
730  $st_item->getId(),
731  $this->map->getAreaNr()
732  );
733 
734  $area->setShape($this->map->getAreaType());
735  $area->setCoords($this->map->getCoords());
736  $area->update();
737  break;
738 
739  // save new area
740  default:
741  $area_type = $this->map->getAreaType();
742  $coords = $this->map->getCoords();
743 
744  $st_item = $this->media_object->getMediaItem("Standard");
745  $max = ilMapArea::_getMaxNr($st_item->getId());
746 
747  // make new area object
748  $area = new ilMapArea();
749  $area->setItemId($st_item->getId());
750  $area->setShape($area_type);
751  $area->setCoords($coords);
752  $area->setNr($max + 1);
753  $area->setTitle($this->request->getAreaName());
754  switch ($this->request->getAreaLinkType()) {
755  case "ext":
756  $area->setLinkType(IL_EXT_LINK);
757  $area->setHref($this->request->getExternalLink());
758  break;
759 
760  case "int":
761  $area->setLinkType(IL_INT_LINK);
762  $int_link = $this->map->getInternalLink();
763  $area->setType($int_link["type"] ?? "");
764  $area->setTarget($int_link["target"] ?? "");
765  $area->setTargetFrame($int_link["type_frame"] ?? "");
766  break;
767  }
768 
769  // put area into item and update media object
770  $st_item->addMapArea($area);
771  $this->media_object->update();
772  break;
773  }
774 
775  //$this->initMapParameters();
776  $this->main_tpl->setOnScreenMessage('success', $lng->txt("cont_saved_map_area"), true);
777  $ilCtrl->redirect($this, "editMapAreas");
778  return "";
779  }
780 
781  public function setInternalLink(): string
782  {
783  $this->map->setLinkType("int");
784  $this->map->setInternalLink(
785  $this->request->getLinkType(),
786  $this->request->getLinkTarget(),
787  $this->request->getLinkTargetFrame(),
788  $this->request->getLinkAnchor()
789  );
790 
791  switch ($this->map->getMode()) {
792  case "edit_link":
793  return $this->setLink();
794 
795  default:
796  return $this->addArea();
797  }
798  }
799 
800  public function setLink(
801  bool $a_handle = true
802  ): string {
803  $lng = $this->lng;
804  $ilCtrl = $this->ctrl;
805  $area = null;
806  if ($a_handle) {
807  $this->handleMapParameters();
808  }
809  if ($this->map->getAreaNr() > 0) {
810  $area_nr = $this->map->getAreaNr();
811  } else {
812  $area = $this->request->getArea();
813  $area_nr = (int) ($area[0] ?? 0);
814  }
815  if ($area_nr === 0) {
816  $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
817  $ilCtrl->redirect($this, "editMapAreas");
818  }
819 
820  if (count($area ?? []) > 1) {
821  $this->main_tpl->setOnScreenMessage('failure', $lng->txt("cont_select_max_one_item"), true);
822  $ilCtrl->redirect($this, "editMapAreas");
823  }
824 
825 
826  if ($this->map->getMode() != "edit_link") {
827  $this->map->setAreaNr($area_nr);
828  $this->map->setLinkType($this->getLinkTypeOfArea($area_nr));
829  $this->map->setMode("edit_link");
830  $this->map->setTargetScript($ilCtrl->getLinkTarget($this, "setLink"));
831  if ($this->map->getLinkType() == IL_INT_LINK) {
832  $this->map->setInternalLink(
833  $this->getTypeOfArea($area_nr),
834  $this->getTargetOfArea($area_nr),
835  $this->getTargetFrameOfArea($area_nr),
836  ""
837  );
838  } else {
839  $this->map->setExternalLink($this->getHrefOfArea($area_nr));
840  }
841  }
842 
843  return $this->editMapArea(false, false, true, "link", $area_nr);
844  }
845 
846  public function getLinkTypeOfArea(
847  int $a_nr
848  ): string {
849  $st_item = $this->media_object->getMediaItem("Standard");
850  $area = $st_item->getMapArea($a_nr);
851  return $area->getLinkType();
852  }
853 
857  public function getTypeOfArea(
858  int $a_nr
859  ): string {
860  $st_item = $this->media_object->getMediaItem("Standard");
861  $area = $st_item->getMapArea($a_nr);
862  return $area->getType();
863  }
864 
868  public function getTargetOfArea(
869  int $a_nr
870  ): string {
871  $st_item = $this->media_object->getMediaItem("Standard");
872  $area = $st_item->getMapArea($a_nr);
873  return $area->getTarget();
874  }
875 
879  public function getTargetFrameOfArea(
880  int $a_nr
881  ): string {
882  $st_item = $this->media_object->getMediaItem("Standard");
883  $area = $st_item->getMapArea($a_nr);
884  return $area->getTargetFrame();
885  }
886 
890  public function getHrefOfArea(
891  int $a_nr
892  ): string {
893  $st_item = $this->media_object->getMediaItem("Standard");
894  $area = $st_item->getMapArea($a_nr);
895  return $area->getHref();
896  }
897 
901  public function deleteAreas(): void
902  {
903  $ilCtrl = $this->ctrl;
904  $lng = $this->lng;
905 
906  $area = $this->request->getArea();
907  if (count($area) == 0) {
908  $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
909  $ilCtrl->redirect($this, "editMapAreas");
910  }
911 
912  $st_item = $this->media_object->getMediaItem("Standard");
913  $max = ilMapArea::_getMaxNr($st_item->getId());
914 
915  if (count($area) > 0) {
916  $i = 0;
917 
918  foreach ($area as $area_nr) {
919  $st_item->deleteMapArea($area_nr - $i);
920  $i++;
921  }
922 
923  $this->media_object->update();
924  $this->main_tpl->setOnScreenMessage('success', $lng->txt("cont_areas_deleted"), true);
925  }
926 
927  $ilCtrl->redirect($this, "editMapAreas");
928  }
929 
933  public function editLink(): string
934  {
935  $this->map->clear();
936  return $this->setLink(false);
937  }
938 
942  public function editShapeWholePicture(): string
943  {
944  $this->clearSessionVars();
945  $this->map->setAreaType("WholePicture");
946  return $this->setShape(false);
947  }
948 
952  public function editShapeRectangle(): string
953  {
954  $this->clearSessionVars();
955  $this->map->setAreaType("Rect");
956  return $this->setShape(false);
957  }
958 
962  public function editShapeCircle(): string
963  {
964  $this->clearSessionVars();
965  $this->map->setAreaType("Circle");
966  return $this->setShape(false);
967  }
968 
972  public function editShapePolygon(): string
973  {
974  $this->clearSessionVars();
975  $this->map->setAreaType("Poly");
976  return $this->setShape(false);
977  }
978 
982  public function setShape(
983  bool $a_handle = true
984  ): string {
985  $lng = $this->lng;
986  $ilCtrl = $this->ctrl;
987 
988  $area = [];
989  if ($a_handle) {
990  $this->handleMapParameters();
991  }
992  /* this seems to be obsolete
993  if ($_POST["areatype2"] != "") {
994  $this->map->setAreaType($_POST["areatype2"]);
995  }*/
996  if ($this->map->getAreaNr() > 0) {
997  $area_nr = $this->map->getAreaNr();
998  } else {
999  $area = $this->request->getArea();
1000  $area_nr = (int) ($area[0] ?? 0);
1001  }
1002  if ($area_nr === 0) {
1003  $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
1004  $ilCtrl->redirect($this, "editMapAreas");
1005  }
1006 
1007  if (count($area ?? []) > 1) {
1008  $this->main_tpl->setOnScreenMessage('failure', $lng->txt("cont_select_max_one_item"), true);
1009  $ilCtrl->redirect($this, "editMapAreas");
1010  }
1011 
1012  if ($this->map->getMode() != "edit_shape") {
1013  $this->map->setAreaNr($area_nr);
1014  $this->map->setMode("edit_shape");
1015  $this->map->setTargetScript(
1016  $ilCtrl->getLinkTarget($this, "setShape", "", false, false)
1017  );
1018  }
1019 
1020 
1021  $area_type = $this->map->getAreaType();
1022  $coords = $this->map->getCoords();
1023  $cnt_coords = ilMapArea::countCoords($coords);
1024 
1025  // decide what to do next
1026  switch ($area_type) {
1027  // Rectangle
1028  case "Rect":
1029  if ($cnt_coords < 2) {
1030  return $this->editMapArea(true, false, false, "shape", $area_nr);
1031  } elseif ($cnt_coords == 2) {
1032  return $this->saveArea();
1033  }
1034  break;
1035 
1036  // Circle
1037  case "Circle":
1038  if ($cnt_coords <= 1) {
1039  return $this->editMapArea(true, false, false, "shape", $area_nr);
1040  } else {
1041  if ($cnt_coords == 2) {
1042  $c = explode(",", $coords);
1043  $coords = $c[0] . "," . $c[1] . ","; // determine radius
1044  $coords .= round(sqrt(pow(abs($c[3] - $c[1]), 2) + pow(abs($c[2] - $c[0]), 2)));
1045  }
1046  $this->map->setCoords($coords);
1047  return $this->saveArea();
1048  }
1049 
1050  // Polygon
1051  // no break
1052  case "Poly":
1053  if ($cnt_coords < 1) {
1054  return $this->editMapArea(true, false, false, "shape", $area_nr);
1055  } elseif ($cnt_coords < 3) {
1056  return $this->editMapArea(true, true, false, "shape", $area_nr);
1057  } else {
1058  return $this->editMapArea(true, true, true, "shape", $area_nr);
1059  }
1060 
1061  // Whole Picture
1062  // no break
1063  case "WholePicture":
1064  return $this->saveArea();
1065  }
1066  return "";
1067  }
1068 
1072  public function setHighlight(): void
1073  {
1074  $ilCtrl = $this->ctrl;
1075  $lng = $this->lng;
1076 
1077  $st_item = $this->media_object->getMediaItem("Standard");
1078  // seems to be obsolete, methods don't exist
1079  //$st_item->setHighlightMode($this->request->getHighlightMode());
1080  //$st_item->setHighlightClass($this->request->getHighlightClass());
1081  $st_item->update();
1082 
1083  $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1084  $ilCtrl->redirect($this, "editMapAreas");
1085  }
1086 }
static getWebspaceDir(string $mode="filesystem")
get webspace directory
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
makeMapWorkCopy(string $a_edit_property="", int $a_area_nr=0, bool $a_output_new_area=false, string $a_area_type="", string $a_coords="")
Make work file for editing.
static getInitHTML(string $a_url)
Get initialisation HTML to use internal link editing.
getImageMapOutput(string $a_map_edit_mode="")
Render the image map.
setTitle(string $a_title)
set (tooltip)title of area
editShapeWholePicture()
Edit an existing shape (make it a whole picture link)
This class represents a selection list property in a property form.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setLink(bool $a_handle=true)
saveArea()
Save new or updated map area.
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjMediaObject $a_media_object)
getTargetOfArea(int $a_nr)
Get Target of Area (only internal link)
static includePresentationJS(ilGlobalTemplateInterface $a_tpl=null)
Include media object presentation JS.
static _getMaxNr(int $a_item_id)
get maximum nr of media item (static)
Manages items in repository clipboard.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
getMapAreaLinkString(string $a_target, string $a_type, string $a_frame)
Get text name of internal link.
ILIAS COPage Xsl XslManager $xsl
setOptions(array $a_options)
Internal link selector.
setShape(string $a_shape)
set shape (IL_AREA_RECT, IL_AREA_CIRCLE, IL_AREA_POLY, IL_AREA_WHOLE_PICTURE)
initAreaEditingForm(string $a_edit_property)
const IL_NO_LINK
getHrefOfArea(int $a_nr)
Get Href of Area (only external link)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $a_obj_id)
global $DIC
Definition: feed.php:28
getTargetFrameOfArea(int $a_nr)
Get TargetFrame of Area (only internal link)
editShapeCircle()
Edit an existing shape (make it a circle)
setHighlight()
Set highlight settings.
getNextClass($a_gui_class=null)
This class represents a property in a property form.
static _lookupTitle(int $obj_id)
const IL_INT_LINK
outputPostProcessing(string $a_output)
static countCoords(string $c)
count the number of coordinates (x,y) in a coordinate string (format: "x1,y1,x2,y2,x3,y3,...")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLinkType(string $a_link_type)
set link type
editLink()
Edit existing link.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
deleteAreas()
Delete map areas.
editMapArea(bool $a_get_next_coordinate=false, bool $a_output_new_area=false, bool $a_save_form=false, string $a_edit_property="", int $a_area_nr=0)
Edit a single map area.
const IL_MODE_ALIAS
static redirect(string $a_script)
const IL_EXT_LINK
User interface class for map editor.
setShape(bool $a_handle=true)
edit shape of existing map area
Class ilMapArea.
static _recoverParameters()
Recover parameters from session variables (static)
editShapePolygon()
Edit an existing shape (make it a polygon)
editImagemapForward()
Get image map coordinates.
setTargetScript(string $a_target_script)
getTypeOfArea(int $a_nr)
Get Type of Area (only internal link)
getAdditionalPageXML()
Get additional page xml (to be overwritten)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_MODE_OUTPUT
outputMapWorkCopy()
output raw map work copy file
addArea(bool $a_handle=true)
ilGlobalTemplateInterface $main_tpl
editShapeRectangle()
Edit an existing shape (make it a rectangle)