ILIAS  release_8 Revision v8.24
ILIAS\GlobalScreen\Client\Notifications Class Reference
+ Collaboration diagram for ILIAS\GlobalScreen\Client\Notifications:

Public Member Functions

 __construct ()
 
 run ()
 

Data Fields

const ADDITIONAL_ACTION = 'additional_action'
 
const MODE = "mode"
 Name of the GET param used in the async calls. More...
 
const MODE_OPENED = "opened"
 Value of the MODE GET param, if the Notification Center has been opened. More...
 
const MODE_CLOSED = "closed"
 Value of the MODE GET param, if the Notification Center has been closed. More...
 
const MODE_HANDLE_TOAST_ACTION = "toast_action"
 Value of the MODE GET param, if a ToastLik has been klicked. More...
 
const MODE_RERENDER = "rerender"
 Value of the MODE GET param, if the Notification Center should be rerendered. More...
 
const ITEM_ID = "item_id"
 NAME of the GET param, to indicate the item ID of the closed item. More...
 
const NOTIFICATION_IDENTIFIERS = "notification_identifiers"
 Used to read the identifiers out of the GET param later. More...
 
const NOTIFY_ENDPOINT = "src/GlobalScreen/Client/notify.php"
 Location of the endpoint handling async notification requests. More...
 

Protected Attributes

Container $dic
 
array $notification_groups
 Collected set of collected notifications. More...
 
array $identifiers_to_handle = []
 
string $single_identifier_to_handle = null
 
array $administrative_notifications = []
 

Private Member Functions

 handleToastAction ()
 
 handleOpened ()
 Loops through all available open callable provided by the notification providers. More...
 
 handleClosed ()
 Runs the closed callable if such a callable is provided. More...
 
 handleRerender ()
 

Private Attributes

string $additional_action = null
 
array $toasts = []
 

Detailed Description

Definition at line 35 of file Notifications.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\GlobalScreen\Client\Notifications::__construct ( )

Definition at line 89 of file Notifications.php.

90 {
91 global $DIC;
92 $this->dic = $DIC;
93 }
global $DIC
Definition: feed.php:28

References $DIC.

Member Function Documentation

◆ handleClosed()

ILIAS\GlobalScreen\Client\Notifications::handleClosed ( )
private

Runs the closed callable if such a callable is provided.

Definition at line 182 of file Notifications.php.

182 : void
183 {
184 foreach ($this->notification_groups as $notification_group) {
185 foreach ($notification_group->getNotifications() as $notification) {
186 if ($this->single_identifier_to_handle !== $this->hash(
187 $notification->getProviderIdentification()->serialize()
188 )) {
189 continue;
190 }
191 if (!$notification->hasClosedCallable()) {
192 continue;
193 }
194 $notification->getClosedCallable()();
195 }
196 }
197 foreach ($this->administrative_notifications as $administrative_notification) {
198 if ($this->single_identifier_to_handle !== $this->hash(
199 $administrative_notification->getProviderIdentification()->serialize()
200 )) {
201 continue;
202 }
203 if (!$administrative_notification->hasClosedCallable()) {
204 continue;
205 }
206 $administrative_notification->getClosedCallable()();
207 }
208 }

Referenced by ILIAS\GlobalScreen\Client\Notifications\run().

+ Here is the caller graph for this function:

◆ handleOpened()

ILIAS\GlobalScreen\Client\Notifications::handleOpened ( )
private

Loops through all available open callable provided by the notification providers.

Definition at line 157 of file Notifications.php.

157 : void
158 {
159 foreach ($this->notification_groups as $notification_group) {
160 foreach ($notification_group->getNotifications() as $notification) {
161 if (in_array(
162 $this->hash($notification->getProviderIdentification()->serialize()),
163 $this->identifiers_to_handle,
164 true
165 )) {
166 $notification->getOpenedCallable()();
167 }
168 }
169 if (in_array(
170 $this->hash($notification_group->getProviderIdentification()->serialize()),
171 $this->identifiers_to_handle,
172 true
173 )) {
174 $notification_group->getOpenedCallable()();
175 }
176 }
177 }

Referenced by ILIAS\GlobalScreen\Client\Notifications\run().

+ Here is the caller graph for this function:

◆ handleRerender()

ILIAS\GlobalScreen\Client\Notifications::handleRerender ( )
private
Exceptions
ResponseSendingException
JsonException

Definition at line 214 of file Notifications.php.

