ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilImageMapEditorGUI.php
Go to the documentation of this file.
1<?php
2
21
28{
29 protected \ILIAS\COPage\Xsl\XslManager $xsl;
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, "components/ILIAS/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;
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 {
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 = $this->makeMapWorkCopy(
188 $this->request->getOutEditProperty(),
189 $this->request->getOutAreaNr(),
190 $this->request->getOutOutputNewArea(),
191 $this->request->getOutAreaType(),
192 $this->request->getOutCoords()
193 );
194
195 //$item = new ilMediaItem($this->request->getItemId());
196 $item->outputMapWorkCopy();
197 }
198
199 public function updateAreas(): void
200 {
202 $ilCtrl = $this->ctrl;
203
204 $st_item = $this->media_object->getMediaItem("Standard");
205 $max = ilMapArea::_getMaxNr($st_item->getId());
206 for ($i = 1; $i <= $max; $i++) {
207 $area = new ilMapArea($st_item->getId(), $i);
208 $area->setTitle(
209 $this->request->getAreaTitle($i)
210 );
211 $area->setHighlightMode(
212 $this->request->getAreaHighlightMode($i)
213 );
214 $area->setHighlightClass(
215 $this->request->getAreaHighlightClass($i)
216 );
217 $area->update();
218 }
219
220 $this->main_tpl->setOnScreenMessage('success', $lng->txt("cont_saved_map_data"), true);
221 $ilCtrl->redirect($this, "editMapAreas");
222 }
223
224 public function addNewArea(): string
225 {
226 switch ($this->request->getAreaShape()) {
227 case "WholePicture": return $this->linkWholePicture();
228 case "Rect": return $this->addRectangle();
229 case "Circle": return $this->addCircle();
230 case "Poly": return $this->addPolygon();
231 }
232 return "";
233 }
234
235 public function linkWholePicture(): string
236 {
237 $this->clearSessionVars();
238 $this->map->setAreaType("WholePicture");
239
240 return $this->editMapArea(false, false, true);
241 }
242
243 public function addRectangle(): string
244 {
245 $this->clearSessionVars();
246 $this->map->setAreaType("Rect");
247 return $this->addArea(false);
248 }
249
250 public function addCircle(): string
251 {
252 $this->clearSessionVars();
253 $this->map->setAreaType("Circle");
254 return $this->addArea(false);
255 }
256
257 public function addPolygon(): string
258 {
259 $this->clearSessionVars();
260 $this->map->setAreaType("Poly");
261 return $this->addArea(false);
262 }
263
264 public function clearSessionVars(): void
265 {
266 $this->map->clear();
267 }
268
269 public function addArea(
270 bool $a_handle = true
271 ): string {
272 // handle map parameters
273 if ($a_handle) {
274 $this->handleMapParameters();
275 }
276
277 $area_type = $this->map->getAreaType();
278 $coords = $this->map->getCoords();
279 $cnt_coords = ilMapArea::countCoords($coords);
280
281 // decide what to do next
282 switch ($area_type) {
283 // Rectangle
284 case "Rect":
285 if ($cnt_coords < 2) {
286 $html = $this->editMapArea(true, false, false);
287 return $html;
288 } elseif ($cnt_coords == 2) {
289 return $this->editMapArea(false, true, true);
290 }
291 break;
292
293 // Circle
294 case "Circle":
295 if ($cnt_coords <= 1) {
296 return $this->editMapArea(true, false, false);
297 } else {
298 if ($cnt_coords == 2) {
299 $c = explode(",", $coords);
300 $coords = $c[0] . "," . $c[1] . ","; // determine radius
301 $coords .= round(sqrt(pow(abs($c[3] - $c[1]), 2) + pow(abs($c[2] - $c[0]), 2)));
302 }
303 $this->map->setCoords($coords);
304
305 return $this->editMapArea(false, true, true);
306 }
307
308 // Polygon
309 // no break
310 case "Poly":
311 if ($cnt_coords < 1) {
312 return $this->editMapArea(true, false, false);
313 } elseif ($cnt_coords < 3) {
314 return $this->editMapArea(true, true, false);
315 } else {
316 return $this->editMapArea(true, true, true);
317 }
318
319 // Whole picture
320 // no break
321 case "WholePicture":
322 return $this->editMapArea(false, false, true);
323 }
324 return "";
325 }
326
336 public function editMapArea(
337 bool $a_get_next_coordinate = false,
338 bool $a_output_new_area = false,
339 bool $a_save_form = false,
340 string $a_edit_property = "",
341 int $a_area_nr = 0
342 ): string {
343 $ilCtrl = $this->ctrl;
345
346 $area_type = $this->map->getAreaType();
347 $coords = $this->map->getCoords();
348 $cnt_coords = ilMapArea::countCoords($coords);
349
350 $this->tpl = new ilTemplate("tpl.map_edit.html", true, true, "components/ILIAS/MediaObjects");
351
352 $this->tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
353
354 if ($a_edit_property != "link") {
355 switch ($area_type) {
356 // rectangle
357 case "Rect":
358 if ($cnt_coords == 0) {
359 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_tl_corner"));
360 }
361 if ($cnt_coords == 1) {
362 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_br_corner"));
363 }
364 break;
365
366 // circle
367 case "Circle":
368 if ($cnt_coords == 0) {
369 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_center"));
370 }
371 if ($cnt_coords == 1) {
372 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_circle"));
373 }
374 break;
375
376 // polygon
377 case "Poly":
378 if ($cnt_coords == 0) {
379 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_starting_point"));
380 } elseif ($cnt_coords < 3) {
381 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_next_point"));
382 } else {
383 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_next_or_save"));
384 }
385 break;
386 }
387 }
388
389
390 // map properties input fields (name and link)
391 if ($a_save_form) {
392 if ($a_edit_property != "shape") {
393 // prepare link gui
394 $ilCtrl->setParameter($this, "linkmode", "map");
395 $this->tpl->setCurrentBlock("int_link_prep");
396 $this->tpl->setVariable("INT_LINK_PREP", ilInternalLinkGUI::getInitHTML(
397 $ilCtrl->getLinkTargetByClass(
398 "ilinternallinkgui",
399 "",
400 false,
401 true,
402 false
403 )
404 ));
405 $this->tpl->parseCurrentBlock();
406 }
407 $form = $this->initAreaEditingForm($a_edit_property);
408 $this->tpl->setVariable("FORM", $form->getHTML());
409 }
410
411 $ilCtrl->setParameter($this, "out_edit_property", $a_edit_property);
412 $ilCtrl->setParameter($this, "out_area_nr", $a_area_nr);
413 $ilCtrl->setParameter($this, "out_output_new_area", (int) $a_output_new_area);
414 $ilCtrl->setParameter($this, "out_area_type", $area_type);
415 $ilCtrl->setParameter($this, "out_coords", $coords);
416
417 $edit_mode = ($a_get_next_coordinate)
418 ? "get_coords"
419 : (($a_output_new_area)
420 ? "new_area"
421 : "");
422
423 $output = $this->getImageMapOutput($edit_mode);
424 $this->tpl->setVariable("IMAGE_MAP", $output);
425
426 return $this->tpl->get();
427 }
428
429 public function initAreaEditingForm(
430 string $a_edit_property
432 $lng = $this->lng;
433
434 $form = new ilPropertyFormGUI();
435 $form->setOpenTag(false);
436 $form->setCloseTag(false);
437
438 // link
439 if ($a_edit_property != "shape") {
440 //
441 $radg = new ilRadioGroupInputGUI($lng->txt("cont_link"), "area_link_type");
442 if ($this->map->getLinkType() != "int") {
443 if ($this->map->getExternalLink() == "") {
444 $radg->setValue("no");
445 } else {
446 $radg->setValue("ext");
447 }
448 } else {
449 $radg->setValue("int");
450 }
451
452 // external link
453 $ext = new ilRadioOption($lng->txt("cont_link_ext"), "ext");
454 $radg->addOption($ext);
455
456 $ti = new ilTextInputGUI("", "area_link_ext");
457 $ti->setMaxLength(800);
458 $ti->setSize(50);
459 if ($this->map->getExternalLink() != "") {
460 $ti->setValue($this->map->getExternalLink());
461 } else {
462 $ti->setValue("https://");
463 }
464 $ext->addSubItem($ti);
465
466 // internal link
467 $int = new ilRadioOption($lng->txt("cont_link_int"), "int");
468 $radg->addOption($int);
469
470 $ne = new ilNonEditableValueGUI("", "", true);
471 $link_str = "";
472 $int_link = $this->map->getInternalLink();
473 if ($int_link["target"] != "") {
474 $link_str = $this->getMapAreaLinkString(
475 $int_link["target"],
476 $int_link["type"],
477 $int_link["target_frame"]
478 );
479 }
480 $ne->setValue(
481 $link_str .
482 '&nbsp;<a id="iosEditInternalLinkTrigger" href="#">' .
483 "[" . $lng->txt("cont_get_link") . "]" .
484 '</a>'
485 );
486 $int->addSubItem($ne);
487
488 // no link
489 $no = new ilRadioOption($lng->txt("cont_link_no"), "no");
490 $radg->addOption($no);
491
492 $form->addItem($radg);
493 }
494
495
496 // name
497 if ($a_edit_property != "link" && $a_edit_property != "shape") {
498 $ti = new ilTextInputGUI($lng->txt("cont_name"), "area_name");
499 $ti->setMaxLength(200);
500 $ti->setSize(20);
501 $form->addItem($ti);
502 }
503
504 // save and cancel commands
505 $form->setTitle($lng->txt("cont_new_area"));
506 $form->addCommandButton("saveArea", $lng->txt("save"));
507
508 // $form->setFormAction($ilCtrl->getFormAction($this));
509
510 return $form;
511 }
512
516 public function makeMapWorkCopy(
517 string $a_edit_property = "",
518 int $a_area_nr = 0,
519 bool $a_output_new_area = false,
520 string $a_area_type = "",
521 string $a_coords = ""
522 ): ilMediaItem {
523 // create/update imagemap work copy
524 $st_item = $this->media_object->getMediaItem("Standard");
525
526 if ($a_edit_property == "shape") {
527 $st_item->makeMapWorkCopy($a_area_nr, true); // exclude area currently being edited
528 } else {
529 $st_item->makeMapWorkCopy($a_area_nr, false);
530 }
531
532 if ($a_output_new_area) {
533 $st_item->addAreaToMapWorkCopy($a_area_type, $a_coords);
534 }
535
536 return $st_item;
537 }
538
542 public function getImageMapOutput(
543 string $a_map_edit_mode = ""
544 ): string {
545 $ilCtrl = $this->ctrl;
546
547 $st_item = $this->media_object->getMediaItem("Standard");
548
549 // output image map
550 $xml = "<dummy>";
551 $xml .= $this->getAliasXML();
552 $xml .= $this->media_object->getXML(IL_MODE_OUTPUT);
553 $xml .= $this->getAdditionalPageXML();
554 $xml .= "</dummy>";
555
556 $wb_path = ilFileUtils::getWebspaceDir("output") . "/";
557 $mode = "media";
558 //echo htmlentities($ilCtrl->getLinkTarget($this, "showImageMap"));
559
560 $random = new \Random\Randomizer();
561 $params = array('map_edit_mode' => $a_map_edit_mode,
562 'map_item' => $st_item->getId(),
563 'map_mob_id' => $this->media_object->getId(),
564 'mode' => $mode,
565 'media_mode' => 'enable',
566 'image_map_link' => $ilCtrl->getLinkTarget($this, "showImageMap", "", false, false),
567 'link_params' => "ref_id=" . $this->request->getRefId() . "&rand=" . $random->getInt(1, 999999),
568 'ref_id' => $this->request->getRefId(),
569 'pg_frame' => "",
570 'enlarge_path' => ilUtil::getImagePath("media/enlarge.svg"),
571 'webspace_path' => $wb_path);
572 $output = $this->xsl->process($xml, $params);
573
574 $output = $this->outputPostProcessing($output);
575
576 return $output;
577 }
578
583 public function getAdditionalPageXML(): string
584 {
585 return "";
586 }
587
588 public function outputPostProcessing(
589 string $a_output
590 ): string {
591 return $a_output;
592 }
593
594 public function getAliasXML(): string
595 {
596 return $this->media_object->getXML(IL_MODE_ALIAS);
597 }
598
605 public function getMapAreaLinkString(
606 string $a_target,
607 string $a_type,
608 string $a_frame
609 ): string {
610 $lng = $this->lng;
611 $frame_str = "";
612 $link_str = "";
613 $t_arr = explode("_", $a_target);
614 if ($a_frame != "") {
615 $frame_str = " (" . $a_frame . " Frame)";
616 }
617 switch ($a_type) {
618 case "StructureObject":
619 $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
620 $link_str = $lng->txt("chapter") .
621 ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
622 break;
623
624 case "PageObject":
625 $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
626 $link_str = $lng->txt("page") .
627 ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
628 break;
629
630 case "GlossaryItem":
631 $term = new ilGlossaryTerm($t_arr[count($t_arr) - 1]);
632 $link_str = $lng->txt("term") .
633 ": " . $term->getTerm() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
634 break;
635
636 case "MediaObject":
637 $mob = new ilObjMediaObject($t_arr[count($t_arr) - 1]);
638 $link_str = $lng->txt("mob") .
639 ": " . $mob->getTitle() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
640 break;
641
642 case "RepositoryItem":
643 if (trim($a_target) !== "") {
644 $title = ilObject::_lookupTitle(
645 ilObject::_lookupObjId((int) $t_arr[count($t_arr) - 1])
646 );
647 $link_str = $lng->txt("obj_" . $t_arr[count($t_arr) - 2]) .
648 ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
649 } else {
650 $title = "";
651 $link_str = "";
652 }
653 break;
654
655 case "WikiPage":
656 $wpg = new ilWikiPage($t_arr[count($t_arr) - 1]);
657 $link_str = $lng->txt("cont_wiki_page") .
658 ": " . $wpg->getTitle() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
659 break;
660
661 }
662
663 return $link_str;
664 }
665
669 public function editImagemapForward(): void
670 {
672
673 $coords = $this->map->getCoords();
674 if ($coords != "") {
675 $coords .= ",";
676 }
677
678 $this->map->setCoords($coords . $this->request->getX() . "," .
679 $this->request->getY());
680
681 // call editing script
682 ilUtil::redirect($this->map->getTargetScript());
683 }
684
688 public static function _recoverParameters(): void
689 {
690 global $DIC;
691
692 $map = $DIC->mediaObjects()->internal()->domain()->imageMap();
693 /*
694 $_GET["ref_id"] = $map->getRefId();
695 $_GET["obj_id"] = $map->getObjId();
696 $_GET["hier_id"] = $map->getHierId();
697 $_GET["pc_id"] = $map->getPCId();*/
698 }
699
703 public function saveArea(): string
704 {
706 $ilCtrl = $this->ctrl;
707
708 switch ($this->map->getMode()) {
709 // save edited link
710 case "edit_link":
711 $st_item = $this->media_object->getMediaItem("Standard");
712 $max = ilMapArea::_getMaxNr($st_item->getId());
713 $area = new ilMapArea($st_item->getId(), $this->map->getAreaNr());
714
715 if ($this->request->getAreaLinkType() == IL_INT_LINK) {
716 $area->setLinkType(IL_INT_LINK);
717 $int_link = $this->map->getInternalLink();
718 $area->setType($int_link["type"] ?? "");
719 $area->setTarget($int_link["target"] ?? "");
720 $area->setTargetFrame($int_link["target_frame"] ?? "");
721 } else {
722 $area->setLinkType(IL_EXT_LINK);
723 if ($this->request->getAreaLinkType() != IL_NO_LINK) {
724 $area->setHref(
725 $this->request->getExternalLink()
726 );
727 } else {
728 $area->setHref("");
729 }
730 }
731 $area->update();
732 break;
733
734 // save edited shape
735 case "edit_shape":
736 $st_item = $this->media_object->getMediaItem("Standard");
737 $max = ilMapArea::_getMaxNr($st_item->getId());
738 $area = new ilMapArea(
739 $st_item->getId(),
740 $this->map->getAreaNr()
741 );
742
743 $area->setShape($this->map->getAreaType());
744 $area->setCoords($this->map->getCoords());
745 $area->update();
746 break;
747
748 // save new area
749 default:
750 $area_type = $this->map->getAreaType();
751 $coords = $this->map->getCoords();
752
753 $st_item = $this->media_object->getMediaItem("Standard");
754 $max = ilMapArea::_getMaxNr($st_item->getId());
755
756 // make new area object
757 $area = new ilMapArea();
758 $area->setItemId($st_item->getId());
759 $area->setShape($area_type);
760 $area->setCoords($coords);
761 $area->setNr($max + 1);
762 $area->setTitle($this->request->getAreaName());
763 switch ($this->request->getAreaLinkType()) {
764 case "ext":
765 $area->setLinkType(IL_EXT_LINK);
766 $area->setHref($this->request->getExternalLink());
767 break;
768
769 case "int":
770 $area->setLinkType(IL_INT_LINK);
771 $int_link = $this->map->getInternalLink();
772 $area->setType($int_link["type"] ?? "");
773 $area->setTarget($int_link["target"] ?? "");
774 $area->setTargetFrame($int_link["type_frame"] ?? "");
775 break;
776 }
777
778 // put area into item and update media object
779 $st_item->addMapArea($area);
780 $this->media_object->update();
781 break;
782 }
783
784 //$this->initMapParameters();
785 $this->main_tpl->setOnScreenMessage('success', $lng->txt("cont_saved_map_area"), true);
786 $ilCtrl->redirect($this, "editMapAreas");
787 return "";
788 }
789
790 public function setInternalLink(): string
791 {
792 $this->map->setLinkType("int");
793 $this->map->setInternalLink(
794 $this->request->getLinkType(),
795 $this->request->getLinkTarget(),
796 $this->request->getLinkTargetFrame(),
797 $this->request->getLinkAnchor()
798 );
799
800 switch ($this->map->getMode()) {
801 case "edit_link":
802 return $this->setLink();
803
804 default:
805 return $this->addArea();
806 }
807 }
808
809 public function setLink(
810 bool $a_handle = true
811 ): string {
812 $lng = $this->lng;
813 $ilCtrl = $this->ctrl;
814 $area = null;
815 if ($a_handle) {
816 $this->handleMapParameters();
817 }
818 if ($this->map->getAreaNr() > 0) {
819 $area_nr = $this->map->getAreaNr();
820 } else {
821 $area = $this->request->getArea();
822 $area_nr = (int) ($area[0] ?? 0);
823 }
824 if ($area_nr === 0) {
825 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
826 $ilCtrl->redirect($this, "editMapAreas");
827 }
828
829 if (count($area ?? []) > 1) {
830 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("cont_select_max_one_item"), true);
831 $ilCtrl->redirect($this, "editMapAreas");
832 }
833
834
835 if ($this->map->getMode() != "edit_link") {
836 $this->map->setAreaNr($area_nr);
837 $this->map->setLinkType($this->getLinkTypeOfArea($area_nr));
838 $this->map->setMode("edit_link");
839 $this->map->setTargetScript($ilCtrl->getLinkTarget($this, "setLink"));
840 if ($this->map->getLinkType() == IL_INT_LINK) {
841 $this->map->setInternalLink(
842 $this->getTypeOfArea($area_nr),
843 $this->getTargetOfArea($area_nr),
844 $this->getTargetFrameOfArea($area_nr),
845 ""
846 );
847 } else {
848 $this->map->setExternalLink($this->getHrefOfArea($area_nr));
849 }
850 }
851
852 return $this->editMapArea(false, false, true, "link", $area_nr);
853 }
854
855 public function getLinkTypeOfArea(
856 int $a_nr
857 ): string {
858 $st_item = $this->media_object->getMediaItem("Standard");
859 $area = $st_item->getMapArea($a_nr);
860 return $area->getLinkType();
861 }
862
866 public function getTypeOfArea(
867 int $a_nr
868 ): string {
869 $st_item = $this->media_object->getMediaItem("Standard");
870 $area = $st_item->getMapArea($a_nr);
871 return $area->getType();
872 }
873
877 public function getTargetOfArea(
878 int $a_nr
879 ): string {
880 $st_item = $this->media_object->getMediaItem("Standard");
881 $area = $st_item->getMapArea($a_nr);
882 return $area->getTarget();
883 }
884
888 public function getTargetFrameOfArea(
889 int $a_nr
890 ): string {
891 $st_item = $this->media_object->getMediaItem("Standard");
892 $area = $st_item->getMapArea($a_nr);
893 return $area->getTargetFrame();
894 }
895
899 public function getHrefOfArea(
900 int $a_nr
901 ): string {
902 $st_item = $this->media_object->getMediaItem("Standard");
903 $area = $st_item->getMapArea($a_nr);
904 return $area->getHref();
905 }
906
910 public function deleteAreas(): void
911 {
912 $ilCtrl = $this->ctrl;
914
915 $area = $this->request->getArea();
916 if (count($area) == 0) {
917 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
918 $ilCtrl->redirect($this, "editMapAreas");
919 }
920
921 $st_item = $this->media_object->getMediaItem("Standard");
922 $max = ilMapArea::_getMaxNr($st_item->getId());
923
924 if (count($area) > 0) {
925 $i = 0;
926
927 foreach ($area as $area_nr) {
928 $st_item->deleteMapArea($area_nr - $i);
929 $i++;
930 }
931
932 $this->media_object->update();
933 $this->main_tpl->setOnScreenMessage('success', $lng->txt("cont_areas_deleted"), true);
934 }
935
936 $ilCtrl->redirect($this, "editMapAreas");
937 }
938
942 public function editLink(): string
943 {
944 $this->map->clear();
945 return $this->setLink(false);
946 }
947
951 public function editShapeWholePicture(): string
952 {
953 $this->clearSessionVars();
954 $this->map->setAreaType("WholePicture");
955 return $this->setShape(false);
956 }
957
961 public function editShapeRectangle(): string
962 {
963 $this->clearSessionVars();
964 $this->map->setAreaType("Rect");
965 return $this->setShape(false);
966 }
967
971 public function editShapeCircle(): string
972 {
973 $this->clearSessionVars();
974 $this->map->setAreaType("Circle");
975 return $this->setShape(false);
976 }
977
981 public function editShapePolygon(): string
982 {
983 $this->clearSessionVars();
984 $this->map->setAreaType("Poly");
985 return $this->setShape(false);
986 }
987
991 public function setShape(
992 bool $a_handle = true
993 ): string {
994 $lng = $this->lng;
995 $ilCtrl = $this->ctrl;
996
997 $area = [];
998 if ($a_handle) {
999 $this->handleMapParameters();
1000 }
1001 if ($this->map->getAreaNr() > 0) {
1002 $area_nr = $this->map->getAreaNr();
1003 } else {
1004 $area = $this->request->getArea();
1005 $area_nr = (int) ($area[0] ?? 0);
1006 }
1007 if ($area_nr === 0) {
1008 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
1009 $ilCtrl->redirect($this, "editMapAreas");
1010 }
1011
1012 if (count($area ?? []) > 1) {
1013 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("cont_select_max_one_item"), true);
1014 $ilCtrl->redirect($this, "editMapAreas");
1015 }
1016
1017 if ($this->map->getMode() != "edit_shape") {
1018 $this->map->setAreaNr($area_nr);
1019 $this->map->setMode("edit_shape");
1020 $this->map->setTargetScript(
1021 $ilCtrl->getLinkTarget($this, "setShape", "", false, false)
1022 );
1023 }
1024
1025
1026 $area_type = $this->map->getAreaType();
1027 $coords = $this->map->getCoords();
1028 $cnt_coords = ilMapArea::countCoords($coords);
1029
1030 // decide what to do next
1031 switch ($area_type) {
1032 // Rectangle
1033 case "Rect":
1034 if ($cnt_coords < 2) {
1035 return $this->editMapArea(true, false, false, "shape", $area_nr);
1036 } elseif ($cnt_coords == 2) {
1037 return $this->saveArea();
1038 }
1039 break;
1040
1041 // Circle
1042 case "Circle":
1043 if ($cnt_coords <= 1) {
1044 return $this->editMapArea(true, false, false, "shape", $area_nr);
1045 } else {
1046 if ($cnt_coords == 2) {
1047 $c = explode(",", $coords);
1048 $coords = $c[0] . "," . $c[1] . ","; // determine radius
1049 $coords .= round(sqrt(pow(abs($c[3] - $c[1]), 2) + pow(abs($c[2] - $c[0]), 2)));
1050 }
1051 $this->map->setCoords($coords);
1052 return $this->saveArea();
1053 }
1054
1055 // Polygon
1056 // no break
1057 case "Poly":
1058 if ($cnt_coords < 1) {
1059 return $this->editMapArea(true, false, false, "shape", $area_nr);
1060 } elseif ($cnt_coords < 3) {
1061 return $this->editMapArea(true, true, false, "shape", $area_nr);
1062 } else {
1063 return $this->editMapArea(true, true, true, "shape", $area_nr);
1064 }
1065
1066 // Whole Picture
1067 // no break
1068 case "WholePicture":
1069 return $this->saveArea();
1070 }
1071 return "";
1072 }
1073
1077 public function setHighlight(): void
1078 {
1079 $ilCtrl = $this->ctrl;
1080 $lng = $this->lng;
1081
1082 $st_item = $this->media_object->getMediaItem("Standard");
1083 // seems to be obsolete, methods don't exist
1084 //$st_item->setHighlightMode($this->request->getHighlightMode());
1085 //$st_item->setHighlightClass($this->request->getHighlightClass());
1086 $st_item->update();
1087
1088 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1089 $ilCtrl->redirect($this, "editMapAreas");
1090 }
1091}
Manages items in repository clipboard.
const IL_INT_LINK
const IL_EXT_LINK
const IL_NO_LINK
const IL_MODE_ALIAS
const IL_MODE_OUTPUT
Class ilCtrl provides processing control methods.
getNextClass($a_gui_class=null)
@inheritDoc
setTargetScript(string $a_target_script)
@inheritDoc
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...
User interface class for map editor.
__construct(ilObjMediaObject $a_media_object)
getHrefOfArea(int $a_nr)
Get Href of Area (only external link)
static _recoverParameters()
Recover parameters from session variables (static)
getTargetFrameOfArea(int $a_nr)
Get TargetFrame of Area (only internal link)
editImagemapForward()
Get image map coordinates.
getTargetOfArea(int $a_nr)
Get Target of Area (only internal link)
initAreaEditingForm(string $a_edit_property)
ilGlobalTemplateInterface $main_tpl
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.
editLink()
Edit existing link.
setLink(bool $a_handle=true)
ILIAS COPage Xsl XslManager $xsl
setShape(bool $a_handle=true)
edit shape of existing map area
getAdditionalPageXML()
Get additional page xml (to be overwritten)
addArea(bool $a_handle=true)
setHighlight()
Set highlight settings.
editShapeWholePicture()
Edit an existing shape (make it a whole picture link)
getMapAreaLinkString(string $a_target, string $a_type, string $a_frame)
Get text name of internal link.
getImageMapOutput(string $a_map_edit_mode="")
Render the image map.
editShapeRectangle()
Edit an existing shape (make it a rectangle)
saveArea()
Save new or updated map area.
getTypeOfArea(int $a_nr)
Get Type of Area (only internal link)
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.
editShapePolygon()
Edit an existing shape (make it a polygon)
editShapeCircle()
Edit an existing shape (make it a circle)
outputPostProcessing(string $a_output)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Internal link selector.
static getInitHTML(string $a_url)
Get initialisation HTML to use internal link editing.
static _lookupTitle(int $a_obj_id)
language handling
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...
Class ilMapArea.
static _getMaxNr(int $a_item_id)
get maximum nr of media item (static)
static countCoords(string $c)
count the number of coordinates (x,y) in a coordinate string (format: "x1,y1,x2,y2,...
Class ilMediaItem Media Item, component of a media object (file or reference)
makeMapWorkCopy(int $a_area_nr=0, bool $a_exclude=false)
make map work copy of image
This class represents a non editable value in a property form.
static includePresentationJS(?ilGlobalTemplateInterface $a_tpl=null)
Include media object presentation JS.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static redirect(string $a_script)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: deliver.php:25
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26