- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/mysql/ratings.php
- Класс: CRatings
- Вызов: CRatings::CheckAllowVote
static function CheckAllowVote($arVoteParam)
{
global $USER;
if (
isset($arVoteParam['CURRENT_USER_ID'])
&& (int)$arVoteParam['CURRENT_USER_ID'] > 0
)
{
$userId = (int)$arVoteParam['CURRENT_USER_ID'];
$bUserAuth = ($userId > 0);
}
else
{
$userId = (int)$USER->GetId();
$bUserAuth = $USER->IsAuthorized();
}
$arInfo = array(
'RESULT' => true,
'ERROR_TYPE' => '',
'ERROR_MSG' => '',
);
$bSelfVote = COption::GetOptionString("main", "rating_self_vote", 'N');
if ($bSelfVote == 'N' && intval($arVoteParam['OWNER_ID']) == $userId)
{
$arInfo = array(
'RESULT' => false,
'ERROR_TYPE' => 'SELF',
'ERROR_MSG' => GetMessage('RATING_ALLOW_VOTE_SELF'),
);
}
else if (!$bUserAuth)
{
$arInfo = array(
'RESULT' => false,
'ERROR_TYPE' => 'GUEST',
'ERROR_MSG' => GetMessage('RATING_ALLOW_VOTE_GUEST'),
);
}
else
{
static $cacheAllowVote = array();
static $cacheUserVote = array();
static $cacheVoteSize = 0;
if(!array_key_exists($userId, $cacheAllowVote))
{
global $DB;
$arGroups = array();
$sVoteType = $arVoteParam['ENTITY_TYPE_ID'] == 'USER'? 'A': 'R';
$userVoteGroup = Array();
$ar = CRatings::GetVoteGroupEx();
foreach($ar as $group)
if ($sVoteType == $group['TYPE'])
$userVoteGroup[] = $group['GROUP_ID'];
$userGroup = $USER->GetUserGroupArray();
$result = array_intersect($userGroup, $userVoteGroup);
if (empty($result))
{
$arInfo = $cacheAllowVote[$userId] = array(
'RESULT' => false,
'ERROR_TYPE' => 'ACCESS',
'ERROR_MSG' => GetMessage('RATING_ALLOW_VOTE_ACCESS'),
);
}
$authorityRatingId = CRatings::GetAuthorityRating();
$arAuthorityUserProp = CRatings::GetRatingUserPropEx($authorityRatingId, $userId);
if (
$arAuthorityUserProp['VOTE_WEIGHT'] < 0
|| (
$arAuthorityUserProp['VOTE_WEIGHT'] == 0
&& !IsModuleInstalled('intranet')
)
)
{
$arInfo = $cacheAllowVote[$userId] = array(
'RESULT' => false,
'ERROR_TYPE' => 'ACCESS',
'ERROR_MSG' => GetMessage('RATING_ALLOW_VOTE_LOW_WEIGHT'),
);
}
if ($arInfo['RESULT'] && $sVoteType == 'A')
{
$strSql = '
SELECT COUNT(*) as VOTE
FROM b_rating_vote RV
WHERE RV.USER_ID = '.$userId.'
AND RV.CREATED > ' . $helper->addDaysToDateTime(-1);
$res = $DB->Query($strSql, false, $err_mess.__LINE__);
$countVote = $res->Fetch();
$cacheVoteSize = BitrixMainApplication::getInstance()->getSession()['RATING_VOTE_COUNT'] = $countVote['VOTE'];
$cacheUserVote[$userId] = BitrixMainApplication::getInstance()->getSession()['RATING_USER_VOTE_COUNT'] = $arAuthorityUserProp['VOTE_COUNT'];
if ($cacheVoteSize >= $cacheUserVote[$userId])
{
$arInfo = $cacheAllowVote[$userId] = array(
'RESULT' => false,
'ERROR_TYPE' => 'COUNT_VOTE',
'ERROR_MSG' => GetMessage('RATING_ALLOW_VOTE_COUNT_VOTE'),
);
}
}
}
else
{
if ($cacheAllowVote[$userId]['RESULT'])
{
if ($cacheVoteSize >= $cacheUserVote[$userId])
{
$arInfo = $cacheAllowVote[$userId] = array(
'RESULT' => false,
'ERROR_TYPE' => 'COUNT_VOTE',
'ERROR_MSG' => GetMessage('RATING_ALLOW_VOTE_COUNT_VOTE'),
);
}
}
$arInfo = $cacheAllowVote[$userId];
}
}
static $handlers;
if (!isset($handlers))
$handlers = GetModuleEvents("main", "OnAfterCheckAllowVote", true);
foreach ($handlers as $arEvent)
{
$arEventResult = ExecuteModuleEventEx($arEvent, array($arVoteParam));
if (is_array($arEventResult) && isset($arEventResult['RESULT']) && $arEventResult['RESULT'] === false
&& isset($arEventResult['ERROR_TYPE']) && $arEventResult['ERROR_TYPE'] <> ''
&& isset($arEventResult['ERROR_MSG']) && $arEventResult['ERROR_MSG'] <> '')
{
$arInfo = array(
'RESULT' => false,
'ERROR_TYPE' => $arEventResult['ERROR_TYPE'],
'ERROR_MSG' => $arEventResult['ERROR_MSG'],
);
}
}
return $arInfo;
}