ILIAS  release_8 Revision v8.24
class.ilPCInteractiveImageGUI.php
Go to the documentation of this file.
1<?php
2
26{
27 protected ilTabsGUI $tabs;
29
30 public function __construct(
31 ilPageObject $a_pg_obj,
32 ?ilPageContent $a_content_obj,
33 string $a_hier_id,
34 string $a_pc_id = ""
35 ) {
36 global $DIC;
37
38 $this->tpl = $DIC["tpl"];
39 $this->lng = $DIC->language();
40 $this->tabs = $DIC->tabs();
41 $this->ctrl = $DIC->ctrl();
42 $this->toolbar = $DIC->toolbar();
43 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
44 }
45
46 public function executeCommand(): void
47 {
49 $ilTabs = $this->tabs;
50
51 // get next class that processes or forwards current command
52 $next_class = $this->ctrl->getNextClass($this);
53
54 // get current command
55 $cmd = $this->ctrl->getCmd();
56
57 if (is_object($this->content_obj)) {
58 $tpl->setTitleIcon(ilUtil::getImagePath("icon_mob.svg"));
59 $this->getTabs();
60 }
61
62 switch ($next_class) {
63 // trigger editor
64 case "ilpciimtriggereditorgui":
65 $ilTabs->setTabActive("triggers");
67 $iim = $this->content_obj;
68 $image_map_edit = new ilPCIIMTriggerEditorGUI(
69 $iim,
70 $this->pg_obj,
71 $this->request
72 );
73 $ret = $this->ctrl->forwardCommand($image_map_edit);
74 if ($ret != "") {
75 $tpl->setContent($ret);
76 }
77 break;
78
79 default:
80 $this->$cmd();
81 break;
82 }
83 }
84
88 public function getTabs(
89 bool $a_create = false,
90 bool $a_change_obj_ref = false
91 ): void {
92 $ilCtrl = $this->ctrl;
93 $ilTabs = $this->tabs;
95
96 if (!$a_create) {
97 $ilTabs->setBackTarget(
98 $lng->txt("pg"),
99 (string) $ilCtrl->getParentReturn($this)
100 );
101
102 $ilTabs->addTab(
103 "triggers",
104 $lng->txt("cont_active_areas"),
105 $ilCtrl->getLinkTargetByClass("ilpciimtriggereditorgui", "editMapAreas")
106 );
107
108 $ilTabs->addTab(
109 "list_overlays",
110 $lng->txt("cont_overlay_images"),
111 $ilCtrl->getLinkTarget($this, "listOverlayImages")
112 );
113
114 $ilTabs->addTab(
115 "content_popups",
116 $lng->txt("cont_content_popups"),
117 $ilCtrl->getLinkTarget($this, "listContentPopups")
118 );
119
120 $ilTabs->addTab(
121 "edit_base_image",
122 $lng->txt("cont_base_image") . " & " . $lng->txt("cont_caption"),
123 $ilCtrl->getLinkTarget($this, "editBaseImage")
124 );
125 }
126 }
127
131 public function insert(
132 string $a_post_cmd = "edpost",
133 string $a_submit_cmd = "create_mob",
134 bool $a_input_error = false
135 ): void {
136 $tpl = $this->tpl;
137 $ilCtrl = $this->ctrl;
139
140 $this->tpl->setOnScreenMessage('info', $lng->txt("cont_iim_create_info"));
141
142 $form = $this->initForm("create");
143 $form->setFormAction($ilCtrl->getFormAction($this));
144
145 $this->displayValidationError();
146
147 $tpl->setContent($form->getHTML());
148 }
149
150 public function edit(): void
151 {
152 $ilCtrl = $this->ctrl;
153 $ilCtrl->redirectByClass(array("ilpcinteractiveimagegui", "ilpciimtriggereditorgui"), "editMapAreas");
154 }
155
156 public function editBaseImage(): void
157 {
159 $ilTabs = $this->tabs;
160 $ilTabs->activateTab("edit_base_image");
161 $form = $this->initForm();
162 $tpl->setContent($form->getHTML());
163 }
164
165
166 public function initForm(string $a_mode = "edit"): ilPropertyFormGUI
167 {
169 $ilCtrl = $this->ctrl;
170 $ti = null;
171
172 $form = new ilPropertyFormGUI();
173
174 // image file
175 $fi = new ilImageFileInputGUI($lng->txt("cont_file"), "image_file");
176 $fi->setAllowDeletion(false);
177 if ($a_mode == "edit") {
178 $fi->setImage($this->content_obj->getBaseThumbnailTarget());
179 } else {
180 $fi->setRequired(true);
181 }
182 $form->addItem($fi);
183
184 if ($a_mode == "edit") {
185 // caption
186 $ti = new ilTextInputGUI($this->lng->txt("cont_caption"), "caption");
187 $ti->setMaxLength(200);
188 $ti->setSize(50);
189 $form->addItem($ti);
190 }
191
192 // save and cancel commands
193 if ($a_mode == "create") {
194 $form->setTitle($lng->txt("cont_ed_insert_iim"));
195 $form->addCommandButton("create_iim", $lng->txt("save"));
196 $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
197 } else {
198 // get caption
199 $std_alias_item = new ilMediaAliasItem(
200 $this->dom,
201 $this->getHierId(),
202 "Standard",
203 $this->content_obj->getPCId(),
204 "InteractiveImage"
205 );
206 $ti->setValue($std_alias_item->getCaption());
207
208 $form->setTitle($lng->txt("cont_edit_base_image"));
209 $form->addCommandButton("update", $lng->txt("save"));
210 }
211
212 $form->setFormAction($ilCtrl->getFormAction($this));
213
214 return $form;
215 }
216
217 public function create(): void
218 {
219 $ilCtrl = $this->ctrl;
222
223 $form = $this->initForm("create");
224 if (!$form->checkInput()) {
225 $this->displayValidationError();
226 $form->setValuesByPost();
227 $tpl->setContent($form->getHTML());
228 return;
229 }
230
231 $this->content_obj = new ilPCInteractiveImage($this->getPage());
232 $this->content_obj->createMediaObject();
233 $media_obj = $this->content_obj->getMediaObject();
234 $media_obj->setTitle($_FILES['image_file']['name']);
235 $media_obj->create();
236 $mob_dir = ilObjMediaObject::_getDirectory($media_obj->getId());
237 // $media_obj->setStandardType("File");
238 $media_obj->createDirectory();
239 $media_item = new ilMediaItem();
240 $media_obj->addMediaItem($media_item);
241 $media_item->setPurpose("Standard");
242
243 $file = $mob_dir . "/" . $_FILES['image_file']['name'];
244 try {
246 $_FILES['image_file']['tmp_name'],
247 $_FILES['image_file']['name'],
248 $file
249 );
250 } catch (ilException $e) {
251 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("file_is_infected"), true);
252 return;
253 }
254 // get mime type
256 $location = $_FILES['image_file']['name'];
257
258 // set real meta and object data
259 $media_item->setFormat($format);
260 $media_item->setLocation($location);
261 $media_item->setLocationType("LocalFile");
262
264 $media_obj->update();
265
266 $this->content_obj->createAlias($this->pg_obj, $this->hier_id, $this->pc_id);
267 $this->updated = $this->pg_obj->update();
268 if ($this->updated === true) {
269 $this->pg_obj->stripHierIDs();
270 $this->pg_obj->addHierIDs();
271 $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
272 $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
273 $this->content_obj->setHierId($this->content_obj->readHierId());
274 $this->setHierId($this->content_obj->readHierId());
275 $this->content_obj->setPcId($this->content_obj->readPCId());
276 $this->tpl->setOnScreenMessage('success', $lng->txt("cont_saved_interactive_image"), true);
277 $this->ctrl->redirectByClass("ilpcinteractiveimagegui", "edit");
278
279 //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
280 } else {
281 $this->insert();
282 }
283 }
284
288 public function update(): void
289 {
290 $ilCtrl = $this->ctrl;
292
293 $form = $this->initForm("edit");
294 if ($form->checkInput()) {
295 $mob = $this->content_obj->getMediaObject();
296 $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
297 $std_item = $mob->getMediaItem("Standard");
298 $location = $_FILES['image_file']['name'];
299
300 if ($location != "" && is_file($_FILES['image_file']['tmp_name'])) {
301 $file = $mob_dir . "/" . $_FILES['image_file']['name'];
303 $_FILES['image_file']['tmp_name'],
304 $_FILES['image_file']['name'],
305 $file
306 );
307
308 // get mime type
310 $location = $_FILES['image_file']['name'];
311 $std_item->setFormat($format);
312 $std_item->setLocation($location);
313 $std_item->setLocationType("LocalFile");
314 $mob->setDescription($format);
315 $mob->update();
316 }
317
318 // set caption
319 $std_alias_item = new ilMediaAliasItem(
320 $this->dom,
321 $this->getHierId(),
322 "Standard",
323 $this->content_obj->getPCId(),
324 "InteractiveImage"
325 );
326 $std_alias_item->setCaption(
327 $form->getInput("caption")
328 );
329 $this->edit_repo->setPageError($this->pg_obj->update());
330 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
331 }
332
333 $ilCtrl->redirectByClass("ilpcinteractiveimagegui", "editBaseImage");
334 }
335
336
340 public function centerAlign(): void
341 {
342 $std_alias_item = new ilMediaAliasItem(
343 $this->dom,
344 $this->getHierId(),
345 "Standard",
346 $this->content_obj->getPCId(),
347 "InteractiveImage"
348 );
349 $std_alias_item->setHorizontalAlign("Center");
350 $this->updateAndReturn();
351 }
352
356 public function leftAlign(): void
357 {
358 $std_alias_item = new ilMediaAliasItem(
359 $this->dom,
360 $this->getHierId(),
361 "Standard",
362 $this->content_obj->getPCId(),
363 "InteractiveImage"
364 );
365 $std_alias_item->setHorizontalAlign("Left");
366 $this->updateAndReturn();
367 }
368
372 public function rightAlign(): void
373 {
374 $std_alias_item = new ilMediaAliasItem(
375 $this->dom,
376 $this->getHierId(),
377 "Standard",
378 $this->content_obj->getPCId(),
379 "InteractiveImage"
380 );
381 $std_alias_item->setHorizontalAlign("Right");
382 $this->updateAndReturn();
383 }
384
388 public function leftFloatAlign(): void
389 {
390 $std_alias_item = new ilMediaAliasItem(
391 $this->dom,
392 $this->getHierId(),
393 "Standard",
394 $this->content_obj->getPCId(),
395 "InteractiveImage"
396 );
397 $std_alias_item->setHorizontalAlign("LeftFloat");
398 $this->updateAndReturn();
399 }
400
404 public function rightFloatAlign(): void
405 {
406 $std_alias_item = new ilMediaAliasItem(
407 $this->dom,
408 $this->getHierId(),
409 "Standard",
410 $this->content_obj->getPCId(),
411 "InteractiveImage"
412 );
413 $std_alias_item->setHorizontalAlign("RightFloat");
414 $this->updateAndReturn();
415 }
416
420
421 public function listOverlayImages(): void
422 {
424 $ilToolbar = $this->toolbar;
425 $ilCtrl = $this->ctrl;
426 $ilTabs = $this->tabs;
428
429 $this->tpl->setOnScreenMessage('info', $lng->txt("cont_iim_overlay_info"));
430
431 $ilTabs->setTabActive("list_overlays");
432
433 $ilToolbar->addButton(
434 $lng->txt("cont_add_images"),
435 $ilCtrl->getLinkTarget($this, "addOverlayImages")
436 );
437
438 $tab = new ilPCIIMOverlaysTableGUI(
439 $this,
440 "listOverlayImages",
441 $this->content_obj->getMediaObject()
442 );
443 $tpl->setContent($tab->getHTML());
444 }
445
446 public function addOverlayImages(ilPropertyFormGUI $a_form = null): void
447 {
449
450 if ($a_form) {
451 $form = $a_form;
452 } else {
453 $form = $this->initAddOverlaysForm();
454 }
455
456 $tpl->setContent($form->getHTML());
457 }
458
460 {
462 $ilCtrl = $this->ctrl;
463 $ilTabs = $this->tabs;
464
465 $ilTabs->setTabActive("list_overlays");
466
467 $form = new ilPropertyFormGUI();
468 $form->setTitle($lng->txt("cont_add_images"));
469 $form->setFormAction($ilCtrl->getFormAction($this));
470
471 // file input
472 $fi = new ilFileWizardInputGUI($lng->txt("file"), "ovfile");
473 $fi->setSuffixes(array("gif", "jpeg", "jpg", "png"));
474 $fi->setFilenames(array(0 => ''));
475 $fi->setRequired(true);
476 $form->addItem($fi);
477
478 $form->addCommandButton("uploadOverlayImages", $lng->txt("upload"));
479 $form->addCommandButton("listOverlayImages", $lng->txt("cancel"));
480
481 return $form;
482 }
483
484 public function uploadOverlayImages(): void
485 {
487 $ilCtrl = $this->ctrl;
488
489 $form = $this->initAddOverlaysForm();
490 if ($form->checkInput()) {
491 if (is_array($_FILES["ovfile"]["name"])) {
492 foreach ($_FILES["ovfile"]["name"] as $k => $v) {
493 $name = $_FILES["ovfile"]["name"][$k];
494 $tmp_name = $_FILES["ovfile"]["tmp_name"][$k];
495
496 $this->content_obj->getMediaObject()->uploadAdditionalFile(
497 $name,
498 $tmp_name,
499 "overlays"
500 );
501 $piname = pathinfo($name);
502 $this->content_obj->getMediaObject()->makeThumbnail(
503 "overlays/" . $name,
504 basename($name, "." . $piname['extension']) . ".png"
505 );
506 }
507 }
508 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"));
509 $ilCtrl->redirect($this, "listOverlayImages");
510 } else {
511 $form->setValuesByPost();
512 $this->addOverlayImages($form);
513 }
514 }
515
516 public function confirmDeleteOverlays(): void
517 {
518 $ilCtrl = $this->ctrl;
521 $ilTabs = $this->tabs;
522
523 $ilTabs->setTabActive("list_overlays");
524
525 $files = $this->request->getStringArray("file");
526 if (count($files) == 0) {
527 $this->tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
528 $ilCtrl->redirect($this, "listOverlayImages");
529 } else {
530 $cgui = new ilConfirmationGUI();
531 $cgui->setFormAction($ilCtrl->getFormAction($this));
532 $cgui->setHeaderText($lng->txt("cont_really_delete_overlays"));
533 $cgui->setCancel($lng->txt("cancel"), "listOverlayImages");
534 $cgui->setConfirm($lng->txt("delete"), "deleteOverlays");
535
536 foreach ($files as $i => $d) {
537 $cgui->addItem("file[]", $i, $i);
538 }
539
540 $tpl->setContent($cgui->getHTML());
541 }
542 }
543
544 public function deleteOverlays(): void
545 {
546 $ilCtrl = $this->ctrl;
548
549 $files = $this->request->getStringArray("file");
550 if (count($files) > 0) {
551 foreach ($files as $f) {
552 $f = str_replace("..", "", ilUtil::stripSlashes($f));
553 $this->content_obj->getMediaObject()
554 ->removeAdditionalFile("overlays/" . $f);
555 }
556
557 $this->tpl->setOnScreenMessage('success', $lng->txt("cont_overlays_have_been_deleted"), true);
558 }
559 $ilCtrl->redirect($this, "listOverlayImages");
560 }
561
562
566
567 public function listContentPopups(): void
568 {
570 $ilToolbar = $this->toolbar;
571 $ilCtrl = $this->ctrl;
572 $ilTabs = $this->tabs;
574
575 $this->tpl->setOnScreenMessage('info', $lng->txt("cont_iim_content_popups_info"));
576
577 $ilTabs->setTabActive("content_popups");
578
579 $ilToolbar->addButton(
580 $lng->txt("cont_add_popup"),
581 $ilCtrl->getLinkTarget($this, "addPopup")
582 );
583
585 $iim = $this->content_obj;
586 $tab = new ilPCIIMPopupTableGUI(
587 $this,
588 "listContentPopups",
589 $iim
590 );
591 $tpl->setContent($tab->getHTML());
592 }
593
594 public function addPopup(): void
595 {
596 $ilCtrl = $this->ctrl;
598
599 $this->content_obj->addContentPopup();
600 $this->pg_obj->update();
601 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
602 $ilCtrl->redirect($this, "listContentPopups");
603 }
604
605 public function savePopups(): void
606 {
607 $ilCtrl = $this->ctrl;
609
610 $titles = $this->request->getStringArray("title");
611 if (count($titles) > 0) {
612 $this->content_obj->savePopups($titles);
613 $this->pg_obj->update();
614 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
615 }
616 $ilCtrl->redirect($this, "listContentPopups");
617 }
618
619 public function confirmPopupDeletion(): void
620 {
621 $ilCtrl = $this->ctrl;
624 $ilTabs = $this->tabs;
625
626 $ilTabs->setTabActive("content_popups");
627
628 $tids = $this->request->getStringArray("tid");
629 $titles = $this->request->getStringArray("title");
630
631 if (count($tids) == 0) {
632 $this->tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
633 $ilCtrl->redirect($this, "listContentPopups");
634 } else {
635 $cgui = new ilConfirmationGUI();
636 $cgui->setFormAction($ilCtrl->getFormAction($this));
637 $cgui->setHeaderText($lng->txt("cont_really_delete_popups"));
638 $cgui->setCancel($lng->txt("cancel"), "listContentPopups");
639 $cgui->setConfirm($lng->txt("delete"), "deletePopups");
640
641 foreach ($tids as $i => $d) {
642 $cgui->addItem("tid[]", $i, $titles[$i]);
643 }
644
645 $tpl->setContent($cgui->getHTML());
646 }
647 }
648
649 public function deletePopups(): void
650 {
652 $ilCtrl = $this->ctrl;
653
654 $tids = $this->request->getStringArray("tid");
655
656 if (count($tids) > 0) {
657 foreach ($tids as $id) {
658 $id = explode(":", $id);
659 $this->content_obj->deletePopup($id[0], $id[1]);
660 }
661 $this->pg_obj->update();
662 $this->tpl->setOnScreenMessage('success', $lng->txt("cont_popups_have_been_deleted"), true);
663 }
664 $ilCtrl->redirect($this, "listContentPopups");
665 }
666}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
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 renameExecutables(string $a_dir)
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
This class represents a file wizard property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
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 getMimeType(string $a_file, bool $a_external=false)
get mime type for file
static _getDirectory(int $a_mob_id)
Get absolute directory.
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...
User interface class for page content map editor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTabs(bool $a_create=false, bool $a_change_obj_ref=false)
Add tabs to ilTabsGUI object.
rightFloatAlign()
align media object to right, floating text
leftAlign()
align media object to left
leftFloatAlign()
align media object to left, floating text
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
insert(string $a_post_cmd="edpost", string $a_submit_cmd="create_mob", bool $a_input_error=false)
Insert new media object form.
centerAlign()
Align media object to center.
addOverlayImages(ilPropertyFormGUI $a_form=null)
rightAlign()
align media object to right
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
global $DIC
Definition: feed.php:28
setContent(string $a_html)
Sets content for standard template.
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
if($format !==null) $name
Definition: metadata.php:247
$format
Definition: metadata.php:235
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$lng