- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/integration/im/notification/usecase/taskcreated.php
- Класс: BitrixTasksIntegrationIMNotificationUseCaseTaskCreated
- Вызов: TaskCreated::getNotification
public function getNotification(Message $message): ?Notification
{
$metadata = $message->getMetaData();
$task = $metadata->getTask();
$userRepository = $metadata->getUserRepository();
if ($task === null || $userRepository === null)
{
return null;
}
$recepient = $message->getRecepient();
$responsible = $this->getResponsible($metadata->getTask(), $metadata->getUserRepository());
$locKey = 'TASKS_NEW_TASK_MESSAGE';
$nameTemplate = $metadata->getParams()['user_params']['NAME_TEMPLATE'] ?? null;
$serverTimeZoneOffset = $metadata->getUserRepository()->getUserTimeZoneOffset(0);
$description = '';
if ($responsible instanceof User)
{
$description .= Loc::getMessage('TASKS_MESSAGE_RESPONSIBLE_ID', null, $recepient->getLang());
$description .= ': '. $responsible->toString($nameTemplate) . "rn";
}
$accomplices = $this->getCommaSeparatedUserNames($userRepository, $task->getAccompliceMembersIds(), $nameTemplate);
if ($accomplices)
{
$description .= Loc::getMessage('TASKS_MESSAGE_ACCOMPLICES', null, $recepient->getLang());
$description .= ': ' . $accomplices . "rn";
}
$auditors = $this->getCommaSeparatedUserNames($userRepository, $task->getAuditorMembersIds(), $nameTemplate);
if ($auditors)
{
$description .= Loc::getMessage('TASKS_MESSAGE_AUDITORS', null, $recepient->getLang());
$description .= ': ' . $auditors . "rn";
}
if ($task->getDeadline())
{
// Get unix timestamp for DEADLINE
$utsDeadline = $task->getDeadline()->getTimestamp() - $serverTimeZoneOffset;
$recepientTimeZoneOffset = $userRepository->getUserTimeZoneOffset($recepient->getId());
// Make bitrix timestamp for given user
$bitrixTsDeadline = $utsDeadline + $recepientTimeZoneOffset;
$deadlineAsString = BitrixTasksUI::formatDateTime($bitrixTsDeadline, '^'.BitrixTasksUI::getDateTimeFormat());
$description .= Loc::getMessage('TASKS_MESSAGE_DEADLINE', null, $recepient->getLang());
$description .= ': ' . $deadlineAsString . "rn";
}
$notification = new Notification(
$locKey,
$message
);
$title = new NotificationTaskTitle($task);
$notification->addTemplate(new NotificationTemplate('#TASK_TITLE#', $title->getFormatted($recepient->getLang())));
$notification->addTemplate(new NotificationTemplate('#TASK_EXTRA#', $description));
return $notification;
}