- Модуль: imopenlines
- Путь к файлу: ~/bitrix/modules/imopenlines/lib/chat.php
- Класс: BitrixImOpenLinesChat
- Вызов: Chat::sendRatingNotify
static function sendRatingNotify($type, $sessionId, $rating, $toUserId, $fromUserId = null)
{
$result = false;
$toUserId = intval($toUserId);
$fromUserId = intval($fromUserId);
if ($fromUserId <= 0)
{
$fromUserId = $GLOBALS['USER']->GetId();
}
if (
Loader::includeModule('im') &&
in_array($type, Array(self::RATING_TYPE_CLIENT, self::RATING_TYPE_HEAD, self::RATING_TYPE_HEAD_AND_COMMENT, self::RATING_TYPE_COMMENT)) &&
$toUserId > 0 &&
$toUserId != $fromUserId
)
{
$commentValue = null;
$ratingValue = null;
if($type == self::RATING_TYPE_CLIENT || $type == self::RATING_TYPE_HEAD)
{
$rating = intval($rating);
if ($rating < 6 && $rating > 0)
{
$ratingValue = $rating;
}
}
elseif($type == self::RATING_TYPE_COMMENT)
{
$commentValue = htmlspecialcharsbx($rating);
}
elseif($type == self::RATING_TYPE_HEAD_AND_COMMENT)
{
if ($rating['vote'] < 6 && $rating['vote'] > 0)
{
$ratingValue = $rating['vote'];
}
$commentValue = htmlspecialcharsbx($rating['comment']);
}
if($commentValue !== null || $ratingValue !== null)
{
$userName = '';
if ($type == self::RATING_TYPE_CLIENT)
{
$notifyMessageName = $ratingValue == self::RATING_VALUE_DISLIKE? 'IMOL_CHAT_NOTIFY_RATING_CLIENT_DISLIKE_NEW': 'IMOL_CHAT_NOTIFY_RATING_CLIENT_LIKE_NEW';
$ratingImage = $ratingValue == self::RATING_VALUE_DISLIKE? '[dislike]': '[like]';
$ratingText = Loc::getMessage('IMOL_CHAT_NOTIFY_RATING_VALUE_'.($ratingValue == self::RATING_VALUE_DISLIKE? 'DISLIKE': 'LIKE'));
$commentText = '';
}
else
{
$userName = User::getInstance($fromUserId)->getFullName(false);
$userGender = User::getInstance($fromUserId)->getGender();
if($type == self::RATING_TYPE_HEAD)
{
$notifyMessageName = 'IMOL_CHAT_NOTIFY_RATING_HEAD_' . $userGender . '_LIKE';
$ratingImage = "[RATING=" . $ratingValue . "]";
$ratingText = Loc::getMessage('IMOL_CHAT_NOTIFY_RATING_VALUE_' . $ratingValue);
$commentText = '';
}
elseif($type == self::RATING_TYPE_COMMENT)
{
$notifyMessageName = 'IMOL_CHAT_NOTIFY_RATING_HEAD_' . $userGender . '_COMMENT';
$ratingImage = "[RATING=" . $ratingValue . "]";
$ratingText = '';
$commentText = $commentValue;
}
else
{
$notifyMessageName = 'IMOL_CHAT_NOTIFY_RATING_HEAD_'.$userGender.'_LIKE_AND_COMMENT';
$ratingImage = "[RATING=" . $ratingValue . "]";
$ratingText = Loc::getMessage('IMOL_CHAT_NOTIFY_RATING_VALUE_' . $ratingValue);
$commentText = $commentValue;
}
}
$userViewChat = CIMContactList::InRecent($toUserId, IM_MESSAGE_OPEN_LINE, $sessionId);
CIMNotify::DeleteBySubTag("IMOL|RATING|".$type.'|'.$sessionId);
CIMNotify::Add(array(
"TO_USER_ID" => $toUserId,
"NOTIFY_TYPE" => IM_NOTIFY_SYSTEM,
"NOTIFY_MODULE" => "imopenlines",
"NOTIFY_EVENT" => $type == self::RATING_TYPE_CLIENT? 'rating_client': 'rating_head',
"NOTIFY_SUB_TAG" => "IMOL|RATING|".$type.'|'.$sessionId,
"NOTIFY_MESSAGE" => '[b]'.Loc::getMessage('IMOL_CHAT_NOTIFY_RATING_TITLE').'[/b][br]'.Loc::getMessage($notifyMessageName, Array(
'#NUMBER#' => '[CHAT=imol|'.$sessionId.']'.$sessionId.'[/CHAT]',
'#USER#' => '[USER='.$fromUserId.']'.$userName.'[/USER]',
'#RATING#' => $ratingImage,
'#COMMENT#' => $commentText,
)),
"NOTIFY_MESSAGE_OUT" => '[b]'.Loc::getMessage('IMOL_CHAT_NOTIFY_RATING_TITLE').'[/b][br]'.Loc::getMessage($notifyMessageName, Array(
'#NUMBER#' => '[URL=/online/?IM_HISTORY=imol|'.$sessionId.']'.$sessionId.'[/URL]',
'#USER#' => $userName,
'#RATING#' => $ratingText,
'#COMMENT#' => $commentText,
)),
"RECENT_ADD" => $userViewChat? 'Y': 'N'
));
$result = true;
}
}
return $result;
}