Ejemplo n.º 1
0
	public static function GetCommunityInfo($ratingId)
	{
		global $DB;

		$bAllGroups = false;
		$arInfo = Array();
		$arGroups = Array();
		$communityLastVisit = COption::GetOptionString("main", "rating_community_last_visit", '90');
		$res = CRatings::GetVoteGroup();
		while ($arVoteGroup = $res->Fetch())
		{
			if ($arVoteGroup['GROUP_ID'] == 2)
			{
				$bAllGroups = true;
				break;
			}
			$arGroups[] = $arVoteGroup['GROUP_ID'];
		}

		$strModulesSql = '';
		if (IsModuleInstalled("forum"))
		{
			$strModulesSql .= "
					SELECT USER_START_ID as ENTITY_ID
					FROM b_forum_topic
					WHERE START_DATE > DATE_SUB(NOW(), INTERVAL ".intval($communityLastVisit)." DAY)
					GROUP BY USER_START_ID
				UNION ALL
					SELECT AUTHOR_ID as ENTITY_ID
					FROM b_forum_message
					WHERE POST_DATE > DATE_SUB(NOW(), INTERVAL ".intval($communityLastVisit)." DAY)
					GROUP BY AUTHOR_ID
				UNION ALL
			";
		}
		if (IsModuleInstalled("blog"))
		{
			$strModulesSql .= "
					SELECT	AUTHOR_ID as ENTITY_ID
					FROM b_blog_post
					WHERE DATE_PUBLISH > DATE_SUB(NOW(), INTERVAL ".intval($communityLastVisit)." DAY)
					GROUP BY AUTHOR_ID
				UNION ALL
					SELECT AUTHOR_ID as ENTITY_ID
					FROM b_blog_comment
					WHERE DATE_CREATE > DATE_SUB(NOW(), INTERVAL ".intval($communityLastVisit)." DAY)
					GROUP BY AUTHOR_ID
				UNION ALL";
		}
		if (IsModuleInstalled("intranet"))
		{
			$ratingId = COption::GetOptionString("main", "rating_authority_rating", 0);
			$strModulesSql .= "
					SELECT ENTITY_ID
					FROM b_rating_subordinate
					WHERE RATING_ID = $ratingId
				UNION ALL";
		}
		if (!empty($strModulesSql))
		{
			$strModulesSql = "
				(
					".$strModulesSql."
					SELECT USER_ID as ENTITY_ID
					FROM b_rating_vote
					WHERE CREATED > DATE_SUB(NOW(), INTERVAL ".intval($communityLastVisit)." DAY)
					GROUP BY USER_ID
				) MS,
			";
		}

		$DB->Query("TRUNCATE TABLE b_rating_prepare", false, $err_mess.__LINE__);
		if ($bAllGroups || empty($arGroups))
		{
			$strSql .= "
				INSERT INTO b_rating_prepare (ID)
				SELECT DISTINCT U.ID
				FROM ".$strModulesSql."
					b_user U
				WHERE ".(!empty($strModulesSql)? "U.ID = MS.ENTITY_ID AND": "")."
				U.ACTIVE = 'Y'
				AND U.LAST_LOGIN > DATE_SUB(NOW(), INTERVAL ".intval($communityLastVisit)." DAY)
			";
		}
		else
		{
			$strSql .= "
				INSERT INTO b_rating_prepare (ID)
				SELECT DISTINCT U.ID
				FROM ".$strModulesSql."
					b_user U
				WHERE ".(!empty($strModulesSql)? "U.ID = MS.ENTITY_ID AND": "")."
				U.ACTIVE = 'Y'
				AND U.LAST_LOGIN > DATE_SUB(NOW(), INTERVAL ".intval($communityLastVisit)." DAY)
			";
		}
		$DB->Query($strSql, false, $err_mess.__LINE__);

		$strSql = 'SELECT COUNT(*) as COMMUNITY_SIZE, SUM(CURRENT_VALUE) COMMUNITY_AUTHORITY
						FROM b_rating_results RC LEFT JOIN b_rating_prepare TT ON RC.ENTITY_ID = TT.ID
						WHERE RATING_ID = '.intval($ratingId).' AND TT.ID IS NOT NULL';
		$res = $DB->Query($strSql, false, $err_mess.__LINE__);

		return $res->Fetch();
	}
Ejemplo n.º 2
0
echo GetMessage('RATING_SETTINGS_FRM_ASSIGN_VOTE_2');
?>
: <input name="RATING_ASSIGN_RATING_GROUP_DELETE" value="<?php 
echo $ratingAssignRatingGroupDelete;
?>
" style="width:45px;" type="text">
			</td>
		</tr>

	<?




$arRatingVoteAuthorityGroupID = array();
$rsGroups = CRatings::GetVoteGroup('A');
while($arGroup = $rsGroups -> Fetch())
	$arRatingVoteAuthorityGroupID[] = $arGroup["GROUP_ID"];
?>
	<tr class="heading">
		<td colspan="2"><?php 
echo GetMessage('RATING_SETTINGS_FRM_AUTHORITY');
?>
</td>
	</tr>
	<tr>
		<td width="50%" valign="top"><?php 
echo GetMessage('RATING_SETTINGS_FRM_RATING_VOTE_AUTHORITY_GROUP_ID');
?>
</td>
		<td><?php 
Ejemplo n.º 3
0
	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.'
						AND RV.CREATED > DATE_SUB(NOW(), INTERVAL 1 DAY)';
					$res = $DB->Query($strSql, false, $err_mess.__LINE__);
					$countVote = $res->Fetch();
					$cacheVoteSize = $_SESSION['RATING_VOTE_COUNT'] = $countVote['VOTE'];

					$cacheUserVote[$userId] = $_SESSION['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];
			}
		}

		$db_events = GetModuleEvents("main", "OnAfterCheckAllowVote");
		while ($arEvent = $db_events->Fetch())
		{
			$arEventResult = ExecuteModuleEventEx($arEvent, array($arVoteParam));
			if (is_array($arEventResult) && isset($arEventResult['RESULT']) && $arEventResult['RESULT'] === false
				&& isset($arEventResult['ERROR_TYPE']) && strlen($arEventResult['ERROR_MSG']) > 0
				&& isset($arEventResult['ERROR_MSG']) && strlen($arEventResult['ERROR_MSG']) > 0)
			{
				$arInfo = array(
					'RESULT' => false,
					'ERROR_TYPE' => $arEventResult['ERROR_TYPE'],
					'ERROR_MSG' => $arEventResult['ERROR_MSG'],
				);
			}
		}
		return $arInfo;
	}