ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMMItemRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
35
41{
43
45
47
49
54 public function __construct()
55 {
56 global $DIC;
57 $this->cache = $DIC->globalCache()->get($this);
58 $this->db = $DIC->database();
59 $this->main_collector = $DIC->globalScreen()->collector()->mainmenu();
60 $this->main_collector->collectOnce();
61 $this->services = $DIC->globalScreen();
62
63 foreach ($this->main_collector->getRawUnfilteredItems() as $top_item) {
65 }
66 }
67
68 public function getContainerKey(): string
69 {
70 return 'mm_items';
71 }
72
73 public function isForced(): bool
74 {
75 return false;
76 }
77
78 public function clearCache(): void
79 {
80 $this->cache->flush();
81 }
82
83 public function getSingleItem(IdentificationInterface $identification): isItem
84 {
85 return $this->main_collector->getSingleItemFromRaw($identification);
86 }
87
88 public function getSingleItemFromFilter(IdentificationInterface $identification): isItem
89 {
90 return $this->main_collector->getSingleItemFromFilter($identification);
91 }
92
93 public function resolveIdentificationFromString(string $identification_string): IdentificationInterface
94 {
95 return $this->services->identification()->fromSerializedIdentification($identification_string);
96 }
97
98 public function repository(): ilMMItemRepository
99 {
100 return $this;
101 }
102
106 public function getTopItems(): array
107 {
108 return ilMMItemStorage::where(" parent_identification = '' OR parent_identification IS NULL ")->orderBy(
109 'position'
110 )->getArray();
111 }
112
113 public function getSubItemsForTable(?ilMMItemFacadeInterface $parent = null): array
114 {
115 if ($parent !== null) {
116 $r = $this->db->queryF(
117 "SELECT sub_items.*, top_items.position AS parent_position
118FROM il_mm_items AS sub_items
119LEFT JOIN il_mm_items AS top_items ON top_items.identification = sub_items.parent_identification
120WHERE sub_items.parent_identification != '' AND sub_items.parent_identification = %s
121ORDER BY top_items.position, parent_identification, sub_items.position ASC",
122 ['text'],
123 [$parent->identification()->serialize()]
124 );
125 } else {
126 $r = $this->db->query(
127 "SELECT sub_items.*, top_items.position AS parent_position
128FROM il_mm_items AS sub_items
129LEFT JOIN il_mm_items AS top_items ON top_items.identification = sub_items.parent_identification
130WHERE sub_items.parent_identification != ''
131ORDER BY top_items.position, parent_identification, sub_items.position ASC",
132 );
133 }
134 $return = [];
135 while ($data = $this->db->fetchAssoc($r)) {
136 $return[] = $data;
137 }
138
139 return $return;
140 }
141
142 public function flushLostItems(): void
143 {
144 foreach ($this->getTopItems() as $item) {
145 $item_facade = $this->getItemFacade(
146 $this->services->identification()->fromSerializedIdentification($item['identification'])
147 );
148 if (Lost::class === $item_facade->getType()) {
149 $item_facade->delete();
150 }
151 }
152
153 foreach ($this->getSubItemsForTable() as $item) {
154 $item_facade = $this->getItemFacade(
155 $this->services->identification()->fromSerializedIdentification($item['identification'])
156 );
157 if (Lost::class === $item_facade->getType()) {
158 $item_facade->delete();
159 }
160 }
161 }
162
163 public function hasLostItems(): bool
164 {
165 foreach ($this->getTopItems() as $item) {
166 $item_facade = $this->getItemFacade(
167 $this->services->identification()->fromSerializedIdentification($item['identification'])
168 );
169 if (Lost::class === $item_facade->getType()) {
170 return true;
171 }
172 }
173
174 foreach ($this->getSubItemsForTable() as $item) {
175 $item_facade = $this->getItemFacade(
176 $this->services->identification()->fromSerializedIdentification($item['identification'])
177 );
178 if (Lost::class === $item_facade->getType()) {
179 return true;
180 }
181 }
182 return false;
183 }
184
188 public function getItemFacade(?IdentificationInterface $identification = null): ilMMItemFacadeInterface
189 {
190 if ($identification === null || $identification instanceof NullIdentification || $identification instanceof NullPluginIdentification) {
191 return new ilMMNullItemFacade($identification ?: new NullIdentification(), $this->main_collector);
192 }
193 if ($identification->getClassName() === CustomMainBarProvider::class) {
194 return new ilMMCustomItemFacade($identification, $this->main_collector);
195 }
196
197 return new ilMMItemFacade($identification, $this->main_collector);
198 }
199
200 public function getItemFacadesForIdentificationStrings(array $identifications): array
201 {
202 $item_facades = [];
203 foreach ($identifications as $identification) {
204 $id = $this->services->identification()->fromSerializedIdentification($identification);
205 $item_facades[] = $this->getItemFacade($id);
206 }
207
208 return $item_facades;
209 }
210
214 public function getItemFacadeForIdentificationString(string $identification): ilMMItemFacadeInterface
215 {
216 $id = $this->services->identification()->fromSerializedIdentification($identification);
217
218 return $this->getItemFacade($id);
219 }
220
221 public function getPossibleParentsForFormAndTable(): array
222 {
223 static $parents;
224 if ($parents === null) {
225 $parents = [];
226 foreach (array_keys($this->getTopItems()) as $top_item_identification) {
227 $identification = $this->services->identification()->fromSerializedIdentification(
228 $top_item_identification
229 );
230 $item = $this->getSingleItem($identification);
231 if ($item instanceof TopParentItem) {
232 $parents[$top_item_identification] = $this->getItemFacade($identification)
233 ->getDefaultTitle();
234 }
235 }
236 }
237
238 return $parents;
239 }
240
245 {
246 $types = [];
247 foreach ($this->main_collector->getTypeInformationCollection()->getAll() as $information) {
248 if ($information->isCreationPrevented()) {
249 continue;
250 }
251 if ($information->isChild()) {
252 // since these two types are identical (more or less), we truncate one
253 if ($information->getType() === TopLinkItem::class) {
254 continue;
255 }
256 $types[$information->getType()] = $information;
257 }
258 }
259
260 return $types;
261 }
262
266 public function getPossibleTopItemTypesWithInformation(bool $new): array
267 {
268 $types = [];
269 foreach ($this->main_collector->getTypeInformationCollection()->getAll() as $information) {
270 if (!$new || $information->isTop()) {
271 $types[$information->getType()] = $information;
272 }
273 }
274
275 return $types;
276 }
277
281 public function getTypeHandlerForType(string $type): TypeHandler
282 {
283 $item = $this->services->mainBar()->custom($type, new NullIdentification());
284
285 return $this->main_collector->getTypeHandlerForItem($item);
286 }
287
288 public function updateItem(ilMMItemFacadeInterface $item_facade): void
289 {
290 if ($item_facade->isEditable()) {
291 $item_facade->update();
292 $this->clearCache();
293 }
294 }
295
296 public function createItem(ilMMItemFacadeInterface $item_facade): void
297 {
298 $item_facade->create();
299 $this->clearCache();
300 }
301
302 public function deleteItem(ilMMItemFacadeInterface $item_facade): void
303 {
304 if ($item_facade->isDeletable()) {
305 $item_facade->delete();
306 $this->clearCache();
307 }
308 }
309}
$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...
Class ilMMCustomItemFacade.
Class ilMMItemFacade.
getSubItemsForTable(?ilMMItemFacadeInterface $parent=null)
__construct()
ilMMItemRepository constructor.
resolveIdentificationFromString(string $identification_string)
updateItem(ilMMItemFacadeInterface $item_facade)
deleteItem(ilMMItemFacadeInterface $item_facade)
getItemFacadesForIdentificationStrings(array $identifications)
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.
Interface ilDBInterface.
Interface ilMMItemFacadeInterface.
global $DIC
Definition: shib_login.php:26