Поддержка серверов

CSecurityIPRule::GetList: метод Битрикс

Постоянная ссылка: http://bxapi.ru/src/?id=178435

//    CSecurityIPRule::GetList()
//    /bitrix/modules/security/classes/general/iprule.php:678

    public static function GetList($arSelect, $arFilter, $arOrder)
    {
        global $DB;

        if(!is_array($arSelect))
            $arSelect = array();
        if(count($arSelect) < 1)
            $arSelect = array(
                "ID",
                "RULE_TYPE",
                "ACTIVE",
                "ADMIN_SECTION",
                "SITE_ID",
                "SORT",
                "NAME",
                "ACTIVE_FROM",
                "ACTIVE_TO",
            );

        if(!is_array($arOrder))
            $arOrder = array();

        $arQueryOrder = array();
        foreach($arOrder as $strColumn => $strDirection)
        {
            $strColumn = strtoupper($strColumn);
            $strDirection = strtoupper($strDirection)=="ASC"? "ASC": "DESC";
            switch($strColumn)
            {
                case "ID":
                case "RULE_TYPE":
                case "ACTIVE":
                case "ADMIN_SECTION":
                case "SITE_ID":
                case "SORT":
                case "NAME":
                    $arSelect[] = $strColumn;
                    $arQueryOrder[$strColumn] = $strColumn." ".$strDirection;
                    break;
                case "ACTIVE_FROM":
                case "ACTIVE_TO":
                    $arSelect[] = $strColumn;
                    $arSelect[] = $strColumn."_TIMESTAMP";
                    $arQueryOrder[$strColumn] = $strColumn."_TIMESTAMP ".$strDirection;
                    break;
            }
        }

        $arQuerySelect = array();
        foreach($arSelect as $strColumn)
        {
            $strColumn = strtoupper($strColumn);
            switch($strColumn)
            {
                case "ID":
                case "RULE_TYPE":
                case "ACTIVE":
                case "ADMIN_SECTION":
                case "SITE_ID":
                case "SORT":
                case "NAME":
                case "ACTIVE_FROM_TIMESTAMP":
                case "ACTIVE_TO_TIMESTAMP":
                    $arQuerySelect[$strColumn] = "r.".$strColumn;
                    break;
                case "ACTIVE_FROM":
                case "ACTIVE_TO":
                    $arQuerySelect[$strColumn] = $DB->DateToCharFunction("r.".$strColumn, "FULL")." AS ".$strColumn;
                    break;
            }
        }
        if(count($arQuerySelect) < 1)
            $arQuerySelect = array("ID"=>"r.ID");

        $obQueryWhere = new CSQLWhere;
        $arFields = array(
            "ID" => array(
                "TABLE_ALIAS" => "r",
                "FIELD_NAME" => "r.ID",
                "FIELD_TYPE" => "int",
                "JOIN" => false,
            ),
            "RULE_TYPE" => array(
                "TABLE_ALIAS" => "r",
                "FIELD_NAME" => "r.RULE_TYPE",
                "FIELD_TYPE" => "string",
                "JOIN" => false,
            ),
            "ACTIVE" => array(
                "TABLE_ALIAS" => "r",
                "FIELD_NAME" => "r.ACTIVE",
                "FIELD_TYPE" => "string",
                "JOIN" => false,
            ),
            "ADMIN_SECTION" => array(
                "TABLE_ALIAS" => "r",
                "FIELD_NAME" => "r.ADMIN_SECTION",
                "FIELD_TYPE" => "string",
                "JOIN" => false,
            ),
            "SITE_ID" => array(
                "TABLE_ALIAS" => "r",
                "FIELD_NAME" => "r.SITE_ID",
                "FIELD_TYPE" => "string",
                "JOIN" => false,
            ),
            "SORT" => array(
                "TABLE_ALIAS" => "r",
                "FIELD_NAME" => "r.SORT",
                "FIELD_TYPE" => "int",
                "JOIN" => false,
            ),
            "NAME" => array(
                "TABLE_ALIAS" => "r",
                "FIELD_NAME" => "r.NAME",
                "FIELD_TYPE" => "string",
                "JOIN" => false,
            ),
            "ACTIVE_FROM" => array(
                "TABLE_ALIAS" => "r",
                "FIELD_NAME" => "r.ACTIVE_FROM",
                "FIELD_TYPE" => "datetime",
                "JOIN" => false,
            ),
            "ACTIVE_TO" => array(
                "TABLE_ALIAS" => "r",
                "FIELD_NAME" => "r.ACTIVE_TO",
                "FIELD_TYPE" => "datetime",
                "JOIN" => false,
            ),
        );
        $obQueryWhere->SetFields($arFields);

        if(!is_array($arFilter))
            $arFilter = array();
        $strQueryWhere = $obQueryWhere->GetQuery($arFilter);

        $bDistinct = $obQueryWhere->bDistinctReqired;

        $strMaskJoin = "";
        if(array_key_exists("PATH", $arFilter))
        {
            $path = trim($arFilter["PATH"]);
            if($path)
            {
                $bDistinct = true;
                $strMaskJoin = "
                    INNER JOIN b_sec_iprule_incl_mask im on im.IPRULE_ID = r.ID
                    LEFT JOIN b_sec_iprule_excl_mask em on em.IPRULE_ID = r.ID AND '".$DB->ForSQL($path)."' like em.LIKE_MASK
                ";
                $strMaskWhere = "('".$DB->ForSQL($path)."' like im.LIKE_MASK AND em.IPRULE_ID is null)";

                if($strQueryWhere)
                    $strQueryWhere = "(".$strQueryWhere.") AND ".$strMaskWhere;
                else
                    $strQueryWhere = $strMaskWhere;
            }
        }

        $strIPJoin = "";
        if(array_key_exists("IP", $arFilter))
        {
            $ip = self::ip2number($arFilter["IP"]);
            if($ip > 0)
            {
                $bDistinct = true;
                $strIPJoin = "
                    INNER JOIN b_sec_iprule_incl_ip ii on ii.IPRULE_ID = r.ID
                    LEFT JOIN b_sec_iprule_excl_ip ei on ei.IPRULE_ID = r.ID AND ".$ip." between ei.IP_START AND ei.IP_END
                ";
                $strIPWhere = "(".$ip." between ii.IP_START AND ii.IP_END AND ei.IPRULE_ID is null)";
                if($strQueryWhere)
                    $strQueryWhere = "(".$strQueryWhere.") AND ".$strIPWhere;
                else
                    $strQueryWhere = $strIPWhere;
            }
        }

        $strSql = "
            SELECT ".($bDistinct? "DISTINCT": "")."
            ".implode(", ", $arQuerySelect)."
            FROM
                b_sec_iprule r
                ".$strMaskJoin."
                ".$strIPJoin."
            ".$obQueryWhere->GetJoins()."
        ";

        if($strQueryWhere)
        {
            $strSql .= "
                WHERE
                ".$strQueryWhere."
            ";
        }

        if(count($arQueryOrder) > 0)
        {
            $strSql .= "
                ORDER BY
                ".implode(", ", $arQueryOrder)."
            ";
        }

        return $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
    }
';

Блог разработчика

9 августа 2016 ResizeImageGet и простой водяной знак налету

Сегодня поговорим о том как проще всего воткнуть водяной знак на картинки в Битрикс. Например, на все изображения каталога.

21 июля 2016 Добавление вкладки в CRM коробки Битрикс24

В этом посте я покажу, как легко и просто добавить вкладку в сущность CRM. И не просто добавить, а вывести там свой контент.

21 июля 2016 Как просто обращаться из коробки Битрикс24 на сайт на базе Битрикс

К примеру вам хочется внутренним скриптом дернуть с сайта-магазина информацию, которая там, в свою очередь, закрыта некоторыми правами. Например, админскими. Можно конечно мутить свой REST, или иной формат общения, но проще всего воспользоваться штатным инструментом:

Текст сообщения*
Загрузить изображение