ILIAS  release_8 Revision v8.23
EmployeeTalkEmailNotificationService.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
24 {
26  private string $subject;
27  private \ilObjUser $to;
28  private \ilObjUser $cc;
30 
31  public function __construct(
33  string $subject,
34  \ilObjUser $to,
35  \ilObjUser $cc,
36  VCalender $calendar
37  ) {
38  $this->message = $message;
39  $this->subject = $subject;
40  $this->to = $to;
41  $this->cc = $cc;
42  $this->calendar = $calendar;
43  }
44 
50  public function send(): bool
51  {
52  $notif = new \ilSystemNotification();
53  $notif->setLangModules(['etal', 'orgu']);
54  $attachment = new \ilFileDataMail(ANONYMOUS_USER_ID);
55 
56  $subject = sprintf(
57  $notif->getUserLanguage($this->to->getId())->txt($this->message->getSubjectLangKey()),
58  $this->subject
59  );
60 
61  $notif->setRefId($this->message->getTalkRefId());
62  $notif->setObjId(0);
63  $notif->setIntroductionLangId($this->message->getMessageLangKey());
64 
65  $notif->addAdditionalInfo(
66  'obj_etal',
67  $this->message->getTalkName()
68  );
69 
70  if ($this->message->getTalkDescription()) {
71  $notif->addAdditionalInfo(
72  'description',
73  $this->message->getTalkDescription()
74  );
75  }
76 
77  if ($this->message->getTalkLocation()) {
78  $notif->addAdditionalInfo(
79  'location',
80  $this->message->getTalkLocation()
81  );
82  }
83 
84  $notif->addAdditionalInfo(
85  'superior',
86  $this->message->getNameOfSuperior()
87  );
88 
89  $notif->addAdditionalInfo(
90  'notification_talks_date_list_header',
91  "- " . implode("\r\n- ", $this->message->getDates()),
92  true
93  );
94 
95  if ($this->message->getAddGoto()) {
96  $notif->addAdditionalInfo(
97  'url',
98  $this->getTalkGoto()
99  );
100  }
101 
102  $attachment_name = 'appointments.ics';
103  $attachment->storeAsAttachment(
104  $attachment_name,
105  $this->calendar->render()
106  );
107 
108  $mail = new \ilMail(ANONYMOUS_USER_ID);
109  $mail->enqueue(
110  \ilObjUser::_lookupLogin($this->to->getId()),
111  \ilObjUser::_lookupLogin($this->cc->getId()),
112  "",
113  $subject,
114  $notif->composeAndGetMessage($this->to->getId(), null, '', true),
115  [$attachment_name]
116  );
117 
118  $attachment->unlinkFile('appointments.ics');
119 
120  return true;
121  }
122 
123  private function getIcalEvent(string $mime_boundary): string
124  {
125  $message = "--$mime_boundary\r\n";
126  $message .= 'Content-Type: text/calendar;name="appointment.ics";method=' . $this->calendar->getMethod() . "\r\n";
127  $message .= "Content-Disposition: attachment;filename=\"appointment.ics\"\r\n";
128  $message .= "Content-Transfer-Encoding: UTF8\r\n\r\n";
129  $message .= $this->calendar->render() . "\r\n";
130  return $message;
131  }
132 
133  private function getTalkGoto(): string
134  {
135  return ILIAS_HTTP_PATH . '/goto.php?target=' . \ilObjEmployeeTalk::TYPE . '_' .
136  $this->message->getTalkRefId() . '&client_id=' . CLIENT_ID;
137  }
138 }
__construct(EmployeeTalkEmailNotification $message, string $subject, \ilObjUser $to, \ilObjUser $cc, VCalender $calendar)
const ANONYMOUS_USER_ID
Definition: constants.php:27
const CLIENT_ID
Definition: constants.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupLogin(int $a_user_id)