示例#1
0
 /**
  * <p>Метод добавляет голос к рейтинговому голосованию. Динамичный метод.</p>
  *
  *
  * @param array $Param  Массив значений параметров. В качестве ключей данного массива
  * допустимо использовать: <ul> <li> <b>ENTITY_TYPE_ID</b> – объект голосования.
  * Например: FORUM_TOPIC для тем форума, FORUM_POST для сообщений форума, BLOG_POST
  * для постов в блоге, BLOG_COMMENT для комментариев в блоге. Сам список
  * кодов не регламентирован, можно использовать любой удобный.</li> <li>
  * <b>ENTITY_ID</b> – идентификатор объекта голосования</li> <li> <b>VALUE</b> –
  * выставленная оценка</li> <li> <b>USER_ID</b> – идентификатор
  * пользователя</li> <li> <b>USER_IP</b> – IP-адрес пользователя</li> </ul> Все поля
  * являются обязательными.
  *
  * @return bool 
  *
  * <h4>Example</h4> 
  * <pre>
  * &lt;?
  * // добавляем теме отрицательную оценку.
  * $arAddVote = array(
  * 	"ENTITY_TYPE_ID"  =&gt;  "FORUM_TOPIC",
  * 	"ENTITY_ID"       =&gt;  38,
  * 	"VALUE"           =&gt;  -1,
  * 	"USER_ID"         =&gt;  1, 
  *  	"USER_IP"         =&gt;  '127.0.0.1',
  * );
  * CRatings::AddRatingVote($arAddVote);
  * ?&gt;
  * </pre>
  *
  *
  * @static
  * @link http://dev.1c-bitrix.ru/api_help/main/reference/cratings/addratingvote.php
  * @author Bitrix
  */
 public static function AddRatingVote($arParam)
 {
     global $DB, $CACHE_MANAGER;
     if (isset($_SESSION['RATING_VOTE_COUNT']) && $arParam['ENTITY_TYPE_ID'] == 'USER') {
         if ($_SESSION['RATING_VOTE_COUNT'] >= $_SESSION['RATING_USER_VOTE_COUNT']) {
             return false;
         } else {
             $_SESSION['RATING_VOTE_COUNT']++;
         }
     }
     $arParam['ENTITY_TYPE_ID'] = substr($arParam['ENTITY_TYPE_ID'], 0, 50);
     CRatings::CancelRatingVote($arParam);
     $err_mess = CRatings::err_mess() . "<br>Function: AddRatingVote<br>Line: ";
     $votePlus = $arParam['VALUE'] >= 0 ? true : false;
     $ratingId = CRatings::GetAuthorityRating();
     $arRatingUserProp = CRatings::GetRatingUserProp($ratingId, $arParam['USER_ID']);
     $voteUserWeight = $arRatingUserProp['VOTE_WEIGHT'];
     $sRatingWeightType = COption::GetOptionString("main", "rating_weight_type", "auto");
     if ($sRatingWeightType == 'auto') {
         if ($arParam['ENTITY_TYPE_ID'] == 'USER') {
             $sRatingAuthrorityWeight = COption::GetOptionString("main", "rating_authority_weight_formula", 'Y');
             if ($sRatingAuthrorityWeight == 'Y') {
                 $communitySize = COption::GetOptionString("main", "rating_community_size", 1);
                 $communityAuthority = COption::GetOptionString("main", "rating_community_authority", 1);
                 $voteWeight = COption::GetOptionString("main", "rating_vote_weight", 1);
                 $arParam['VALUE'] = $arParam['VALUE'] * ($communitySize * ($voteUserWeight / $voteWeight) / $communityAuthority);
             }
         } else {
             $arParam['VALUE'] = $arParam['VALUE'] * $voteUserWeight;
         }
     } else {
         $arParam['VALUE'] = $arParam['VALUE'] * $voteUserWeight;
     }
     $arFields = array('ACTIVE' => "'Y'", 'TOTAL_VOTES' => "TOTAL_VOTES+1", 'TOTAL_VALUE' => "TOTAL_VALUE" . ($votePlus ? '+' : '') . floatval($arParam['VALUE']), 'LAST_CALCULATED' => $DB->GetNowFunction());
     $arFields[$votePlus ? 'TOTAL_POSITIVE_VOTES' : 'TOTAL_NEGATIVE_VOTES'] = $votePlus ? 'TOTAL_POSITIVE_VOTES+1' : 'TOTAL_NEGATIVE_VOTES+1';
     // GetOwnerDocument
     $arParam['OWNER_ID'] = 0;
     foreach (GetModuleEvents("main", "OnGetRatingContentOwner", true) as $arEvent) {
         $result = ExecuteModuleEventEx($arEvent, array($arParam));
         if ($result !== false) {
             $arParam['OWNER_ID'] = IntVal($result);
         }
     }
     $rowAffected = $DB->Update("b_rating_voting", $arFields, "WHERE ENTITY_TYPE_ID='" . $DB->ForSql($arParam['ENTITY_TYPE_ID']) . "' AND ENTITY_ID='" . intval($arParam['ENTITY_ID']) . "'", $err_mess . __LINE__);
     if ($rowAffected > 0) {
         $rsRV = $DB->Query("SELECT ID, TOTAL_POSITIVE_VOTES FROM b_rating_voting WHERE ENTITY_TYPE_ID='" . $DB->ForSql($arParam['ENTITY_TYPE_ID']) . "' AND ENTITY_ID='" . intval($arParam['ENTITY_ID']) . "'", false, $err_mess . __LINE__);
         $arRV = $rsRV->Fetch();
         $arParam['RATING_VOTING_ID'] = $arRV['ID'];
         $arParam['TOTAL_POSITIVE_VOTES'] = $arRV['TOTAL_POSITIVE_VOTES'];
     } else {
         $arFields = array("ENTITY_TYPE_ID" => "'" . $DB->ForSql($arParam["ENTITY_TYPE_ID"]) . "'", "ENTITY_ID" => intval($arParam['ENTITY_ID']), "OWNER_ID" => intval($arParam['OWNER_ID']), "ACTIVE" => "'Y'", "CREATED" => $DB->GetNowFunction(), "LAST_CALCULATED" => $DB->GetNowFunction(), "TOTAL_VOTES" => 1, "TOTAL_VALUE" => floatval($arParam['VALUE']), "TOTAL_POSITIVE_VOTES" => $votePlus ? 1 : 0, "TOTAL_NEGATIVE_VOTES" => $votePlus ? 0 : 1);
         $arParam['RATING_VOTING_ID'] = $DB->Insert("b_rating_voting", $arFields, $err_mess . __LINE__);
         $arParam['TOTAL_POSITIVE_VOTES'] = $votePlus ? 1 : 0;
     }
     $arFields = array("RATING_VOTING_ID" => intval($arParam['RATING_VOTING_ID']), "ENTITY_TYPE_ID" => "'" . $DB->ForSql($arParam["ENTITY_TYPE_ID"]) . "'", "ENTITY_ID" => intval($arParam['ENTITY_ID']), "VALUE" => floatval($arParam['VALUE']), "ACTIVE" => "'Y'", "CREATED" => $DB->GetNowFunction(), "USER_ID" => intval($arParam['USER_ID']), "USER_IP" => "'" . $DB->ForSql($arParam["USER_IP"]) . "'", "OWNER_ID" => intval($arParam['OWNER_ID']));
     $ID = $DB->Insert("b_rating_vote", $arFields, $err_mess . __LINE__);
     foreach (GetModuleEvents("main", "OnAddRatingVote", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(intval($ID), $arParam));
     }
     if (CModule::IncludeModule('pull')) {
         CPullStack::AddShared(array('module_id' => 'main', 'command' => 'rating_vote', 'params' => array("TYPE" => "ADD", "USER_ID" => intval($arParam['USER_ID']), "ENTITY_TYPE_ID" => $arParam["ENTITY_TYPE_ID"], "ENTITY_ID" => intval($arParam['ENTITY_ID']), "TOTAL_POSITIVE_VOTES" => $arParam['TOTAL_POSITIVE_VOTES'], "RESULT" => $votePlus ? 'PLUS' : 'MINUS')));
     }
     if (CACHED_b_rating_vote !== false) {
         $bucket_size = intval(CACHED_b_rating_bucket_size);
         if ($bucket_size <= 0) {
             $bucket_size = 100;
         }
         $bucket = intval(intval($arParam['ENTITY_ID']) / $bucket_size);
         $CACHE_MANAGER->Clean("b_rvg_" . $DB->ForSql($arParam["ENTITY_TYPE_ID"]) . $bucket, "b_rating_voting");
     }
     return true;
 }
