1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
attachmentmanager.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\ICal\MailInvitation;
4
5use Bitrix\Calendar\ICal\Basic\RecurrenceRuleProperty;
6use Bitrix\Calendar\ICal\Builder\Attach;
7use Bitrix\Calendar\ICal\Builder\Attendee;
8use Bitrix\Calendar\ICal\Builder\Calendar;
9use Bitrix\Calendar\ICal\Builder\Dictionary;
10use Bitrix\Calendar\ICal\Builder\Event;
11use Bitrix\Calendar\ICal\Builder\StandardObservances;
12use Bitrix\Calendar\ICal\Builder\Timezone;
13use Bitrix\Calendar\Util;
14use Bitrix\Mail\User;
15use Bitrix\Main\Loader;
16use Bitrix\Main\Localization\Loc;
17use Bitrix\Main\ObjectException;
18use Bitrix\Main\Type\Date;
19
20abstract class AttachmentManager
21{
25 protected $event = [];
29 protected $uid;
30
36 {
37 return new static($event);
38 }
39
44 public function __construct(array $event)
45 {
46 $this->event = $event;
47 }
48
52 public function getUid(): ?string
53 {
54 return $this->uid;
55 }
56
61 protected function prepareDescription(string $description = null): ?string
62 {
63 if (
64 empty($description)
65 && empty($this->event['ICAL_ATTACHES']?->getCollection())
66 )
67 {
68 return null;
69 }
70
72
73 if (!empty($this->event['ICAL_ATTACHES']?->getCollection()))
74 {
75 $description .= "\n" . $this->getFilesDescription();
76 }
77
78 $description = str_replace("\r\n", "\n", $description);
79
80 return preg_replace("/\n{3,}/", "\n\n", $description);
81 }
82
87 protected function prepareRecurrenceRule($rrule): ?RecurrenceRuleProperty
88 {
89 if (is_string($rrule))
90 {
91 $rrule = \CCalendarEvent::ParseRRULE($rrule);
92 }
93
94 return is_array($rrule)
95 ? new RecurrenceRuleProperty($rrule)
96 : null;
97 }
98
102 protected function getFilesDescription(): string
103 {
104 if (empty($this->event['ICAL_ATTACHES']->getCollection()))
105 {
106 return '';
107 }
108
109 $filesDescription = [];
110 if (is_iterable($this->event['ICAL_ATTACHES']))
111 {
112 foreach ($this->event['ICAL_ATTACHES'] as $attach)
113 {
114 if ($attach instanceof Attach)
115 {
116 $filesDescription[] = "{$attach->getName()} ({$attach->getLink()})";
117 }
118 }
119 }
120
121 return Loc::getMessage('EC_FILES_TITLE') . ":\n" . implode("\n", $filesDescription) ."";
122 }
123
129 protected function prepareExDate(string $exDates = null): ?Date
130 {
131 return !$exDates
132 ? null
133 : array_map(function ($exDate) {
134 return new Date($exDate, 'd.m.Y');
135 }, explode(';', $exDates));
136 }
137
142 protected function getOrganizerMailTo(): string
143 {
144 if (!Loader::includeModule('mail'))
145 {
146 return '';
147 }
148
149 $boxes = \Bitrix\Mail\MailboxTable::getUserMailboxes($this->event['MEETING_HOST']);
150 $organizer = $this->event['ICAL_ORGANIZER'];
151 if ($organizer === null)
152 {
153 $user = Helper::getUserById($this->event['MEETING_HOST']);
154 $organizer = Attendee::createInstance(
155 $user['EMAIL'],
156 $user['NAME'],
157 $user['LAST_NAME'],
158 null,
159 null,
160 null,
161 $user['EMAIL'],
162 false
163 );
164 }
165
166 foreach ($boxes as $box)
167 {
169 if ($box['EMAIL'] === $organizer->getMailTo())
170 {
171 return $organizer->getMailTo();
172 }
173 }
174
175 return $this->getReplyAddress();
176
177 }
178
179 protected function getReplyAddress(): string
180 {
181 [$replyTo, $backUrl] = User::getReplyTo(
182 SITE_ID,
183 $this->event['OWNER_ID'],
184 'ICAL_INVENT',
185 $this->event['PARENT_ID'],
186 SITE_ID
187 );
188
189 return $replyTo;
190 }
191
196 protected function parseText(?string $description): string
197 {
198 if (!$description)
199 {
200 return '';
201 }
202
203 return \CTextParser::clearAllTags($description);
204 }
205
206 public function getContent(): string
207 {
209
210 $isFullDay = $this->event['DT_SKIP_TIME'] === 'Y';
211 $icalEvent = Event::createInstance($this->uid)
212 ->setName($event['NAME'])
213 ->setStartsAt(Util::getDateObject($event['DATE_FROM'], $isFullDay, $event['TZ_FROM']))
214 ->setEndsAt(Util::getDateObject($event['DATE_TO'], $isFullDay, $event['TZ_TO']))
215 ->setCreatedAt(Util::getDateObject($event['DATE_CREATE'] ?? null, false, $event['TZ_FROM']))
216 ->setDtStamp(Util::getDateObject($event['DATE_CREATE'] ?? null, false, $event['TZ_FROM']))
217 ->setModified(Util::getDateObject($event['TIMESTAMP_X'] ?? null, false, $event['TZ_FROM']))
218 ->setWithTimezone(!$isFullDay)
219 ->setWithTime(!$isFullDay)
220 ->setDescription($this->prepareDescription($event['DESCRIPTION']))
221 ->setTransparent(Dictionary::TRANSPARENT[$event['ACCESSIBILITY']] ?? Dictionary::TRANSPARENT['busy'])
222 ->setRRule($this->prepareRecurrenceRule($event['RRULE'] ?? null))
223 ->setLocation(\CCalendar::GetTextLocation($event['LOCATION'] ?? null))
224 ->setSequence((int)$event['VERSION'])
225 ->setStatus(Dictionary::EVENT_STATUS['confirmed'])
226 ;
227
228 if (!empty($event['ICAL_ATTENDEES']) && !($event['MEETING']['HIDE_GUESTS'] ?? true))
229 {
230 $icalEvent->setAttendees($event['ICAL_ATTENDEES']);
231 }
232
233 if (!empty($event['ICAL_ORGANIZER']))
234 {
235 $icalEvent->setOrganizer($event['ICAL_ORGANIZER'], $this->getOrganizerMailTo());
236 }
237
239 ->setMethod('REQUEST')
240 ->setTimezones(Timezone::createInstance()
241 ->setTimezoneId(Helper::getTimezoneObject($event['TZ_FROM']))
242 ->setObservance(StandardObservances::createInstance()
243 ->setOffsetFrom(Helper::getTimezoneObject($event['TZ_FROM']))
244 ->setOffsetTo(Helper::getTimezoneObject($event['TZ_TO']))
245 ->setDTStart()
246 )
247 )
248 ->addEvent($icalEvent)
249 ->get();
250 }
251}
static createInstance(string $name=null)
Определения calendar.php:27
prepareDescription(string $description=null)
Определения attachmentmanager.php:61
static getDateObject(string $date=null, ?bool $fullDay=true, ?string $tz='UTC')
Определения util.php:107
static getUserMailboxes($userId=null, bool $onlyIds=false)
Определения mailbox.php:339
Определения date.php:9
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
if($request->getPost('Update') !==null) elseif( $request->getPost( 'Apply') !==null) elseif($request->getPost('RestoreDefaults') !==null) $backUrl
Определения options.php:66
$user
Определения mysql_to_pgsql.php:33
const SITE_ID
Определения sonet_set_content_view.php:12