• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/timeline/commentcontroller.php
  • Класс: Bitrix\Crm\Timeline\CommentController
  • Вызов: CommentController::sendMentions
private function sendMentions($id, array $data)
{
	$mentionList = self::getMentionIds($data['COMMENT']);

	if (!empty($mentionList))
	{
		$currentUser = \CCrmSecurityHelper::GetCurrentUserID();
		$parser = static::getParser();
		if ($parser instanceof \forumTextParser)
		{
			$data['COMMENT'] = $parser->clearAllTags($data['COMMENT']);
		}
		else
		{
			$data['COMMENT'] = preg_replace('/\[[^\]]+\]/', '', $data['COMMENT']);
		}
		$data['COMMENT'] = trim($data['COMMENT']);
		$cuttedComment = TruncateText($data['COMMENT'], 255);
		$userDB = \CUser::GetByID($currentUser);
		if (\CCrmOwnerType::isPossibleDynamicTypeId((int)$data['ENTITY_TYPE_ID']))
		{
			$entityName = \CCrmOwnerType::CommonDynamicName;
		}
		else
		{
			$entityName = \CCrmOwnerType::ResolveName($data['ENTITY_TYPE_ID']);
		}
		$genderSuffix = "";
		if ($arUser = $userDB->Fetch())
		{
			switch ($arUser["PERSONAL_GENDER"])
			{
				case "M":
					$genderSuffix = "_M";
					break;
				case "F":
					$genderSuffix = "_F";
					break;
			}
		}

		$info = array();
		\CCrmOwnerType::TryGetInfo($data['ENTITY_TYPE_ID'], $data['ENTITY_ID'], $info);
		$info['LINK'] = \CCrmOwnerType::GetEntityShowPath($data['ENTITY_TYPE_ID'], $data['ENTITY_ID']);
		$nameLink = "" . htmlspecialcharsbx($info['CAPTION']) . "";
		$phrase = "CRM_ENTITY_TITLE_" . $entityName;
		if ($entityName === \CCrmOwnerType::SmartInvoiceName)
		{
			$phrase = "CRM_ENTITY_TITLE_" . \CCrmOwnerType::InvoiceName;
		}
		$entityTitle = Loc::getMessage($phrase, ["#ENTITY_NAME#" => $nameLink]);
		if (!$entityTitle)
		{
			$entityTitle = Loc::getMessage($phrase . '_MSGVER_1', ["#ENTITY_NAME#" => $nameLink]);
		}
		$message = Loc::getMessage("CRM_COMMENT_IM_MENTION_POST" . $genderSuffix, [
			"#COMMENT#" => $cuttedComment,
			"#ENTITY_TITLE#" => $entityTitle
		]);
		$oldMentionList = $data['OLD_MENTION_LIST'] ?? [];
		foreach ($mentionList as $mentionId)
		{
			$mentionId = (int)$mentionId;
			if ($mentionId <= 0 || $currentUser === $mentionId || in_array( $mentionId, $oldMentionList ))
				continue;

			\CIMNotify::Add(array(
				'TO_USER_ID' => $mentionId,
				'FROM_USER_ID' => $currentUser,
				'NOTIFY_TYPE' => IM_NOTIFY_FROM,
				'NOTIFY_MODULE' => 'crm',
				'NOTIFY_EVENT' => 'mention',
				'NOTIFY_TAG' => 'CRM|MESSAGE_TIMELINE_MENTION|' . $id,
				'NOTIFY_MESSAGE' => $message
			));
		}
	}
}