ILIAS  release_8 Revision v8.24
MailNotificationProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Mail\Provider;
22
27use DateTimeImmutable;
28use ilDateTime;
30use Throwable;
32
38{
39 public const MUTED_UNTIL_PREFERENCE_KEY = 'mail_nc_muted_until';
40
41 public function getNotifications(): array
42 {
43 $id = function (string $id): IdentificationInterface {
44 return $this->if->identifier($id);
45 };
46
47 if (0 === $this->dic->user()->getId() || $this->dic->user()->isAnonymous()) {
48 return [];
49 }
50
51 $hasInternalMailAccess = $this->dic->rbac()->system()->checkAccess(
52 'internal_mail',
54 );
55 if (!$hasInternalMailAccess) {
56 return [];
57 }
58
59 $leftIntervalTimestamp = $this->dic->user()->getPref(self::MUTED_UNTIL_PREFERENCE_KEY);
61 $this->dic->user(),
62 is_numeric($leftIntervalTimestamp) ? (int) $leftIntervalTimestamp : 0
63 );
64
65 $numberOfNewMessages = $newMailData['count'];
66 if (0 === $numberOfNewMessages) {
67 return [];
68 }
69
70 $this->dic->language()->loadLanguageModule('mail');
71
72 $factory = $this->globalScreen()->notifications()->factory();
73
74 $mailUrl = 'ilias.php?baseClass=ilMailGUI';
75
76 if (1 === $numberOfNewMessages) {
77 $linkText = $this->dic->language()->txt('nc_mail_unread_messages_number_s');
78 } else {
79 $linkText = sprintf(
80 $this->dic->language()->txt('nc_mail_unread_messages_number_p'),
81 $numberOfNewMessages
82 );
83 }
84
85 $body = sprintf(
86 $this->dic->language()->txt('nc_mail_unread_messages'),
87 $this->dic->ui()->renderer()->render(
88 $this->dic->ui()->factory()
89 ->link()
90 ->standard($linkText, $mailUrl)
91 )
92 );
93
94 $icon = $this->dic->ui()->factory()->symbol()->icon()->standard(Standard::MAIL, 'mail');
95 $title = $this->dic->ui()->factory()->link()->standard(
96 $this->dic->language()->txt('nc_mail_noti_item_title'),
97 $mailUrl
98 );
99
101 $notificationItem = $this->dic->ui()->factory()
102 ->item()
103 ->notification($title, $icon)
104 ->withDescription($body);
105
106 try {
107 $dateTime = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $newMailData['max_time']);
108 $notificationItem = $notificationItem->withProperties([
109 $this->dic->language()->txt('nc_mail_prop_time') => ilDatePresentation::formatDate(
110 new ilDateTime($dateTime->getTimestamp(), IL_CAL_UNIX)
111 ),
112 ]);
113 } catch (Throwable $e) {
114 }
115
116 $group = $factory->standardGroup($id('mail_bucket_group'))
117 ->withTitle($this->dic->language()->txt('mail'))
118 ->addNotification(
119 $factory->standard($id('mail_bucket'))
120 ->withNotificationItem($notificationItem)
121 ->withClosedCallable(
122 function (): void {
123 $this->dic->user()->writePref(self::MUTED_UNTIL_PREFERENCE_KEY, (string) time());
124 }
125 )
126 ->withNewAmount(1)
127 );
128
129 return [
130 $group,
131 ];
132 }
133}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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)
@classDescription Date and time handling
Class for global mail information (e.g.
static getNewMailsData(ilObjUser $user, int $leftInterval=0)
This describes the specific behavior of an ILIAS standard icon.
Definition: Standard.php:27
$factory
Definition: metadata.php:75