ILIAS  release_8 Revision v8.24
ilSystemStyleIcon Class Reference

Abstracts an Icon and the necessary actions to get all colors out of an svg Icon. More...

+ Collaboration diagram for ilSystemStyleIcon:

Public Member Functions

 __construct (string $name, string $path, string $type)
 
 changeColors (array $color_changes)
 Changes colors in the svg file of the icon and updates the icon abstraction by extracting the colors again. More...
 
 getType ()
 
 setType (string $type)
 
 getName ()
 
 setName (string $name)
 
 __toString ()
 
 getPath ()
 
 setPath (string $path)
 
 getDirRelToCustomizing ()
 Only get dir rel to the Customizing dir without name and extension from. More...
 
 getColorSet ()
 
 setColorSet (ilSystemStyleIconColorSet $color_set)
 
 usesColor (string $color_id)
 

Protected Member Functions

 extractColorSet ()
 Extracts all colors from the icon by parsing the svg file for a regular expresion. More...
 

Protected Attributes

string $path = ''
 Path to the icon including name and extension. More...
 
string $name = ''
 Name of the Icon. More...
 
string $type = ''
 Extension of the icon. More...
 
ilSystemStyleIconColorSet $color_set
 Color set extracted from the icon. More...
 

Detailed Description

Abstracts an Icon and the necessary actions to get all colors out of an svg Icon.

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

Constructor & Destructor Documentation

◆ __construct()

ilSystemStyleIcon::__construct ( string  $name,
string  $path,
string  $type 
)

Definition at line 46 of file class.ilSystemStyleIcon.php.

47 {
48 $this->setName($name);
49 $this->setType($type);
50 $this->setPath($path);
51 }
string $type
Extension of the icon.
string $name
Name of the Icon.
string $path
Path to the icon including name and extension.

References setName(), setPath(), and setType().

+ Here is the call graph for this function:

Member Function Documentation

◆ __toString()

ilSystemStyleIcon::__toString ( )

Definition at line 88 of file class.ilSystemStyleIcon.php.

88 : string
89 {
90 return $this->getName();
91 }

References getName().

+ Here is the call graph for this function:

◆ changeColors()

ilSystemStyleIcon::changeColors ( array  $color_changes)

Changes colors in the svg file of the icon and updates the icon abstraction by extracting the colors again.

Definition at line 56 of file class.ilSystemStyleIcon.php.

56 : void
57 {
58 if ($this->getType() == 'svg') {
59 $icon = file_get_contents($this->getPath());
60 foreach ($color_changes as $old_color => $new_color) {
61 $icon = preg_replace('/#' . $old_color . '/i', '#' . $new_color, $icon, -1);
62 }
63 file_put_contents($this->getPath(), $icon);
64 }
65 $this->extractColorSet();
66 }
extractColorSet()
Extracts all colors from the icon by parsing the svg file for a regular expresion.

References extractColorSet(), getPath(), and getType().

+ Here is the call graph for this function:

◆ extractColorSet()

ilSystemStyleIcon::extractColorSet ( )
protected

Extracts all colors from the icon by parsing the svg file for a regular expresion.

Definition at line 127 of file class.ilSystemStyleIcon.php.

127 : void
128 {
129 $regex_for_extracting_color = '/((?<=#)[\dabcdef]{6})|((?<=#)[\dabcdef]{3})/i';
130
131 $this->color_set = new ilSystemStyleIconColorSet();
132 if ($this->getType() == 'svg') {
133 $icon_content = file_get_contents($this->getPath());
134 $color_matches = [];
135 preg_match_all($regex_for_extracting_color, $icon_content, $color_matches);
136 if (is_array($color_matches) && is_array($color_matches[0])) {
137 foreach ($color_matches[0] as $color_value) {
138 $numeric = strtoupper(str_replace('#', '', $color_value));
139 $color = new ilSystemStyleIconColor('id_' . $numeric, $color_value, $numeric, $color_value);
140 $this->getColorSet()->addColor($color);
141 }
142 }
143 }
144 }

