ILIAS  release_7 Revision v7.30-3-g800a261c036
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.

43 {
44 $this->setPath($path);
45 $this->read();
46 }
read()
Reads the folder recursively and sorts the icons by name and type.

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

+ 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.

135 {
136 $this->icons[] = $icon;
137 }

◆ 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.

123 {
124 foreach ($this->getIcons() as $icon) {
125 $icon->changeColors($color_changes);
126 }
127 }
getIcons()
Gets an Icon from the folders abstraction.

◆ 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.

239 {
240 $this->color_set = new ilSystemStyleIconColorSet();
241 foreach ($this->getIcons() as $icon) {
242 $this->color_set->mergeColorSet($icon->getColorSet());
243 }
244 }

◆ getColorSet()

ilSystemStyleIconFolder::getColorSet ( )
Returns
ilSystemStyleIconColorSet

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

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.

◆ getIconByName()

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

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

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

References $name, and ilSystemStyleIconException\ICON_DOES_NOT_EXIST.

◆ getIconByPath()

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

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

170 {
171 foreach ($this->icons as $icon) {
172 if ($icon->getPath() == $path) {
173 return $icon;
174 }
175 }
177 }

References ilSystemStyleIconException\ICON_DOES_NOT_EXIST.

◆ getIcons()

ilSystemStyleIconFolder::getIcons ( )

Gets an Icon from the folders abstraction.

Returns
ilSystemStyleIcon[]

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

◆ 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.

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 }

◆ getPath()

ilSystemStyleIconFolder::getPath ( )
Returns
string

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

212 {
213 return $this->path;
214 }

Referenced by read().

+ 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.

253 {
254 $icons = [];
255 foreach ($this->getIcons() as $icon) {
256 if ($icon->usesColor($color_id)) {
257 $icons[] = $icon;
258 }
259 }
260 return $icons;
261 }

◆ 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.

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.

◆ 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.

54 {
55 $this->xRead($this->getPath(), "");
56 $this->sortIcons();
57 }
sortIcons()
Sorts the Icons by name and type.

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

Referenced by __construct().

+ 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.

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

◆ setIcons()

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

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

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

◆ setPath()

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

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

220 {
221 $this->path = $path;
222 }

Referenced by __construct().

+ 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.

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

References Vendor\Package\$a, and Vendor\Package\$b.

Referenced by read().

+ Here is the caller graph for this function:

◆ sortIconsByPath()

ilSystemStyleIconFolder::sortIconsByPath ( )

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

79 : void
80 {
81 usort($this->icons, static function (ilSystemStyleIcon $a, ilSystemStyleIcon $b) : int {
82 return strcmp($a->getPath(), $b->getPath());
83 });
84 }

References Vendor\Package\$a, and Vendor\Package\$b.

◆ 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.

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.

References ilSystemStyleException\FILE_OPENING_FAILED, and ilSystemStyleIconException\IMAGES_FOLDER_DOES_NOT_EXIST.

Referenced by read().

+ 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.

◆ $icons

ilSystemStyleIconFolder::$icons = []
protected

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

◆ $path

ilSystemStyleIconFolder::$path = ""
protected

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

Referenced by __construct().


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