ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilSystemStyleIconFolder Class Reference

Abstracts a folder containing a set of icons. More...

+ Collaboration diagram for ilSystemStyleIconFolder:

Public Member Functions

 __construct ($path)
 ilSystemStyleIconFolder constructor. More...
 
 read ()
 Reads the folder recursively and sorts the icons by name and type. More...
 
 changeIconColors (array $color_changes)
 Changes a set of colors in all icons contained in the folder. More...
 
 addIcon (ilSystemStyleIcon $icon)
 Adds an icon to the folders abstraction. More...
 
 getIcons ()
 Gets an Icon from the folders abstraction. More...
 
 getIconByName ($name)
 
 getIconsSortedByFolder ()
 Sorts all icons by their occurrence in folders. More...
 
 setIcons ($icons)
 
 getPath ()
 
 setPath ($path)
 
 getColorSet ()
 
 getUsagesOfColor ($color_id)
 Gets the usages of a certain color. More...
 
 getUsagesOfColorAsString ($color_id)
 Gets the usages of a color as string. More...
 
 setColorSet ($color_set)
 

Protected Member Functions

 sortIcons ()
 Sorts the Icons by name and type. More...
 
 xRead ($src="", $rel_path="")
 
 extractColorSet ()
 Gets the color sets of all icons an merges them into one. More...
 

Protected Attributes

 $icons = []
 
 $path = ""
 
 $color_set = null
 

Detailed Description

Abstracts a folder containing a set of icons.

Author
Timon Amstutz timon.nosp@m..ams.nosp@m.tutz@.nosp@m.ilub.nosp@m..unib.nosp@m.e.ch
Version
$Id$

Class ilSystemStyleIconFolder

Definition at line 15 of file class.ilSystemStyleIconFolder.php.

Constructor & Destructor Documentation

◆ __construct()

ilSystemStyleIconFolder::__construct (   $path)

ilSystemStyleIconFolder constructor.

Parameters
string$path

Definition at line 42 of file class.ilSystemStyleIconFolder.php.

References $path, read(), and setPath().

43  {
44  $this->setPath($path);
45  $this->read();
46  }
read()
Reads the folder recursively and sorts the icons by name and type.
+ Here is the call graph for this function:

Member Function Documentation

◆ addIcon()

ilSystemStyleIconFolder::addIcon ( ilSystemStyleIcon  $icon)

Adds an icon to the folders abstraction.

Parameters
ilSystemStyleIcon$icon

Definition at line 127 of file class.ilSystemStyleIconFolder.php.

Referenced by xRead().

128  {
129  $this->icons[] = $icon;
130  }
+ Here is the caller graph for this function:

◆ changeIconColors()

ilSystemStyleIconFolder::changeIconColors ( array  $color_changes)

Changes a set of colors in all icons contained in the folder.

Parameters
array$color_changes

Definition at line 115 of file class.ilSystemStyleIconFolder.php.

References getIcons().

116  {
117  foreach ($this->getIcons() as $icon) {
118  $icon->changeColors($color_changes);
119  }
120  }
getIcons()
Gets an Icon from the folders abstraction.
+ Here is the call graph for this function:

◆ extractColorSet()

ilSystemStyleIconFolder::extractColorSet ( )
protected

Gets the color sets of all icons an merges them into one.

Definition at line 216 of file class.ilSystemStyleIconFolder.php.

References getIcons().

Referenced by getColorSet().

217  {
218  $this->color_set = new ilSystemStyleIconColorSet();
219  foreach ($this->getIcons() as $icon) {
220  $this->color_set->mergeColorSet($icon->getColorSet());
221  }
222  }
getIcons()
Gets an Icon from the folders abstraction.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getColorSet()

ilSystemStyleIconFolder::getColorSet ( )
Returns
ilSystemStyleIconColorSet

Definition at line 205 of file class.ilSystemStyleIconFolder.php.

References $color_set, and extractColorSet().

