ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
MainNotificationCollector.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
21 
29 use Iterator;
30 use Generator;
31 
37 {
38  use Hasher;
39 
43  private $providers;
47  private $notifications = [];
52 
57  public function __construct(array $providers)
58  {
59  $this->providers = $providers;
60  $this->collectOnce();
61  }
62 
68  {
69  foreach ($this->providers as $provider) {
70  yield $provider->getNotifications();
71  }
72  }
73 
78  {
79  foreach ($this->providers as $provider) {
80  yield $provider->getAdministrativeNotifications();
81  }
82  }
83 
84  public function collectStructure() : void
85  {
86  $this->notifications = array_merge([], ...iterator_to_array($this->returnNotificationsFromProviders()));
87  $this->administrative_notifications = array_merge([], ...iterator_to_array($this->returnAdministrativeNotificationsFromProviders()));
88  }
89 
90  public function filterItemsByVisibilty(bool $async_only = false) : void
91  {
92  $this->administrative_notifications = array_filter($this->administrative_notifications, static function (AdministrativeNotification $n) : bool {
93  return $n->isVisible();
94  });
95  }
96 
97  public function prepareItemsForUIRepresentation() : void
98  {
99  // TODO: Implement prepareItemsForUIRepresentation() method.
100  }
101 
102  public function cleanupItemsForUIRepresentation() : void
103  {
104  // TODO: Implement cleanupItemsForUIRepresentation() method.
105  }
106 
107  public function sortItemsForUIRepresentation() : void
108  {
109  // TODO: Implement sortItemsForUIRepresentation() method.
110  }
111 
116  {
117  yield from $this->notifications;
118  }
119 
120 
121  public function hasItems() : bool
122  {
123  return (is_array($this->notifications) && count($this->notifications) > 0);
124  }
125 
126 
127  public function hasVisibleItems() : bool
128  {
129  return $this->hasItems();
130  }
131 
132 
138  public function getAmountOfOldNotifications() : int
139  {
140  if (is_array($this->notifications)) {
141  $count = 0;
142  foreach ($this->notifications as $notification) {
143  if ($notification instanceof StandardNotificationGroup) {
144  foreach ($notification->getNotifications() as $s_notification) {
145  if ($s_notification->getOldAmount() > 0) {
146  $count++;
147  }
148  }
149  } else {
150  if ($notification->getOldAmount() > 0) {
151  $count++;
152  }
153  }
154  }
155 
156  return $count;
157  }
158 
159  return 0;
160  }
161 
167  public function getAmountOfNewNotifications() : int
168  {
169  if (is_array($this->notifications)) {
170  $count = 0;
171  foreach ($this->notifications as $notification) {
172  if ($notification instanceof StandardNotificationGroup) {
173  foreach ($notification->getNotifications() as $s_notification) {
174  if ($s_notification->getNewAmount() > 0) {
175  $count++;
176  }
177  }
178  } else {
179  if ($notification->getNewAmount() > 0) {
180  $count++;
181  }
182  }
183  }
184 
185  return $count;
186  }
187 
188  return 0;
189  }
190 
195  public function getNotifications() : array
196  {
197  return $this->notifications;
198  }
199 
203  public function getAdministrativeNotifications() : array
204  {
206  }
207 
211  public function getNotificationsIdentifiersAsArray(bool $hashed = false) : array
212  {
213  $identifiers = [];
214  foreach ($this->notifications as $notification) {
215  if ($notification instanceof StandardNotificationGroup) {
216  foreach ($notification->getNotifications() as $item) {
217  if ($hashed) {
218  $identifiers[] = $this->hash($item->getProviderIdentification()->serialize());
219  } else {
220  $identifiers[] = $item->getProviderIdentification()->serialize();
221  }
222  }
223  }
224  if ($hashed) {
225  $identifiers[] = $this->hash($notification->getProviderIdentification()->serialize());
226  } else {
227  $identifiers[] = $notification->getProviderIdentification()->serialize();
228  }
229  }
230 
231  return $identifiers;
232  }
233 }
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.
Class StandardNotificationGroup Groups a set of Notification.
returnNotificationsFromProviders()
Generator yielding the Notifications from the set of providers.
$n
Definition: RandomTest.php:85