ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 = "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 36 of file Notifications.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 90 of file Notifications.php.

91 {
92 global $DIC;
93 $this->dic = $DIC;
94 }
global $DIC
Definition: shib_login.php:26

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 183 of file Notifications.php.

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

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 158 of file Notifications.php.

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

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 215 of file Notifications.php.

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

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 139 of file Notifications.php.

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

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 96 of file Notifications.php.

96 : void
97 {
101 global $DIC;
102 $this->notification_groups = $DIC->globalScreen()->collector()->notifications()->getNotifications();
103 $this->administrative_notifications = $DIC->globalScreen()->collector()->notifications(
104 )->getAdministrativeNotifications();
105 $this->identifiers_to_handle = $DIC->http()->request()->getQueryParams()[self::NOTIFICATION_IDENTIFIERS] ?? [];
106 $this->single_identifier_to_handle = $DIC->http()->request()->getQueryParams()[self::ITEM_ID] ?? null;
107 $this->toasts = $DIC->globalScreen()->collector()->toasts()->getToasts();
108
109 $query = $DIC->http()->wrapper()->query();
110
111 $this->additional_action = $query->has(self::ADDITIONAL_ACTION)
112 ? $query->retrieve(
113 self::ADDITIONAL_ACTION,
114 $DIC->refinery()->kindlyTo()->string()
115 )
116 : null;
117
118 $mode = 'none';
119 if ($query->has(self::MODE)) {
120 $mode = $query->retrieve(self::MODE, $DIC->refinery()->to()->string());
121 }
122
123 switch ($mode) {
125 $this->handleOpened();
126 break;
128 $this->handleClosed();
129 break;
131 $this->handleRerender();
132 break;
134 $this->handleToastAction();
135 break;
136 }
137 }
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.

References $DIC, 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 44 of file Notifications.php.

◆ $administrative_notifications

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

Definition at line 84 of file Notifications.php.

◆ $dic

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

Definition at line 45 of file Notifications.php.

◆ $identifiers_to_handle

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

Definition at line 82 of file Notifications.php.

◆ $notification_groups

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

Collected set of collected notifications.

Definition at line 49 of file Notifications.php.

◆ $single_identifier_to_handle

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

Definition at line 83 of file Notifications.php.

◆ $toasts

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

Definition at line 88 of file Notifications.php.

◆ ADDITIONAL_ACTION

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

Definition at line 40 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 73 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 53 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 61 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 65 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 57 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 69 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 77 of file Notifications.php.

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

◆ NOTIFY_ENDPOINT

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

Location of the endpoint handling async notification requests.

Definition at line 81 of file Notifications.php.


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