- Модуль: timeman
- Путь к файлу: ~/bitrix/modules/timeman/lib/service/agent/worktimeagentmanager.php
- Класс: BitrixTimemanServiceAgentWorktimeAgentManager
- Вызов: WorktimeAgentManager::recountPeriodTimeLackAgents
private function recountPeriodTimeLackAgents($schedule)
{
$violationRulesList = $this->violationRulesRepository
->findAllByScheduleId(
$schedule->getId(),
[
'ID',
'ENTITY_CODE',
'PERIOD_TIME_LACK_AGENT_ID',
'MAX_WORK_TIME_LACK_FOR_PERIOD',
'USERS_TO_NOTIFY',
],
Query::filter()
->where('PERIOD_TIME_LACK_AGENT_ID', '>', 0)
);
if ($violationRulesList->count() == 0)
{
return new Result();
};
$this->deleteAgentsByIds($violationRulesList->getPeriodTimeLackAgentIdList());
$listToUpdate = new ViolationRulesCollection();
foreach ($violationRulesList as $violationRules)
{
$this->deleteAgentById($violationRules->getPeriodTimeLackAgentId());
$violationRules->setPeriodTimeLackAgentId(0);
if ($this->isPeriodTimeLackControlEnabled($schedule, $violationRules))
{
$agentId = $this->addAgent(
$this->preparePeriodTimeLackAgentFields($schedule, $violationRules)
);
$violationRules->setPeriodTimeLackAgentId($agentId);
$this->violationRulesRepository->save($violationRules);
}
if ($violationRules->getPeriodTimeLackAgentId() === 0)
{
$listToUpdate->add($violationRules);
}
}
return $this->violationRulesRepository->saveAll($listToUpdate, ['PERIOD_TIME_LACK_AGENT_ID' => 0]);
}