ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\File\Icon\IconDatabaseRepository Class Reference
+ Inheritance diagram for ILIAS\File\Icon\IconDatabaseRepository:
+ Collaboration diagram for ILIAS\File\Icon\IconDatabaseRepository:

Public Member Functions

 __construct (private ?\ilDBInterface $db=null, private ?Services $irss=null)
 
 createIcon (string $a_rid, bool $a_active, bool $a_is_default_icon, array $a_suffixes)
 
 getIconsForFilter (array $filter)
 
 getIcons ()
 
 getIconByRid (string $a_rid)
 
 getActiveIconForSuffix (string $a_suffix)
 
 getIconFilePathBySuffix (string $suffix)
 
 updateIcon (string $a_rid, bool $a_active, bool $a_is_default_icon, array $a_suffixes)
 
 deleteIconByRid (string $a_rid)
 
- Public Member Functions inherited from ILIAS\File\Icon\IconAbstractRepository
 __construct ()
 
 turnSuffixesArrayIntoString (array $a_suffixes)
 
 turnSuffixesStringIntoArray (string $a_suffixes)
 
 hasSuffixInputOnlyAllowedCharacters (array $a_suffixes)
 
 hasSuffixInputNoDuplicatesToItsOwnEntries (array $a_suffixes)
 
 causesNoActiveSuffixesConflict (array $a_future_suffixes, bool $a_future_activation_state, Icon $a_current_icon)
 
 createIcon (string $a_rid, bool $a_active, bool $a_is_default_icon, array $a_suffixes)
 
 getIcons ()
 
 getIconsForFilter (array $filter)
 
 getIconByRid (string $a_rid)
 
 getActiveIconForSuffix (string $a_suffix)
 
 getIconFilePathBySuffix (string $suffix)
 
 updateIcon (string $a_rid, bool $a_active, bool $a_is_default_icon, array $a_suffixes)
 
 deleteIconByRid (string $a_rid)
 

Data Fields

const ICON_TABLE_NAME = 'il_file_icon'
 
const ICON_RESOURCE_IDENTIFICATION = 'rid'
 
const ICON_ACTIVE = 'active'
 
const IS_DEFAULT_ICON = 'is_default_icon'
 
const SUFFIX_TABLE_NAME = 'il_file_icon_suffixes'
 
const SUFFIX = 'suffix'
 
const SUFFIXES = 'suffixes'
 

Detailed Description

Author
Lukas Zehnder lukas.nosp@m.@sr..nosp@m.solut.nosp@m.ions

Definition at line 30 of file IconDatabaseRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\File\Icon\IconDatabaseRepository::__construct ( private ?\ilDBInterface  $db = null,
private ?Services  $irss = null 
)

Definition at line 40 of file IconDatabaseRepository.php.

