1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
senderinvitation.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\ICal\MailInvitation;
4
5use Bitrix\Calendar\Core;
6use Bitrix\Calendar\Public;
7use Bitrix\Calendar\Sharing;
8use Bitrix\Calendar\SerializeObject;
9use Bitrix\Calendar\Util;
10use Bitrix\Main\ArgumentException;
11use Bitrix\Main\LoaderException;
12use Bitrix\Main\Mail\Event;
13use Bitrix\Main\NotImplementedException;
14use Bitrix\Main\ObjectPropertyException;
15use Bitrix\Main\SystemException;
16use Bitrix\Main\Type\DateTime;
17use CEvent;
18use \Serializable;
19
24abstract class SenderInvitation implements Serializable
25{
26 use SerializeObject;
27
28 public const CHARSET = 'utf-8';
29 public const CONTENT_TYPE = 'text/calendar';
30 protected const ATTACHMENT_NAME = 'invite.ics';
31 protected const MAIL_TEMPLATE = 'SEND_ICAL_INVENT';
32
36 protected int $counterInvitations = 0;
40 protected ?array $event = null;
44 protected ?Context $context = null;
48 protected ?string $uid = '';
49
50 abstract public function executeAfterSuccessfulInvitation();
51 abstract protected function getContent();
52 abstract protected function getTemplateParams();
53 abstract protected function getSubjectTitle();
54
56 {
57 return new static($event, $context);
58 }
59
61 {
62 $this->event = $event;
63 $this->context = $context;
64 }
65
66 public function setCounterInvitations(?int $counterInvitations): static
67 {
68 $this->counterInvitations = $counterInvitations ?? 0;
69
70 return $this;
71 }
72
73 public function setEvent(?array $event): static
74 {
75 $this->event = $event;
76
77 return $this;
78 }
79
88 public function send(): bool
89 {
90 if ($this->event === null || $this->context === null)
91 {
92 return false;
93 }
94
95 $this->prepareEventFields();
96
97 $content = $this->getContent();
98 if (!$content)
99 {
100 return false;
101 }
102
103 $fields = $this->getMailEventFields();
104 $params = array_merge($this->getBaseTemplateParams(), $this->getTemplateParams());
105
106 $status = CEvent::sendImmediate(
107 self::MAIL_TEMPLATE,
108 SITE_ID,
109 array_merge($fields, $params),
110 'Y',
111 '',
112 [],
113 '',
114 $content,
115 );
116
117 return $status === Event::SEND_RESULT_SUCCESS;
118 }
119
120 protected function getMailEventFields(): array
121 {
122 return [
123 "=Reply-To" => "{$this->getAddresser()->getFullName()} <{$this->getAddresser()->getEmail()}>",
124 "=From" => "{$this->getAddresser()->getFullName()} <{$this->getAddresser()->getEmail()}>",
125 "=Message-Id" => $this->getMessageId(),
126 "=In-Reply-To" => $this->getMessageReplyTo(),
127 'EMAIL_FROM' => $this->getAddresser()->getEmail(),
128 'EMAIL_TO' => $this->getReceiver()->getEmail(),
129 'MESSAGE_SUBJECT' => $this->getSubjectMessage(),
130 'MESSAGE_PHP' => $this->getBodyMessage(),
131 ];
132 }
133
134 private function getBaseTemplateParams(): array
135 {
137 $this->getEventId(),
138 $this->getEventOwnerId(),
140 );
141
142 return [
143 'EVENT_NAME' => $this->event['NAME'],
144 'DATE_FROM' => $this->event['DATE_FROM'],
145 'DATE_TO' => $this->event['DATE_TO'],
146 'IS_FULL_DAY' => $this->event['DT_SKIP_TIME'] === 'Y',
147 'TZ_FROM' => $this->event['TZ_FROM'],
148 'TZ_TO' => $this->event['TZ_TO'],
149 'AVATARS' => $this->event['AVATARS'],
150 'OWNER_STATUS' => $this->event['OWNER_STATUS'],
151 'RRULE' => $this->getRRuleString(),
152
153 'DETAIL_LINK' => $detailLink,
154 'ICS_LINK' => $detailLink . Public\PublicEvent::ACTION_ICS,
155 'DECISION_YES_LINK' => $detailLink . Public\PublicEvent::ACTION_ACCEPT,
156 'DECISION_NO_LINK' => $detailLink . Public\PublicEvent::ACTION_DECLINE,
157 'BITRIX24_LINK' => Sharing\Helper::getBitrix24Link(),
158 ];
159 }
160
161 protected function getMessageReplyTo(): string
162 {
163 return $this->getMessageId();
164 }
165
169 protected function getRRuleString(): string
170 {
171 $rrule = \CCalendarEvent::ParseRRULE($this->event['RRULE']);
172 if (is_array($rrule))
173 {
174 return Helper::getIcalTemplateRRule(
175 $rrule,
176 [
177 'DATE_FROM' => $this->event['DATE_FROM'],
178 ],
179 );
180 }
181
182 return '';
183 }
184
188 public function getMethod(): string
189 {
190 return static::METHOD;
191 }
192
196 public function getEvent(): array
197 {
198 return $this->event ?? [];
199 }
200
204 public function incrementCounterInvitations(): void
205 {
206 $this->counterInvitations++;
207 }
208
212 public function getUid(): string
213 {
214 return $this->uid;
215 }
216
220 public function getCountAttempsSend(): int
221 {
223 }
224
228 public function getAddresser():MailAddresser
229 {
230 return $this->context->getAddresser();
231 }
232
236 public function getReceiver(): MailReceiver
237 {
238 return $this->context->getReceiver();
239 }
240
244 public function getEventId(): ?int
245 {
246 return $this->event['ID'] ?? null;
247 }
248
252 public function getEventParentId(): int
253 {
254 return (int) ($this->event['PARENT_ID'] ?? 0);
255 }
256
260 protected function getBodyMessage(): string
261 {
262 //@TODO edit body message
263 return 'ical body message';
264 }
265
269 protected function getSiteName(): string
270 {
271 if (!empty($siteName = \COption::GetOptionString("main", "site_name", '', '-')))
272 {
273 return "[{$siteName}]";
274 }
275
276 return '';
277 }
278
282 protected function getSubjectMessage(): string
283 {
284 return $this->getSiteName(). ' ' . $this->getSubjectTitle();
285 }
286
290 protected function getMessageId(): string
291 {
292 $serverName = \COption::GetOptionString("main", "server_name", $GLOBALS["SERVER_NAME"]);
293
294 return "<CALENDAR_EVENT_{$this->getEventParentId()}@{$serverName}>";
295 }
296
300 protected function getEventDateCreateTimestamp(): int
301 {
302 return (int) Util::getTimestamp($this->event['DATE_CREATE']);
303 }
304
308 protected function getEventOwnerId(): int
309 {
310 return (int) $this->event['OWNER_ID'];
311 }
312
313 private function getFormattedDate(DateTime $formattedDate, string $dtSkipTime): string
314 {
315 $timestamp = \CCalendar::Timestamp($formattedDate, false, $dtSkipTime !== 'Y');
316
317 return \CCalendar::Date($timestamp);
318 }
319
320
328 protected function prepareEventFields(): void
329 {
330 $dtSkipTime = $this->event['DT_SKIP_TIME'];
331 $this->event['DATE_FROM'] = $this->getFormattedDate($this->event['DATE_FROM'], $dtSkipTime);
332 $this->event['DATE_TO'] = $this->getFormattedDate($this->event['DATE_TO'], $dtSkipTime);
333 $this->event['DATE_CREATE'] = $this->event['DATE_CREATE']->toString();
334 $this->event['TIMESTAMP_X'] = $this->event['TIMESTAMP_X']->toString();
335
336 $this->event['MEETING'] = unserialize($this->event['MEETING'], ['allowed_classes' => false]);
337 $this->event['REMIND'] = unserialize($this->event['REMIND'], ['allowed_classes' => false]);
338 $this->event['RRULE'] = \CCalendarEvent::ParseRRULE($this->event['RRULE']);
339 $this->event['ATTENDEES_CODES'] = !empty($this->event['ATTENDEES_CODES']) && is_string($this->event['ATTENDEES_CODES'])
340 ? explode(',', $this->event['ATTENDEES_CODES'])
341 : []
342 ;
343 $this->event['ICAL_ORGANIZER'] = Helper::getAttendee($this->event['MEETING_HOST'], $this->event['PARENT_ID'], false);
344 $this->event['ICAL_ATTACHES'] = Helper::getMailAttaches(
345 null,
346 $this->event['MEETING_HOST'],
347 $this->event['PARENT_ID']
348 );
349
350 $event = (new Core\Mappers\Event())->getByArray($this->event);
351 $this->event['DESCRIPTION'] = Public\PublicEvent::prepareEventDescriptionForIcs($event);
352
353 $attendees = \CCalendarEvent::GetAttendees([$this->event['PARENT_ID']], false)[$this->event['PARENT_ID']] ?? [];
354
355 $ownerId = (int)$this->event['OWNER_ID'];
356 $owner = current(array_filter(
357 $attendees,
358 static fn($attendee) => (int)$attendee['USER_ID'] === $ownerId,
359 ));
360
361 $this->event['OWNER_STATUS'] = $owner['STATUS'];
362
363 $this->event['AVATARS'] = [];
364 if (!$this->event['MEETING']['HIDE_GUESTS'])
365 {
366 usort($attendees, static fn($a, $b) => ((int)$b['USER_ID'] === $ownerId) - ((int)$a['USER_ID'] === $ownerId));
367 foreach ($attendees as $attendee)
368 {
369 $this->event['AVATARS'][] = $attendee['AVATAR'];
370 }
371 $this->event['ICAL_ATTENDEES'] = Helper::getAttendeesByEventParentId($this->event['PARENT_ID']);
372 }
373 }
374}
static createInstance(array $event, Context $context)
Определения senderinvitation.php:55
setCounterInvitations(?int $counterInvitations)
Определения senderinvitation.php:66
__construct(array $event, Context $context)
Определения senderinvitation.php:60
static getDetailLink(int $eventId, int $userId, int $dateCreateTimestamp)
Определения publicevent.php:56
static prepareEventDescriptionForIcs(Event $event)
Определения publicevent.php:82
static getBitrix24Link()
Определения helper.php:414
static getTimestamp($date, $round=true, $getTime=true)
Определения util.php:60
$content
Определения commerceml.php:144
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$status
Определения session.php:10
Определения culture.php:9
$GLOBALS['____1690880296']
Определения license.php:1
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
else $a
Определения template.php:137
const SITE_ID
Определения sonet_set_content_view.php:12
$fields
Определения yandex_run.php:501