ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMMItemInformation.php
Go to the documentation of this file.
1 <?php
2 
31 
37 {
38  private const ICON_ID = 'icon_id';
42  private $ui_factory;
46  private $storage;
50  private $translations = [];
54  private $items = [];
55 
59  public function __construct()
60  {
61  global $DIC;
62  $this->items = ilMMItemStorage::getArray('identification');
63  $this->translations = ilMMItemTranslationStorage::getArray('id', 'translation');
64  $this->storage = $DIC['resource_storage'];
65  }
66 
70  public function customTranslationForUser(hasTitle $item) : hasTitle
71  {
75  global $DIC;
76  static $usr_language_key;
77  static $default_language;
78 
79  // see https://mantis.ilias.de/view.php?id=32276
80  if (!isset($usr_language_key) && $DIC->user()->getId() === 0 || $DIC->user()->isAnonymous()) {
81  $usr_language_key = $DIC->http()->request()->getQueryParams()['lang'] ?? false;
82  }
83 
84  if (!isset($usr_language_key)) {
85  $usr_language_key = $DIC->language()->getUserLanguage() ? $DIC->language()->getUserLanguage() : $DIC->language()->getDefaultLanguage();
86  }
87  if (!isset($default_language)) {
89  }
90  if ($item instanceof RepositoryLink && empty($item->getTitle())) {
91  $item = $item->withTitle(
92  ($item->getRefId() > 0) ?
94  ""
95  );
96  }
97  if ($item instanceof hasTitle && isset($this->translations["{$item->getProviderIdentification()->serialize()}|$usr_language_key"])
98  && $this->translations["{$item->getProviderIdentification()->serialize()}|$usr_language_key"] !== ''
99  ) {
100  $item = $item->withTitle((string) $this->translations["{$item->getProviderIdentification()->serialize()}|$usr_language_key"]);
101  }
102 
103  return $item;
104  }
105 
109  public function customPosition(isItem $item) : isItem
110  {
111  return $item->withPosition($this->getPosition($item));
112  }
113 
114  private function getPosition(isItem $item) : int
115  {
116  if (isset($this->items[$item->getProviderIdentification()->serialize()]['position'])) {
117  return (int) $this->items[$item->getProviderIdentification()->serialize()]['position'];
118  }
119 
120  return $item->getPosition();
121  }
122 
126  public function isItemActive(isItem $item) : bool
127  {
128  $serialize = $item->getProviderIdentification()->serialize();
129  if (isset($this->items[$serialize]['active'])) {
130  return $this->items[$serialize]['active'] === '1';
131  }
132  return true;
133  }
134 
138  public function getParent(isItem $item) : IdentificationInterface
139  {
140  global $DIC;
141  $serialized = $item->getProviderIdentification()->serialize();
142  if (isset($this->items[$serialized]['parent_identification'])) {
143  return $DIC->globalScreen()->identification()->fromSerializedIdentification($this->items[$serialized]['parent_identification']);
144  }
145 
146  return $item->getParent();
147  }
148 
152  public function customSymbol(hasSymbol $item) : hasSymbol
153  {
154  $id = $item->getProviderIdentification()->serialize();
155  if (isset($this->items[$id][self::ICON_ID]) && strlen($this->items[$id][self::ICON_ID]) > 1) {
156  global $DIC;
157 
158  $ri = $this->storage->manage()->find($this->items[$id][self::ICON_ID]);
159  if (!$ri) {
160  return $item;
161  }
162 
163  try {
164  $src = $this->storage->consume()->src($ri);
165  } catch (FileNotFoundException $f) {
166  return $item;
167  }
168 
169  $old_symbol = $item->hasSymbol() ? $item->getSymbol() : null;
170  if ($old_symbol instanceof Glyph) {
171  $aria_label = $old_symbol->getAriaLabel();
172  } elseif ($old_symbol instanceof Icon) {
173  $aria_label = $old_symbol->getLabel();
174  } elseif ($item instanceof hasTitle) {
175  $aria_label = $item->getTitle();
176  }
177 
178  $aria_label = empty($aria_label) ? $id : $aria_label;
179 
180  $symbol = $DIC->ui()->factory()->symbol()->icon()->custom($src->getSrc(), $aria_label);
181 
182  return $item->withSymbol($symbol);
183  }
184 
185  return $item;
186  }
187 }
Class ilMMItemInformation.
static _lookupTitle($a_id)
This describes how an icon could be modified during construction of UI.
Definition: Icon.php:9
static _lookupObjectId($a_ref_id)
This describes how a glyph could be modified during construction of UI.
Definition: Glyph.php:13
getPosition()
Return the default position for installation, this will be overridden by the configuration later...
global $DIC
Definition: goto.php:24
Interface hasSymbol Methods for Entries with Symbols.
Definition: hasSymbol.php:32
Class FileNotFoundException Indicates that a file is missing or not found.
static getArray($key=null, $values=null)
__construct()
ilMMItemInformation constructor.