Exemplo n.º 1
0
 public static function Set($userId, $params)
 {
     $userId = intval($userId);
     if ($userId <= 0) {
         return false;
     }
     if (isset($params['STATUS'])) {
         $params['IDLE'] = null;
     }
     $needToUpdate = false;
     $params = self::PrepereFields($params);
     $res = IM\StatusTable::getById($userId);
     if ($status = $res->fetch()) {
         foreach ($params as $key => $value) {
             $oldValue = is_object($status[$key]) ? $status[$key]->toString() : $status[$key];
             $newValue = is_object($value) ? $value->toString() : $value;
             if ($oldValue != $newValue) {
                 $status[$key] = $value;
                 $needToUpdate = true;
             }
         }
         if ($needToUpdate) {
             IM\StatusTable::update($userId, $params);
         }
     } else {
         $params['USER_ID'] = $userId;
         IM\StatusTable::add($params);
         $needToUpdate = true;
         $status = $params;
     }
     if ($needToUpdate && self::Enable()) {
         CPullStack::AddShared(array('module_id' => 'online', 'command' => 'user_status', 'params' => self::PrepereToPush($status)));
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * Method will be invoked after an database record updated.
  *
  * @param array $oldRecord All fields before update.
  * @param array $newRecord All fields after update.
  *
  * @return void
  */
 public function afterUpdateTrigger(array $oldRecord, array $newRecord)
 {
     if ($oldRecord["STATUS"] !== $newRecord["STATUS"]) {
         if (\CIMStatus::Enable()) {
             \CPullStack::AddShared(array('module_id' => 'online', 'command' => 'user_status', 'expiry' => 120, 'params' => array("USER_ID" => $newRecord["USER_ID"], "STATUS" => $newRecord["STATUS"])));
         }
     }
 }
Exemplo n.º 3
0
 public static function CancelRatingVote($arParam)
 {
     global $DB, $CACHE_MANAGER;
     $err_mess = CRatings::err_mess() . "<br>Function: CancelRatingVote<br>Line: ";
     $sqlStr = "\n\t\t\tSELECT\n\t\t\t\tRVG.ID,\n\t\t\t\tRV.ID AS VOTE_ID,\n\t\t\t\tRV.VALUE AS VOTE_VALUE,\n\t\t\t\tRVG.TOTAL_POSITIVE_VOTES\n\t\t\tFROM\n\t\t\t\tb_rating_voting RVG,\n\t\t\t\tb_rating_vote RV\n\t\t\tWHERE\n\t\t\t\tRVG.ENTITY_TYPE_ID = '" . $DB->ForSql($arParam['ENTITY_TYPE_ID']) . "'\n\t\t\tand RVG.ENTITY_ID = " . intval($arParam['ENTITY_ID']) . "\n\t\t\tand RVG.ID = RV.RATING_VOTING_ID\n\t\t\tand RV.USER_ID = " . intval($arParam['USER_ID']);
     $res = $DB->Query($sqlStr, false, $err_mess . __LINE__);
     if ($arVote = $res->Fetch()) {
         $votePlus = $arVote['VOTE_VALUE'] >= 0 ? true : false;
         $arFields = array('TOTAL_VOTES' => "TOTAL_VOTES-1", 'TOTAL_VALUE' => "TOTAL_VALUE" . ($votePlus ? '-' . floatval($arVote['VOTE_VALUE']) : '+' . floatval(-1 * $arVote['VOTE_VALUE'])), 'LAST_CALCULATED' => $DB->GetNowFunction());
         $arFields[$votePlus ? 'TOTAL_POSITIVE_VOTES' : 'TOTAL_NEGATIVE_VOTES'] = $votePlus ? 'TOTAL_POSITIVE_VOTES-1' : 'TOTAL_NEGATIVE_VOTES-1';
         $DB->Update("b_rating_voting", $arFields, "WHERE ID=" . intval($arVote['ID']), $err_mess . __LINE__);
         $DB->Query("DELETE FROM b_rating_vote WHERE ID=" . intval($arVote['VOTE_ID']), false, $err_mess . __LINE__);
         foreach (GetModuleEvents("main", "OnCancelRatingVote", true) as $arEvent) {
             ExecuteModuleEventEx($arEvent, array(intval($arVote['VOTE_ID']), $arParam));
         }
         if (CModule::IncludeModule('pull')) {
             CPullStack::AddShared(array('module_id' => 'main', 'command' => 'rating_vote', 'params' => array("TYPE" => "CANCEL", "USER_ID" => intval($arParam['USER_ID']), "ENTITY_TYPE_ID" => $arParam["ENTITY_TYPE_ID"], "ENTITY_ID" => intval($arParam['ENTITY_ID']), "TOTAL_POSITIVE_VOTES" => intval($arVote['TOTAL_POSITIVE_VOTES'] + ($votePlus ? -1 : 1)), "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;
     }
     return false;
 }
Exemplo n.º 4
0
	public static function OnAfterUserLogout($arParams)
	{
		if (!CPullOptions::GetQueueServerStatus())
			return false;

		if ($arParams['USER_ID'] <= 0)
			return false;

		$arParams['USER_ID'] = intval($arParams['USER_ID']);

		if (isset($_SESSION['USER_LAST_LOGOUT_'.$arParams['USER_ID']])
			&& intval($_SESSION['USER_LAST_LOGOUT_'.$arParams['USER_ID']])+100 > time())
			return false;

		$_SESSION['USER_LAST_LOGOUT_'.$arParams['USER_ID']] = time();
		unset($_SESSION['USER_LAST_AUTH_'.$arParams['USER_ID']]);

		$arChannel = CPullChannel::GetChannel($arParams['USER_ID']);
		$result = CPullChannel::Send($arChannel['CHANNEL_ID'], 'ping', 'GET', 5, false);
		if (is_object($result) && isset($result->infos[0]))
		{
			$sendOffline = $result->infos[0]->subscribers > 0? false: true;
		}
		else
		{
			$sendOffline = true;
		}

		if ($sendOffline)
		{
			CPullStack::AddShared(Array(
				'module_id' => 'online',
				'command' => 'user_offline',
				'params' => Array(
					'USER_ID' => $arParams['USER_ID']
				),
			));
		}

		return true;
	}
Exemplo n.º 5
0
 public static function UnlinkGeneralChatId()
 {
     COption::RemoveOption("im", "general_chat_id");
     if (CModule::IncludeModule('pull')) {
         CPullStack::AddShared(array('module_id' => 'im', 'command' => 'generalChatId', 'params' => array("ID" => 0)));
     }
     return true;
 }
Exemplo n.º 6
0
	public static function OnAfterUserLogout($arParams)
	{
		if ($arParams['USER_ID'] <= 0)
			return false;

		$arParams['USER_ID'] = intval($arParams['USER_ID']);

		if (isset($_SESSION['USER_LAST_LOGOUT_'.$arParams['USER_ID']])
			&& intval($_SESSION['USER_LAST_LOGOUT_'.$arParams['USER_ID']])+100 > time())
			return false;

		$_SESSION['USER_LAST_LOGOUT_'.$arParams['USER_ID']] = time();
		unset($_SESSION['USER_LAST_AUTH_'.$arParams['USER_ID']]);

		CPullStack::AddShared(Array(
			'module_id' => 'main',
			'command' => 'user_logout',
			'params' => Array(
				'USER_ID' => $arParams['USER_ID']
			),
		));
	}