• Модуль: timeman
  • Путь к файлу: ~/bitrix/modules/timeman/lib/service/schedule/shiftplanservice.php
  • Класс: BitrixTimemanServiceScheduleShiftPlanService
  • Вызов: ShiftPlanService::add
public function add(ShiftPlanForm $shiftPlanForm, $forceCreateIfOverlaps = false)
{
	if (!($shift = $this->shiftRepository->findByIdWithSchedule($shiftPlanForm->shiftId))
		|| !$shift->obtainSchedule()->isShifted())
	{
		return (new ShiftPlanServiceResult())->addShiftNotFoundError();
	}
	$shiftPlan = $this->shiftPlanRepository->findByComplexId(
		$shiftPlanForm->shiftId,
		$shiftPlanForm->userId,
		$shiftPlanForm->getDateAssigned()
	);
	if ($shiftPlan && $shiftPlan->isActive())
	{
		return new ShiftPlanServiceResult();
	}
	if (!$forceCreateIfOverlaps)
	{
		$overlapResult = $this->checkOverlappingPlans($shiftPlanForm, $shift);
		if (!$overlapResult->isSuccess())
		{
			return $overlapResult;
		}
	}

	if ($shiftPlan)
	{
		$shiftPlan->restore();
	}
	else
	{
		$shiftPlan = ShiftPlan::create($shiftPlanForm);
	}

	$res = $this->shiftPlanRepository->save($shiftPlan);
	if (!$res->isSuccess())
	{
		return ShiftPlanServiceResult::createByResult($res);
	}

	// create agent on every shiftplan, always
	$this->worktimeAgentManager->createMissedShiftChecking($shiftPlan, $shift);

	return (new ShiftPlanServiceResult())
		->setShift($shift)
		->setSchedule($shift->obtainSchedule())
		->setShiftPlan($shiftPlan);
}