ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
Notifications.php
Go to the documentation of this file.
1<?php
2
4
5use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
7
14{
15 use Hasher;
16
25 const MODE = "mode";
29 const MODE_OPENED = "opened";
33 const MODE_CLOSED = "closed";
37 const ITEM_ID = "item_id";
41 const NOTIFICATION_IDENTIFIERS = "notification_identifiers";
45 const NOTIFY_ENDPOINT = ILIAS_HTTP_PATH . "/src/GlobalScreen/Client/notify.php";
54
55 public function run()
56 {
60 global $DIC;
61 $this->notification_groups = $DIC->globalScreen()->collector()->notifications()->getNotifications();
62 $this->identifiers_to_handle = $DIC->http()->request()->getQueryParams()[self::NOTIFICATION_IDENTIFIERS] ?? [];
63 $this->single_identifier_to_handle = $DIC->http()->request()->getQueryParams()[self::ITEM_ID] ?? null;
64
65 switch ($DIC->http()->request()->getQueryParams()[self::MODE]) {
67 $this->handleOpened();
68 break;
70 $this->handleClosed();
71 break;
72 }
73 }
74
79 private function handleOpened() : void
80 {
81 foreach ($this->notification_groups as $notification_group) {
82 foreach ($notification_group->getNotifications() as $notification) {
83 if (in_array($this->hash($notification->getProviderIdentification()->serialize()), $this->identifiers_to_handle, true)) {
84 $notification->getOpenedCallable()();
85 }
86 }
87 if (in_array($this->hash($notification_group->getProviderIdentification()->serialize()), $this->identifiers_to_handle, true)) {
88 $notification_group->getOpenedCallable()();
89 }
90 }
91 }
92
96 private function handleClosed() : void
97 {
98 foreach ($this->notification_groups as $notification_group) {
99 foreach ($notification_group->getNotifications() as $notification) {
100 if ($this->single_identifier_to_handle === $this->hash($notification->getProviderIdentification()->serialize())) {
101 if ($notification->hasClosedCallable()) {
102 $notification->getClosedCallable()();
103 }
104 }
105 }
106 }
107 }
108}
An exception for terminatinating execution or to throw for unit testing.
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 ITEM_ID
NAME of the GET param, to indicate the item ID of the closed item.
const NOTIFY_ENDPOINT
Location of the endpoint handling async notification requests.
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.
const MODE
Name of the GET param used in the async calls.
handleClosed()
Runs the closed callable if such a callable is provided.
Entry Point for Async calls from the Notification Center.
Definition: gs_content.php:1
$DIC
Definition: xapitoken.php:46