- Модуль: vote
- Путь к файлу: ~/bitrix/modules/vote/classes/general/channel.php
- Класс: CAllVoteChannel
- Вызов: CAllVoteChannel::GetGroupPermission
static function GetGroupPermission($channel_id, $arGroups=false, $params = array())
{
global $DB, $USER, $CACHE_MANAGER, $APPLICATION;
$err_mess = (CAllVoteChannel::err_mess())."
Function: GetGroupPermission
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"] ?? null);
$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"] ?? null != "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
FROM b_vote_channel_2_group BVC2G
INNER JOIN b_vote_channel BVC ON (BVC2G.CHANNEL_ID = BVC.ID)
WHERE ".($params["CHANNEL_SID"] != "Y" ? "BVC2G.CHANNEL_ID" : "BVC.SYMBOLIC_NAME").
"='".$DB->ForSql($channel_id)."' and GROUP_ID in ($groups)
GROUP 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;
}