CAdvType::GetList: Bitrix method

      
<?php 
//  CAdvType :: GetList()
//  /dist/bitrix/modules/advertising/classes/general/advertising.php:5351

    
public static function GetList(&$by, &$order$arFilter=Array(), &$is_filtered$CHECK_RIGHTS="Y")
    {
        
$err_mess = (CAdvType_all::err_mess())."<br>Function: GetList<br>Line: ";
        global 
$DB;
        
$arSqlSearch = Array();
        if (
$CHECK_RIGHTS=="Y")
        {
            
$isAdmin CAdvContract::IsAdmin();
            
$isDemo CAdvContract::IsDemo();
            
$isManager CAdvContract::IsManager();
            
$isAdvertiser CAdvContract::IsAdvertiser();
        }
        else
        {
            
$isAdmin true;
            
$isDemo true;
            
$isManager true;
            
$isAdvertiser true;
        }
        if (
$isAdmin || $isDemo || $isManager || $isAdvertiser)
        {
            if (
CAdvType::CheckFilter($arFilter))
            {
                if (
is_array($arFilter))
                {
                    
$filter_keys array_keys($arFilter);
                    for (
$i=0$n count($filter_keys); $i $n$i++)
                    {
                        
$key $filter_keys[$i];
                        
$val $arFilter[$filter_keys[$i]];
                        if(
is_array($val))
                        {
                            if(
count($val) <= 0)
                                continue;
                        }
                        else
                        {
                            if( (
strlen($val) <= 0) || ($val === "NOT_REF") )
                                continue;
                        }
                        
$match_value_set = (in_array($key."_EXACT_MATCH"$filter_keys)) ? true false;
                        
$key strtoupper($key);
                        switch(
$key)
                        {
                            case 
"SID":
                                
$match = ($arFilter[$key."_EXACT_MATCH"]=="N" && $match_value_set) ? "Y" "N";
                                
$arSqlSearch[] = GetFilterQuery("T.SID"$val$match);
                                break;
                            case 
"DATE_MODIFY_1":
                                
$arSqlSearch[] = "T.DATE_MODIFY>=".$DB->CharToDateFunction($val"SHORT");
                                break;
                            case 
"DATE_MODIFY_2":
                                
$arSqlSearch[] = "T.DATE_MODIFY<=".$DB->CharToDateFunction($val." 23:59:59""FULL");
                                break;
                            case 
"ACTIVE":
                                
$arSqlSearch[] = ($val=="Y") ? "T.ACTIVE='Y'" "T.ACTIVE='N'";
                                break;
                            case 
"NAME":
                            case 
"DESCRIPTION":
                                
$match = ($arFilter[$key."_EXACT_MATCH"]=="Y" && $match_value_set) ? "N" "Y";
                                
$arSqlSearch[] = GetFilterQuery("T.".$key$val$match);
                                break;
                        }
                    }
                }
            }
            if (
$by == "s_sid")                $strSqlOrder " ORDER BY T.SID ";
            elseif (
$by == "s_date_modify")    $strSqlOrder " ORDER BY T.DATE_MODIFY ";
            elseif (
$by == "s_modified_by")    $strSqlOrder " ORDER BY T.MODIFIED_BY ";
            elseif (
$by == "s_date_create")    $strSqlOrder " ORDER BY T.DATE_CREATE ";
            elseif (
$by == "s_created_by")    $strSqlOrder " ORDER BY T.CREATED_BY ";
            elseif (
$by == "s_active")        $strSqlOrder " ORDER BY T.ACTIVE ";
            elseif (
$by == "s_name")        $strSqlOrder " ORDER BY T.NAME ";
            elseif (
$by == "s_banners")        $strSqlOrder " ORDER BY BANNER_COUNT ";
            elseif (
$by == "s_description")    $strSqlOrder " ORDER BY T.DESCRIPTION ";
            else
            {
                
$strSqlOrder " ORDER BY T.SORT ";
                
$by "s_sort";
            }
            if (
$order!="desc")
            {
                
$strSqlOrder .= " asc ";
                
$order "asc";
            }
            else
            {
                
$strSqlOrder .= " desc ";
                
$order "desc";
            }
            
$strSqlSearch GetFilterSqlSearch($arSqlSearch);


            
$strContracts "";
            if (!
$isAdmin && !$isDemo && !$isManager)
            {
                
$strContracts "0";
                
$arPermissions CAdvContract::GetUserPermissions();
                foreach (
$arPermissions as $contract_id => $arContractPerms)
                {
                    if (
is_array($arContractPerms) && !empty($arContractPerms))
                        
$strContracts .= ",".$contract_id;
                }
            }

            
$strSql "
                SELECT
                    T.SID,
                    T.ACTIVE,
                    T.SORT,
                    T.NAME,
                    T.DESCRIPTION,
                    "
.$DB->DateToCharFunction("T.DATE_CREATE")."    DATE_CREATE,
                    "
.$DB->DateToCharFunction("T.DATE_MODIFY")."    DATE_MODIFY,
                    T.CREATED_BY,
                    T.MODIFIED_BY,
                    count(distinct B.ID)                            BANNER_COUNT
                FROM
                    b_adv_type T
                    LEFT JOIN b_adv_banner B ON (B.TYPE_SID=T.SID"
.($strContracts == "" "" :" AND B.CONTRACT_ID IN (".$strContracts.")").")
                WHERE
                
$strSqlSearch ".
                (
$strContracts == "" "" :
                    
"and exists(select 'x' from b_adv_contract_2_type CT where (CT.TYPE_SID=T.SID OR CT.TYPE_SID='ALL') AND CT.CONTRACT_ID IN (".$strContracts.")) "
                
).
                
" and T.SID<>'ALL'
                GROUP BY
                    T.SID, T.ACTIVE, T.SORT, T.NAME, T.DESCRIPTION,    T.DATE_CREATE, T.DATE_MODIFY, T.CREATED_BY, T.MODIFIED_BY
                
$strSqlOrder
                "
;

            
$res $DB->Query($strSqlfalse$err_mess.__LINE__);
            
$is_filtered = (IsFiltered($strSqlSearch));
            return 
$res;
        }
        return 
null;
    }