ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
CustomMainBarProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
55
61{
62 private \ilMainMenuAccess $mm_access;
63 protected Container $dic;
64
68 public function __construct(Container $dic, ?\ilMainMenuAccess $access = null)
69 {
71 $this->mm_access = $access ?? new ilObjMainMenuAccess();
72 }
73
77 public function getStaticTopItems(): array
78 {
82 $top_items = [];
83 foreach (ilMMCustomItemStorage::where(['top_item' => true])->get() as $item) {
84 $top_items[] = $this->getSingleCustomItem($item, true);
85 }
86
87 return $top_items;
88 }
89
93 public function getStaticSubItems(): array
94 {
98 $items = [];
99 foreach (ilMMCustomItemStorage::where(['top_item' => false])->get() as $item) {
100 $items[] = $this->getSingleCustomItem($item, true);
101 }
102
103 return $items;
104 }
105
111 public function getSingleCustomItem(ilMMCustomItemStorage $storage, bool $register = false): isItem
112 {
113 $identification = $this->globalScreen()->identification()->core($this)->identifier($storage->getIdentifier());
114
115 $item = $this->globalScreen()->mainBar()->custom($storage->getType(), $identification);
116
117 $item = $item->withVisibilityCallable(
118 $this->mm_access->isCurrentUserAllowedToSeeCustomItem(
119 $storage,
120 fn(): bool => $item->isVisible()
121 )
122 );
123
124 if ($item instanceof hasTitle && !empty($storage->getDefaultTitle())) {
125 $item = $item->withTitle($storage->getDefaultTitle());
126 }
127 if ($item instanceof hasAction) {
128 $item = $item->withAction("#");
129 }
130 if ($item instanceof isChild) {
131 $mm_item = ilMMItemStorage::find($identification->serialize());
132 $parent_identification = '';
133 if ($mm_item instanceof ilMMItemStorage) {
134 $parent_identification = $mm_item->getParentIdentification();
135 }
136
137 if ($parent_identification !== '' && $parent_identification !== '0') {
138 $item = $item->withParent(
139 $this->globalScreen()
140 ->identification()
141 ->fromSerializedIdentification($parent_identification)
142 );
143 }
144 }
145
146 if ($register) {
148 }
149
150 return $item;
151 }
152
156 #[\Override]
158 {
160 // TopParentItem
161 $c->add(
162 new TypeInformation(
163 TopParentItem::class,
164 $this->translateType(TopParentItem::class),
166 )
167 );
168 // TopLinkItem
169 $c->add(
170 new TypeInformation(
171 TopLinkItem::class,
172 $this->translateType(TopLinkItem::class),
175 )
176 );
177 // Link
178 $c->add(
179 new TypeInformation(
180 Link::class,
181 $this->translateType(Link::class),
184 )
185 );
186
187 // LinkList
188 $link_list = new TypeInformation(
189 LinkList::class,
190 $this->translateType(LinkList::class),
192 );
193 $link_list->setCreationPrevented(true);
194 $c->add($link_list);
195
196 // Separator
197 $c->add(
198 new TypeInformation(
199 Separator::class,
200 $this->translateType(Separator::class),
203 $this->translateByline(Separator::class)
204 )
205 );
206
207 // RepositoryLink
208 $c->add(
209 new TypeInformation(
210 RepositoryLink::class,
211 $this->translateType(RepositoryLink::class),
214 )
215 );
216
217 // Lost
218 $lost = new TypeInformation(
219 Lost::class,
220 $this->translateType(Lost::class),
221 new LostItemRenderer()
222 );
223 $lost->setCreationPrevented(true);
224 $c->add($lost);
225
226 // Complex
227 $complex = new TypeInformation(
228 Complex::class,
229 $this->translateType(Complex::class),
231 );
232 $complex->setCreationPrevented(true);
233 $c->add($complex);
234
235 return $c;
236 }
237
242 private function translateType(string $type): string
243 {
244 $last_part = substr(strrchr($type, "\\"), 1);
245 $last_part = strtolower((string) preg_replace('/(?<!^)[A-Z]/', '_$0', $last_part));
246
247 return $this->dic->language()->txt("type_" . strtolower($last_part));
248 }
249
254 private function translateByline(string $type): string
255 {
256 $last_part = substr(strrchr($type, "\\"), 1);
257 $last_part = strtolower((string) preg_replace('/(?<!^)[A-Z]/', '_$0', $last_part));
258
259 return $this->dic->language()->txt("type_" . strtolower($last_part) . "_info");
260 }
261
265 #[\Override]
266 public function getProviderNameForPresentation(): string
267 {
268 return "Custom";
269 }
270}
static where($where, $operator=null)
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
__construct(Container $dic, ?\ilMainMenuAccess $access=null)
@inheritDoc
getSingleCustomItem(ilMMCustomItemStorage $storage, bool $register=false)
Class ilMMCustomItemStorage.
Class ilMMItemStorage.
static register(isItem $item)
Class ilMMLinkItemRenderer.
Class ilMMRepositoryLinkItemRenderer.
Class ilMMTopLinkItemRenderer.
Class ilMMTypeHandlerSeparator.
Class ilObjMainMenuAccess.
$c
Definition: deliver.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc