ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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)));
72 } catch (ilSystemStyleExceptionBase $e) {
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();
159 } catch (ilSystemStyleExceptionBase $e) {
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
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->getId()) {
277 $color_changes[$old_color->getId()] = $new_color;
278 $message_stack->addMessage(new ilSystemStyleMessage(
279 $this->lng->txt("color_changed_from") . " " . $old_color->getId() . " " .
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()->getIconByName($icon_name);
310 $form = $this->initByIconForm($icon);
311 $this->getByIconValues($form, $icon);
312 $this->tpl->setContent($form->getHTML() . $this->renderIconPreview($icon));
313 }
314 }
315
319 protected function addSelectIconToolbar($icon_name)
320 {
321 global $DIC;
322
323 $toolbar = $DIC->toolbar();
324
325 $si = new ilSelectInputGUI($this->lng->txt("select_icon"), "selected_icon");
326
327 $options = array();
328 foreach ($this->getIconFolder()->getIcons() as $icon) {
329 if ($icon->getType()=="svg") {
330 $options[$icon->getName()] = $icon->getName();
331 }
332 }
333
334 $si->setOptions($options);
335
336 $si->setValue($icon_name);
337
338 $toolbar->addInputItem($si, true);
339
340 $select_btn = ilSubmitButton::getInstance();
341 $select_btn->setCaption($this->lng->txt("select"), false);
342 $toolbar->addButtonInstance($select_btn);
343 $toolbar->setFormAction($this->ctrl->getLinkTarget($this, 'editIcon'));
344 }
345
350 public function initByIconForm(ilSystemStyleIcon $icon)
351 {
352 $form = new ilPropertyFormGUI();
353
354 $form->setTitle($this->lng->txt("adapt_icon") . " " . $icon->getName());
355 $form->setDescription($this->lng->txt("adapt_icon_description"));
356
357 $color_set = [];
358
359 if ($this->getIconFolder()) {
360 try {
361 $color_set = $icon->getColorSet()->getColorsSortedAsArray();
362 } catch (ilSystemStyleExceptionBase $e) {
363 ilUtil::sendFailure($e->getMessage());
364 }
365 }
366
367 foreach ($color_set as $type => $colors) {
368 $title = $this->lng->txt("color");
369
370 foreach ($colors as $id => $color) {
374 $input = new ilColorPickerInputGUI($title . " " . ($id+1), $color->getId());
375 $input->setRequired(true);
376 $form->addItem($input);
377 }
378 }
379
380 $upload = new ilFileInputGUI($this->lng->txt("change_icon"), "changed_icon");
381 $upload->setSuffixes(["svg"]);
382 $form->addItem($upload);
383
384 $hidden_name = new ilHiddenInputGUI("selected_icon");
385
386 $form->addItem($hidden_name);
387
388 if ($this->getIconFolder() && count($this->getIconFolder()->getIcons()) > 0) {
389 $form->addCommandButton("updateIcon", $this->lng->txt("update_icon"));
390 $form->addCommandButton("cancelIcon", $this->lng->txt("cancel"));
391 }
392
393 $form->setFormAction($this->ctrl->getFormAction($this));
394
395 return $form;
396 }
397
398
404 {
405 $values = [];
406
407 $colors = $this->getIconFolder()->getColorSet()->getColors();
408 foreach ($icon-> getColorSet()->getColors() as $color) {
409 $id = $color->getId();
410 if ($colors[$color->getId()]) {
411 $values[$id] = $colors[$color->getId()]->getColor();
412 } else {
413 $values[$id] = $color->getColor();
414 }
415 }
416 $values["selected_icon"] = $icon->getName();
417
418 $form->setValuesByArray($values);
419 }
420
421 public function updateIcon()
422 {
423 global $DIC;
424
425
426 $icon_name = $_POST['selected_icon'];
427 $icon = $this->getIconFolder()->getIconByName($icon_name);
428
429 $form = $this->initByIconForm($icon);
430
431 if ($form->checkInput()) {
432 $message_stack = new ilSystemStyleMessageStack();
433
434 $color_changes = [];
435 foreach ($icon->getColorSet()->getColors() as $old_color) {
436 $new_color = $form->getInput($old_color->getId());
437 if (!preg_match("/[\dabcdef]{6}/i", $new_color)) {
438 $message_stack->addMessage(new ilSystemStyleMessage(
439 $this->lng->txt("invalid_color") . $new_color,
441 ));
442 } elseif ($new_color != $old_color->getId()) {
443 $color_changes[$old_color->getId()] = $new_color;
444
445 $message_stack->addMessage(new ilSystemStyleMessage(
446 $this->lng->txt("color_changed_from") . " " . $old_color->getId() . " " .
447 $this->lng->txt("color_changed_to") . " " . $new_color,
449 ));
450 }
451 }
452 $icon->changeColors($color_changes);
453
454 if ($_POST["changed_icon"]) {
458 $upload = $DIC->upload();
459 $upload->process();
460 $old_icon = $this->getIconFolder()->getIconByName($icon_name);
461
462 $upload->moveOneFileTo(
463 array_pop($upload->getResults()),
464 $old_icon->getDirRelToCustomizing(),
465 Location::CUSTOMIZING,
466 $old_icon->getName(),
467 true
468 );
469 }
470
471 $message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt("color_update"), ilSystemStyleMessage::TYPE_SUCCESS));
472
473 foreach ($message_stack->getJoinedMessages() as $type => $message) {
475 $skin = $this->getStyleContainer()->getSkin();
476 $skin->getVersionStep($skin->getVersion());
477 $this->getStyleContainer()->updateSkin($skin);
478 continue;
479 }
480 }
481 $message_stack->sendMessages(true);
482 $this->ctrl->setParameter($this, "selected_icon", $icon->getName());
483 $this->ctrl->redirect($this, "editIcon");
484 }
485 $form->setValuesByPost();
486 $this->tpl->setContent($form->getHTML());
487 }
488
493 protected function renderIconPreview(ilSystemStyleIcon $icon)
494 {
495 global $DIC;
496
497 $f = $DIC->ui()->factory();
498
499 $icon_image = $f->image()->standard($icon->getPath(), $icon->getName());
500
501 $card = $f->card(
502 $icon->getName(),
503 $icon_image
504 );
505
506 $report = $f->panel()->standard($this->lng->txt("preview"), $f->deck([$card]));
507
508 return $DIC->ui()->renderer()->render($report);
509 }
510
511
515 protected function renderIconsPreviews()
516 {
517 global $DIC;
518
519 $f = $DIC->ui()->factory();
520
521
522 $sub_panels = [];
523 foreach ($this->getIconFolder()->getIconsSortedByFolder() as $folder_name => $icons) {
524 $cards = [];
525
526 foreach ($icons as $icon) {
530 $icon_image = $f->image()->standard($icon->getPath(), $icon->getName());
531 $card = $f->card(
532 $icon->getName(),
533 $icon_image
534 );
535 $colors = $icon->getColorSet()->asString();
536 if ($colors) {
537 $card = $card->withSections(array(
538 $f->listing()->descriptive(array($this->lng->txt("used_colors")=>$colors))
539 ));
540 }
541 $cards[] = $card;
542 }
543 $sub_panels[] = $f->panel()->sub($folder_name, $f->deck($cards));
544 }
545
546 $report = $f->panel()->report($this->lng->txt("icons"), $sub_panels);
547
548 return $DIC->ui()->renderer()->render($report);
549 }
550
554 public function getStyleContainer()
555 {
557 }
558
563 {
564 $this->style_container = $style_container;
565 }
566
570 public function getIconFolder()
571 {
572 return $this->icon_folder;
573 }
574
579 {
580 $this->icon_folder = $icon_folder;
581 }
582}
$section
Definition: Utf8Test.php:83
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
$_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.
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.
$style
Definition: example_012.php:70
if(!array_key_exists('StateId', $_REQUEST)) $id
Interface Location.
Definition: Location.php:17
catch(Exception $e) $message
$type
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7