206  {
207  if (!$this->color_set) {
208  $this->extractColorSet();
209  }
210  return $this->color_set;
211  }
extractColorSet()
Gets the color sets of all icons an merges them into one.
+ Here is the call graph for this function:

◆ getIconByName()

ilSystemStyleIconFolder::getIconByName (   $name)
Parameters
$name
Returns
ilSystemStyleIcon
Exceptions
ilSystemStyleIconException

Definition at line 147 of file class.ilSystemStyleIconFolder.php.

References $name, and ilSystemStyleIconException\ICON_DOES_NOT_EXIST.

148  {
149  foreach ($this->icons as $icon) {
150  if ($icon->getName() == $name) {
151  return $icon;
152  }
153  }
155  }
Class for advanced editing exception handling in ILIAS.
if($format !==null) $name
Definition: metadata.php:146

◆ getIcons()

ilSystemStyleIconFolder::getIcons ( )

Gets an Icon from the folders abstraction.

Returns
ilSystemStyleIcon[]

Definition at line 137 of file class.ilSystemStyleIconFolder.php.

References $icons.

Referenced by changeIconColors(), extractColorSet(), getIconsSortedByFolder(), and getUsagesOfColor().

+ Here is the caller graph for this function:

◆ getIconsSortedByFolder()

ilSystemStyleIconFolder::getIconsSortedByFolder ( )

Sorts all icons by their occurrence in folders.

Returns
array array(folder_path_name => [$icons])

Definition at line 162 of file class.ilSystemStyleIconFolder.php.

References $id, and getIcons().

163  {
164  $folders = [];
165 
166  foreach ($this->getIcons() as $icon) {
167  $folders[dirname($icon->getPath())][] = $icon;
168  }
169 
170  ksort($folders);
171 
172  foreach ($folders as $id => $folder) {
173  ksort($folders[$id]);
174  }
175 
176  return $folders;
177  }
if(!array_key_exists('StateId', $_REQUEST)) $id
getIcons()
Gets an Icon from the folders abstraction.
+ Here is the call graph for this function:

◆ getPath()

ilSystemStyleIconFolder::getPath ( )
Returns
string

Definition at line 189 of file class.ilSystemStyleIconFolder.php.

References $path.

Referenced by read(), and xRead().

+ Here is the caller graph for this function:

◆ getUsagesOfColor()

ilSystemStyleIconFolder::getUsagesOfColor (   $color_id)

Gets the usages of a certain color.

Parameters
$color_id
Returns
ilSystemStyleIcon[]

Definition at line 230 of file class.ilSystemStyleIconFolder.php.

References $icons, and getIcons().

Referenced by getUsagesOfColorAsString().

231  {
232  $icons = [];
233  foreach ($this->getIcons() as $icon) {
234  if ($icon->usesColor($color_id)) {
235  $icons[] = $icon;
236  }
237  }
238  return $icons;
239  }
getIcons()
Gets an Icon from the folders abstraction.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUsagesOfColorAsString()

ilSystemStyleIconFolder::getUsagesOfColorAsString (   $color_id)

Gets the usages of a color as string.

Parameters
$color_id
Returns
string

Definition at line 247 of file class.ilSystemStyleIconFolder.php.

References getUsagesOfColor().

248  {
249  $usage_string = "";
250  foreach ($this->getUsagesOfColor($color_id) as $icon) {
251  $usage_string .= rtrim($icon->getName(), ".svg") . "; ";
252  }
253  return $usage_string;
254  }
getUsagesOfColor($color_id)
Gets the usages of a certain color.
+ Here is the call graph for this function:

◆ read()

ilSystemStyleIconFolder::read ( )

Reads the folder recursively and sorts the icons by name and type.

Exceptions
ilSystemStyleException

Definition at line 53 of file class.ilSystemStyleIconFolder.php.

References getPath(), sortIcons(), and xRead().

Referenced by __construct().

54  {
55  $this->xRead($this->getPath(), "");
56  $this->sortIcons();
57  }
sortIcons()
Sorts the Icons by name and type.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setColorSet()

