ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMMCustomProvider.php
Go to the documentation of this file.
1 <?php
2 
18 
25 {
26 
30  protected $dic;
31 
32 
36  public function getStaticTopItems() : array
37  {
41  $top_items = [];
42  foreach (ilMMCustomItemStorage::where(['top_item' => true])->get() as $item) {
43  $top_items[] = $this->getSingleCustomItem($item, false);
44  }
45 
46  return $top_items;
47  }
48 
49 
53  public function getStaticSubItems() : array
54  {
58  $items = [];
59  foreach (ilMMCustomItemStorage::where(['top_item' => false])->get() as $item) {
60  $items[] = $this->getSingleCustomItem($item, false);
61  }
62 
63  return $items;
64  }
65 
66 
73  public function getSingleCustomItem(ilMMCustomItemStorage $storage, $register = false) : \ILIAS\GlobalScreen\Scope\MainMenu\Factory\isItem
74  {
75  $identification = $this->globalScreen()->identification()->core($this)->identifier($storage->getIdentifier());
76 
77  if ($register) {
79  }
80 
81  $item = $this->globalScreen()->mainmenu()->custom($storage->getType(), $identification);
82 
83  if ($item instanceof hasTitle && $storage->getDefaultTitle() !== '') {
84  $item = $item->withTitle($storage->getDefaultTitle());
85  }
86  if ($item instanceof hasAction) {
87  $item = $item->withAction("#");
88  }
89  if ($item instanceof isChild) {
90  $mm_item = ilMMItemStorage::find($identification->serialize());
91  $parent_identification = "";
92  if ($mm_item instanceof ilMMItemStorage) {
93  $parent_identification = $mm_item->getParentIdentification();
94  }
95 
96  if ($parent_identification) {
97  $item = $item->withParent(
98  $this->globalScreen()
99  ->identification()
100  ->fromSerializedIdentification($parent_identification)
101  );
102  }
103  }
104 
105  if ($register) {
107  }
108 
109  return $item;
110  }
111 
112 
117  {
119  $c->add(new TypeInformation(TopParentItem::class, $this->translateType(TopParentItem::class), new ilMMTopParentItemRenderer()));
120  $c->add(new TypeInformation(TopLinkItem::class, $this->translateType(TopLinkItem::class), new ilMMTopLinkItemRenderer(), new ilMMTypeHandlerTopLink()));
121  $c->add(new TypeInformation(Link::class, $this->translateType(Link::class), null, new ilMMTypeHandlerLink()));
122  $link_list = new TypeInformation(LinkList::class, $this->translateType(LinkList::class));
123  $link_list->setCreationPrevented(true);
124  $c->add($link_list);
125  $c->add(new TypeInformation(Separator::class, $this->translateType(Separator::class), null, new ilMMTypeHandlerSeparator(), $this->translateByline(Separator::class)));
126  $c->add(new TypeInformation(RepositoryLink::class, $this->translateType(RepositoryLink::class), null, new ilMMTypeHandlerRepositoryLink()));
127  $complex = new TypeInformation(Complex::class, $this->translateType(Complex::class));
128  $complex->setCreationPrevented(true);
129  $c->add($complex);
130  $lost = new TypeInformation(Lost::class, $this->translateType(Lost::class), new ilMMLostItemRenderer());
131  $lost->setCreationPrevented(true);
132  $c->add($lost);
133 
134  return $c;
135  }
136 
137 
143  private function translateType(string $type) : string
144  {
145  $last_part = substr(strrchr($type, "\\"), 1);
146  $last_part = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $last_part));
147 
148  return $this->dic->language()->txt("type_" . strtolower($last_part));
149  }
150 
151 
157  private function translateByline(string $type) : string
158  {
159  $last_part = substr(strrchr($type, "\\"), 1);
160  $last_part = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $last_part));
161 
162  return $this->dic->language()->txt("type_" . strtolower($last_part) . "_info");
163  }
164 }
Class ilMMTypeHandlerSeparator.
static find($primary_key, array $add_constructor_args=array())
Class ilMMCustomItemStorage.
Class ilMMCustomProvider.
$type
Class BaseForm.
static where($where, $operator=null)
static register(isItem $item)
getSingleCustomItem(ilMMCustomItemStorage $storage, $register=false)
Class ilMMItemStorage.
Class ilMMTopLinkItemRenderer.
static registerIdentification(\ILIAS\GlobalScreen\Identification\IdentificationInterface $identification, \ILIAS\GlobalScreen\Provider\Provider $provider)
Class ilMMTopParentItemRenderer.
Class ilMMLostItemRenderer.