1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
eventbuilderfromentityobject.php
См. документацию.
1<?php
2
3
4namespace Bitrix\Calendar\Core\Builders;
5
6use Bitrix\Calendar\Core\Base\BaseException;
7use Bitrix\Calendar\Core\Base\Date;
8use Bitrix\Calendar\Core\Base\DateTimeZone;
9use Bitrix\Calendar\Core\Event;
10use Bitrix\Calendar\Core\Event\Properties\AttendeeCollection;
11use Bitrix\Calendar\Core\Event\Properties\ExcludedDatesCollection;
12use Bitrix\Calendar\Core\Event\Properties\Location;
13use Bitrix\Calendar\Core\Event\Properties\MeetingDescription;
14use Bitrix\Calendar\Core\Event\Properties\RecurringEventRules;
15use Bitrix\Calendar\Core\Event\Properties\Relations;
16use Bitrix\Calendar\Core\Event\Properties\RemindCollection;
17use Bitrix\Calendar\Core\Event\Tools\UidGenerator;
18use Bitrix\Calendar\Core\EventOption\EventOption;
19use Bitrix\Calendar\Core\Mappers\Factory;
20use Bitrix\Calendar\Core\Role\Helper;
21use Bitrix\Calendar\Core\Role\Role;
22use Bitrix\Calendar\Internals\EO_Event;
23use Bitrix\Calendar\Core\Section\Section;
24use Bitrix\Calendar\Util;
25use Bitrix\Main\ArgumentException;
26use Bitrix\Main\DI\ServiceLocator;
27use Bitrix\Main\ObjectException;
28use Bitrix\Main\ObjectNotFoundException;
29use Bitrix\Main\ObjectPropertyException;
30use Bitrix\Main\SystemException;
31use CCalendarEvent;
32use Psr\Container\NotFoundExceptionInterface;
33
35{
39 private EO_Event $event;
40
44 public function __construct(EO_Event $event)
45 {
46 $this->event = $event;
47 }
48
52 protected function getId(): ?int
53 {
54 return $this->event->getId();
55 }
56
57 protected function getParentId(): ?int
58 {
59 return $this->event->getParentId();
60 }
61
62 protected function getName(): string
63 {
64 return $this->event->getName();
65 }
66
67 protected function getStartTimezone(): ?DateTimeZone
68 {
69 if (!$this->event->getTzFrom())
70 {
71 return null;
72 }
73
74 return new DateTimeZone(Util::prepareTimezone($this->event->getTzFrom()));
75 }
76
77 protected function getEndTimezone(): ?DateTimeZone
78 {
79 if (!$this->event->getTzTo())
80 {
81 return null;
82 }
83
84 return new DateTimeZone(Util::prepareTimezone($this->event->getTzTo()));
85 }
86
92 {
93 $rule = CCalendarEvent::convertDateToCulture($this->event->getRrule());
94 return $this->prepareRecurringRule(
95 CCalendarEvent::ParseRRULE($rule)
96 );
97 }
98
99 protected function getLocation(): ?Location
100 {
101 return $this->prepareLocation($this->event->getLocation());
102 }
103
107 protected function getStart(): Date
108 {
109 return new Date(Util::getDateObject(
110 $this->event->getDateFrom()
111 ? $this->event->getDateFrom()->format(\Bitrix\Main\Type\Date::convertFormatToPhp(FORMAT_DATETIME))
112 : null
113 ,
114 false,
115 $this->getStartTimezone() ? $this->getStartTimezone()->getTimeZone()->getName() : null
116 ));
117 }
118
122 protected function getEnd(): Date
123 {
124 return new Date(Util::getDateObject(
125 $this->event->getDateTo()
126 ? $this->event->getDateTo()->format(\Bitrix\Main\Type\Date::convertFormatToPhp(FORMAT_DATETIME))
127 : null
128 ,
129 false,
130 $this->getEndTimezone() ? $this->getEndTimezone()->getTimeZone()->getName() : null
131 ));
132 }
133
138 protected function getOriginalDate(): ?Date
139 {
140 if (empty($this->event->getOriginalDateFrom()))
141 {
142 return null;
143 }
144
145 return new Date(Util::getDateObject(
146 $this->event->getOriginalDateFrom()->format(\Bitrix\Main\Type\Date::convertFormatToPhp(FORMAT_DATETIME)),
147 false,
148 $this->getStartTimezone() ? $this->getStartTimezone()->getTimeZone()->getName() : null
149 ));
150 }
151
152
153 protected function getFullDay(): bool
154 {
155 return $this->event->getDtSkipTime();
156 }
157
158 protected function getAttendees(): ?AttendeeCollection
159 {
160 $collection = new AttendeeCollection();
161 if (is_string($this->event->getAttendeesCodes()))
162 {
163 $collection->setAttendeesCodes(explode(',', $this->event->getAttendeesCodes()));
164 }
165 else
166 {
167 $collection->setAttendeesId([$this->event->getOwnerId()]);
168 }
169
170 return $collection;
171 }
172
177 protected function getReminders(): RemindCollection
178 {
179 $remindField = $this->event->getRemind();
180 if (is_string($remindField))
181 {
182 $remindField = unserialize($remindField, ['allowed_classes' => false]);
183 }
184
185 if (!is_array($remindField))
186 {
187 return new RemindCollection();
188 }
189
190 $eventStart = $this->getStart();
191
192 $collection = new RemindCollection();
193 $collection->setEventStart($eventStart);
194 foreach ($remindField as $remind)
195 {
196 if ($remind['type'] === Event\Tools\Dictionary::REMIND_UNIT['date'])
197 {
198 $collection->add((new Event\Properties\Remind())
199 ->setSpecificTime(
201 $remind['value'],
202 false,
203 $this->getStartTimezone()
204 ))
205 )
206 ->setEventStart($eventStart)
207 );
208 }
209 elseif ($remind['type'] === Event\Properties\Remind::UNIT_DAY_BEFORE)
210 {
211 $collection->add((new Event\Properties\Remind())
212 ->setEventStart($eventStart)
213 ->setSpecificTime(
215 $eventStart->toString(),
216 false,
217 $this->getStartTimezone())
218 ))
219 ->resetTime()
220 ->sub("{$remind['before']} days")
221 ->add("{$remind['time']} minutes")
222 )
223 ->setDaysBefore($remind['before'])
224 );
225 }
226 else
227 {
228 $collection->add((new Event\Properties\Remind())
229 ->setTimeBeforeEvent(
230 $remind['count'],
231 Event\Tools\Dictionary::REMIND_UNIT[$remind['type']]
232 )
233 ->setEventStart($eventStart)
234 );
235 }
236 }
237
238 return $collection;
239 }
240
241 protected function getDescription(): ?string
242 {
243 return $this->event->getDescription();
244 }
245
254 protected function getSection(): Section
255 {
256 if ($this->event->getSectionId())
257 {
259 $mapper = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
260
261 $section = $mapper->getSection()->getById($this->event->getSectionId());
262 if ($section)
263 {
264 return $section;
265 }
266 }
267
268 throw new BuilderException('Section ID not found');
269 }
270
271 protected function getColor(): ?string
272 {
273 return $this->event->getColor();
274 }
275
276 protected function getTransparency(): ?string
277 {
278 // TODO: what to do here?
279 return '';
280 }
281
282 protected function getImportance(): ?string
283 {
284 return $this->event->getImportance();
285 }
286
287 protected function getAccessibility(): ?string
288 {
289 return $this->event->getAccessibility();
290 }
291
292 protected function getIsPrivate(): bool
293 {
294 return (bool) $this->event->getPrivateEvent();
295 }
296
302 protected function getEventHost(): ?Role
303 {
304 if (!$this->event->getMeetingHost())
305 {
306 return null;
307 }
308 try
309 {
310 return Helper::getUserRole($this->event->getMeetingHost());
311 }
312 catch (BaseException $exception)
313 {
314 return null;
315 }
316 }
317
323 protected function getCreator(): ?Role
324 {
325 if (!$this->event->getCreatedBy())
326 {
327 return null;
328 }
329 try
330 {
331 return Helper::getUserRole($this->event->getCreatedBy());
332 }
333 catch (BaseException $exception)
334 {
335 return null;
336 }
337 }
338
344 protected function getOwner(): ?Role
345 {
346 if (!$this->event->getOwnerId())
347 {
348 return null;
349 }
350 try
351 {
352 return Helper::getRole($this->event->getOwnerId(), $this->event->getCalType());
353 }
354 catch (BaseException $exception)
355 {
356 return null;
357 }
358 }
359
364 {
365 return $this->prepareMeetingDescription($this->event->getMeeting());
366 }
367
368 protected function getVersion(): int
369 {
370 return (int)$this->event->getVersion();
371 }
372
376 protected function getCalendarType(): ?string
377 {
378 return $this->event->getCalType();
379 }
380
384 protected function getUid(): ?string
385 {
386 $uid = $this->event->getDavXmlId();
387 if ($uid === (string)$this->event->getId())
388 {
389 $uid = UidGenerator::createInstance()
390 ->setPortalName(Util::getServerName())
391 ->setDate(new Date(Util::getDateObject(
392 $this->event->getDateFrom()
393 ? $this->event->getDateFrom()->format(\Bitrix\Main\Type\Date::convertFormatToPhp(FORMAT_DATETIME))
394 : null
395 ,
396 false,
397 $this->getStartTimezone() ? $this->getStartTimezone()->getTimeZone()->getName() : null
398 )))
399 ->setUserId($this->event->getOwnerId())
400 ->getUidWithDate()
401 ;
402 }
403
404 return $uid;
405 }
406
407 protected function isDeleted(): bool
408 {
409 return $this->event->getDeleted();
410 }
411
412 protected function isActive(): bool
413 {
414 return $this->event->getActive();
415 }
416
417 protected function getRecurrenceId(): ?int
418 {
419 return $this->event->getRecurrenceId();
420 }
421
422 protected function getDateCreate(): ?Date
423 {
424 if (empty($this->event->getDateCreate()))
425 {
426 return null;
427 }
428
429 return new Date($this->event->getDateCreate());
430 }
431
432 protected function getDateModified(): ?Date
433 {
434 if (empty($this->event->getTimestampX()))
435 {
436 return null;
437 }
438
439 return new Date($this->event->getTimestampX());
440 }
441
446 {
447 return $this->prepareExcludedDates($this->event->getExdate());
448 }
449
450 protected function isMeeting(): bool
451 {
452 return (bool)$this->event->getIsMeeting();
453 }
454
455 protected function getMeetingStatus(): ?string
456 {
457 return $this->event->getMeetingStatus();
458 }
459
460 protected function getRelations(): ?Relations
461 {
462 return $this->prepareRelations($this->event->getRelations());
463 }
464
468 protected function getSpecialLabel(): ?string
469 {
470 return $this->event->getEventType();
471 }
472
473 protected function getEventOption(): ?EventOption
474 {
475 if ($eventId = $this->event->getId())
476 {
478 $mapperFactory = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
479
480 return $mapperFactory->getEventOption()->getMap(['=EVENT_ID' => $eventId])->fetch();
481 }
482
483 return null;
484 }
485
486 protected function getDtLength(): ?int
487 {
488 return $this->event->getDtLength();
489 }
490
491 protected function getCollabId(): ?int
492 {
493 return null;
494 }
495}
prepareLocation($locationData='')
Определения eventbuilder.php:172
prepareMeetingDescription($meeting=null)
Определения eventbuilder.php:445
prepareRecurringRule($ruleData=null)
Определения eventbuilder.php:110
prepareExcludedDates(string $dates='')
Определения eventbuilder.php:500
static prepareTimezone(?string $tz=null)
Определения util.php:80
static getDateObject(string $date=null, ?bool $fullDay=true, ?string $tz='UTC')
Определения util.php:107
static getServerName()
Определения util.php:683
Определения date.php:9
$uid
Определения hot_keys_act.php:8
const FORMAT_DATETIME
Определения include.php:64
Определения collection.php:2
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393