ILIAS  release_8 Revision v8.23
class.ilMMItemInformation.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
32 
38 {
39  private const ICON_ID = 'icon_id';
40 
41  private Services $storage;
42  private array $translations;
43  private array $items;
44 
48  public function __construct()
49  {
50  global $DIC;
51  $this->items = ilMMItemStorage::getArray('identification');
52  $this->translations = ilMMItemTranslationStorage::getArray('id', 'translation');
53  $this->storage = $DIC['resource_storage'];
54  }
55 
59  public function customTranslationForUser(hasTitle $item): hasTitle
60  {
64  global $DIC;
65  static $usr_language_key;
66  static $default_language;
67 
68  // see https://mantis.ilias.de/view.php?id=32276
69  if (!isset($usr_language_key) && ($DIC->user()->getId() === 0 || $DIC->user()->isAnonymous())) {
70  $usr_language_key = $DIC->http()->wrapper()->query()->has('lang')
71  ? $DIC->http()->wrapper()->query()->retrieve('lang', $DIC->refinery()->to()->string())
72  : null;
73  }
74 
75  if (!isset($usr_language_key)) {
76  $usr_language_key = $DIC->language()->getUserLanguage() ? $DIC->language()->getUserLanguage() : $DIC->language()->getDefaultLanguage();
77  }
78  if (!isset($default_language)) {
80  }
81  if ($item instanceof RepositoryLink && empty($item->getTitle())) {
82  $item = $item->withTitle(
83  ($item->getRefId() > 0) ?
85  ""
86  );
87  }
88  if ($item instanceof hasTitle && isset($this->translations["{$item->getProviderIdentification()->serialize()}|$usr_language_key"])
89  && $this->translations["{$item->getProviderIdentification()->serialize()}|$usr_language_key"] !== ''
90  ) {
91  $item = $item->withTitle((string) $this->translations["{$item->getProviderIdentification()->serialize()}|$usr_language_key"]);
92  }
93 
94  return $item;
95  }
96 
100  public function customPosition(isItem $item): isItem
101  {
102  return $item->withPosition($this->getPosition($item));
103  }
104 
105  private function getPosition(isItem $item): int
106  {
107  if (isset($this->items[$item->getProviderIdentification()->serialize()]['position'])) {
108  return (int) $this->items[$item->getProviderIdentification()->serialize()]['position'];
109  }
110 
111  return $item->getPosition();
112  }
113 
117  public function isItemActive(isItem $item): bool
118  {
119  $serialize = $item->getProviderIdentification()->serialize();
120  if (isset($this->items[$serialize]['active'])) {
121  return $this->items[$serialize]['active'] === '1';
122  }
123  return true;
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($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) {
151  return $item;
152  }
153 
154  try {
155  $src = $this->storage->consume()->src($ri);
156  } catch (FileNotFoundException $f) {
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 $e) {
173  return $item;
174  }
175 
176  return $item->withSymbol($symbol);
177  }
178 
179  return $item;
180  }
181 }
Class ilMMItemInformation.
static getArray(?string $key=null, $values=null)
This describes how an icon could be modified during construction of UI.
Definition: Icon.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This describes how a glyph could be modified during construction of UI.
Definition: Glyph.php:30
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)
static _lookupObjectId(int $ref_id)
Interface hasSymbol Methods for Entries with Symbols.
Definition: hasSymbol.php:32
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct()
ilMMItemInformation constructor.