ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
NotificationsToastProvider.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
32 use ilSetting;
34 
39 {
43  public function getToasts(): array
44  {
45  $settings = new ilSetting('notifications');
46  $toasts = [];
47 
48  $osd_repository = new ilNotificationOSDRepository($this->dic->database());
49  $osd_notification_handler = new ilNotificationOSDHandler($osd_repository);
50 
51  foreach ($osd_notification_handler->getOSDNotificationsForUser(
52  $this->dic->user()->getId(),
53  true,
54  time() - ($this->dic->http()->request()->getQueryParams()['max_age'] ?? time())
55  ) as $notification) {
56  $type = $notification->getType();
57  $toast = $this->toast_factory
58  ->standard(
59  $this->if->identifier((string) $notification->getId()),
60  $notification->getObject()->title
61  )
62  ->withIcon($this->getIconByType($notification->getType()))
63  ->withDescription($notification->getObject()->shortDescription)
64  ->withClosedCallable(static function () use ($osd_repository, $notification) {
65  $osd_repository->deleteOSDNotificationById($notification->getId());
66  });
67 
68  foreach ($notification->getObject()->links as $id => $link) {
69  $toast = $toast->withAdditionToastAction(
70  $this->toast_factory->action(
71  $notification->getId() . '_link_' . $id,
72  $link->getTitle(),
73  function () use ($link, $osd_repository, $notification): void {
74  $osd_repository->deleteOSDNotificationById($notification->getId());
75  $this->dic->ctrl()->redirectToURL($link->getUrl());
76  }
77  )
78  );
79  }
80  $toasts[] = $toast;
81  }
82 
83  return $toasts;
84  }
85 
86  protected function getIconByType(string $type): Icon
87  {
88  $name = 'default';
89  switch ($type) {
90  case BadgeNotificationProvider::NOTIFICATION_TYPE:
91  $name = Standard::BDGA;
92  break;
93  case ChatInvitationNotificationProvider::NOTIFICATION_TYPE:
94  $name = Standard::CHTA;
95  break;
96  case ContactNotificationProvider::NOTIFICATION_TYPE:
97  $name = Standard::CADM;
98  break;
100  $name = Standard::LSO;
101  break;
102 
103  }
104  return $this->dic->ui()->factory()->symbol()->icon()->standard($name, $type);
105  }
106 }
if(!file_exists('../ilias.ini.php'))
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23