43 {
44 global $DIC;
46 $this->db ??= $DIC->database();
47 $this->irss ??= $DIC->resourceStorage();
48 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26

References $DIC, and ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ createIcon()

ILIAS\File\Icon\IconDatabaseRepository::createIcon ( string  $a_rid,
bool  $a_active,
bool  $a_is_default_icon,
array  $a_suffixes 
)

Implements ILIAS\File\Icon\IconRepositoryInterface.

Definition at line 50 of file IconDatabaseRepository.php.

50 : Icon
51 {
52 $icon = new CustomIcon($a_rid, $a_active, $a_is_default_icon, $a_suffixes);
53 foreach ($icon->getSuffixes() as $suffix) {
54 $this->db->insert(
55 self::SUFFIX_TABLE_NAME,
56 [
57 self::ICON_RESOURCE_IDENTIFICATION => ['text', $icon->getRid()],
58 self::SUFFIX => ['text', $suffix],
59 ]
60 );
61 }
62 $this->db->insert(
63 self::ICON_TABLE_NAME,
64 [
65 self::ICON_RESOURCE_IDENTIFICATION => ['text', $icon->getRid()],
66 self::ICON_ACTIVE => ['integer', $icon->isActive()],
67 self::IS_DEFAULT_ICON => ['integer', $icon->isDefaultIcon()]
68 ]
69 );
70 return $icon;
71 }

◆ deleteIconByRid()

ILIAS\File\Icon\IconDatabaseRepository::deleteIconByRid ( string  $a_rid)

Implements ILIAS\File\Icon\IconRepositoryInterface.

Definition at line 269 of file IconDatabaseRepository.php.

269 : bool
270 {
271 $icon = $this->getIconByRid($a_rid);
272 if (!$icon instanceof NullIcon) {
273 $this->db->manipulateF(
274 "DELETE FROM " . self::SUFFIX_TABLE_NAME . " WHERE " . self::ICON_RESOURCE_IDENTIFICATION . " = %s",
275 ['text'],
276 [$a_rid]
277 );
278 $this->db->manipulateF(
279 "DELETE FROM " . self::ICON_TABLE_NAME . " WHERE " . self::ICON_RESOURCE_IDENTIFICATION . " = %s",
280 ['text'],
281 [$a_rid]
282 );
283 return true;
284 }
285 return false;
286 }

References ILIAS\File\Icon\IconDatabaseRepository\getIconByRid().

+ Here is the call graph for this function:

◆ getActiveIconForSuffix()

ILIAS\File\Icon\IconDatabaseRepository::getActiveIconForSuffix ( string  $a_suffix)

Implements ILIAS\File\Icon\IconRepositoryInterface.

Definition at line 192 of file IconDatabaseRepository.php.

192 : Icon
193 {
194 $rid = null;
195 $icon = new NullIcon();
196
197 // Determine the icon's rid first and then determine the icon by its rid.
198 // This is done because a query like the one in getIconByRid with a where-clause
199 // for the suffix would not return all suffixes of the matching icon.
200 $query = "SELECT s." . self::ICON_RESOURCE_IDENTIFICATION . " FROM " . self::SUFFIX_TABLE_NAME . " AS s"
201 . " INNER JOIN " . self::ICON_TABLE_NAME . " AS i"
202 . " ON s." . self::ICON_RESOURCE_IDENTIFICATION . " = i." . self::ICON_RESOURCE_IDENTIFICATION
203 . " WHERE s." . self::SUFFIX . " = %s AND i." . self::ICON_ACTIVE . " = %s";
204 $result = $this->db->queryF(
205 $query,
206 ["text", "integer"],
207 [$a_suffix, 1]
208 );
209 while ($data = $this->db->fetchAssoc($result)) {
211 }
212
213 if ($rid !== null) {
214 return $this->getIconByRid($rid);
215 }
216
217 return $icon;
218 }

References $data, ILIAS\File\Icon\IconDatabaseRepository\getIconByRid(), and ILIAS\File\Icon\IconDatabaseRepository\ICON_RESOURCE_IDENTIFICATION.

Referenced by ILIAS\File\Icon\IconDatabaseRepository\getIconFilePathBySuffix().

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

◆ getIconByRid()

ILIAS\File\Icon\IconDatabaseRepository::getIconByRid ( string  $a_rid)

Implements ILIAS\File\Icon\IconRepositoryInterface.

Definition at line 160 of file IconDatabaseRepository.php.

160 : Icon
161 {
162 $icon = new NullIcon();
163
164 $query = "SELECT i." . self::ICON_RESOURCE_IDENTIFICATION
165 . ", i." . self::ICON_ACTIVE
166 . ", i." . self::IS_DEFAULT_ICON
167 . ", GROUP_CONCAT(s." . self::SUFFIX . ") AS " . self::SUFFIXES
168 . " FROM " . self::ICON_TABLE_NAME . " AS i"
169 . " INNER JOIN " . self::SUFFIX_TABLE_NAME . " AS s"
170 . " ON " . "i." . self::ICON_RESOURCE_IDENTIFICATION . " = " . "s." . self::ICON_RESOURCE_IDENTIFICATION
171 . " WHERE i." . self::ICON_RESOURCE_IDENTIFICATION . " = %s"
172 . " GROUP BY i." . self::ICON_RESOURCE_IDENTIFICATION;
173
174 $result = $this->db->queryF(
175 $query,
176 ["text"],
177 [$a_rid]
178 );
179
180 while ($data = $this->db->fetchAssoc($result)) {
181 $icon = new CustomIcon(
182 $rid = $data[self::ICON_RESOURCE_IDENTIFICATION],
183 (bool) $data[self::ICON_ACTIVE],
184 (bool) $data[self::IS_DEFAULT_ICON],
185 $this->turnSuffixesStringIntoArray($data[self::SUFFIXES])
186 );
187 }
188
189 return $icon;
190 }

References $data, ILIAS\File\Icon\IconDatabaseRepository\ICON_RESOURCE_IDENTIFICATION, and ILIAS\File\Icon\IconAbstractRepository\turnSuffixesStringIntoArray().

Referenced by ILIAS\File\Icon\IconDatabaseRepository\deleteIconByRid(), and ILIAS\File\Icon\IconDatabaseRepository\getActiveIconForSuffix().

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

◆ getIconFilePathBySuffix()

ILIAS\File\Icon\IconDatabaseRepository::getIconFilePathBySuffix ( string  $suffix)

Implements ILIAS\File\Icon\IconRepositoryInterface.

Definition at line 220 of file IconDatabaseRepository.php.

220 : string
221 {
222 if ($suffix !== "") {
223 $icon = $this->getActiveIconForSuffix($suffix);
224 if (!$icon instanceof NullIcon) {
225 $resource_identification = $this->irss->manage()->find($icon->getRid());
226 if ($resource_identification instanceof ResourceIdentification) {
227 try {
228 return $this->irss->consume()->src($resource_identification)->getSrc(
229 false
230 );
231 } catch (\Throwable) {
232 // error reading the resource, continue
233 }
234 }
235 }
236 }
237 return ilUtil::getImagePath("standard/icon_file.svg");
238 }
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)

