ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSystemStyleIconFolder.php
Go to the documentation of this file.
1 <?php
2 require_once("./Services/Style/System/classes/Icons/class.ilSystemStyleIcon.php");
3 require_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  $this->xRead($this->getPath(),"");
55  $this->sortIcons();
56  }
57 
61  protected function sortIcons(){
62  usort($this->icons, function(ilSystemStyleIcon $a, ilSystemStyleIcon $b){
63  if($a->getType() == $b->getType()){
64  return strcmp($a->getName(),$b->getName());
65  }
66  else{
67  if($a->getType() == "svg"){
68  return false;
69  }else if($b->getType() == "svg"){
70  return true;
71  }else{
72  return strcmp($a->getType(),$b->getType());
73  }
74  }
75  });
76  }
77 
84  protected function xRead($src = "",$rel_path=""){
85  if(!is_dir($src)){
87  }
88  foreach (scandir($src) as $file) {
89  $src_file = rtrim($src, '/') . '/' . $file;
90  if (!is_readable($src_file)) {
92  }
93  if (substr($file, 0, 1) != ".") {
94  if (is_dir($src_file)) {
95  self::xRead($src_file,$rel_path."/".$file);
96  } else {
97  $info = new SplFileInfo($src_file);
98  $extension = $info->getExtension();
99  if($extension == "gif" || $extension == "svg" || $extension == "png"){
100  $this->addIcon(new ilSystemStyleIcon($file,$this->getPath().$rel_path."/".$file,$extension));
101  }
102  }
103  }
104  }
105  }
106 
107 
113  public function changeIconColors(array $color_changes){
114  foreach($this->getIcons() as $icon){
115  $icon->changeColors($color_changes);
116  }
117  }
118 
124  public function addIcon(ilSystemStyleIcon $icon){
125  $this->icons[] = $icon;
126  }
127 
133  public function getIcons()
134  {
135  return $this->icons;
136  }
137 
143  public function getIconByName($name){
144  foreach($this->icons as $icon){
145  if($icon->getName() == $name){
146  return $icon;
147  }
148  }
150  }
151 
157  public function getIconsSortedByFolder(){
158  $folders = [];
159 
160  foreach($this->getIcons() as $icon){
161  $folders[dirname($icon->getPath())][] = $icon;
162  }
163 
164  ksort($folders);
165 
166  foreach($folders as $id => $folder){
167  ksort($folders[$id]);
168  }
169 
170  return $folders;
171  }
175  public function setIcons($icons)
176  {
177  $this->icons = $icons;
178  }
179 
183  public function getPath()
184  {
185  return $this->path;
186  }
187 
191  public function setPath($path)
192  {
193  $this->path = $path;
194  }
195 
199  public function getColorSet()
200  {
201  if(!$this->color_set){
202  $this->extractColorSet();
203  }
204  return $this->color_set;
205  }
206 
210  protected function extractColorSet(){
211  $this->color_set = new ilSystemStyleIconColorSet();
212  foreach($this->getIcons() as $icon){
213  $this->color_set->mergeColorSet($icon->getColorSet());
214  }
215  }
216 
223  public function getUsagesOfColor($color_id){
224  $icons = [];
225  foreach($this->getIcons() as $icon){
226  if($icon->usesColor($color_id)){
227  $icons[] = $icon;
228  }
229  }
230  return $icons;
231  }
232 
239  public function getUsagesOfColorAsString($color_id)
240  {
241  $usage_string = "";
242  foreach($this->getUsagesOfColor($color_id) as $icon){
243  $usage_string .= rtrim($icon->getName(),".svg")."; ";
244  }
245  return $usage_string;
246  }
247 
251  public function setColorSet($color_set)
252  {
253  $this->color_set = $color_set;
254  }
255 
256 
257 }
Class for advanced editing exception handling in ILIAS.
sortIcons()
Sorts the Icons by name and type.
getUsagesOfColorAsString($color_id)
Gets the usages of a color as string.
addIcon(ilSystemStyleIcon $icon)
Adds an icon to the folders abstraction.
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.
Abstracts an Icon and the necessary actions to get all colors out of an svg Icon. ...
getUsagesOfColor($color_id)
Gets the usages of a certain color.
$info
Definition: example_052.php:80
Class for advanced editing exception handling in ILIAS.
changeIconColors(array $color_changes)
Changes a set of colors in all icons contained in the folder.
Create styles array
The data for the language used.
Abstracts a folder containing a set of icons.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
__construct($path)
ilSystemStyleIconFolder constructor.
read()
Reads the folder recursively and sorts the icons by name and type.