ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 = [];
37  protected $type_information;
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 
108  public function setRoleBasedVisibility(bool $role_based_visibility) : void
109  {
110  $this->role_based_visibility = $role_based_visibility;
111  }
112 
116  public function getGlobalRoleIDs() : array
117  {
118  return $this->global_role_ids;
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  {
150  return $this->identification;
151  }
152 
153 
154  public function getRawItem() : isItem
155  {
156  return $this->raw_item;
157  }
158  public function getFilteredItem() : isItem
159  {
160  return $this->filtered_item;
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 
214  return $this->default_title;
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->raw_item instanceof isChild) {
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  return $this->getRawItem() instanceof isChild;
298  }
299 
303  public function isInLostItem() : bool
304  {
305  if ($this->raw_item instanceof isChild) {
306  return $this->raw_item->getParent() instanceof NullIdentification;
307  }
308 
309  return false;
310  }
311 
315  public function setIsTopItm(bool $top_item)
316  {
317  // TODO: Implement setIsTopItm() method.
318  }
319 
323  public function isInterchangeable() : bool
324  {
325  return false;
326  }
327 
332  public function getType() : string
333  {
334  return $this->type_information->getType();
335  }
336 
340  public function setParent(string $parent)
341  {
342  $this->mm_item->setParentIdentification($parent);
343  }
344 
348  public function setPosition(int $position)
349  {
350  $this->mm_item->setPosition($position);
351  }
352 
356  public function setActiveStatus(bool $status)
357  {
358  $this->mm_item->setActive($status);
359  }
360 
361  public function supportsCustomIcon() : bool
362  {
363  return $this->raw_item instanceof hasSymbol;
364  }
365 
366  public function getIconID() : ?string
367  {
368  return $this->mm_item->getIconId();
369  }
370 
374  public function setIconID(string $icon_id)
375  {
376  $this->mm_item->setIconId($icon_id);
377  }
378 
379  // CRUD
380 
381  public function update()
382  {
384  $this->mm_item->update();
385  }
386 
387  public function create()
388  {
390  $this->mm_item->create();
391  ilMMItemStorage::register($this->raw_item);
392  }
393 
398  protected function deleteAssociatedTranslations()
399  {
401  'identification' => $this->identification->serialize(),
402  ], '=')->get();
403 
404  if (!empty($ts)) {
405  foreach ($ts as $translation) {
406  if ($translation instanceof ilMMItemTranslationStorage) {
407  $translation->delete();
408  }
409  }
410  }
411  }
412 
416  public function delete()
417  {
418  if ($this->isDeletable()) {
420  $serialize = $this->identification->serialize();
421  $mm = ilMMItemStorage::find($serialize);
422  if ($mm instanceof ilMMItemStorage) {
423  $mm->delete();
424  }
425  }
426  }
427 }
deleteAssociatedTranslations()
deletes all translations associated with the current identification.
Class ilMMAbstractItemFacade.
static find($primary_key, array $add_constructor_args=array())
Class ChatMainBarProvider .
__construct(\ILIAS\GlobalScreen\Identification\IdentificationInterface $identification, Main $collector)
ilMMAbstractItemFacade constructor.
static storeDefaultTranslation(IdentificationInterface $identification, string $translation)
setRoleBasedVisibility(bool $role_based_visibility)
static where($where, $operator=null)
static register(isItem $item)
setGlobalRoleIDs(array $global_role_ids)
getType()
FSX check if doublette .
$DIC
Definition: xapitoken.php:46
Interface ilMMItemFacadeInterface.
setDefaultTitle(string $default_title)
Class ilMMItemTranslationStorage.