16 private array $canSeeNameCache = [];
17 private int $skipEventId = 0;
21 $this->skipEventId = $curEventId;
31 $dateFromTs = $timestampFrom - ($timestampFrom % \CCalendar::DAY_LENGTH);
32 $dateToTs = $timestampTo - ($timestampTo % \CCalendar::DAY_LENGTH);
33 $accessibility = $this
34 ->getAccessibility($userIds, $dateFromTs, $dateToTs)
38 $timezoneName = \CCalendar::GetUserTimezoneName(\CCalendar::GetUserId());
40 foreach ($accessibility as
$userId => $events)
42 foreach ($events as $accessibilityItem)
44 $itemFrom = \CCalendar::TimestampUTC($accessibilityItem[
'from']);
45 $itemTo = \CCalendar::TimestampUTC($accessibilityItem[
'to']);
47 if ($accessibilityItem[
'isFullDay'])
49 $itemFrom -= $timezoneOffset;
50 $itemTo -= $timezoneOffset;
61 return $busyUsersList;
71 return $this->formatAccessibilityTs($accessibilityTs);
74 private function formatAccessibilityTs(
array $accessibilityTs):
array
77 fn(
array $userAccessibility) => array_map(
78 fn(
array $accessibilityItem) => array_merge($accessibilityItem, [
79 'from' => $this->formatTimestamp($accessibilityItem[
'from'], $accessibilityItem[
'isFullDay']),
80 'to' => $this->formatTimestamp($accessibilityItem[
'to'], $accessibilityItem[
'isFullDay']),
88 private function formatTimestamp(
int $timestamp,
bool $isFullDay): string
107 return $accessibility;
110 $events = $this->
getEventsTs($userIds, $timestampFrom, $timestampTo);
111 $absences = $this->
getAbsencesTs($userIds, $timestampFrom, $timestampTo);
118 return $accessibility;
126 [$from, $to] = $this->formatLimitFromTimestamps($timestampFrom, $timestampTo);
127 $events = \CCalendarEvent::GetList([
129 'FROM_LIMIT' => $from,
132 Dictionary::CALENDAR_TYPE[
'user'],
133 Dictionary::CALENDAR_TYPE[
'open_event'],
135 'OWNER_ID' => $userIds,
136 'ACTIVE_SECTION' =>
'Y'
138 'arSelect' => \CCalendarEvent::$defaultSelectEvent,
139 'getUserfields' =>
false,
140 'parseRecursion' =>
true,
141 'fetchAttendees' =>
false,
142 'fetchSection' =>
true,
143 'parseDescription' =>
false,
144 'setDefaultLimit' =>
false,
145 'checkPermissions' =>
false,
148 $accessibility = $this->initAccessibility($userIds);
149 foreach ($events as
$event)
151 if ((
int)
$event[
'ID'] === $this->skipEventId || (
int)
$event[
'PARENT_ID'] === $this->skipEventId)
155 if (
$event[
'ACCESSIBILITY'] ===
'free')
159 if (
$event[
'IS_MEETING'] &&
$event[
'MEETING_STATUS'] ===
'N')
163 if (\CCalendarSect::CheckGoogleVirtualSection(
$event[
'SECTION_DAV_XML_ID']))
168 $isFullDay =
$event[
'DT_SKIP_TIME'] ===
'Y';
171 $from = \CCalendar::TimestampUTC(
$event[
'DATE_FROM']);
172 $to = \CCalendar::TimestampUTC(
$event[
'DATE_TO']) + \CCalendar::GetDayLen();
179 $accessibility[
$event[
'OWNER_ID']][] = [
180 'id' => (int)
$event[
'ID'],
181 'parentId' => (
int)
$event[
'PARENT_ID'],
182 'name' => $this->getEventName(
$event),
185 'isFullDay' => $isFullDay,
189 return $accessibility;
192 private function getEventName(
array $event): string
194 if (!$this->canSeeName(
$event))
196 return '[' . Loc::getMessage(
'EC_ACCESSIBILITY_BUSY') .
']';
199 return !empty(
$event[
'NAME']) ?
$event[
'NAME'] : Loc::getMessage(
'EC_T_NEW_EVENT');
204 $currentUserId = \CCalendar::GetUserId();
205 $eventId = (int)
$event[
'ID'];
206 $cachedValue = $this->canSeeNameCache[$eventId] ??
null;
208 if ($cachedValue ===
null)
211 $eventModel = EventModel::createFromArray(
$event);
213 $canViewTitle =
$accessController->check(ActionDictionary::ACTION_EVENT_VIEW_TITLE, $eventModel);
214 $this->canSeeNameCache[$eventId] = !$this->isPrivate(
$event) && $canViewTitle;
217 return $this->canSeeNameCache[$eventId];
222 $curUserId = \CCalendar::GetUserId();
224 return $event[
'PRIVATE_EVENT'] &&
$event[
'CAL_TYPE'] ===
'user' &&
$event[
'OWNER_ID'] !== $curUserId;
232 if (!\CCalendar::IsIntranetEnabled())
237 [$from, $to] = $this->formatLimitFromTimestamps($timestampFrom, $timestampTo);
238 $usersAbsence = \CIntranetUtils::GetAbsenceData(
240 'DATE_START' => $from,
241 'DATE_FINISH' => $to,
245 BX_INTRANET_ABSENCE_HR,
248 $absenceTypes = \Bitrix\Intranet\UserAbsence::getVacationTypes();
249 $vacationTypes = array_filter(
251 fn (
$type) => in_array(
$type[
'ID'], [
'VACATION',
'LEAVESICK',
'LEAVEMATERINITY',
'LEAVEUNPAYED'],
true),
253 $vacationTypesIds = array_map(fn (
$type) => (
int)
$type[
'ENUM_ID'], $vacationTypes);
255 $offset = (int)date(
'Z') + \CCalendar::GetOffset(\CCalendar::GetUserId());
256 $accessibility = $this->initAccessibility($userIds);
257 foreach($usersAbsence as
$userId => $absenceData)
259 foreach($absenceData as
$event)
261 $from = \CCalendar::TimestampUTC(
$event[
'DATE_ACTIVE_FROM']);
262 $to = \CCalendar::TimestampUTC(
$event[
'DATE_ACTIVE_TO']);
263 $isFullDay = $this->isFullDay(
$event[
'DATE_ACTIVE_FROM'],
$event[
'DATE_ACTIVE_TO']);
265 if ($this->isDateWithoutTimeOrIsMidnight(
$event[
'DATE_ACTIVE_TO']))
267 $to += \CCalendar::GetDayLen();
279 'isFullDay' => $isFullDay,
280 'name' =>
$event[
'PROPERTY_ABSENCE_TYPE_VALUE'] ??
null,
281 'isVacation' => in_array((
int)
$event[
'PROPERTY_ABSENCE_TYPE_ENUM_ID'], $vacationTypesIds,
true),
286 return $accessibility;
289 private function isFullDay(
string $from,
string $to): bool
291 return $this->isDateWithoutTimeOrIsMidnight($from) && $this->isDateWithoutTimeOrIsMidnight($to);
294 private function isDateWithoutTimeOrIsMidnight(
string $date): bool
300 private function formatLimitFromTimestamps(
int $timestampFrom,
int $timestampTo):
array
308 private function initAccessibility(
array $userIds):
array
316 return $accessibility;