ILIAS  release_7 Revision v7.30-3-g800a261c036
CustomMainBarProvider.php
Go to the documentation of this file.
1<?php
18
50
56{
57
65 private $mm_access;
69 protected $dic;
70
74 public function __construct(Container $dic)
75 {
77 $this->mm_access = new ilObjMainMenuAccess();
78 $this->access_helper = BasicAccessCheckClosures::getInstance();
79 }
80
84 public function getStaticTopItems() : array
85 {
89 $top_items = [];
90 foreach (ilMMCustomItemStorage::where(['top_item' => true])->get() as $item) {
91 $top_items[] = $this->getSingleCustomItem($item, true);
92 }
93
94 return $top_items;
95 }
96
100 public function getStaticSubItems() : array
101 {
105 $items = [];
106 foreach (ilMMCustomItemStorage::where(['top_item' => false])->get() as $item) {
107 $items[] = $this->getSingleCustomItem($item, true);
108 }
109
110 return $items;
111 }
112
118 public function getSingleCustomItem(ilMMCustomItemStorage $storage, $register = false) : isItem
119 {
120 $identification = $this->globalScreen()->identification()->core($this)->identifier($storage->getIdentifier());
121
122 $item = $this->globalScreen()->mainBar()->custom($storage->getType(), $identification);
123
124 $item = $item->withVisibilityCallable(
125 $this->mm_access->isCurrentUserAllowedToSeeCustomItem(
126 $storage,
127 function () use ($item) {
128 return $item->isVisible();
129 }
130 )
131 );
132
133 if ($item instanceof hasTitle && !empty($storage->getDefaultTitle())) {
134 $item = $item->withTitle($storage->getDefaultTitle());
135 }
136 if ($item instanceof hasAction) {
137 $item = $item->withAction("#");
138 }
139 if ($item instanceof isChild) {
140 $mm_item = ilMMItemStorage::find($identification->serialize());
141 $parent_identification = '';
142 if ($mm_item instanceof ilMMItemStorage) {
143 $parent_identification = $mm_item->getParentIdentification();
144 }
145
146 if ($parent_identification) {
147 $item = $item->withParent(
148 $this->globalScreen()
149 ->identification()
150 ->fromSerializedIdentification($parent_identification)
151 );
152 }
153 }
154
155 if ($register) {
157 }
158
159 return $item;
160 }
161
166 {
168 // TopParentItem
169 $c->add(
170 new TypeInformation(
171 TopParentItem::class,
172 $this->translateType(TopParentItem::class),
174 )
175 );
176 // TopLinkItem
177 $c->add(
178 new TypeInformation(
179 TopLinkItem::class,
180 $this->translateType(TopLinkItem::class),
183 )
184 );
185 // Link
186 $c->add(
187 new TypeInformation(
188 Link::class,
189 $this->translateType(Link::class),
192 )
193 );
194
195 // LinkList
196 $link_list = new TypeInformation(
197 LinkList::class,
198 $this->translateType(LinkList::class),
200 );
201 $link_list->setCreationPrevented(true);
202 $c->add($link_list);
203
204 // Separator
205 $c->add(
206 new TypeInformation(
207 Separator::class,
208 $this->translateType(Separator::class),
211 $this->translateByline(Separator::class)
212 )
213 );
214
215 // RepositoryLink
216 $c->add(
217 new TypeInformation(
218 RepositoryLink::class,
219 $this->translateType(RepositoryLink::class),
222 )
223 );
224
225 // Lost
226 $lost = new TypeInformation(
227 Lost::class,
228 $this->translateType(Lost::class),
229 new LostItemRenderer()
230 );
231 $lost->setCreationPrevented(true);
232 $c->add($lost);
233
234 // Complex
235 $complex = new TypeInformation(
236 Complex::class,
237 $this->translateType(Complex::class),
239 );
240 $complex->setCreationPrevented(true);
241 $c->add($complex);
242
243 return $c;
244 }
245
250 private function translateType(string $type) : string
251 {
252 $last_part = substr(strrchr($type, "\\"), 1);
253 $last_part = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $last_part));
254
255 return $this->dic->language()->txt("type_" . strtolower($last_part));
256 }
257
262 private function translateByline(string $type) : string
263 {
264 $last_part = substr(strrchr($type, "\\"), 1);
265 $last_part = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $last_part));
266
267 return $this->dic->language()->txt("type_" . strtolower($last_part) . "_info");
268 }
269
273 public function getProviderNameForPresentation() : string
274 {
275 return "Custom";
276 }
277}
static where($where, $operator=null)
An exception for terminatinating execution or to throw for unit testing.
static find($primary_key, array $add_constructor_args=array())
@inheritDoc
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:19
getSingleCustomItem(ilMMCustomItemStorage $storage, $register=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilMMItemStorage.
static register(isItem $item)
Class ilMMLinkItemRenderer.
Class ilMMRepositoryLinkItemRenderer.
Class ilMMTopLinkItemRenderer.
Class ilMMTypeHandlerSeparator.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: cli.php:37
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type