ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilSystemStyleIconFolder.php
Go to the documentation of this file.
1<?php
2require_once("./Services/Style/System/classes/Icons/class.ilSystemStyleIcon.php");
3require_once("./Services/Style/System/classes/Exceptions/class.ilSystemStyleIconException.php");
4
16{
22 protected $icons = [];
23
29 protected $path = "";
30
36 protected $color_set = null;
37
42 public function __construct($path)
43 {
44 $this->setPath($path);
45 $this->read();
46 }
47
53 public function read()
54 {
55 $this->xRead($this->getPath(), "");
56 $this->sortIcons();
57 }
58
62 protected function sortIcons()
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 }
78
79 public function sortIconsByPath() : void
80 {
81 usort($this->icons, static function (ilSystemStyleIcon $a, ilSystemStyleIcon $b) : int {
82 return strcmp($a->getPath(), $b->getPath());
83 });
84 }
85
92 protected function xRead($src = "", $rel_path = "")
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 }
115
116
122 public function changeIconColors(array $color_changes)
123 {
124 foreach ($this->getIcons() as $icon) {
125 $icon->changeColors($color_changes);
126 }
127 }
128
134 public function addIcon(ilSystemStyleIcon $icon)
135 {
136 $this->icons[] = $icon;
137 }
138
144 public function getIcons()
145 {
146 return $this->icons;
147 }
148
154 public function getIconByName($name)
155 {
156 foreach ($this->icons as $icon) {
157 if ($icon->getName() == $name) {
158 return $icon;
159 }
160 }
162 }
163
169 public function getIconByPath($path)
170 {
171 foreach ($this->icons as $icon) {
172 if ($icon->getPath() == $path) {
173 return $icon;
174 }
175 }
177 }
178
184 public function getIconsSortedByFolder()
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 }
203 public function setIcons($icons)
204 {
205 $this->icons = $icons;
206 }
207
211 public function getPath()
212 {
213 return $this->path;
214 }
215
219 public function setPath($path)
220 {
221 $this->path = $path;
222 }
223
227 public function getColorSet()
228 {
229 if (!$this->color_set) {
230 $this->extractColorSet();
231 }
232 return $this->color_set;
233 }
234
238 protected function extractColorSet()
239 {
240 $this->color_set = new ilSystemStyleIconColorSet();
241 foreach ($this->getIcons() as $icon) {
242 $this->color_set->mergeColorSet($icon->getColorSet());
243 }
244 }
245
252 public function getUsagesOfColor($color_id)
253 {
254 $icons = [];
255 foreach ($this->getIcons() as $icon) {
256 if ($icon->usesColor($color_id)) {
257 $icons[] = $icon;
258 }
259 }
260 return $icons;
261 }
262
269 public function getUsagesOfColorAsString($color_id)
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 }
277
281 public function setColorSet($color_set)
282 {
283 $this->color_set = $color_set;
284 }
285}
An exception for terminatinating execution or to throw for unit testing.
Class for advanced editing exception handling in ILIAS.
Class for advanced editing exception handling in ILIAS.
Abstracts a folder containing a set of icons.
sortIcons()
Sorts the Icons by name and type.
changeIconColors(array $color_changes)
Changes a set of colors in all icons contained in the folder.
addIcon(ilSystemStyleIcon $icon)
Adds an icon to the folders abstraction.
getUsagesOfColor($color_id)
Gets the usages of a certain color.
getUsagesOfColorAsString($color_id)
Gets the usages of a color as string.
__construct($path)
ilSystemStyleIconFolder constructor.
extractColorSet()
Gets the color sets of all icons an merges them into one.
getIconsSortedByFolder()
Sorts all icons by their occurrence in folders.
getIcons()
Gets an Icon from the folders abstraction.
read()
Reads the folder recursively and sorts the icons by name and type.
Abstracts an Icon and the necessary actions to get all colors out of an svg Icon.
if($format !==null) $name
Definition: metadata.php:230
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples