ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ILIAS\File\Icon\IconDatabaseRepository Class Reference
+ Inheritance diagram for ILIAS\File\Icon\IconDatabaseRepository:
+ Collaboration diagram for ILIAS\File\Icon\IconDatabaseRepository:

Public Member Functions

 __construct ()
 
 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)
 

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'
 

Private Attributes

ilDBInterface $db
 
Services $irss
 

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 ( )

Definition at line 43 of file IconDatabaseRepository.php.

References $DIC, and ILIAS\MetaData\Repository\Validation\Data\__construct().

44  {
45  global $DIC;
47  $this->db = $DIC->database();
48  $this->irss = $DIC->resourceStorage();
49  }
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
+ 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 51 of file IconDatabaseRepository.php.

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

◆ deleteIconByRid()

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

Implements ILIAS\File\Icon\IconRepositoryInterface.

Definition at line 258 of file IconDatabaseRepository.php.

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

258  : bool
259  {
260  $icon = $this->getIconByRid($a_rid);
261  if (!$icon instanceof NullIcon) {
262  $this->db->manipulateF(
263  "DELETE FROM " . self::SUFFIX_TABLE_NAME . " WHERE " . self::ICON_RESOURCE_IDENTIFICATION . " = %s",
264  ['text'],
265  [$a_rid]
266  );
267  $this->db->manipulateF(
268  "DELETE FROM " . self::ICON_TABLE_NAME . " WHERE " . self::ICON_RESOURCE_IDENTIFICATION . " = %s",
269  ['text'],
270  [$a_rid]
271  );
272  return true;
273  }
274  return false;
275  }
+ 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 181 of file IconDatabaseRepository.php.

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

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

181  : Icon
182  {
183  $rid = null;
184  $icon = new NullIcon();
185 
186  // Determine the icon's rid first and then determine the icon by its rid.
187  // This is done because a query like the one in getIconByRid with a where-clause
188  // for the suffix would not return all suffixes of the matching icon.
189  $query = "SELECT s." . self::ICON_RESOURCE_IDENTIFICATION . " FROM " . self::SUFFIX_TABLE_NAME . " AS s"
190  . " INNER JOIN " . self::ICON_TABLE_NAME . " AS i"
191  . " ON s." . self::ICON_RESOURCE_IDENTIFICATION . " = i." . self::ICON_RESOURCE_IDENTIFICATION
192  . " WHERE s." . self::SUFFIX . " = %s AND i." . self::ICON_ACTIVE . " = %s";
193  $result = $this->db->queryF(
194  $query,
195  ["text", "integer"],
196  [$a_suffix, 1]
197  );
198  while ($data = $this->db->fetchAssoc($result)) {
199  $rid = $data[self::ICON_RESOURCE_IDENTIFICATION];
200  }
201 
202  if ($rid !== null) {
203  return $this->getIconByRid($rid);
204  }
205 
206  return $icon;
207  }
+ 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 149 of file IconDatabaseRepository.php.

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

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

149  : Icon
150  {
151  $icon = new NullIcon();
152 
153  $query = "SELECT i." . self::ICON_RESOURCE_IDENTIFICATION
154  . ", i." . self::ICON_ACTIVE
155  . ", i." . self::IS_DEFAULT_ICON
156  . ", GROUP_CONCAT(s." . self::SUFFIX . ") AS " . self::SUFFIXES
157  . " FROM " . self::ICON_TABLE_NAME . " AS i"
158  . " INNER JOIN " . self::SUFFIX_TABLE_NAME . " AS s"
159  . " ON " . "i." . self::ICON_RESOURCE_IDENTIFICATION . " = " . "s." . self::ICON_RESOURCE_IDENTIFICATION
160  . " WHERE i." . self::ICON_RESOURCE_IDENTIFICATION . " = %s"
161  . " GROUP BY i." . self::ICON_RESOURCE_IDENTIFICATION;
162 
163  $result = $this->db->queryF(
164  $query,
165  ["text"],
166  [$a_rid]
167  );
168 
169  while ($data = $this->db->fetchAssoc($result)) {
170  $icon = new CustomIcon(
171  $rid = $data[self::ICON_RESOURCE_IDENTIFICATION],
172  (bool) $data[self::ICON_ACTIVE],
173  (bool) $data[self::IS_DEFAULT_ICON],
174  $this->turnSuffixesStringIntoArray($data[self::SUFFIXES])
175  );
176  }
177 
178  return $icon;
179  }
+ 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 209 of file IconDatabaseRepository.php.

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

209  : string
210  {
211  if ($suffix !== "") {
212  $icon = $this->getActiveIconForSuffix($suffix);
213  if (!$icon instanceof NullIcon) {
214  $resource_identification = $this->irss->manage()->find($icon->getRid());
215  if ($resource_identification instanceof ResourceIdentification) {
216  try {
217  return $this->irss->consume()->src($resource_identification)->getSrc(
218  false
219  );
220  } catch (\Throwable) {
221  // error reading the resource, continue
222  }
223  }
224  }
225  }
226  return ilUtil::getImagePath("standard/icon_file.svg");
227  }
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
+ Here is the call graph for this function:

◆ getIcons()

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

Implements ILIAS\File\Icon\IconRepositoryInterface.

Definition at line 121 of file IconDatabaseRepository.php.

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

