ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
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(): mixed
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 if (!$this->request->hasRow($i)) {
208 continue;
209 }
210 $area = new ilMapArea($st_item->getId(), $i);
211 $area->setTitle(
212 $this->request->getAreaTitle($i)
213 );
214 $area->setHighlightMode(
215 $this->request->getAreaHighlightMode($i)
216 );
217 $area->setHighlightClass(
218 $this->request->getAreaHighlightClass($i)
219 );
220 $area->update();
221 }
222
223 $this->main_tpl->setOnScreenMessage('success', $lng->txt("cont_saved_map_data"), true);
224 $ilCtrl->redirect($this, "editMapAreas");
225 }
226
227 public function addNewArea(): string
228 {
229 switch ($this->request->getAreaShape()) {
230 case "WholePicture": return $this->linkWholePicture();
231 case "Rect": return $this->addRectangle();
232 case "Circle": return $this->addCircle();
233 case "Poly": return $this->addPolygon();
234 }
235 return "";
236 }
237
238 public function linkWholePicture(): string
239 {
240 $this->clearSessionVars();
241 $this->map->setAreaType("WholePicture");
242
243 return $this->editMapArea(false, false, true);
244 }
245
246 public function addRectangle(): string
247 {
248 $this->clearSessionVars();
249 $this->map->setAreaType("Rect");
250 return $this->addArea(false);
251 }
252
253 public function addCircle(): string
254 {
255 $this->clearSessionVars();
256 $this->map->setAreaType("Circle");
257 return $this->addArea(false);
258 }
259
260 public function addPolygon(): string
261 {
262 $this->clearSessionVars();
263 $this->map->setAreaType("Poly");
264 return $this->addArea(false);
265 }
266
267 public function clearSessionVars(): void
268 {
269 $this->map->clear();
270 }
271
272 public function addArea(
273 bool $a_handle = true
274 ): string {
275 // handle map parameters
276 if ($a_handle) {
277 $this->handleMapParameters();
278 }
279
280 $area_type = $this->map->getAreaType();
281 $coords = $this->map->getCoords();
282 $cnt_coords = ilMapArea::countCoords($coords);
283
284 // decide what to do next
285 switch ($area_type) {
286 // Rectangle
287 case "Rect":
288 if ($cnt_coords < 2) {
289 $html = $this->editMapArea(true, false, false);
290 return $html;
291 } elseif ($cnt_coords == 2) {
292 return $this->editMapArea(false, true, true);
293 }
294 break;
295
296 // Circle
297 case "Circle":
298 if ($cnt_coords <= 1) {
299 return $this->editMapArea(true, false, false);
300 } else {
301 if ($cnt_coords == 2) {
302 $c = explode(",", $coords);
303 $coords = $c[0] . "," . $c[1] . ","; // determine radius
304 $coords .= round(sqrt(pow(abs($c[3] - $c[1]), 2) + pow(abs($c[2] - $c[0]), 2)));
305 }
306 $this->map->setCoords($coords);
307
308 return $this->editMapArea(false, true, true);
309 }
310
311 // Polygon
312 // no break
313 case "Poly":
314 if ($cnt_coords < 1) {
315 return $this->editMapArea(true, false, false);
316 } elseif ($cnt_coords < 3) {
317 return $this->editMapArea(true, true, false);
318 } else {
319 return $this->editMapArea(true, true, true);
320 }
321
322 // Whole picture
323 // no break
324 case "WholePicture":
325 return $this->editMapArea(false, false, true);
326 }
327 return "";
328 }
329
339 public function editMapArea(
340 bool $a_get_next_coordinate = false,
341 bool $a_output_new_area = false,
342 bool $a_save_form = false,
343 string $a_edit_property = "",
344 int $a_area_nr = 0
345 ): string {
346 $ilCtrl = $this->ctrl;
348
349 $area_type = $this->map->getAreaType();
350 $coords = $this->map->getCoords();
351 $cnt_coords = ilMapArea::countCoords($coords);
352
353 $this->tpl = new ilTemplate("tpl.map_edit.html", true, true, "components/ILIAS/MediaObjects");
354
355 $this->tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
356
357 if ($a_edit_property != "link") {
358 switch ($area_type) {
359 // rectangle
360 case "Rect":
361 if ($cnt_coords == 0) {
362 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_tl_corner"));
363 }
364 if ($cnt_coords == 1) {
365 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_br_corner"));
366 }
367 break;
368
369 // circle
370 case "Circle":
371 if ($cnt_coords == 0) {
372 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_center"));
373 }
374 if ($cnt_coords == 1) {
375 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_circle"));
376 }
377 break;
378
379 // polygon
380 case "Poly":
381 if ($cnt_coords == 0) {
382 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_starting_point"));
383 } elseif ($cnt_coords < 3) {
384 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_next_point"));
385 } else {
386 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_next_or_save"));
387 }
388 break;
389 }
390 }
391
392
393 // map properties input fields (name and link)
394 if ($a_save_form) {
395 if ($a_edit_property != "shape") {
396 // prepare link gui
397 $ilCtrl->setParameter($this, "linkmode", "map");
398 $this->tpl->setCurrentBlock("int_link_prep");
399 $this->tpl->setVariable("INT_LINK_PREP", ilInternalLinkGUI::getInitHTML(
400 $ilCtrl->getLinkTargetByClass(
401 "ilinternallinkgui",
402 "",
403 false,
404 true,
405 false
406 )
407 ));
408 $this->tpl->parseCurrentBlock();
409 }
410 $form = $this->initAreaEditingForm($a_edit_property);
411 $this->tpl->setVariable("FORM", $form->getHTML());
412 }
413
414 $ilCtrl->setParameter($this, "out_edit_property", $a_edit_property);
415 $ilCtrl->setParameter($this, "out_area_nr", $a_area_nr);
416 $ilCtrl->setParameter($this, "out_output_new_area", (int) $a_output_new_area);
417 $ilCtrl->setParameter($this, "out_area_type", $area_type);
418 $ilCtrl->setParameter($this, "out_coords", $coords);
419
420 $edit_mode = ($a_get_next_coordinate)
421 ? "get_coords"
422 : (($a_output_new_area)
423 ? "new_area"
424 : "");
425
426 $output = $this->getImageMapOutput($edit_mode);
427 $this->tpl->setVariable("IMAGE_MAP", $output);
428
429 return $this->tpl->get();
430 }
431
432 public function initAreaEditingForm(
433 string $a_edit_property
435 $lng = $this->lng;
436
437 $form = new ilPropertyFormGUI();
438 $form->setOpenTag(false);
439 $form->setCloseTag(false);
440
441 // link
442 if ($a_edit_property != "shape") {
443 //
444 $radg = new ilRadioGroupInputGUI($lng->txt("cont_link"), "area_link_type");
445 if ($this->map->getLinkType() != "int") {
446 if ($this->map->getExternalLink() == "") {
447 $radg->setValue("no");
448 } else {
449 $radg->setValue("ext");
450 }
451 } else {
452 $radg->setValue("int");
453 }
454
455 // external link
456 $ext = new ilRadioOption($lng->txt("cont_link_ext"), "ext");
457 $radg->addOption($ext);
458
459 $ti = new ilTextInputGUI("", "area_link_ext");
460 $ti->setMaxLength(800);
461 $ti->setSize(50);
462 if ($this->map->getExternalLink() != "") {
463 $ti->setValue($this->map->getExternalLink());
464 } else {
465 $ti->setValue("https://");
466 }
467 $ext->addSubItem($ti);
468
469 // internal link
470 $int = new ilRadioOption($lng->txt("cont_link_int"), "int");
471 $radg->addOption($int);
472
473 $ne = new ilNonEditableValueGUI("", "", true);
474 $link_str = "";
475 $int_link = $this->map->getInternalLink();
476 if ($int_link["target"] != "") {
477 $link_str = $this->getMapAreaLinkString(
478 $int_link["target"],
479 $int_link["type"],
480 $int_link["target_frame"]
481 );
482 }
483 $ne->setValue(
484 $link_str .
485 '&nbsp;<a id="iosEditInternalLinkTrigger" href="#">' .
486 "[" . $lng->txt("cont_get_link") . "]" .
487 '</a>'
488 );
489 $int->addSubItem($ne);
490
491 // no link
492 $no = new ilRadioOption($lng->txt("cont_link_no"), "no");
493 $radg->addOption($no);
494
495 $form->addItem($radg);
496 }
497
498
499 // name
500 if ($a_edit_property != "link" && $a_edit_property != "shape") {
501 $ti = new ilTextInputGUI($lng->txt("cont_name"), "area_name");
502 $ti->setMaxLength(200);
503 $ti->setSize(20);
504 $form->addItem($ti);
505 }
506
507 // save and cancel commands
508 $form->setTitle($lng->txt("cont_new_area"));
509 $form->addCommandButton("saveArea", $lng->txt("save"));
510
511 // $form->setFormAction($ilCtrl->getFormAction($this));
512
513 return $form;
514 }
515
519 public function makeMapWorkCopy(
520 string $a_edit_property = "",
521 int $a_area_nr = 0,
522 bool $a_output_new_area = false,
523 string $a_area_type = "",
524 string $a_coords = ""
525 ): ilMediaItem {
526 // create/update imagemap work copy
527 $st_item = $this->media_object->getMediaItem("Standard");
528
529 if ($a_edit_property == "shape") {
530 $st_item->makeMapWorkCopy($a_area_nr, true); // exclude area currently being edited
531 } else {
532 $st_item->makeMapWorkCopy($a_area_nr, false);
533 }
534
535 if ($a_output_new_area) {
536 $st_item->addAreaToMapWorkCopy($a_area_type, $a_coords);
537 }
538
539 return $st_item;
540 }
541
545 public function getImageMapOutput(
546 string $a_map_edit_mode = ""
547 ): string {
548 $ilCtrl = $this->ctrl;
549
550 $st_item = $this->media_object->getMediaItem("Standard");
551
552 // output image map
553 $xml = "<dummy>";
554 $xml .= $this->getAliasXML();
555 $xml .= $this->media_object->getXML(IL_MODE_OUTPUT);
556 $xml .= $this->getAdditionalPageXML();
557 $xml .= "</dummy>";
558
559 $wb_path = ilFileUtils::getWebspaceDir("output") . "/";
560 $mode = "media";
561 //echo htmlentities($ilCtrl->getLinkTarget($this, "showImageMap"));
562
563 $random = new \Random\Randomizer();
564 $params = array('map_edit_mode' => $a_map_edit_mode,
565 'map_item' => $st_item->getId(),
566 'map_mob_id' => $this->media_object->getId(),
567 'mode' => $mode,
568 'media_mode' => 'enable',
569 'image_map_link' => $ilCtrl->getLinkTarget($this, "showImageMap", "", false, false),
570 'link_params' => "ref_id=" . $this->request->getRefId() . "&rand=" . $random->getInt(1, 999999),
571 'ref_id' => $this->request->getRefId(),
572 'pg_frame' => "",
573 'enlarge_path' => ilUtil::getImagePath("media/enlarge.svg"),
574 'webspace_path' => $wb_path);
575 $output = $this->xsl->process($xml, $params);
576
577 $output = $this->outputPostProcessing($output);
578
579 return $output;
580 }
581
586 public function getAdditionalPageXML(): string
587 {
588 return "";
589 }
590
591 public function outputPostProcessing(
592 string $a_output
593 ): string {
594 return $a_output;
595 }
596
597 public function getAliasXML(): string
598 {
599 return $this->media_object->getXML(IL_MODE_ALIAS);
600 }
601
608 public function getMapAreaLinkString(
609 string $a_target,
610 string $a_type,
611 string $a_frame
612 ): string {
613 $lng = $this->lng;
614 $frame_str = "";
615 $link_str = "";
616 $t_arr = explode("_", $a_target);
617 if ($a_frame != "") {
618 $frame_str = " (" . $a_frame . " Frame)";
619 }
620 switch ($a_type) {
621 case "StructureObject":
622 $id = (int) $t_arr[count($t_arr) - 1];
625 $link_str = $lng->txt("chapter") .
626 ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
627 }
628 break;
629
630 case "PageObject":
631 $id = (int) $t_arr[count($t_arr) - 1];
634 $link_str = $lng->txt("page") .
635 ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
636 }
637 break;
638
639 case "GlossaryItem":
640 $id = (int) $t_arr[count($t_arr) - 1];
642 $term = new ilGlossaryTerm($id);
643 $link_str = $lng->txt("term") .
644 ": " . $term->getTerm() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
645 }
646 break;
647
648 case "MediaObject":
649 $id = (int) $t_arr[count($t_arr) - 1];
651 $mob = new ilObjMediaObject($id);
652 $link_str = $lng->txt("mob") .
653 ": " . $mob->getTitle() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
654 }
655 break;
656
657 case "RepositoryItem":
658 if (trim($a_target) !== "") {
659 $id = (int) $t_arr[count($t_arr) - 1];
660 $obj_id = ilObject::_lookupObjId($id);
661 if (ilObject::_exists($obj_id)) {
662 $title = ilObject::_lookupTitle(
663 $obj_id
664 );
665 $link_str = $lng->txt("obj_" . $t_arr[count($t_arr) - 2]) .
666 ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
667 }
668 } else {
669 $title = "";
670 $link_str = "";
671 }
672 break;
673
674 case "WikiPage":
675 $id = (int) $t_arr[count($t_arr) - 1];
676 if (ilWikiPage::_exists("wpg", $id)) {
677 $wpg = new ilWikiPage($id);
678 $link_str = $lng->txt("cont_wiki_page") .
679 ": " . $wpg->getTitle() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
680 }
681 break;
682
683 }
684
685 return $link_str;
686 }
687
691 public function editImagemapForward(): void
692 {
694
695 $coords = $this->map->getCoords();
696 if ($coords != "") {
697 $coords .= ",";
698 }
699
700 $this->map->setCoords($coords . $this->request->getX() . "," .
701 $this->request->getY());
702
703 // call editing script
704 ilUtil::redirect($this->map->getTargetScript());
705 }
706
710 public static function _recoverParameters(): void
711 {
712 global $DIC;
713
714 $map = $DIC->mediaObjects()->internal()->domain()->imageMap();
715 /*
716 $_GET["ref_id"] = $map->getRefId();
717 $_GET["obj_id"] = $map->getObjId();
718 $_GET["hier_id"] = $map->getHierId();
719 $_GET["pc_id"] = $map->getPCId();*/
720 }
721
725 public function saveArea(): string
726 {
728 $ilCtrl = $this->ctrl;
729
730 switch ($this->map->getMode()) {
731 // save edited link
732 case "edit_link":
733 $st_item = $this->media_object->getMediaItem("Standard");
734 $max = ilMapArea::_getMaxNr($st_item->getId());
735 $area = new ilMapArea($st_item->getId(), $this->map->getAreaNr());
736
737 if ($this->request->getAreaLinkType() == IL_INT_LINK) {
738 $area->setLinkType(IL_INT_LINK);
739 $int_link = $this->map->getInternalLink();
740 $area->setType($int_link["type"] ?? "");
741 $area->setTarget($int_link["target"] ?? "");
742 $area->setTargetFrame($int_link["target_frame"] ?? "");
743 } else {
744 $area->setLinkType(IL_EXT_LINK);
745 if ($this->request->getAreaLinkType() != IL_NO_LINK) {
746 $area->setHref(
747 $this->request->getExternalLink()
748 );
749 } else {
750 $area->setHref("");
751 }
752 }
753 $area->update();
754 break;
755
756 // save edited shape
757 case "edit_shape":
758 $st_item = $this->media_object->getMediaItem("Standard");
759 $max = ilMapArea::_getMaxNr($st_item->getId());
760 $area = new ilMapArea(
761 $st_item->getId(),
762 $this->map->getAreaNr()
763 );
764
765 $area->setShape($this->map->getAreaType());
766 $area->setCoords($this->map->getCoords());
767 $area->update();
768 break;
769
770 // save new area
771 default:
772 $area_type = $this->map->getAreaType();
773 $coords = $this->map->getCoords();
774
775 $st_item = $this->media_object->getMediaItem("Standard");
776 $max = ilMapArea::_getMaxNr($st_item->getId());
777
778 // make new area object
779 $area = new ilMapArea();
780 $area->setItemId($st_item->getId());
781 $area->setShape($area_type);
782 $area->setCoords($coords);
783 $area->setNr($max + 1);
784 $area->setTitle($this->request->getAreaName());
785 switch ($this->request->getAreaLinkType()) {
786 case "ext":
787 $area->setLinkType(IL_EXT_LINK);
788 $area->setHref($this->request->getExternalLink());
789 break;
790
791 case "int":
792 $area->setLinkType(IL_INT_LINK);
793 $int_link = $this->map->getInternalLink();
794 $area->setType($int_link["type"] ?? "");
795 $area->setTarget($int_link["target"] ?? "");
796 $area->setTargetFrame($int_link["type_frame"] ?? "");
797 break;
798 }
799
800 // put area into item and update media object
801 $st_item->addMapArea($area);
802 $this->media_object->update();
803 break;
804 }
805
806 //$this->initMapParameters();
807 $this->main_tpl->setOnScreenMessage('success', $lng->txt("cont_saved_map_area"), true);
808 $ilCtrl->redirect($this, "editMapAreas");
809 return "";
810 }
811
812 public function setInternalLink(): string
813 {
814 $this->map->setLinkType("int");
815 $this->map->setInternalLink(
816 $this->request->getLinkType(),
817 $this->request->getLinkTarget(),
818 $this->request->getLinkTargetFrame(),
819 $this->request->getLinkAnchor()
820 );
821
822 switch ($this->map->getMode()) {
823 case "edit_link":
824 return $this->setLink();
825
826 default:
827 return $this->addArea();
828 }
829 }
830
831 public function setLink(
832 bool $a_handle = true
833 ): string {
834 $lng = $this->lng;
835 $ilCtrl = $this->ctrl;
836 $area = null;
837 if ($a_handle) {
838 $this->handleMapParameters();
839 }
840 if ($this->map->getAreaNr() > 0) {
841 $area_nr = $this->map->getAreaNr();
842 } else {
843 $area = $this->request->getArea();
844 $area_nr = (int) ($area[0] ?? 0);
845 }
846 if ($area_nr === 0) {
847 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
848 $ilCtrl->redirect($this, "editMapAreas");
849 }
850
851 if (count($area ?? []) > 1) {
852 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("cont_select_max_one_item"), true);
853 $ilCtrl->redirect($this, "editMapAreas");
854 }
855
856
857 if ($this->map->getMode() != "edit_link") {
858 $this->map->setAreaNr($area_nr);
859 $this->map->setLinkType($this->getLinkTypeOfArea($area_nr));
860 $this->map->setMode("edit_link");
861 $this->map->setTargetScript($ilCtrl->getLinkTarget($this, "setLink"));
862 if ($this->map->getLinkType() == IL_INT_LINK) {
863 $this->map->setInternalLink(
864 $this->getTypeOfArea($area_nr),
865 $this->getTargetOfArea($area_nr),
866 $this->getTargetFrameOfArea($area_nr),
867 ""
868 );
869 } else {
870 $this->map->setExternalLink($this->getHrefOfArea($area_nr));
871 }
872 }
873
874 return $this->editMapArea(false, false, true, "link", $area_nr);
875 }
876
877 public function getLinkTypeOfArea(
878 int $a_nr
879 ): string {
880 $st_item = $this->media_object->getMediaItem("Standard");
881 $area = $st_item->getMapArea($a_nr);
882 return $area->getLinkType();
883 }
884
888 public function getTypeOfArea(
889 int $a_nr
890 ): string {
891 $st_item = $this->media_object->getMediaItem("Standard");
892 $area = $st_item->getMapArea($a_nr);
893 return $area->getType();
894 }
895
899 public function getTargetOfArea(
900 int $a_nr
901 ): string {
902 $st_item = $this->media_object->getMediaItem("Standard");
903 $area = $st_item->getMapArea($a_nr);
904 return $area->getTarget();
905 }
906
910 public function getTargetFrameOfArea(
911 int $a_nr
912 ): string {
913 $st_item = $this->media_object->getMediaItem("Standard");
914 $area = $st_item->getMapArea($a_nr);
915 return $area->getTargetFrame();
916 }
917
921 public function getHrefOfArea(
922 int $a_nr
923 ): string {
924 $st_item = $this->media_object->getMediaItem("Standard");
925 $area = $st_item->getMapArea($a_nr);
926 return $area->getHref();
927 }
928
932 public function deleteAreas(): void
933 {
934 $ilCtrl = $this->ctrl;
936
937 $area = $this->request->getArea();
938 if (count($area) == 0) {
939 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
940 $ilCtrl->redirect($this, "editMapAreas");
941 }
942
943 $st_item = $this->media_object->getMediaItem("Standard");
944 $max = ilMapArea::_getMaxNr($st_item->getId());
945
946 if (count($area) > 0) {
947 $i = 0;
948
949 foreach ($area as $area_nr) {
950 $st_item->deleteMapArea($area_nr - $i);
951 $i++;
952 }
953
954 $this->media_object->update();
955 $this->main_tpl->setOnScreenMessage('success', $lng->txt("cont_areas_deleted"), true);
956 }
957
958 $ilCtrl->redirect($this, "editMapAreas");
959 }
960
964 public function editLink(): string
965 {
966 $this->map->clear();
967 return $this->setLink(false);
968 }
969
973 public function editShapeWholePicture(): string
974 {
975 $this->clearSessionVars();
976 $this->map->setAreaType("WholePicture");
977 return $this->setShape(false);
978 }
979
983 public function editShapeRectangle(): string
984 {
985 $this->clearSessionVars();
986 $this->map->setAreaType("Rect");
987 return $this->setShape(false);
988 }
989
993 public function editShapeCircle(): string
994 {
995 $this->clearSessionVars();
996 $this->map->setAreaType("Circle");
997 return $this->setShape(false);
998 }
999
1003 public function editShapePolygon(): string
1004 {
1005 $this->clearSessionVars();
1006 $this->map->setAreaType("Poly");
1007 return $this->setShape(false);
1008 }
1009
1013 public function setShape(
1014 bool $a_handle = true
1015 ): string {
1016 $lng = $this->lng;
1017 $ilCtrl = $this->ctrl;
1018
1019 $area = [];
1020 if ($a_handle) {
1021 $this->handleMapParameters();
1022 }
1023 if ($this->map->getAreaNr() > 0) {
1024 $area_nr = $this->map->getAreaNr();
1025 } else {
1026 $area = $this->request->getArea();
1027 $area_nr = (int) ($area[0] ?? 0);
1028 }
1029 if ($area_nr === 0) {
1030 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
1031 $ilCtrl->redirect($this, "editMapAreas");
1032 }
1033
1034 if (count($area ?? []) > 1) {
1035 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("cont_select_max_one_item"), true);
1036 $ilCtrl->redirect($this, "editMapAreas");
1037 }
1038
1039 if ($this->map->getMode() != "edit_shape") {
1040 $this->map->setAreaNr($area_nr);
1041 $this->map->setMode("edit_shape");
1042 $this->map->setTargetScript(
1043 $ilCtrl->getLinkTarget($this, "setShape", "", false, false)
1044 );
1045 }
1046
1047
1048 $area_type = $this->map->getAreaType();
1049 $coords = $this->map->getCoords();
1050 $cnt_coords = ilMapArea::countCoords($coords);
1051
1052 // decide what to do next
1053 switch ($area_type) {
1054 // Rectangle
1055 case "Rect":
1056 if ($cnt_coords < 2) {
1057 return $this->editMapArea(true, false, false, "shape", $area_nr);
1058 } elseif ($cnt_coords == 2) {
1059 return $this->saveArea();
1060 }
1061 break;
1062
1063 // Circle
1064 case "Circle":
1065 if ($cnt_coords <= 1) {
1066 return $this->editMapArea(true, false, false, "shape", $area_nr);
1067 } else {
1068 if ($cnt_coords == 2) {
1069 $c = explode(",", $coords);
1070 $coords = $c[0] . "," . $c[1] . ","; // determine radius
1071 $coords .= round(sqrt(pow(abs($c[3] - $c[1]), 2) + pow(abs($c[2] - $c[0]), 2)));
1072 }
1073 $this->map->setCoords($coords);
1074 return $this->saveArea();
1075 }
1076
1077 // Polygon
1078 // no break
1079 case "Poly":
1080 if ($cnt_coords < 1) {
1081 return $this->editMapArea(true, false, false, "shape", $area_nr);
1082 } elseif ($cnt_coords < 3) {
1083 return $this->editMapArea(true, true, false, "shape", $area_nr);
1084 } else {
1085 return $this->editMapArea(true, true, true, "shape", $area_nr);
1086 }
1087
1088 // Whole Picture
1089 // no break
1090 case "WholePicture":
1091 return $this->saveArea();
1092 }
1093 return "";
1094 }
1095
1099 public function setHighlight(): void
1100 {
1101 $ilCtrl = $this->ctrl;
1102 $lng = $this->lng;
1103
1104 $st_item = $this->media_object->getMediaItem("Standard");
1105 // seems to be obsolete, methods don't exist
1106 //$st_item->setHighlightMode($this->request->getHighlightMode());
1107 //$st_item->setHighlightClass($this->request->getHighlightClass());
1108 $st_item->update();
1109
1110 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1111 $ilCtrl->redirect($this, "editMapAreas");
1112 }
1113}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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...
static _exists(int $a_id)
checks whether a glossary term with specified id exists or not
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 _exists(int $a_id)
checks wether a lm content object with specified id exists or not
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 _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
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:26
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26