ilSystemStyleIconFolder::setColorSet (   $color_set)
Parameters
$color_set

Definition at line 259 of file class.ilSystemStyleIconFolder.php.

References $color_set.

260  {
261  $this->color_set = $color_set;
262  }

◆ setIcons()

ilSystemStyleIconFolder::setIcons (   $icons)
Parameters
ilSystemStyleIcon[]$icons

Definition at line 181 of file class.ilSystemStyleIconFolder.php.

References $icons.

182  {
183  $this->icons = $icons;
184  }

◆ setPath()

ilSystemStyleIconFolder::setPath (   $path)
Parameters
string$path

Definition at line 197 of file class.ilSystemStyleIconFolder.php.

References $path.

Referenced by __construct().

198  {
199  $this->path = $path;
200  }
+ Here is the caller graph for this function:

◆ sortIcons()

ilSystemStyleIconFolder::sortIcons ( )
protected

Sorts the Icons by name and type.

Definition at line 62 of file class.ilSystemStyleIconFolder.php.

References ilSystemStyleIcon\getName(), and ilSystemStyleIcon\getType().

Referenced by read().

63  {
64  usort($this->icons, function (ilSystemStyleIcon $a, ilSystemStyleIcon $b) {
65  if ($a->getType() == $b->getType()) {
66  return strcmp($a->getName(), $b->getName());
67  } else {
68  if ($a->getType() == "svg") {
69  return false;
70  } elseif ($b->getType() == "svg") {
71  return true;
72  } else {
73  return strcmp($a->getType(), $b->getType());
74  }
75  }
76  });
77  }
Abstracts an Icon and the necessary actions to get all colors out of an svg Icon. ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ xRead()

ilSystemStyleIconFolder::xRead (   $src = "",
  $rel_path = "" 
)
protected
Parameters
string$src
string$rel_path
Exceptions
ilSystemStyleException
ilSystemStyleIconException

Definition at line 85 of file class.ilSystemStyleIconFolder.php.

References $file, $info, addIcon(), ilSystemStyleException\FILE_OPENING_FAILED, getPath(), and ilSystemStyleIconException\IMAGES_FOLDER_DOES_NOT_EXIST.

Referenced by read().

86  {
87  if (!is_dir($src)) {
89  }
90  foreach (scandir($src) as $file) {
91  $src_file = rtrim($src, '/') . '/' . $file;
92  if (!is_readable($src_file)) {
94  }
95  if (substr($file, 0, 1) != ".") {
96  if (is_dir($src_file)) {
97  self::xRead($src_file, $rel_path . "/" . $file);
98  } else {
99  $info = new SplFileInfo($src_file);
100  $extension = $info->getExtension();
101  if ($extension == "gif" || $extension == "svg" || $extension == "png") {
102  $this->addIcon(new ilSystemStyleIcon($file, $this->getPath() . $rel_path . "/" . $file, $extension));
103  }
104  }
105  }
106  }
107  }
Class for advanced editing exception handling in ILIAS.
addIcon(ilSystemStyleIcon $icon)
Adds an icon to the folders abstraction.
Abstracts an Icon and the necessary actions to get all colors out of an svg Icon. ...
Class for advanced editing exception handling in ILIAS.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
$info
Definition: index.php:5
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $color_set

ilSystemStyleIconFolder::$color_set = null
protected

Definition at line 36 of file class.ilSystemStyleIconFolder.php.

Referenced by getColorSet(), and setColorSet().

◆ $icons

ilSystemStyleIconFolder::$icons = []
protected

Definition at line 22 of file class.ilSystemStyleIconFolder.php.

Referenced by getIcons(), getUsagesOfColor(), and setIcons().

◆ $path

ilSystemStyleIconFolder::$path = ""
protected

Definition at line 29 of file class.ilSystemStyleIconFolder.php.

Referenced by __construct(), getPath(), and setPath().


The documentation for this class was generated from the following file: