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