ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
85 protected function xRead($src = "", $rel_path="")
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 }
108
109
115 public function changeIconColors(array $color_changes)
116 {
117 foreach ($this->getIcons() as $icon) {
118 $icon->changeColors($color_changes);
119 }
120 }
121
127 public function addIcon(ilSystemStyleIcon $icon)
128 {
129 $this->icons[] = $icon;
130 }
131
137 public function getIcons()
138 {
139 return $this->icons;
140 }
141
147 public function getIconByName($name)
148 {
149 foreach ($this->icons as $icon) {
150 if ($icon->getName() == $name) {
151 return $icon;
152 }
153 }
155 }
156
162 public function getIconsSortedByFolder()
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 }
181 public function setIcons($icons)
182 {
183 $this->icons = $icons;
184 }
185
189 public function getPath()
190 {
191 return $this->path;
192 }
193
197 public function setPath($path)
198 {
199 $this->path = $path;
200 }
201
205 public function getColorSet()
206 {
207 if (!$this->color_set) {
208 $this->extractColorSet();
209 }
210 return $this->color_set;
211 }
212
216 protected function extractColorSet()
217 {
218 $this->color_set = new ilSystemStyleIconColorSet();
219 foreach ($this->getIcons() as $icon) {
220 $this->color_set->mergeColorSet($icon->getColorSet());
221 }
222 }
223
230 public function getUsagesOfColor($color_id)
231 {
232 $icons = [];
233 foreach ($this->getIcons() as $icon) {
234 if ($icon->usesColor($color_id)) {
235 $icons[] = $icon;
236 }
237 }
238 return $icons;
239 }
240
247 public function getUsagesOfColorAsString($color_id)
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 }
255
259 public function setColorSet($color_set)
260 {
261 $this->color_set = $color_set;
262 }
263}
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(!array_key_exists('StateId', $_REQUEST)) $id
if($format !==null) $name
Definition: metadata.php:146
$info
Definition: index.php:5
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file