ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
NotificationCenterRenderer.php
Go to the documentation of this file.
2 
3 use ILIAS\GlobalScreen\Client\Notifications as ClientNotifications;
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 }
getToggleSignal()
Signal that toggles the slate when triggered.
attachJSShowEvent(Combined $center)
Attaches on load code for communicating back, that the notification center has been opened...
ui()
Definition: ui.php:5
withAdditionalOnLoadCode(\Closure $binder)
Add some onload-code to the component instead of replacing the existing one.
__construct(Container $dic, ilPlugin $plugin)
$DIC
Definition: xapitoken.php:46
$url
This describes the Combined Slate.
Definition: Combined.php:12