• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/ratings.php
  • Класс: CAllRatings
  • Вызов: CAllRatings::getRatingVoteReaction
static function getRatingVoteReaction($arParam)
{
	global $DB;

	static $cache = array();

	$bplus = (mb_strtoupper($arParam['LIST_TYPE']) !== 'MINUS');
	$key = $arParam['ENTITY_TYPE_ID'].'_'.(int)$arParam['ENTITY_ID'].'_'.($bplus ? '1' : '0');

	if (
		isset($arParam['USE_REACTIONS_CACHE'])
		&& $arParam['USE_REACTIONS_CACHE'] === 'Y'
		&& isset($cache[$key])
	)
	{
		$result = $cache[$key];
	}
	else
	{
		$sqlStr = "
			SELECT
				REACTION,
				COUNT(RV.ID) as CNT
			FROM
				b_rating_vote RV
			WHERE
				RV.ENTITY_TYPE_ID = '".$DB->ForSql($arParam['ENTITY_TYPE_ID'])."'
				AND RV.ENTITY_ID = ".(int)$arParam['ENTITY_ID']." ".
//				($bplus ? " AND RV.VALUE > 0 ": " and RV.VALUE < 0 ")
			"GROUP BY REACTION";
		$res_cnt = $DB->Query($sqlStr);

		$cnt = 0;
		$cntReactions = array();
		while($ar_cnt = $res_cnt->fetch())
		{
			$key = (!empty($ar_cnt["REACTION"]) ? $ar_cnt["REACTION"] : self::REACTION_DEFAULT);
			if (!isset($cntReactions[$key]))
			{
				$cntReactions[$key] = 0;
			}
			$cntReactions[$key] += $ar_cnt["CNT"];
			$cnt += $ar_cnt["CNT"];
		}

		$result = $cache[$key] = array(
			'items_all' => $cnt,
			'reactions' => $cntReactions
		);
	}

	return $result;
}