ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMMAbstractItemFacade.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
24 
30 {
31  protected bool $role_based_visibility = false;
32 
33  protected array $global_role_ids = [];
34 
36 
39  protected isItem $raw_item;
40 
42  protected string $default_title = "-";
43 
50  public function __construct(
51  IdentificationInterface $identification,
52  Main $collector
53  ) {
55  $this->raw_item = $collector->getSingleItemFromRaw($identification);
56  $this->filtered_item = $collector->getSingleItemFromFilter($identification);
57  $this->type_information = $collector->getTypeInformationCollection()->get(get_class($this->raw_item));
58  $this->mm_item = ilMMItemStorage::register($this->raw_item);
59  }
60 
61  public function getId(): string
62  {
63  return $this->identification->serialize();
64  }
65 
69  public function hasStorage(): bool
70  {
71  return ilMMItemStorage::find($this->getId()) !== null;
72  }
73 
77  public function supportsRoleBasedVisibility(): bool
78  {
79  return false;
80  }
81 
85  public function hasRoleBasedVisibility(): bool
86  {
88  }
89 
93  public function setRoleBasedVisibility(bool $role_based_visibility): void
94  {
95  $this->role_based_visibility = $role_based_visibility;
96  }
97 
101  public function getGlobalRoleIDs(): array
102  {
103  return $this->global_role_ids;
104  }
105 
109  public function setGlobalRoleIDs(array $global_role_ids): void
110  {
111  $this->global_role_ids = $global_role_ids;
112  }
113 
117  public function isEmpty(): bool
118  {
119  return $this->mm_item->getIdentification() == '';
120  }
121 
125  public function itemStorage(): ilMMItemStorage
126  {
127  return $this->mm_item;
128  }
129 
134  {
135  return $this->identification;
136  }
137 
138  public function getRawItem(): isItem
139  {
140  return $this->raw_item;
141  }
142  public function getFilteredItem(): isItem
143  {
144  return $this->filtered_item;
145  }
146 
147  public function getAmountOfChildren(): int
148  {
149  if ($this->filtered_item instanceof isParent) {
150  return count($this->filtered_item->getChildren());
151  }
152 
153  return 0;
154  }
155 
156  public function isAvailable(): bool
157  {
158  return $this->filtered_item->isAvailable() || $this->filtered_item->isAlwaysAvailable();
159  }
160 
164  public function isActivated(): bool
165  {
166  return $this->mm_item->isActive() && $this->getRawItem()->isAvailable() || $this->getRawItem()->isAlwaysAvailable();
167  }
168 
172  public function isAlwaysAvailable(): bool
173  {
174  return $this->getRawItem()->isAlwaysAvailable();
175  }
176 
180  public function getProviderNameForPresentation(): string
181  {
182  return $this->identification->getProviderNameForPresentation();
183  }
184 
188  public function getDefaultTitle(): string
189  {
190  $default_translation = ilMMItemTranslationStorage::getDefaultTranslation($this->identification);
191  if ($default_translation !== "") {
192  return $default_translation;
193  }
194  if ($this->default_title == "-" && $this->raw_item instanceof hasTitle) {
195  $this->default_title = $this->raw_item->getTitle();
196  }
197 
198  return $this->default_title;
199  }
200 
204  public function setDefaultTitle(string $default_title): void
205  {
206  $this->default_title = $default_title;
207  }
208 
212  public function getStatus(): string
213  {
214  global $DIC;
215  if (!$this->raw_item->isAvailable() || $this->raw_item->isAlwaysAvailable()) {
216  return $DIC->ui()->renderer()->render($this->raw_item->getNonAvailableReason());
217  }
218 
219  return "";
220  }
221 
226  public function getTypeForPresentation(): string
227  {
228  return $this->type_information->getTypeNameForPresentation();
229  }
230 
231  public function getParentIdentificationString(): string
232  {
233  if ($this->getFilteredItem() instanceof isChild || $this->getFilteredItem() instanceof isInterchangeableItem) {
234  $provider_name_for_presentation = $this->raw_item->getParent()->serialize();
235 
236  $storage_parent = $this->mm_item->getParentIdentification();
237  if ($storage_parent !== $provider_name_for_presentation) {
238  return $storage_parent;
239  }
240 
241  return $provider_name_for_presentation;
242  }
243 
244  return "";
245  }
246 
250  public function isCustomType(): bool
251  {
252  $known_core_types = [
253  Complex::class,
254  Link::class,
255  LinkList::class,
256  Lost::class,
257  RepositoryLink::class,
258  Separator::class,
259  TopLinkItem::class,
260  TopParentItem::class,
261  ];
262  foreach ($known_core_types as $known_core_type) {
263  if (get_class($this->raw_item) === $known_core_type) {
264  return false;
265  }
266  }
267 
268  return true;
269  }
270 
274  public function isTopItem(): bool
275  {
276  return $this->raw_item instanceof isTopItem;
277  }
278 
279  public function isChild(): bool
280  {
281  $item = $this->getFilteredItem();
282  return $item instanceof isChild
283  || ($item instanceof isInterchangeableItem && $item->hasChanged());
284  }
285 
289  public function isInLostItem(): bool
290  {
291  if ($this->raw_item instanceof isChild) {
292  return $this->raw_item->getParent() instanceof NullIdentification;
293  }
294 
295  return false;
296  }
297 
301  public function setIsTopItm(bool $top_item): void
302  {
303  // TODO: Implement setIsTopItm() method.
304  }
305 
309  public function isInterchangeable(): bool
310  {
311  return $this->raw_item instanceof isInterchangeableItem;
312  }
313 
318  public function getType(): string
319  {
320  return $this->type_information->getType();
321  }
322 
326  public function setParent(string $parent): void
327  {
328  $this->mm_item->setParentIdentification($parent);
329  }
330 
334  public function setPosition(int $position): void
335  {
336  $this->mm_item->setPosition($position);
337  }
338 
342  public function setActiveStatus(bool $status): void
343  {
344  $this->mm_item->setActive($status);
345  }
346 
347  public function supportsCustomIcon(): bool
348  {
349  return $this->raw_item instanceof hasSymbol;
350  }
351 
352  public function getIconID(): ?string
353  {
354  return $this->mm_item->getIconId();
355  }
356 
360  public function setIconID(string $icon_id): void
361  {
362  $this->mm_item->setIconId($icon_id);
363  }
364 
365  // CRUD
366 
367  public function update(): void
368  {
370  $this->mm_item->update();
371  }
372 
373  public function create(): void
374  {
376  $this->mm_item->create();
377  ilMMItemStorage::register($this->raw_item);
378  }
379 
384  protected function deleteAssociatedTranslations(): void
385  {
387  'identification' => $this->identification->serialize(),
388  ], '=')->get();
389 
390  if (!empty($ts)) {
391  foreach ($ts as $translation) {
392  if ($translation instanceof ilMMItemTranslationStorage) {
393  $translation->delete();
394  }
395  }
396  }
397  }
398 
402  public function delete(): void
403  {
404  if ($this->isDeletable()) {
406  $serialize = $this->identification->serialize();
407  $mm = ilMMItemStorage::find($serialize);
408  if ($mm instanceof ilMMItemStorage) {
409  $mm->delete();
410  }
411  }
412  }
413 }
deleteAssociatedTranslations()
deletes all translations associated with the current identification.
Class ilMMAbstractItemFacade.
static storeDefaultTranslation(IdentificationInterface $identification, string $translation)
setRoleBasedVisibility(bool $role_based_visibility)
static where($where, $operator=null)
global $DIC
Definition: feed.php:28
IdentificationInterface $identification
static register(isItem $item)
setGlobalRoleIDs(array $global_role_ids)
__construct(IdentificationInterface $identification, Main $collector)
ilMMAbstractItemFacade constructor.
getType()
FSX check if doublette .
Interface ilMMItemFacadeInterface.
setDefaultTitle(string $default_title)
Class ilMMItemTranslationStorage.