ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMMAbstractItemFacade.php
Go to the documentation of this file.
1<?php
2
16
23{
24
32 protected $mm_item;
36 protected $gs_item;
40 protected $identification;
44 protected $default_title = "-";
45
46
55 public function __construct(\ILIAS\GlobalScreen\Identification\IdentificationInterface $identification, Main $collector)
56 {
58 $this->gs_item = $collector->getSingleItem($identification);
59 $this->type_information = $collector->getTypeInformationCollection()->get(get_class($this->gs_item));
60 $this->mm_item = ilMMItemStorage::register($this->gs_item);
61 }
62
63
64 public function getId() : string
65 {
66 return $this->identification->serialize();
67 }
68
69
73 public function hasStorage() : bool
74 {
75 return ilMMItemStorage::find($this->getId()) !== null;
76 }
77
78
82 public function isEmpty() : bool
83 {
84 return $this->mm_item->getIdentification() == '';
85 }
86
87
91 public function itemStorage() : ilMMItemStorage
92 {
93 return $this->mm_item;
94 }
95
96
100 public function identification() : \ILIAS\GlobalScreen\Identification\IdentificationInterface
101 {
103 }
104
105
109 public function item() : isItem
110 {
111 return $this->gs_item;
112 }
113
114
115 public function getAmountOfChildren() : int
116 {
117 if ($this->gs_item instanceof \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isParent) {
118 return count($this->gs_item->getChildren());
119 }
120
121 return 0;
122 }
123
124
125 public function isAvailable() : bool
126 {
127 return (bool) ($this->gs_item->isAvailable() || $this->item()->isAlwaysAvailable());
128 }
129
130
134 public function isActivated() : bool
135 {
136 return (bool) $this->mm_item->isActive() || $this->item()->isAlwaysAvailable();
137 }
138
139
143 public function isAlwaysAvailable() : bool
144 {
145 return $this->item()->isAlwaysAvailable();
146 }
147
148
152 public function getProviderNameForPresentation() : string
153 {
154 return $this->identification->getProviderNameForPresentation();
155 }
156
157
161 public function getDefaultTitle() : string
162 {
163 $default_translation = ilMMItemTranslationStorage::getDefaultTranslation($this->identification);
164 if ($default_translation !== "") {
165 return $default_translation;
166 }
167 if ($this->default_title == "-" && $this->gs_item instanceof \ILIAS\GlobalScreen\Scope\MainMenu\Factory\hasTitle) {
168 $this->default_title = $this->gs_item->getTitle();
169 }
170
172 }
173
174
178 public function setDefaultTitle(string $default_title)
179 {
180 $this->default_title = $default_title;
181 }
182
183
187 public function getStatus() : string
188 {
189 global $DIC;
190 if (!$this->gs_item->isAvailable() || $this->gs_item->isAlwaysAvailable()) {
191 return $DIC->ui()->renderer()->render($this->gs_item->getNonAvailableReason());
192 }
193
194 return "";
195 }
196
197
202 public function getTypeForPresentation() : string
203 {
204 return $this->type_information->getTypeNameForPresentation();
205 }
206
207
208 public function getParentIdentificationString() : string
209 {
210 if ($this->gs_item instanceof isChild) {
211 $provider_name_for_presentation = $this->gs_item->getParent()->serialize();
212
213 return $provider_name_for_presentation;
214 }
215
216 return "";
217 }
218
219
223 public function isCustomType() : bool
224 {
225 $known_core_types = [
226 Complex::class,
227 Link::class,
228 LinkList::class,
229 Lost::class,
230 RepositoryLink::class,
231 Separator::class,
232 TopLinkItem::class,
233 TopParentItem::class,
234 ];
235 foreach ($known_core_types as $known_core_type) {
236 if (get_class($this->gs_item) === $known_core_type) {
237 return false;
238 }
239 }
240
241 return true;
242 }
243
244
248 public function isTopItem() : bool
249 {
250 return $this->gs_item instanceof isTopItem;
251 }
252
253
257 public function isInLostItem() : bool
258 {
259 if ($this->gs_item instanceof isChild) {
260 return $this->gs_item->getParent() instanceof NullIdentification;
261 }
262
263 return false;
264 }
265
266
270 public function setIsTopItm(bool $top_item)
271 {
272 // TODO: Implement setIsTopItm() method.
273 }
274
275
281 public function getType() : string
282 {
283 return $this->type_information->getType();
284 }
285
286
290 public function setParent(string $parent)
291 {
292 $this->mm_item->setParentIdentification($parent);
293 }
294
295
299 public function setPosition(int $position)
300 {
301 $this->mm_item->setPosition($position);
302 }
303
304
308 public function setActiveStatus(bool $status)
309 {
310 $this->mm_item->setActive($status);
311 }
312
313
314 // CRUD
315
316 public function update()
317 {
319 $this->mm_item->update();
320 }
321
322
323 public function create()
324 {
326 $this->mm_item->create();
327 ilMMItemStorage::register($this->gs_item);
328 }
329
334 protected function deleteAssociatedTranslations()
335 {
337 'identification' => $this->identification->serialize(),
338 ], '=')->get();
339
340 if (!empty($ts)) {
341 foreach ($ts as $translation) {
342 if ($translation instanceof ilMMItemTranslationStorage) {
343 $translation->delete();
344 }
345 }
346 }
347 }
348
352 public function delete()
353 {
354 if ($this->isDeletable()) {
356 $serialize = $this->identification->serialize();
357 $gs = ilGSIdentificationStorage::find($serialize);
358 if ($gs instanceof ilGSIdentificationStorage) {
359 $gs->delete();
360 }
361 $mm = ilMMItemStorage::find($serialize);
362 if ($mm instanceof ilMMItemStorage) {
363 $mm->delete();
364 }
365 }
366 }
367}
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 ilMMAbstractItemFacade.
getType()
FSX check if doublette.
__construct(\ILIAS\GlobalScreen\Identification\IdentificationInterface $identification, Main $collector)
ilMMAbstractItemFacade constructor.
setDefaultTitle(string $default_title)
setIsTopItm(bool $top_item)
@inheritDoc
deleteAssociatedTranslations()
deletes all translations associated with the current identification.
Class ilMMItemStorage.
static register(isItem $item)
Class ilMMItemTranslationStorage.
static storeDefaultTranslation(IdentificationInterface $identification, string $translation)
Interface ilMMItemFacadeInterface.
Class BaseForm.
global $DIC
Definition: saml.php:7