References ILIAS\File\Icon\IconDatabaseRepository\getActiveIconForSuffix(), and ilUtil\getImagePath().

+ Here is the call graph for this function:

◆ getIcons()

ILIAS\File\Icon\IconDatabaseRepository::getIcons ( )
Returns
array<int|string, CustomIcon>

Implements ILIAS\File\Icon\IconRepositoryInterface.

Definition at line 132 of file IconDatabaseRepository.php.

132 : array
133 {
134 $icons = [];
135
136 $query = "SELECT i." . self::ICON_RESOURCE_IDENTIFICATION
137 . ", i." . self::ICON_ACTIVE
138 . ", i." . self::IS_DEFAULT_ICON
139 . ", GROUP_CONCAT(s." . self::SUFFIX . ") AS " . self::SUFFIXES
140 . " FROM " . self::ICON_TABLE_NAME . " AS i"
141 . " INNER JOIN " . self::SUFFIX_TABLE_NAME . " AS s"
142 . " ON " . "i." . self::ICON_RESOURCE_IDENTIFICATION . " = " . "s." . self::ICON_RESOURCE_IDENTIFICATION
143 . " GROUP BY i." . self::ICON_RESOURCE_IDENTIFICATION;
144
145 $result = $this->db->query($query);
146
147 while ($data = $this->db->fetchAssoc($result)) {
148 $icon = new CustomIcon(
149 $rid = $data[self::ICON_RESOURCE_IDENTIFICATION],
150 (bool) $data[self::ICON_ACTIVE],
151 (bool) $data[self::IS_DEFAULT_ICON],
152 $this->turnSuffixesStringIntoArray($data[self::SUFFIXES])
153 );
154 $icons[$rid] = $icon;
155 }
156
157 return $icons;
158 }

References $data, ILIAS\File\Icon\IconDatabaseRepository\ICON_RESOURCE_IDENTIFICATION, and ILIAS\File\Icon\IconAbstractRepository\turnSuffixesStringIntoArray().

+ Here is the call graph for this function:

◆ getIconsForFilter()

ILIAS\File\Icon\IconDatabaseRepository::getIconsForFilter ( array  $filter)

Implements ILIAS\File\Icon\IconRepositoryInterface.

Definition at line 74 of file IconDatabaseRepository.php.

74 : array
75 {
76 $icons = [];
77
78 $rid_filter = null;
79 // due to the database schema, the suffixes filter has to be handled separately
80 if ($filter !== [] && ($filter['suffixes'] ?? null) !== null && $filter['suffixes'] !== '') {
81 $suffixes = explode(',', (string) $filter['suffixes']);
82 $suffixes = array_map(fn($suffix): string => $this->db->quote(trim((string) $suffix), 'text'), $suffixes);
83 $q = "SELECT rid FROM " . self::SUFFIX_TABLE_NAME . " WHERE suffix IN (" . implode(',', $suffixes) . ")";
84 $rid_filter = $this->db->fetchAll($this->db->query($q));
85 $rid_filter = array_map(fn($row) => $row['rid'], $rid_filter);
86 }
87
88 $query = "SELECT i." . self::ICON_RESOURCE_IDENTIFICATION
89 . ", i." . self::ICON_ACTIVE
90 . ", i." . self::IS_DEFAULT_ICON
91 . ", GROUP_CONCAT(s." . self::SUFFIX . ") AS " . self::SUFFIXES
92 . " FROM " . self::ICON_TABLE_NAME . " AS i"
93 . " JOIN " . self::SUFFIX_TABLE_NAME . " AS s"
94 . " ON " . "i." . self::ICON_RESOURCE_IDENTIFICATION . " = " . "s." . self::ICON_RESOURCE_IDENTIFICATION;
95
96 if ($filter !== []) {
97 $query .= " WHERE true ";
98 if (($filter['active'] ?? null) !== null && $filter['active'] !== '') {
99 $query .= " AND i.active = " . $this->db->quote($filter['active'], 'integer');
100 }
101
102 if ($rid_filter) {
103 $rid_filter = array_map(fn($rid): string => $this->db->quote(trim((string) $rid), 'text'), $rid_filter);
104 $query .= " AND i.rid IN (" . implode(',', $rid_filter) . ")";
105 }
106
107 if (($filter['is_default_icon'] ?? null) !== null && $filter['is_default_icon'] !== '') {
108 $query .= " AND i.is_default_icon = " . $this->db->quote($filter['is_default_icon'], 'integer');
109 }
110 }
111
112 $query .= " GROUP BY i." . self::ICON_RESOURCE_IDENTIFICATION;
113
114 $result = $this->db->query($query);
115
116 while ($data = $this->db->fetchAssoc($result)) {
117 $icon = new CustomIcon(
118 $rid = $data[self::ICON_RESOURCE_IDENTIFICATION],
119 (bool) $data[self::ICON_ACTIVE],
120 (bool) $data[self::IS_DEFAULT_ICON],
121 $this->turnSuffixesStringIntoArray($data[self::SUFFIXES])
122 );
123 $icons[$rid] = $icon;
124 }
125
126 return $icons;
127 }
$q
Definition: shib_logout.php:23

