ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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...
 
 sortIconsByPath ()
 
 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)
 
 getIconByPath ($path)
 
 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 134 of file class.ilSystemStyleIconFolder.php.

Referenced by xRead().

135  {
136  $this->icons[] = $icon;
137  }
+ 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 122 of file class.ilSystemStyleIconFolder.php.

References getIcons().

123  {
124  foreach ($this->getIcons() as $icon) {
125  $icon->changeColors($color_changes);
126  }
127  }
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 238 of file class.ilSystemStyleIconFolder.php.

References getIcons().

Referenced by getColorSet().

239  {
240  $this->color_set = new ilSystemStyleIconColorSet();
241  foreach ($this->getIcons() as $icon) {
242  $this->color_set->mergeColorSet($icon->getColorSet());
243  }
244  }
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 227 of file class.ilSystemStyleIconFolder.php.

References $color_set, and extractColorSet().

228  {
229  if (!$this->color_set) {
230  $this->extractColorSet();
231  }
232  return $this->color_set;
233  }
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 154 of file class.ilSystemStyleIconFolder.php.

References $name, and ilSystemStyleIconException\ICON_DOES_NOT_EXIST.

155  {
156  foreach ($this->icons as $icon) {
157  if ($icon->getName() == $name) {
158  return $icon;
159  }
160  }
162  }
Class for advanced editing exception handling in ILIAS.
if($format !==null) $name
Definition: metadata.php:230

◆ getIconByPath()

ilSystemStyleIconFolder::getIconByPath (   $path)
Parameters
$path
Returns
ilSystemStyleIcon
Exceptions
ilSystemStyleIconException

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

References $path, and ilSystemStyleIconException\ICON_DOES_NOT_EXIST.

170  {
171  foreach ($this->icons as $icon) {
172  if ($icon->getPath() == $path) {
173  return $icon;
174  }
175  }
177  }
Class for advanced editing exception handling in ILIAS.

◆ getIcons()

ilSystemStyleIconFolder::getIcons ( )

Gets an Icon from the folders abstraction.

Returns
ilSystemStyleIcon[]

Definition at line 144 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 184 of file class.ilSystemStyleIconFolder.php.

References getIcons().

185  {
186  $folders = [];
187 
188  foreach ($this->getIcons() as $icon) {
189  $folders[dirname($icon->getPath())][] = $icon;
190  }
191 
192  ksort($folders);
193 
194  foreach ($folders as $id => $folder) {
195  ksort($folders[$id]);
196  }
197 
198  return $folders;
199  }
getIcons()
Gets an Icon from the folders abstraction.
+ Here is the call graph for this function:

◆ getPath()

ilSystemStyleIconFolder::getPath ( )
Returns
string

Definition at line 211 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 252 of file class.ilSystemStyleIconFolder.php.

References $icons, and getIcons().

Referenced by getUsagesOfColorAsString().

253  {
254  $icons = [];
255  foreach ($this->getIcons() as $icon) {
256  if ($icon->usesColor($color_id)) {
257  $icons[] = $icon;
258  }
259  }
260  return $icons;
261  }
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 269 of file class.ilSystemStyleIconFolder.php.

References getUsagesOfColor().

270  {
271  $usage_string = "";
272  foreach ($this->getUsagesOfColor($color_id) as $icon) {
273  $usage_string .= rtrim($icon->getName(), ".svg") . "; ";
274  }
275  return $usage_string;
276  }
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 281 of file class.ilSystemStyleIconFolder.php.

References $color_set.

282  {
283  $this->color_set = $color_set;
284  }

◆ setIcons()

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

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

References $icons.

204  {
205  $this->icons = $icons;
206  }

◆ setPath()

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

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

References $path.

Referenced by __construct().

220  {
221  $this->path = $path;
222  }
+ 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 Vendor\Package\$a, Vendor\Package\$b, 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. ...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sortIconsByPath()

ilSystemStyleIconFolder::sortIconsByPath ( )

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

References Vendor\Package\$a, Vendor\Package\$b, and ilSystemStyleIcon\getPath().

79  : void
80  {
81  usort($this->icons, static function (ilSystemStyleIcon $a, ilSystemStyleIcon $b) : int {
82  return strcmp($a->getPath(), $b->getPath());
83  });
84  }
Abstracts an Icon and the necessary actions to get all colors out of an svg Icon. ...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:

◆ xRead()

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

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

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

Referenced by read().

93  {
94  if (!is_dir($src)) {
96  }
97  foreach (scandir($src) as $file) {
98  $src_file = rtrim($src, '/') . '/' . $file;
99  if (!is_readable($src_file)) {
101  }
102  if (substr($file, 0, 1) != ".") {
103  if (is_dir($src_file)) {
104  self::xRead($src_file, $rel_path . "/" . $file);
105  } else {
106  $info = new SplFileInfo($src_file);
107  $extension = $info->getExtension();
108  if ($extension == "gif" || $extension == "svg" || $extension == "png") {
109  $this->addIcon(new ilSystemStyleIcon($file, $this->getPath() . $rel_path . "/" . $file, $extension));
110  }
111  }
112  }
113  }
114  }
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.
+ 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(), getIconByPath(), getPath(), and setPath().


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