• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/lib/rooms/occupancychecker.php
  • Класс: BitrixCalendarRoomsOccupancyChecker
  • Вызов: OccupancyChecker::fillTimeline
private function fillTimeline(array $event, array $eventsForCheck, array $existingEvents)
{
	if (!empty($event['ID']) && $event['ID'] > 0)
	{
		$this->checkEventId = $event['ID'];
	}

	$currentIndex = 1;
	foreach ($eventsForCheck as $eventForCheck)
	{
		if (empty($eventForCheck['DATE_FROM']) || empty($eventForCheck['DATE_TO']))
		{
			continue;
		}
		[$timestampFrom, $timestampTo] = $this->getEventTimestamps($eventForCheck);

		$this->timeline[$this->getTimelineKey($this->checkEventId, $currentIndex, false)] = $timestampFrom;
		$this->timeline[$this->getTimelineKey($this->checkEventId, $currentIndex, true)] = $timestampTo;
		$this->cachedEvents[$this->getCachedEventKey($eventForCheck['ID'], $currentIndex)] = [
			'ID' => $eventForCheck['ID'],
			'DATE_FROM' => $eventForCheck['DATE_FROM'],
			'TZ_FROM' => $eventForCheck['TZ_FROM'],
		];
		$currentIndex++;
	}

	$currentIndex = 1;
	$previousEventId = 0;
	foreach ($existingEvents as $existingEvent)
	{
		if (!$this->canFindIntersections($event, $existingEvent))
		{
			continue;
		}

		$currentEventId = (int)$existingEvent['ID'];
		if ($currentEventId !== $previousEventId)
		{
			$previousEventId = $currentEventId;
			$currentIndex = 1;
		}

		try
		{
			[$timestampFrom, $timestampTo] = $this->getEventTimestamps($existingEvent);

			$this->timeline[$this->getTimelineKey($currentEventId, $currentIndex, false)] = $timestampFrom;
			$this->timeline[$this->getTimelineKey($currentEventId, $currentIndex, true)] = $timestampTo;
			$this->cachedEvents[$this->getCachedEventKey($currentEventId, $currentIndex)] = [
				'ID' => $currentEventId,
				'DATE_FROM' => $existingEvent['DATE_FROM'],
				'TZ_FROM' => $existingEvent['TZ_FROM'],
			];
			$currentIndex++;
		}
		catch (ObjectException $exception)
		{
		}
	}
}