ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSystemStyleIconsGUI.php
Go to the documentation of this file.
1 <?php
2 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
3 include_once("Services/Style/System/classes/Utilities/class.ilSystemStyleSkinContainer.php");
4 include_once("Services/Style/System/classes/Icons/class.ilSystemStyleIconColorSet.php");
5 include_once("Services/Style/System/classes/Icons/class.ilSystemStyleIconFolder.php");
6 
15 {
19  protected $ctrl;
20 
24  protected $lng;
25 
29  protected $tpl;
30 
34  protected $style_container;
35 
39  protected $icon_folder = null;
40 
44  protected $tabs;
45 
51  function __construct($skin_id = "",$style_id = "")
52  {
53  global $DIC;
54 
55  $this->ctrl = $DIC->ctrl();
56  $this->lng = $DIC->language();
57  $this->tpl = $DIC["tpl"];
58  $this->tabs = $DIC->tabs();
59 
60  if($skin_id == ""){
61  $skin_id = $_GET["skin_id"];
62  }
63  if($style_id == ""){
64  $style_id = $_GET["style_id"];
65  }
67  if($this->ctrl->getCmd() != "reset"){
68  try{
69  $this->setIconFolder(new ilSystemStyleIconFolder($this->getStyleContainer()->getImagesSkinPath($style_id)));
70  }catch(ilSystemStyleExceptionBase $e){
71  ilUtil::sendFailure($e->getMessage());
72  $this->ctrl->setCmd("fail");
73  }
74  }
75 
76  }
77 
81  function executeCommand()
82  {
83  $cmd = $this->ctrl->getCmd();
84  $this->setSubStyleSubTabs($cmd);
85 
86  switch ($cmd)
87  {
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  $form = $this->initByColorForm();
111  $this->tpl->setContent($form->getHTML());
112  }
113 
117  protected function setSubStyleSubTabs($active = "") {
118  $this->tabs->addSubTab('edit', $this->lng->txt('edit_by_color'), $this->ctrl->getLinkTarget($this,'edit'));
119  $this->tabs->addSubTab('editIcon', $this->lng->txt('edit_by_icon'), $this->ctrl->getLinkTarget($this,'editIcon'));
120  $this->tabs->addSubTab('preview', $this->lng->txt('icons_gallery'), $this->ctrl->getLinkTarget($this,"preview"));
121 
122  if($active == "preview"){
123  $this->tabs->activateSubTab($active);
124  }else if($active == "cancelIcon"|| $active == "editIcon"){
125  $this->tabs->activateSubTab("editIcon");
126  }
127  else{
128  $this->tabs->activateSubTab("edit");
129  }
130 
131  }
132 
133  protected function edit(){
134  $form = $this->initByColorForm();
135  $this->getByColorValues($form);
136  $this->tpl->setContent($form->getHTML());
137  }
138 
139  protected function preview(){
140  $this->tpl->setContent($this->renderIconsPreviews());
141  }
145  public function initByColorForm()
146  {
147  $form = new ilPropertyFormGUI();
148 
149  $form->setTitle($this->lng->txt("adapt_icons"));
150  $form->setDescription($this->lng->txt("adapt_icons_description"));
151 
152  $color_set = [];
153 
154  if($this->getIconFolder()){
155  try{
156  $color_set = $this->getIconFolder()->getColorSet()->getColorsSortedAsArray();
157  }catch(ilSystemStyleExceptionBase $e) {
158  ilUtil::sendFailure($e->getMessage());
159  }
160  }
161 
162  foreach($color_set as $type => $colors){
164  $title = "";
165 
166  if($type == ilSystemStyleIconColor::GREY){
167  $title = $this->lng->txt("grey_color");
168  $section->setTitle($this->lng->txt("grey_colors"));
169  $section->setInfo($this->lng->txt("grey_colors_description"));
170  $section->setSectionAnchor($this->lng->txt("grey_colors"));
171  }
172  if($type == ilSystemStyleIconColor::RED){
173  $title = $this->lng->txt("red_color");
174  $section->setTitle($this->lng->txt("red_colors"));
175  $section->setInfo($this->lng->txt("red_colors_description"));
176  $section->setSectionAnchor($this->lng->txt("red_colors"));
177  }
178  if($type == ilSystemStyleIconColor::GREEN){
179  $title = $this->lng->txt("green_color");
180  $section->setTitle($this->lng->txt("green_colors"));
181  $section->setInfo($this->lng->txt("green_colors_description"));
182  $section->setSectionAnchor($this->lng->txt("green_colors"));
183  }
184  if($type == ilSystemStyleIconColor::BLUE){
185  $title = $this->lng->txt("blue_color");
186  $section->setTitle($this->lng->txt("blue_colors"));
187  $section->setInfo($this->lng->txt("blue_colors_description"));
188  $section->setSectionAnchor($this->lng->txt("blue_colors"));
189  }
190  $form->addItem($section);
191 
192  foreach($colors as $id => $color){
196  $input = new ilColorPickerInputGUI($title." ".($id+1),$color->getId());
197  $input->setRequired(true);
198  $input->setInfo("Usages: ".$this->getIconFolder()->getUsagesOfColorAsString($color->getId()));
199  $form->addItem($input);
200  }
201  }
202 
203  $has_icons = $this->getIconFolder() && count($this->getIconFolder()->getIcons()) > 0;
204 
205  if($has_icons){
206  $form->addCommandButton("update", $this->lng->txt("update_colors"));
207  }
208  $form->addCommandButton("reset", $this->lng->txt("reset_icons"));
209  if($has_icons){
210  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
211  }
212 
213 
214 
215 
216  $form->setFormAction($this->ctrl->getFormAction($this));
217 
218  return $form;
219  }
220 
221 
226  {
227  $values = [];
228 
229  if($this->getIconFolder()){
230  $colors = $this->getIconFolder()->getColorSet()->getColors();
231  foreach($colors as $color){
232  $id = $color->getId();
233  if($colors[$color->getId()]){
234  $values[$id] = $colors[$color->getId()]->getColor();
235  }else{
236  $values[$id] = $color->getColor();
237  }
238  }
239  }
240 
241 
242  $form->setValuesByArray($values);
243  }
244 
245  public function reset()
246  {
247  $style = $this->getStyleContainer()->getSkin()->getStyle($_GET["style_id"]);
248  $this->getStyleContainer()->resetImages($style);
249  $this->setIconFolder(new ilSystemStyleIconFolder($this->getStyleContainer()->getImagesSkinPath($style->getId())));
250  $message_stack = new ilSystemStyleMessageStack();
251  $message_stack->sendMessages(true);
252  $message_stack->addMessage(new ilSystemStyleMessage(
253  $this->lng->txt("color_reset"),
255  $this->ctrl->redirect($this,"edit");
256  }
257 
258  public function update()
259  {
260  $form = $this->initByColorForm();
261  if ($form->checkInput())
262  {
263  $message_stack = new ilSystemStyleMessageStack();
264 
265  $color_changes = [];
266  foreach($this->getIconFolder()->getColorSet()->getColors() as $old_color){
267  $new_color = $form->getInput($old_color->getId());
268  if(!preg_match("/[\dabcdef]{6}/i",$new_color)){
269  $message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt("invalid_color").$new_color,
271  }else if($new_color != $old_color->getId()){
272  $color_changes[$old_color->getId()] = $new_color;
273  $message_stack->addMessage(new ilSystemStyleMessage(
274  $this->lng->txt("color_changed_from")." ".$old_color->getId()." ".
275  $this->lng->txt("color_changed_to")." ".$new_color,
277  }
278  }
279  $this->getIconFolder()->changeIconColors($color_changes);
280  $this->setIconFolder(new ilSystemStyleIconFolder($this->getStyleContainer()->getImagesSkinPath($_GET["style_id"])));
281  $skin = $this->getStyleContainer()->getSkin();
282  $skin->getVersionStep($skin->getVersion());
283  $this->getStyleContainer()->updateSkin($skin);
284  $message_stack->sendMessages(true);
285  $this->ctrl->redirect($this,"edit");
286  }
287  $form->setValuesByPost();
288  $this->tpl->setContent($form->getHTML());
289  }
290 
291 
292  protected function editIcon(){
293  $icon_name = $_POST['selected_icon']?$_POST['selected_icon']:$_GET['selected_icon'];
294 
295  $this->addSelectIconToolbar($icon_name);
296 
297  if($icon_name){
298  $icon = $this->getIconFolder()->getIconByName($icon_name);
299  $form = $this->initByIconForm($icon);
300  $this->getByIconValues($form, $icon);
301  $this->tpl->setContent($form->getHTML().$this->renderIconPreview($icon));
302  }
303  }
304 
308  protected function addSelectIconToolbar($icon_name){
309  global $DIC;
310 
311  $toolbar = $DIC->toolbar();
312 
313  $si = new ilSelectInputGUI($this->lng->txt("select_icon"), "selected_icon");
314 
315  $options = array();
316  foreach($this->getIconFolder()->getIcons() as $icon) {
317  if($icon->getType()=="svg"){
318  $options[$icon->getName()] = $icon->getName();
319  }
320  }
321 
322  $si->setOptions($options);
323 
324  $si->setValue($icon_name);
325 
326  $toolbar->addInputItem($si, true);
327 
328  $select_btn = ilSubmitButton::getInstance();
329  $select_btn->setCaption($this->lng->txt("select"),false);
330  $toolbar->addButtonInstance($select_btn);
331  $toolbar->setFormAction($this->ctrl->getLinkTarget($this, 'editIcon'));
332  }
333 
338  public function initByIconForm(ilSystemStyleIcon $icon)
339  {
340  $form = new ilPropertyFormGUI();
341 
342  $form->setTitle($this->lng->txt("adapt_icon")." ".$icon->getName());
343  $form->setDescription($this->lng->txt("adapt_icon_description"));
344 
345  $color_set = [];
346 
347  if($this->getIconFolder()){
348  try{
349  $color_set = $icon->getColorSet()->getColorsSortedAsArray();
350  }catch(ilSystemStyleExceptionBase $e) {
351  ilUtil::sendFailure($e->getMessage());
352  }
353  }
354 
355  foreach($color_set as $type => $colors){
356 
357  $title = $this->lng->txt("color");
358 
359  foreach($colors as $id => $color){
363  $input = new ilColorPickerInputGUI($title." ".($id+1),$color->getId());
364  $input->setRequired(true);
365  $form->addItem($input);
366  }
367  }
368 
369  $upload = new ilFileInputGUI($this->lng->txt("change_icon"),"changed_icon");
370  $upload->setSuffixes(["svg"]);
371  $form->addItem($upload);
372 
373  $hidden_name = new ilHiddenInputGUI("selected_icon");
374 
375  $form->addItem($hidden_name);
376 
377  if($this->getIconFolder() && count($this->getIconFolder()->getIcons()) > 0){
378  $form->addCommandButton("updateIcon", $this->lng->txt("update_icon"));
379  $form->addCommandButton("cancelIcon", $this->lng->txt("cancel"));
380  }
381 
382  $form->setFormAction($this->ctrl->getFormAction($this));
383 
384  return $form;
385  }
386 
387 
393  {
394  $values = [];
395 
396  $colors = $this->getIconFolder()->getColorSet()->getColors();
397  foreach($icon-> getColorSet()->getColors() as $color){
398  $id = $color->getId();
399  if($colors[$color->getId()]){
400  $values[$id] = $colors[$color->getId()]->getColor();
401  }else{
402  $values[$id] = $color->getColor();
403  }
404  }
405  $values["selected_icon"] = $icon->getName();
406 
407  $form->setValuesByArray($values);
408  }
409 
410  public function updateIcon()
411  {
412 
413  $icon_name = $_POST['selected_icon'];
414  $icon = $this->getIconFolder()->getIconByName($icon_name);
415 
416  $form = $this->initByIconForm($icon);
417 
418  if ($form->checkInput())
419  {
420  $message_stack = new ilSystemStyleMessageStack();
421 
422  $color_changes = [];
423  foreach($icon->getColorSet()->getColors() as $old_color){
424  $new_color = $form->getInput($old_color->getId());
425  if(!preg_match("/[\dabcdef]{6}/i",$new_color)){
426  $message_stack->addMessage(new ilSystemStyleMessage($this->lng->txt("invalid_color").$new_color,
428  }else if($new_color != $old_color->getId()){
429  $color_changes[$old_color->getId()] = $new_color;
430 
431  $message_stack->addMessage(new ilSystemStyleMessage(
432  $this->lng->txt("color_changed_from")." ".$old_color->getId()." ".
433  $this->lng->txt("color_changed_to")." ".$new_color,
435  }
436  }
437  $icon->changeColors($color_changes);
438 
439  if($_POST["changed_icon"]){
440  $old_icon = $this->getIconFolder()->getIconByName($icon_name);
441  move_uploaded_file($_POST["changed_icon"]["tmp_name"],$old_icon->getPath());
442  }
443 
444 
445  foreach ($message_stack->getJoinedMessages() as $type => $message) {
447  $skin = $this->getStyleContainer()->getSkin();
448  $skin->getVersionStep($skin->getVersion());
449  $this->getStyleContainer()->updateSkin($skin);
450  continue;
451  }
452  }
453  $message_stack->sendMessages(true);
454  $this->ctrl->setParameter($this,"selected_icon",$icon->getName());
455  $this->ctrl->redirect($this,"editIcon");
456  }
457  $form->setValuesByPost();
458  $this->tpl->setContent($form->getHTML());
459  }
460 
465  protected function renderIconPreview(ilSystemStyleIcon $icon){
466  global $DIC;
467 
468  $f = $DIC->ui()->factory();
469 
470  $icon_image = $f->image()->standard($icon->getPath(),$icon->getName());
471 
472  $card = $f->card(
473  $icon->getName(),
474  $icon_image
475  );
476 
477  $report = $f->panel()->standard($this->lng->txt("preview"),$f->deck([$card]));
478 
479  return $DIC->ui()->renderer()->render($report);
480  }
481 
482 
486  protected function renderIconsPreviews(){
487  global $DIC;
488 
489  $f = $DIC->ui()->factory();
490 
491 
492  $sub_panels = [];
493  foreach($this->getIconFolder()->getIconsSortedByFolder() as $folder_name => $icons){
494  $cards = [];
495 
496  foreach($icons as $icon){
500  $icon_image = $f->image()->standard($icon->getPath(),$icon->getName());
501  $card = $f->card(
502  $icon->getName(),
503  $icon_image
504  );
505  $colors = $icon->getColorSet()->asString();
506  if($colors){
507  $card = $card->withSections(array(
508  $f->listing()->descriptive(array($this->lng->txt("used_colors")=>$colors))
509  ));
510  }
511  $cards[] = $card;
512  }
513  $sub_panels[] = $f->panel()->sub($folder_name,$f->deck($cards));
514  }
515 
516  $report = $f->panel()->report($this->lng->txt("icons"),$sub_panels);
517 
518  return $DIC->ui()->renderer()->render($report);
519  }
520 
524  public function getStyleContainer()
525  {
526  return $this->style_container;
527  }
528 
533  {
534  $this->style_container = $style_container;
535  }
536 
540  public function getIconFolder()
541  {
542  return $this->icon_folder;
543  }
544 
548  public function setIconFolder($icon_folder)
549  {
550  $this->icon_folder = $icon_folder;
551  }
552 }
$style
Definition: example_012.php:70
This class represents a selection list property in a property form.
This class represents a property form user interface.
$_GET["client_id"]
This class represents a section header in a property form.
This class represents a file property in a property form.
Color picker form for selecting color hexcodes using yui library.
$cmd
Definition: sahs_server.php:35
Abstracts an Icon and the necessary actions to get all colors out of an svg Icon. ...
$section
Definition: Utf8Test.php:83
This class represents a hidden form property in a property form.
if(!is_array($argv)) $options
getByIconValues(ilPropertyFormGUI $form, ilSystemStyleIcon $icon)
__construct($skin_id="", $style_id="")
ilSystemStyleIconsGUI constructor.
Create styles array
The data for the language used.
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.
renderIconPreview(ilSystemStyleIcon $icon)
changeColors(array $color_changes)
Changes colors in the svg file of the icon and updates the icon abstraction by extracting the colors ...
Abstracts a folder containing a set of icons.
Used to stack messages to be shown to the user.
global $DIC
setSuffixes($a_suffixes)
Set Accepted Suffixes.
$_POST["username"]
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.
Class for advanced editing exception handling in ILIAS.
setRequired($a_required)
Set Required.
getByColorValues(ilPropertyFormGUI $form)