References $data, $q, ILIAS\File\Icon\IconDatabaseRepository\ICON_RESOURCE_IDENTIFICATION, and ILIAS\File\Icon\IconAbstractRepository\turnSuffixesStringIntoArray().

+ Here is the call graph for this function:

◆ updateIcon()

ILIAS\File\Icon\IconDatabaseRepository::updateIcon ( string  $a_rid,
bool  $a_active,
bool  $a_is_default_icon,
array  $a_suffixes 
)

Implements ILIAS\File\Icon\IconRepositoryInterface.

Definition at line 240 of file IconDatabaseRepository.php.

240 : Icon
241 {
242 $icon = new CustomIcon($a_rid, $a_active, $a_is_default_icon, $a_suffixes);
243 // Delete the old suffix entries of the given icon first as they can not be identified by form input and therefore cannot be overwritten - only deleted and created anew
244 $this->db->manipulateF(
245 "DELETE FROM " . self::SUFFIX_TABLE_NAME . " WHERE " . self::ICON_RESOURCE_IDENTIFICATION . " = %s",
246 ['text'],
247 [$icon->getRid()]
248 );
249 foreach ($icon->getSuffixes() as $suffix) {
250 $this->db->insert(
251 self::SUFFIX_TABLE_NAME,
252 [
253 self::ICON_RESOURCE_IDENTIFICATION => ['text', $icon->getRid()],
254 self::SUFFIX => ['text', $suffix],
255 ]
256 );
257 }
258 $this->db->update(
259 self::ICON_TABLE_NAME,
260 [
261 self::ICON_ACTIVE => ['integer', $icon->isActive()],
262 self::IS_DEFAULT_ICON => ['integer', $icon->isDefaultIcon()]
263 ],
264 [self::ICON_RESOURCE_IDENTIFICATION => ['text', $icon->getRid()]]
265 );
266 return $icon;
267 }

Field Documentation

◆ ICON_ACTIVE

const ILIAS\File\Icon\IconDatabaseRepository::ICON_ACTIVE = 'active'

Definition at line 34 of file IconDatabaseRepository.php.

◆ ICON_RESOURCE_IDENTIFICATION

◆ ICON_TABLE_NAME

const ILIAS\File\Icon\IconDatabaseRepository::ICON_TABLE_NAME = 'il_file_icon'

Definition at line 32 of file IconDatabaseRepository.php.

◆ IS_DEFAULT_ICON

const ILIAS\File\Icon\IconDatabaseRepository::IS_DEFAULT_ICON = 'is_default_icon'

Definition at line 35 of file IconDatabaseRepository.php.

◆ SUFFIX

const ILIAS\File\Icon\IconDatabaseRepository::SUFFIX = 'suffix'

Definition at line 37 of file IconDatabaseRepository.php.

◆ SUFFIX_TABLE_NAME

const ILIAS\File\Icon\IconDatabaseRepository::SUFFIX_TABLE_NAME = 'il_file_icon_suffixes'

Definition at line 36 of file IconDatabaseRepository.php.

◆ SUFFIXES

const ILIAS\File\Icon\IconDatabaseRepository::SUFFIXES = 'suffixes'

Definition at line 38 of file IconDatabaseRepository.php.


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