Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
outcomingattachmentmanager.php
1<?php
2
3
5
6
7use Bitrix\Calendar\ICal\Basic\{AttachmentManager, Dictionary, ICalUtil};
13{
14 AttendeesCollection,
15 Calendar,
16 Event,
17 StandardObservances,
18 Timezone};
20
22{
23 private ?array $event = [];
24 private ?AttendeesCollection $attendees;
25 private ?string $attachment = '';
26 private ?string $method = '';
27 private ?string $uid = '';
28
29 public function __construct($data, $attendees, $method)
30 {
31 $this->event = $data;
32 $this->attendees = $attendees;
33 $this->method = $method;
34 }
35
37 {
38 $event = $this->prepareRequestEvent();
39 $this->uid = isset($event['DAV_XML_ID']) ? $event['DAV_XML_ID'] : ICalUtil::getUniqId();
40
41 $this->attachment = Calendar::createInstance()
42 ->setMethod(Dictionary::METHODS[$this->method])
43 ->setTimezones(Timezone::createInstance()
44 ->setTimezoneId($event['TZ_FROM'])
45 ->setObservance(StandardObservances::createInstance()
46 ->setOffsetFrom($event['TZ_FROM'])
47 ->setOffsetTo($event['TZ_TO'])
48 ->setDTStart()
49 )
50 )
51 ->addEvent(Event::createInstance($this->uid)
52 ->setName($event['NAME'])
53 ->setAttendees($this->attendees)
54 ->setStartsAt(Util::getDateObject($event['DATE_FROM'], $event['SKIP_TIME'], $event['TZ_FROM']))
55 ->setEndsAt(Util::getDateObject($event['DATE_TO'], $event['SKIP_TIME'], $event['TZ_TO']))
56 ->setCreatedAt(Util::getDateObject($event['CREATED'], false, $event['TZ_FROM']))
57 ->setDtStamp(Util::getDateObject($event['CREATED'], false, $event['TZ_FROM']))
58 ->setModified(Util::getDateObject($event['MODIFIED'], false, $event['TZ_FROM']))
59 ->setWithTimezone(!$event['SKIP_TIME'])
60 ->setWithTime(!$event['SKIP_TIME'])
61 ->setOrganizer($this->attendees[$event['MEETING_HOST']], $this->getReplyAddress())
62 ->setDescription($event['DESCRIPTION'])
63 ->setTransparent(Dictionary::TRANSPARENT[$event['ACCESSIBILITY']])
64 ->setRRule($event['RRULE'])
65 ->setExdates($event['EXDATE'])
66 ->setLocation($event['TEXT_LOCATION'])
67 ->setSequence((int)$event['VERSION'])
68 ->setStatus(Dictionary::INVITATION_STATUS['confirmed'])
69 )
70 ->get();
71
72 return $this;
73 }
74
75 public function getAttachment(): string
76 {
77 return $this->attachment;
78 }
79
80 public function getUid()
81 {
82 return $this->uid;
83 }
84
86 {
87 $event = $this->event;
88 $this->uid = $event['DAV_XML_ID'];
89
90 $this->attachment = Calendar::createInstance()
91 ->setMethod(Dictionary::METHODS[$this->method])
92 ->addEvent(Event::createInstance($event['DAV_XML_ID'])
93 ->setName($event['NAME'])
94 ->setAttendees($this->attendees)
95 ->setStartsAt(Util::getDateObject($event['DATE_FROM'], $event['SKIP_TIME'], $event['TZ_FROM']))
96 ->setEndsAt($this->getEndDate($event))
97 // ->setCreatedAt(Util::getDateObject($event['DATE_CREATE'], false, $event['TZ_FROM']))
98 // ->setDtStamp(Helper::getIcalDateTime())
99 ->setDtStamp(Helper::getIcalDateTime('20230828T200641Z'))
100 ->setCreatedAt(Helper::getIcalDateTime('20230828T200631Z'))
101 // ->setModified(Helper::getIcalDateTime())
102 ->setModified(Helper::getIcalDateTime('20230828T200639Z'))
103 ->setWithTimezone(!$event['SKIP_TIME'])
104 ->setWithTime(!$event['SKIP_TIME'])
105 ->setOrganizer(
106 $event['ICAL_ORGANIZER'],
107 $event['ORGANIZER_MAIL']['MAILTO'] ?? $event['ORGANIZER_MAIL']['EMAIL']
108 )
109 ->setTransparent(Dictionary::TRANSPARENT[$event['ACCESSIBILITY']])
110// ->setRRule($event['RRULE'])
111// ->setLocation($event['TEXT_LOCATION'])
112 ->setSequence(((int)$event['VERSION']))
113 ->setStatus(Dictionary::INVITATION_STATUS['confirmed'])
114 ->setUrl($event['URL'])
115 )
116 ->get();
117
118 return $this;
119 }
120
122 {
123 $event = $this->event;
124 $fullDay = $event['DT_SKIP_TIME'] === 'Y';
125
126 $this->attachment = Calendar::createInstance()
127 ->setMethod(Dictionary::METHODS[$this->method])
128 ->addEvent(Event::createInstance($event['DAV_XML_ID'])
129 ->setName($event['NAME'])
130 ->setAttendees($this->attendees)
131 ->setStartsAt(Util::getDateObject($event['DATE_FROM'], $fullDay, $event['TZ_FROM']))
132 ->setEndsAt(Util::getDateObject($event['DATE_TO'], $fullDay, $event['TZ_TO']))
133 ->setCreatedAt(Util::getDateObject($event['DATE_CREATE'], false, $event['TZ_FROM']))
134 ->setDtStamp(Helper::getIcalDateTime())
135 ->setModified(Util::getDateObject($event['TIMESTAMP_X'], false, $event['TZ_FROM']))
136 ->setWithTimezone(!$fullDay)
137 ->setWithTime(!$fullDay)
138 ->setOrganizer($this->attendees[$event['MEETING_HOST']], $this->getReplyAddress())
139 ->setDescription($event['DESCRIPTION'])
140 ->setTransparent(Dictionary::TRANSPARENT[$event['ACCESSIBILITY']])
141// ->setRRule($event['RRULE'])
142 ->setLocation($event['TEXT_LOCATION'])
143 ->setSequence((int)$event['VERSION'] + 1)
144 ->setStatus(Dictionary::INVITATION_STATUS['cancelled'])
145 )
146 ->get();
147
148 return $this;
149 }
150
151 private function getReplyAddress(): string
152 {
153 if (Loader::includeModule('mail'))
154 {
155 [$replyTo, $backUrl] = User::getReplyTo(
156 SITE_ID,
157 $this->event['OWNER_ID'],
158 'ICAL_INVENT',
159 $this->event['PARENT_ID'],
160 SITE_ID
161 );
162 }
163
164 return $replyTo;
165 }
166
167 private function prepareRequestEvent()
168 {
169 $event = $this->event;
170
171 if (!empty($event['ATTACHES']))
172 {
173 $filesDesc = [];
174 foreach ($event['ATTACHES'] as $attach)
175 {
176 $filesDesc[] = $attach['name'] . ' (' . $attach['link'] . ')';
177 }
178
179 if (!empty($event['DESCRIPTION']))
180 {
181 $event['DESCRIPTION'] .= "\r\n";
182 }
183 $event['DESCRIPTION'] .= Loc::getMessage('EC_FILES_TITLE') . ': ' . implode(', ', $filesDesc);
184 }
185
186 return $event;
187 }
188
189 private function getEndDate($event)
190 {
191 if ($event['SKIP_TIME'])
192 {
193 return (Util::getDateObject($event['DATE_TO']))->add('1 days');
194 }
195 else
196 {
197 return Util::getDateObject($event['DATE_TO'], false, $event['TZ_TO']);
198 }
199 }
200}
static createInstance(string $name=null)
Definition calendar.php:27
static getDateObject(string $date=null, ?bool $fullDay=true, ?string $tz='UTC')
Definition util.php:102
static getReplyTo($siteId, $userId, $entityType, $entityId, $entityLink=null, $backurl=null)
Definition user.php:122
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29