1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
incominginvitationcancelhandler.php
См. документацию.
1<?php
2
3
4namespace Bitrix\Calendar\ICal\MailInvitation;
5
6
7use Bitrix\Calendar\Core\Event\Properties\ExcludedDatesCollection;
8use Bitrix\Calendar\ICal\Parser\Calendar;
9use Bitrix\Main\ArgumentException;
10use Bitrix\Main\ObjectException;
11use Bitrix\Main\ObjectPropertyException;
12use Bitrix\Main\SystemException;
13use CCalendar;
14
16{
20 private $userId;
24 private $icalComponent;
25
29 public function __construct()
30 {
31 }
32
38 public static function createWithComponent(int $userId, Calendar $icalComponent): IncomingInvitationCancelHandler
39 {
40 $handler = new self();
41 $handler->userId = $userId;
42 $handler->icalComponent = $icalComponent;
43
44 return $handler;
45 }
46
53 public function handle(): bool
54 {
55 $icalEvent = $this->icalComponent->getEvent();
56 $event = Helper::getEventByUId($icalEvent->getUid());
57
58 if ($event)
59 {
60 if ($icalEvent->getRecurrenceId() !== null)
61 {
62 $date = $this->getExdateFromRecurrenceId($icalEvent->getRecurrenceId());
63 if ($date !== null)
64 {
65 \CCalendarEvent::ExcludeInstance(
66 $event['ID'],
67 $date->format(ExcludedDatesCollection::EXCLUDED_DATE_FORMAT)
68 );
69
70 return true;
71 }
72 }
73 else
74 {
75 return CCalendar::DeleteEvent($event['ID'], true, [
76 'sendNotification' => true,
77 'userId' => (int)$event['OWNER_ID'],
78 ]);
79 }
80 }
81
82 return false;
83 }
84
90 {
91 $this->userId = $userId;
92
93 return $this;
94 }
95
100 private function getExdateFromRecurrenceId(?\Bitrix\Calendar\ICal\Parser\ParserPropertyType $property)
101 {
102 try
103 {
104 if ($property?->getParameterValueByName('value') === 'DATE')
105 {
106 return Helper::getIcalDate($property?->getValue());
107 }
108
109 if ($tz = $property?->getParameterValueByName('tzid'))
110 {
111 return Helper::getIcalDateTime($property?->getValue(), $tz);
112 }
113 }
114 catch (ObjectException)
115 {
116 return null;
117 }
118
119 return null;
120 }
121}
static createWithComponent(int $userId, Calendar $icalComponent)
$event
Определения prolog_after.php:141