ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Notification.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 protected \ilObjUser $to;
26 protected \ilObjUser $cc;
27 protected int $talk_ref_id;
28 protected string $talk_name;
29 protected string $talk_description;
30 protected string $talk_location;
31 protected string $subject_key;
32 protected string $message_key;
33
37 protected array $dates;
38 protected bool $add_goto;
39 protected string $attachment;
40
41 public function __construct(
44 int $talk_ref_id,
45 string $talk_name,
46 string $talk_description,
47 string $talk_location,
48 string $subject_key,
49 string $message_key,
50 string $attachment,
51 bool $add_goto,
52 string ...$dates,
53 ) {
54 $this->to = $to;
55 $this->cc = $cc;
56 $this->talk_ref_id = $talk_ref_id;
57 $this->talk_name = $talk_name;
58 $this->talk_description = $talk_description;
59 $this->talk_location = $talk_location;
60 $this->subject_key = $subject_key;
61 $this->message_key = $message_key;
62 $this->dates = $dates;
63 $this->add_goto = $add_goto;
64 $this->attachment = $attachment;
65 }
66
67 public function send(): void
68 {
69 $notif = new \ilSystemNotification();
70 $notif->setLangModules(['etal', 'orgu']);
71 $attachment = new \ilFileDataMail(ANONYMOUS_USER_ID);
72
73 $subject = sprintf(
74 $notif->getUserLanguage($this->to->getId())->txt($this->subject_key),
75 $this->talk_name
76 );
77
78 $notif->setRefId($this->talk_ref_id);
79 $notif->setObjId(0);
80 $notif->setIntroductionLangId($this->message_key);
81
82 $notif->addAdditionalInfo(
83 'obj_etal',
84 $this->talk_name
85 );
86
87 if ($this->talk_description) {
88 $notif->addAdditionalInfo(
89 'description',
90 $this->talk_description
91 );
92 }
93
94 if ($this->talk_location) {
95 $notif->addAdditionalInfo(
96 'location',
97 $this->talk_location
98 );
99 }
100
101 $notif->addAdditionalInfo(
102 'superior',
103 $this->cc->getFullname()
104 );
105
106 $notif->addAdditionalInfo(
107 'notification_talks_date_list_header',
108 "- " . implode("\r\n- ", $this->dates),
109 true
110 );
111
112 if ($this->add_goto) {
113 $notif->addAdditionalInfo(
114 'url',
115 $this->getTalkGoto()
116 );
117 }
118
119 $attachment_name = 'appointments.ics';
120 $attachment->storeAsAttachment(
121 $attachment_name,
122 $this->attachment
123 );
124
125 $mail = new \ilMail(ANONYMOUS_USER_ID);
126 $mail->enqueue(
127 $this->to->getLogin(),
128 $this->cc->getLogin(),
129 '',
130 $subject,
131 $notif->composeAndGetMessage($this->to->getId(), null, '', true),
132 [$attachment_name]
133 );
134
135 $attachment->unlinkFile($attachment_name);
136 }
137
138 protected function getTalkGoto(): string
139 {
140 return ILIAS_HTTP_PATH . '/goto.php?target=' . \ilObjEmployeeTalk::TYPE . '_' .
141 $this->talk_ref_id . '&client_id=' . CLIENT_ID;
142 }
143}
__construct(\ilObjUser $to, \ilObjUser $cc, int $talk_ref_id, string $talk_name, string $talk_description, string $talk_location, string $subject_key, string $message_key, string $attachment, bool $add_goto, string ... $dates,)
User class.
const CLIENT_ID
Definition: constants.php:41
const ANONYMOUS_USER_ID
Definition: constants.php:27
to(\GdImage $image, ?int $quality=null)
Currently this is the only way to make a FileStream from a GD image resource.