Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
eventbuilderfromentityobject.php
1<?php
2
3
5
21use Bitrix\Calendar\Internals\EO_Event;
29use CCalendarEvent;
30
32{
36 private EO_Event $event;
37
41 public function __construct(EO_Event $event)
42 {
43 $this->event = $event;
44 }
45
49 protected function getId(): ?int
50 {
51 return $this->event->getId();
52 }
53
54 protected function getParentId(): ?int
55 {
56 return $this->event->getParentId();
57 }
58
59 protected function getName(): string
60 {
61 return $this->event->getName();
62 }
63
64 protected function getStartTimezone(): ?DateTimeZone
65 {
66 if (!$this->event->getTzFrom())
67 {
68 return null;
69 }
70
71 return new DateTimeZone(Util::prepareTimezone($this->event->getTzFrom()));
72 }
73
74 protected function getEndTimezone(): ?DateTimeZone
75 {
76 if (!$this->event->getTzTo())
77 {
78 return null;
79 }
80
81 return new DateTimeZone(Util::prepareTimezone($this->event->getTzTo()));
82 }
83
89 {
90 $rule = CCalendarEvent::convertDateToCulture($this->event->getRrule());
91 return $this->prepareRecurringRule(
92 CCalendarEvent::ParseRRULE($rule)
93 );
94 }
95
96 protected function getLocation(): ?Location
97 {
98 return $this->prepareLocation($this->event->getLocation());
99 }
100
104 protected function getStart(): Date
105 {
106 return new Date(Util::getDateObject(
107 $this->event->getDateFrom()
108 ? $this->event->getDateFrom()->format(\Bitrix\Main\Type\Date::convertFormatToPhp(FORMAT_DATETIME))
109 : null
110 ,
111 false,
112 $this->getStartTimezone() ? $this->getStartTimezone()->getTimeZone()->getName() : null
113 ));
114 }
115
119 protected function getEnd(): Date
120 {
121 return new Date(Util::getDateObject(
122 $this->event->getDateTo()
123 ? $this->event->getDateTo()->format(\Bitrix\Main\Type\Date::convertFormatToPhp(FORMAT_DATETIME))
124 : null
125 ,
126 false,
127 $this->getEndTimezone() ? $this->getEndTimezone()->getTimeZone()->getName() : null
128 ));
129 }
130
135 protected function getOriginalDate(): ?Date
136 {
137 if (empty($this->event->getOriginalDateFrom()))
138 {
139 return null;
140 }
141
142 return new Date(Util::getDateObject(
143 $this->event->getOriginalDateFrom()->format(\Bitrix\Main\Type\Date::convertFormatToPhp(FORMAT_DATETIME)),
144 false,
145 $this->getStartTimezone() ? $this->getStartTimezone()->getTimeZone()->getName() : null
146 ));
147 }
148
149
150 protected function getFullDay(): bool
151 {
152 return $this->event->getDtSkipTime();
153 }
154
155 protected function getAttendees(): ?AttendeeCollection
156 {
157 $collection = new AttendeeCollection();
158 if (is_string($this->event->getAttendeesCodes()))
159 {
160 $collection->setAttendeesCodes(explode(',', $this->event->getAttendeesCodes()));
161 }
162 else
163 {
164 $collection->setAttendeesId([$this->event->getOwnerId()]);
165 }
166
167 return $collection;
168 }
169
174 protected function getReminders(): RemindCollection
175 {
176 $remindField = $this->event->getRemind();
177 if (is_string($remindField))
178 {
179 $remindField = unserialize($remindField, ['allowed_classes' => false]);
180 }
181
182 if (!is_array($remindField))
183 {
184 return new RemindCollection();
185 }
186
187 $eventStart = $this->getStart();
188
189 $collection = new RemindCollection();
190 $collection->setEventStart($eventStart);
191 foreach ($remindField as $remind)
192 {
193 if ($remind['type'] === Event\Tools\Dictionary::REMIND_UNIT['date'])
194 {
195 $collection->add((new Event\Properties\Remind())
196 ->setSpecificTime(
198 $remind['value'],
199 false,
200 $this->getStartTimezone()
201 ))
202 )
203 ->setEventStart($eventStart)
204 );
205 }
206 elseif ($remind['type'] === Event\Properties\Remind::UNIT_DAY_BEFORE)
207 {
208 $collection->add((new Event\Properties\Remind())
209 ->setEventStart($eventStart)
210 ->setSpecificTime(
212 $eventStart->toString(),
213 false,
214 $this->getStartTimezone())
215 ))
216 ->resetTime()
217 ->sub("{$remind['before']} days")
218 ->add("{$remind['time']} minutes")
219 )
220 ->setDaysBefore($remind['before'])
221 );
222 }
223 else
224 {
225 $collection->add((new Event\Properties\Remind())
226 ->setTimeBeforeEvent(
227 $remind['count'],
228 Event\Tools\Dictionary::REMIND_UNIT[$remind['type']]
229 )
230 ->setEventStart($eventStart)
231 );
232 }
233 }
234
235 return $collection;
236 }
237
238 protected function getDescription(): ?string
239 {
240 return $this->event->getDescription();
241 }
242
251 protected function getSection(): Section
252 {
253 if ($this->event->getSectionId())
254 {
256 $mapper = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
257
258 return $mapper->getSection()->getById($this->event->getSectionId());
259 }
260
261 throw new ObjectException('Section ID not found');
262 }
263
264 protected function getColor(): ?string
265 {
266 return $this->event->getColor();
267 }
268
269 protected function getTransparency(): ?string
270 {
271 // TODO: what to do here?
272 return '';
273 }
274
275 protected function getImportance(): ?string
276 {
277 return $this->event->getImportance();
278 }
279
280 protected function getAccessibility(): ?string
281 {
282 return $this->event->getAccessibility();
283 }
284
285 protected function getIsPrivate(): bool
286 {
287 return (bool) $this->event->getPrivateEvent();
288 }
289
295 protected function getEventHost(): ?Role
296 {
297 if (!$this->event->getMeetingHost())
298 {
299 return null;
300 }
301 try
302 {
303 return Helper::getUserRole($this->event->getMeetingHost());
304 }
305 catch (BaseException $exception)
306 {
307 return null;
308 }
309 }
310
316 protected function getCreator(): ?Role
317 {
318 if (!$this->event->getCreatedBy())
319 {
320 return null;
321 }
322 try
323 {
324 return Helper::getUserRole($this->event->getCreatedBy());
325 }
326 catch (BaseException $exception)
327 {
328 return null;
329 }
330 }
331
337 protected function getOwner(): ?Role
338 {
339 if (!$this->event->getOwnerId())
340 {
341 return null;
342 }
343 try
344 {
345 return Helper::getRole($this->event->getOwnerId(), $this->event->getCalType());
346 }
347 catch (BaseException $exception)
348 {
349 return null;
350 }
351 }
352
357 {
358 return $this->prepareMeetingDescription($this->event->getMeeting());
359 }
360
361 protected function getVersion(): int
362 {
363 return (int)$this->event->getVersion();
364 }
365
369 protected function getCalendarType(): ?string
370 {
371 return $this->event->getCalType();
372 }
373
377 protected function getUid(): ?string
378 {
379 $uid = $this->event->getDavXmlId();
380 if ($uid == $this->event->getId())
381 {
383 ->setPortalName(Util::getServerName())
384 ->setDate(new Date(Util::getDateObject(
385 $this->event->getDateFrom()->format(\Bitrix\Main\Type\Date::convertFormatToPhp(FORMAT_DATETIME)),
386 false,
387 $this->getStartTimezone() ? $this->getStartTimezone()->getTimeZone()->getName() : null
388 )))
389 ->setUserId((int)$this->event->getOwnerId())
390 ->getUidWithDate()
391 ;
392 }
393
394 return $uid;
395 }
396
397 protected function isDeleted(): bool
398 {
399 return $this->event->getDeleted();
400 }
401
402 protected function isActive(): bool
403 {
404 return $this->event->getActive();
405 }
406
407 protected function getRecurrenceId(): ?int
408 {
409 return $this->event->getRecurrenceId();
410 }
411
412 protected function getDateCreate(): ?Date
413 {
414 if (empty($this->event->getDateCreate()))
415 {
416 return null;
417 }
418
419 return new Date($this->event->getDateCreate());
420 }
421
422 protected function getDateModified(): ?Date
423 {
424 if (empty($this->event->getTimestampX()))
425 {
426 return null;
427 }
428
429 return new Date($this->event->getTimestampX());
430 }
431
436 {
437 return $this->prepareExcludedDates($this->event->getExdate());
438 }
439
440 protected function isMeeting(): bool
441 {
442 return (bool)$this->event->getIsMeeting();
443 }
444
445 protected function getMeetingStatus(): ?string
446 {
447 return $this->event->getMeetingStatus();
448 }
449
450 protected function getRelations(): ?Relations
451 {
452 return $this->prepareRelations($this->event->getRelations());
453 }
454
458 protected function getSpecialLabel(): ?string
459 {
460 return $this->event->getEventType();
461 }
462}
static prepareTimezone(?string $tz=null)
Definition util.php:75
static getDateObject(string $date=null, ?bool $fullDay=true, ?string $tz='UTC')
Definition util.php:102
static getServerName()
Definition util.php:649