ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilMMItemInformation.php
Go to the documentation of this file.
1<?php
2
4use ILIAS\GlobalScreen\Collector\StorageFacade;
15
21{
22 private const ICON_ID = 'icon_id';
26 private $ui_factory;
30 private $storage;
34 private $translations = [];
38 private $items = [];
39
43 public function __construct()
44 {
45 $this->items = ilMMItemStorage::getArray('identification');
46 $this->translations = ilMMItemTranslationStorage::getArray('id', 'translation');
47 $this->storage = new Services();
48 }
49
53 public function customTranslationForUser(hasTitle $item) : hasTitle
54 {
58 global $DIC;
59 static $usr_language_key;
60 static $default_language;
61
62 // see https://mantis.ilias.de/view.php?id=32276
63 if (!isset($usr_language_key) && $DIC->user()->getId() === 0 || $DIC->user()->isAnonymous()) {
64 $usr_language_key = $DIC->http()->request()->getQueryParams()['lang'] ?? false;
65 }
66
67 if (!isset($usr_language_key)) {
68 $usr_language_key = $DIC->language()->getUserLanguage() ? $DIC->language()->getUserLanguage() : $DIC->language()->getDefaultLanguage();
69 }
70 if (!isset($default_language)) {
72 }
73 if ($item instanceof RepositoryLink && empty($item->getTitle())) {
74 $item = $item->withTitle(($item->getRefId() > 0) ?
76 ""
77 );
78 }
79 if ($item instanceof hasTitle && isset($this->translations["{$item->getProviderIdentification()->serialize()}|$usr_language_key"])
80 && $this->translations["{$item->getProviderIdentification()->serialize()}|$usr_language_key"] !== ''
81 ) {
82 $item = $item->withTitle((string) $this->translations["{$item->getProviderIdentification()->serialize()}|$usr_language_key"]);
83 }
84
85 return $item;
86 }
87
91 public function customPosition(isItem $item) : isItem
92 {
93 return $item->withPosition($this->getPosition($item));
94 }
95
96 private function getPosition(isItem $item) : int
97 {
98 if (isset($this->items[$item->getProviderIdentification()->serialize()]['position'])) {
99 return (int) $this->items[$item->getProviderIdentification()->serialize()]['position'];
100 }
101
102 return $item->getPosition();
103 }
104
108 public function isItemActive(isItem $item) : bool
109 {
110 $serialize = $item->getProviderIdentification()->serialize();
111 if (isset($this->items[$serialize]['active'])) {
112 return $this->items[$serialize]['active'] === '1';
113 }
114 return true;
115 }
116
121 {
122 global $DIC;
123 $parent_string = $item->getProviderIdentification()->serialize();
124 if (isset($this->items[$parent_string]['parent_identification'])) {
125 return $DIC->globalScreen()->identification()->fromSerializedIdentification($this->items[$parent_string]['parent_identification']);
126 }
127
128 return $item->getParent();
129 }
130
134 public function customSymbol(hasSymbol $item) : hasSymbol
135 {
136 $id = $item->getProviderIdentification()->serialize();
137 if (isset($this->items[$id][self::ICON_ID]) && strlen($this->items[$id][self::ICON_ID]) > 1) {
138 global $DIC;
139
140 $ri = $this->storage->find($this->items[$id][self::ICON_ID]);
141 if (!$ri) {
142 return $item;
143 }
144 $stream = $this->storage->stream($ri)->getStream();
145 $data = 'data:' . $this->storage->getRevision($ri)->getInformation()->getMimeType() . ';base64,' . base64_encode($stream->getContents());
146 $old_symbol = $item->hasSymbol() ? $item->getSymbol() : null;
147 if ($old_symbol instanceof Glyph || $old_symbol instanceof Icon) {
148 $aria_label = $old_symbol->getAriaLabel();
149 } elseif ($item instanceof hasTitle) {
150 $aria_label = $item->getTitle();
151 } else {
152 $aria_label = 'Custom icon';
153 }
154
155 $symbol = $DIC->ui()->factory()->symbol()->icon()->custom($data, $aria_label);
156
157 return $item->withSymbol($symbol);
158 }
159
160 return $item;
161 }
162}
static getArray($key=null, $values=null)
An exception for terminatinating execution or to throw for unit testing.
Class ilMMItemInformation.
customPosition(isItem $item)
@inheritDoc
customSymbol(hasSymbol $item)
@inheritDoc
__construct()
ilMMItemInformation constructor.
getParent(isChild $item)
@inheritDoc
isItemActive(isItem $item)
@inheritDoc
static _lookupTitle($a_id)
lookup object title
static _lookupObjectId($a_ref_id)
lookup object id
Interface hasSymbol Methods for Entries with Symbols.
Definition: hasSymbol.php:12
getPosition()
Return the default position for installation, this will be overridden by the configuration later.
This describes how a glyph could be modified during construction of UI.
Definition: Glyph.php:14
This describes how a icon could be modified during construction of UI.
Definition: Icon.php:10
Class ilAsqQuestionAuthoringFactory.
$data
Definition: storeScorm.php:23
$DIC
Definition: xapitoken.php:46