• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/general/iblock_rights.php
  • Класс: CIBlockRights
  • Вызов: CIBlockRights::GetRights
function GetRights($arOptions = array())
{
	global $DB;
	$arResult = array();

	if(
		!isset($arOptions["operations"])
		|| !is_array($arOptions["operations"])
		|| empty($arOptions["operations"])
	)
	{
		$rs = $DB->Query("
			SELECT
				BR.ID
				,BR.GROUP_CODE
				,BR.TASK_ID
				,BR.DO_INHERIT
				,'N' IS_INHERITED
				,BR.XML_ID
				,BR.ENTITY_TYPE
				,BR.ENTITY_ID
			FROM
				b_iblock_right BR
			WHERE
				BR.IBLOCK_ID = ".$this->IBLOCK_ID."
				AND BR.ENTITY_TYPE = 'iblock'
			ORDER BY
				BR.ID
		");
	}
	elseif(
		isset($arOptions["operations_mode"])
		&& $arOptions["operations_mode"] == CIBlockRights::ALL_OPERATIONS
		&& count($arOptions["operations"]) > 1
	)
	{
		$arOperations = array_map(array($DB, "ForSQL"), $arOptions["operations"]);
		$rs = $DB->Query("
			SELECT
				BR.ID, BR.GROUP_CODE, BR.TASK_ID, BR.DO_INHERIT, 'N' IS_INHERITED, BR.XML_ID
			FROM
				b_iblock_right BR
				INNER JOIN b_task_operation T ON T.TASK_ID = BR.TASK_ID
				INNER JOIN b_operation O ON O.ID = T.OPERATION_ID
			WHERE
				BR.IBLOCK_ID = ".$this->IBLOCK_ID."
				AND BR.ENTITY_TYPE = 'iblock'
				AND O.NAME IN ('".implode("', '", $arOperations)."')
			GROUP BY
				BR.ID, BR.GROUP_CODE, BR.TASK_ID, BR.DO_INHERIT
			HAVING
				COUNT(DISTINCT O.ID) = ".count($arOperations)."
			ORDER BY
				BR.ID
		");
	}
	else//if($opMode == CIBlockRights::ANY_OPERATION)
	{
		$arOperations = array_map(array($DB, "ForSQL"), $arOptions["operations"]);
		$rs = $DB->Query("
			SELECT DISTINCT
				BR.ID, BR.GROUP_CODE, BR.TASK_ID, BR.DO_INHERIT, 'N' IS_INHERITED, BR.XML_ID
			FROM
				b_iblock_right BR
				INNER JOIN b_task_operation T ON T.TASK_ID = BR.TASK_ID
				INNER JOIN b_operation O ON O.ID = T.OPERATION_ID
			WHERE
				BR.IBLOCK_ID = ".$this->IBLOCK_ID."
				AND BR.ENTITY_TYPE = 'iblock'
				AND O.NAME IN ('".implode("', '", $arOperations)."')
			ORDER BY
				BR.ID
		");
	}

	$obStorage = $this->_storage_object();
	while($ar = $rs->Fetch())
	{
		$arResult[$ar["ID"]] = array(
			"GROUP_CODE" => $ar["GROUP_CODE"],
			"DO_INHERIT" => $ar["DO_INHERIT"],
			"IS_INHERITED" => $ar["IS_INHERITED"],
			"OVERWRITED" => isset($arOptions["count_overwrited"]) && $arOptions["count_overwrited"]? $obStorage->CountOverWrited($ar["GROUP_CODE"]): 0,
			"TASK_ID" => $ar["TASK_ID"],
			"XML_ID" => $ar["XML_ID"],
		);
		if(isset($ar["ENTITY_TYPE"]))
			$arResult[$ar["ID"]]["ENTITY_TYPE"] = $ar["ENTITY_TYPE"];
		if(isset($ar["ENTITY_ID"]))
			$arResult[$ar["ID"]]["ENTITY_ID"] = $ar["ENTITY_ID"];
	}

	return $arResult;
}