1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
outcomingeventmanager.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\ICal;
4
5use Bitrix\Calendar\Core;
6use Bitrix\Calendar\ICal\Builder\Attendee;
7use Bitrix\Calendar\ICal\Builder\AttendeesCollection;
8use Bitrix\Calendar\ICal\MailInvitation\Helper;
9use Bitrix\Calendar\ICal\MailInvitation\IncomingInvitationRequestHandler;
10use Bitrix\Calendar\Public;
11use Bitrix\Calendar\Sharing;
12use Bitrix\Calendar\Util;
13use Bitrix\Main\Loader;
14use Bitrix\Main\Localization\Loc;
15use Bitrix\Calendar\ICal\Basic\{Dictionary, ICalUtil};
16
17IncludeModuleLangFile($_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/modules/calendar/lib/ical/mailinvitation/senderrequestinvitation.php');
18
20{
21 const ATTACHMENT_NAME = 'invite.ics';
22 const CHARSET = 'utf-8';
23 const CONTENT_TYPE = 'text/calendar';
24 const MAX_SENT = 3;
25
29 private $method;
33 private $uid;
37 private $status;
41 private $eventFields;
42 private AttendeesCollection $attendees;
46 private $receiver;
50 private $sender;
51 private $answer;
55 private $changeFields;
56 private $counterInvitations;
57
59 {
60 return new self($params);
61 }
62
63 public function __construct(array $params)
64 {
65 $this->method = $params['icalMethod'];
66 $this->eventFields = $params['arFields'];
67 $this->attendees = $params['userIndex'];
68 $this->receiver = $params['receiver'];
69 $this->sender = $params['sender'];
70 $this->changeFields = $params['changeFields'] ?? null;
71 $this->counterInvitations = 0;
72 $this->answer = $params['answer'] ?? null;
73 }
74
75 public function __serialize(): array
76 {
77 return [
78 'method' => $this->method,
79 'eventFields' => $this->eventFields,
80 'attendees' => $this->attendees,
81 'receiver' => $this->receiver,
82 'sender' => $this->sender,
83 'changeFields' => $this->changeFields,
84 ];
85 }
86
87 public function __unserialize(array $data): void
88 {
89 $this->method = $data['method'];
90 $this->eventFields = $data['eventFields'];
91 $this->attendees = $data['attendees'];
92 $this->receiver = $data['receiver'];
93 $this->sender = $data['sender'];
94 $this->changeFields = $data['changeFields'];
95 }
96
98 {
99 $this->checkOrganizerEmail();
100 $filesContent = $this->getRequestContent();
101 $mailEventFields = $this->getRequestMailEventFields();
102 $files = $this->getFiles();
103 $this->status = \CEvent::sendImmediate('SEND_ICAL_INVENT', SITE_ID, $mailEventFields, "Y", "", $files, '', $filesContent);
104
105 return $this;
106 }
107
109 {
110 $this->prepareEventFields();
111
112 $filesContent = $this->getReplyContent();
113 $mailEventFields = $this->getReplyMailEventFields();
114 $files = $this->getFiles();
115 $this->status = \CEvent::sendImmediate('SEND_ICAL_INVENT', SITE_ID, $mailEventFields, "Y", "", $files, '', $filesContent);
116
117 return $this;
118 }
119
121 {
122 $filesContent = $this->getCancelContent();
123 $mailEventFields = $this->getCancelMailEventFields();
124 $files = [];
125 $this->status = \CEvent::sendImmediate('SEND_ICAL_INVENT', SITE_ID, $mailEventFields, "Y", "", $files, '', $filesContent);
126
127 return $this;
128 }
129
130 public function getUId(): string
131 {
132 return $this->uid;
133 }
134
136 {
137 $this->counterInvitations++;
138 }
139
140 public function getEventId()
141 {
142 return $this->eventFields['ID'];
143 }
144
145 public function getEvent()
146 {
147 return $this->eventFields;
148 }
149
150 public function getMethod()
151 {
152 return $this->method;
153 }
154
155 public function getCountInvitations()
156 {
157 return $this->counterInvitations;
158 }
159
160 public function getStatus(): string
161 {
162 return $this->status;
163 }
164
165 public function getReceiver()
166 {
167 return $this->receiver;
168 }
169
170 private function getSenderAddress(): string
171 {
172 return $this->eventFields['MEETING']['MAIL_FROM'] ?? $this->sender['EMAIL'];
173 }
174
175 private function getReceiverAddress(): string
176 {
177 if (isset($this->receiver['MAILTO']))
178 {
179 return $this->receiver['MAILTO'];
180 }
181
182 return $this->receiver['EMAIL'];
183 }
184
185 private function getBodyMessage(): string
186 {
187 return 'ical body message';
188 }
189
190 private function getSubjectMessage(): string
191 {
192 $result = '';
193 $siteName = \COption::GetOptionString("main", "site_name", '');
194 if ($siteName !== '')
195 {
196 $result = "[".$siteName."]";
197 }
198
199 $result .= ' ' . $this->getLocMeetingStatus();
200
201 $result .= ": ".$this->eventFields['NAME'];
202
203 return $result;
204 }
205
206 protected function getLocMeetingStatus(): string
207 {
208 return match ($this->method)
209 {
210 'request' => Loc::getMessage('EC_CALENDAR_ICAL_MAIL_METHOD_REQUEST'),
211 'edit' => Loc::getMessage('EC_CALENDAR_ICAL_MAIL_METHOD_EDIT'),
212 'cancel' => Loc::getMessage('EC_CALENDAR_ICAL_MAIL_METHOD_CANCEL'),
213 'reply' => match ($this->answer)
214 {
215 IncomingInvitationRequestHandler::MEETING_STATUS_ACCEPTED_CODE => Loc::getMessage('EC_CALENDAR_ICAL_MAIL_METHOD_REPLY_ACCEPTED'),
216 IncomingInvitationRequestHandler::MEETING_STATUS_DECLINED_CODE => Loc::getMessage('EC_CALENDAR_ICAL_MAIL_METHOD_REPLY_DECLINED'),
217 default => '',
218 },
219 default => '',
220 };
221 }
222
223 private function getFiles(): array
224 {
225 return [];
226 }
227
228 private function getRequestContent(): array
229 {
230 $attachmentManager = new OutcomingAttachmentManager ($this->eventFields, $this->attendees, $this->method);
231 $attachmentManager->prepareRequestAttachment();
232 $this->uid = $attachmentManager->getUid();
233 $fileContent = $attachmentManager->getAttachment();
234 return [[
235 'CONTENT' => $fileContent,
236 'CONTENT_TYPE' => self::CONTENT_TYPE,
237 'METHOD' => Dictionary::METHODS[$this->method],
238 'CHARSET' => self::CHARSET,
239 'NAME' => self::ATTACHMENT_NAME,
240 'ID' => Helper::getUniqId(),
241 ]];
242 }
243
244 private function getRequestMailEventFields(): array
245 {
246 return [];
247 }
248
249 private function getReplyMailEventFields(): array
250 {
251 return [
252 'EMAIL_FROM' => $this->getSenderAddress(),
253 'EMAIL_TO' => $this->getReceiverAddress(),
254 'MESSAGE_SUBJECT' => $this->getSubjectMessage(),
255 'MESSAGE_PHP' => $this->getReplyBodyMessage(),
256
257 'LOC_MEETING_STATUS' => $this->getLocMeetingStatus(),
258 'STATUS' => 'event',
259 'EVENT_NAME' => $this->eventFields['NAME'],
260 'DATE_FROM' => $this->eventFields['DATE_FROM'],
261 'DATE_TO' => $this->eventFields['DATE_TO'],
262 'IS_FULL_DAY' => $this->eventFields['DT_SKIP_TIME'] === 'Y',
263 'TZ_FROM' => $this->eventFields['TZ_FROM'],
264 'TZ_TO' => $this->eventFields['TZ_TO'],
265 'AVATARS' => $this->eventFields['AVATARS'],
266 'OWNER_STATUS' => $this->eventFields['OWNER_STATUS'],
267 'RRULE' => $this->getRRuleString(),
268 'BITRIX24_LINK' => Sharing\Helper::getBitrix24Link(),
269 ];
270 }
271
272 protected function getRRuleString(): string
273 {
274 $rrule = \CCalendarEvent::ParseRRULE($this->eventFields['RRULE']);
275 if (is_array($rrule))
276 {
277 return Helper::getIcalTemplateRRule(
278 $rrule,
279 [
280 'DATE_FROM' => $this->eventFields['DATE_FROM'],
281 ],
282 );
283 }
284
285 return '';
286 }
287
288 private function getCancelMailEventFields()
289 {
290 return [
291 "=Reply-To" => $this->getOrganizerName().' <'.$this->getReceiverAddress().'>',
292 "=From" => $this->getOrganizerName().' <'.$this->getSenderAddress().'>',
293 "=Message-Id" => $this->getMessageId(),
294 "=In-Reply-To" => $this->getMessageReplyTo(),
295 'EMAIL_FROM' => $this->getSenderAddress(),
296 'EMAIL_TO' => $this->getReceiverAddress(),
297 'MESSAGE_SUBJECT' => $this->getSubjectMessage(),
298 'MESSAGE_PHP' => $this->getBodyMessage(),
299 'DATE_FROM' => $this->eventFields['DATE_FROM'],
300 'DATE_TO' => $this->eventFields['DATE_TO'],
301 'NAME' => $this->eventFields['NAME'],
302 'DESCRIPTION' => str_replace("\r\n", "#$&#$&#$&", $this->eventFields['DESCRIPTION']),
303 'ATTENDEES' => $this->getAttendeesList(),
304 'ORGANIZER' => $this->getOrganizerName(),
305 'LOCATION' => $this->eventFields['LOCATION'],
306 'FILES_LINK' =>$this->getFilesLink(),
307 'METHOD' => $this->method,
308 ];
309 }
310
311 private function getAttendeesList(): string
312 {
313 if ($this->eventFields['MEETING']['HIDE_GUESTS'] ?? false)
314 {
315 return (string)Loc::getMessage('EC_CALENDAR_ICAL_MAIL_HIDE_GUESTS_INFORMATION');
316 }
317
318 $attendees = [];
319
321 foreach ($this->attendees as $attendee)
322 {
323 if (!empty($attendee->getFullName()))
324 {
325 $attendees[] = $attendee->getFullName();
326 }
327 }
328
329 return implode(", ", $attendees);
330 }
331
332 private function getOrganizerName(): string
333 {
335 $organizer = $this->eventFields['ICAL_ORGANIZER'];
336 return $organizer->getFullName() . ' (' . $organizer->getEmail() .')';
337 }
338
339 private function getFilesLink()
340 {
341 if (empty($this->eventFields['ATTACHES']))
342 {
343 return '';
344 }
345
346 $attaches = [];
347
348 foreach ($this->eventFields['ATTACHES'] as $attach)
349 {
350 $attaches[] = '<a href="'.$attach['link'].'">'.$attach['name'].'</a><br />' ;
351 }
352
353 return implode(" ", $attaches);
354 }
355
356 private function getMessageId(): string
357 {
358 return "<CALENDAR_EVENT_".$this->eventFields['PARENT_ID']."@".$GLOBALS["SERVER_NAME"].">";
359 }
360
361 private function getMessageReplyTo(): string
362 {
363 return $this->getMessageId();
364 }
365
366 private function getReplyContent(): array
367 {
368 $attachmentManager = new OutcomingAttachmentManager ($this->eventFields, $this->attendees, $this->method);
369 $attachmentManager->prepareReplyAttachment();
370 $fileContent = $attachmentManager->getAttachment();
371 return [[
372 'CONTENT' => $fileContent,
373 'CONTENT_TYPE' => self::CONTENT_TYPE,
374 'METHOD' => Dictionary::METHODS[$this->method],
375 'CHARSET' => self::CHARSET,
376 'NAME' => self::ATTACHMENT_NAME,
377 'ID' => Helper::getUniqId(),
378 ]];
379 }
380
381 private function getReplyBodyMessage()
382 {
383 return 'reply body message';
384 }
385
386 private function getCancelContent(): array
387 {
388 $attachmentManager = new OutcomingAttachmentManager ($this->eventFields, $this->attendees, $this->method);
389 $attachmentManager->prepareCancelAttachment();
390 $fileContent = $attachmentManager->getAttachment();
391 return [[
392 'CONTENT' => $fileContent,
393 'CONTENT_TYPE' => self::CONTENT_TYPE,
394 'METHOD' => Dictionary::METHODS[$this->method],
395 'CHARSET' => self::CHARSET,
396 'NAME' => self::ATTACHMENT_NAME,
397 'ID' => ICalUtil::getUniqId(),
398 ]];
399 }
400
401 private function getDateForTemplate()
402 {
403 $res = Util::getIcalTemplateDate([
404 'DATE_FROM' => $this->eventFields['DATE_FROM'],
405 'DATE_TO' => $this->eventFields['DATE_TO'],
406 'TZ_FROM' => $this->eventFields['TZ_FROM'],
407 'TZ_TO' => $this->eventFields['TZ_TO'],
408 'FULL_DAY' => $this->eventFields['SKIP_TIME'],
409 ]);
410 $offset = (Util::getDateObject(null, false, $this->eventFields['TZ_FROM']))->format('P');
411 $res .= ' (' . $this->eventFields['TZ_FROM'] . ', ' . 'UTC' . $offset . ')';
412
413 if (isset($this->eventFields['RRULE']['FREQ']) && $this->eventFields['RRULE']['FREQ'] !== 'NONE')
414 {
415 $rruleString = Util::getIcalTemplateRRule($this->eventFields['RRULE'],
416 [
417 'DATE_FROM' => $this->eventFields['DATE_FROM'],
418 'DATE_TO' => $this->eventFields['DATE_TO'],
419 'TZ_FROM' => $this->eventFields['TZ_FROM'],
420 'TZ_TO' => $this->eventFields['TZ_TO'],
421 'FULL_DAY' => $this->eventFields['SKIP_TIME'],
422 ]
423 );
424 $res .= ', (' . $rruleString . ')';
425 }
426
427 return $res;
428 }
429
430 private function getEditTitle()
431 {
432 if ($this->method !== 'edit')
433 {
434 return null;
435 }
436
437 if (count($this->changeFields) === 1)
438 {
439 switch ($this->changeFields[0]['fieldKey'])
440 {
441 case 'DATE_FROM':
442 return Loc::getMessage('EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_DATE');
443 case 'LOCATION':
444 return Loc::getMessage('EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_LOCATION');
445 case 'ATTENDEES':
446 return Loc::getMessage('EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_ATTENDEES');
447 case 'RRULE':
448 return Loc::getMessage('EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_RRULE');
449 case 'NAME':
450 return Loc::getMessage('EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_NAME');
451 default:
452 return Loc::getMessage('EC_CALENDAR_ICAL_MAIL_METHOD_EDIT');
453 }
454 }
455
456 return Loc::getMessage('EC_CALENDAR_ICAL_MAIL_METHOD_EDIT');
457 }
458
459 private function getChangeFieldsString()
460 {
461 $res = [];
462 if (!empty($this->changeFields))
463 {
464 foreach ($this->changeFields as $changeField)
465 {
466 $res[] = $changeField['fieldKey'];
467 }
468 }
469 return implode(';', $res);
470 }
471
472 private function checkOrganizerEmail()
473 {
474 if (Loader::includeModule('mail'))
475 {
476 if (empty($this->sender['EMAIL']))
477 {
478 $boxes = \Bitrix\Mail\MailboxTable::getUserMailboxes($this->eventFields['MEETING_HOST']);
479 $email = array_shift($boxes)['EMAIL'];
480 $this->sender['EMAIL'] = $email;
481 $this->attendees[$this->eventFields['MEETING_HOST']]['EMAIL'] = $email;
482 }
483 }
484 }
485
486 protected function prepareEventFields(): void
487 {
488 $event = (new Core\Mappers\Event())->getByArray($this->eventFields);
489 $this->eventFields['DESCRIPTION'] = Public\PublicEvent::prepareEventDescriptionForIcs($event);
490 $this->eventFields['OWNER_STATUS'] = $this->answer === 'accepted' ? 'Y' : 'N';
491 $this->eventFields['AVATARS'] = [];
492
494 $parentEvent = (new Core\Mappers\Event())->getById($this->eventFields['PARENT_ID']);
495 $this->eventFields['DAV_XML_ID'] = $parentEvent->getUid();
496 }
497}
const BX_ROOT
Определения bx_root.php:3
static createInstance(array $params)
Определения outcomingeventmanager.php:58
static getDateObject(string $date=null, ?bool $fullDay=true, ?string $tz='UTC')
Определения util.php:107
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$fileContent
Определения file_property.php:47
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$uid
Определения hot_keys_act.php:8
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
$status
Определения session.php:10
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
$files
Определения mysql_to_pgsql.php:30
$GLOBALS['____1690880296']
Определения license.php:1
$email
Определения payment.php:49
$event
Определения prolog_after.php:141
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$method
Определения index.php:27
const SITE_ID
Определения sonet_set_content_view.php:12