Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
event.php
1<?php
2
4
5use Bitrix\Calendar\ICal\Basic\AttachPropertytype;
15
16class Event extends BasicComponent implements BuilderComponent
17{
18 public const TYPE = 'VEVENT';
19
20 private $alerts = [];
21 private $starts;
22 private $ends;
23 private $name;
24 private $description = '';
25 private $address;
26 private $uid;
27 private $created;
28 private $withTimezone = false;
29 private $classification = null;
30 private $transparent = null;
31 private $attendees = [];
32 private $organizer = null;
33 private $status = null;
34 private $rrule;
35 private $withTime;
36 private $location = null;
37 private $modified;
38 private $sequence = 0;
39 private $attaches = [];
40 private $exdates = [];
41 private $dtStamp;
42 private $url;
43
48 public static function createInstance($uid): EVent
49 {
50 return new self($uid);
51 }
52
53 public function __construct($uid)
54 {
55 $this->uid = $uid;
56 }
57
61 public function getType(): string
62 {
63 return self::TYPE;
64 }
65
70 public function setRRule(RecurrenceRuleProperty $rrule = null): Event
71 {
72 $this->rrule = $rrule;
73
74 return $this;
75 }
76
81 public function setWithTime(bool $withTime = false): Event
82 {
83 $this->withTime = $withTime;
84
85 return $this;
86 }
87
92 public function setLocation(string $location = null): Event
93 {
94 $this->location = $location;
95
96 return $this;
97 }
98
103 public function setModified(Date $modified): Event
104 {
105 $this->modified = $modified;
106
107 return $this;
108 }
109
115 public function setSequence(int $sequence): Event
116 {
117 $this->sequence = $sequence;
118
119 return $this;
120 }
121
125 public function getProperties(): array
126 {
127 //TODO: write all properties
128 return [
129 'UID',
130 'DTSTAMP',
131 'DTSTART',
132 ];
133 }
134
139 public function setStartsAt(Date $starts): Event
140 {
141 $this->starts = $starts;
142
143 return $this;
144 }
145
150 public function setEndsAt(Date $ends): Event
151 {
152 $this->ends = $ends;
153
154 return $this;
155 }
156
161 public function setName(string $name = null): Event
162 {
163 $this->name = $name ? Emoji::decode($name) : Loc::getMessage('CAL_ICAL_NEW_EVENT');
164
165 return $this;
166 }
167
172 public function setDescription(string $description = null): Event
173 {
174 $this->description = $description ? Emoji::decode($description) : $description;
175
176 return $this;
177 }
178
183 public function setAddress(string $address = null): Event
184 {
185 $this->address = $address;
186
187 return $this;
188 }
189
194 public function setCreatedAt(Date $created): Event
195 {
196 $this->created = $created;
197
198 return $this;
199 }
200
205 public function setWithTimezone(bool $withTimeZone): Event
206 {
207 $this->withTimezone = $withTimeZone;
208
209 return $this;
210 }
211
216 public function setClassification(string $classification = null): Event
217 {
218 $this->classification = $classification;
219
220 return $this;
221 }
222
227 public function setTransparent(string $transparent): Event
228 {
229 $this->transparent = $transparent;
230
231 return $this;
232 }
233
238 public function setAttendees(iterable $attendees): Event
239 {
240 foreach ($attendees as $attendee)
241 {
242 if ($attendee instanceof Attendee)
243 {
244 $this->attendees[] = new AttendeesProperty(
245 $attendee->getEmail(),
246 $attendee->getFullName(),
247 $attendee->getStatus(),
248 $attendee->getRole(),
249 $attendee->getCuType(),
250 $attendee->getMailTo(),
251 $attendee->isRsvp()
252 );
253 }
254 }
255
256 return $this;
257 }
258
264 public function setOrganizer(Attendee $organizer, string $mailTo): Event
265 {
266 $this->organizer = new AttendeesProperty(
267 $organizer->getEmail(),
268 $organizer->getFullName(),
269 $organizer->getStatus(),
270 $organizer->getRole(),
271 $organizer->getCuType(),
272 $mailTo,
273 $organizer->isRsvp()
274 );
275
276 return $this;
277 }
278
283 public function setStatus(string $status): Event
284 {
285 $this->status = $status;
286
287 return $this;
288 }
289
294 public function setAttaches(array $attaches = null): Event
295 {
296 $this->attaches[] = $attaches;
297
298 return $this;
299 }
300
305 public function setExdates(array $exdates = null): Event
306 {
307 $this->exdates = $exdates;
308
309 return $this;
310 }
311
316 public function setDtStamp(Date $dtStamp): Event
317 {
318 $this->dtStamp = $dtStamp;
319
320 return $this;
321 }
322
327 public function setUrl($url): Event
328 {
329 $this->url = $url;
330
331 return $this;
332 }
333
337 public function setContent(): Content
338 {
339 $content = Content::getInstance(self::TYPE)
340 ->textProperty('UID', $this->uid)
341 ->textProperty('SUMMARY', $this->name)
342 ->textProperty('DESCRIPTION', $this->description)
343 ->textProperty('LOCATION', $this->address)
344 ->textProperty('CLASS', $this->classification)
345 ->textProperty('TRANSP', $this->transparent)
346 ->textProperty('STATUS', $this->status)
347 ->textProperty('LOCATION', $this->location)
348 ->textProperty('SEQUENCE', $this->sequence)
349 ->property(AttendeesPropertyType::createInstance('ORGANIZER', $this->organizer))
350 ->dateTimeProperty('DTSTART', $this->starts, $this->withTime, $this->withTimezone)
351 ->dateTimeProperty('DTEND', $this->ends, $this->withTime, $this->withTimezone)
352 ->dateTimeProperty('DTSTAMP', $this->dtStamp, true, false, true)
353 ->dateTimeProperty('CREATED', $this->created, true, false, true)
354 ->dateTimeProperty('LAST-MODIFIED', $this->modified, true, false, true)
355 ->subComponent(...$this->alerts);
356
357 foreach ($this->attendees as $attendee)
358 {
359 $content->property(AttendeesPropertyType::createInstance('ATTENDEE', $attendee));
360 }
361
362 if ($this->isRecurringEvent())
363 {
364 $content->property(RecurrenceRulePropertyType::createInstance('RRULE', $this->rrule));
365
366 if (!empty($this->exdates))
367 {
368 foreach ($this->exdates as $exdate)
369 {
370 $content->dateTimeProperty('EXDATE', $exdate, $this->withTime, $this->withTimezone);
371 }
372 }
373 }
374
375 if (!empty($this->attaches))
376 {
377 foreach ($this->attaches as $attach)
378 {
379 $content->property(AttachPropertyType::getInstance('ATTACH', $attach));
380 }
381 }
382
383 if (!empty($this->url))
384 {
385 $content->textProperty('URL', $this->url);
386 }
387
388 return $content;
389 }
390
394 private function isRecurringEvent(): bool
395 {
396 return !empty($this->rrule) && !empty($this->rrule->freq) && $this->rrule->freq !== 'NONE';
397 }
398}
static getInstance($names, AttachProperty $attach)
static createInstance($names, AttendeesProperty $calendarAddress)
textProperty($names, ?string $value, bool $disableEscaping=false)
Definition content.php:48
static createInstance($names, RecurrenceRuleProperty $rrule)
setExdates(array $exdates=null)
Definition event.php:305
setTransparent(string $transparent)
Definition event.php:227
setAttaches(array $attaches=null)
Definition event.php:294
setRRule(RecurrenceRuleProperty $rrule=null)
Definition event.php:70
setName(string $name=null)
Definition event.php:161
setWithTime(bool $withTime=false)
Definition event.php:81
setAttendees(iterable $attendees)
Definition event.php:238
setWithTimezone(bool $withTimeZone)
Definition event.php:205
setOrganizer(Attendee $organizer, string $mailTo)
Definition event.php:264
setAddress(string $address=null)
Definition event.php:183
setLocation(string $location=null)
Definition event.php:92
setClassification(string $classification=null)
Definition event.php:216
setDescription(string $description=null)
Definition event.php:172
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29