ILIAS  release_8 Revision v8.24
class.ilSystemStyleIconsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25use ILIAS\Refinery\Factory as Refinery;
27
32{
33 protected ilCtrl $ctrl;
34 protected ilLanguage $lng;
43 protected Refinery $refinery;
44 protected ilTabsGUI $tabs;
47 protected string $style_id;
48
49 public function __construct(
57 Refinery $refinery,
61 string $skin_id,
62 string $style_id
63 ) {
64 $this->ctrl = $ctrl;
65 $this->lng = $lng;
66 $this->tpl = $tpl;
67 $this->ui_factory = $ui_factory;
68 $this->renderer = $renderer;
69 $this->request_wrapper = $request_wrapper;
70 $this->toolbar = $toolbar;
71 $this->refinery = $refinery;
72 $this->tabs = $tabs;
73 $this->upload = $upload;
74 $this->style_id = $style_id;
75 $this->message_stack = new ilSystemStyleMessageStack($this->tpl);
76 $this->skin_factory = $skin_factory;
77 $this->style_container = $this->skin_factory->skinStyleContainerFromId($skin_id, $this->message_stack);
78
79 $this->setStyleContainer($this->skin_factory->skinStyleContainerFromId($skin_id, $this->message_stack));
80 }
81
82 public function executeCommand(): void
83 {
84 $cmd = $this->ctrl->getCmd();
85 $this->setSubStyleSubTabs($cmd);
86
87 if ($this->ctrl->getCmd() != 'reset') {
88 try {
89 $this->setIconFolder(new ilSystemStyleIconFolder($this->getStyleContainer()->getImagesSkinPath($this->style_id)));
91 $this->message_stack->addMessage(new ilSystemStyleMessage(
92 $e->getMessage(),
94 ));
95 $cmd = 'fail';
96 }
97 }
98
99 switch ($cmd) {
100 case 'fail':
101 $this->fail();
102 break;
103 case 'cancelIcon':
104 $this->editIcon();
105 break;
106 case 'save':
107 case 'edit':
108 case 'editIcon':
109 case 'update':
110 case 'reset':
111 case 'preview':
112 case 'updateIcon':
113 $this->$cmd();
114 break;
115 default:
116 $this->edit();
117 break;
118 }
119 $this->message_stack->sendMessages();
120 }
121
122 protected function fail(): void
123 {
124 $form = $this->initByColorForm();
125 $this->tpl->setContent($form->getHTML());
126 }
127
128 protected function setSubStyleSubTabs(string $active = ''): void
129 {
130 $this->tabs->addSubTab('edit', $this->lng->txt('edit_by_color'), $this->ctrl->getLinkTarget($this, 'edit'));
131 $this->tabs->addSubTab(
132 'editIcon',
133 $this->lng->txt('edit_by_icon'),
134 $this->ctrl->getLinkTarget($this, 'editIcon')
135 );
136 $this->tabs->addSubTab(
137 'preview',
138 $this->lng->txt('icons_gallery'),
139 $this->ctrl->getLinkTarget($this, 'preview')
140 );
141
142 if ($active == 'preview') {
143 $this->tabs->activateSubTab($active);
144 } elseif ($active == 'cancelIcon' || $active == 'editIcon') {
145 $this->tabs->activateSubTab('editIcon');
146 } else {
147 $this->tabs->activateSubTab('edit');
148 }
149 }
150
151 protected function edit(): void
152 {
153 $form = $this->initByColorForm();
154 $this->getByColorValues($form);
155 $this->tpl->setContent($form->getHTML());
156 }
157
158 protected function preview(): void
159 {
160 $this->tpl->setContent($this->renderer->render($this->getIconsPreviews()));
161 }
162
163 protected function initByColorForm(): ilPropertyFormGUI
164 {
165 $form = new ilPropertyFormGUI();
166
167 $form->setTitle($this->lng->txt('adapt_icons'));
168 $form->setDescription($this->lng->txt('adapt_icons_description'));
169
170 $color_set = [];
171
172 try {
173 $color_set = $this->getIconFolder()->getColorSet()->getColorsSortedAsArray();
175 $this->message_stack->addMessage(new ilSystemStyleMessage(
176 $e->getMessage(),
178 ));
179 }
180
181 foreach ($color_set as $type => $colors) {
182 $section = new ilFormSectionHeaderGUI();
183 $title = '';
184
186 $title = $this->lng->txt('grey_color');
187 $section->setTitle($this->lng->txt('grey_colors'));
188 $section->setInfo($this->lng->txt('grey_colors_description'));
189 $section->setSectionAnchor($this->lng->txt('grey_colors'));
190 }
192 $title = $this->lng->txt('red_color');
193 $section->setTitle($this->lng->txt('red_colors'));
194 $section->setInfo($this->lng->txt('red_colors_description'));
195 $section->setSectionAnchor($this->lng->txt('red_colors'));
196 }
198 $title = $this->lng->txt('green_color');
199 $section->setTitle($this->lng->txt('green_colors'));
200 $section->setInfo($this->lng->txt('green_colors_description'));
201 $section->setSectionAnchor($this->lng->txt('green_colors'));
202 }
204 $title = $this->lng->txt('blue_color');
205 $section->setTitle($this->lng->txt('blue_colors'));
206 $section->setInfo($this->lng->txt('blue_colors_description'));
207 $section->setSectionAnchor($this->lng->txt('blue_colors'));
208 }
209 $form->addItem($section);
210
211 foreach ($colors as $id => $color) {
215 $input = new ilColorPickerInputGUI($title . ' ' . ($id + 1), $color->getId());
216 $input->setRequired(true);
217 $input->setInfo('Usages: ' . $this->getIconFolder()->getUsagesOfColorAsString($color->getId()));
218 $form->addItem($input);
219 }
220 }
221
222 $has_icons = count($this->getIconFolder()->getIcons()) > 0;
223
224 if ($has_icons) {
225 $form->addCommandButton('update', $this->lng->txt('update_colors'));
226 }
227 $form->addCommandButton('reset', $this->lng->txt('reset_icons'));
228 if ($has_icons) {
229 $form->addCommandButton('cancel', $this->lng->txt('cancel'));
230 }
231
232 $form->setFormAction($this->ctrl->getFormAction($this));
233
234 return $form;
235 }
236
237 protected function getByColorValues(ilPropertyFormGUI $form): void
238 {
239 $values = [];
240
241 $colors = $this->getIconFolder()->getColorSet()->getColors();
242 foreach ($colors as $color) {
243 $id = $color->getId();
244 if (array_key_exists($color->getId(), $colors)) {
245 $values[$id] = $colors[$color->getId()]->getColor();
246 } else {
247 $values[$id] = $color->getColor();
248 }
249 }
250
251 $form->setValuesByArray($values);
252 }
253
254 protected function reset(): void
255 {
256 $style = $this->getStyleContainer()->getSkin()->getStyle($this->style_id);
257 $this->getStyleContainer()->resetImages($style);
258 $this->setIconFolder(new ilSystemStyleIconFolder($this->getStyleContainer()->getImagesSkinPath($style->getId())));
261 $this->lng->txt('color_reset'),
263 ));
264 $message_stack->sendMessages();
265
266 $this->ctrl->redirect($this, 'edit');
267 }
268
269 protected function update(): void
270 {
271 $form = $this->initByColorForm();
272 if ($form->checkInput()) {
274
275 $color_changes = [];
276 foreach ($this->getIconFolder()->getColorSet()->getColors() as $old_color) {
277 $new_color = $form->getInput($old_color->getId());
278 if (!preg_match('/[\dabcdef]{6}/i', $new_color)) {
280 $this->lng->txt('invalid_color') . $new_color,
282 ));
283 } elseif ($new_color != $old_color->getColor()) {
284 $color_changes[$old_color->getColor()] = $new_color;
286 $this->lng->txt('color_changed_from') . ' ' . $old_color->getColor() . ' ' .
287 $this->lng->txt('color_changed_to') . ' ' . $new_color,
289 ));
290 }
291 }
292 $this->getIconFolder()->changeIconColors($color_changes);
293 $this->setIconFolder(new ilSystemStyleIconFolder($this->getStyleContainer()->getImagesSkinPath($this->style_id)));
294 $skin = $this->getStyleContainer()->getSkin();
295 $skin->getVersionStep($skin->getVersion());
296 $this->getStyleContainer()->updateSkin($skin);
298 $this->lng->txt('color_update'),
300 ));
301 $message_stack->sendMessages();
302 $this->ctrl->redirect($this, 'edit');
303 }
304 $form->setValuesByPost();
305 $this->tpl->setContent($form->getHTML());
306 }
307
308 protected function editIcon(): void
309 {
310 $icon_name = '';
311 if ($this->request_wrapper->post()->has('selected_icon')) {
312 $icon_name = $this->request_wrapper->post()->retrieve(
313 'selected_icon',
314 $this->refinery->kindlyTo()->string()
315 );
316 } elseif ($this->request_wrapper->query()->has('selected_icon')) {
317 $icon_name = $this->request_wrapper->query()->retrieve(
318 'selected_icon',
319 $this->refinery->kindlyTo()->string()
320 );
321 }
322
323 $this->addSelectIconToolbar($icon_name);
324
325 if ($icon_name) {
326 $icon = $this->getIconFolder()->getIconByPath($icon_name);
327 $form = $this->initByIconForm($icon);
328 $this->tpl->setContent($form->getHTML() . $this->renderIconPreview($icon));
329 }
330 }
331
332 protected function addSelectIconToolbar(?string $icon_name = ''): void
333 {
334 $si = new ilSelectInputGUI($this->lng->txt('select_icon'), 'selected_icon');
335
336 $options = [];
337 $this->getIconFolder()->sortIconsByPath();
338 $substr_len = strlen($this->getIconFolder()->getPath()) + 1;
339 foreach ($this->getIconFolder()->getIcons() as $icon) {
340 if ($icon->getType() == 'svg') {
341 $options[$icon->getPath()] = substr($icon->getPath(), $substr_len);
342 }
343 }
344
345 $si->setOptions($options);
346
347 $si->setValue($icon_name);
348
349 $this->toolbar->addInputItem($si, true);
350
351 $this->toolbar->addComponent($this->ui_factory->button()->standard(
352 $this->lng->txt('select'),
353 ''
354 ));
355 $this->toolbar->setFormAction($this->ctrl->getLinkTarget($this, 'editIcon'));
356 }
357
358 protected function initByIconForm(ilSystemStyleIcon $icon): ilPropertyFormGUI
359 {
360 $form = new ilPropertyFormGUI();
361
362 $form->setTitle($this->lng->txt('adapt_icon') . ' ' . $icon->getName());
363 $form->setDescription($this->lng->txt('adapt_icon_description'));
364
365 $title = $this->lng->txt('color');
366 $id = 1;
367 foreach ($icon->getColorSet()->getColors() as $color) {
371 $input = new ilColorPickerInputGUI($title . ' ' . $id, $color->getId());
372 $input->setRequired(true);
373 $input->setValue($color->getColor());
374 $form->addItem($input);
375 $id++;
376 }
377
378 $upload = new ilFileInputGUI($this->lng->txt('change_icon'), 'changed_icon');
379 $upload->setSuffixes(['svg']);
380 $form->addItem($upload);
381
382 $hidden_path = new ilHiddenInputGUI('selected_icon');
383 $hidden_path->setValue($icon->getPath());
384 $form->addItem($hidden_path);
385
386 if (count($this->getIconFolder()->getIcons()) > 0) {
387 $form->addCommandButton('updateIcon', $this->lng->txt('update_icon'));
388 $form->addCommandButton('cancelIcon', $this->lng->txt('cancel'));
389 }
390
391 $form->setFormAction($this->ctrl->getFormAction($this));
392
393 return $form;
394 }
395
396 protected function updateIcon(): void
397 {
398 $icon_path = $this->request_wrapper->post()->retrieve(
399 'selected_icon',
400 $this->refinery->kindlyTo()->string()
401 );
402
403 $icon = $this->getIconFolder()->getIconByPath($icon_path);
404
405 $form = $this->initByIconForm($icon);
406
407 if ($form->checkInput()) {
409
410 $color_changes = [];
411 foreach ($icon->getColorSet()->getColors() as $old_color) {
412 $new_color = $form->getInput($old_color->getId());
413 if (!preg_match('/[\dabcdef]{6}/i', $new_color)) {
415 $this->lng->txt('invalid_color') . $new_color,
417 ));
418 } elseif ($new_color != $old_color->getColor()) {
419 $color_changes[$old_color->getColor()] = $new_color;
420
422 $this->lng->txt('color_changed_from') . ' ' . $old_color->getColor() . ' ' .
423 $this->lng->txt('color_changed_to') . ' ' . $new_color,
425 ));
426 }
427 }
428 $icon->changeColors($color_changes);
429
430 if ($this->upload->hasUploads()) {
432 $result = array_values($this->upload->getResults())[0];
433
434 $old_icon = $this->getIconFolder()->getIconByPath($icon_path);
435
436 $this->upload->moveOneFileTo(
437 $result,
438 $old_icon->getDirRelToCustomizing(),
439 Location::CUSTOMIZING,
440 $old_icon->getName(),
441 true
442 );
443 }
444
446 $this->lng->txt('color_update'),
448 ));
449
450 foreach ($message_stack->getJoinedMessages() as $type => $message) {
452 $skin = $this->getStyleContainer()->getSkin();
453 $skin->getVersionStep($skin->getVersion());
454 $this->getStyleContainer()->updateSkin($skin);
455 }
456 }
458 $this->ctrl->setParameter($this, 'selected_icon', $icon->getPath());
459 $this->ctrl->redirect($this, 'editIcon');
460 }
461 $form->setValuesByPost();
462 $this->tpl->setContent($form->getHTML());
463 }
464
465 protected function renderIconPreview(ilSystemStyleIcon $icon): string
466 {
467 $icon_image = $this->ui_factory->image()->standard($icon->getPath(), $icon->getName());
468
469 $card = $this->ui_factory->card()->standard(
470 $icon->getName(),
471 $icon_image
472 );
473
474 $report = $this->ui_factory->panel()->standard($this->lng->txt('preview'), $this->ui_factory->deck([$card]));
475
476 return $this->renderer->render($report);
477 }
478
479 public function getIconsPreviews(): \ILIAS\UI\Component\Panel\Report
480 {
481 $sub_panels = [];
482 foreach ($this->getIconFolder()->getIconsSortedByFolder() as $folder_name => $icons) {
483 $cards = [];
484
485 foreach ($icons as $icon) {
489 $icon_image = $this->ui_factory->image()->standard($icon->getPath(), $icon->getName());
490 $card = $this->ui_factory->card()->standard(
491 $icon->getName(),
492 $icon_image
493 );
494 $colors = $icon->getColorSet()->asString();
495 if ($colors) {
496 $card = $card->withSections([
497 $this->ui_factory->listing()->descriptive([$this->lng->txt('used_colors') => $colors])
498 ]);
499 }
500 $cards[] = $card;
501 }
502 $sub_panels[] = $this->ui_factory->panel()->sub($folder_name, $this->ui_factory->deck($cards));
503 }
504
505 return $this->ui_factory->panel()->report($this->lng->txt('icons'), $sub_panels);
506 }
507
509 {
511 }
512
514 {
515 $this->style_container = $style_container;
516 }
517
519 {
520 return $this->icon_folder;
521 }
522
524 {
525 $this->icon_folder = $icon_folder;
526 }
527}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds data types.
Definition: Factory.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
This class represents a file property in a property form.
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...
language handling
This class represents a property form user interface.
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
This class represents a selection list property in a property form.
Factory to create Skin classes holds an manages the basic data of a skin as provide by the template o...
skinStyleContainerFromId(string $skin_id, ilSystemStyleMessageStack $message_stack)
Get container class is responsible for all file system related actions related actions of a skin such...
This class is responsible for all file system related actions related actions of a skin such as copyi...
Class for advanced editing exception handling in ILIAS.
Abstracts a folder containing a set of icons.
Abstracts an Icon and the necessary actions to get all colors out of an svg Icon.
changeColors(array $color_changes)
Changes colors in the svg file of the icon and updates the icon abstraction by extracting the colors ...
@ilCtrl_Calls ilSystemStyleIconsGUI:
setIconFolder(ilSystemStyleIconFolder $icon_folder)
getByColorValues(ilPropertyFormGUI $form)
__construct(ilCtrl $ctrl, ilLanguage $lng, ilGlobalTemplateInterface $tpl, Factory $ui_factory, Renderer $renderer, WrapperFactory $request_wrapper, ilToolbarGUI $toolbar, Refinery $refinery, ilSkinFactory $skin_factory, ilTabsGUI $tabs, FileUpload $upload, string $skin_id, string $style_id)
addSelectIconToolbar(?string $icon_name='')
ilSystemStyleIconFolder $icon_folder
ilSystemStyleMessageStack $message_stack
renderIconPreview(ilSystemStyleIcon $icon)
ilGlobalTemplateInterface $tpl
ilSkinStyleContainer $style_container
setStyleContainer(ilSkinStyleContainer $style_container)
Used to stack messages to be shown to the user.
getJoinedMessages()
Return an array containing a string with all messages for each type.
addMessage(ilSystemStyleMessage $message)
Add a message to be displayed by the stack.
sendMessages(bool $keep=true)
Send messages via ilUtil to be displayed, still needed for messagees, that need to survive a redirect...
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...
Interface Location.
Definition: Location.php:30
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
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...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$type
$message
Definition: xapiexit.php:32