ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
MainNotificationCollector.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 use Iterator;
31 use Generator;
32 
38 {
39  use Hasher;
43  private array $notifications = [];
47  private array $administrative_notifications = [];
48 
53  public function __construct(private array $providers)
54  {
55  $this->collectOnce();
56  }
57 
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 
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 
131  public function getAmountOfOldNotifications(): int
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 
158  public function getAmountOfNewNotifications(): int
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  {
186  return $this->notifications;
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.
$provider
Definition: ltitoken.php:80
__construct(private array $providers)
MetaBarMainCollector constructor.
Class StandardNotificationGroup Groups a set of Notification.
returnNotificationsFromProviders()
Generator yielding the Notifications from the set of providers.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...