ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMMItemInformation.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
31 
37 {
41  private const ICON_ID = 'icon_id';
42 
43  private Services $storage;
44  private array $translations;
45  private array $items;
46 
50  public function __construct()
51  {
52  global $DIC;
53  $this->items = ilMMItemStorage::getArray('identification');
54  $this->translations = ilMMItemTranslationStorage::getArray('id', 'translation');
55  $this->storage = $DIC['resource_storage'];
56  }
57 
61  public function customTranslationForUser(hasTitle $item): hasTitle
62  {
66  global $DIC;
67  static $usr_language_key;
68  static $default_language;
69 
70  // see https://mantis.ilias.de/view.php?id=32276
71  if (!isset($usr_language_key) && ($DIC->user()->getId() === 0 || $DIC->user()->isAnonymous())) {
72  $usr_language_key = $DIC->http()->wrapper()->query()->has('lang')
73  ? $DIC->http()->wrapper()->query()->retrieve('lang', $DIC->refinery()->to()->string())
74  : null;
75  }
76 
77  if (!isset($usr_language_key)) {
78  $usr_language_key = $DIC->language()->getUserLanguage() ?: $DIC->language()->getDefaultLanguage();
79  }
80  if (!isset($default_language)) {
82  }
83  if ($item instanceof RepositoryLink && empty($item->getTitle())) {
84  $item = $item->withTitle(
85  ($item->getRefId() > 0) ?
87  ""
88  );
89  }
90  if ($item instanceof hasTitle && isset($this->translations["{$item->getProviderIdentification()->serialize()}|$usr_language_key"])
91  && $this->translations["{$item->getProviderIdentification()->serialize()}|$usr_language_key"] !== '') {
92  return $item->withTitle((string) $this->translations["{$item->getProviderIdentification()->serialize()}|$usr_language_key"]);
93  }
94 
95  return $item;
96  }
97 
101  public function customPosition(isItem $item): isItem
102  {
103  return $item->withPosition($this->getPosition($item));
104  }
105 
106  private function getPosition(isItem $item): int
107  {
108  if (isset($this->items[$item->getProviderIdentification()->serialize()]['position'])) {
109  return (int) $this->items[$item->getProviderIdentification()->serialize()]['position'];
110  }
111 
112  return $item->getPosition();
113  }
114 
118  public function isItemActive(isItem $item): bool
119  {
120  if (!isset($this->items[$item->getProviderIdentification()->serialize()]['active'])) {
121  return $item->isAvailable();
122  }
123  return ((int) ($this->items[$item->getProviderIdentification()->serialize()]['active'] ?? 0) === 1);
124  }
125 
129  public function getParent(isItem $item): IdentificationInterface
130  {
131  global $DIC;
132  $serialized = $item->getProviderIdentification()->serialize();
133  if (isset($this->items[$serialized]['parent_identification'])) {
134  return $DIC->globalScreen()->identification()->fromSerializedIdentification($this->items[$serialized]['parent_identification']);
135  }
136 
137  return $item->getParent();
138  }
139 
143  public function customSymbol(hasSymbol $item): hasSymbol
144  {
145  $id = $item->getProviderIdentification()->serialize();
146  if (isset($this->items[$id][self::ICON_ID]) && strlen((string) $this->items[$id][self::ICON_ID]) > 1) {
147  global $DIC;
148 
149  $ri = $this->storage->manage()->find($this->items[$id][self::ICON_ID]);
150  if ($ri === null) {
151  return $item;
152  }
153 
154  try {
155  $src = $this->storage->consume()->src($ri);
156  } catch (FileNotFoundException) {
157  return $item;
158  }
159 
160  $old_symbol = $item->hasSymbol() ? $item->getSymbol() : null;
161  if ($old_symbol instanceof Glyph) {
162  $aria_label = $old_symbol->getAriaLabel();
163  } elseif ($old_symbol instanceof Icon) {
164  $aria_label = $old_symbol->getLabel();
165  } elseif ($item instanceof hasTitle) {
166  $aria_label = $item->getTitle();
167  }
168 
169  $aria_label = empty($aria_label) ? $id : $aria_label;
170  try {
171  $symbol = $DIC->ui()->factory()->symbol()->icon()->custom($src->getSrc(), $aria_label);
172  } catch (Exception) {
173  return $item;
174  }
175 
176  return $item->withSymbol($symbol);
177  }
178 
179  return $item;
180  }
181 }
Class ilMMItemInformation.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getPosition()
Return the default position for installation, this will be overridden by the configuration later...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTitle(int $obj_id)
global $DIC
Definition: shib_login.php:22
static _lookupObjectId(int $ref_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static getArray(?string $key=null, string|array|null $values=null)
Indicates that a file is missing or not found.
__construct()
ilMMItemInformation constructor.