ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMMItemRepository.php
Go to the documentation of this file.
1 <?php
2 
14 
21 {
22 
26  private $services;
30  private $synced = false;
34  private $storage;
38  private $main_collector;
39 
40 
46  public function __construct()
47  {
48  global $DIC;
49  $this->storage = new CoreStorageFacade();
50  $this->main_collector = $DIC->globalScreen()->collector()->mainmenu();
51  $this->services = $DIC->globalScreen();
52 
53  foreach ($this->main_collector->getStackedTopItemsForPresentation() as $top_item) {
54  ilMMItemStorage::register($top_item);
55  if ($top_item instanceof isParent) {
56  foreach ($top_item->getChildren() as $child) {
58  }
59  }
60  }
61  $this->sync();
62  }
63 
64 
65  private function sync() : bool
66  {
67  if ($this->synced === false || $this->synced === null) {
69  foreach ($provider->getAllIdentifications() as $identification) {
70  ilGSIdentificationStorage::registerIdentification($identification, $provider);
71  }
72  }
73 
74  $this->storage->db()->manipulate(
75  "DELETE FROM il_mm_items
76  WHERE EXISTS (SELECT null FROM il_gs_identifications
77  WHERE il_gs_identifications.identification = il_mm_items.identification
78  AND il_gs_identifications.identification IS NULL)"
79  );
80  $this->synced = true;
81  }
82 
83  return $this->synced;
84  }
85 
86 
92  public function getEmptyItemForTypeString(string $class_name) : isItem
93  {
94  return $this->services->mainmenu()->custom($class_name, new NullIdentification());
95  }
96 
97 
98  public function clearCache()
99  {
100  $this->storage->cache()->flush();
101  }
102 
103 
108  public function getStackedTopItemsForPresentation() : array
109  {
110  $top_items = $this->main_collector->getStackedTopItemsForPresentation();
111 
112  return $top_items;
113  }
114 
115 
122  public function getSingleItem(IdentificationInterface $identification) : isItem
123  {
124  return $this->main_collector->getSingleItem($identification);
125  }
126 
127 
131  public function repository() : ilMMItemRepository
132  {
133  return $this;
134  }
135 
136 
141  public function getTopItems() : array
142  {
143  return ilMMItemStorage::where(" parent_identification = '' OR parent_identification IS NULL ")->orderBy('position')->getArray();
144  }
145 
146 
150  public function getSubItemsForTable() : array
151  {
152  $r = $this->storage->db()->query(
153  "SELECT sub_items.*, top_items.position AS parent_position
154 FROM il_mm_items AS sub_items
155 LEFT JOIN il_mm_items AS top_items ON top_items.identification = sub_items.parent_identification
156 WHERE sub_items.parent_identification != '' ORDER BY top_items.position, parent_identification, sub_items.position ASC"
157  );
158  $return = [];
159  while ($data = $this->storage->db()->fetchAssoc($r)) {
160  $return[] = $data;
161  }
162 
163  return $return;
164  }
165 
166  public function flushLostItems()
167  {
168  foreach ($this->getTopItems() as $item) {
169  $item_facade = $this->getItemFacade($this->services->identification()->fromSerializedIdentification($item['identification']));
170  if (Lost::class === $item_facade->getType()) {
171  $item_facade->delete();
172  }
173  }
174 
175  foreach ($this->getSubItemsForTable() as $item) {
176  $item_facade = $this->getItemFacade($this->services->identification()->fromSerializedIdentification($item['identification']));
177  if (Lost::class === $item_facade->getType()) {
178  $item_facade->delete();
179  }
180  }
181  }
182 
183  public function hasLostItems() : bool
184  {
185  foreach ($this->getTopItems() as $item) {
186  $item_facade = $this->getItemFacade($this->services->identification()->fromSerializedIdentification($item['identification']));
187  if (Lost::class === $item_facade->getType()) {
188  return true;
189  }
190  }
191 
192  foreach ($this->getSubItemsForTable() as $item) {
193  $item_facade = $this->getItemFacade($this->services->identification()->fromSerializedIdentification($item['identification']));
194  if (Lost::class === $item_facade->getType()) {
195  return true;
196  }
197  }
198  return false;
199  }
200 
201 
208  public function getItemFacade(IdentificationInterface $identification = null) : ilMMItemFacadeInterface
209  {
210  if ($identification === null || $identification instanceof NullIdentification || $identification instanceof NullPluginIdentification) {
211  return new ilMMNullItemFacade($identification ? $identification : new NullIdentification(), $this->main_collector);
212  }
213  if ($identification->getClassName() === ilMMCustomProvider::class) {
214  return new ilMMCustomItemFacade($identification, $this->main_collector);
215  }
216 
217  return new ilMMItemFacade($identification, $this->main_collector);
218  }
219 
220 
227  public function getItemFacadeForIdentificationString(string $identification) : ilMMItemFacadeInterface
228  {
229  $id = $this->services->identification()->fromSerializedIdentification($identification);
230 
231  return $this->getItemFacade($id);
232  }
233 
234 
235  public function getPossibleParentsForFormAndTable() : array
236  {
237  static $parents;
238  if (is_null($parents)) {
239  $parents = [];
240  foreach ($this->getTopItems() as $top_item_identification => $data) {
241  $identification = $this->services->identification()->fromSerializedIdentification($top_item_identification);
242  $item = $this->getSingleItem($identification);
243  if ($item instanceof TopParentItem) {
244  $parents[$top_item_identification] = $this->getItemFacade($identification)
245  ->getDefaultTitle();
246  }
247  }
248  }
249 
250  return $parents;
251  }
252 
253 
260  public function getPossibleSubItemTypesForForm() : array
261  {
262  $types = [];
263  foreach ($this->main_collector->getTypeInformationCollection()->getAll() as $information) {
264  if ($information->isCreationPrevented()) {
265  continue;
266  }
267  if ($information->isChild()) {
268  $types[$information->getType()] = $information->getTypeNameForPresentation();
269  }
270  }
271 
272  return $types;
273  }
274 
275 
279  public function getPossibleSubItemTypesWithInformation() : array
280  {
281  $types = [];
282  foreach ($this->main_collector->getTypeInformationCollection()->getAll() as $information) {
283  if ($information->isCreationPrevented()) {
284  continue;
285  }
286  if ($information->isChild()) {
287  $types[$information->getType()] = $information;
288  }
289  }
290 
291  return $types;
292  }
293 
294 
300  public function getPossibleTopItemTypesForForm() : array
301  {
302  $types = [];
303  foreach ($this->main_collector->getTypeInformationCollection()->getAll() as $information) {
304  if ($information->isTop()) {
305  $types[$information->getType()] = $information->getTypeNameForPresentation();
306  }
307  }
308 
309  return $types;
310  }
311 
312 
316  public function getPossibleTopItemTypesWithInformation() : array
317  {
318  $types = [];
319  foreach ($this->main_collector->getTypeInformationCollection()->getAll() as $information) {
320  if ($information->isTop()) {
321  $types[$information->getType()] = $information;
322  }
323  }
324 
325  return $types;
326  }
327 
328 
336  public function getTypeHandlerForType(string $type) : TypeHandler
337  {
338  $item = $this->services->mainmenu()->custom($type, new NullIdentification());
339 
340  return $this->main_collector->getHandlerForItem($item);
341  }
342 
343 
347  public function updateItem(ilMMItemFacadeInterface $item_facade)
348  {
349  if ($item_facade->isEditable()) {
350  $item_facade->update();
351  $this->storage->cache()->flush();
352  }
353  }
354 
355 
359  public function createItem(ilMMItemFacadeInterface $item_facade)
360  {
361  $item_facade->create();
362  $this->storage->cache()->flush();
363  }
364 
365 
369  public function deleteItem(ilMMItemFacadeInterface $item_facade)
370  {
371  if ($item_facade->isDeletable()) {
372  $item_facade->delete();
373  $this->storage->cache()->flush();
374  }
375  }
376 }
getItemFacadeForIdentificationString(string $identification)
getEmptyItemForTypeString(string $class_name)
deleteItem(ilMMItemFacadeInterface $item_facade)
static getAllGlobalScreenProviders()
Class ilMMNullItemFacade.
$type
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
static where($where, $operator=null)
Class ilMMItemRepository.
Class ilMMItemFacade.
updateItem(ilMMItemFacadeInterface $item_facade)
$r
Definition: example_031.php:79
static register(isItem $item)
__construct()
ilMMItemRepository constructor.
static registerIdentification(\ILIAS\GlobalScreen\Identification\IdentificationInterface $identification, \ILIAS\GlobalScreen\Provider\Provider $provider)
Class ilMMCustomItemFacade.
createItem(ilMMItemFacadeInterface $item_facade)
getItemFacade(IdentificationInterface $identification=null)
Interface ilMMItemFacadeInterface.
getSingleItem(IdentificationInterface $identification)
$data
Definition: bench.php:6