Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
incominginvitationcancelhandler.php
1<?php
2
3
5
6
12use CCalendar;
13
15{
19 private $userId;
23 private $icalComponent;
24
28 public function __construct()
29 {
30 }
31
37 public static function createWithComponent(int $userId, Calendar $icalComponent): IncomingInvitationCancelHandler
38 {
39 $handler = new self();
40 $handler->userId = $userId;
41 $handler->icalComponent = $icalComponent;
42
43 return $handler;
44 }
45
52 public function handle(): bool
53 {
54 $icalEvent = $this->icalComponent->getEvent();
55 $event = Helper::getEventByUId($icalEvent->getUid());
56
57 if ($event)
58 {
59 if ($icalEvent->getRecurrenceId() !== null)
60 {
61 $date = $this->getExdateFromRecurrenceId($icalEvent->getRecurrenceId());
62 if ($date !== null)
63 {
64 \CCalendarEvent::ExcludeInstance(
65 $event['ID'],
66 $date->format(ExcludedDatesCollection::EXCLUDED_DATE_FORMAT)
67 );
68
69 return true;
70 }
71 }
72 else
73 {
74 return CCalendar::DeleteEvent($event['ID'], true, [
75 'sendNotification' => true,
76 'userId' => (int)$event['OWNER_ID'],
77 ]);
78 }
79 }
80
81 return false;
82 }
83
89 {
90 $this->userId = $userId;
91
92 return $this;
93 }
94
95 private function getExdateFromRecurrenceId(?\Bitrix\Calendar\ICal\Parser\ParserPropertyType $property)
96 {
97 if ($property->getParameterValueByName('value') === 'DATE')
98 {
99 return Helper::getIcalDate($property->getValue());
100 }
101 elseif ($tz = $property->getParameterValueByName('tzid'))
102 {
103 return Helper::getIcalDateTime($property->getValue(), $tz);
104 }
105
106 return null;
107 }
108}
static getIcalDate(string $date=null)
Definition helper.php:533
static getIcalDateTime(string $dateTime=null, string $tz=null)
Definition helper.php:521