- Модуль: calendar
- Путь к файлу: ~/bitrix/modules/calendar/lib/userfield/resourcebooking.php
- Класс: BitrixCalendarUserFieldResourceBooking
- Вызов: ResourceBooking::getAvailableTimeSlots
static function getAvailableTimeSlots($accessibility, $options)
{
$from = (isset($options['from']) && $options['from'] instanceof Date) ? $options['from'] : new Date();
$to = (isset($options['to']) && $options['to'] instanceof Date) ? $options['to'] : new Date();
$to->add('P1D');
$scale = (int)$options['scale'] > 0 ? (int)$options['scale'] : 60;
$workTimeStart = (int)COption::getOptionString('calendar', 'work_time_start', 9);
$workTimeEnd = (int)COption::getOptionString('calendar', 'work_time_end', 19);
$step = 0;
$currentDate = new DateTime($from->toString(), Date::convertFormatToPhp(FORMAT_DATETIME));
$slots = [];
while ($currentDate->getTimestamp() < $to->getTimestamp())
{
$currentDate->setTime($workTimeStart, 0, 0);
while ((int)$currentDate->format('H') < $workTimeEnd)
{
if ($currentDate->getTimestamp() > time())
{
$isFree = true;
$slotStart = $currentDate->getTimestamp();
$slotEnd = $slotStart + $scale * 60;
foreach ($accessibility as $i => $item)
{
if ($item['toTs'] > $slotStart && $item['fromTs'] < $slotEnd)
{
$isFree = false;
break;
}
}
if ($isFree)
{
$slots[] = clone $currentDate;
}
}
$currentDate->add('PT'.$scale.'M');
$step++;
}
if($step > 1000)
{
break;
}
$currentDate->add('P1D');
}
return $slots;
}