ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
ilSystemStyleIconFolder Class Reference

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

+ Collaboration diagram for ilSystemStyleIconFolder:

Public Member Functions

 __construct (string $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 (string $name)
 
 getIconByPath (string $path)
 
 getIconsSortedByFolder ()
 Sorts all icons by their occurrence in folders. More...
 
 setIcons (array $icons)
 
 getPath ()
 
 setPath (string $path)
 
 getColorSet ()
 
 getUsagesOfColor (string $color_id)
 Gets the usages of a certain color. More...
 
 getUsagesOfColorAsString (string $color_id)
 Gets the usages of a color as string. More...
 
 setColorSet (ilSystemStyleIconColorSet $color_set)
 

Protected Member Functions

 sortIcons ()
 Sorts the Icons by name and type. More...
 
 compareIconsByName (ilSystemStyleIcon $a, ilSystemStyleIcon $b)
 
 readIconsFromFolder (string $src='')
 
 extractColorSet ()
 Gets the color sets of all icons an merges them into one. More...
 

Protected Attributes

array $icons = []
 
string $path = ''
 Path to the root of the folder. More...
 
ilSystemStyleIconColorSet $color_set
 Complete color set of all icons contained in this folder. More...
 

Detailed Description

Abstracts a folder containing a set of icons.

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

Constructor & Destructor Documentation

◆ __construct()

ilSystemStyleIconFolder::__construct ( string  $path)

ilSystemStyleIconFolder constructor.

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

46 {
47 $this->setPath($path);
48 $this->read();
49 }
string $path
Path to the root of the folder.
read()
Reads the folder recursively and sorts the icons by name and type.

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

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

129 : void
130 {
131 $this->icons[] = $icon;
132 }

Referenced by readIconsFromFolder().

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

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

119 : void
120 {
121 foreach ($this->getIcons() as $icon) {
122 $icon->changeColors($color_changes);
123 }
124 }
getIcons()
Gets an Icon from the folders abstraction.

References getIcons().

+ Here is the call graph for this function:

◆ compareIconsByName()

ilSystemStyleIconFolder::compareIconsByName ( ilSystemStyleIcon  $a,
ilSystemStyleIcon  $b 
)
protected

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

69 : int
70 {
71 if ($a->getType() == $b->getType()) {
72 return strcmp($a->getName(), $b->getName());
73 } elseif ($a->getType() == 'svg') {
74 return -1;
75 } elseif ($b->getType() == 'svg') {
76 return 1;
77 } else {
78 return strcmp($a->getType(), $b->getType());
79 }
80 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

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

◆ extractColorSet()

ilSystemStyleIconFolder::extractColorSet ( )
protected

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

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

219 : void
220 {
221 $this->color_set = new ilSystemStyleIconColorSet();
222 foreach ($this->getIcons() as $icon) {
223 $this->color_set->mergeColorSet($icon->getColorSet());
224 }
225 }

References getIcons().

Referenced by getColorSet().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getColorSet()

ilSystemStyleIconFolder::getColorSet ( )

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

209 {
210 if (!isset($this->color_set)) {
211 $this->extractColorSet();
212 }
213 return $this->color_set;
214 }
ilSystemStyleIconColorSet $color_set
Complete color set of all icons contained in this folder.
extractColorSet()
Gets the color sets of all icons an merges them into one.

References $color_set, and extractColorSet().

+ Here is the call graph for this function:

◆ getIconByName()

ilSystemStyleIconFolder::getIconByName ( string  $name)
Exceptions
ilSystemStyleIconException

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

147 {
148 foreach ($this->icons as $icon) {
149 if ($icon->getName() == $name) {
150 return $icon;
151 }
152 }
154 }
Class for advanced editing exception handling in ILIAS.
Abstracts an Icon and the necessary actions to get all colors out of an svg Icon.
if($format !==null) $name
Definition: metadata.php:247

References $name, and ilSystemStyleIconException\ICON_DOES_NOT_EXIST.

◆ getIconByPath()

ilSystemStyleIconFolder::getIconByPath ( string  $path)
Exceptions
ilSystemStyleIconException

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

160 {
161 foreach ($this->icons as $icon) {
162 if ($icon->getPath() == $path) {
163 return $icon;
164 }
165 }
167 }

References $path, and ilSystemStyleIconException\ICON_DOES_NOT_EXIST.

◆ getIcons()

ilSystemStyleIconFolder::getIcons ( )

Gets an Icon from the folders abstraction.

Returns
ilSystemStyleIcon[]

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

138 : array
139 {
140 return $this->icons;
141 }

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 173 of file class.ilSystemStyleIconFolder.php.

173 : array
174 {
175 $folders = [];
176
177 foreach ($this->getIcons() as $icon) {
178 $folders[dirname($icon->getPath())][] = $icon;
179 }
180
181 ksort($folders);
182
183 foreach ($folders as $id => $folder) {
184 ksort($folders[$id]);
185 }
186
187 return $folders;
188 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id, and getIcons().

+ Here is the call graph for this function:

◆ getPath()

ilSystemStyleIconFolder::getPath ( )

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

198 : string
199 {
200 return $this->path;
201 }

References $path.

Referenced by read().

+ Here is the caller graph for this function:

◆ getUsagesOfColor()

ilSystemStyleIconFolder::getUsagesOfColor ( string  $color_id)

Gets the usages of a certain color.

Returns
ilSystemStyleIcon[]

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

231 : array
232 {
233 $icons = [];
234 foreach ($this->getIcons() as $icon) {
235 if ($icon->usesColor($color_id)) {
236 $icons[] = $icon;
237 }
238 }
239 return $icons;
240 }

References $icons, and getIcons().

Referenced by getUsagesOfColorAsString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUsagesOfColorAsString()

ilSystemStyleIconFolder::getUsagesOfColorAsString ( string  $color_id)

Gets the usages of a color as string.

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

245 : string
246 {
247 $usage_string = '';
248 foreach ($this->getUsagesOfColor($color_id) as $icon) {
249 $usage_string .= rtrim($icon->getName(), '.svg') . '; ';
250 }
251 return $usage_string;
252 }
getUsagesOfColor(string $color_id)
Gets the usages of a certain color.

References getUsagesOfColor().

+ 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 55 of file class.ilSystemStyleIconFolder.php.

55 : void
56 {
57 $this->readIconsFromFolder($this->getPath());
58 $this->sortIcons();
59 }
sortIcons()
Sorts the Icons by name and type.

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

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readIconsFromFolder()

ilSystemStyleIconFolder::readIconsFromFolder ( string  $src = '')
protected
Exceptions
ilSystemStyleException
ilSystemStyleIconException

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

93 : void
94 {
95 try {
96 $dir_iterator = new RecursiveDirectoryIterator($src);
97 } catch (UnexpectedValueException $e) {
99 }
100
101 $rec_it = new RecursiveIteratorIterator($dir_iterator);
102
103 foreach ($rec_it as $file) {
104 if (!$file->isReadable()) {
106 }
107 if ($file->isFile()) {
108 $extension = $file->getExtension();
109 if ($extension == 'gif' || $extension == 'svg' || $extension == 'png') {
110 $this->addIcon(new ilSystemStyleIcon($file->getFilename(), $file->getPathname(), $extension));
111 }
112 }
113 }
114 }
Class for advanced editing exception handling in ILIAS.
addIcon(ilSystemStyleIcon $icon)
Adds an icon to the folders abstraction.

References Vendor\Package\$e, addIcon(), ilSystemStyleException\FILE_OPENING_FAILED, and ilSystemStyleIconException\IMAGES_FOLDER_DOES_NOT_EXIST.

Referenced by read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setColorSet()

ilSystemStyleIconFolder::setColorSet ( ilSystemStyleIconColorSet  $color_set)

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

254 : void
255 {
256 $this->color_set = $color_set;
257 }

References $color_set.

◆ setIcons()

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

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

193 : void
194 {
195 $this->icons = $icons;
196 }

References $icons.

◆ setPath()

ilSystemStyleIconFolder::setPath ( string  $path)

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

203 : void
204 {
205 $this->path = $path;
206 }

References $path.

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 64 of file class.ilSystemStyleIconFolder.php.

64 : void
65 {
66 usort($this->icons, [$this, 'compareIconsByName']);
67 }

Referenced by read().

+ Here is the caller graph for this function:

◆ sortIconsByPath()

ilSystemStyleIconFolder::sortIconsByPath ( )

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

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

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

Field Documentation

◆ $color_set

ilSystemStyleIconColorSet ilSystemStyleIconFolder::$color_set
protected

Complete color set of all icons contained in this folder.

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

Referenced by getColorSet(), and setColorSet().

◆ $icons

array ilSystemStyleIconFolder::$icons = []
protected

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

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

◆ $path

string ilSystemStyleIconFolder::$path = ''
protected

Path to the root of the folder.

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

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


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