ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMMAbstractItemFacade.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
40 
46 {
47  protected bool $role_based_visibility = false;
48 
49  protected array $global_role_ids = [];
50 
52 
55  protected isItem $raw_item;
56  protected string $default_title = "-";
57 
64  public function __construct(
65  protected IdentificationInterface $identification,
66  Main $collector
67  ) {
68  $this->raw_item = $collector->getSingleItemFromRaw($this->identification);
69  $this->filtered_item = $collector->getSingleItemFromFilter($this->identification);
70  $this->type_information = $collector->getTypeInformationCollection()->get($this->raw_item::class);
71  $this->mm_item = ilMMItemStorage::register($this->raw_item);
72  }
73 
74  public function getId(): string
75  {
76  return $this->identification->serialize();
77  }
78 
82  public function hasStorage(): bool
83  {
84  return ilMMItemStorage::find($this->getId()) !== null;
85  }
86 
90  public function supportsRoleBasedVisibility(): bool
91  {
92  return false;
93  }
94 
98  public function hasRoleBasedVisibility(): bool
99  {
101  }
102 
106  public function setRoleBasedVisibility(bool $role_based_visibility): void
107  {
108  $this->role_based_visibility = $role_based_visibility;
109  }
110 
114  public function getGlobalRoleIDs(): array
115  {
116  return $this->global_role_ids;
117  }
118 
122  public function setGlobalRoleIDs(array $global_role_ids): void
123  {
124  $this->global_role_ids = $global_role_ids;
125  }
126 
130  public function isEmpty(): bool
131  {
132  return $this->mm_item->getIdentification() === '';
133  }
134 
138  public function itemStorage(): ilMMItemStorage
139  {
140  return $this->mm_item;
141  }
142 
147  {
148  return $this->identification;
149  }
150 
151  public function getRawItem(): isItem
152  {
153  return $this->raw_item;
154  }
155  public function getFilteredItem(): isItem
156  {
157  return $this->filtered_item;
158  }
159 
160  public function getAmountOfChildren(): int
161  {
162  if ($this->filtered_item instanceof isParent) {
163  return count($this->filtered_item->getChildren());
164  }
165 
166  return 0;
167  }
168 
169  public function isAvailable(): bool
170  {
171  if ($this->filtered_item->isAvailable()) {
172  return true;
173  }
174  return $this->filtered_item->isAlwaysAvailable();
175  }
176 
180  public function isActivated(): bool
181  {
182  if ($this->mm_item->isActive() && $this->getRawItem()->isAvailable()) {
183  return true;
184  }
185  return $this->getRawItem()->isAlwaysAvailable();
186  }
187 
191  public function isAlwaysAvailable(): bool
192  {
193  return $this->getRawItem()->isAlwaysAvailable();
194  }
195 
199  public function getProviderNameForPresentation(): string
200  {
201  return $this->identification->getProviderNameForPresentation();
202  }
203 
207  public function getDefaultTitle(): string
208  {
209  $default_translation = ilMMItemTranslationStorage::getDefaultTranslation($this->identification);
210  if ($default_translation !== "") {
211  return $default_translation;
212  }
213  if ($this->default_title === "-" && $this->raw_item instanceof hasTitle) {
214  $this->default_title = $this->raw_item->getTitle();
215  }
216 
217  return $this->default_title;
218  }
219 
223  public function setDefaultTitle(string $default_title): void
224  {
225  $this->default_title = $default_title;
226  }
227 
231  public function getStatus(): string
232  {
233  global $DIC;
234  if (!$this->raw_item->isAvailable() || $this->raw_item->isAlwaysAvailable()) {
235  return $DIC->ui()->renderer()->render($this->raw_item->getNonAvailableReason());
236  }
237 
238  return "";
239  }
240 
245  public function getTypeForPresentation(): string
246  {
247  return $this->type_information->getTypeNameForPresentation();
248  }
249 
250  public function getParentIdentificationString(): string
251  {
252  if ($this->getFilteredItem() instanceof isChild || $this->getFilteredItem() instanceof isInterchangeableItem) {
253  $provider_name_for_presentation = $this->raw_item->getParent()->serialize();
254 
255  $storage_parent = $this->mm_item->getParentIdentification();
256  if ($storage_parent !== $provider_name_for_presentation) {
257  return $storage_parent;
258  }
259 
260  return $provider_name_for_presentation;
261  }
262 
263  return "";
264  }
265 
269  public function isCustomType(): bool
270  {
271  $known_core_types = [
272  Complex::class,
273  Link::class,
274  LinkList::class,
275  Lost::class,
276  RepositoryLink::class,
277  Separator::class,
278  TopLinkItem::class,
279  TopParentItem::class,
280  ];
281  return !in_array($this->raw_item::class, $known_core_types, true);
282  }
283 
287  public function isTopItem(): bool
288  {
289  return $this->raw_item instanceof isTopItem;
290  }
291 
292  public function isChild(): bool
293  {
294  $item = $this->getFilteredItem();
295  return $item instanceof isChild
296  || ($item instanceof isInterchangeableItem && $item->hasChanged());
297  }
298 
302  public function isInLostItem(): bool
303  {
304  if ($this->raw_item instanceof isChild) {
305  return $this->raw_item->getParent() instanceof NullIdentification;
306  }
307 
308  return false;
309  }
310 
314  public function setIsTopItm(bool $top_item): void
315  {
316  // TODO: Implement setIsTopItm() method.
317  }
318 
322  public function isInterchangeable(): bool
323  {
324  return $this->raw_item instanceof isInterchangeableItem;
325  }
326 
331  public function getType(): string
332  {
333  return $this->type_information->getType();
334  }
335 
339  public function setParent(string $parent): void
340  {
341  $this->mm_item->setParentIdentification($parent);
342  }
343 
347  public function setPosition(int $position): void
348  {
349  $this->mm_item->setPosition($position);
350  }
351 
355  public function setActiveStatus(bool $status): void
356  {
357  $this->mm_item->setActive($status);
358  }
359 
360  public function supportsCustomIcon(): bool
361  {
362  return $this->raw_item instanceof hasSymbol;
363  }
364 
365  public function getIconID(): ?string
366  {
367  return $this->mm_item->getIconId();
368  }
369 
373  public function setIconID(string $icon_id): void
374  {
375  $this->mm_item->setIconId($icon_id);
376  }
377 
378  // CRUD
379 
380  public function update(): void
381  {
383  $this->mm_item->update();
384  }
385 
386  public function create(): void
387  {
389  $this->mm_item->create();
390  ilMMItemStorage::register($this->raw_item);
391  }
392 
397  protected function deleteAssociatedTranslations(): void
398  {
400  'identification' => $this->identification->serialize(),
401  ], '=')->get();
402 
403  if (!empty($ts)) {
404  foreach ($ts as $translation) {
405  if ($translation instanceof ilMMItemTranslationStorage) {
406  $translation->delete();
407  }
408  }
409  }
410  }
411 
415  public function delete(): void
416  {
417  if ($this->isDeletable()) {
419  $serialize = $this->identification->serialize();
420  $mm = ilMMItemStorage::find($serialize);
421  if ($mm instanceof ilMMItemStorage) {
422  $mm->delete();
423  }
424  }
425  }
426 }
deleteAssociatedTranslations()
deletes all translations associated with the current identification.
Class ilMMAbstractItemFacade.
static storeDefaultTranslation(IdentificationInterface $identification, string $translation)
setRoleBasedVisibility(bool $role_based_visibility)
__construct(protected IdentificationInterface $identification, Main $collector)
ilMMAbstractItemFacade constructor.
static where($where, $operator=null)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static register(isItem $item)
global $DIC
Definition: shib_login.php:22
setGlobalRoleIDs(array $global_role_ids)
getType()
FSX check if doublette .
Interface ilMMItemFacadeInterface.
setDefaultTitle(string $default_title)
Class ilMMItemTranslationStorage.