214 : void
215 {
216 $notifications = [];
217 $amount = 0;
218 foreach ($this->notification_groups as $group) {
219 $notifications[] = $group->getRenderer($this->dic->ui()->factory())->getNotificationComponentForItem(
220 $group
221 );
222 if ($group->getNewNotificationsCount() > 0) {
223 $amount++;
224 }
225 }
226 $this->dic->http()->saveResponse(
227 $this->dic->http()->response()
228 ->withBody(
230 json_encode([
231 'html' => $this->dic->ui()->renderer()->renderAsync($notifications),
232 'symbol' => $this->dic->ui()->renderer()->render(
233 $this->dic->ui()->factory()->symbol()->glyph()->notification()->withCounter(
234 $this->dic->ui()->factory()->counter()->novelty($amount)
235 )
236 )
237 ], JSON_THROW_ON_ERROR)
238 )
239 )
240 ->withHeader(ResponseHeader::CONTENT_TYPE, 'application/json')
241 );
242 $this->dic->http()->sendResponse();
243 $this->dic->http()->close();
244 }
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:43

References ILIAS\HTTP\Response\ResponseHeader\CONTENT_TYPE, and ILIAS\Filesystem\Stream\Streams\ofString().

Referenced by ILIAS\GlobalScreen\Client\Notifications\run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleToastAction()

ILIAS\GlobalScreen\Client\Notifications::handleToastAction ( )
private

Definition at line 138 of file Notifications.php.

138 : void
139 {
140 foreach ($this->toasts as $toast) {
141 if ($this->hash($toast->getProviderIdentification()->serialize()) === $this->single_identifier_to_handle) {
142 foreach ($toast->getAllToastActions() as $toast_action) {
143 if ($toast_action->getIdentifier() === $this->additional_action) {
144 $callable = $toast_action->getAction();
145 $callable();
146 return;
147 }
148 }
149 }
150 }
151 }

Referenced by ILIAS\GlobalScreen\Client\Notifications\run().

+ Here is the caller graph for this function:

◆ run()

ILIAS\GlobalScreen\Client\Notifications::run ( )

@DI $DI

Definition at line 95 of file Notifications.php.

95 : void
96 {
100 global $DIC;
101 $this->notification_groups = $DIC->globalScreen()->collector()->notifications()->getNotifications();
102 $this->administrative_notifications = $DIC->globalScreen()->collector()->notifications(
103 )->getAdministrativeNotifications();
104 $this->identifiers_to_handle = $DIC->http()->request()->getQueryParams()[self::NOTIFICATION_IDENTIFIERS] ?? [];
105 $this->single_identifier_to_handle = $DIC->http()->request()->getQueryParams()[self::ITEM_ID] ?? null;
106 $this->toasts = $DIC->globalScreen()->collector()->toasts()->getToasts();
107
108 $query = $DIC->http()->wrapper()->query();
109
110 $this->additional_action = $query->has(self::ADDITIONAL_ACTION)
111 ? $query->retrieve(
112 self::ADDITIONAL_ACTION,
113 $DIC->refinery()->kindlyTo()->string()
114 )
115 : null;
116
117 $mode = 'none';
118 if ($query->has(self::MODE)) {
119 $mode = $query->retrieve(self::MODE, $DIC->refinery()->to()->string());
120 }
121
122 switch ($mode) {
124 $this->handleOpened();
125 break;
127 $this->handleClosed();
128 break;
130 $this->handleRerender();
131 break;
133 $this->handleToastAction();
134 break;
135 }
136 }
const MODE_CLOSED
Value of the MODE GET param, if the Notification Center has been closed.
const NOTIFICATION_IDENTIFIERS
Used to read the identifiers out of the GET param later.
const MODE_HANDLE_TOAST_ACTION
Value of the MODE GET param, if a ToastLik has been klicked.
const MODE_RERENDER
Value of the MODE GET param, if the Notification Center should be rerendered.
const ITEM_ID
NAME of the GET param, to indicate the item ID of the closed item.
const MODE_OPENED
Value of the MODE GET param, if the Notification Center has been opened.
handleOpened()
Loops through all available open callable provided by the notification providers.
handleClosed()
Runs the closed callable if such a callable is provided.
$query

