Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
senderinvitation.php
1<?php
2
4
6use Bitrix\Calendar\SerializeObject;
17use \Serializable;
18
23abstract class SenderInvitation implements Serializable
24{
25 use SerializeObject;
26
27 public const CHARSET = 'utf-8';
28 public const CONTENT_TYPE = 'text/calendar';
29 public const DECISION_YES = 'Y';
30 public const DECISION_NO = 'N';
31 protected const ATTACHMENT_NAME = 'invite.ics';
32 protected const MAIL_TEMPLATE = 'SEND_ICAL_INVENT';
33
37 protected int $counterInvitations = 0;
41 protected ?array $event = null;
45 protected ?Context $context = null;
49 protected ?string $uid = '';
50
51 abstract public function executeAfterSuccessfulInvitation();
52 abstract protected function getContent();
53 abstract protected function getMailEventField();
54 abstract protected function getSubjectTitle();
55
56 public static function createInstance(array $event, Context $context): SenderInvitation
57 {
58 return new static($event, $context);
59 }
60
61 public function __construct(array $event, Context $context)
62 {
63 $this->event = $event;
64 $this->context = $context;
65 }
66
67 public function setCounterInvitations(?int $counterInvitations): static
68 {
69 $this->counterInvitations = $counterInvitations ?? 0;
70 return $this;
71 }
72
73 public function setEvent(?array $event): static
74 {
75 $this->event = $event;
76 return $this;
77 }
78
87 public function send(): bool
88 {
89 if ($this->event === null || $this->context === null)
90 {
91 return false;
92 }
93
94 $this->prepareEventFields();
95
96 $content = $this->getContent();
97 if (!$content)
98 {
99 return false;
100 }
101
102 $status = \CEvent::sendImmediate(
103 self::MAIL_TEMPLATE,
104 SITE_ID,
105 $this->getMailEventField(),
106 "Y",
107 "",
108 [],
109 '',
110 $content
111 );
112
113 return $status === Event::SEND_RESULT_SUCCESS;
114 }
115
119 public function getMethod(): string
120 {
121 return static::METHOD;
122 }
123
127 public function getEvent(): array
128 {
129 return $this->event ?? [];
130 }
131
135 public function incrementCounterInvitations(): void
136 {
137 $this->counterInvitations++;
138 }
139
143 public function getUid(): string
144 {
145 return $this->uid;
146 }
147
151 public function getCountAttempsSend(): int
152 {
154 }
155
159 public function getAddresser():MailAddresser
160 {
161 return $this->context->getAddresser();
162 }
163
167 public function getReceiver(): MailReceiver
168 {
169 return $this->context->getReceiver();
170 }
171
175 public function getEventId(): ?int
176 {
177 return $this->event['ID'] ?? null;
178 }
179
183 public function getEventParentId(): int
184 {
185 return (int) ($this->event['PARENT_ID'] ?? 0);
186 }
187
191 protected function getBodyMessage(): string
192 {
193 //@TODO edit body message
194 return 'ical body message';
195 }
196
201 protected function getDateForTemplate(): string
202 {
204 'DATE_FROM' => $this->event['DATE_FROM'],
205 'DATE_TO' => $this->event['DATE_TO'],
206 'TZ_FROM' => $this->event['TZ_FROM'],
207 'TZ_TO' => $this->event['TZ_TO'],
208 'FULL_DAY' => $this->event['SKIP_TIME'],
209 ]);
210 $offset = (Helper::getDateObject(null, false, $this->event['TZ_FROM']))->format('P');
211 $res .= ' (' . $this->event['TZ_FROM'] . ', ' . 'UTC' . $offset . ')';
212
213 if (isset($this->event['RRULE']['FREQ']) && $this->event['RRULE']['FREQ'] !== 'NONE')
214 {
215 $rruleString = Helper::getIcalTemplateRRule($this->event['RRULE'],
216 [
217 'DATE_FROM' => $this->event['DATE_FROM'],
218 'DATE_TO' => $this->event['DATE_TO'],
219 'TZ_FROM' => $this->event['TZ_FROM'],
220 'TZ_TO' => $this->event['TZ_TO'],
221 'FULL_DAY' => $this->event['SKIP_TIME'],
222 ]
223 );
224 $res .= ', (' . $rruleString . ')';
225 }
226
227 return $res;
228 }
229
233 protected function getFilesLink(): string
234 {
235 $result = "";
236
237 if (is_iterable($this->event['ICAL_ATTACHES']))
238 {
239 foreach ($this->event['ICAL_ATTACHES'] as $attach)
240 {
241 if ($attach instanceof Attach)
242 {
243 $result .= "<a href=\"{$attach->getLink()}\"> {$attach->getName() }</a> <br />";
244 }
245 }
246 }
247
248 return $result;
249 }
250
254 protected function getSiteName(): string
255 {
256 if (!empty($siteName = \COption::GetOptionString("main", "site_name", '', '-')))
257 {
258 return "[{$siteName}]";
259 }
260
261 return '';
262 }
263
267 protected function getSubjectMessage(): string
268 {
269 return $this->getSiteName(). ' ' . $this->getSubjectTitle();
270 }
271
275 protected function getMessageId(): string
276 {
277 $serverName = \COption::GetOptionString("main", "server_name", $GLOBALS["SERVER_NAME"]);
278 return "<CALENDAR_EVENT_{$this->getEventParentId()}@{$serverName}>";
279 }
280
284 protected function getAttendeesListForTemplate(): string
285 {
286 if ($this->event['MEETING']['HIDE_GUESTS'])
287 {
288 return Loc::getMessage('EC_CALENDAR_ICAL_MAIL_HIDE_GUESTS_INFORMATION');
289 }
290
291 return $this->event['ICAL_ATTENDEES'];
292 }
293
297 protected function getEventDateCreateTimestamp(): int
298 {
299 return (int) Util::getTimestamp($this->event['CREATED']);
300 }
301
305 protected function getEventOwnerId(): int
306 {
307 return (int) $this->event['OWNER_ID'];
308 }
309
310 private function getFormattedDate(DateTime $formattedDate, string $dtSkipTime): string
311 {
312 $timestamp = \CCalendar::Timestamp($formattedDate, false, $dtSkipTime !== 'Y');
313
314 return \CCalendar::Date($timestamp);
315 }
316
317
325 protected function prepareEventFields(): void
326 {
327 $dtSkipTime = $this->event['DT_SKIP_TIME'];
328 $this->event['DATE_FROM'] = $this->getFormattedDate($this->event['DATE_FROM'], $dtSkipTime);
329 $this->event['DATE_TO'] = $this->getFormattedDate($this->event['DATE_TO'], $dtSkipTime);
330 $this->event['CREATED'] = $this->getFormattedDate($this->event['DATE_CREATE'], false);
331 $this->event['MODIFIED'] = $this->getFormattedDate($this->event['TIMESTAMP_X'], false);
332
333 $this->event['SKIP_TIME'] = $dtSkipTime === 'Y';
334 $this->event['MEETING'] = unserialize($this->event['MEETING'], ['allowed_classes' => false]);
335 $this->event['REMIND'] = unserialize($this->event['REMIND'], ['allowed_classes' => false]);
336 $this->event['RRULE'] = \CCalendarEvent::ParseRRULE($this->event['RRULE']);
337 $this->event['ATTENDEES_CODES'] = !empty($this->event['ATTENDEES_CODES']) && is_string($this->event['ATTENDEES_CODES'])
338 ? explode(',', $this->event['ATTENDEES_CODES'])
339 : []
340 ;
341 $this->event['ICAL_ATTENDEES'] = Helper::getAttendeesByEventParentId($this->event['PARENT_ID']);
342 $this->event['ICAL_ORGANIZER'] = Helper::getAttendee($this->event['MEETING_HOST'], $this->event['PARENT_ID'], false);
343 $this->event['TEXT_LOCATION'] = \CCalendar::GetTextLocation($this->event['LOCATION'] ?? null);
344 $this->event['ICAL_ATTACHES'] = Helper::getMailAttaches(
345 null,
346 $this->event['MEETING_HOST'],
347 $this->event['PARENT_ID']
348 );
349
350 unset($this->event['DT_SKIP_TIME'], $this->event['DATE_CREATE'], $this->event['TIMESTAMP_X']);
351 }
352}
static getAttendee(int $userId, int $eventParentId, $isRsvp=true)
Definition helper.php:450
static getDateObject(string $date=null, $fullDay=true, $tz='UTC')
Definition helper.php:73
static getAttendeesByEventParentId(int $parentId)
Definition helper.php:494
static getMailAttaches($fields, $userId, $parentId, &$isChangeFiles=false)
Definition helper.php:362
static getIcalTemplateRRule(array $rrule=null, array $params=null)
Definition helper.php:92
static getIcalTemplateDate(array $params=null)
Definition helper.php:46
static createInstance(array $event, Context $context)
static getTimestamp($date, $round=true, $getTime=true)
Definition util.php:55
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
$GLOBALS['____1444769544']
Definition license.php:1