• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/lib/rooms/occupancychecker.php
  • Класс: BitrixCalendarRoomsOccupancyChecker
  • Вызов: OccupancyChecker::check
public function check(array $event): Result
{
	$result = new Result();

	if (!$this->canCheck($event))
	{
		return $result;
	}

	$location = Util::parseLocation($event['LOCATION']['NEW']);
	$roomId = $location['room_id'];

	if (!$roomId)
	{
		return $result;
	}

	$eventsForCheck = $this->getEventsForCheck($event);

	$existingEvents = $this->getExistingEvents($roomId, $event);

	$this->fillTimeline($event, $eventsForCheck, $existingEvents);
	asort($this->timeline, SORT_NUMERIC);

	$checkingEventsStartedCount = 0;
	$existingEventsStartedCount = 0;
	$disturbingEventDates = [];
	$isDisturbingEventsAmountOverShowLimit = false;
	foreach ($this->timeline as $key => $value)
	{
		[$eventId, $repeatNumber, $isEnd] = $this->parseTimelineKey($key);
		if ($eventId === $this->checkEventId)
		{
			if ($isEnd)
			{
				$checkingEventsStartedCount--;
			}
			else
			{
				$checkingEventsStartedCount++;
			}
		}
		else
		{
			if ($isEnd)
			{
				$existingEventsStartedCount--;
			}
			else
			{
				$existingEventsStartedCount++;
			}
		}

		if ($checkingEventsStartedCount > 0 && $existingEventsStartedCount > 0)
		{
			$disturbingEvent = $this->cachedEvents[$this->getCachedEventKey($eventId, $repeatNumber)];;
			if (count($disturbingEventDates) >= self::DISTURBING_EVENTS_LIMIT)
			{
				$isDisturbingEventsAmountOverShowLimit = true;
				break;
			}
			$disturbingEventDate = $this->getEventFormattedDate($disturbingEvent);
			if (!in_array($disturbingEventDate, $disturbingEventDates))
			{
				$disturbingEventDates[] = $disturbingEventDate;
			}
		}
	}

	if (!empty($disturbingEventDates))
	{
		$result->addError(new Error('ROOM IS OCCUPIED'));
		$result->setData([
			'disturbingEventsFormatted' => implode(', ', $disturbingEventDates),
			'isDisturbingEventsAmountOverShowLimit' => $isDisturbingEventsAmountOverShowLimit,
		]);
	}

	return $result;
}