References $DIC, $query, ILIAS\GlobalScreen\Client\Notifications\handleClosed(), ILIAS\GlobalScreen\Client\Notifications\handleOpened(), ILIAS\GlobalScreen\Client\Notifications\handleRerender(), ILIAS\GlobalScreen\Client\Notifications\handleToastAction(), ILIAS\GlobalScreen\Client\Notifications\ITEM_ID, ILIAS\GlobalScreen\Client\Notifications\MODE_CLOSED, ILIAS\GlobalScreen\Client\Notifications\MODE_HANDLE_TOAST_ACTION, ILIAS\GlobalScreen\Client\Notifications\MODE_OPENED, ILIAS\GlobalScreen\Client\Notifications\MODE_RERENDER, and ILIAS\GlobalScreen\Client\Notifications\NOTIFICATION_IDENTIFIERS.

+ Here is the call graph for this function:

Field Documentation

◆ $additional_action

string ILIAS\GlobalScreen\Client\Notifications::$additional_action = null
private

Definition at line 43 of file Notifications.php.

◆ $administrative_notifications

array ILIAS\GlobalScreen\Client\Notifications::$administrative_notifications = []
protected

Definition at line 83 of file Notifications.php.

◆ $dic

Container ILIAS\GlobalScreen\Client\Notifications::$dic
protected

Definition at line 44 of file Notifications.php.

◆ $identifiers_to_handle

array ILIAS\GlobalScreen\Client\Notifications::$identifiers_to_handle = []
protected

Definition at line 81 of file Notifications.php.

◆ $notification_groups

array ILIAS\GlobalScreen\Client\Notifications::$notification_groups
protected

Collected set of collected notifications.

Definition at line 48 of file Notifications.php.

◆ $single_identifier_to_handle

string ILIAS\GlobalScreen\Client\Notifications::$single_identifier_to_handle = null
protected

Definition at line 82 of file Notifications.php.

◆ $toasts

array ILIAS\GlobalScreen\Client\Notifications::$toasts = []
private

Definition at line 87 of file Notifications.php.

◆ ADDITIONAL_ACTION

const ILIAS\GlobalScreen\Client\Notifications::ADDITIONAL_ACTION = 'additional_action'

Definition at line 39 of file Notifications.php.

◆ ITEM_ID

const ILIAS\GlobalScreen\Client\Notifications::ITEM_ID = "item_id"

NAME of the GET param, to indicate the item ID of the closed item.

Definition at line 72 of file Notifications.php.

Referenced by ILIAS\GlobalScreen\Client\Notifications\run().

◆ MODE

const ILIAS\GlobalScreen\Client\Notifications::MODE = "mode"

Name of the GET param used in the async calls.

Definition at line 52 of file Notifications.php.

◆ MODE_CLOSED

const ILIAS\GlobalScreen\Client\Notifications::MODE_CLOSED = "closed"

Value of the MODE GET param, if the Notification Center has been closed.

Definition at line 60 of file Notifications.php.

Referenced by ILIAS\GlobalScreen\Client\Notifications\run().

◆ MODE_HANDLE_TOAST_ACTION

const ILIAS\GlobalScreen\Client\Notifications::MODE_HANDLE_TOAST_ACTION = "toast_action"

Value of the MODE GET param, if a ToastLik has been klicked.

Definition at line 64 of file Notifications.php.

Referenced by ILIAS\GlobalScreen\Client\Notifications\run().

◆ MODE_OPENED

const ILIAS\GlobalScreen\Client\Notifications::MODE_OPENED = "opened"

Value of the MODE GET param, if the Notification Center has been opened.

Definition at line 56 of file Notifications.php.

Referenced by ILIAS\GlobalScreen\Client\Notifications\run().

◆ MODE_RERENDER

const ILIAS\GlobalScreen\Client\Notifications::MODE_RERENDER = "rerender"

Value of the MODE GET param, if the Notification Center should be rerendered.

Definition at line 68 of file Notifications.php.

Referenced by ILIAS\GlobalScreen\Client\Notifications\run().

◆ NOTIFICATION_IDENTIFIERS

const ILIAS\GlobalScreen\Client\Notifications::NOTIFICATION_IDENTIFIERS = "notification_identifiers"

Used to read the identifiers out of the GET param later.

Definition at line 76 of file Notifications.php.

Referenced by ILIAS\GlobalScreen\Client\Notifications\run().

◆ NOTIFY_ENDPOINT

const ILIAS\GlobalScreen\Client\Notifications::NOTIFY_ENDPOINT = "src/GlobalScreen/Client/notify.php"

Location of the endpoint handling async notification requests.

Definition at line 80 of file Notifications.php.


The documentation for this class was generated from the following file: