ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MainNotificationCollector.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
30use Iterator;
31use Generator;
32
38{
39 use Hasher;
43 private array $notifications = [];
48
53 public function __construct(private array $providers)
54 {
55 $this->collectOnce();
56 }
57
62 private function returnNotificationsFromProviders(): Iterator
63 {
64 foreach ($this->providers as $provider) {
65 yield $provider->getNotifications();
66 }
67 }
68
73 {
74 foreach ($this->providers as $provider) {
75 yield $provider->getAdministrativeNotifications();
76 }
77 }
78
79 public function collectStructure(): void
80 {
81 $this->notifications = array_merge([], ...iterator_to_array($this->returnNotificationsFromProviders()));
82 $this->administrative_notifications = array_merge([], ...iterator_to_array($this->returnAdministrativeNotificationsFromProviders()));
83 }
84
85 public function filterItemsByVisibilty(bool $async_only = false): void
86 {
87 $this->administrative_notifications = array_filter($this->administrative_notifications, static fn(AdministrativeNotification $n): bool => $n->isVisible());
88 }
89
90 public function prepareItemsForUIRepresentation(): void
91 {
92 // TODO: Implement prepareItemsForUIRepresentation() method.
93 }
94
95 public function cleanupItemsForUIRepresentation(): void
96 {
97 // TODO: Implement cleanupItemsForUIRepresentation() method.
98 }
99
100 public function sortItemsForUIRepresentation(): void
101 {
102 // TODO: Implement sortItemsForUIRepresentation() method.
103 }
104
108 public function getItemsForUIRepresentation(): Generator
109 {
111 }
112
113
114 public function hasItems(): bool
115 {
116 return (is_array($this->notifications) && $this->notifications !== []);
117 }
118
119
120 public function hasVisibleItems(): bool
121 {
122 return $this->hasItems();
123 }
124
125
132 {
133 if (is_array($this->notifications)) {
134 $count = 0;
135 foreach ($this->notifications as $notification) {
136 if ($notification instanceof StandardNotificationGroup) {
137 foreach ($notification->getNotifications() as $s_notification) {
138 if ($s_notification->getOldAmount() > 0) {
139 $count++;
140 }
141 }
142 } elseif ($notification->getOldAmount() > 0) {
143 $count++;
144 }
145 }
146
147 return $count;
148 }
149
150 return 0;
151 }
152
159 {
160 if (is_array($this->notifications)) {
161 $count = 0;
162 foreach ($this->notifications as $notification) {
163 if ($notification instanceof StandardNotificationGroup) {
164 foreach ($notification->getNotifications() as $s_notification) {
165 if ($s_notification->getNewAmount() > 0) {
166 $count++;
167 }
168 }
169 } elseif ($notification->getNewAmount() > 0) {
170 $count++;
171 }
172 }
173
174 return $count;
175 }
176
177 return 0;
178 }
179
184 public function getNotifications(): array
185 {
187 }
188
192 public function getAdministrativeNotifications(): array
193 {
195 }
196
200 public function getNotificationsIdentifiersAsArray(bool $hashed = false): array
201 {
202 $identifiers = [];
203 foreach ($this->notifications as $notification) {
204 if ($notification instanceof StandardNotificationGroup) {
205 foreach ($notification->getNotifications() as $item) {
206 if ($hashed) {
207 $identifiers[] = $this->hash($item->getProviderIdentification()->serialize());
208 } else {
209 $identifiers[] = $item->getProviderIdentification()->serialize();
210 }
211 }
212 }
213 if ($hashed) {
214 $identifiers[] = $this->hash($notification->getProviderIdentification()->serialize());
215 } else {
216 $identifiers[] = $notification->getProviderIdentification()->serialize();
217 }
218 }
219
220 return $identifiers;
221 }
222}
collectOnce()
Runs the Collection of all items from the providers.
getAmountOfOldNotifications()
Returns the sum of all old notifications values in the Standard Notifications.
getAmountOfNewNotifications()
Returns the sum of all new notifications values in the Standard Notifications.
returnNotificationsFromProviders()
Generator yielding the Notifications from the set of providers.
__construct(private array $providers)
MetaBarMainCollector constructor.
Class StandardNotificationGroup Groups a set of Notification.
$provider
Definition: ltitoken.php:80