1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
incominginvitationreplyhandler.php
См. документацию.
1<?php
2
3
4namespace Bitrix\Calendar\ICal\MailInvitation;
5
6
7use Bitrix\Calendar\ICal\Parser\Calendar;
8use Bitrix\Calendar\ICal\Parser\Dictionary;
9use Bitrix\Main\ArgumentException;
10use Bitrix\Main\Event;
11use Bitrix\Main\IO\File;
12use Bitrix\Main\IO\FileNotFoundException;
13use Bitrix\Main\LoaderException;
14use Bitrix\Main\ObjectPropertyException;
15use Bitrix\Main\SystemException;
16use CCalendarEvent;
17
19{
20 public const CONTENT_TYPES = ['application/ics', 'text/calendar'];
24 private $component;
28 private $handleStatus = false;
29
34 public static function fromComponent(Calendar $component): IncomingInvitationReplyHandler
35 {
36 $handler = new self();
37 $handler->component = $component;
38 return $handler;
39 }
40
45 {
46 return new self();
47 }
48
53 public function __construct()
54 {
55 }
56
64 {
65 $localEvent = Helper::getEventByUId($this->component->getEvent()->getUid());
66 if (!is_null($localEvent))
67 {
68 $user = Helper::getUserById((int)$localEvent['OWNER_ID']);
69 if (
70 $user
71 && $user['EMAIL']
72 && !is_null($attendeeStatus = $this->getAttendeeStatus($user['EMAIL']))
73 )
74 {
75 $this->sendNotificationGuestReaction($localEvent, $attendeeStatus);
76 $this->handleStatus = true;
77 }
78 }
79
80 return $this;
81 }
82
87 private function getAttendeeStatus(string $userEmail): ?string
88 {
89 $attendees = $this->component->getEvent()->getAttendees();
90 if (is_iterable($attendees))
91 {
92 foreach ($attendees as $attendee)
93 {
94 if ($attendee->getParameterValueByName('email') === $userEmail
95 || $this->getMailTo($attendee->getValue()) === $userEmail)
96 {
97 $attendeeStatus = $attendee->getParameterValueByName('partstat');
98 if(array_key_exists($attendeeStatus,Dictionary::ATTENDEES_STATUS))
99 {
100 return Dictionary::ATTENDEES_STATUS[$attendeeStatus];
101 }
102 }
103 }
104 }
105
106 return null;
107 }
108
113 public function sendNotificationGuestReaction(array $event, string $attendeeStatus): void
114 {
115 CCalendarEvent::SetMeetingStatusEx([
116 'attendeeId' => $event['OWNER_ID'],
117 'eventId' => $event['ID'],
118 'status' => $attendeeStatus,
119 'personalNotification' => $event['MEETING_HOST'],
120 'doSendMail' => false,
121 ]);
122 }
123
127 public function isSuccess(): bool
128 {
129 return $this->handleStatus;
130 }
131
140 public static function handleFromRequest(Event $event): bool
141 {
142 $attachments = $event->getParameter('attachments');
143 if (is_array($attachments))
144 {
145 foreach($attachments as $file)
146 {
147 if (in_array($file['type'], self::CONTENT_TYPES, true))
148 {
149 try
150 {
151 $fileObject = new File($file['tmp_name'], $event->getParameter('site_id'));
152 $fileContent = $fileObject->getContents();
153 }
154 catch (FileNotFoundException $e)
155 {
156 return false;
157 }
158
160 ->parseContent()
161 ->getComponent();
162
163 if ($icalComponent?->getMethod() === Dictionary::METHOD['reply'])
164 {
165 return self::fromComponent($icalComponent)
166 ->handle()
167 ->isSuccess();
168 }
169 }
170 }
171 }
172
173 return false;
174 }
175}
static createInstance(string $content)
Определения inboxmanager.php:24
sendNotificationGuestReaction(array $event, string $attendeeStatus)
</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
Определения Image.php:9
$user
Определения mysql_to_pgsql.php:33
$event
Определения prolog_after.php:141