ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
CustomMainBarProvider.php
Go to the documentation of this file.
1 <?php namespace ILIAS\MainMenu\Provider;
2 
28 use ilMMItemStorage;
34 
40 {
41 
45  private $access_helper;
49  private $mm_access;
53  protected $dic;
54 
58  public function __construct(Container $dic)
59  {
60  parent::__construct($dic);
61  $this->mm_access = new ilObjMainMenuAccess();
62  $this->access_helper = BasicAccessCheckClosures::getInstance();
63  }
64 
68  public function getStaticTopItems() : array
69  {
73  $top_items = [];
74  foreach (ilMMCustomItemStorage::where(['top_item' => true])->get() as $item) {
75  $top_items[] = $this->getSingleCustomItem($item, true);
76  }
77 
78  return $top_items;
79  }
80 
84  public function getStaticSubItems() : array
85  {
89  $items = [];
90  foreach (ilMMCustomItemStorage::where(['top_item' => false])->get() as $item) {
91  $items[] = $this->getSingleCustomItem($item, true);
92  }
93 
94  return $items;
95  }
96 
102  public function getSingleCustomItem(ilMMCustomItemStorage $storage, $register = false) : isItem
103  {
104  $identification = $this->globalScreen()->identification()->core($this)->identifier($storage->getIdentifier());
105 
106  $item = $this->globalScreen()->mainBar()->custom($storage->getType(), $identification)->withVisibilityCallable(
107  $this->mm_access->isCurrentUserAllowedToSeeCustomItem($storage)
108  );
109 
110  if ($item instanceof hasTitle && !empty($storage->getDefaultTitle())) {
111  $item = $item->withTitle($storage->getDefaultTitle());
112  }
113  if ($item instanceof hasAction) {
114  $item = $item->withAction("#");
115  }
116  if ($item instanceof isChild) {
117  $mm_item = ilMMItemStorage::find($identification->serialize());
118  $parent_identification = '';
119  if ($mm_item instanceof ilMMItemStorage) {
120  $parent_identification = $mm_item->getParentIdentification();
121  }
122 
123  if ($parent_identification) {
124  $item = $item->withParent(
125  $this->globalScreen()
126  ->identification()
127  ->fromSerializedIdentification($parent_identification)
128  );
129  }
130  }
131 
132  if ($register) {
134  }
135 
136  return $item;
137  }
138 
143  {
145  // TopParentItem
146  $c->add(new TypeInformation(
147  TopParentItem::class,
148  $this->translateType(TopParentItem::class),
149  new TopParentItemRenderer())
150  );
151  // TopLinkItem
152  $c->add(new TypeInformation(
153  TopLinkItem::class,
154  $this->translateType(TopLinkItem::class),
157  );
158  // Link
159  $c->add(new TypeInformation(
160  Link::class,
161  $this->translateType(Link::class),
162  new \ilMMLinkItemRenderer(),
163  new ilMMTypeHandlerLink())
164  );
165 
166  // LinkList
167  $link_list = new TypeInformation(
168  LinkList::class,
169  $this->translateType(LinkList::class),
171  );
172  $link_list->setCreationPrevented(true);
173  $c->add($link_list);
174 
175  // Separator
176  $c->add(new TypeInformation(
177  Separator::class,
178  $this->translateType(Separator::class),
179  new SeparatorItemRenderer(),
181  $this->translateByline(Separator::class))
182  );
183 
184  // RepositoryLink
185  $c->add(new TypeInformation(
186  RepositoryLink::class,
187  $this->translateType(RepositoryLink::class),
190  );
191 
192  // Lost
193  $lost = new TypeInformation(
194  Lost::class,
195  $this->translateType(Lost::class),
196  new LostItemRenderer()
197  );
198  $lost->setCreationPrevented(true);
199  $c->add($lost);
200 
201  // Complex
202  $complex = new TypeInformation(
203  Complex::class,
204  $this->translateType(Complex::class),
205  new ComplexItemRenderer()
206  );
207  $complex->setCreationPrevented(true);
208  $c->add($complex);
209 
210  return $c;
211  }
212 
217  private function translateType(string $type) : string
218  {
219  $last_part = substr(strrchr($type, "\\"), 1);
220  $last_part = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $last_part));
221 
222  return $this->dic->language()->txt("type_" . strtolower($last_part));
223  }
224 
229  private function translateByline(string $type) : string
230  {
231  $last_part = substr(strrchr($type, "\\"), 1);
232  $last_part = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $last_part));
233 
234  return $this->dic->language()->txt("type_" . strtolower($last_part) . "_info");
235  }
236 
240  public function getProviderNameForPresentation() : string
241  {
242  return "Custom";
243  }
244 }
static find($primary_key, array $add_constructor_args=array())
$type
static where($where, $operator=null)
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:17
Class ilMMLinkItemRenderer.
static register(isItem $item)
Class ilMMRepositoryLinkItemRenderer.
Class ilMMTopLinkItemRenderer.
getSingleCustomItem(ilMMCustomItemStorage $storage, $register=false)
__construct(Container $dic, ilPlugin $plugin)