- Модуль: timeman
- Путь к файлу: ~/bitrix/modules/timeman/lib/service/schedule/scheduleservice.php
- Класс: BitrixTimemanServiceScheduleScheduleService
- Вызов: ScheduleService::update
public function update($scheduleId, ScheduleForm $scheduleForm)
{
$schedule = $this->scheduleProvider->findByIdWith($scheduleId, [
'CALENDAR',
'CALENDAR.EXCLUSIONS',
'SHIFTS',
'DEPARTMENT_ASSIGNMENTS',
'USER_ASSIGNMENTS',
'SCHEDULE_VIOLATION_RULES',
]);
if (!$schedule)
{
return (new ScheduleServiceResult())->addScheduleNotFoundError();
}
$result = $this->wrapAction(function () use ($schedule, $scheduleForm) {
# schedule
$wasAutoClosing = $schedule->isAutoClosing();
$this->safeRun($this->editSchedule($schedule, $scheduleForm));
$autoClosingAfterUpdate = $schedule->isAutoClosing();
# violation rules
$this->safeRun($this->violationRulesService->update($scheduleForm->violationForm, $schedule));
// todo $schedule->setScheduleViolationRules($violationRules);
# shifts
if ($schedule->isFlextime())
{
$this->safeRun($this->removeShifts($schedule));
}
else
{
$this->safeRun($this->removeShifts($schedule, $scheduleForm));
$this->safeRun($this->createShifts($schedule, $scheduleForm));
$this->safeRun($updatedEndIdsResult = $this->updateShifts($schedule, $scheduleForm));
/** @var ShiftCollection $shiftCollection */
$shiftCollection = $updatedEndIdsResult->getData()[0];
if ($wasAutoClosing && $autoClosingAfterUpdate && $shiftCollection->count() > 0)
{
$this->worktimeAgentManager->deleteAutoClosingAgents($schedule, $shiftCollection);
$this->worktimeAgentManager->addAutoClosingAgents($schedule, $shiftCollection);
}
}
# auto close records
if ($wasAutoClosing && !$autoClosingAfterUpdate)
{
$this->worktimeAgentManager->deleteAutoClosingAgents($schedule);
}
elseif (!$wasAutoClosing && $autoClosingAfterUpdate)
{
$this->worktimeAgentManager->addAutoClosingAgents($schedule);
}
# users
# departments
$this->safeRun($this->saveAssignments($schedule, $scheduleForm));
# calendar
$this->safeRun($this->saveCalendar($scheduleForm, $schedule));
$this->cleanCache();
return $this->buildResultWithSchedule($schedule);
});
if (!WorktimeServiceResult::isSuccessResult($result))
{
return ScheduleServiceResult::createByResult($result);
}
$this->wrapAction(function () use ($schedule, $scheduleForm) {
$this->safeRun($this->excludeSelectedDepartmentsFromOtherSchedules($schedule));
});
return $this->buildResultWithSchedule($schedule);
}