CAdvBanner :: GetDynamicList: Bitrix method

      
<?php 
//  CAdvBanner :: GetDynamicList()
//  /dist/bitrix/modules/advertising/classes/general/advertising.php:4741

    
public static function GetDynamicList($arFilter, &$arrLegend, &$is_filtered)
    {
        
$err_mess = (CAdvBanner::err_mess())."<br>Function: GetDynamicList<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;
                    }
                }
            }
        }
        
$arContract is_array($arFilter["CONTRACT_ID"]) ? $arFilter["CONTRACT_ID"] : array();
        
$arBanner is_array($arFilter["BANNER_ID"]) ? $arFilter["BANNER_ID"] : array();
        
$arGroup is_array($arFilter["GROUP_SID"]) ? $arFilter["GROUP_SID"] : array();
        
$contract_total $arFilter["CONTRACT_SUMMA"]=="Y" "Y" "N";
        
$banner_total $arFilter["BANNER_SUMMA"]=="Y" "Y" "N";
        
$group_total $arFilter["GROUP_SUMMA"]=="Y" "Y" "N";
        
$arShow is_array($arFilter["WHAT_SHOW"]) ? $arFilter["WHAT_SHOW"] : array();
        if (
in_array("ctr",$arShow))
        {
            
$arShow[] = "show";
            
$arShow[] = "click";
        }
        
$arShow array_unique($arShow);
        
$arrDays = array();
        
$arrLegend = array();
        
$strSqlSearch GetFilterSqlSearch($arSqlSearch);
        
