ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ChatInvitationNotificationProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ilDateTime;
29
31{
32 final public const string MUTED_UNTIL_PREFERENCE_KEY = 'chatinv_nc_muted_until';
33 final public const string NOTIFICATION_TYPE = 'chat_invitation';
34
35 public function getNotifications(): array
36 {
37 if (0 === $this->dic->user()->getId() || $this->dic->user()->isAnonymous()) {
38 return [];
39 }
40
41 $leftIntervalTimestamp = $this->dic->user()->getPref(self::MUTED_UNTIL_PREFERENCE_KEY);
42
43 $latest_time = 0;
44 $osd_notification_handler = new ilNotificationOSDHandler(new ilNotificationOSDRepository($this->dic->database()));
45 $invitations = [];
46 foreach ($osd_notification_handler->getOSDNotificationsForUser(
47 $this->dic->user()->getId(),
48 true,
49 time() - $leftIntervalTimestamp,
50 self::NOTIFICATION_TYPE
51 ) as $osd) {
52 $invitations[] = $osd;
53 if ($latest_time < $osd->getTimeAdded()) {
54 $latest_time = $osd->getTimeAdded();
55 }
56 }
57
58 $this->dic->language()->loadLanguageModule('chatroom');
59
60 if ($invitations === []) {
61 return [];
62 }
63
64 $aggregatedItems = [];
65 foreach ($invitations as $invitation) {
66 $link = '';
67 if (count($invitation->getObject()->links) === 1) {
68 $link = $this->dic->ui()->renderer()->render(
69 $this->dic->ui()->factory()->link()->standard(
70 $invitation->getObject()->shortDescription,
71 $invitation->getObject()->links[0]->getUrl()
72 )
73 );
74 }
75 $aggregatedItems[] = $this->dic->ui()->factory()->item()->notification(
76 $invitation->getObject()->title,
77 $this->dic->ui()->factory()->symbol()->icon()->standard(Standard::CHTA, 'chat_invitations')
78 )->withDescription($link)
79 ->withProperties([
80 $this->dic->language()->txt('time') => ilDatePresentation::formatDate(
81 new ilDateTime($invitation->getTimeAdded(), IL_CAL_UNIX)
82 )
83 ]);
84 }
85
86 $notificationItem = $this->dic->ui()->factory()->item()->notification(
87 $this->dic->ui()->factory()->link()->standard($this->dic->language()->txt('chat_invitations'), '#'),
88 $this->dic->ui()->factory()->symbol()->icon()->standard(Standard::CHTA, 'chat_invitations')
89 )->withAggregateNotifications($aggregatedItems)
90 ->withDescription(
91 sprintf(
92 $this->dic->language()->txt('chat_invitation_nc_inv_x'),
93 count($aggregatedItems)
94 )
95 )->withProperties([
96 $this->dic->language()->txt('time') => ilDatePresentation::formatDate(
97 new ilDateTime($latest_time, IL_CAL_UNIX)
98 )
99 ]);
100
101 return [
102 $this->globalScreen()->notifications()->factory()->standardGroup(
103 $this->if->identifier('chat_invitation_bucket_group')
104 )->withTitle('Chat')
105 ->addNotification(
106 $this->globalScreen()->notifications()->factory()->standard(
107 $this->if->identifier('chat_invitation_bucket')
108 )->withNotificationItem($notificationItem)
109 ->withNewAmount(count($invitations))
110 ->withClosedCallable(
111 function () use ($osd_notification_handler): void {
112 $this->dic->user()->writePref(self::MUTED_UNTIL_PREFERENCE_KEY, (string) time());
113
114 $osd_notification_handler->deleteStaleNotificationsForUserAndType(
115 $this->dic->user()->getId(),
116 self::NOTIFICATION_TYPE
117 );
118 }
119 )
120 )
121 ];
122 }
123}
factory()
const IL_CAL_UNIX
Class for date presentation.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
This describes the specific behavior of an ILIAS standard icon.
Definition: Standard.php:27
if(!file_exists('../ilias.ini.php'))