ILIAS  release_8 Revision v8.24
class.ilCalendarMailNotification.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 public const TYPE_GRP_NOTIFICATION = 1;
29 public const TYPE_GRP_NEW_NOTIFICATION = 2;
30 public const TYPE_CRS_NOTIFICATION = 3;
31 public const TYPE_CRS_NEW_NOTIFICATION = 4;
32 public const TYPE_BOOKING_CONFIRMATION = 5;
33 public const TYPE_BOOKING_CANCELLATION = 6;
34 public const TYPE_USER = 7;
35 public const TYPE_USER_ANONYMOUS = 8;
36 public const TYPE_BOOKING_REMINDER = 9;
37
38 private ?int $appointment_id = null;
40
41 protected ilLanguage $lng;
43
44 public function __construct(bool $a_is_personal_workspace = false)
45 {
46 global $DIC;
47
48 parent::__construct($a_is_personal_workspace);
49 $this->lng = $DIC->language();
50 $this->rbacreview = $DIC->rbac()->review();
51 }
52
53 public function setAppointmentId(int $a_id): void
54 {
55 $this->appointment_id = $a_id;
56 $this->appointment = new ilCalendarEntry($this->getAppointmentId());
57 }
58
59 public function getAppointment(): ?ilCalendarEntry
60 {
61 return $this->appointment;
62 }
63
64 public function getAppointmentId(): ?int
65 {
67 }
68
69 public function appendAppointmentDetails(): void
70 {
72 $this->appendBody($app->appointmentToMailString($this->getLanguage()));
73 }
74
75 public function send(): void
76 {
77 switch ($this->getType()) {
78 case self::TYPE_USER:
79 $rcps = $this->getRecipients();
80 $rcp = array_pop($rcps);
81 $this->initLanguage($rcp);
82 $this->getLanguage()->loadLanguageModule('dateplaner');
83 $this->initMail();
84 $this->setSubject(
85 sprintf(
86 $this->getLanguageText('cal_mail_notification_subject'),
87 $this->getAppointment()->getTitle()
88 )
89 );
90 $this->setBody(ilMail::getSalutation($rcp, $this->getLanguage()));
91 $this->appendBody("\n\n");
92 $this->appendBody(
93 $this->getLanguageText('cal_mail_notification_body')
94 );
95 $this->appendBody("\n\n");
97 $this->appendBody("\n\n");
98 $this->getMail()->appendInstallationSignature(true);
99 $this->addAttachment();
100
101 $this->sendMail(
102 $this->getRecipients(),
103 true
104 );
105 break;
106
108
109 $rcps = $this->getRecipients();
110 $rcp = array_pop($rcps);
111
112 $this->setLanguage(ilLanguageFactory::_getLanguage($this->lng->getDefaultLanguage()));
113 $this->getLanguage()->loadLanguageModule('dateplaner');
114 $this->getLanguage()->loadLanguageModule('mail');
115 $this->initMail();
116 $this->setSubject(
117 sprintf(
118 $this->getLanguageText('cal_mail_notification_subject'),
119 $this->getAppointment()->getTitle()
120 )
121 );
122 $this->setBody(ilMail::getSalutation(0, $this->getLanguage()));
123 $this->appendBody("\n\n");
124 $this->appendBody(
125 $this->getLanguageText('cal_mail_notification_body')
126 );
127 $this->appendBody("\n\n");
129 $this->appendBody("\n\n");
130 $this->getMail()->appendInstallationSignature(true);
131 $this->addAttachment();
132
133 $this->sendMail(
134 $this->getRecipients(),
135 false
136 );
137 break;
138
140
141 $this->setLanguage(ilLanguageFactory::_getLanguage($this->lng->getDefaultLanguage()));
142 $this->getLanguage()->loadLanguageModule('grp');
143 $this->getLanguage()->loadLanguageModule('dateplaner');
144 $this->initMail();
145 $this->setSubject(
146 sprintf($this->getLanguageText('cal_grp_new_notification_sub'), $this->getObjectTitle(true))
147 );
148 $this->setBody($this->getLanguageText('grp_notification_salutation'));
149 $this->appendBody("\n\n");
150 $this->appendBody(
151 sprintf($this->getLanguageText('cal_grp_new_notification_body'), $this->getObjectTitle(true))
152 );
153 $this->appendBody("\n\n");
154 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
155 $this->appendBody("\n\n");
156
158
159 $this->appendBody("\n\n");
160 $this->appendBody($this->createPermanentLink());
161 $this->getMail()->appendInstallationSignature(true);
162
163 $this->addAttachment();
164
165 $this->sendMail(
166 array('#il_grp_admin_' . $this->getRefId(), '#il_grp_member_' . $this->getRefId()),
167 false
168 );
169 break;
170
172
173 $this->setLanguage(ilLanguageFactory::_getLanguage($this->lng->getDefaultLanguage()));
174 $this->getLanguage()->loadLanguageModule('grp');
175 $this->getLanguage()->loadLanguageModule('dateplaner');
176 $this->initMail();
177 $this->setSubject(
178 sprintf($this->getLanguageText('cal_grp_notification_sub'), $this->getObjectTitle(true))
179 );
180 $this->setBody($this->getLanguageText('grp_notification_salutation'));
181 $this->appendBody("\n\n");
182 $this->appendBody(
183 sprintf($this->getLanguageText('cal_grp_notification_body'), $this->getObjectTitle(true))
184 );
185 $this->appendBody("\n\n");
186
188
189 $this->appendBody("\n\n");
190 $this->appendBody($this->getLanguageText('grp_mail_permanent_link'));
191 $this->appendBody("\n\n");
192 $this->appendBody($this->createPermanentLink());
193 $this->getMail()->appendInstallationSignature(true);
194
195 $this->addAttachment();
196
197 $this->sendMail(
198 array('#il_grp_admin_' . $this->getRefId(), '#il_grp_member_' . $this->getRefId()),
199 false
200 );
201 break;
202
204
205 $this->setLanguage(ilLanguageFactory::_getLanguage($this->lng->getDefaultLanguage()));
206 $this->getLanguage()->loadLanguageModule('crs');
207 $this->getLanguage()->loadLanguageModule('dateplaner');
208 $this->initMail();
209 $this->setSubject(
210 sprintf($this->getLanguageText('cal_crs_new_notification_sub'), $this->getObjectTitle(true))
211 );
212 $this->setBody($this->getLanguageText('crs_notification_salutation'));
213 $this->appendBody("\n\n");
214 $this->appendBody(
215 sprintf($this->getLanguageText('cal_crs_new_notification_body'), $this->getObjectTitle(true))
216 );
217 $this->appendBody("\n\n");
218 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
219 $this->appendBody("\n\n");
220 $this->appendBody($this->createPermanentLink());
221 $this->appendBody("\n\n");
223
224 $this->getMail()->appendInstallationSignature(true);
225
226 $this->addAttachment();
227
228 $this->sendMail(array('#il_crs_admin_' . $this->getRefId(),
229 '#il_crs_tutor_' . $this->getRefId(),
230 '#il_crs_member_' . $this->getRefId()
231 ), false);
232 break;
233
235
236 $this->setLanguage(ilLanguageFactory::_getLanguage($this->lng->getDefaultLanguage()));
237 $this->getLanguage()->loadLanguageModule('crs');
238 $this->getLanguage()->loadLanguageModule('dateplaner');
239 $this->initMail();
240 $this->setSubject(
241 sprintf($this->getLanguageText('cal_crs_notification_sub'), $this->getObjectTitle(true))
242 );
243 $this->setBody($this->getLanguageText('crs_notification_salutation'));
244 $this->appendBody("\n\n");
245 $this->appendBody(
246 sprintf($this->getLanguageText('cal_crs_notification_body'), $this->getObjectTitle(true))
247 );
248 $this->appendBody("\n\n");
249
251
252 $this->appendBody("\n\n");
253 $this->appendBody($this->getLanguageText('crs_mail_permanent_link'));
254 $this->appendBody("\n\n");
255 $this->appendBody($this->createPermanentLink());
256 $this->getMail()->appendInstallationSignature(true);
257
258 $this->addAttachment();
259
260 $this->sendMail(array('#il_crs_admin_' . $this->getRefId(),
261 '#il_crs_tutor_' . $this->getRefId(),
262 '#il_crs_member_' . $this->getRefId()
263 ), false);
264 break;
265
267
268 $rcps = $this->getRecipients();
269 $user_id = array_pop($rcps);
270 $entry = new ilCalendarEntry($this->getAppointmentId());
271 $booking = new ilBookingEntry($entry->getContextId());
272
273 $this->initLanguage($user_id);
274 $this->getLanguage()->loadLanguageModule('dateplaner');
275 $this->initMail();
276 $this->setSubject(
277 sprintf($this->getLanguageText('cal_booking_confirmation_subject'), $entry->getTitle())
278 );
279 $this->setBody(ilMail::getSalutation($user_id, $this->getLanguage()));
280 $this->appendBody("\n\n");
281 $this->appendBody(
282 sprintf(
283 $this->getLanguageText('cal_booking_confirmation_body'),
284 ilObjUser::_lookupFullname($booking->getObjId())
285 )
286 );
287 $this->appendBody("\n\n");
289
290 /*
291 $this->appendBody("\n\n");
292 $this->appendBody($this->getLanguageText('cal_booking_confirmation_link'));
293 $this->appendBody("\n\n");
294 $this->appendBody($this->createPermanentLink());
295 */
296 $this->getMail()->appendInstallationSignature(true);
297
298 $this->sendMail(array($user_id), true);
299
300 $this->appendBody("\n\n");
301 $this->appendBody($this->getLanguageText('cal_booking_confirmation_user') . "\n");
302 $this->appendBody(ilObjUser::_lookupFullname($user_id));
303
304 $this->sendMail(array($booking->getObjId()), true);
305 break;
306
308
309 $rcps = $this->getRecipients();
310 $user_id = array_pop($rcps);
311 $entry = new ilCalendarEntry($this->getAppointmentId());
312 $booking = new ilBookingEntry($entry->getContextId());
313
314 $rcps = $this->getRecipients();
315 $user_id = array_pop($rcps);
316 $this->initLanguage($user_id);
317 $this->getLanguage()->loadLanguageModule('dateplaner');
318 $this->initMail();
319 $this->setSubject(
320 sprintf($this->getLanguageText('cal_booking_cancellation_subject'), $entry->getTitle())
321 );
322 $this->setBody(ilMail::getSalutation($user_id, $this->getLanguage()));
323 $this->appendBody("\n\n");
324 $this->appendBody(
325 sprintf(
326 $this->getLanguageText('cal_booking_cancellation_body'),
327 ilObjUser::_lookupFullname($booking->getObjId())
328 )
329 );
330 $this->appendBody("\n\n");
331
333
334 $this->getMail()->appendInstallationSignature(true);
335
336 $this->sendMail(array($user_id), true);
337
338 $this->appendBody("\n\n");
339 $this->appendBody($this->getLanguageText('cal_booking_cancellation_user') . "\n");
340 $this->appendBody(ilObjUser::_lookupFullname($user_id));
341
342 $this->sendMail(array($booking->getObjId()), true);
343 break;
344
346
347 $rcps = $this->getRecipients();
348 $user_id = array_pop($rcps);
349
350 $entry = new ilCalendarEntry($this->getAppointmentId());
351 $booking = new ilBookingEntry($entry->getContextId());
352
353 $this->initLanguage($user_id);
354 $this->getLanguage()->loadLanguageModule('dateplaner');
355 $this->initMail();
356 $this->setSubject(
357 sprintf($this->getLanguageText('cal_ch_booking_reminder_subject'), $entry->getTitle())
358 );
359 $this->setBody(ilMail::getSalutation($user_id, $this->getLanguage()));
360 $this->appendBody("\n\n");
361 $this->appendBody(
362 sprintf(
363 $this->getLanguageText('cal_ch_booking_reminder_body'),
364 ilObjUser::_lookupFullname($booking->getObjId())
365 )
366 );
367 $this->appendBody("\n\n");
369 $this->getMail()->appendInstallationSignature(true);
370 $this->sendMail(array($user_id), true);
371 break;
372 }
373
374 $this->deleteAttachments();
375 }
376
377 protected function addAttachment(): void
378 {
379 $export = new ilCalendarExport();
380 $export->setExportType(ilCalendarExport::EXPORT_APPOINTMENTS);
381 $export->setAppointments([(int) $this->getAppointmentId()]);
382 $export->export();
383
384 $ics_filename = 'appointment_' . (new DateTimeImmutable('now'))->format('Ymd_His_u') . '.ics';
385
386 $attachment = new ilFileDataMail($this->getSender());
387 $effective_ics_filename = $attachment->storeAsAttachment(
388 $ics_filename,
389 $export->getExportString()
390 );
391
392 $this->setAttachments([$effective_ics_filename]);
393 }
394
395 protected function deleteAttachments(): void
396 {
397 $attachment = new ilFileDataMail($this->getSender());
398 $attachment->unlinkFiles($this->getAttachments());
399 }
400}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@classDescription Export calendar(s) to ical format
Distributes calendar mail notifications.
__construct(bool $a_is_personal_workspace=false)
This class handles all operations on files (attachments) in directory ilias_data/mail.
static _getLanguage(string $a_lang_key='')
Get language object.
language handling
Base class for course/group mail notifications.
getObjectTitle(bool $a_shorten=false)
setLanguage(ilLanguage $a_language)
sendMail(array $a_rcp, bool $a_parse_recipients=true)
createPermanentLink(array $a_params=[], string $a_append='')
getLanguageText(string $a_keyword)
setSubject(string $a_subject)
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
static _lookupFullname(int $a_user_id)
class ilRbacReview Contains Review functions of core Rbac.
$app
Definition: cli.php:39
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc