ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
MainNotificationCollector.php
Go to the documentation of this file.
2
5use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
9
15{
16 use Hasher;
17
21 private $providers = [];
25 private $notifications = [];
26
27
32 public function __construct(array $providers)
33 {
34 $this->providers = $providers;
35 $this->collectOnce();
36 }
37
42 private function returnNotificationsFromProviders() : \Generator
43 {
44 foreach ($this->providers as $provider) {
45 yield $provider->getNotifications();
46 }
47 }
48
49
50 public function collectStructure() : void
51 {
52 $this->notifications = array_merge([], ...iterator_to_array($this->returnNotificationsFromProviders()));
53 }
54
55
56 public function filterItemsByVisibilty(bool $async_only = false) : void
57 {
58 // TODO: Implement filterItemsByVisibilty() method.
59 }
60
61
62 public function prepareItemsForUIRepresentation() : void
63 {
64 // TODO: Implement prepareItemsForUIRepresentation() method.
65 }
66
67 public function cleanupItemsForUIRepresentation() : void
68 {
69 // TODO: Implement cleanupItemsForUIRepresentation() method.
70 }
71
72 public function sortItemsForUIRepresentation() : void
73 {
74 // TODO: Implement sortItemsForUIRepresentation() method.
75 }
76
80 public function getItemsForUIRepresentation() : \Generator
81 {
82 yield from $this->notifications;
83 }
84
88 public function hasItems() : bool
89 {
90 return (is_array($this->notifications) && count($this->notifications) > 0);
91 }
92
98 public function getAmountOfOldNotifications() : int
99 {
100 if (is_array($this->notifications)) {
101 $count = 0;
102 foreach ($this->notifications as $notification) {
103 if ($notification instanceof StandardNotificationGroup) {
104 foreach ($notification->getNotifications() as $notification) {
105 $count += $notification->getOldAmount();
106 }
107 } else {
108 $count += $notification->getOldAmount();
109 }
110 }
111
112 return $count;
113 }
114
115 return 0;
116 }
117
123 public function getAmountOfNewNotifications() : int
124 {
125 if (is_array($this->notifications)) {
126 $count = 0;
127 foreach ($this->notifications as $notification) {
128 if ($notification instanceof StandardNotificationGroup) {
129 foreach ($notification->getNotifications() as $notification) {
130 $count += $notification->getNewAmount();
131 }
132 } else {
133 $count += $notification->getNewAmount();
134 }
135 }
136
137 return $count;
138 }
139
140 return 0;
141 }
142
147 public function getNotifications() : array
148 {
150 }
151
152
157 public function getNotificationsIdentifiersAsArray($hashed = false) : array
158 {
159 $identifiers = [];
160 foreach ($this->notifications as $notification) {
161 if ($notification instanceof StandardNotificationGroup) {
162 foreach ($notification->getNotifications() as $item) {
163 if ($hashed) {
164 $identifiers[] = $this->hash($item->getProviderIdentification()->serialize());
165 } else {
166 $identifiers[] = $item->getProviderIdentification()->serialize();
167 }
168 }
169 }
170 if ($hashed) {
171 $identifiers[] = $this->hash($notification->getProviderIdentification()->serialize());
172 } else {
173 $identifiers[] = $notification->getProviderIdentification()->serialize();
174 }
175 }
176
177 return $identifiers;
178 }
179}
An exception for terminatinating execution or to throw for unit testing.
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.