ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMMAbstractItemFacade.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
41
47{
48 protected bool $role_based_visibility = false;
49
50 protected array $global_role_ids = [];
51
53
56 protected isItem $raw_item;
57 protected string $default_title = "-";
58
63 public function __construct(
64 protected IdentificationInterface $identification,
65 Main $collector
66 ) {
67 $this->raw_item = $collector->getSingleItemFromRaw($this->identification);
68 $this->filtered_item = $collector->getSingleItemFromFilter($this->identification);
69 $this->type_information = $collector->getTypeInformationCollection()->get($this->raw_item::class);
70 $this->mm_item = ilMMItemStorage::register($this->raw_item);
71 }
72
73 public function getId(): string
74 {
75 return $this->identification->serialize();
76 }
77
78 public function hasStorage(): bool
79 {
80 return ilMMItemStorage::find($this->getId()) !== null;
81 }
82
86 public function supportsRoleBasedVisibility(): bool
87 {
88 return false;
89 }
90
91 public function canBeDeactivated(): bool
92 {
93 return !$this->raw_item->isAlwaysAvailable();
94 }
95
99 public function hasRoleBasedVisibility(): bool
100 {
102 }
103
108 {
109 $this->role_based_visibility = $role_based_visibility;
110 }
111
115 public function getGlobalRoleIDs(): array
116 {
118 }
119
123 public function setGlobalRoleIDs(array $global_role_ids): void
124 {
125 $this->global_role_ids = $global_role_ids;
126 }
127
128 public function isEmpty(): bool
129 {
130 return $this->mm_item->getIdentification() === '';
131 }
132
133 public function itemStorage(): ilMMItemStorage
134 {
135 return $this->mm_item;
136 }
137
139 {
140 return $this->identification;
141 }
142
143 public function getRawItem(): isItem
144 {
145 return $this->raw_item;
146 }
147 public function getFilteredItem(): isItem
148 {
150 }
151
152 public function getAmountOfChildren(): int
153 {
154 if ($this->filtered_item instanceof isParent || $this->filtered_item instanceof isTopItem) {
155 return $this->filtered_item->getAmountOfChildren();
156 }
157
158 return 0;
159 }
160
161 public function isAvailable(): bool
162 {
163 if ($this->filtered_item->isAvailable()) {
164 return true;
165 }
166 return $this->filtered_item->isAlwaysAvailable();
167 }
168
172 public function isActivated(): bool
173 {
174 if ($this->mm_item->isActive() && $this->getRawItem()->isAvailable()) {
175 return true;
176 }
177 return $this->getRawItem()->isAlwaysAvailable();
178 }
179
183 public function isAlwaysAvailable(): bool
184 {
185 return $this->getRawItem()->isAlwaysAvailable();
186 }
187
188 public function getProviderNameForPresentation(): string
189 {
190 return $this->identification->getProviderNameForPresentation();
191 }
192
193 public function getDefaultTitle(): string
194 {
195 $default_translation = ilMMItemTranslationStorage::getDefaultTranslation($this->identification);
196 if ($default_translation !== "") {
197 return $default_translation;
198 }
199 if ($this->default_title === "-" && $this->raw_item instanceof hasTitle) {
200 $this->default_title = $this->raw_item->getTitle();
201 }
202
204 }
205
206 public function setDefaultTitle(string $default_title): void
207 {
208 $this->default_title = $default_title;
209 }
210
211 public function getStatus(): ?Content
212 {
213 $non_available_reason = $this->raw_item->getNonAvailableReason();
214 if (!$this->raw_item->isAvailable()) {
215 return $non_available_reason;
216 }
217 if ($this->raw_item->isAlwaysAvailable()) {
218 return $non_available_reason;
219 }
220
221 return null;
222 }
223
227 public function getTypeForPresentation(): string
228 {
229 return $this->type_information->getTypeNameForPresentation();
230 }
231
232 public function getParentIdentificationString(): string
233 {
234 if ($this->getFilteredItem() instanceof isChild || $this->getFilteredItem() instanceof isInterchangeableItem) {
235 $provider_name_for_presentation = $this->raw_item->getParent()->serialize();
236
237 $storage_parent = $this->mm_item->getParentIdentification();
238 if ($storage_parent !== $provider_name_for_presentation) {
239 return $storage_parent;
240 }
241
242 return $provider_name_for_presentation;
243 }
244
245 return "";
246 }
247
248 public function isCustomType(): bool
249 {
250 $known_core_types = [
251 Complex::class,
252 Link::class,
253 LinkList::class,
254 Lost::class,
255 RepositoryLink::class,
256 Separator::class,
257 TopLinkItem::class,
258 TopParentItem::class,
259 ];
260 return !in_array($this->raw_item::class, $known_core_types, true);
261 }
262
266 public function isTopItem(): bool
267 {
268 return $this->raw_item instanceof isTopItem;
269 }
270
271 public function canHaveChildren(): bool
272 {
273 return $this->raw_item instanceof isParent;
274 }
275
276 public function isChild(): bool
277 {
278 $item = $this->getFilteredItem();
279 return $item instanceof isChild
280 || ($item instanceof isInterchangeableItem && $item->hasChanged());
281 }
282
286 public function isInLostItem(): bool
287 {
288 if ($this->raw_item instanceof isChild) {
289 return $this->raw_item->getParent() instanceof NullIdentification;
290 }
291
292 return false;
293 }
294
298 public function setIsTopItm(bool $top_item): void
299 {
300 // TODO: Implement setIsTopItm() method.
301 }
302
306 public function isInterchangeable(): bool
307 {
308 return $this->raw_item instanceof isInterchangeableItem;
309 }
310
315 public function getType(): string
316 {
317 return $this->type_information->getType();
318 }
319
320 public function setParent(string $parent): void
321 {
322 $this->mm_item->setParentIdentification($parent);
323 }
324
328 public function setPosition(int $position): void
329 {
330 $this->mm_item->setPosition($position);
331 }
332
333 public function setActiveStatus(bool $status): void
334 {
335 $this->mm_item->setActive($status);
336 }
337
338 public function supportsCustomIcon(): bool
339 {
340 return $this->raw_item instanceof hasSymbol;
341 }
342
343 public function getIconID(): ?string
344 {
345 return $this->mm_item->getIconId();
346 }
347
351 public function setIconID(string $icon_id): void
352 {
353 $this->mm_item->setIconId($icon_id);
354 }
355
356 // CRUD
357
358 public function update(): void
359 {
361 $this->mm_item->update();
362 }
363
364 public function create(): void
365 {
367 $this->mm_item->create();
368 ilMMItemStorage::register($this->raw_item);
369 }
370
375 protected function deleteAssociatedTranslations(): void
376 {
378 'identification' => $this->identification->serialize(),
379 ], '=')->get();
380
381 foreach ($ts as $translation) {
382 if ($translation instanceof ilMMItemTranslationStorage) {
383 $translation->delete();
384 }
385 }
386 }
387
388 public function getTitle(): string
389 {
390 return $this->getDefaultTitle();
391 }
392
396 public function delete(): void
397 {
398 if ($this->isDeletable()) {
400 $serialize = $this->identification->serialize();
401 $mm = ilMMItemStorage::find($serialize);
402 if ($mm instanceof ilMMItemStorage) {
403 $mm->delete();
404 }
405 }
406 }
407
408
409}
static where($where, $operator=null)
Class MainMenuMainCollector This Collector will collect and then provide all available slates from th...
Class ilMMAbstractItemFacade.
__construct(protected IdentificationInterface $identification, Main $collector)
ilMMAbstractItemFacade constructor.
setRoleBasedVisibility(bool $role_based_visibility)
@inheritDoc
getType()
FSX check if doublette @inheritDoc.
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)
Interface ilMMItemFacadeInterface.