ILIAS  release_7 Revision v7.30-3-g800a261c036
MailNotificationProvider.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3namespace ILIAS\Mail\Provider;
4
9
15{
16 const MUTED_UNTIL_PREFERENCE_KEY = 'mail_nc_muted_until';
17
21 public function getNotifications() : array
22 {
23 $id = function (string $id) : IdentificationInterface {
24 return $this->if->identifier($id);
25 };
26
27 if (0 === (int) $this->dic->user()->getId() || $this->dic->user()->isAnonymous()) {
28 return [];
29 }
30
31 $hasInternalMailAccess = $this->dic->rbac()->system()->checkAccess(
32 'internal_mail',
34 );
35 if (!$hasInternalMailAccess) {
36 return [];
37 }
38
39 $leftIntervalTimestamp = $this->dic->user()->getPref(self::MUTED_UNTIL_PREFERENCE_KEY);
41 (int) $this->dic->user()->getId(),
42 is_numeric($leftIntervalTimestamp) ? (int) $leftIntervalTimestamp : 0
43 );
44
45 $numberOfNewMessages = (int) $newMailData['count'];
46 if (0 === $numberOfNewMessages) {
47 return [];
48 }
49
50 $this->dic->language()->loadLanguageModule('mail');
51
52 $factory = $this->globalScreen()->notifications()->factory();
53
54 $mailUrl = 'ilias.php?baseClass=ilMailGUI';
55
56 if (1 === $numberOfNewMessages) {
57 $linkText = $this->dic->language()->txt('nc_mail_unread_messages_number_s');
58 } else {
59 $linkText = sprintf(
60 $this->dic->language()->txt('nc_mail_unread_messages_number_p'),
61 $numberOfNewMessages
62 );
63 }
64
65 $body = sprintf(
66 $this->dic->language()->txt('nc_mail_unread_messages'),
67 $this->dic->ui()->renderer()->render(
68 $this->dic->ui()->factory()
69 ->link()
70 ->standard($linkText, $mailUrl)
71 )
72 );
73
74 $icon = $this->dic->ui()->factory()->symbol()->icon()->standard(Standard::MAIL, 'mail')
75 ->withIsOutlined(true);
76 $title = $this->dic->ui()->factory()->link()->standard(
77 $this->dic->language()->txt('nc_mail_noti_item_title'),
78 $mailUrl
79 );
80
81 $notificationItem = $this->dic->ui()->factory()
82 ->item()
83 ->notification($title, $icon)
84 ->withDescription($body);
85
86 try {
87 $dateTime = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $newMailData['max_time']);
88 $notificationItem = $notificationItem->withProperties([
89 $this->dic->language()->txt('nc_mail_prop_time') => \ilDatePresentation::formatDate(
90 new \ilDateTime($dateTime->getTimestamp(), IL_CAL_UNIX)
91 )
92 ]);
93 } catch (\Throwable $e) {
94 }
95
96 $group = $factory->standardGroup($id('mail_bucket_group'))
97 ->withTitle($this->dic->language()->txt('mail'))
98 ->addNotification(
99 $factory->standard($id('mail_bucket'))
100 ->withNotificationItem($notificationItem)
101 ->withClosedCallable(
102 function () {
103 $this->dic->user()->writePref(self::MUTED_UNTIL_PREFERENCE_KEY, time());
104 }
105 )
106 ->withNewAmount(1)
107 );
108
109 return [
110 $group,
111 ];
112 }
113}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable.
static getNewMailsData(int $usr_id, int $leftInterval=0)
Determines the number of new mails for the passed user id and stores this information in a local cach...
This describes the specific behavior of an ILIAS standard icon.
Definition: Standard.php:11
$factory
Definition: metadata.php:58