Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
attachmentmanager.php
1<?php
2
3
5
6
15
16abstract class AttachmentManager
17{
21 protected $event = [];
25 protected $uid;
26
27 abstract public function getContent(): string;
28
33 public static function createInstance(array $event): AttachmentManager
34 {
35 return new static($event);
36 }
37
42 public function __construct(array $event)
43 {
44 $this->event = $event;
45 }
46
50 public function getUid(): ?string
51 {
52 return $this->uid;
53 }
54
59 protected function prepareDescription(string $description = null): ?string
60 {
61 if (
62 empty($description)
63 && (empty($this->event['ICAL_ATTACHES'])
64 || empty($this->event['ICAL_ATTACHES']->getCollection())
65 )
66 )
67 {
68 return null;
69 }
70
71 $description = $this->parseText($description);
72
73 if (empty($this->event['ICAL_ATTACHES']->getCollection()))
74 {
75 return str_replace("\r\n", " \n", $description);
76 }
77
78 return str_replace("\r\n", " \n", $description . "\n" . $this->getFilesDescription());
79 }
80
85 protected function prepareRecurrenceRule($rrule): ?RecurrenceRuleProperty
86 {
87 if (is_string($rrule))
88 {
89 $rrule = \CCalendarEvent::ParseRRULE($rrule);
90 }
91
92 return is_array($rrule)
93 ? new RecurrenceRuleProperty($rrule)
94 : null;
95 }
96
100 protected function getFilesDescription(): string
101 {
102 if (empty($this->event['ICAL_ATTACHES']->getCollection()))
103 {
104 return '';
105 }
106
107 $filesDescription = [];
108 if (is_iterable($this->event['ICAL_ATTACHES']))
109 {
110 foreach ($this->event['ICAL_ATTACHES'] as $attach)
111 {
112 if ($attach instanceof Attach)
113 {
114 $filesDescription[] = "{$attach->getName()} ({$attach->getLink()})";
115 }
116 }
117 }
118
119 return Loc::getMessage('EC_FILES_TITLE') . ":\n" . implode("\n", $filesDescription) ."";
120 }
121
127 protected function prepareExDate(string $exDates = null): ?Date
128 {
129 return !$exDates
130 ? null
131 : array_map(function ($exDate) {
132 return new Date($exDate, 'd.m.Y');
133 }, explode(';', $exDates));
134 }
135
140 protected function getOrganizerMailTo(): string
141 {
142 if (!Loader::includeModule('mail'))
143 {
144 return '';
145 }
146
147 $boxes = \Bitrix\Mail\MailboxTable::getUserMailboxes($this->event['MEETING_HOST']);
148 $organizer = $this->event['ICAL_ORGANIZER'];
149 if ($organizer === null)
150 {
151 $user = Helper::getUserById($this->event['MEETING_HOST']);
152 $organizer = Attendee::createInstance(
153 $user['EMAIL'],
154 $user['NAME'],
155 $user['LAST_NAME'],
156 null,
157 null,
158 null,
159 $user['EMAIL'],
160 false
161 );
162 }
163
164 foreach ($boxes as $box)
165 {
167 if ($box['EMAIL'] === $organizer->getMailTo())
168 {
169 return $organizer->getMailTo();
170 }
171 }
172
173 return $this->getReplyAddress();
174
175 }
176
177 protected function getReplyAddress(): string
178 {
179 [$replyTo, $backUrl] = User::getReplyTo(
180 SITE_ID,
181 $this->event['OWNER_ID'],
182 'ICAL_INVENT',
183 $this->event['PARENT_ID'],
184 SITE_ID
185 );
186
187 return $replyTo;
188 }
189
194 protected function parseText(?string $description): string
195 {
196 if (!$description)
197 {
198 return '';
199 }
200
201 return \CTextParser::clearAllTags($description);
202 }
203}
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