- Модуль: timeman
- Путь к файлу: ~/bitrix/modules/timeman/lib/service/agent/violationnotifieragent.php
- Класс: BitrixTimemanServiceAgentViolationNotifierAgent
- Вызов: ViolationNotifierAgent::notifyIfPeriodTimeLack
static function notifyIfPeriodTimeLack($scheduleId, $fromDateTimeFormatted, $toDateTimeFormatted, $entityCode = null)
{
if ($entityCode === null)
{
$entityCode = EntityCodesHelper::getAllUsersCode();
}
$violationRules = DependencyManager::getInstance()
->getViolationRulesRepository()
->findByScheduleIdEntityCode($scheduleId, $entityCode);
if (!$violationRules)
{
return '';
}
$violationRules->setPeriodTimeLackAgentId(0);
DependencyManager::getInstance()
->getViolationRulesRepository()
->save($violationRules);
$schedule = DependencyManager::getInstance()
->getScheduleRepository()
->findByIdWith($scheduleId, ['SHIFTS', 'DEPARTMENT_ASSIGNMENTS', 'USER_ASSIGNMENTS']);
if (!$schedule || !$schedule->isFixed())
{
return '';
}
if (empty($violationRules->getNotifyUsersSymbolic(ViolationRulesTable::USERS_TO_NOTIFY_FIXED_TIME_FOR_PERIOD)))
{
return '';
}
$fromDateTime = DateTime::createFromFormat(TimeDictionary::DATE_TIME_FORMAT, $fromDateTimeFormatted);
$expectedToDateTime = static::buildExpectedPeriodEndDate($fromDateTime, $schedule);
if ($expectedToDateTime->format(TimeDictionary::DATE_TIME_FORMAT) !== $toDateTimeFormatted)
{
return '';
}
$violationResult = DependencyManager::getInstance()
->getViolationManager()
->buildPeriodTimeLackViolation(
(new WorktimeViolationParams())
->setSchedule($schedule)
->setViolationRules($violationRules),
$fromDateTime,
$expectedToDateTime
);
if (!$violationResult->isSuccess())
{
return '';
}
$users = static::findUsers($violationResult);
DependencyManager::getInstance()
->getWorktimeNotificationService()
->sendViolationsNotifications(
$schedule,
$violationResult->getViolations(),
null,
function ($violation, $toUserId) use ($users) {
$notificationParams = new NotificationParameters();
$notificationParams->messageType = "S";
$notificationParams->fromUserId = $violation->userId;
$notificationParams->toUserId = $toUserId;
$notificationParams->notifyType = 2;
$notificationParams->notifyModule = 'timeman';
$notificationParams->notifyEvent = 'period_time_lack';
$gender = '_MALE';
$name = '';
if ($users[$violation->userId])
{
if ($users[$violation->userId]['PERSONAL_GENDER'] === 'F')
{
$gender = '_FEMALE';
}
$name = UserHelper::getInstance()->getFormattedName($users[$violation->userId]);
}
$notificationParams->notifyMessage = Loc::getMessage(
'TM_VIOLATION_NOTIFIER_AGENT_PERIOD_TIME_LACK' . $gender,
['#USER_NAME#' => $name]
);
return $notificationParams;
}
);
DependencyManager::getInstance()
->getWorktimeAgentManager()
->createTimeLackForPeriodChecking($schedule, $expectedToDateTime, $violationRules);
return '';
}