ILIAS  release_8 Revision v8.24
NotificationsToastProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
32use ilSetting;
33
38{
42 public function getToasts(): array
43 {
44 $settings = new ilSetting('notifications');
45 $toasts = [];
46
47 $osd_repository = new ilNotificationOSDRepository($this->dic->database());
48 $osd_notification_handler = new ilNotificationOSDHandler($osd_repository);
49
50 foreach ($osd_notification_handler->getOSDNotificationsForUser(
51 $this->dic->user()->getId(),
52 true,
53 time() - ($this->dic->http()->request()->getQueryParams()['max_age'] ?? time())
54 ) as $notification) {
55 $type = $notification->getType();
56 $toast = $this->toast_factory
57 ->standard(
58 $this->if->identifier((string) $notification->getId()),
59 $notification->getObject()->title
60 )
61 ->withIcon($this->getIconByType($notification->getType()))
62 ->withDescription($notification->getObject()->shortDescription)
63 ->withVanishTime((int) $settings->get('osd_vanish', (string) Toast::DEFAULT_VANISH_TIME))
64 ->withDelayTime((int) $settings->get('osd_delay', (string) Toast::DEFAULT_DELAY_TIME))
65 ->withClosedCallable(static function () use ($osd_repository, $notification) {
66 $osd_repository->deleteOSDNotificationById($notification->getId());
67 });
68
69 foreach ($notification->getObject()->links as $id => $link) {
70 $toast = $toast->withAdditionToastAction(
71 $this->toast_factory->action(
72 $notification->getId() . '_link_' . $id,
73 $link->getTitle(),
74 function () use ($link, $osd_repository, $notification): void {
75 $osd_repository->deleteOSDNotificationById($notification->getId());
76 $this->dic->ctrl()->redirectToURL($link->getUrl());
77 }
78 )
79 );
80 }
81 $toasts[] = $toast;
82 }
83
84 return $toasts;
85 }
86
87 protected function getIconByType(string $type): Icon
88 {
89 $name = 'default';
90 switch ($type) {
92 $name = Standard::BDGA;
93 break;
95 $name = Standard::CHTA;
96 break;
98 $name = Standard::CADM;
99 break;
100 }
101 return $this->dic->ui()->factory()->symbol()->icon()->standard($name, $type);
102 }
103}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
if($format !==null) $name
Definition: metadata.php:247
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type