• Модуль: timeman
  • Путь к файлу: ~/bitrix/modules/timeman/lib/absence.php
  • Класс: BitrixTimemanAbsence
  • Вызов: Absence::getIntersectWithCalendar
static function getIntersectWithCalendar($userId)
{
	$userId = intval($userId);
	if ($userId <= 0)
	{
		return false;
	}

	if (!BitrixMainLoader::includeModule("calendar"))
	{
		return false;
	}

	$result = null;

	$now = (new BitrixMainTypeDateTime())->getTimestamp();
	$today = (new BitrixMainTypeDate())->toString();

	$entries = CCalendar::GetAccessibilityForUsers(array(
		'users' => [$userId],
		'from' => $today,
		'to' => $today,
	));

	foreach ($entries[$userId] as $entry)
	{
		$tzFrom = $entry['TZ_FROM']? new DateTimeZone($entry['TZ_FROM']): null;
		$tzTo = $entry['TZ_TO']? new DateTimeZone($entry['TZ_TO']): null;

		$entryFrom = new BitrixMainTypeDateTime($entry['DATE_FROM'], null, $tzFrom);
		$entryTo = new BitrixMainTypeDateTime($entry['DATE_TO'], null, $tzTo);

		if ($entryFrom->getTimestamp() < $now && $now < $entryTo->getTimestamp())
		{
			$result = Array(
				'ID' => $entry['ID'],
				'TITLE' => $entry['NAME']? $entry['NAME']: Loc::getMessage('TIMEMAN_ABSENCE_CALENDAR_ENTRY_TITLE'),
				'DATE_FROM' => $entryFrom,
				'DATE_TO' => $entryTo,
				'ABSENCE_SCHEDULE' => $entry['FROM_HR']? true: false,
			);
			break;
		}
	}

	return $result;
}