ILIAS  release_8 Revision v8.24
ilNotificationOSDHandler.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21namespace ILIAS\Notifications;
22
27
32{
35
37 {
38 if ($repo === null) {
40 }
41 $this->repo = $repo;
42
43 if ($clock === null) {
44 $clock = (new \ILIAS\Data\Factory())->clock()->utc();
45 }
46 $this->clock = $clock;
47 }
48
49 public function notify(ilNotificationObject $notification): void
50 {
51 $this->repo->createOSDNotification($notification->user->getId(), $notification);
52 }
53
57 public function getOSDNotificationsForUser(int $user_id, bool $append_osd_id_to_link = true, int $max_age_seconds = 0, string $type = ''): array
58 {
59 $notifications = $this->repo->getOSDNotificationsByUser($user_id, $max_age_seconds, $type);
60
61 foreach ($notifications as $notification) {
62 if ($append_osd_id_to_link) {
63 foreach ($notification->getObject()->links as $link) {
64 $link->setUrl($this->appendParamToLink($link->getUrl(), 'osd_id', $notification->getId()));
65 }
66 }
67 }
68
69 return $notifications;
70 }
71
75 public function deleteStaleNotificationsForUserAndType(int $user_id, string $type): void
76 {
77 $this->repo->deleteStaleOSDNotificationsForUserAndType($type, $user_id, $this->clock->now()->getTimestamp());
78 }
79
80 public function deleteStaleOSDNotificationsForUser(string $provider, int $user_id): void
81 {
82 $this->repo->deleteStaleOSDNotificationsForUserAndType($provider, $user_id, $this->clock->now()->getTimestamp());
83 }
84
85 public function removeOSDNotification(int $notification_osd_id): bool
86 {
87 return $this->repo->deleteOSDNotificationById($notification_osd_id);
88 }
89
90 public function removeOSDNotificationByIdentification(string $provider, string $identification, int $user_id = 0): bool
91 {
92 return $this->repo->deleteOSDNotificationByIdentification(
94 $identification,
95 $user_id
96 );
97 }
98
99 private function appendParamToLink(string $link, string $param, int $value): string
100 {
101 if (strpos($link, '?') !== false) {
102 $link .= '&' . $param . '=' . $value;
103 } else {
104 $link .= '?' . $param . '=' . $value;
105 }
106 return $link;
107 }
108
109 public function clear(): void
110 {
111 $this->repo->deleteAllOSDNotifications();
112 }
113}
getOSDNotificationsForUser(int $user_id, bool $append_osd_id_to_link=true, int $max_age_seconds=0, string $type='')
deleteStaleNotificationsForUserAndType(int $user_id, string $type)
__construct(?ilNotificationOSDRepository $repo=null, ?ClockInterface $clock=null)
removeOSDNotificationByIdentification(string $provider, string $identification, int $user_id=0)
deleteStaleOSDNotificationsForUser(string $provider, int $user_id)
appendParamToLink(string $link, string $param, int $value)
$provider
Definition: ltitoken.php:83
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type
$param
Definition: xapitoken.php:46