• Модуль: timeman
  • Путь к файлу: ~/bitrix/modules/timeman/lib/service/agent/worktimeagentmanager.php
  • Класс: BitrixTimemanServiceAgentWorktimeAgentManager
  • Вызов: WorktimeAgentManager::addAutoClosingAgents
public function addAutoClosingAgents(Schedule $schedule, $shiftCollection = null)
{
	$shiftCollection = $shiftCollection === null ? new ShiftCollection() : $shiftCollection;
	$result = new WorktimeServiceResult();
	if (!$schedule->isAutoClosing())
	{
		return $result;
	}

	$selectFields = ['*'];
	if ($shiftCollection->count() === 0)
	{
		$selectFields[] = 'SHIFT';
	}
	$records = $this->worktimeRepository->findAll(
		$selectFields,
		$this->worktimeRepository->buildOpenRecordsQuery($schedule, $shiftCollection)
	);
	if ($records->count() === 0)
	{
		return $result;
	}
	foreach ($records as $record)
	{
		$record->defineSchedule($schedule);
		if ($shiftCollection->count() > 0 && $shiftCollection->getByPrimary($record->getShiftId()))
		{
			$record->defineShift($shiftCollection->getByPrimary($record->getShiftId()));
		}
	}

	$this->createAutoClosingAgentForRecords($records);
	foreach ($records as $record)
	{
		if ($record->getAutoClosingAgentId() > 0)
		{
			$recordToSave = WorktimeRecord::wakeUpRecord([
				'ID' => $record->getId(),
			]);
			$recordToSave->setAutoClosingAgentId($record->getAutoClosingAgentId());
			$this->worktimeRepository->save($recordToSave);
		}
	}

	return $result;
}