15 private ?
string $eventOriginalDate;
18 public function __construct(
private int $userId,
private string $xmlId)
20 $xmlIdExploded = explode(
'_', $this->xmlId);
22 $this->eventId = (int)($xmlIdExploded[1] ??
null);
23 $this->eventOriginalDate = $xmlIdExploded[2] ??
null;
27 public function canView(
int $eventId,
int $userId): bool
29 return \CCalendarEvent::CanView($eventId, $userId);
34 if ($this->eventId <= 0 || empty($this->eventOriginalDate) || empty($this->targetDateTime))
39 $query = $this->getSearchExceptionsQuery($this->userId);
44 $query->setOffset($offset);
45 $exceptionEvents = $query->fetchAll();
47 $actualEventId = $this->processExceptionEvents($exceptionEvents);
49 if ($actualEventId > 0 || count($exceptionEvents) < $query->getLimit())
54 $offset += $query->getLimit();
57 return $actualEventId;
60 private function getSearchExceptionsQuery(
int $userId):
Query
62 $select = [
'ID',
'PARENT_ID',
'DELETED',
'OWNER_ID',
'DATE_FROM_TS_UTC',
'DATE_TO_TS_UTC',
'EXDATE',
'RELATIONS'];
64 return \Bitrix\Calendar\Internals\EventTable::query()
66 ->registerRuntimeField(
69 EventOriginalRecursionTable::class,
70 Join::on(
'this.PARENT_ID',
'ref.PARENT_EVENT_ID'),
72 ->configureJoinType(Join::TYPE_LEFT)
74 ->where(
'OWNER_ID', $userId)
75 ->where(
'CAL_TYPE', Dictionary::CALENDAR_TYPE[
'user'])
76 ->where(
'DELETED',
'N')
77 ->where(
'ORIGINAL_RECURSION.ORIGINAL_RECURSION_EVENT_ID', $this->eventId)
78 ->addOrder(
'ID',
'DESC')
83 private function processExceptionEvents(array $exceptionEvents): ?int
85 foreach ($exceptionEvents as $exceptionEvent)
88 if (!empty($exceptionEvent[
'RELATIONS']))
90 $eventRelations = unserialize($exceptionEvent[
'RELATIONS'], [
'allowed_classes' =>
false]);
92 $commentXmlId = $eventRelations[
'COMMENT_XML_ID'] ??
'';
93 if (!empty($commentXmlId) && $commentXmlId === $this->xmlId)
95 return (
int)$exceptionEvent[
'ID'];
97 elseif (!empty($commentXmlId))
103 $exceptionDatesParsed = \CCalendarEvent::GetExDate($exceptionEvent[
'EXDATE']);
104 foreach ($exceptionDatesParsed as $exceptionDateParsed)
106 if ($exceptionDateParsed === $this->eventOriginalDate)
117 $doEventStartsBeforeTargetDate = $dateFrom->getTimestamp() <= $this->targetDateTime->getTimestamp();
118 $doEventEndsAfterTargetDate = $dateTo->getTimestamp() >= $this->targetDateTime->getTimestamp();
119 if ($doEventStartsBeforeTargetDate && $doEventEndsAfterTargetDate)
121 return (
int)$exceptionEvent[
'ID'];
static createFromText($text)
static createFromTimestamp($timestamp)