function GetRelation($firstUserID, $secondUserID) { global $DB; $firstUserID = IntVal($firstUserID); if ($firstUserID <= 0) return false; $secondUserID = IntVal($secondUserID); if ($secondUserID <= 0) return false; global $arSocNetURNCache; if (!isset($arSocNetURNCache) || !is_array($arSocNetURNCache) || array_key_exists("arSocNetURNCache", $_REQUEST)) $arSocNetURNCache = array(); if (array_key_exists($firstUserID, $arSocNetURNCache)) { if (array_key_exists($secondUserID, $arSocNetURNCache[$firstUserID])) return $arSocNetURNCache[$firstUserID][$secondUserID]; elseif(count($arSocNetURNCache[$firstUserID]) != 100) return false; } elseif (array_key_exists($secondUserID, $arSocNetURNCache)) { if (array_key_exists($firstUserID, $arSocNetURNCache[$secondUserID])) return $arSocNetURNCache[$secondUserID][$firstUserID]; elseif(count($arSocNetURNCache[$secondUserID]) != 100) return false; } // get top N relations of user1 $arSocNetURNCache[$firstUserID] = array(); $dbResult = CSocNetUserRelations::GetRelationsTop($firstUserID, 100); while ($arResult = $dbResult->Fetch()) { if ($arResult["FIRST_USER_ID"] == $firstUserID) $arSocNetURNCache[$firstUserID][$arResult["SECOND_USER_ID"]] = $arResult["RELATION"]; else $arSocNetURNCache[$firstUserID][$arResult["FIRST_USER_ID"]] = $arResult["RELATION"]; } // get top N relations of user2 $arSocNetURNCache[$secondUserID] = array(); $dbResult = CSocNetUserRelations::GetRelationsTop($secondUserID, 100); while ($arResult = $dbResult->Fetch()) { if ($arResult["FIRST_USER_ID"] == $secondUserID) $arSocNetURNCache[$secondUserID][$arResult["SECOND_USER_ID"]] = $arResult["RELATION"]; else $arSocNetURNCache[$secondUserID][$arResult["FIRST_USER_ID"]] = $arResult["RELATION"]; } global $arSocNetUserRelationsCache1; if (!isset($arSocNetUserRelationsCache1) || !is_array($arSocNetUserRelationsCache1) || array_key_exists("arSocNetUserRelationsCache1", $_REQUEST)) $arSocNetUserRelationsCache1 = array(); if (!array_key_exists($firstUserID."_".$secondUserID, $arSocNetUserRelationsCache1)) { $strSql = "SELECT UR.RELATION ". "FROM b_sonet_user_relations UR ". "WHERE UR.FIRST_USER_ID = ".$firstUserID." ". " AND UR.SECOND_USER_ID = ".$secondUserID." ". "UNION ". "SELECT UR.RELATION ". "FROM b_sonet_user_relations UR ". "WHERE UR.FIRST_USER_ID = ".$secondUserID." ". " AND UR.SECOND_USER_ID = ".$firstUserID." "; $dbResult = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); if ($arResult = $dbResult->Fetch()) $arSocNetUserRelationsCache1[$firstUserID."_".$secondUserID] = $arResult["RELATION"]; else $arSocNetUserRelationsCache1[$firstUserID."_".$secondUserID] = false; } return $arSocNetUserRelationsCache1[$firstUserID."_".$secondUserID]; }