ILIAS  release_8 Revision v8.24
class.ilMMItemRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
33
39{
41
43
45
47
52 public function __construct()
53 {
54 global $DIC;
56 $this->db = $DIC->database();
57 $this->main_collector = $DIC->globalScreen()->collector()->mainmenu();
58 $this->main_collector->collectOnce();
59 $this->services = $DIC->globalScreen();
60
61 foreach ($this->main_collector->getRawUnfilteredItems() as $top_item) {
63 }
64 }
65
66 public function clearCache(): void
67 {
68 $this->cache->flush();
69 }
70
75 public function getSingleItem(IdentificationInterface $identification): isItem
76 {
77 return $this->main_collector->getSingleItemFromRaw($identification);
78 }
79
80 public function getSingleItemFromFilter(IdentificationInterface $identification): isItem
81 {
82 return $this->main_collector->getSingleItemFromFilter($identification);
83 }
84
85 public function resolveIdentificationFromString(string $identification_string): IdentificationInterface
86 {
87 return $this->services->identification()->fromSerializedIdentification($identification_string);
88 }
89
93 public function repository(): ilMMItemRepository
94 {
95 return $this;
96 }
97
102 public function getTopItems(): array
103 {
104 return ilMMItemStorage::where(" parent_identification = '' OR parent_identification IS NULL ")->orderBy('position')->getArray();
105 }
106
110 public function getSubItemsForTable(): array
111 {
112 $r = $this->db->query(
113 "SELECT sub_items.*, top_items.position AS parent_position
114FROM il_mm_items AS sub_items
115LEFT JOIN il_mm_items AS top_items ON top_items.identification = sub_items.parent_identification
116WHERE sub_items.parent_identification != '' ORDER BY top_items.position, parent_identification, sub_items.position ASC"
117 );
118 $return = [];
119 while ($data = $this->db->fetchAssoc($r)) {
120 $return[] = $data;
121 }
122
123 return $return;
124 }
125
126 public function flushLostItems(): void
127 {
128 foreach ($this->getTopItems() as $item) {
129 $item_facade = $this->getItemFacade($this->services->identification()->fromSerializedIdentification($item['identification']));
130 if (Lost::class === $item_facade->getType()) {
131 $item_facade->delete();
132 }
133 }
134
135 foreach ($this->getSubItemsForTable() as $item) {
136 $item_facade = $this->getItemFacade($this->services->identification()->fromSerializedIdentification($item['identification']));
137 if (Lost::class === $item_facade->getType()) {
138 $item_facade->delete();
139 }
140 }
141 }
142
143 public function hasLostItems(): bool
144 {
145 foreach ($this->getTopItems() as $item) {
146 $item_facade = $this->getItemFacade($this->services->identification()->fromSerializedIdentification($item['identification']));
147 if (Lost::class === $item_facade->getType()) {
148 return true;
149 }
150 }
151
152 foreach ($this->getSubItemsForTable() as $item) {
153 $item_facade = $this->getItemFacade($this->services->identification()->fromSerializedIdentification($item['identification']));
154 if (Lost::class === $item_facade->getType()) {
155 return true;
156 }
157 }
158 return false;
159 }
160
166 public function getItemFacade(IdentificationInterface $identification = null): ilMMItemFacadeInterface
167 {
168 if ($identification === null || $identification instanceof NullIdentification || $identification instanceof NullPluginIdentification) {
169 return new ilMMNullItemFacade($identification ?: new NullIdentification(), $this->main_collector);
170 }
171 if ($identification->getClassName() === CustomMainBarProvider::class) {
172 return new ilMMCustomItemFacade($identification, $this->main_collector);
173 }
174
175 return new ilMMItemFacade($identification, $this->main_collector);
176 }
177
183 public function getItemFacadeForIdentificationString(string $identification): ilMMItemFacadeInterface
184 {
185 $id = $this->services->identification()->fromSerializedIdentification($identification);
186
187 return $this->getItemFacade($id);
188 }
189
190 public function getPossibleParentsForFormAndTable(): array
191 {
192 static $parents;
193 if ($parents === null) {
194 $parents = [];
195 foreach ($this->getTopItems() as $top_item_identification => $data) {
196 $identification = $this->services->identification()->fromSerializedIdentification($top_item_identification);
197 $item = $this->getSingleItem($identification);
198 if ($item instanceof TopParentItem) {
199 $parents[$top_item_identification] = $this->getItemFacade($identification)
200 ->getDefaultTitle();
201 }
202 }
203 }
204
205 return $parents;
206 }
207
212 {
213 $types = [];
214 foreach ($this->main_collector->getTypeInformationCollection()->getAll() as $information) {
215 if ($information->isCreationPrevented()) {
216 continue;
217 }
218 if ($information->isChild()) {
219 if ($information->getType() === TopLinkItem::class) { // since these two types are identical (more or less), we truncate one
220 continue;
221 }
222 $types[$information->getType()] = $information;
223 }
224 }
225
226 return $types;
227 }
228
232 public function getPossibleTopItemTypesWithInformation(bool $new): array
233 {
234 $types = [];
235 foreach ($this->main_collector->getTypeInformationCollection()->getAll() as $information) {
236 if (!$new || $information->isTop()) {
237 $types[$information->getType()] = $information;
238 }
239 }
240
241 return $types;
242 }
243
249 public function getTypeHandlerForType(string $type): TypeHandler
250 {
251 $item = $this->services->mainBar()->custom($type, new NullIdentification());
252
253 return $this->main_collector->getTypeHandlerForItem($item);
254 }
255
259 public function updateItem(ilMMItemFacadeInterface $item_facade): void
260 {
261 if ($item_facade->isEditable()) {
262 $item_facade->update();
263 $this->clearCache();
264 }
265 }
266
270 public function createItem(ilMMItemFacadeInterface $item_facade): void
271 {
272 $item_facade->create();
273 $this->clearCache();
274 }
275
279 public function deleteItem(ilMMItemFacadeInterface $item_facade): void
280 {
281 if ($item_facade->isDeletable()) {
282 $item_facade->delete();
283 $this->clearCache();
284 }
285 }
286}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static where($where, $operator=null)
Class MainMenuMainCollector This Collector will collect and then provide all available slates from th...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(?string $component)
Class ilMMCustomItemFacade.
Class ilMMItemFacade.
Class ilMMItemRepository.
__construct()
ilMMItemRepository constructor.
resolveIdentificationFromString(string $identification_string)
updateItem(ilMMItemFacadeInterface $item_facade)
deleteItem(ilMMItemFacadeInterface $item_facade)
getItemFacadeForIdentificationString(string $identification)
createItem(ilMMItemFacadeInterface $item_facade)
getItemFacade(IdentificationInterface $identification=null)
getSingleItem(IdentificationInterface $identification)
getPossibleTopItemTypesWithInformation(bool $new)
MainMenuMainCollector $main_collector
getSingleItemFromFilter(IdentificationInterface $identification)
static register(isItem $item)
Class ilMMNullItemFacade.
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
Interface ilMMItemFacadeInterface.
$type