示例#2
0
         $arParams['TOTAL_NEGATIVE_VOTES'] = 0;
         $arParams['USER_HAS_VOTED'] = 'N';
         $arParams['USER_VOTE'] = '0';
     }
     $arAllowVote = CRatings::CheckAllowVote($arParams);
     if ($arAllowVote['RESULT']) {
         $APPLICATION->RestartBuffer();
         $action = 'list';
         if ($_POST['RATING_VOTE_ACTION'] == 'plus' || $_POST['RATING_VOTE_ACTION'] == 'minus') {
             $arAdd = array("ENTITY_TYPE_ID" => $_POST['RATING_VOTE_TYPE_ID'], "ENTITY_ID" => intval($_POST['RATING_VOTE_ENTITY_ID']), "VALUE" => $_POST['RATING_VOTE_ACTION'] == 'plus' ? 1 : -1, "USER_IP" => $_SERVER['REMOTE_ADDR'], "USER_ID" => $USER->GetId());
             CRatings::AddRatingVote($arAdd);
             $action = $_POST['RATING_VOTE_ACTION'];
         } else {
             if ($_POST['RATING_VOTE_ACTION'] == 'cancel') {
                 $arCancel = array("ENTITY_TYPE_ID" => $_POST['RATING_VOTE_TYPE_ID'], "ENTITY_ID" => intval($_POST['RATING_VOTE_ENTITY_ID']), "USER_ID" => $USER->GetId());
                 CRatings::CancelRatingVote($arCancel);
                 $action = $_POST['RATING_VOTE_ACTION'];
             }
         }
         $ar = array("ENTITY_TYPE_ID" => $_POST['RATING_VOTE_TYPE_ID'], "ENTITY_ID" => intval($_POST['RATING_VOTE_ENTITY_ID']), "LIST_LIMIT" => 0, "LIST_TYPE" => isset($_POST['RATING_VOTE_ACTION']) && $_POST['RATING_VOTE_ACTION'] == 'minus' ? 'minus' : 'plus');
         $arVoteList = CRatings::GetRatingVoteList($ar);
         if ($_POST['RATING_RESULT'] == 'Y') {
             $arVoteResult = GetVoteResult($_POST['RATING_VOTE_TYPE_ID'], $_POST['RATING_VOTE_ENTITY_ID']);
             $arVoteList = array_merge($arVoteList, $arVoteResult);
         }
         $arVoteList['action'] = $action;
         Header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
         echo CUtil::PhpToJsObject($arVoteList);
     }
 } else {
     if ($_POST['RATING_RESULT'] == 'Y' && strlen($_POST['RATING_VOTE_TYPE_ID']) > 0 && intval($_POST['RATING_VOTE_ENTITY_ID']) > 0 && check_bitrix_sessid()) {
示例#3
0
 function AddRatingVote($arParam)
 {
     global $DB, $CACHE_MANAGER;
     if (isset($_SESSION['RATING_VOTE_COUNT']) && $arParam['ENTITY_TYPE_ID'] == 'USER') {
         if ($_SESSION['RATING_VOTE_COUNT'] >= $_SESSION['RATING_USER_VOTE_COUNT']) {
             return false;
         } else {
             $_SESSION['RATING_VOTE_COUNT']++;
         }
     }
     CRatings::CancelRatingVote($arParam);
     $err_mess = CRatings::err_mess() . "<br>Function: AddRatingVote<br>Line: ";
     $votePlus = $arParam['VALUE'] < 0 ? false : true;
     $ratingId = CRatings::GetAuthorityRating();
     $arRatingUserProp = CRatings::GetRatingUserProp($ratingId, $arParam['USER_ID']);
     $voteUserWeight = $arRatingUserProp['VOTE_WEIGHT'];
     $sRatingWeightType = COption::GetOptionString("main", "rating_weight_type", "auto");
     if ($sRatingWeightType == 'auto') {
         if ($arParam['ENTITY_TYPE_ID'] == 'USER') {
             $sRatingAuthrorityWeight = COption::GetOptionString("main", "rating_authority_weight_formula", 'Y');
             if ($sRatingAuthrorityWeight == 'Y') {
                 $communitySize = COption::GetOptionString("main", "rating_community_size", 1);
                 $communityAuthority = COption::GetOptionString("main", "rating_community_authority", 1);
                 $voteWeight = COption::GetOptionString("main", "rating_vote_weight", 1);
                 $arParam['VALUE'] = $arParam['VALUE'] * ($communitySize * ($voteUserWeight / $voteWeight) / $communityAuthority);
             }
         } else {
             $arParam['VALUE'] = $arParam['VALUE'] * $voteUserWeight;
         }
     } else {
         $arParam['VALUE'] = $arParam['VALUE'] * $voteUserWeight;
     }
     $arFields = array('ACTIVE' => "'Y'", 'TOTAL_VOTES' => "TOTAL_VOTES+1", 'TOTAL_VALUE' => "TOTAL_VALUE" . ($votePlus ? '+' : '') . floatval($arParam['VALUE']), 'LAST_CALCULATED' => $DB->GetNowFunction());
     $arFields[$votePlus ? 'TOTAL_POSITIVE_VOTES' : 'TOTAL_NEGATIVE_VOTES'] = $votePlus ? 'TOTAL_POSITIVE_VOTES+1' : 'TOTAL_NEGATIVE_VOTES+1';
     // GetOwnerDocument
     $arParam['OWNER_ID'] = 0;
     $db_events = GetModuleEvents("main", "OnGetRatingContentOwner");
     while ($arEvent = $db_events->Fetch()) {
         $result = ExecuteModuleEventEx($arEvent, array($arParam));
         if ($result !== false) {
             $arParam['OWNER_ID'] = IntVal($result);
         }
     }
     $rowAffected = $DB->Update("b_rating_voting", $arFields, "WHERE ENTITY_TYPE_ID='" . $DB->ForSql($arParam['ENTITY_TYPE_ID']) . "' AND ENTITY_ID='" . intval($arParam['ENTITY_ID']) . "'", $err_mess . __LINE__);
     if ($rowAffected > 0) {
         $rsRV = $DB->Query("SELECT ID FROM b_rating_voting WHERE ENTITY_TYPE_ID='" . $DB->ForSql($arParam['ENTITY_TYPE_ID']) . "' AND ENTITY_ID='" . intval($arParam['ENTITY_ID']) . "'", false, $err_mess . __LINE__);
         $arRV = $rsRV->Fetch();
         $arParam['RATING_VOTING_ID'] = $arRV['ID'];
     } else {
         $arFields = array("ENTITY_TYPE_ID" => "'" . $DB->ForSql($arParam["ENTITY_TYPE_ID"]) . "'", "ENTITY_ID" => intval($arParam['ENTITY_ID']), "OWNER_ID" => intval($arParam['OWNER_ID']), "ACTIVE" => "'Y'", "CREATED" => $DB->GetNowFunction(), "LAST_CALCULATED" => $DB->GetNowFunction(), "TOTAL_VOTES" => 1, "TOTAL_VALUE" => floatval($arParam['VALUE']), "TOTAL_POSITIVE_VOTES" => $votePlus ? 1 : 0, "TOTAL_NEGATIVE_VOTES" => $votePlus ? 0 : 1);
         $arParam['RATING_VOTING_ID'] = $DB->Insert("b_rating_voting", $arFields, $err_mess . __LINE__);
     }
     $arFields = array("RATING_VOTING_ID" => intval($arParam['RATING_VOTING_ID']), "ENTITY_TYPE_ID" => "'" . $DB->ForSql($arParam["ENTITY_TYPE_ID"]) . "'", "ENTITY_ID" => intval($arParam['ENTITY_ID']), "VALUE" => floatval($arParam['VALUE']), "ACTIVE" => "'Y'", "CREATED" => $DB->GetNowFunction(), "USER_ID" => intval($arParam['USER_ID']), "USER_IP" => "'" . $DB->ForSql($arParam["USER_IP"]) . "'", "OWNER_ID" => intval($arParam['OWNER_ID']));
     $ID = $DB->Insert("b_rating_vote", $arFields, $err_mess . __LINE__);
     $db_events = GetModuleEvents("main", "OnAddRatingVote");
     while ($arEvent = $db_events->Fetch()) {
         ExecuteModuleEventEx($arEvent, array(intval($ID), $arParam));
     }
     $CACHE_MANAGER->ClearByTag('RV_' . $arParam["ENTITY_TYPE_ID"] . "_" . intval($arParam['ENTITY_ID']));
     return true;
 }