ILIAS  release_8 Revision v8.24
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 function () use ($item) {
121 return $item->isVisible();
122 }
123 )
124 );
125
126 if ($item instanceof hasTitle && !empty($storage->getDefaultTitle())) {
127 $item = $item->withTitle($storage->getDefaultTitle());
128 }
129 if ($item instanceof hasAction) {
130 $item = $item->withAction("#");
131 }
132 if ($item instanceof isChild) {
133 $mm_item = ilMMItemStorage::find($identification->serialize());
134 $parent_identification = '';
135 if ($mm_item instanceof ilMMItemStorage) {
136 $parent_identification = $mm_item->getParentIdentification();
137 }
138
139 if ($parent_identification) {
140 $item = $item->withParent(
141 $this->globalScreen()
142 ->identification()
143 ->fromSerializedIdentification($parent_identification)
144 );
145 }
146 }
147
148 if ($register) {
150 }
151
152 return $item;
153 }
154
159 {
161 // TopParentItem
162 $c->add(
163 new TypeInformation(
164 TopParentItem::class,
165 $this->translateType(TopParentItem::class),
167 )
168 );
169 // TopLinkItem
170 $c->add(
171 new TypeInformation(
172 TopLinkItem::class,
173 $this->translateType(TopLinkItem::class),
176 )
177 );
178 // Link
179 $c->add(
180 new TypeInformation(
181 Link::class,
182 $this->translateType(Link::class),
185 )
186 );
187
188 // LinkList
189 $link_list = new TypeInformation(
190 LinkList::class,
191 $this->translateType(LinkList::class),
193 );
194 $link_list->setCreationPrevented(true);
195 $c->add($link_list);
196
197 // Separator
198 $c->add(
199 new TypeInformation(
200 Separator::class,
201 $this->translateType(Separator::class),
204 $this->translateByline(Separator::class)
205 )
206 );
207
208 // RepositoryLink
209 $c->add(
210 new TypeInformation(
211 RepositoryLink::class,
212 $this->translateType(RepositoryLink::class),
215 )
216 );
217
218 // Lost
219 $lost = new TypeInformation(
220 Lost::class,
221 $this->translateType(Lost::class),
222 new LostItemRenderer()
223 );
224 $lost->setCreationPrevented(true);
225 $c->add($lost);
226
227 // Complex
228 $complex = new TypeInformation(
229 Complex::class,
230 $this->translateType(Complex::class),
232 );
233 $complex->setCreationPrevented(true);
234 $c->add($complex);
235
236 return $c;
237 }
238
243 private function translateType(string $type): string
244 {
245 $last_part = substr(strrchr($type, "\\"), 1);
246 $last_part = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $last_part));
247
248 return $this->dic->language()->txt("type_" . strtolower($last_part));
249 }
250
255 private function translateByline(string $type): string
256 {
257 $last_part = substr(strrchr($type, "\\"), 1);
258 $last_part = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $last_part));
259
260 return $this->dic->language()->txt("type_" . strtolower($last_part) . "_info");
261 }
262
266 public function getProviderNameForPresentation(): string
267 {
268 return "Custom";
269 }
270}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
static where($where, $operator=null)
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
getSingleCustomItem(ilMMCustomItemStorage $storage, bool $register=false)
__construct(Container $dic, \ilMainMenuAccess $access=null)
@inheritDoc
Class ilMMCustomItemStorage.
Class ilMMItemStorage.
static register(isItem $item)
Class ilMMLinkItemRenderer.
Class ilMMRepositoryLinkItemRenderer.
Class ilMMTopLinkItemRenderer.
Class ilMMTypeHandlerSeparator.
Class ilObjMainMenuAccess.
$c
Definition: cli.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type