ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
FooterMainCollector.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 use Generator;
34 
39 {
40  private readonly Map $map;
41 
42  public function __construct(
43  private readonly array $providers,
44  private readonly ItemInformation $item_information
45  ) {
46  $this->map = new Map();
47  }
48 
52  private function getProvidersFromList(): Generator
53  {
54  yield from $this->providers;
55  }
56 
57  public function collectStructure(): void
58  {
59  foreach ($this->getProvidersFromList() as $provider) {
60  $this->map->addMultiple(...$provider->getGroups());
61  $this->map->addMultiple(...$provider->getEntries());
62  $this->map->addMultiple(...$provider->getAdditionalTexts());
63  if (($permanent = $provider->getPermanentURI()) !== null) {
64  $this->map->add($permanent);
65  }
66  }
67  }
68 
69  public function filterItemsByVisibilty(bool $async_only = false): void
70  {
71  // apply filter
72  $this->map->filter(fn(isItem $item): bool => $item->isAvailable() && $item->isVisible());
73  }
74 
75  public function prepareItemsForUIRepresentation(): void
76  {
77  $this->map->filter(fn(isItem $item): bool => $this->item_information->isItemActive($item));
78 
79  $this->map->walk(function (isItem &$item): isItem {
80  if ($item instanceof hasTitle) {
81  $item = $this->item_information->customTranslationForUser($item);
82  }
83 
84  $item = $this->item_information->customPosition($item);
85 
86  return $item;
87  });
88 
89  // Override parent from configuration
90  $this->map->walk(function (isItem $item): isItem {
91  if ($item instanceof canHaveParent && $item->hasParent()) {
92  $parent_id = $this->item_information->getParent($item);
93 
94  $parent = $this->map->getSingleItemFromFilter($parent_id); // $item->getParentIdentification()
95 
96  if ($parent instanceof isGroup) {
97  $parent->addEntry($item);
98  $this->map->add($parent);
99  }
100  }
101 
102  return $item;
103  });
104  }
105 
106  public function sortItemsForUIRepresentation(): void
107  {
108  $this->map->sort();
109  }
110 
111  public function cleanupItemsForUIRepresentation(): void
112  {
113  // remove empty groups
114  $this->map->filter(function (isItem $item): bool {
115  if (!$item instanceof isGroup) {
116  return true;
117  }
118 
119  return $item->getEntries() !== [];
120  });
121  }
122 
124  {
125  foreach ($this->map->getAllFromFilter() as $item) {
126  yield $item;
127  }
128  }
129 
130  public function getRawItems(): Generator
131  {
132  yield from $this->map->getAllFromFilter();
133  }
134 
135  public function getRawUnfilteredItems(): Generator
136  {
137  yield from $this->map->getAllFromRaw();
138  }
139 
140  public function hasItems(): bool
141  {
142  return $this->map->has();
143  }
144 
145  public function hasVisibleItems(): bool
146  {
147  if (!$this->hasItems()) {
148  return false;
149  }
150  foreach ($this->getItemsForUIRepresentation() as $item) {
151  return $item instanceof isItem;
152  }
153  return false;
154  }
155 
159  public function getSingleItemFromFilter(IdentificationInterface $identification): isItem
160  {
161  return $this->map->getSingleItemFromFilter($identification);
162  }
163 
167  public function getSingleItemFromRaw(IdentificationInterface $identification): isItem
168  {
169  return $this->map->getSingleItemFromRaw($identification);
170  }
171 
172 }
getSingleItemFromFilter(IdentificationInterface $identification)
__construct(private readonly array $providers, private readonly ItemInformation $item_information)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$provider
Definition: ltitoken.php:80
getSingleItemFromRaw(IdentificationInterface $identification)