CAdvBanner::GetStatList: Bitrix method

      
<?php 
//  CAdvBanner :: GetStatList()
//  /dist/bitrix/modules/advertising/classes/general/advertising.php:4950

    
public static function GetStatList($by$order$arFilter)
    {
        
$err_mess = (CAdvBanner::err_mess())."<br>Function: GetStatList<br>Line: ";
        global 
$DB;
        
$arSqlSearch = Array();
        if (
CAdvBanner::CheckDynamicFilter($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;
                    }
                    
$key strtoupper($key);
                    switch(
$key)
                    {
                        case 
"DATE_1":
                            
$arSqlSearch[] = "D.DATE_STAT>=".$DB->CharToDateFunction($val"SHORT");
                            break;
                        case 
"DATE_2":
                            
$arSqlSearch[] = "D.DATE_STAT<=".$DB->CharToDateFunction($val." 23:59:59""FULL");
                            break;
                    }
                }

                \
Bitrix\Main\Type\Collection::normalizeArrayValuesByInt($arFilter['BANNER_ID']);

                if(!empty(
$arFilter['BANNER_ID']))
                {
                    
$arSqlSearch[] = CSQLWhere::_NumberIN("D.BANNER_ID"$arFilter['BANNER_ID']);
                }
            }
        }

        
$strSqlSearch GetFilterSqlSearch($arSqlSearch);
        if (
$by == "s_date")
        {
            
$strSqlOrder " ORDER BY D.DATE_STAT ";
        }
        elseif (
$by == "s_visitors")
        {
            
$strSqlOrder " ORDER BY VISITOR_COUNT ";
        }
        elseif (
$by == "s_clicks")
        {
            
$strSqlOrder " ORDER BY CLICK_COUNT ";
        }
        elseif (
$by == "s_ctr")
        {
            
$strSqlOrder " ORDER BY CTR";
        }
        elseif (
$by == "s_show")
        {
            
$strSqlOrder " ORDER BY SHOW_COUNT ";
        }
        elseif (
$by == "s_id")
        {
            
$strSqlOrder " ORDER BY D.BANNER_ID";
        }
        else
        {
            
$strSqlOrder " ORDER BY DATE_STAT";
            
$by "s_date";
        }

        if (
$order!="asc")
        {
            
$strSqlOrder .= " desc ";
        }


        if (
$by != "s_date")
        {
            
$strSqlOrder .= ', DATE_STAT ASC';
        }

        if (
$arFilter['BANNER_SUMMA'] == 'Y')
        {
            
$strSql "
                SELECT
                    "
.$DB->DateToCharFunction("D.DATE_STAT","SHORT")."        DATE_STAT,
                    SUM(D.SHOW_COUNT)                                        SHOW_COUNT,
                    SUM(D.CLICK_COUNT)                                        CLICK_COUNT,
                    SUM(D.VISITOR_COUNT)                                    VISITOR_COUNT,
                    " 
CAdvBanner::getCTRSQL() . "
                FROM
                    b_adv_banner_2_day D
                INNER JOIN b_adv_banner B ON (D.BANNER_ID = B.ID)
                INNER JOIN b_adv_contract C ON (B.CONTRACT_ID = C.ID)
                WHERE
                
$strSqlSearch
                GROUP by DATE_STAT
                
$strSqlOrder
                "
;
        }
        else
        {
            
$strSql "
                SELECT
                    "
.$DB->DateToCharFunction("D.DATE_STAT","SHORT")."        DATE_STAT,
                    SUM(D.SHOW_COUNT)                                        SHOW_COUNT,
                    SUM(D.CLICK_COUNT)                                        CLICK_COUNT,
                    SUM(D.VISITOR_COUNT)                                    VISITOR_COUNT,
                    D.BANNER_ID,
                    B.NAME                                                    BANNER_NAME,
                    " 
CAdvBanner::getCTRSQL() . "
                FROM
                    b_adv_banner_2_day D
                INNER JOIN b_adv_banner B ON (D.BANNER_ID = B.ID)
                INNER JOIN b_adv_contract C ON (B.CONTRACT_ID = C.ID)
                WHERE
                
$strSqlSearch
                GROUP by D.DATE_STAT, D.BANNER_ID, B.NAME
                
$strSqlOrder
                "
;
        }

        return 
$DB->Query($strSqlfalse$err_mess.__LINE__);
    }