ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilSystemStyleIconsGUI.php
Go to the documentation of this file.
1<?php
2include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
3include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
4include_once("Services/Style/System/classes/Icons/class.ilSystemStyleIconColorSet.php");
5include_once("Services/Style/System/classes/Icons/class.ilSystemStyleIconFolder.php");
6
8
17{
21 protected $ctrl;
22
26 protected $lng;
27
31 protected $tpl;
32
37
41 protected $icon_folder = null;
42
46 protected $tabs;
47
53 public function __construct($skin_id = "", $style_id = "")
54 {
55 global $DIC;
56
57 $this->ctrl = $DIC->ctrl();
58 $this->lng = $DIC->language();
59 $this->tpl = $DIC["tpl"];
60 $this->tabs = $DIC->tabs();
61
62 if ($skin_id == "") {
63 $skin_id = $_GET["skin_id"];
64 }
65 if ($style_id == "") {
66 $style_id = $_GET["style_id"];
67 }
69 if ($this->ctrl->getCmd() != "reset") {
70 try {
71 $this->setIconFolder(new ilSystemStyleIconFolder($this->getStyleContainer()->getImagesSkinPath($style_id)));
73 ilUtil::sendFailure($e->getMessage());
74 $this->ctrl->setCmd("fail");
75 }
76 }
77 }
78
82 public function executeCommand()
83 {
84 $cmd = $this->ctrl->getCmd();
85 $this->setSubStyleSubTabs($cmd);
86
87 switch ($cmd) {
88 case "fail":
89 $this->fail();
90 break;
91 case "cancelIcon":
92 $this->editIcon();
93 break;
94 case "save":
95 case "edit":
96 case "editIcon":
97 case "update":
98 case "reset":
99 case "preview":
100 case "updateIcon":
101 $this->$cmd();
102 break;
103 default:
104 $this->edit();
105 break;
106 }
107 }
108
109 protected function fail()
110 {
111 $form = $this->initByColorForm();
112 $this->tpl->setContent($form->getHTML());
113 }
114
118 protected function setSubStyleSubTabs($active = "")
119 {
120 $this->tabs->addSubTab('edit', $this->lng->txt('edit_by_color'), $this->ctrl->getLinkTarget($this, 'edit'));
121 $this->tabs->addSubTab('editIcon', $this->lng->txt('edit_by_icon'), $this->ctrl->getLinkTarget($this, 'editIcon'));
122 $this->tabs->addSubTab('preview', $this->lng->txt('icons_gallery'), $this->ctrl->getLinkTarget($this, "preview"));
123
124 if ($active == "preview") {
125 $this->tabs->activateSubTab($active);
126 } elseif ($active == "cancelIcon" || $active == "editIcon") {
127 $this->tabs->activateSubTab("editIcon");
128 } else {
129 $this->tabs->activateSubTab("edit");
130 }
131 }
132
133 protected function edit()
134 {
135 $form = $this->initByColorForm();
136 $this->getByColorValues($form);
137 $this->tpl->setContent($form->getHTML());
138 }
139
140 protected function preview()
141 {
142 $this->tpl->setContent($this->renderIconsPreviews());
143 }
147 public function initByColorForm()
148 {
149 $form = new ilPropertyFormGUI();
150
151 $form->setTitle($this->lng->txt("adapt_icons"));
152 $form->setDescription($this->lng->txt("adapt_icons_description"));
153
154 $color_set = [];
155
156 if ($this->getIconFolder()) {
157 try {
158 $color_set = $this->getIconFolder()->getColorSet()->getColorsSortedAsArray();
160 ilUtil::sendFailure($e->getMessage());
161 }
162 }
163
164 foreach ($color_set as $type => $colors) {
166 $title = "";
167
169 $title = $this->lng->txt("grey_color");
170 $section->setTitle($this->lng->txt("grey_colors"));
171 $section->setInfo($this->lng->txt("grey_colors_description"));
172 $section->setSectionAnchor($this->lng->txt("grey_colors"));
173 }
175 $title = $this->lng->txt("red_color");
176 $section->setTitle($this->lng->txt("red_colors"));
177 $section->setInfo($this->lng->txt("red_colors_description"));
178 $section->setSectionAnchor($this->lng->txt("red_colors"));
179 }
181 $title = $this->lng->txt("green_color");
182 $section->setTitle($this->lng->txt("green_colors"));
183 $section->setInfo($this->lng->txt("green_colors_description"));
184 $section->setSectionAnchor($this->lng->txt("green_colors"));
185 }
187 $title = $this->lng->txt("blue_color");
188 $section->setTitle($this->lng->txt("blue_colors"));
189 $section->setInfo($this->lng->txt("blue_colors_description"));
190 $section->setSectionAnchor($this->lng->txt("blue_colors"));
191 }
192 $form->addItem($section);
193
194 foreach ($colors as $id => $color) {
198 $input = new ilColorPickerInputGUI($title . " " . ($id + 1), $color->getId());
199 $input->setRequired(true);
200 $input->setInfo("Usages: " . $this->getIconFolder()->getUsagesOfColorAsString($color->getId()));
201 $form->addItem($input);
202 }
203 }
204
205 $has_icons = $this->getIconFolder() && count($this->getIconFolder()->getIcons()) > 0;
206
207 if ($has_icons) {
208 $form->addCommandButton("update", $this->lng->txt("update_colors"));
209 }
210 $form->addCommandButton("reset", $this->lng->txt("reset_icons"));
211 if ($has_icons) {
212 $form->addCommandButton("cancel", $this->lng->txt("cancel"));
213 }
214
215
216
217
218 $form->setFormAction($this->ctrl->getFormAction($this));
219
220 return $form;
221 }
222
223
227 public function getByColorValues(ilPropertyFormGUI $form)
228 {
229 $values = [];
230
231 if ($this->getIconFolder()) {
232 $colors = $this->getIconFolder()->getColorSet()->getColors();
233 foreach ($colors as $color) {
234 $id = $color->getId();
235 if ($colors[$color->getId()]) {
236 $values[$id] = $colors[$color->getId()]->getColor();
237 } else {
238 $values[$id] = $color->getColor();
239 }
240 }
241 }
242
243
244 $form->setValuesByArray($values);
245 }
246
247 public function reset()
248 {
249 $style = $this->getStyleContainer()->getSkin()->getStyle($_GET["style_id"]);
250 $this->getStyleContainer()->resetImages($style);
251 $this->setIconFolder(new ilSystemStyleIconFolder($this->getStyleContainer()->getImagesSkinPath($style->getId())));
252 $message_stack = new ilSystemStyleMessageStack();
253 $message_stack->addMessage(new ilSystemStyleMessage(
254 $this->lng->txt("color_reset"),
256 ));
257 $message_stack->sendMessages(true);
258
259 $this->ctrl->redirect($this, "edit");
260 }
261
262 public function update()
263 {
264 $form = $this->initByColorForm();
265 if ($form->checkInput()) {
266 $message_stack = new ilSystemStyleMessageStack();
267
268 $color_changes = [];
269 foreach ($this->getIconFolder()->getColorSet()->getColors() as $old_color) {
270 $new_color = $form->getInput($old_color->getId());
271 if (!preg_match("/[\dabcdef]{6}/i", $new_color)) {
272 $message_stack->addMessage(new ilSystemStyleMessage(
273 $this->lng->txt("invalid_color") . $new_color,
275 ));
276 } elseif ($new_color != $old_color->getColor()) {
277 $color_changes[$old_color->getColor()] = $new_color;
278 $message_stack->addMessage(new ilSystemStyleMessage(
279 $this->lng->txt("color_changed_from") . " " . $old_color->getColor() . " " .
280 $this->lng->txt("color_changed_to") . " " . $new_color,
282 ));
283 }
284 }
285 $this->getIconFolder()->changeIconColors($color_changes);
286 $this->setIconFolder(new ilSystemStyleIconFolder($this->getStyleContainer()->getImagesSkinPath($_GET["style_id"])));
287 $skin = $this->getStyleContainer()->getSkin();
288 $skin->getVersionStep($skin->getVersion());
289 $this->getStyleContainer()->updateSkin($skin);
290 $message_stack->addMessage(new ilSystemStyleMessage(
291 $this->lng->txt("color_update"),
293 ));
294 $message_stack->sendMessages(true);
295 $this->ctrl->redirect($this, "edit");
296 }
297 $form->setValuesByPost();
298 $this->tpl->setContent($form->getHTML());
299 }
300
301
302 protected function editIcon()
303 {
304 $icon_name = $_POST['selected_icon']?$_POST['selected_icon']:$_GET['selected_icon'];
305
306 $this->addSelectIconToolbar($icon_name);
307
308 if ($icon_name) {
309 $icon = $this->getIconFolder()->getIconByPath($icon_name);
310 $form = $this->initByIconForm($icon);
311 $this->tpl->setContent($form->getHTML() . $this->renderIconPreview($icon));
312 }
313 }
314
318 protected function addSelectIconToolbar($icon_name)
319 {
320 global $DIC;
321
322 $toolbar = $DIC->toolbar();
323
324 $si = new ilSelectInputGUI($this->lng->txt("select_icon"), "selected_icon");
325
326 $options = array();
327 $this->getIconFolder()->sortIconsByPath();
328 $substr_len = strlen($this->getIconFolder()->getPath()) + 1;
329 foreach ($this->getIconFolder()->getIcons() as $icon) {
330 if ($icon->getType() == "svg") {
331 $options[$icon->getPath()] = substr($icon->getPath(), $substr_len);
332 }
333 }
334
335 $si->setOptions($options);
336
337 $si->setValue($icon_name);
338
339 $toolbar->addInputItem($si, true);
340
341 $select_btn = ilSubmitButton::getInstance();
342 $select_btn->setCaption($this->lng->txt("select"), false);
343 $toolbar->addButtonInstance($select_btn);
344 $toolbar->setFormAction($this->ctrl->getLinkTarget($this, 'editIcon'));
345 }
346
351 public function initByIconForm(ilSystemStyleIcon $icon)
352 {
353 $form = new ilPropertyFormGUI();
354
355 $form->setTitle($this->lng->txt("adapt_icon") . " " . $icon->getName());
356 $form->setDescription($this->lng->txt("adapt_icon_description"));
357
358 $color_set = [];
359
360 $title = $this->lng->txt("color");
361 $id = 1;
362 foreach ($icon->getColorSet()->getColors() as $color) {
366 $input = new ilColorPickerInputGUI($title . " " . $id, $color->getId());
367 $input->setRequired(true);
368 $input->setValue($color->getColor());
369 $form->addItem($input);
370 $id++;
371 }
372
373 $upload = new ilFileInputGUI($this->lng->txt("change_icon"), "changed_icon");
374 $upload->setSuffixes(["svg"]);
375 $form->addItem($upload);
376
377 $hidden_path = new ilHiddenInputGUI("selected_icon");
378 $hidden_path->setValue($icon->getPath());
379 $form->addItem($hidden_path);
380
381 if ($this->getIconFolder() && count($this->getIconFolder()->getIcons()) > 0) {
382 $form->addCommandButton("updateIcon", $this->lng->txt("update_icon"));
383 $form->addCommandButton("cancelIcon", $this->lng->txt("cancel"));
384 }
385
386 $form->setFormAction($this->ctrl->getFormAction($this));
387
388 return $form;
389 }
390
391
397 {
398 $values = [];
399
400 foreach ($this->getIconFolder()->getColorSet()->getColors() as $color) {
401 $values[$color->getId()] = $color->getColor();
402 }
403 $values["selected_icon"] = $icon->getPath();
404
405 $form->setValuesByArray($values);
406 }
407
408 public function updateIcon()
409 {
410 global $DIC;
411
412
413 $icon_path = $_POST['selected_icon'];
414 $icon = $this->getIconFolder()->getIconByPath($icon_path);
415
416 $form = $this->initByIconForm($icon);
417
418 if ($form->checkInput()) {
419 $message_stack = new ilSystemStyleMessageStack();
420
421 $color_changes = [];
422 foreach ($icon->getColorSet()->getColors() as $old_color) {
423 $new_color = $form->getInput($old_color->getId());
424 if (!preg_match("/[\dabcdef]{6}/i", $new_color)) {
425 $message_stack->addMessage(new ilSystemStyleMessage(
426 $this->lng->txt("invalid_color") . $new_color,
428 ));
429 } elseif ($new_color != $old_color->getColor()) {
430 $color_changes[$old_color->getColor()] = $new_color;
431
432 $message_stack->addMessage(new ilSystemStyleMessage(
433 $this->lng->txt("color_changed_from") . " " . $old_color->getColor() . " " .
434 $this->lng->txt("color_changed_to") . " " . $new_color,
436 ));
437 }
438 }
439 $icon->changeColors($color_changes);
440
441 if ($_POST["changed_icon"]) {
445 $upload = $DIC->upload();
446 $upload->process();
447 $old_icon = $this->getIconFolder()->getIconByPath($icon_path);
448
449 $upload->moveOneFileTo(
450 array_pop($upload->getResults()),
451 $old_icon->getDirRelToCustomizing(),
452 Location::CUSTOMIZING,
453 $old_icon->getName(),
454 true
455 );
456 }
457
458 $message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt("color_update"), ilSystemStyleMessage::TYPE_SUCCESS));
459
460 foreach ($message_stack->getJoinedMessages() as $type => $message) {
462 $skin = $this->getStyleContainer()->getSkin();
463 $skin->getVersionStep($skin->getVersion());
464 $this->getStyleContainer()->updateSkin($skin);
465 continue;
466 }
467 }
468 $message_stack->sendMessages(true);
469 $this->ctrl->setParameter($this, "selected_icon", $icon->getPath());
470 $this->ctrl->redirect($this, "editIcon");
471 }
472 $form->setValuesByPost();
473 $this->tpl->setContent($form->getHTML());
474 }
475
480 protected function renderIconPreview(ilSystemStyleIcon $icon)
481 {
482 global $DIC;
483
484 $f = $DIC->ui()->factory();
485
486 $icon_image = $f->image()->standard($icon->getPath(), $icon->getName());
487
488 $card = $f->card()->standard(
489 $icon->getName(),
490 $icon_image
491 );
492
493 $report = $f->panel()->standard($this->lng->txt("preview"), $f->deck([$card]));
494
495 return $DIC->ui()->renderer()->render($report);
496 }
497
498
502 protected function renderIconsPreviews()
503 {
504 global $DIC;
505
506 $f = $DIC->ui()->factory();
507
508
509 $sub_panels = [];
510 foreach ($this->getIconFolder()->getIconsSortedByFolder() as $folder_name => $icons) {
511 $cards = [];
512
513 foreach ($icons as $icon) {
517 $icon_image = $f->image()->standard($icon->getPath(), $icon->getName());
518 $card = $f->card()->standard(
519 $icon->getName(),
520 $icon_image
521 );
522 $colors = $icon->getColorSet()->asString();
523 if ($colors) {
524 $card = $card->withSections(array(
525 $f->listing()->descriptive(array($this->lng->txt("used_colors") => $colors))
526 ));
527 }
528 $cards[] = $card;
529 }
530 $sub_panels[] = $f->panel()->sub($folder_name, $f->deck($cards));
531 }
532
533 $report = $f->panel()->report($this->lng->txt("icons"), $sub_panels);
534
535 return $DIC->ui()->renderer()->render($report);
536 }
537
541 public function getStyleContainer()
542 {
544 }
545
550 {
551 $this->style_container = $style_container;
552 }
553
557 public function getIconFolder()
558 {
559 return $this->icon_folder;
560 }
561
566 {
567 $this->icon_folder = $icon_folder;
568 }
569}
$section
Definition: Utf8Test.php:83
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Color picker form for selecting color hexcodes using yui library.
This class represents a file property in a property form.
This class represents a section header in a property form.
This class represents a hidden form property in a property form.
This class represents a property form user interface.
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.
This class represents a selection list property in a property form.
static getInstance()
Factory.
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 ...
getByColorValues(ilPropertyFormGUI $form)
getByIconValues(ilPropertyFormGUI $form, ilSystemStyleIcon $icon)
renderIconPreview(ilSystemStyleIcon $icon)
__construct($skin_id="", $style_id="")
ilSystemStyleIconsGUI constructor.
Used to stack messages to be shown to the user.
static generateFromId($skin_id, ilSystemStyleMessageStack $message_stack=null, ilSystemStyleConfig $system_styles_conf=null)
Generate the container class by parsing the corresponding XML.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Interface Location.
Definition: Location.php:17
$type
$message
Definition: xapiexit.php:14
$DIC
Definition: xapitoken.php:46