39 public function getBusyUsersIds(array $userIds,
int $timestampFromUTC,
int $timestampToUTC): array
43 $accessibility = $this
44 ->setCheckPermissions(
false)
45 ->getAccessibility($userIds, $dateFromTs, $dateToTs)
49 $timezoneName = \CCalendar::GetUserTimezoneName(\CCalendar::GetUserId());
51 foreach ($accessibility as $userId => $events)
53 foreach ($events as $accessibilityItem)
55 $itemFrom = \CCalendar::TimestampUTC($accessibilityItem[
'from']);
56 $itemTo = \CCalendar::TimestampUTC($accessibilityItem[
'to']);
58 if ($accessibilityItem[
'isFullDay'])
60 $itemFrom -= $timezoneOffset;
61 $itemTo -= $timezoneOffset;
66 $busyUsersList[] = $userId;
71 return $busyUsersList;
81 public function getAccessibility(array $userIds,
int $timestampFromUTC,
int $timestampToUTC): array
87 return $accessibility;
90 $events = $this->
getEvents($userIds, $timestampFromUTC, $timestampToUTC);
91 $absences = $this->
getAbsences($userIds, $timestampFromUTC, $timestampToUTC);
93 foreach ($userIds as $userId)
95 $accessibility[$userId] = array_merge($events[$userId], $absences[$userId]);
98 return $accessibility;
108 public function getEvents(array $userIds,
int $timestampFromUTC,
int $timestampToUTC): array
110 [$from, $to] = $this->formatLimitFromTimestamps($timestampFromUTC, $timestampToUTC);
111 $events = \CCalendarEvent::GetList([
113 'FROM_LIMIT' => $from,
115 'CAL_TYPE' =>
'user',
116 'OWNER_ID' => $userIds,
117 'ACTIVE_SECTION' =>
'Y'
119 'arSelect' => \CCalendarEvent::$defaultSelectEvent,
120 'getUserfields' =>
false,
121 'parseRecursion' =>
true,
122 'fetchAttendees' =>
false,
123 'fetchSection' =>
true,
124 'parseDescription' =>
false,
125 'setDefaultLimit' =>
false,
126 'checkPermissions' => $this->checkPermissions
129 $accessibility = $this->initAccessibility($userIds);
130 foreach ($events as $event)
132 if ((
int)$event[
'ID'] === $this->skipEventId || (
int)$event[
'PARENT_ID'] === $this->skipEventId)
136 if ($event[
'ACCESSIBILITY'] ===
'free')
140 if ($event[
'IS_MEETING'] && $event[
'MEETING_STATUS'] ===
'N')
144 if (\CCalendarSect::CheckGoogleVirtualSection($event[
'SECTION_DAV_XML_ID']))
149 $isFullDay = $event[
'DT_SKIP_TIME'] ===
'Y';
162 $accessibility[$event[
'OWNER_ID']][] = [
163 'id' => $event[
'ID'],
164 'name' => $this->getEventName($event),
167 'isFullDay' => $isFullDay,
171 return $accessibility;
206 public function getAbsences(array $userIds,
int $timestampFromUTC,
int $timestampToUTC): array
208 if (!\CCalendar::IsIntranetEnabled())
213 [$from, $to] = $this->formatLimitFromTimestamps($timestampFromUTC, $timestampToUTC);
214 $usersAbsence = \CIntranetUtils::GetAbsenceData(
216 'DATE_START' => $from,
217 'DATE_FINISH' => $to,
221 BX_INTRANET_ABSENCE_HR
224 $absenceTypes = \Bitrix\Intranet\UserAbsence::getVacationTypes();
225 $vacationTypes = array_filter(
227 fn ($type) => in_array($type[
'ID'], [
'VACATION',
'LEAVESICK',
'LEAVEMATERINITY',
'LEAVEUNPAYED'],
true),
229 $vacationTypesIds = array_map(fn ($type) => (
int)$type[
'ENUM_ID'], $vacationTypes);
231 $serverOffset = (int)date(
'Z');
232 $userOffset = \CCalendar::GetOffset(\CCalendar::GetUserId());
233 $accessibility = $this->initAccessibility($userIds);
234 foreach($usersAbsence as $userId => $absenceData)
236 foreach($absenceData as $event)
238 $fromUTC = \CCalendar::TimestampUTC($event[
'DATE_ACTIVE_FROM']);
239 $toUTC = \CCalendar::TimestampUTC($event[
'DATE_ACTIVE_TO']);
240 $isFullDay = $this->isFullDay($event[
'DATE_ACTIVE_FROM'], $event[
'DATE_ACTIVE_TO']);
241 if ($this->isDateWithoutTimeOrIsMidnight($event[
'DATE_ACTIVE_TO']))
243 $toUTC += \CCalendar::GetDayLen();
256 $accessibility[$userId][] = [
259 'isFullDay' => $isFullDay,
260 'name' => $event[
'PROPERTY_ABSENCE_TYPE_VALUE'] ??
null,
261 'isVacation' => in_array((
int)$event[
'PROPERTY_ABSENCE_TYPE_ENUM_ID'], $vacationTypesIds,
true),
266 return $accessibility;