ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
NotificationHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
26{
28
29 public function __construct(
31 ) {
32 $this->vcalendar_generator = $vcalendar_generator;
33 }
34
35 public function send(
36 NotificationType $type,
37 \ilObjEmployeeTalk ...$affected_talks
38 ): void {
39 if (count($affected_talks) === 0) {
40 return;
41 }
42
43 $superior = new \ilObjUser($affected_talks[0]->getOwner());
44 $employee = new \ilObjUser($affected_talks[0]->getData()->getEmployee());
45
46 switch ($type) {
47 case NotificationType::INVITATION:
48 $subject_key = 'notification_talks_subject';
49 $message_key = 'notification_talks_created';
50 $add_goto = true;
51 break;
52
54 $subject_key = 'notification_talks_subject_update';
55 $message_key = 'notification_talks_removed';
56 $add_goto = false;
57 break;
58
59 case NotificationType::UPDATE:
60 default:
61 $subject_key = 'notification_talks_subject_update';
62 $message_key = 'notification_talks_updated';
63 $add_goto = true;
64 break;
65 }
66
67 $add_time = $affected_talks[0]->getData()->isAllDay() ? 0 : 1;
68 $format = \ilCalendarUtil::getUserDateFormat($add_time, true);
69 $timezone = $employee->getTimeZone();
70
71 $notification = new Notification(
72 $employee,
73 $superior,
74 $affected_talks[0]->getRefId(),
75 $affected_talks[0]->getTitle(),
76 $affected_talks[0]->getDescription(),
77 $affected_talks[0]->getData()->getLocation(),
78 $subject_key,
79 $message_key,
80 $this->vcalendar_generator->fromTalkSeries($affected_talks[0]->getParent(), $employee, $superior),
81 $add_goto,
82 ...$this->extractFormattedDates($format, $timezone, ...$affected_talks)
83 );
84 $notification->send();
85 }
86
90 protected function extractFormattedDates(
91 string $format,
92 string $timezone,
93 \ilObjEmployeeTalk ...$talks
94 ): array {
95 $dates = [];
96 foreach ($talks as $talk) {
97 $dates[] = $talk->getData()->getStartDate();
98 }
99
100 usort($dates, function (\ilDateTime $a, \ilDateTime $b) {
101 $a = $a->getUnixTime();
102 $b = $b->getUnixTime();
103 if ($a === $b) {
104 return 0;
105 }
106 return $a < $b ? -1 : 1;
107 });
108
109 $formatted_dates = [];
110 foreach ($dates as $date) {
111 $formatted_dates[] = $date->get(IL_CAL_FKT_DATE, $format, $timezone);
112 }
113 return $formatted_dates;
114 }
115}
extractFormattedDates(string $format, string $timezone, \ilObjEmployeeTalk ... $talks)
__construct(VCalendarGeneratorInterface $vcalendar_generator)
send(NotificationType $type, \ilObjEmployeeTalk ... $affected_talks)
All affected talks must come from the same series.
const IL_CAL_FKT_DATE
static getUserDateFormat(int $a_add_time=0, bool $a_for_parsing=false)
Parse current user setting into date/time format.
@classDescription Date and time handling
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
if(!file_exists('../ilias.ini.php'))