ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
NotificationCenterRenderer.php
Go to the documentation of this file.
2
3use ILIAS\GlobalScreen\Client\Notifications as ClientNotifications;
4use ILIAS\GlobalScreen\Collector\Renderer\isSupportedTrait;
9
16{
17 use isSupportedTrait;
21 private $gs;
22
26 private $lng;
27
31 public function __construct()
32 {
33 global $DIC;
34 $this->gs = $DIC->globalScreen();
35 $this->lng = $DIC->language();
37 }
38
39
45 protected function getSpecificComponentForItem(isItem $item) : Component
46 {
47 $f = $this->ui->factory();
48
49 $center = $f->mainControls()->slate()->combined($this->lng->txt("noc"), $item->getSymbol())
50 ->withEngaged(false);
51
52 foreach ($this->gs->collector()->notifications()->getNotifications() as $notification) {
53 $center = $center->withAdditionalEntry($notification->getRenderer($this->ui->factory())->getNotificationComponentForItem($notification));
54 }
55
56 return $this->attachJSShowEvent($center);
57 }
58
59
69 protected function attachJSShowEvent(Combined $center)
70 {
71 $toggle_signal = $center->getToggleSignal();
72 $url = ClientNotifications::NOTIFY_ENDPOINT . "?" . $this->buildShowQuery();
73
74 $center = $center->withAdditionalOnLoadCode(
75 function ($id) use ($toggle_signal, $url) {
76 return "
77 $(document).on('$toggle_signal', function(event, signalData) {
78 $.ajax({url: '$url'});
79 });";
80 }
81 );
82
83 return $center;
84 }
85
86
90 protected function buildShowQuery() : string
91 {
92 return http_build_query([
93 ClientNotifications::MODE => ClientNotifications::MODE_OPENED,
94 ClientNotifications::NOTIFICATION_IDENTIFIERS => $this->gs->collector()->notifications()->getNotificationsIdentifiersAsArray(true),
95 ]);
96 }
97}
An exception for terminatinating execution or to throw for unit testing.
attachJSShowEvent(Combined $center)
Attaches on load code for communicating back, that the notification center has been opened.
A component is the most general form of an entity in the UI.
Definition: Component.php:14
withAdditionalOnLoadCode(\Closure $binder)
Add some onload-code to the component instead of replacing the existing one.
This describes the Combined Slate.
Definition: Combined.php:13
getToggleSignal()
Signal that toggles the slate when triggered.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$url
ui()
Definition: ui.php:5
$DIC
Definition: xapitoken.php:46