- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/integration/im/notification/task/pushnotification.php
- Класс: BitrixTasksIntegrationIMNotificationTaskPushNotification
- Вызов: PushNotification::cropMessage
private function cropMessage(string $message, array $templates): string
{
$left = self::PUSH_MESSAGE_MAX_LENGTH - mb_strlen(preg_replace(self::PATTERN, '', $message));
$result = $message;
// todo: make more clever algorithm here
foreach($templates as $template)
{
$value = $template->getReplace();
$fullValue = $template->getReplace();
$placeHolder = '#'. $template->getSearch() .'#';
if ($left <= 0)
{
$result = str_replace($placeHolder, '', $result);
continue;
}
if (mb_strlen($template->getReplace()) > $left)
{
$value = mb_substr($template->getReplace(), 0, $left - 3).'...';
}
$result = str_replace($placeHolder, $value, $result);
$left -= mb_strlen($fullValue);
}
return $result;
}