References getColorSet(), getPath(), and getType().

Referenced by changeColors(), and getColorSet().

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

◆ getColorSet()

ilSystemStyleIcon::getColorSet ( )

Definition at line 116 of file class.ilSystemStyleIcon.php.

117 {
118 if (!isset($this->color_set)) {
119 $this->extractColorSet();
120 }
121 return $this->color_set;
122 }
ilSystemStyleIconColorSet $color_set
Color set extracted from the icon.

References $color_set, and extractColorSet().

Referenced by extractColorSet(), and usesColor().

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

◆ getDirRelToCustomizing()

ilSystemStyleIcon::getDirRelToCustomizing ( )

Only get dir rel to the Customizing dir without name and extension from.

Definition at line 107 of file class.ilSystemStyleIcon.php.

107 : string
108 {
109 $path = strstr($this->getPath(), 'global/skin');
110 if (!$path) {
111 return '';
112 }
113 return dirname($path);
114 }

References $path, and getPath().

+ Here is the call graph for this function:

◆ getName()

ilSystemStyleIcon::getName ( )

Definition at line 78 of file class.ilSystemStyleIcon.php.

78 : string
79 {
80 return $this->name;
81 }

References $name.

Referenced by __toString(), and ilSystemStyleIconsGUI\renderIconPreview().

+ Here is the caller graph for this function:

◆ getPath()

ilSystemStyleIcon::getPath ( )

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

93 : string
94 {
95 return $this->path;
96 }

References $path.

Referenced by changeColors(), extractColorSet(), getDirRelToCustomizing(), and ilSystemStyleIconsGUI\renderIconPreview().

+ Here is the caller graph for this function:

◆ getType()

ilSystemStyleIcon::getType ( )

Definition at line 68 of file class.ilSystemStyleIcon.php.

68 : string
69 {
70 return $this->type;
71 }

References $type.

Referenced by changeColors(), and extractColorSet().

+ Here is the caller graph for this function:

◆ setColorSet()

ilSystemStyleIcon::setColorSet ( ilSystemStyleIconColorSet  $color_set)

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

146 : void
147 {
148 $this->color_set = $color_set;
149 }

References $color_set.

◆ setName()

ilSystemStyleIcon::setName ( string  $name)

Definition at line 83 of file class.ilSystemStyleIcon.php.

83 : void
84 {
85 $this->name = $name;
86 }

References $name.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setPath()

ilSystemStyleIcon::setPath ( string  $path)

Definition at line 98 of file class.ilSystemStyleIcon.php.

98 : void
99 {
100 $this->path = $path;
101 }

References $path.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setType()

ilSystemStyleIcon::setType ( string  $type)

Definition at line 73 of file class.ilSystemStyleIcon.php.

73 : void
74 {
75 $this->type = $type;
76 }

References $type.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ usesColor()

ilSystemStyleIcon::usesColor ( string  $color_id)

Definition at line 151 of file class.ilSystemStyleIcon.php.

151 : bool
152 {
153 return $this->getColorSet()->doesColorExist($color_id);
154 }

References getColorSet().

+ Here is the call graph for this function:

Field Documentation

◆ $color_set

ilSystemStyleIconColorSet ilSystemStyleIcon::$color_set
protected

Color set extracted from the icon.

Definition at line 44 of file class.ilSystemStyleIcon.php.

Referenced by getColorSet(), and setColorSet().

◆ $name

string ilSystemStyleIcon::$name = ''
protected

Name of the Icon.

Definition at line 34 of file class.ilSystemStyleIcon.php.

Referenced by getName(), and setName().

◆ $path

string ilSystemStyleIcon::$path = ''
protected

Path to the icon including name and extension.

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

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

◆ $type

string ilSystemStyleIcon::$type = ''
protected

Extension of the icon.

Definition at line 39 of file class.ilSystemStyleIcon.php.

Referenced by getType(), and setType().


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