コード例 #1
0
ファイル: channel.php プロジェクト: rasuldev/torino
 public static function GetGroupPermission($channel_id, $arGroups = false, $params = array())
 {
     global $DB, $USER, $CACHE_MANAGER, $APPLICATION;
     $err_mess = CAllVoteChannel::err_mess() . "<br>Function: GetGroupPermission<br>Line: ";
     $channel_id = trim($channel_id);
     $arGroups = $arGroups === false ? $USER->GetUserGroupArray() : $arGroups;
     $arGroups = !is_array($arGroups) || empty($arGroups) ? array(2) : $arGroups;
     $groups = implode(",", $arGroups);
     $params = is_array($params) ? $params : array("get_from_database" => $params);
     $cache = array("channel_id" => $channel_id, "groups" => $arGroups, "get_from_database" => $params["get_from_database"]);
     $cache_id = "b_vote_perm_" . md5(serialize($cache));
     $permission = 0;
     if (VOTE_CACHE_TIME !== false && $CACHE_MANAGER->Read(VOTE_CACHE_TIME, $cache_id, "b_vote_perm")) {
         $permission = intval($CACHE_MANAGER->Get($cache_id));
     } else {
         if ($params["get_from_database"] != "Y") {
             $permission = in_array(1, $USER->GetUserGroupArray()) || $APPLICATION->GetGroupRight("vote") >= "W" ? 4 : $permission;
         }
         if ($permission <= 0 && !empty($groups)) {
             $strSql = "SELECT BVC2G.CHANNEL_ID, BVC.SYMBOLIC_NAME CHANNEL_SID, MAX(BVC2G.PERMISSION) as PERMISSION\n\t\t\t\tFROM b_vote_channel_2_group BVC2G\n\t\t\t\tINNER JOIN b_vote_channel BVC ON (BVC2G.CHANNEL_ID = BVC.ID)\n\t\t\t\tWHERE " . ($params["CHANNEL_SID"] != "Y" ? "BVC2G.CHANNEL_ID" : "BVC.SYMBOLIC_NAME") . "='" . $DB->ForSql($channel_id) . "' and GROUP_ID in ({$groups})\n\t\t\t\tGROUP BY BVC2G.CHANNEL_ID, BVC.SYMBOLIC_NAME";
             $db_res = $DB->Query($strSql, false, $err_mess . __LINE__);
             if ($db_res && ($res = $db_res->Fetch())) {
                 $permission = intval($res["PERMISSION"]);
                 if (VOTE_CACHE_TIME !== false) {
                     $cache["channel_id"] = $res["CHANNEL_SID"];
                     $cache_id = "b_vote_perm_" . md5(serialize($cache));
                     $CACHE_MANAGER->Set($cache_id, $permission);
                     $cache["channel_id"] = trim($res["CHANNEL_ID"]);
                 }
             }
         }
         if (VOTE_CACHE_TIME !== false) {
             $cache_id = "b_vote_perm_" . md5(serialize($cache));
             $CACHE_MANAGER->Set($cache_id, $permission);
         }
     }
     return $permission;
 }