$strSql CAdvBanner::GetDynamicList_SQL($strSqlSearch);

        
$rsD $DB->Query($strSqlfalse$err_mess.__LINE__);
        while (
$arD $rsD->Fetch())
        {
            
$arrDays[$arD["DATE_STAT"]]["DATE"] = $arD["DATE_STAT"];
            
$arrDays[$arD["DATE_STAT"]]["D"] = $arD["DAY"];
            
$arrDays[$arD["DATE_STAT"]]["M"] = $arD["MONTH"];
            
$arrDays[$arD["DATE_STAT"]]["Y"] = $arD["YEAR"];

            foreach(
$arShow as $ctype)
            {
                if (
$ctype=="CTR") continue;
                
$ctype_u strtoupper($ctype);
                if (
intval($arD[$ctype_u."_COUNT"])>0)
                {
                    if (
in_array($arD["CONTRACT_ID"], $arContract))
                    {
                        if (
$contract_total=="N")
                        {
                            
$arrLegend["3_CONTRACT_".$arD["CONTRACT_ID"]]["TYPE"] = "CONTRACT";
                            
$arrLegend["3_CONTRACT_".$arD["CONTRACT_ID"]]["ID"] = $arD["CONTRACT_ID"];
                            
$arrLegend["3_CONTRACT_".$arD["CONTRACT_ID"]]["NAME"] = $arD["CONTRACT_NAME"];
                            
$arrLegend["3_CONTRACT_".$arD["CONTRACT_ID"]]["COUNTER_TYPE"] = "DETAIL";
                            
$arrLegend["3_CONTRACT_".$arD["CONTRACT_ID"]][$ctype_u] += $arD[$ctype_u."_COUNT"];
                            
$arrDays[$arD["DATE_STAT"]]["CONTRACT"]["DETAIL_".$ctype_u][$arD["CONTRACT_ID"]] += $arD[$ctype_u."_COUNT"];
                        }
                        elseif (
$contract_total=="Y")
                        {
                            
$arrLegend["3_CONTRACT"]["TYPE"] = "CONTRACT";
                            
$arrLegend["3_CONTRACT"]["COUNTER_TYPE"] = "TOTAL";
                            
$arrLegend["3_CONTRACT"][$ctype_u] += $arD[$ctype_u."_COUNT"];
                            
$arrDays[$arD["DATE_STAT"]]["CONTRACT"]["TOTAL_".$ctype_u] += $arD[$ctype_u."_COUNT"];
                        }
                    }
                    if (
in_array($arD["BANNER_ID"], $arBanner))
                    {
                        if (
$banner_total=="N")
                        {
                            
$arrLegend["1_BANNER_".$arD["BANNER_ID"]]["TYPE"] = "BANNER";
                            
$arrLegend["1_BANNER_".$arD["BANNER_ID"]]["ID"] = $arD["BANNER_ID"];
                            
$arrLegend["1_BANNER_".$arD["BANNER_ID"]]["TYPE_SID"] = $arD["BANNER_TYPE_SID"];
                            
$arrLegend["1_BANNER_".$arD["BANNER_ID"]]["GROUP"] = $arD["GROUP_SID"];
                            
$arrLegend["1_BANNER_".$arD["BANNER_ID"]]["NAME"] = $arD["BANNER_NAME"];
                            
$arrLegend["1_BANNER_".$arD["BANNER_ID"]]["CONTRACT_ID"] = $arD["CONTRACT_ID"];
                            
$arrLegend["1_BANNER_".$arD["BANNER_ID"]]["COUNTER_TYPE"] = "DETAIL";
                            
$arrLegend["1_BANNER_".$arD["BANNER_ID"]][$ctype_u] += $arD[$ctype_u."_COUNT"];
                            
$arrDays[$arD["DATE_STAT"]]["BANNER"]["DETAIL_".$ctype_u][$arD["BANNER_ID"]] += $arD[$ctype_u."_COUNT"];
                        }
                        elseif (
$banner_total=="Y")
                        {
                            
$arrLegend["1_BANNER"]["TYPE"] = "BANNER";
                            
$arrLegend["1_BANNER"]["COUNTER_TYPE"] = "TOTAL";
                            
$arrLegend["1_BANNER"][$ctype_u] += $arD[$ctype_u."_COUNT"];
                            
$arrDays[$arD["DATE_STAT"]]["BANNER"]["TOTAL_".$ctype_u] += $arD[$ctype_u."_COUNT"];
                        }
                    }
                    if (
in_array($arD["GROUP_SID"], $arGroup))
                    {
                        if (
$group_total=="N")
                        {
                            
$arrLegend["2_GROUP_".$arD["GROUP_SID"]]["TYPE"] = "GROUP";
                            
$arrLegend["2_GROUP_".$arD["GROUP_SID"]]["ID"] = $arD["GROUP_SID"];
                            
$arrLegend["2_GROUP_".$arD["GROUP_SID"]]["COUNTER_TYPE"] = "DETAIL";
                            
$arrLegend["2_GROUP_".$arD["GROUP_SID"]][$ctype_u] += $arD[$ctype_u."_COUNT"];
                            
$arrDays[$arD["DATE_STAT"]]["GROUP"]["DETAIL_".$ctype_u][$arD["GROUP_SID"]] += $arD[$ctype_u."_COUNT"];
                        }
                        elseif (
$group_total=="Y")
                        {
                            
$arrLegend["2_GROUP"]["TYPE"] = "GROUP";
                            
$arrLegend["2_GROUP"]["COUNTER_TYPE"] = "TOTAL";
                            
$arrLegend["2_GROUP"][$ctype_u] += $arD[$ctype_u."_COUNT"];
                            
$arrDays[$arD["DATE_STAT"]]["GROUP"]["TOTAL_".$ctype_u] += $arD[$ctype_u."_COUNT"];
                        }
                    }
                }
            }
        }

        if (
in_array("ctr"$arShow))
        {
            
// рассчитаем CTR
            
reset($arrDays);
            while(list(
$keyD,$arD)=each($arrDays))
            {
                
reset($arrLegend);
                while(list(, 
$arrS) = each($arrLegend))
                {
                    if (
$arrS["COUNTER_TYPE"]=="DETAIL")
                    {
                        
$show_value intval($arD[$arrS["TYPE"]][$arrS["COUNTER_TYPE"]."_SHOW"][$arrS["ID"]]);
                        
$click_value intval($arD[$arrS["TYPE"]][$arrS["COUNTER_TYPE"]."_CLICK"][$arrS["ID"]]);
                        if (
$show_value<=0$ctr_value=0;
                        else 
$ctr_value round(($click_value*100)/$show_value2);
                        
$arD[$arrS["TYPE"]]["DETAIL_CTR"][$arrS["ID"]] = $ctr_value;
                        
$arrDays[$keyD] = $arD;
                    }
                    else
                    {
                        
$show_value intval($arD[$arrS["TYPE"]][$arrS["COUNTER_TYPE"]."_SHOW"]);
                        
$click_value intval($arD[$arrS["TYPE"]][$arrS["COUNTER_TYPE"]."_CLICK"]);
                        if (
$show_value<=0$ctr_value=0;
                        else 
$ctr_value round(($click_value*100)/$show_value2);
                        
$arD[$arrS["TYPE"]]["TOTAL_CTR"] = $ctr_value;
                        
$arrDays[$keyD] = $arD;
                    }
                }
            }
        }

        
// Определим цвета и суммарный CTR
        
reset($arrLegend);
        
$s 0;
        if (
in_array("ctr"$arShow)) $s++;
        if (
$arFilter["WHAT_SHOW"]!=array("ctr") && in_array("show"$arShow)) $s++;
        if (
$arFilter["WHAT_SHOW"]!=array("ctr") && in_array("click"$arShow)) $s++;
        if (
$arFilter["WHAT_SHOW"]!=array("ctr") && in_array("visitor"$arShow)) $s++;
        
$total sizeof($arrLegend)*$s;
        
$color "";
        while (list(
$key$arr) = each($arrLegend))
        {
            if (
in_array("ctr"$arShow))
            {
                
$color GetNextRGB($color$total);
                
$arr["COLOR_CTR"] = $color;
                if (
$arr["SHOW"]<=0$ctr 0;
                else 
$ctr round(($arr["CLICK"]*100)/$arr["SHOW"], 2);
                
$arr["CTR"] = $ctr;
            }
            if (
$arFilter["WHAT_SHOW"]!=array("ctr"))
            {
                if (
in_array("show"$arShow))
                {
                    
$color GetNextRGB($color$total);
                    
$arr["COLOR_SHOW"] = $color;
                }
                if (
in_array("click"$arShow))
                {
                    
$color GetNextRGB($color$total);
                    
$arr["COLOR_CLICK"] = $color;
                }
                if (
in_array("visitor"$arShow))
                {
                    
$color GetNextRGB($color$total);
                    
$arr["COLOR_VISITOR"] = $color;
                }
            }
            
$arr["COLOR"] = $color;
            
$arrLegend[$key] = $arr;
        }
        
krsort($arrLegend);

        
$is_filtered = (IsFiltered($strSqlSearch));
        
reset($arrDays);
        
reset($arrLegend);
        return 
$arrDays;
    }