121  : array
122  {
123  $icons = [];
124 
125  $query = "SELECT i." . self::ICON_RESOURCE_IDENTIFICATION
126  . ", i." . self::ICON_ACTIVE
127  . ", i." . self::IS_DEFAULT_ICON
128  . ", GROUP_CONCAT(s." . self::SUFFIX . ") AS " . self::SUFFIXES
129  . " FROM " . self::ICON_TABLE_NAME . " AS i"
130  . " INNER JOIN " . self::SUFFIX_TABLE_NAME . " AS s"
131  . " ON " . "i." . self::ICON_RESOURCE_IDENTIFICATION . " = " . "s." . self::ICON_RESOURCE_IDENTIFICATION
132  . " GROUP BY i." . self::ICON_RESOURCE_IDENTIFICATION;
133 
134  $result = $this->db->query($query);
135 
136  while ($data = $this->db->fetchAssoc($result)) {
137  $icon = new CustomIcon(
138  $rid = $data[self::ICON_RESOURCE_IDENTIFICATION],
139  (bool) $data[self::ICON_ACTIVE],
140  (bool) $data[self::IS_DEFAULT_ICON],
141  $this->turnSuffixesStringIntoArray($data[self::SUFFIXES])
142  );
143  $icons[$rid] = $icon;
144  }
145 
146  return $icons;
147  }
+ 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.

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

74  : array
75  {
76  $icons = [];
77 
78  $query = "SELECT i." . self::ICON_RESOURCE_IDENTIFICATION
79  . ", i." . self::ICON_ACTIVE
80  . ", i." . self::IS_DEFAULT_ICON
81  . ", GROUP_CONCAT(s." . self::SUFFIX . ") AS " . self::SUFFIXES
82  . " FROM " . self::ICON_TABLE_NAME . " AS i"
83  . " JOIN " . self::SUFFIX_TABLE_NAME . " AS s"
84  . " ON " . "i." . self::ICON_RESOURCE_IDENTIFICATION . " = " . "s." . self::ICON_RESOURCE_IDENTIFICATION;
85 
86  if ($filter !== []) {
87  $query .= " WHERE true ";
88  if (($filter['active'] ?? null) !== null && $filter['active'] !== '') {
89  $query .= " AND i.active = " . $this->db->quote($filter['active'], 'integer');
90  }
91 
92  if (($filter['suffixes'] ?? null) !== null && $filter['suffixes'] !== '') {
93  $query .= " AND s.suffix LIKE " . $this->db->quote('%' . $filter['suffixes'] . '%', 'text');
94  }
95 
96  if (($filter['is_default_icon'] ?? null) !== null && $filter['is_default_icon'] !== '') {
97  $query .= " AND i.is_default_icon = " . $this->db->quote($filter['is_default_icon'], 'integer');
98  }
99  }
100 
101  $query .= " GROUP BY i." . self::ICON_RESOURCE_IDENTIFICATION;
102 
103  $result = $this->db->query($query);
104 
105  while ($data = $this->db->fetchAssoc($result)) {
106  $icon = new CustomIcon(
107  $rid = $data[self::ICON_RESOURCE_IDENTIFICATION],
108  (bool) $data[self::ICON_ACTIVE],
109  (bool) $data[self::IS_DEFAULT_ICON],
110  $this->turnSuffixesStringIntoArray($data[self::SUFFIXES])
111  );
112  $icons[$rid] = $icon;
113  }
114 
115  return $icons;
116  }
+ 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 229 of file IconDatabaseRepository.php.

229  : Icon
230  {
231  $icon = new CustomIcon($a_rid, $a_active, $a_is_default_icon, $a_suffixes);
232  // 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
233  $this->db->manipulateF(
234  "DELETE FROM " . self::SUFFIX_TABLE_NAME . " WHERE " . self::ICON_RESOURCE_IDENTIFICATION . " = %s",
235  ['text'],
236  [$icon->getRid()]
237  );
238  foreach ($icon->getSuffixes() as $suffix) {
239  $this->db->insert(
240  self::SUFFIX_TABLE_NAME,
241  [
242  self::ICON_RESOURCE_IDENTIFICATION => ['text', $icon->getRid()],
243  self::SUFFIX => ['text', $suffix],
244  ]
245  );
246  }
247  $this->db->update(
248  self::ICON_TABLE_NAME,
249  [
250  self::ICON_ACTIVE => ['integer', $icon->isActive()],
251  self::IS_DEFAULT_ICON => ['integer', $icon->isDefaultIcon()]
252  ],
253  [self::ICON_RESOURCE_IDENTIFICATION => ['text', $icon->getRid()]]
254  );
255  return $icon;
256  }

Field Documentation

◆ $db

ilDBInterface ILIAS\File\Icon\IconDatabaseRepository::$db
private

Definition at line 40 of file IconDatabaseRepository.php.

◆ $irss

Services ILIAS\File\Icon\IconDatabaseRepository::$irss
private

Definition at line 41 of file IconDatabaseRepository.php.

◆ ICON_ACTIVE

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

◆ ICON_RESOURCE_IDENTIFICATION

const ILIAS\File\Icon\IconDatabaseRepository::ICON_RESOURCE_IDENTIFICATION = 'rid'

◆ ICON_TABLE_NAME

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

◆ IS_DEFAULT_ICON

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

◆ SUFFIX

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

◆ SUFFIX_TABLE_NAME

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

◆ 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: