Beispiel #1
0
 public static function IsUserSubscribed($userID, $code)
 {
     $userID = intval($userID);
     if ($userID <= 0) {
         return false;
     }
     $code = trim($code);
     if (strlen($code) <= 0) {
         return false;
     }
     $cache = new CPHPCache();
     $cache_time = 31536000;
     $cache_id = "entity_" . $code;
     $cache_path = "/sonet/subscription/";
     if ($cache->InitCache($cache_time, $cache_id, $cache_path)) {
         $arCacheVars = $cache->GetVars();
         $arSubscriberID = $arCacheVars["arSubscriberID"];
     } else {
         $cache->StartDataCache($cache_time, $cache_id, $cache_path);
         $arSubscriberID = array();
         $rsSubscription = CSocNetSubscription::GetList(array(), array("CODE" => $code));
         while ($arSubscription = $rsSubscription->Fetch()) {
             $arSubscriberID[] = $arSubscription["USER_ID"];
         }
         if (defined("BX_COMP_MANAGED_CACHE")) {
             $GLOBALS["CACHE_MANAGER"]->StartTagCache($cache_path);
             $GLOBALS["CACHE_MANAGER"]->RegisterTag("sonet_subscription_" . $code);
             $GLOBALS["CACHE_MANAGER"]->RegisterTag("sonet_group");
         }
         $arCacheData = array("arSubscriberID" => $arSubscriberID);
         $cache->EndDataCache($arCacheData);
         if (defined("BX_COMP_MANAGED_CACHE")) {
             $GLOBALS["CACHE_MANAGER"]->EndTagCache();
         }
     }
     return in_array($userID, $arSubscriberID);
 }
Beispiel #2
0
if (!$GLOBALS["USER"]->IsAuthorized()) {
    echo CUtil::PhpToJsObject(array("ERROR" => "CURRENT_USER_NOT_AUTH"));
    die;
}
$groupID = intval($_POST["groupID"]);
if ($groupID <= 0) {
    echo CUtil::PhpToJsObject(array("ERROR" => "EMPTY_GROUP_ID"));
    die;
}
if (check_bitrix_sessid()) {
    if (in_array($_POST["action"], array("set", "unset"))) {
        $userRole = CSocNetUserToGroup::GetUserRole($GLOBALS["USER"]->GetID(), $groupID);
        if (!in_array($userRole, array(SONET_ROLES_OWNER, SONET_ROLES_MODERATOR, SONET_ROLES_USER))) {
            echo CUtil::PhpToJsObject(array("ERROR" => "INCORRECT_USER_ROLE"));
            die;
        }
        if (CSocNetSubscription::Set($GLOBALS["USER"]->GetID(), "SG" . $groupID, $_POST["action"] == "set" ? "Y" : "N")) {
            $rsSubscription = CSocNetSubscription::GetList(array(), array("USER_ID" => $GLOBALS["USER"]->GetID(), "CODE" => "SG" . $groupID));
            if ($arSubscription = $rsSubscription->Fetch()) {
                echo CUtil::PhpToJsObject(array("SUCCESS" => "Y", "RESULT" => "Y"));
            } else {
                echo CUtil::PhpToJsObject(array("SUCCESS" => "Y", "RESULT" => "N"));
            }
        }
    } else {
        echo CUtil::PhpToJsObject(array("ERROR" => "UNKNOWN_ACTION"));
    }
} else {
    echo CUtil::PhpToJsObject(array("ERROR" => "SESSION_ERROR"));
}
require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_after.php";