当前位置: 首页>>代码示例>>PHP>>正文


PHP CRatings::GetRatingUserProp方法代码示例

本文整理汇总了PHP中CRatings::GetRatingUserProp方法的典型用法代码示例。如果您正苦于以下问题:PHP CRatings::GetRatingUserProp方法的具体用法?PHP CRatings::GetRatingUserProp怎么用?PHP CRatings::GetRatingUserProp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRatings的用法示例。


在下文中一共展示了CRatings::GetRatingUserProp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: AddRatingVote

 /**
  * <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);
//.........这里部分代码省略.........
开发者ID:andy-profi,项目名称:bxApiDocs,代码行数:101,代码来源:ratings.php

示例2: CheckAllowVote

	function CheckAllowVote($arVoteParam)
	{
		global $USER;

		$userId = $USER->GetId();
		$bUserAuth = $USER->IsAuthorized();
		$bAllGroups = false;

		$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 $cacheVoteAccess = null;
			static $cacheVoteGroup = array();
			static $cacheVoteSize = 0;
			if(!array_key_exists($userId, $cacheAllowVote))
			{
				global $DB;
				$arGroups = array();
				$bAllGroups = false;
				$sVoteType = $arVoteParam['ENTITY_TYPE_ID'] == 'USER'? 'A': 'R';
				if (!isset($cacheVoteGroup[$sVoteType]))
				{
					$cacheVoteGroup[$sVoteType] = Array();
					$rsGroups = CRatings::GetVoteGroup($sVoteType);
					while ($arVoteGroup = $rsGroups->Fetch())
						$cacheVoteGroup[$sVoteType][] = $arVoteGroup;
				}
				foreach($cacheVoteGroup[$sVoteType] as $arVoteGroup)
				{
					if ($arVoteGroup['GROUP_ID'] == 2)
					{
						$bAllGroups = true;
						break;
					}
					$arGroups[] = $arVoteGroup['GROUP_ID'];
				}
				if (!$bAllGroups && !empty($arGroups) && is_null($cacheVoteAccess))
				{
					$strSql = '
						SELECT * FROM b_user_group UG
						WHERE UG.GROUP_ID IN ('.implode(',', $arGroups).')
						AND UG.USER_ID = '.$userId.'
						AND ((UG.DATE_ACTIVE_FROM IS NULL) OR (UG.DATE_ACTIVE_FROM <= '.$DB->CurrentTimeFunction().'))
						AND ((UG.DATE_ACTIVE_TO IS NULL) OR (UG.DATE_ACTIVE_TO >= '.$DB->CurrentTimeFunction().'))';
					$res = $DB->Query($strSql, false, $err_mess.__LINE__);
					if ($row = $res->Fetch())
						$cacheVoteAccess = true;
					else
					{
						$cacheVoteAccess = false;
						$arInfo = $cacheAllowVote[$userId] = array(
							'RESULT' => false,
							'ERROR_TYPE' => 'ACCESS',
							'ERROR_MSG' => GetMessage('RATING_ALLOW_VOTE_ACCESS'),
						);
					}
				}

				$authorityRatingId	 = CRatings::GetAuthorityRating();
				$arAuthorityUserProp = CRatings::GetRatingUserProp($authorityRatingId, $userId);
				if ($arAuthorityUserProp['VOTE_WEIGHT'] <= 0)
				{
					$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.'
//.........这里部分代码省略.........
开发者ID:nProfessor,项目名称:Mytb,代码行数:101,代码来源:ratings.php


注:本文中的CRatings::GetRatingUserProp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。