ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
class.ilObjFileIconsOverviewGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\File\Icon;
22
26use Psr\Http\Message\RequestInterface;
29
35{
36 public const CMD_INDEX = 'index';
37 public const CMD_OPEN_CREATION_FORM = 'openCreationForm';
38 public const CMD_OPEN_UPDATING_FORM = 'openUpdatingForm';
39 public const CMD_CHANGE_ACTIVATION = 'changeActivation';
40 public const CMD_CREATE = 'create';
41 public const CMD_UPDATE = 'update';
42 public const CMD_DELETE = 'delete';
43 public const P_RID = 'rid';
44
45 private \ilCtrl $ctrl;
46 private \ilLanguage $lng;
47 private \ilToolbarGUI $toolbar;
50 private \ilGlobalTemplateInterface $main_tpl;
52 private RequestInterface $http_request;
53 private \ILIAS\Refinery\Factory $refinery;
56 private \ilFileServicesSettings $file_service_settings;
57 private \ilAccessHandler $access;
58 private bool $write_access;
59
60 final public function __construct()
61 {
62 global $DIC;
63 $this->ctrl = $DIC->ctrl();
64 $this->access = $DIC->access();
65 $this->lng = $DIC->language();
66 $this->lng->loadLanguageModule('file');
67 $this->toolbar = $DIC->toolbar();
68 $this->main_tpl = $DIC->ui()->mainTemplate();
69 $this->ui_factory = $DIC->ui()->factory();
70 $this->ui_renderer = $DIC->ui()->renderer();
71 $this->http_request = $DIC->http()->request();
72 $this->wrapper = $DIC->http()->wrapper();
73 $this->refinery = $DIC->refinery();
74 $this->storage = $DIC->resourceStorage();
75 $this->icon_repo = new IconDatabaseRepository();
76 $this->file_service_settings = $DIC->fileServiceSettings();
77 $this->write_access = $this->access->checkAccess(
78 'write',
79 '',
80 (int) ($this->http_request->getQueryParams()['ref_id'] ?? 0)
81 );
82 }
83
84 final public function executeCommand(): void
85 {
86 $next_class = $this->ctrl->getNextClass(self::class);
87 if ($next_class === strtolower(ilIconUploadHandlerGUI::class)) {
88 $upload_handler = new ilIconUploadHandlerGUI();
89 $this->ctrl->forwardCommand($upload_handler);
90 }
91
92 match ($cmd = $this->ctrl->getCmd(self::CMD_INDEX)) {
93 self::CMD_OPEN_CREATION_FORM => $this->openCreationForm(),
94 self::CMD_OPEN_UPDATING_FORM => $this->openUpdatingForm(),
95 self::CMD_CHANGE_ACTIVATION => $this->changeActivation(),
96 self::CMD_CREATE => $this->create(),
97 self::CMD_UPDATE => $this->update(),
98 self::CMD_DELETE => $this->delete(),
99 default => $this->index(),
100 };
101 }
102
103 private function index(): void
104 {
105 // toolbar: add new icon button
106 if ($this->write_access) {
107 $btn_new_icon = $this->ui_factory->button()->standard(
108 $this->lng->txt('add_icon'),
109 $this->ctrl->getLinkTargetByClass(self::class, self::CMD_OPEN_CREATION_FORM)
110 );
111 $this->toolbar->addComponent($btn_new_icon);
112 }
113
114 // Listing of icons
115 $listing = new IconListingUI(
116 $this->icon_repo,
117 $this,
118 $this->write_access
119 );
120
121 $content = [];
122 $content[] = $listing->getFilter();
123 $content[] = $listing->getIconList();
124 $content[] = $listing->getDeletionModals();
125
126 $this->main_tpl->setContent(
127 $this->ui_renderer->render($content)
128 );
129 }
130
131 private function openCreationForm(): void
132 {
133 $icon_form_ui = new IconFormUI(new NullIcon('', true), IconFormUI::MODE_CREATE, $this->icon_repo);
134 $icon_form = $icon_form_ui->getIconForm();
135 $this->main_tpl->setContent(
136 $this->ui_renderer->render($icon_form)
137 );
138 }
139
140 private function openUpdatingForm(): void
141 {
142 $to_str = $this->refinery->to()->string();
143 $rid = $this->wrapper->query()->has(self::P_RID) ? $rid = $this->wrapper->query()->retrieve(
144 self::P_RID,
145 $to_str
146 ) : "";
147 $this->ctrl->setParameter($this, self::P_RID, $rid); //store rid for giving icon to form in update function
148 $icon = $this->icon_repo->getIconByRid($rid);
149 $icon_form_ui = new IconFormUI($icon, IconFormUI::MODE_EDIT, $this->icon_repo);
150 $icon_form = $icon_form_ui->getIconForm();
151 $this->main_tpl->setContent(
152 $this->ui_renderer->render($icon_form)
153 );
154 }
155
156 public function changeActivation(): void
157 {
158 $to_str = $this->refinery->to()->string();
159 $rid = $this->wrapper->query()->has(self::P_RID) ? $rid = $this->wrapper->query()->retrieve(
160 self::P_RID,
161 $to_str
162 ) : "";
163 $icon = $this->icon_repo->getIconByRid($rid);
164 $suffixes = $icon->getSuffixes();
165 $icon->isActive();
166 $is_default_icon = $icon->isDefaultIcon();
167
168 if (!$icon->isActive()) {
169 // in case of a change from deactivated to activated no two icons with overlapping suffixes must be active at the same time
170 if ($this->icon_repo->causesNoActiveSuffixesConflict($suffixes, true, $icon)) {
171 $this->icon_repo->updateIcon($rid, true, $is_default_icon, $suffixes);
172
173 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_icon_activated'), true);
174 } else {
175 $this->main_tpl->setOnScreenMessage(
176 'failure',
177 $this->lng->txt('msg_error_active_suffixes_conflict'),
178 true
179 );
180 }
181 } else {
182 $this->icon_repo->updateIcon($rid, false, $is_default_icon, $suffixes);
183 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_icon_deactivated'), true);
184 }
185
186 $this->ctrl->redirect($this, self::CMD_INDEX);
187 }
188
189 public function create(): void
190 {
191 $ui = new IconFormUI(new NullIcon(), IconFormUI::MODE_CREATE, $this->icon_repo);
192 $form = $ui->getIconForm();
193
194 if ($this->http_request->getMethod() === "POST") {
195 $form = $form->withRequest($this->http_request);
196 $result = $form->getData();
197
198 if ($result !== null) {
199 $rid = $result[0][IconFormUI::INPUT_ICON][0];
200 $active = $result[0][IconFormUI::INPUT_ACTIVE];
201 $suffixes = $result[0][IconFormUI::INPUT_SUFFIXES];
202
203 $this->icon_repo->createIcon($rid, $active, false, $suffixes);
204
205 // check if one of the suffixes is not whitelisted
206 if (array_diff($suffixes, $this->file_service_settings->getWhiteListedSuffixes()) !== []) {
207 $this->main_tpl->setOnScreenMessage(
208 'info',
209 $this->lng->txt('msg_error_active_suffixes_not_whitelisted'),
210 true
211 );
212 }
213
214 // check if one of the suffixes is blacklisted
215 if (array_intersect($suffixes, $this->file_service_settings->getBlackListedSuffixes()) !== []) {
216 $this->main_tpl->setOnScreenMessage(
217 'info',
218 $this->lng->txt('msg_error_active_suffixes_blacklisted'),
219 true
220 );
221 }
222
223 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_icon_created'), true);
224 $this->ctrl->redirect($this, self::CMD_INDEX);
225 } else {
226 $this->main_tpl->setContent(
227 $this->ui_renderer->render([$form])
228 );
229 }
230 }
231 }
232
233 public function update(): void
234 {
235 $to_str = $this->refinery->to()->string();
236 $rid = $this->wrapper->query()->has(self::P_RID) ? $rid = $this->wrapper->query()->retrieve(
237 self::P_RID,
238 $to_str
239 ) : "";
240 $this->ctrl->saveParameter(
241 $this,
242 self::P_RID
243 ); //save rid to still have it when re-submitting a previously wrongly filled out form
244 $icon = $this->icon_repo->getIconByRid($rid);
245 $ui = new IconFormUI($icon, IconFormUI::MODE_EDIT, $this->icon_repo);
246 $form = $ui->getIconForm();
247
248 if ($this->http_request->getMethod() === "POST") {
249 $form = $form->withRequest($this->http_request);
250 $result = $form->getData();
251
252 if ($result !== null) {
253 $rid = $result[0][IconFormUI::INPUT_ICON][0];
254 $active = $result[0][IconFormUI::INPUT_ACTIVE];
255 $suffixes = $result[0][IconFormUI::INPUT_SUFFIXES];
256
257 $this->icon_repo->updateIcon($rid, $active, false, $suffixes);
258 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_icon_updated'), true);
259 $this->ctrl->redirect($this, self::CMD_INDEX);
260 } else {
261 $this->main_tpl->setContent(
262 $this->ui_renderer->render([$form])
263 );
264 }
265 }
266 }
267
268 public function delete(): void
269 {
270 $to_str = $this->refinery->to()->string();
271 $rid = $this->wrapper->query()->has(self::P_RID) ? $rid = $this->wrapper->query()->retrieve(
272 self::P_RID,
273 $to_str
274 ) : "";
275
276 // delete icon from irss
277 $is_deleted_from_irss = false;
278 $id = $this->storage->manage()->find($rid);
279 if ($id instanceof ResourceIdentification) {
280 $this->storage->manage()->remove($id, new ilObjFileIconStakeholder());
281 $is_deleted_from_irss = true;
282 }
283 // delete icon from db
284 $is_deleted_from_db = $this->icon_repo->deleteIconByRid($rid);
285
286 if ($is_deleted_from_irss && $is_deleted_from_db) {
287 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_icon_deletion'), true);
288 } elseif ($is_deleted_from_irss) {
289 $this->main_tpl->setOnScreenMessage(
290 'failure',
291 $this->lng->txt('msg_error_icon_deletion') . " " . $this->lng->txt('msg_icon_missing_from_db'),
292 true
293 );
294 } elseif ($is_deleted_from_db) {
295 $this->main_tpl->setOnScreenMessage(
296 'failure',
297 $this->lng->txt('msg_error_icon_deletion') . " " . $this->lng->txt('msg_icon_missing_from_irss'),
298 true
299 );
300 } else {
301 $this->main_tpl->setOnScreenMessage(
302 'failure',
303 $this->lng->txt('msg_error_icon_deletion') . " " . $this->lng->txt(
304 'msg_icon_missing_from_db'
305 ) . " " . $this->lng->txt('msg_icon_missing_from_irss'),
306 true
307 );
308 }
309 $this->ctrl->redirect($this, self::CMD_INDEX);
310 }
311}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
An entity that renders components to a string output.
Definition: Renderer.php:31
global $DIC
Definition: shib_login.php:26