ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMMAbstractItemFacade.php
Go to the documentation of this file.
1<?php
2
19
25{
29 protected $role_based_visibility = false;
33 protected $global_role_ids = [];
41 protected $mm_item;
45 protected $raw_item;
49 protected $filtered_item;
53 protected $identification;
57 protected $default_title = "-";
58
65 public function __construct(
66 \ILIAS\GlobalScreen\Identification\IdentificationInterface $identification,
67 Main $collector
68 ) {
70 $this->raw_item = $collector->getSingleItemFromRaw($identification);
71 $this->filtered_item = $collector->getSingleItemFromFilter($identification);
72 $this->type_information = $collector->getTypeInformationCollection()->get(get_class($this->raw_item));
73 $this->mm_item = ilMMItemStorage::register($this->raw_item);
74 }
75
76 public function getId() : string
77 {
78 return $this->identification->serialize();
79 }
80
84 public function hasStorage() : bool
85 {
86 return ilMMItemStorage::find($this->getId()) !== null;
87 }
88
92 public function supportsRoleBasedVisibility() : bool
93 {
94 return false;
95 }
96
100 public function hasRoleBasedVisibility() : bool
101 {
103 }
104
109 {
110 $this->role_based_visibility = $role_based_visibility;
111 }
112
116 public function getGlobalRoleIDs() : array
117 {
119 }
120
124 public function setGlobalRoleIDs(array $global_role_ids) : void
125 {
126 $this->global_role_ids = $global_role_ids;
127 }
128
132 public function isEmpty() : bool
133 {
134 return $this->mm_item->getIdentification() == '';
135 }
136
140 public function itemStorage() : ilMMItemStorage
141 {
142 return $this->mm_item;
143 }
144
148 public function identification() : \ILIAS\GlobalScreen\Identification\IdentificationInterface
149 {
151 }
152
153
154 public function getRawItem() : isItem
155 {
156 return $this->raw_item;
157 }
158 public function getFilteredItem() : isItem
159 {
161 }
162
163 public function getAmountOfChildren() : int
164 {
165 if ($this->filtered_item instanceof isParent) {
166 return count($this->filtered_item->getChildren());
167 }
168
169 return 0;
170 }
171
172 public function isAvailable() : bool
173 {
174 return (bool) ($this->filtered_item->isAvailable() || $this->filtered_item->isAlwaysAvailable());
175 }
176
180 public function isActivated() : bool
181 {
182 return (bool) ($this->mm_item->isActive() && $this->getRawItem()->isAvailable()) || $this->getRawItem()->isAlwaysAvailable();
183 }
184
188 public function isAlwaysAvailable() : bool
189 {
190 return $this->getRawItem()->isAlwaysAvailable();
191 }
192
196 public function getProviderNameForPresentation() : string
197 {
198 return $this->identification->getProviderNameForPresentation();
199 }
200
204 public function getDefaultTitle() : string
205 {
206 $default_translation = ilMMItemTranslationStorage::getDefaultTranslation($this->identification);
207 if ($default_translation !== "") {
208 return $default_translation;
209 }
210 if ($this->default_title == "-" && $this->raw_item instanceof \ILIAS\GlobalScreen\Scope\MainMenu\Factory\hasTitle) {
211 $this->default_title = $this->raw_item->getTitle();
212 }
213
215 }
216
220 public function setDefaultTitle(string $default_title)
221 {
222 $this->default_title = $default_title;
223 }
224
228 public function getStatus() : string
229 {
230 global $DIC;
231 if (!$this->raw_item->isAvailable() || $this->raw_item->isAlwaysAvailable()) {
232 return $DIC->ui()->renderer()->render($this->raw_item->getNonAvailableReason());
233 }
234
235 return "";
236 }
237
242 public function getTypeForPresentation() : string
243 {
244 return $this->type_information->getTypeNameForPresentation();
245 }
246
247 public function getParentIdentificationString() : string
248 {
249 if ($this->getFilteredItem() instanceof isChild || $this->getFilteredItem() instanceof isInterchangeableItem) {
250 $provider_name_for_presentation = $this->raw_item->getParent()->serialize();
251
252 $storage_parent = $this->mm_item->getParentIdentification();
253 if ($storage_parent !== $provider_name_for_presentation) {
254 return $storage_parent;
255 }
256
257 return $provider_name_for_presentation;
258 }
259
260 return "";
261 }
262
266 public function isCustomType() : bool
267 {
268 $known_core_types = [
269 Complex::class,
270 Link::class,
271 LinkList::class,
272 Lost::class,
273 RepositoryLink::class,
274 Separator::class,
275 TopLinkItem::class,
276 TopParentItem::class,
277 ];
278 foreach ($known_core_types as $known_core_type) {
279 if (get_class($this->raw_item) === $known_core_type) {
280 return false;
281 }
282 }
283
284 return true;
285 }
286
290 public function isTopItem() : bool
291 {
292 return $this->raw_item instanceof isTopItem;
293 }
294
295 public function isChild() : bool
296 {
297 $item = $this->getFilteredItem();
298 return $item instanceof isChild
299 || ($item instanceof isInterchangeableItem && $item->hasChanged());
300 }
301
305 public function isInLostItem() : bool
306 {
307 if ($this->raw_item instanceof isChild) {
308 return $this->raw_item->getParent() instanceof NullIdentification;
309 }
310
311 return false;
312 }
313
317 public function setIsTopItm(bool $top_item)
318 {
319 // TODO: Implement setIsTopItm() method.
320 }
321
325 public function isInterchangeable() : bool
326 {
327 return $this->raw_item instanceof isInterchangeableItem;
328 }
329
334 public function getType() : string
335 {
336 return $this->type_information->getType();
337 }
338
342 public function setParent(string $parent)
343 {
344 $this->mm_item->setParentIdentification($parent);
345 }
346
350 public function setPosition(int $position)
351 {
352 $this->mm_item->setPosition($position);
353 }
354
358 public function setActiveStatus(bool $status)
359 {
360 $this->mm_item->setActive($status);
361 }
362
363 public function supportsCustomIcon() : bool
364 {
365 return $this->raw_item instanceof hasSymbol;
366 }
367
368 public function getIconID() : ?string
369 {
370 return $this->mm_item->getIconId();
371 }
372
376 public function setIconID(string $icon_id)
377 {
378 $this->mm_item->setIconId($icon_id);
379 }
380
381 // CRUD
382
383 public function update()
384 {
386 $this->mm_item->update();
387 }
388
389 public function create()
390 {
392 $this->mm_item->create();
393 ilMMItemStorage::register($this->raw_item);
394 }
395
400 protected function deleteAssociatedTranslations()
401 {
403 'identification' => $this->identification->serialize(),
404 ], '=')->get();
405
406 if (!empty($ts)) {
407 foreach ($ts as $translation) {
408 if ($translation instanceof ilMMItemTranslationStorage) {
409 $translation->delete();
410 }
411 }
412 }
413 }
414
418 public function delete()
419 {
420 if ($this->isDeletable()) {
422 $serialize = $this->identification->serialize();
423 $mm = ilMMItemStorage::find($serialize);
424 if ($mm instanceof ilMMItemStorage) {
425 $mm->delete();
426 }
427 }
428 }
429}
static where($where, $operator=null)
An exception for terminatinating execution or to throw for unit testing.
static find($primary_key, array $add_constructor_args=array())
@inheritDoc
Class MainMenuMainCollector This Collector will collect and then provide all available slates from th...
Class ilMMAbstractItemFacade.
setRoleBasedVisibility(bool $role_based_visibility)
@inheritDoc
getType()
FSX check if doublette @inheritDoc.
__construct(\ILIAS\GlobalScreen\Identification\IdentificationInterface $identification, Main $collector)
ilMMAbstractItemFacade constructor.
setDefaultTitle(string $default_title)
setIconID(string $icon_id)
@inheritDoc
setIsTopItm(bool $top_item)
@inheritDoc
deleteAssociatedTranslations()
deletes all translations associated with the current identification.
setGlobalRoleIDs(array $global_role_ids)
@inheritDoc
Class ilMMItemStorage.
static register(isItem $item)
Class ilMMItemTranslationStorage.
static storeDefaultTranslation(IdentificationInterface $identification, string $translation)
global $DIC
Definition: goto.php:24
Interface ilMMItemFacadeInterface.
Class ChatMainBarProvider \MainMenu\Provider.