ILIAS  release_7 Revision v7.30-3-g800a261c036
ContactNotificationProvider.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
4
11use ilBuddyList;
12use ilObjUser;
13
20{
21 const MUTED_UNTIL_PREFERENCE_KEY = 'bs_nc_muted_until';
22
27 private function getIdentifier(string $id) : IdentificationInterface
28 {
29 return $this->if->identifier($id);
30 }
31
35 public function getNotifications() : array
36 {
37 if (
38 0 === (int) $this->dic->user()->getId() ||
39 $this->dic->user()->isAnonymous() ||
40 !\ilBuddySystem::getInstance()->isEnabled()
41 ) {
42 return [];
43 }
44
45 $leftIntervalTimestamp = $this->dic->user()->getPref(self::MUTED_UNTIL_PREFERENCE_KEY);
46 $latestRequestTimestamp = null;
47
48 $relations = ilBuddyList::getInstanceByGlobalUser()->getRequestRelationsForOwner();
49
50 $openRequests = $relations->filter(
51 function (\ilBuddySystemRelation $relation) use ($leftIntervalTimestamp, &$latestRequestTimestamp, $relations) : bool {
52 $timeStamp = $relation->getTimestamp();
53
54 if ($timeStamp > $latestRequestTimestamp) {
55 $latestRequestTimestamp = $timeStamp;
56 }
57
58 $usrId = $relations->getKey($relation);
59
60 if (!ilObjUser::_lookupActive($usrId)) {
61 return false;
62 }
63
64 if (!is_numeric($leftIntervalTimestamp)) {
65 return true;
66 }
67
68 return $timeStamp > $leftIntervalTimestamp;
69 }
70 );
71
72 $contactRequestsCount = count($openRequests->getKeys());
73 if ($contactRequestsCount === 0) {
74 return [];
75 }
76
77 $factory = $this->globalScreen()->notifications()->factory();
78
79 $icon = $this->dic->ui()->factory()
80 ->symbol()
81 ->icon()
82 ->standard(Standard::CADM, 'contacts')->withIsOutlined(true);
83
84 $title = $this->dic->ui()->factory()
85 ->link()
86 ->standard(
87 $this->dic->language()->txt('nc_contact_requests_headline'),
88 $this->dic->ctrl()->getLinkTargetByClass([ilDashboardGUI::class, ilContactGUI::class], 'showContactRequests')
89 );
90 $description = sprintf(
91 $this->dic->language()->txt(
92 'nc_contact_requests_number' . (($contactRequestsCount > 1) ? '_p' : '_s')
93 ),
94 $contactRequestsCount
95 );
96 $notificationItem = $this->dic->ui()->factory()
97 ->item()
98 ->notification($title, $icon)
99 ->withDescription($description)
100 ->withProperties([
101 $this->dic->language()->txt('nc_contact_requests_prop_time') => \ilDatePresentation::formatDate(
102 new \ilDateTime($latestRequestTimestamp, IL_CAL_UNIX)
103 )
104 ]);
105
106 $group = $factory
107 ->standardGroup($this->getIdentifier('contact_bucket_group'))
108 ->withTitle($this->dic->language()->txt('nc_contact_requests_headline'))
109 ->addNotification(
110 $factory->standard($this->getIdentifier('contact_bucket'))
111 ->withNotificationItem($notificationItem)
112 ->withClosedCallable(
113 function () {
114 $this->dic->user()->writePref(self::MUTED_UNTIL_PREFERENCE_KEY, time());
115 }
116 )->withNewAmount(1)
117 );
118
119 return [
120 $group
121 ];
122 }
123}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
Class ilBuddyList.
static getInstanceByGlobalUser()
Class ilBuddySystemRelation.
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 _lookupActive($a_usr_id)
Check user account active.
This describes the specific behavior of an ILIAS standard icon.
Definition: Standard.php:11
$factory
Definition: metadata.php:58