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

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

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

//    CIBlockElement::GetList()
//    /bitrix/modules/iblock/classes/mysql/iblockelement.php:657

    public static function GetList($arOrder=array("SORT"=>"ASC"), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
    {
        global $DB;

        $el = new CIBlockElement();
        $el->prepareSql($arSelectFields, $arFilter, $arGroupBy, $arOrder);

        if($el->bOnlyCount)
        {
            $res = $DB->Query("
                SELECT ".$el->sSelect."
                FROM ".$el->sFrom."
                WHERE 1=1 ".$el->sWhere."
                ".$el->sGroupBy."
            ");
            $res = $res->Fetch();
            return $res["CNT"];
        }

        if(!empty($arNavStartParams) && is_array($arNavStartParams))
        {
            $nTopCount = (isset($arNavStartParams["nTopCount"]) ? (int)$arNavStartParams["nTopCount"] : 0);
            $nElementID = (isset($arNavStartParams["nElementID"]) ? (int)$arNavStartParams["nElementID"] : 0);

            if($nTopCount > 0)
            {
                $strSql = "
                    SELECT ".$el->sSelect."
                    FROM ".$el->sFrom."
                    WHERE 1=1 ".$el->sWhere."
                    ".$el->sGroupBy."
                    ".$el->sOrderBy."
                    LIMIT ".$nTopCount."
                ";
                $res = $DB->Query($strSql);
            }
            elseif(
                $nElementID > 0
                && $el->sGroupBy == ""
                && $el->sOrderBy != ""
                && strpos($el->sSelect, "BE.ID") !== false
                && !$el->bCatalogSort
            )
            {
                $nPageSize = (isset($arNavStartParams["nPageSize"]) ? (int)$arNavStartParams["nPageSize"] : 0);

                if($nPageSize > 0)
                {
                    $DB->Query("SET @ranx=0");
                    $DB->Query("
                        SELECT @ranx:=el1.ranx
                        FROM (
                            SELECT @ranx:=@ranx+1 AS ranx, el0.*
                            FROM (
                                SELECT ".$el->sSelect."
                                FROM ".$el->sFrom."
                                WHERE 1=1 ".$el->sWhere."
                                ".$el->sGroupBy."
                                ".$el->sOrderBy."
                                LIMIT 18446744073709551615
                            ) el0
                        ) el1
                        WHERE el1.ID = ".$nElementID."
                    ");
                    $DB->Query("SET @ranx2=0");

                    $res = $DB->Query("
                        SELECT *
                        FROM (
                            SELECT @ranx2:=@ranx2+1 AS `RANK`, el0.*
                            FROM (
                                SELECT ".$el->sSelect."
                                FROM ".$el->sFrom."
                                WHERE 1=1 ".$el->sWhere."
                                ".$el->sGroupBy."
                                ".$el->sOrderBy."
                                LIMIT 18446744073709551615
                            ) el0
                        ) el1
                        WHERE el1.`RANK` between @ranx-$nPageSize and @ranx+$nPageSize
                    ");
                }
                else
                {
                    $DB->Query("SET @ranx=0");
                    $res = $DB->Query("
                        SELECT el1.*
                        FROM (
                            SELECT @ranx:=@ranx+1 AS `RANK`, el0.*
                            FROM (
                                SELECT ".$el->sSelect."
                                FROM ".$el->sFrom."
                                WHERE 1=1 ".$el->sWhere."
                                ".$el->sGroupBy."
                                ".$el->sOrderBy."
                                LIMIT 18446744073709551615
                            ) el0
                        ) el1
                        WHERE el1.ID = ".$nElementID."
                    ");
                }
            }
            else
            {
                if ($el->sGroupBy == "")
                {
                    $res_cnt = $DB->Query("
                        SELECT COUNT(".($el->bDistinct? "DISTINCT BE.ID": "'x'").") as C
                        FROM ".$el->sFrom."
                        WHERE 1=1 ".$el->sWhere."
                        ".$el->sGroupBy."
                    ");
                    $res_cnt = $res_cnt->Fetch();
                    $cnt = $res_cnt["C"];
                }
                else
                {
                    $res_cnt = $DB->Query("
                        SELECT 'x'
                        FROM ".$el->sFrom."
                        WHERE 1=1 ".$el->sWhere."
                        ".$el->sGroupBy."
                    ");
                    $cnt = $res_cnt->SelectedRowsCount();
                }

                $strSql = "
                    SELECT ".$el->sSelect."
                    FROM ".$el->sFrom."
                    WHERE 1=1 ".$el->sWhere."
                    ".$el->sGroupBy."
                    ".$el->sOrderBy."
                ";
                $res = new CDBResult();
                $res->NavQuery($strSql, $cnt, $arNavStartParams);
            }
        }
        else//if(is_array($arNavStartParams))
        {
            $strSql = "
                SELECT ".$el->sSelect."
                FROM ".$el->sFrom."
                WHERE 1=1 ".$el->sWhere."
                ".$el->sGroupBy."
                ".$el->sOrderBy."
            ";
            $res = $DB->Query($strSql, false, "FILE: ".__FILE__."
LINE: ".__LINE__);
        }

        $res = new CIBlockResult($res);
        $res->SetIBlockTag($el->arFilterIBlocks);
        $res->arIBlockMultProps = $el->arIBlockMultProps;
        $res->arIBlockConvProps = $el->arIBlockConvProps;
        $res->arIBlockAllProps = $el->arIBlockAllProps;
        $res->arIBlockNumProps = $el->arIBlockNumProps;
        $res->arIBlockLongProps = $el->arIBlockLongProps;

        return $res;
    }

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

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

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

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

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

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

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

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