1C-Bitrix 25.700.0
event.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\ICal\Builder;
4
5use Bitrix\Calendar\ICal\Basic\AttachPropertytype;
6use Bitrix\Calendar\ICal\Basic\AttendeesProperty;
7use Bitrix\Calendar\ICal\Basic\AttendeesPropertyType;
8use Bitrix\Calendar\ICal\Basic\BasicComponent;
9use Bitrix\Calendar\ICal\Basic\Content;
10use Bitrix\Calendar\ICal\Basic\Dictionary;
11use Bitrix\Calendar\ICal\Basic\RecurrenceRuleProperty;
12use Bitrix\Calendar\ICal\Basic\RecurrenceRulePropertyType;
13use Bitrix\Calendar\ICal\MailInvitation\Helper;
14use Bitrix\Calendar\Util;
15use Bitrix\Main\Localization\Loc;
16use Bitrix\Main\Text\Emoji;
17use Bitrix\Main\Type\Date;
18
20{
21 public const TYPE = 'VEVENT';
22
23 private $alerts = [];
24 private $starts;
25 private $ends;
26 private $name;
27 private $description = '';
28 private $address;
29 private $uid;
30 private $created;
31 private $withTimezone = false;
32 private $classification = null;
33 private $transparent = null;
34 private $attendees = [];
35 private ?AttendeesProperty $organizer = null;
36 private $status = null;
37 private $rrule;
38 private $withTime;
39 private $location = null;
40 private $modified;
41 private $sequence = 0;
42 private $attaches = [];
43 private $exdates = [];
44 private $dtStamp;
45 private $url;
46 private $priority;
47
54 public static function create(array $event, string $type): static
55 {
56 return match ($type)
57 {
58 EventFactoryInterface::REPLY => static::createFromReply($event),
59 EventFactoryInterface::CANCEL => static::createFromCancel($event),
60 EventFactoryInterface::REQUEST => static::createFromRequest($event),
61 };
62 }
63
68 public static function createInstance($uid): Event
69 {
70 return new self($uid);
71 }
72
73 public function __construct($uid)
74 {
75 $this->uid = $uid;
76 }
77
81 public function getType(): string
82 {
83 return self::TYPE;
84 }
85
90 public function setRRule(RecurrenceRuleProperty $rrule = null): Event
91 {
92 $this->rrule = $rrule;
93
94 return $this;
95 }
96
101 public function setWithTime(bool $withTime = false): Event
102 {
103 $this->withTime = $withTime;
104
105 return $this;
106 }
107
112 public function setLocation(string $location = null): Event
113 {
114 $this->location = $location;
115
116 return $this;
117 }
118
123 public function setModified(Date $modified): Event
124 {
125 $this->modified = $modified;
126
127 return $this;
128 }
129
135 public function setSequence(int $sequence): Event
136 {
137 $this->sequence = $sequence;
138
139 return $this;
140 }
141
145 public function getProperties(): array
146 {
147 //TODO: write all properties
148 return [
149 'UID',
150 'DTSTAMP',
151 'DTSTART',
152 ];
153 }
154
159 public function setStartsAt(Date $starts): Event
160 {
161 $this->starts = $starts;
162
163 return $this;
164 }
165
170 public function setEndsAt(Date $ends): Event
171 {
172 $this->ends = $ends;
173
174 return $this;
175 }
176
181 public function setName(string $name = null): Event
182 {
183 $this->name = $name ? Emoji::decode($name) : Loc::getMessage('CAL_ICAL_NEW_EVENT');
184
185 return $this;
186 }
187
192 public function setDescription(string $description = null): Event
193 {
194 $this->description = $description ? Emoji::decode($description) : $description;
195
196 return $this;
197 }
198
203 public function setAddress(string $address = null): Event
204 {
205 $this->address = $address;
206
207 return $this;
208 }
209
214 public function setCreatedAt(Date $created): Event
215 {
216 $this->created = $created;
217
218 return $this;
219 }
220
225 public function setWithTimezone(bool $withTimeZone): Event
226 {
227 $this->withTimezone = $withTimeZone;
228
229 return $this;
230 }
231
236 public function setClassification(string $classification = null): Event
237 {
238 $this->classification = $classification;
239
240 return $this;
241 }
242
247 public function setTransparent(string $transparent): Event
248 {
249 $this->transparent = $transparent;
250
251 return $this;
252 }
253
258 public function setAttendees(iterable $attendees): Event
259 {
260 foreach ($attendees as $attendee)
261 {
262 if ($attendee instanceof Attendee)
263 {
264 $this->attendees[] = new AttendeesProperty(
265 $attendee->getEmail(),
266 $attendee->getFullName(),
267 $attendee->getStatus(),
268 $attendee->getRole(),
269 $attendee->getCuType(),
270 $attendee->getMailTo(),
271 $attendee->isRsvp()
272 );
273 }
274 }
275
276 return $this;
277 }
278
284 public function setOrganizer(Attendee $organizer, string $mailTo): Event
285 {
286 $this->organizer = new AttendeesProperty(
287 $organizer->getEmail(),
288 $organizer->getFullName(),
289 $organizer->getStatus(),
290 $organizer->getRole(),
291 $organizer->getCuType(),
292 $mailTo,
293 $organizer->isRsvp()
294 );
295
296 return $this;
297 }
298
303 public function setStatus(string $status): Event
304 {
305 $this->status = $status;
306
307 return $this;
308 }
309
314 public function setAttaches(array $attaches = null): Event
315 {
316 $this->attaches[] = $attaches;
317
318 return $this;
319 }
320
325 public function setExdates(array $exdates = null): Event
326 {
327 $this->exdates = $exdates;
328
329 return $this;
330 }
331
336 public function setDtStamp(Date $dtStamp): Event
337 {
338 $this->dtStamp = $dtStamp;
339
340 return $this;
341 }
342
347 public function setUrl($url): Event
348 {
349 $this->url = $url;
350
351 return $this;
352 }
353
357 public function setAlerts(array $alerts): Event
358 {
359 $this->alerts = $alerts;
360
361 return $this;
362 }
363
364 public function setPriority(int $priority): Event
365 {
366 $this->priority = $priority;
367
368 return $this;
369 }
370
374 public function setContent(): Content
375 {
376 $content = Content::getInstance(self::TYPE)
377 ->textProperty('UID', $this->uid)
378 ->textProperty('SUMMARY', $this->name)
379 ->textProperty('DESCRIPTION', $this->description)
380 ->textProperty('LOCATION', $this->address)
381 ->textProperty('CLASS', $this->classification)
382 ->textProperty('TRANSP', $this->transparent)
383 ->textProperty('STATUS', $this->status)
384 ->textProperty('LOCATION', $this->location)
385 ->textProperty('SEQUENCE', $this->sequence)
386 ->dateTimeProperty('DTSTART', $this->starts, $this->withTime, $this->withTimezone)
387 ->dateTimeProperty('DTEND', $this->ends, $this->withTime, $this->withTimezone)
388 ->dateTimeProperty('DTSTAMP', $this->dtStamp, true, false, true)
389 ->dateTimeProperty('CREATED', $this->created, true, false, true)
390 ->dateTimeProperty('LAST-MODIFIED', $this->modified, true, false, true)
391 ->subComponent(...$this->alerts);
392
393 if ($this->organizer !== null)
394 {
395 $content->property(AttendeesPropertyType::createInstance('ORGANIZER', $this->organizer));
396 }
397
398 foreach ($this->attendees as $attendee)
399 {
400 $content->property(AttendeesPropertyType::createInstance('ATTENDEE', $attendee));
401 }
402
403 if ($this->isRecurringEvent())
404 {
405 $content->property(RecurrenceRulePropertyType::createInstance('RRULE', $this->rrule));
406
407 if (!empty($this->exdates))
408 {
409 foreach ($this->exdates as $exdate)
410 {
411 $content->dateTimeProperty('EXDATE', $exdate, $this->withTime, $this->withTimezone);
412 }
413 }
414 }
415
416 if (!empty($this->attaches))
417 {
418 foreach ($this->attaches as $attach)
419 {
420 $content->property(AttachPropertyType::getInstance('ATTACH', $attach));
421 }
422 }
423
424 if (!empty($this->url))
425 {
426 $content->textProperty('URL', $this->url);
427 }
428
429 if (!empty($this->priority))
430 {
431 $content->textProperty('PRIORITY', $this->priority);
432 }
433
434 return $content;
435 }
436
440 private function isRecurringEvent(): bool
441 {
442 return !empty($this->rrule) && !empty($this->rrule->freq) && $this->rrule->freq !== 'NONE';
443 }
444
450 private function getEndDateByEvent(array $event)
451 {
452 return $event['SKIP_TIME']
453 ? Util::getDateObject($event['DATE_TO'])->add('1 days')
454 : Util::getDateObject($event['DATE_TO'], false, $event['TZ_TO'])
455 ;
456 }
457
463 private static function createFromReply(array $event): static
464 {
465 $instance = new static($event['DAV_XML_ID']);
466
467 return $instance
468 ->setName($event['NAME'])
469 ->setStartsAt(
470 Util::getDateObject($event['DATE_FROM'], $event['SKIP_TIME'], $event['TZ_FROM'])
471 )
472 ->setEndsAt($instance->getEndDateByEvent($event))
473 ->setDtStamp(Helper::getIcalDateTime())
474 ->setCreatedAt(Util::getDateObject($event['DATE_CREATE'], false, $event['TZ_FROM']))
475 ->setModified(Util::getDateObject($event['TIMESTAMP_X'], false, $event['TZ_FROM']))
476 ->setWithTimezone(!$event['SKIP_TIME'])
477 ->setWithTime(!$event['SKIP_TIME'])
478 ->setOrganizer(
479 $event['ICAL_ORGANIZER'],
480 $event['ORGANIZER_MAIL']['MAILTO'] ?? $event['ORGANIZER_MAIL']['EMAIL']
481 )
482 ->setTransparent(Dictionary::TRANSPARENT[$event['ACCESSIBILITY']] ?? Dictionary::TRANSPARENT['busy'])
483 ->setSequence(((int)$event['VERSION']))
484 ->setStatus(Dictionary::INVITATION_STATUS['confirmed'])
485 ->setUrl($event['URL'] ?? null)
486 ;
487 }
488
494 private static function createFromCancel(array $event): static
495 {
496 $fullDay = $event['DT_SKIP_TIME'] === 'Y';
497
498 return (new static($event['DAV_XML_ID']))
499 ->setName($event['NAME'])
500 ->setStartsAt(Util::getDateObject($event['DATE_FROM'], $fullDay, $event['TZ_FROM']))
501 ->setEndsAt(Util::getDateObject($event['DATE_TO'], $fullDay, $event['TZ_TO']))
502 ->setCreatedAt(Util::getDateObject($event['DATE_CREATE'], false, $event['TZ_FROM']))
503 ->setDtStamp(Helper::getIcalDateTime())
504 ->setModified(Util::getDateObject($event['TIMESTAMP_X'], false, $event['TZ_FROM']))
505 ->setWithTimezone(!$fullDay)
506 ->setWithTime(!$fullDay)
507 ->setDescription($event['DESCRIPTION'])
508 ->setTransparent(Dictionary::TRANSPARENT[$event['ACCESSIBILITY']] ?? Dictionary::TRANSPARENT['busy'])
509 ->setLocation($event['TEXT_LOCATION'])
510 ->setSequence((int)$event['VERSION'] + 1)
511 ->setStatus(Dictionary::INVITATION_STATUS['cancelled'])
512 ;
513 }
514
520 private static function createFromRequest(array $event): static
521 {
522 return (new static($event['DAV_XML_ID']))
523 ->setName($event['NAME'])
524 ->setStartsAt(Util::getDateObject($event['DATE_FROM'], $event['SKIP_TIME'], $event['TZ_FROM']))
525 ->setEndsAt(Util::getDateObject($event['DATE_TO'], $event['SKIP_TIME'], $event['TZ_TO']))
526 ->setCreatedAt(Util::getDateObject($event['CREATED'], false, $event['TZ_FROM']))
527 ->setDtStamp(Util::getDateObject($event['CREATED'], false, $event['TZ_FROM']))
528 ->setModified(Util::getDateObject($event['MODIFIED'], false, $event['TZ_FROM']))
529 ->setWithTimezone(!$event['SKIP_TIME'])
530 ->setWithTime(!$event['SKIP_TIME'])
531 ->setDescription($event['DESCRIPTION'])
532 ->setTransparent(Dictionary::TRANSPARENT[$event['ACCESSIBILITY']] ?? Dictionary::TRANSPARENT['busy'])
533 ->setRRule($event['RRULE'])
534 ->setExdates($event['EXDATE'])
535 ->setLocation($event['TEXT_LOCATION'])
536 ->setSequence((int)$event['VERSION'])
537 ->setStatus(Dictionary::INVITATION_STATUS['confirmed'])
538 ;
539 }
540}
$type
Определения options.php:106
static getInstance($names, AttachProperty $attach)
Определения attachpropertytype.php:11
static createInstance($names, AttendeesProperty $calendarAddress)
Определения attendeespropertytype.php:11
static createInstance($names, RecurrenceRuleProperty $rrule)
Определения recurrencerulepropertytype.php:11
setExdates(array $exdates=null)
Определения event.php:325
setTransparent(string $transparent)
Определения event.php:247
__construct($uid)
Определения event.php:73
setAttaches(array $attaches=null)
Определения event.php:314
setRRule(RecurrenceRuleProperty $rrule=null)
Определения event.php:90
setName(string $name=null)
Определения event.php:181
setCreatedAt(Date $created)
Определения event.php:214
static create(array $event, string $type)
Определения event.php:54
setEndsAt(Date $ends)
Определения event.php:170
setWithTime(bool $withTime=false)
Определения event.php:101
setAttendees(iterable $attendees)
Определения event.php:258
setWithTimezone(bool $withTimeZone)
Определения event.php:225
setOrganizer(Attendee $organizer, string $mailTo)
Определения event.php:284
setStatus(string $status)
Определения event.php:303
setAlerts(array $alerts)
Определения event.php:357
setStartsAt(Date $starts)
Определения event.php:159
static createInstance($uid)
Определения event.php:68
setAddress(string $address=null)
Определения event.php:203
setLocation(string $location=null)
Определения event.php:112
setDtStamp(Date $dtStamp)
Определения event.php:336
setSequence(int $sequence)
Определения event.php:135
setClassification(string $classification=null)
Определения event.php:236
setDescription(string $description=null)
Определения event.php:192
setModified(Date $modified)
Определения event.php:123
setPriority(int $priority)
Определения event.php:364
static getDateObject(string $date=null, ?bool $fullDay=true, ?string $tz='UTC')
Определения util.php:107
Определения date.php:9
$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
$event
Определения prolog_after.php:141
$instance
Определения ps_b24_final.php:14