ILIAS  release_8 Revision v8.24
class.ilObjectCustomIconConfigurationGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
24{
25 protected const DEFAULT_CMD = 'showForm';
26
27 protected Container $dic;
28 protected ilObject $object;
30 protected $parentGui;
31 protected ?string $uploadFieldInformationText = null;
33
35 {
36 global $DIC;
37 $this->main_tpl = $DIC->ui()->mainTemplate();
38 $this->dic = $dic;
39 $this->parentGui = $parentGui;
40 $this->object = $object;
41 }
42
43 public function setUploadFieldInformationText(?string $uploadFieldInformationText): void
44 {
45 $this->uploadFieldInformationText = $uploadFieldInformationText;
46 }
47
48 public function executeCommand(): void
49 {
50 $this->dic->ctrl()->getNextClass($this);
51 $cmd = $this->dic->ctrl()->getCmd(self::DEFAULT_CMD);
52
53 switch (true) {
54 case method_exists($this, $cmd):
55 $this->{$cmd}();
56 break;
57
58 default:
59 $this->{self::DEFAULT_CMD}();
60 break;
61 }
62 }
63
64 protected function showForm(?ilPropertyFormGUI $form = null): void
65 {
66 if (null === $form) {
67 $form = $this->getForm();
68 }
69
70 $this->dic->ui()->mainTemplate()->setContent($form->getHTML());
71 }
72
73 protected function getForm(): ilPropertyFormGUI
74 {
75 $this->dic->language()->loadLanguageModule('cntr');
76
77 $form = new ilPropertyFormGUI();
78 $form->setFormAction($this->dic->ctrl()->getFormAction($this, 'saveForm'));
79 $form->setTitle($this->dic->language()->txt('icon_settings'));
80
81 $this->addSettingsToForm($form);
82
83 $form->addCommandButton('saveForm', $this->dic->language()->txt('save'));
84
85 return $form;
86 }
87
88 public function addSettingsToForm(ilPropertyFormGUI $form): void
89 {
91 $customIconFactory = $this->dic['object.customicons.factory'];
92 $customIcon = $customIconFactory->getByObjId($this->object->getId(), $this->object->getType());
93
94 $icon = new ilImageFileInputGUI($this->dic->language()->txt('cont_custom_icon'), 'icon');
95 if (is_string($this->uploadFieldInformationText) && $this->uploadFieldInformationText !== '') {
96 $icon->setInfo($this->uploadFieldInformationText);
97 }
98
99 $icon->setSuffixes($customIcon->getSupportedFileExtensions());
100 $icon->setUseCache(false);
101 if ($customIcon->exists()) {
102 $icon->setImage($customIcon->getFullPath());
103 } else {
104 $icon->setImage('');
105 }
106 $form->addItem($icon);
107 }
108
109 protected function saveForm(): void
110 {
111 $form = $this->getForm();
112 if ($form->checkInput()) {
113 $this->saveIcon($form);
114
115 $this->main_tpl->setOnScreenMessage('success', $this->dic->language()->txt('msg_obj_modified'), true);
116 $this->dic->ctrl()->redirect($this, 'showForm');
117 }
118
119 $form->setValuesByPost();
120 $this->showForm($form);
121 }
122
123 public function saveIcon(ilPropertyFormGUI $form): void
124 {
126 $customIconFactory = $this->dic['object.customicons.factory'];
127 $customIcon = $customIconFactory->getByObjId($this->object->getId(), $this->object->getType());
128
130 $fileData = (array) $form->getInput('icon');
131 $item = $form->getItemByPostVar('icon');
132
133 if ($item && $item->getDeletionFlag()) {
134 $customIcon->remove();
135 }
136
137 if (isset($fileData['tmp_name']) && $fileData['tmp_name']) {
138 $customIcon->saveFromHttpRequest();
139 }
140 }
141}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setUploadFieldInformationText(?string $uploadFieldInformationText)
__construct(Container $dic, $parentGui, ilObject $object)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...