ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
IconAbstractRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\File\Icon;
22 
27 {
28  private static \ILIAS\Refinery\Factory $refinery;
29 
30  public function __construct()
31  {
32  global $DIC;
33  self::$refinery = $DIC->refinery();
34  }
35 
36  final public function turnSuffixesArrayIntoString(array $a_suffixes): string
37  {
38  return implode(", ", $a_suffixes);
39  }
40 
44  final public function turnSuffixesStringIntoArray(string $a_suffixes): array
45  {
46  $a_suffixes = preg_replace('/\s+/', '', $a_suffixes);
47  return explode(",", $a_suffixes);
48  }
49 
50  final public function hasSuffixInputOnlyAllowedCharacters(array $a_suffixes): bool
51  {
52  $suffixes_string = $this->turnSuffixesArrayIntoString($a_suffixes);
53  $matches = preg_match("/^[a-zA-Z0-9\,\s]+$/", $suffixes_string);
54  return self::$refinery->kindlyTo()->bool()->transform($matches);
55  }
56 
57  final public function hasSuffixInputNoDuplicatesToItsOwnEntries(array $a_suffixes): bool
58  {
59  return count($a_suffixes) === count(array_unique($a_suffixes));
60  }
61 
62  final public function causesNoActiveSuffixesConflict(
63  array $a_future_suffixes,
64  bool $a_future_activation_state,
65  Icon $a_current_icon
66  ): bool {
67  //if the icon is not going to be activated there can be no suffix conflict with other icons
68  if (!$a_future_activation_state) {
69  return true;
70  }
71 
72  $existing_icons = $this->getIcons();
73  //remove current icon from existing icon array to prevent validation errors when updating an existing icon
74  if (!$a_current_icon instanceof NullIcon) {
75  unset($existing_icons[$a_current_icon->getRid()]);
76  }
77 
78  $duplicate_suffixes = [];
79  foreach ($existing_icons as $existing_icon) {
80  //skip deactivated icons as having multiple icon entries for the same suffix is allowed, the restriction is that only one can be activated
81  if (!$existing_icon->isActive()) {
82  continue;
83  }
84  $duplicate_suffixes = array_merge(
85  $duplicate_suffixes,
86  array_intersect($a_future_suffixes, $existing_icon->getSuffixes())
87  );
88  }
89 
90  return $duplicate_suffixes === [];
91  }
92 }
global $DIC
Definition: feed.php:28
causesNoActiveSuffixesConflict(array $a_future_suffixes, bool $a_future_activation_state, Icon $a_current_icon)
Refinery Factory $refinery