ILIAS  release_8 Revision v8.24
class.ilImageMapEditorGUI.php
Go to the documentation of this file.
1<?php
2
21
28{
32 protected ilTemplate $tpl;
34 protected ilCtrl $ctrl;
35 protected ilLanguage $lng;
37
38 public function __construct(
39 ilObjMediaObject $a_media_object
40 ) {
41 global $DIC;
42
43 $this->ctrl = $DIC->ctrl();
44 $this->main_tpl = $DIC->ui()->mainTemplate();
45 $this->lng = $DIC->language();
46 $this->toolbar = $DIC->toolbar();
47 $this->media_object = $a_media_object;
48
49 $this->map = $DIC->mediaObjects()
50 ->internal()
51 ->domain()
52 ->imageMap();
53
54 $this->request = $DIC->mediaObjects()
55 ->internal()
56 ->gui()
57 ->imageMap()
58 ->request();
59 }
60
65 public function executeCommand()
66 {
67 $ilCtrl = $this->ctrl;
68
69 $next_class = $ilCtrl->getNextClass($this);
70 $cmd = $ilCtrl->getCmd();
71
72 switch ($next_class) {
73 case "ilinternallinkgui":
74 $link_gui = new ilInternalLinkGUI("Media_Media", 0);
75 $link_gui->setSetLinkTargetScript(
76 $ilCtrl->getLinkTarget(
77 $this,
78 "setInternalLink"
79 )
80 );
81 $link_gui->filterLinkType("File");
82 $ret = $ilCtrl->forwardCommand($link_gui);
83 break;
84
85 default:
87 if ($this->request->getX() != "" &&
88 $this->request->getY() != "") {
89 $cmd = "editImagemapForward";
90 }
91 $ret = $this->$cmd();
92 break;
93 }
94 return $ret;
95 }
96
97 public function editMapAreas(): string
98 {
99 $ilCtrl = $this->ctrl;
100
101 $this->map->setTargetScript(
102 $ilCtrl->getLinkTarget(
103 $this,
104 "addArea",
105 "",
106 false,
107 false
108 )
109 );
110 $this->handleMapParameters();
111
112 $this->tpl = new ilTemplate("tpl.map_edit.html", true, true, "Services/MediaObjects");
113 $this->tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
114
115 // create/update imagemap work copy
116 $this->makeMapWorkCopy();
117
118 $output = $this->getImageMapOutput();
119 $this->tpl->setVariable("IMAGE_MAP", $output);
120
121 $this->tpl->setVariable("TOOLBAR", $this->getToolbar()->getHTML());
122
123 // table
124 $this->tpl->setVariable("MAP_AREA_TABLE", $this->getImageMapTableHTML());
125
126 return $this->tpl->get();
127 }
128
129 public function getToolbar(): ilToolbarGUI
130 {
131 $ilCtrl = $this->ctrl;
133
134 // toolbar
135 $tb = new ilToolbarGUI();
136 $tb->setFormAction($ilCtrl->getFormAction($this));
137 $options = array(
138 "WholePicture" => $lng->txt("cont_WholePicture"),
139 "Rect" => $lng->txt("cont_Rect"),
140 "Circle" => $lng->txt("cont_Circle"),
141 "Poly" => $lng->txt("cont_Poly"),
142 );
143 $si = new ilSelectInputGUI($lng->txt("cont_shape"), "shape");
144 $si->setOptions($options);
145 $tb->addInputItem($si, true);
146 $tb->addFormButton($lng->txt("cont_add_area"), "addNewArea");
147
148 return $tb;
149 }
150
151 public function getEditorTitle(): string
152 {
154 return $lng->txt("cont_imagemap");
155 }
156
157
158 public function getImageMapTableHTML(): string
159 {
160 $image_map_table = new ilImageMapTableGUI($this, "editMapAreas", $this->media_object);
161 return $image_map_table->getHTML();
162 }
163
164 public function handleMapParameters(): void
165 {
166 if ($this->request->getRefId() > 0) {
167 $this->map->setRefId($this->request->getRefId());
168 }
169
170 if ($this->request->getObjId() > 0) {
171 $this->map->setObjId($this->request->getObjId());
172 }
173
174 if ($this->request->getHierId() != "") {
175 $this->map->setHierId($this->request->getHierId());
176 }
177
178 if ($this->request->getPCId() != "") {
179 $this->map->setPCId($this->request->getPCId());
180 }
181 }
182
183 public function showImageMap(): void
184 {
185 $item = new ilMediaItem($this->request->getItemId());
186 $item->outputMapWorkCopy();
187 }
188
189 public function updateAreas(): void
190 {
192 $ilCtrl = $this->ctrl;
193
194 $st_item = $this->media_object->getMediaItem("Standard");
195 $max = ilMapArea::_getMaxNr($st_item->getId());
196 for ($i = 1; $i <= $max; $i++) {
197 $area = new ilMapArea($st_item->getId(), $i);
198 $area->setTitle(
199 $this->request->getAreaTitle($i)
200 );
201 $area->setHighlightMode(
202 $this->request->getAreaHighlightMode($i)
203 );
204 $area->setHighlightClass(
205 $this->request->getAreaHighlightClass($i)
206 );
207 $area->update();
208 }
209
210 $this->main_tpl->setOnScreenMessage('success', $lng->txt("cont_saved_map_data"), true);
211 $ilCtrl->redirect($this, "editMapAreas");
212 }
213
214 public function addNewArea(): string
215 {
216 switch ($this->request->getAreaShape()) {
217 case "WholePicture": return $this->linkWholePicture();
218 case "Rect": return $this->addRectangle();
219 case "Circle": return $this->addCircle();
220 case "Poly": return $this->addPolygon();
221 }
222 return "";
223 }
224
225 public function linkWholePicture(): string
226 {
227 $this->clearSessionVars();
228 $this->map->setAreaType("WholePicture");
229
230 return $this->editMapArea(false, false, true);
231 }
232
233 public function addRectangle(): string
234 {
235 $this->clearSessionVars();
236 $this->map->setAreaType("Rect");
237 return $this->addArea(false);
238 }
239
240 public function addCircle(): string
241 {
242 $this->clearSessionVars();
243 $this->map->setAreaType("Circle");
244 return $this->addArea(false);
245 }
246
247 public function addPolygon(): string
248 {
249 $this->clearSessionVars();
250 $this->map->setAreaType("Poly");
251 return $this->addArea(false);
252 }
253
254 public function clearSessionVars(): void
255 {
256 $this->map->clear();
257 }
258
259 public function addArea(
260 bool $a_handle = true
261 ): string {
262
263 // handle map parameters
264 if ($a_handle) {
265 $this->handleMapParameters();
266 }
267
268 $area_type = $this->map->getAreaType();
269 $coords = $this->map->getCoords();
270 $cnt_coords = ilMapArea::countCoords($coords);
271
272 // decide what to do next
273 switch ($area_type) {
274 // Rectangle
275 case "Rect":
276 if ($cnt_coords < 2) {
277 $html = $this->editMapArea(true, false, false);
278 return $html;
279 } elseif ($cnt_coords == 2) {
280 return $this->editMapArea(false, true, true);
281 }
282 break;
283
284 // Circle
285 case "Circle":
286 if ($cnt_coords <= 1) {
287 return $this->editMapArea(true, false, false);
288 } else {
289 if ($cnt_coords == 2) {
290 $c = explode(",", $coords);
291 $coords = $c[0] . "," . $c[1] . ","; // determine radius
292 $coords .= round(sqrt(pow(abs($c[3] - $c[1]), 2) + pow(abs($c[2] - $c[0]), 2)));
293 }
294 $this->map->setCoords($coords);
295
296 return $this->editMapArea(false, true, true);
297 }
298
299 // Polygon
300 // no break
301 case "Poly":
302 if ($cnt_coords < 1) {
303 return $this->editMapArea(true, false, false);
304 } elseif ($cnt_coords < 3) {
305 return $this->editMapArea(true, true, false);
306 } else {
307 return $this->editMapArea(true, true, true);
308 }
309
310 // Whole picture
311 // no break
312 case "WholePicture":
313 return $this->editMapArea(false, false, true);
314 }
315 return "";
316 }
317
327 public function editMapArea(
328 bool $a_get_next_coordinate = false,
329 bool $a_output_new_area = false,
330 bool $a_save_form = false,
331 string $a_edit_property = "",
332 int $a_area_nr = 0
333 ): string {
334 $ilCtrl = $this->ctrl;
336
337 $area_type = $this->map->getAreaType();
338 $coords = $this->map->getCoords();
339 $cnt_coords = ilMapArea::countCoords($coords);
340
341 $this->tpl = new ilTemplate("tpl.map_edit.html", true, true, "Services/MediaObjects");
342
343 $this->tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
344
345 if ($a_edit_property != "link") {
346 switch ($area_type) {
347 // rectangle
348 case "Rect":
349 if ($cnt_coords == 0) {
350 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_tl_corner"));
351 }
352 if ($cnt_coords == 1) {
353 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_br_corner"));
354 }
355 break;
356
357 // circle
358 case "Circle":
359 if ($cnt_coords == 0) {
360 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_center"));
361 }
362 if ($cnt_coords == 1) {
363 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_circle"));
364 }
365 break;
366
367 // polygon
368 case "Poly":
369 if ($cnt_coords == 0) {
370 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_starting_point"));
371 } elseif ($cnt_coords < 3) {
372 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_next_point"));
373 } else {
374 $this->main_tpl->setOnScreenMessage('info', $lng->txt("cont_click_next_or_save"));
375 }
376 break;
377 }
378 }
379
380
381 // map properties input fields (name and link)
382 if ($a_save_form) {
383 if ($a_edit_property != "shape") {
384 // prepare link gui
385 $ilCtrl->setParameter($this, "linkmode", "map");
386 $this->tpl->setCurrentBlock("int_link_prep");
387 $this->tpl->setVariable("INT_LINK_PREP", ilInternalLinkGUI::getInitHTML(
388 $ilCtrl->getLinkTargetByClass(
389 "ilinternallinkgui",
390 "",
391 false,
392 true,
393 false
394 )
395 ));
396 $this->tpl->parseCurrentBlock();
397 }
398 $form = $this->initAreaEditingForm($a_edit_property);
399 $this->tpl->setVariable("FORM", $form->getHTML());
400 }
401
402 $this->makeMapWorkCopy(
403 $a_edit_property,
404 $a_area_nr,
405 $a_output_new_area,
406 $area_type,
407 $coords
408 );
409
410 $edit_mode = ($a_get_next_coordinate)
411 ? "get_coords"
412 : (($a_output_new_area)
413 ? "new_area"
414 : "");
415 $output = $this->getImageMapOutput($edit_mode);
416 $this->tpl->setVariable("IMAGE_MAP", $output);
417
418 return $this->tpl->get();
419 }
420
421 public function initAreaEditingForm(
422 string $a_edit_property
424 $lng = $this->lng;
425
426 $form = new ilPropertyFormGUI();
427 $form->setOpenTag(false);
428 $form->setCloseTag(false);
429
430 // link
431 if ($a_edit_property != "shape") {
432 //
433 $radg = new ilRadioGroupInputGUI($lng->txt("cont_link"), "area_link_type");
434 if ($this->map->getLinkType() != "int") {
435 if ($this->map->getExternalLink() == "") {
436 $radg->setValue("no");
437 } else {
438 $radg->setValue("ext");
439 }
440 } else {
441 $radg->setValue("int");
442 }
443
444 // external link
445 $ext = new ilRadioOption($lng->txt("cont_link_ext"), "ext");
446 $radg->addOption($ext);
447
448 $ti = new ilTextInputGUI("", "area_link_ext");
449 $ti->setMaxLength(800);
450 $ti->setSize(50);
451 if ($this->map->getExternalLink() != "") {
452 $ti->setValue($this->map->getExternalLink());
453 } else {
454 $ti->setValue("https://");
455 }
456 $ext->addSubItem($ti);
457
458 // internal link
459 $int = new ilRadioOption($lng->txt("cont_link_int"), "int");
460 $radg->addOption($int);
461
462 $ne = new ilNonEditableValueGUI("", "", true);
463 $link_str = "";
464 $int_link = $this->map->getInternalLink();
465 if ($int_link["target"] != "") {
466 $link_str = $this->getMapAreaLinkString(
467 $int_link["target"],
468 $int_link["type"],
469 $int_link["target_frame"]
470 );
471 }
472 $ne->setValue(
473 $link_str .
474 '&nbsp;<a id="iosEditInternalLinkTrigger" href="#">' .
475 "[" . $lng->txt("cont_get_link") . "]" .
476 '</a>'
477 );
478 $int->addSubItem($ne);
479
480 // no link
481 $no = new ilRadioOption($lng->txt("cont_link_no"), "no");
482 $radg->addOption($no);
483
484 $form->addItem($radg);
485 }
486
487
488 // name
489 if ($a_edit_property != "link" && $a_edit_property != "shape") {
490 $ti = new ilTextInputGUI($lng->txt("cont_name"), "area_name");
491 $ti->setMaxLength(200);
492 $ti->setSize(20);
493 $form->addItem($ti);
494 }
495
496 // save and cancel commands
497 $form->setTitle($lng->txt("cont_new_area"));
498 $form->addCommandButton("saveArea", $lng->txt("save"));
499
500 // $form->setFormAction($ilCtrl->getFormAction($this));
501
502 return $form;
503 }
504
508 public function makeMapWorkCopy(
509 string $a_edit_property = "",
510 int $a_area_nr = 0,
511 bool $a_output_new_area = false,
512 string $a_area_type = "",
513 string $a_coords = ""
514 ): void {
515 // create/update imagemap work copy
516 $st_item = $this->media_object->getMediaItem("Standard");
517
518 if ($a_edit_property == "shape") {
519 $st_item->makeMapWorkCopy($a_area_nr, true); // exclude area currently being edited
520 } else {
521 $st_item->makeMapWorkCopy($a_area_nr, false);
522 }
523
524 if ($a_output_new_area) {
525 $st_item->addAreaToMapWorkCopy($a_area_type, $a_coords);
526 }
527 }
528
532 public function getImageMapOutput(
533 string $a_map_edit_mode = ""
534 ): string {
535 $ilCtrl = $this->ctrl;
536
537 $st_item = $this->media_object->getMediaItem("Standard");
538
539 // output image map
540 $xml = "<dummy>";
541 $xml .= $this->getAliasXML();
542 $xml .= $this->media_object->getXML(IL_MODE_OUTPUT);
543 $xml .= $this->getAdditionalPageXML();
544 $xml .= "</dummy>";
545 $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
546 //echo htmlentities($xml); exit;
547 $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
548 $xh = xslt_create();
549 $wb_path = ilFileUtils::getWebspaceDir("output") . "/";
550 $mode = "media";
551 //echo htmlentities($ilCtrl->getLinkTarget($this, "showImageMap"));
552
553 $random = new \ilRandom();
554 $params = array('map_edit_mode' => $a_map_edit_mode,
555 'map_item' => $st_item->getId(),
556 'map_mob_id' => $this->media_object->getId(),
557 'mode' => $mode,
558 'media_mode' => 'enable',
559 'image_map_link' => $ilCtrl->getLinkTarget($this, "showImageMap", "", false, false),
560 'link_params' => "ref_id=" . $this->request->getRefId() . "&rand=" . $random->int(1, 999999),
561 'ref_id' => $this->request->getRefId(),
562 'pg_frame' => "",
563 'enlarge_path' => ilUtil::getImagePath("enlarge.svg"),
564 'webspace_path' => $wb_path);
565 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, $params);
566 xslt_error($xh);
567 xslt_free($xh);
568
569 $output = $this->outputPostProcessing($output);
570
571 return $output;
572 }
573
578 public function getAdditionalPageXML(): string
579 {
580 return "";
581 }
582
583 public function outputPostProcessing(
584 string $a_output
585 ): string {
586 return $a_output;
587 }
588
589 public function getAliasXML(): string
590 {
591 return $this->media_object->getXML(IL_MODE_ALIAS);
592 }
593
600 public function getMapAreaLinkString(
601 string $a_target,
602 string $a_type,
603 string $a_frame
604 ): string {
605 $lng = $this->lng;
606 $frame_str = "";
607 $link_str = "";
608 $t_arr = explode("_", $a_target);
609 if ($a_frame != "") {
610 $frame_str = " (" . $a_frame . " Frame)";
611 }
612 switch ($a_type) {
613 case "StructureObject":
614 $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
615 $link_str = $lng->txt("chapter") .
616 ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
617 break;
618
619 case "PageObject":
620 $title = ilLMObject::_lookupTitle($t_arr[count($t_arr) - 1]);
621 $link_str = $lng->txt("page") .
622 ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
623 break;
624
625 case "GlossaryItem":
626 $term = new ilGlossaryTerm($t_arr[count($t_arr) - 1]);
627 $link_str = $lng->txt("term") .
628 ": " . $term->getTerm() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
629 break;
630
631 case "MediaObject":
632 $mob = new ilObjMediaObject($t_arr[count($t_arr) - 1]);
633 $link_str = $lng->txt("mob") .
634 ": " . $mob->getTitle() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
635 break;
636
637 case "RepositoryItem":
638 if (trim($a_target) !== "") {
639 $title = ilObject::_lookupTitle(
640 ilObject::_lookupObjId((int) $t_arr[count($t_arr) - 1])
641 );
642 $link_str = $lng->txt("obj_" . $t_arr[count($t_arr) - 2]) .
643 ": " . $title . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
644 } else {
645 $title = "";
646 $link_str = "";
647 }
648 break;
649
650 case "WikiPage":
651 $wpg = new ilWikiPage($t_arr[count($t_arr) - 1]);
652 $link_str = $lng->txt("cont_wiki_page") .
653 ": " . $wpg->getTitle() . " [" . $t_arr[count($t_arr) - 1] . "]" . $frame_str;
654 break;
655
656 }
657
658 return $link_str;
659 }
660
664 public function editImagemapForward(): void
665 {
667
668 $coords = $this->map->getCoords();
669 if ($coords != "") {
670 $coords .= ",";
671 }
672
673 $this->map->setCoords($coords . $this->request->getX() . "," .
674 $this->request->getY());
675
676 // call editing script
677 ilUtil::redirect($this->map->getTargetScript());
678 }
679
683 public static function _recoverParameters(): void
684 {
685 global $DIC;
686
687 $map = $DIC->mediaObjects()->internal()->domain()->imageMap();
688 /*
689 $_GET["ref_id"] = $map->getRefId();
690 $_GET["obj_id"] = $map->getObjId();
691 $_GET["hier_id"] = $map->getHierId();
692 $_GET["pc_id"] = $map->getPCId();*/
693 }
694
698 public function saveArea(): string
699 {
701 $ilCtrl = $this->ctrl;
702
703 switch ($this->map->getMode()) {
704 // save edited link
705 case "edit_link":
706 $st_item = $this->media_object->getMediaItem("Standard");
707 $max = ilMapArea::_getMaxNr($st_item->getId());
708 $area = new ilMapArea($st_item->getId(), $this->map->getAreaNr());
709
710 if ($this->request->getAreaLinkType() == IL_INT_LINK) {
711 $area->setLinkType(IL_INT_LINK);
712 $int_link = $this->map->getInternalLink();
713 $area->setType($int_link["type"] ?? "");
714 $area->setTarget($int_link["target"] ?? "");
715 $area->setTargetFrame($int_link["target_frame"] ?? "");
716 } else {
717 $area->setLinkType(IL_EXT_LINK);
718 if ($this->request->getAreaLinkType() != IL_NO_LINK) {
719 $area->setHref(
720 $this->request->getExternalLink()
721 );
722 } else {
723 $area->setHref("");
724 }
725 }
726 $area->update();
727 break;
728
729 // save edited shape
730 case "edit_shape":
731 $st_item = $this->media_object->getMediaItem("Standard");
732 $max = ilMapArea::_getMaxNr($st_item->getId());
733 $area = new ilMapArea(
734 $st_item->getId(),
735 $this->map->getAreaNr()
736 );
737
738 $area->setShape($this->map->getAreaType());
739 $area->setCoords($this->map->getCoords());
740 $area->update();
741 break;
742
743 // save new area
744 default:
745 $area_type = $this->map->getAreaType();
746 $coords = $this->map->getCoords();
747
748 $st_item = $this->media_object->getMediaItem("Standard");
749 $max = ilMapArea::_getMaxNr($st_item->getId());
750
751 // make new area object
752 $area = new ilMapArea();
753 $area->setItemId($st_item->getId());
754 $area->setShape($area_type);
755 $area->setCoords($coords);
756 $area->setNr($max + 1);
757 $area->setTitle($this->request->getAreaName());
758 switch ($this->request->getAreaLinkType()) {
759 case "ext":
760 $area->setLinkType(IL_EXT_LINK);
761 $area->setHref($this->request->getExternalLink());
762 break;
763
764 case "int":
765 $area->setLinkType(IL_INT_LINK);
766 $int_link = $this->map->getInternalLink();
767 $area->setType($int_link["type"] ?? "");
768 $area->setTarget($int_link["target"] ?? "");
769 $area->setTargetFrame($int_link["type_frame"] ?? "");
770 break;
771 }
772
773 // put area into item and update media object
774 $st_item->addMapArea($area);
775 $this->media_object->update();
776 break;
777 }
778
779 //$this->initMapParameters();
780 $this->main_tpl->setOnScreenMessage('success', $lng->txt("cont_saved_map_area"), true);
781 $ilCtrl->redirect($this, "editMapAreas");
782 return "";
783 }
784
785 public function setInternalLink(): string
786 {
787 $this->map->setLinkType("int");
788 $this->map->setInternalLink(
789 $this->request->getLinkType(),
790 $this->request->getLinkTarget(),
791 $this->request->getLinkTargetFrame(),
792 $this->request->getLinkAnchor()
793 );
794
795 switch ($this->map->getMode()) {
796 case "edit_link":
797 return $this->setLink();
798
799 default:
800 return $this->addArea();
801 }
802 }
803
804 public function setLink(
805 bool $a_handle = true
806 ): string {
807 $lng = $this->lng;
808 $ilCtrl = $this->ctrl;
809 $area = null;
810 if ($a_handle) {
811 $this->handleMapParameters();
812 }
813 if ($this->map->getAreaNr() > 0) {
814 $area_nr = $this->map->getAreaNr();
815 } else {
816 $area = $this->request->getArea();
817 $area_nr = (int) ($area[0] ?? 0);
818 }
819 if ($area_nr === 0) {
820 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
821 $ilCtrl->redirect($this, "editMapAreas");
822 }
823
824 if (count($area ?? []) > 1) {
825 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("cont_select_max_one_item"), true);
826 $ilCtrl->redirect($this, "editMapAreas");
827 }
828
829
830 if ($this->map->getMode() != "edit_link") {
831 $this->map->setAreaNr($area_nr);
832 $this->map->setLinkType($this->getLinkTypeOfArea($area_nr));
833 $this->map->setMode("edit_link");
834 $this->map->setTargetScript($ilCtrl->getLinkTarget($this, "setLink"));
835 if ($this->map->getLinkType() == IL_INT_LINK) {
836 $this->map->setInternalLink(
837 $this->getTypeOfArea($area_nr),
838 $this->getTargetOfArea($area_nr),
839 $this->getTargetFrameOfArea($area_nr),
840 ""
841 );
842 } else {
843 $this->map->setExternalLink($this->getHrefOfArea($area_nr));
844 }
845 }
846
847 return $this->editMapArea(false, false, true, "link", $area_nr);
848 }
849
850 public function getLinkTypeOfArea(
851 int $a_nr
852 ): string {
853 $st_item = $this->media_object->getMediaItem("Standard");
854 $area = $st_item->getMapArea($a_nr);
855 return $area->getLinkType();
856 }
857
861 public function getTypeOfArea(
862 int $a_nr
863 ): string {
864 $st_item = $this->media_object->getMediaItem("Standard");
865 $area = $st_item->getMapArea($a_nr);
866 return $area->getType();
867 }
868
872 public function getTargetOfArea(
873 int $a_nr
874 ): string {
875 $st_item = $this->media_object->getMediaItem("Standard");
876 $area = $st_item->getMapArea($a_nr);
877 return $area->getTarget();
878 }
879
883 public function getTargetFrameOfArea(
884 int $a_nr
885 ): string {
886 $st_item = $this->media_object->getMediaItem("Standard");
887 $area = $st_item->getMapArea($a_nr);
888 return $area->getTargetFrame();
889 }
890
894 public function getHrefOfArea(
895 int $a_nr
896 ): string {
897 $st_item = $this->media_object->getMediaItem("Standard");
898 $area = $st_item->getMapArea($a_nr);
899 return $area->getHref();
900 }
901
905 public function deleteAreas(): void
906 {
907 $ilCtrl = $this->ctrl;
909
910 $area = $this->request->getArea();
911 if (count($area) == 0) {
912 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
913 $ilCtrl->redirect($this, "editMapAreas");
914 }
915
916 $st_item = $this->media_object->getMediaItem("Standard");
917 $max = ilMapArea::_getMaxNr($st_item->getId());
918
919 if (count($area) > 0) {
920 $i = 0;
921
922 foreach ($area as $area_nr) {
923 $st_item->deleteMapArea($area_nr - $i);
924 $i++;
925 }
926
927 $this->media_object->update();
928 $this->main_tpl->setOnScreenMessage('success', $lng->txt("cont_areas_deleted"), true);
929 }
930
931 $ilCtrl->redirect($this, "editMapAreas");
932 }
933
937 public function editLink(): string
938 {
939 $this->map->clear();
940 return $this->setLink(false);
941 }
942
946 public function editShapeWholePicture(): string
947 {
948 $this->clearSessionVars();
949 $this->map->setAreaType("WholePicture");
950 return $this->setShape(false);
951 }
952
956 public function editShapeRectangle(): string
957 {
958 $this->clearSessionVars();
959 $this->map->setAreaType("Rect");
960 return $this->setShape(false);
961 }
962
966 public function editShapeCircle(): string
967 {
968 $this->clearSessionVars();
969 $this->map->setAreaType("Circle");
970 return $this->setShape(false);
971 }
972
976 public function editShapePolygon(): string
977 {
978 $this->clearSessionVars();
979 $this->map->setAreaType("Poly");
980 return $this->setShape(false);
981 }
982
986 public function setShape(
987 bool $a_handle = true
988 ): string {
989 $lng = $this->lng;
990 $ilCtrl = $this->ctrl;
991
992 $area = [];
993 if ($a_handle) {
994 $this->handleMapParameters();
995 }
996 /* this seems to be obsolete
997 if ($_POST["areatype2"] != "") {
998 $this->map->setAreaType($_POST["areatype2"]);
999 }*/
1000 if ($this->map->getAreaNr() > 0) {
1001 $area_nr = $this->map->getAreaNr();
1002 } else {
1003 $area = $this->request->getArea();
1004 $area_nr = (int) ($area[0] ?? 0);
1005 }
1006 if ($area_nr === 0) {
1007 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
1008 $ilCtrl->redirect($this, "editMapAreas");
1009 }
1010
1011 if (count($area ?? []) > 1) {
1012 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("cont_select_max_one_item"), true);
1013 $ilCtrl->redirect($this, "editMapAreas");
1014 }
1015
1016 if ($this->map->getMode() != "edit_shape") {
1017 $this->map->setAreaNr($area_nr);
1018 $this->map->setMode("edit_shape");
1019 $this->map->setTargetScript(
1020 $ilCtrl->getLinkTarget($this, "setShape", "", false, false)
1021 );
1022 }
1023
1024
1025 $area_type = $this->map->getAreaType();
1026 $coords = $this->map->getCoords();
1027 $cnt_coords = ilMapArea::countCoords($coords);
1028
1029 // decide what to do next
1030 switch ($area_type) {
1031 // Rectangle
1032 case "Rect":
1033 if ($cnt_coords < 2) {
1034 return $this->editMapArea(true, false, false, "shape", $area_nr);
1035 } elseif ($cnt_coords == 2) {
1036 return $this->saveArea();
1037 }
1038 break;
1039
1040 // Circle
1041 case "Circle":
1042 if ($cnt_coords <= 1) {
1043 return $this->editMapArea(true, false, false, "shape", $area_nr);
1044 } else {
1045 if ($cnt_coords == 2) {
1046 $c = explode(",", $coords);
1047 $coords = $c[0] . "," . $c[1] . ","; // determine radius
1048 $coords .= round(sqrt(pow(abs($c[3] - $c[1]), 2) + pow(abs($c[2] - $c[0]), 2)));
1049 }
1050 $this->map->setCoords($coords);
1051 return $this->saveArea();
1052 }
1053
1054 // Polygon
1055 // no break
1056 case "Poly":
1057 if ($cnt_coords < 1) {
1058 return $this->editMapArea(true, false, false, "shape", $area_nr);
1059 } elseif ($cnt_coords < 3) {
1060 return $this->editMapArea(true, true, false, "shape", $area_nr);
1061 } else {
1062 return $this->editMapArea(true, true, true, "shape", $area_nr);
1063 }
1064
1065 // Whole Picture
1066 // no break
1067 case "WholePicture":
1068 return $this->saveArea();
1069 }
1070 return "";
1071 }
1072
1076 public function setHighlight(): void
1077 {
1078 $ilCtrl = $this->ctrl;
1079 $lng = $this->lng;
1080
1081 $st_item = $this->media_object->getMediaItem("Standard");
1082 // seems to be obsolete, methods don't exist
1083 //$st_item->setHighlightMode($this->request->getHighlightMode());
1084 //$st_item->setHighlightClass($this->request->getHighlightClass());
1085 $st_item->update();
1086
1087 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1088 $ilCtrl->redirect($this, "editMapAreas");
1089 }
1090}
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)
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,...
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...
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 file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 $img, 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: cli.php:38
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
xslt_error(&$proc)
xslt_free(&$proc)
xslt_create()
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:33
$i
Definition: metadata.php:41
$xml
Definition: metadata.php:351
$lng