CAdvBanner::GetList: Bitrix method

      
<?php 
//  CAdvBanner :: GetList()
//  /dist/bitrix/modules/advertising/classes/mysql/advertising.php:297

    
public static function GetList(&$by, &$order$arFilter=Array(), &$is_filtered$CHECK_RIGHTS="Y")
    {
        
$err_mess = (CAdvBanner::err_mess())."<br>Function: GetList<br>Line: ";
        global 
$DB$USER$APPLICATION;
        if (
$CHECK_RIGHTS=="Y")
        {
            
$USER_ID intval($USER->GetID());
            
$isAdmin CAdvContract::IsAdmin();
            
$isDemo CAdvContract::IsDemo();
            
$isManager CAdvContract::IsManager();
            
$isAdvertiser CAdvContract::IsAdvertiser();
        }
        else
        {
            if (
is_object($USER)) $USER_ID intval($USER->GetID()); else $USER_ID 0;
            
$isAdmin true;
            
$isDemo true;
            
$isManager true;
            
$isAdvertiser true;
        }
        
$arSqlSearch = Array();
        
$strSqlSearch "";


        
$DONT_USE_CONTRACT COption::GetOptionString("advertising""DONT_USE_CONTRACT""N");

        if (
$DONT_USE_CONTRACT == "Y")
        {
            
$lamp "
                if ((
                    (B.DATE_SHOW_FROM<=now() or B.DATE_SHOW_FROM is null or length(B.DATE_SHOW_FROM)<=0) and
                    (B.DATE_SHOW_TO>=now() or B.DATE_SHOW_TO is null or length(B.DATE_SHOW_TO)<=0) and
                    (ifnull(B.MAX_SHOW_COUNT,0)>ifnull(B.SHOW_COUNT,0) or ifnull(B.MAX_SHOW_COUNT,0)=0) and
                    (ifnull(B.MAX_CLICK_COUNT,0)>ifnull(B.CLICK_COUNT,0) or ifnull(B.MAX_CLICK_COUNT,0)=0) and
                    (ifnull(B.MAX_VISITOR_COUNT,0)>ifnull(B.VISITOR_COUNT,0) or ifnull(B.MAX_VISITOR_COUNT,0)=0) and
                    (B.ACTIVE='Y') and
                    (B.STATUS_SID='PUBLISHED') and
                    (T.ACTIVE='Y')
                    ),
                    'green',
                    'red')
                "
;
        }
        else
        {
            
$lamp "
                if ((
                    (B.DATE_SHOW_FROM<=now() or B.DATE_SHOW_FROM is null or length(B.DATE_SHOW_FROM)<=0) and
                    (B.DATE_SHOW_TO>=now() or B.DATE_SHOW_TO is null or length(B.DATE_SHOW_TO)<=0) and
                    (ifnull(B.MAX_SHOW_COUNT,0)>ifnull(B.SHOW_COUNT,0) or ifnull(B.MAX_SHOW_COUNT,0)=0) and
                    (ifnull(B.MAX_CLICK_COUNT,0)>ifnull(B.CLICK_COUNT,0) or ifnull(B.MAX_CLICK_COUNT,0)=0) and
                    (ifnull(B.MAX_VISITOR_COUNT,0)>ifnull(B.VISITOR_COUNT,0) or ifnull(B.MAX_VISITOR_COUNT,0)=0) and
                    (B.ACTIVE='Y') and
                    (B.STATUS_SID='PUBLISHED') and
                    (T.ACTIVE='Y') and
                    (C.DATE_SHOW_FROM<=now() or C.DATE_SHOW_FROM is null or length(C.DATE_SHOW_FROM)<=0) and
                    (C.DATE_SHOW_TO>=now() or C.DATE_SHOW_TO is null or length(C.DATE_SHOW_TO)<=0) and
                    (ifnull(C.MAX_SHOW_COUNT,0)>ifnull(C.SHOW_COUNT,0) or ifnull(C.MAX_SHOW_COUNT,0)=0) and
                    (ifnull(C.MAX_CLICK_COUNT,0)>ifnull(C.CLICK_COUNT,0) or ifnull(C.MAX_CLICK_COUNT,0)=0) and
                    (ifnull(C.MAX_VISITOR_COUNT,0)>ifnull(C.VISITOR_COUNT,0) or ifnull(C.MAX_VISITOR_COUNT,0)=0) and
                    (C.ACTIVE='Y')
                    ),
                    'green',
                    'red')
                "
;
        }

        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) && count($val)<=0)
                    continue;
                if(
$val == '' || $val == "NOT_REF")
                    continue;
                
$match_value_set = (in_array($key."_EXACT_MATCH"$filter_keys)) ? true false;
                
$key strtoupper($key);
                switch(
$key)
                {
                    case 
"ID":
                        
$match = ($arFilter[$key."_EXACT_MATCH"]=="N" && $match_value_set) ? "Y" "N";
                        
$arSqlSearch[] = GetFilterQuery("B.ID",$val,$match);
                        break;
                    case 
"LAMP":
                        
$arSqlSearch[] = " ".$lamp." = '".$DB->ForSQL($val)."'";
                        break;
                    case 
"SITE":
                        if (
is_array($val)) $val implode(" | "$val);
                        
$match = ($arFilter[$key."_EXACT_MATCH"]=="N" && $match_value_set) ? "Y" "N";
                        
$arSqlSearch[] = GetFilterQuery("BS.SITE_ID"$val$match);
                        
$left_join "LEFT JOIN b_adv_banner_2_site BS ON (B.ID = BS.BANNER_ID)";
                        break;
                    case 
"DATE_MODIFY_1":
                        
$arSqlSearch[] = "B.DATE_MODIFY>=".$DB->CharToDateFunction($val"SHORT");
                        break;
                    case 
"DATE_MODIFY_2":
                        
$arSqlSearch[] = "B.DATE_MODIFY<".$DB->CharToDateFunction($val"SHORT")." + INTERVAL 1 DAY";
                        break;
                    case 
"DATE_CREATE_1":
                        
$arSqlSearch[] = "B.DATE_CREATE>=".$DB->CharToDateFunction($val"SHORT");
                        break;
                    case 
"DATE_CREATE_2":
                        
$arSqlSearch[] = "B.DATE_CREATE<".$DB->CharToDateFunction($val"SHORT")." + INTERVAL 1 DAY";
                        break;
                    case 
"DATE_SHOW_FROM_1":
                        
$arSqlSearch[] = "B.DATE_SHOW_FROM>=".$DB->CharToDateFunction($val"SHORT");
                        break;
                    case 
"DATE_SHOW_FROM_2":
                        
$arSqlSearch[] = "B.DATE_SHOW_FROM<".$DB->CharToDateFunction($val"SHORT")." + INTERVAL 1 DAY";
                        break;
                    case 
"DATE_SHOW_TO_1":
                        
$arSqlSearch[] = "B.DATE_SHOW_TO>=".$DB->CharToDateFunction($val"SHORT");
                        break;
                    case 
"DATE_SHOW_TO_2":
                        
$arSqlSearch[] = "B.DATE_SHOW_TO<".$DB->CharToDateFunction($val"SHORT")." + INTERVAL 1 DAY";
                        break;
                    case 
"ACTIVE":
                    case 
"FIX_SHOW":
                        
$arSqlSearch[] = ($val=="Y") ? "B.".$key."='Y'" "B.".$key."='N'";
                        break;
                    case 
"WEIGHT_1":
                        
$arSqlSearch[] = "ifnull(B.WEIGHT,0)>='".intval($val)."'";
                        break;
                    case 
"WEIGHT_2":
                        
$arSqlSearch[] = "ifnull(B.WEIGHT,0)<='".intval($val)."'";
                        break;
                    case 
"MAX_VISITOR_COUNT_1":
                        
$arSqlSearch[] = "ifnull(B.MAX_VISITOR_COUNT,0)>='".intval($val)."'";
                        break;
                    case 
"MAX_VISITOR_COUNT_2":
                        
$arSqlSearch[] = "ifnull(B.MAX_VISITOR_COUNT,0)<='".intval($val)."'";
                        break;
                    case 
"VISITOR_COUNT_1":
                        
$arSqlSearch[] = "ifnull(B.VISITOR_COUNT,0)>='".intval($val)."'";
                        break;
                    case 
"VISITOR_COUNT_2":
                        
$arSqlSearch[] = "ifnull(B.VISITOR_COUNT,0)<='".intval($val)."'";
                        break;
                    case 
"MAX_SHOW_COUNT_1":
                        
$arSqlSearch[] = "ifnull(B.MAX_SHOW_COUNT,0)>='".intval($val)."'";
                        break;
                    case 
"MAX_SHOW_COUNT_2":
                        
$arSqlSearch[] = "ifnull(B.MAX_SHOW_COUNT,0)<='".intval($val)."'";
                        break;
                    case 
"SHOW_COUNT_1":
                        
$arSqlSearch[] = "ifnull(B.SHOW_COUNT,0)>='".intval($val)."'";
                        break;
                    case 
"SHOW_COUNT_2":
                        
$arSqlSearch[] = "ifnull(B.SHOW_COUNT,0)<='".intval($val)."'";
                        break;
                    case 
"MAX_CLICK_COUNT_1":
                        
$arSqlSearch[] = "ifnull(B.MAX_CLICK_COUNT,0)>='".intval($val)."'";
                        break;
                    case 
"MAX_CLICK_COUNT_2":
                        
$arSqlSearch[] = "ifnull(B.MAX_CLICK_COUNT,0)<='".intval($val)."'";
                        break;
                    case 
"CLICK_COUNT_1":
                        
$arSqlSearch[] = "ifnull(B.CLICK_COUNT,0)>='".intval($val)."'";
                        break;
                    case 
"CLICK_COUNT_2":
                        
$arSqlSearch[] = "ifnull(B.CLICK_COUNT,0)<='".intval($val)."'";
                        break;
                    case 
"CTR_1":
                        
$arSqlSearch[] = "if(B.SHOW_COUNT<=0,0,round((B.CLICK_COUNT*100)/B.SHOW_COUNT,2))>='".DoubleVal(str_replace(',''.'$val))."'";
                        break;
                    case 
"CTR_2":
                        
$arSqlSearch[] = "if(B.SHOW_COUNT<=0,0,round((B.CLICK_COUNT*100)/B.SHOW_COUNT,2))<='".DoubleVal(str_replace(',''.'$val))."'";
                        break;
                    case 
"GROUP":
                        
$match = ($arFilter[$key."_EXACT_MATCH"]=="Y" && $match_value_set) ? "N" "Y";
                        
$arSqlSearch[] = GetFilterQuery("B.GROUP_SID"$val$match);
                        break;
                    case 
"STATUS":
                    case 
"STATUS_SID":
                        if (
is_array($val)) $val implode(" | ",$val);
                        
$arSqlSearch[] = GetFilterQuery("B.STATUS_SID"$val"N");
                        break;
                    case 
"CONTRACT_ID":
                        if (
is_array($val)) $val implode(" | ",$val);
                        
$match = ($arFilter[$key."_EXACT_MATCH"]=="N" && $match_value_set) ? "Y" "N";
                        
$arSqlSearch[] = GetFilterQuery("B.CONTRACT_ID"$val$match);
                        break;
                    case 
"CONTRACT":
                        if (
is_array($val)) $val implode(" | ",$val);
                        
$match = ($arFilter[$key."_EXACT_MATCH"]=="Y" && $match_value_set) ? "N" "Y";
                        
$arSqlSearch[] = GetFilterQuery("B.CONTRACT_ID, C.NAME, C.DESCRIPTION"$val$match);
                        break;
                    case 
"TYPE_SID":
                        if (
is_array($val)) $val implode(" | ",$val);
                        
$match = ($arFilter[$key."_EXACT_MATCH"]=="N" && $match_value_set) ? "Y" "N";
                        
$arSqlSearch[] = GetFilterQuery("B.TYPE_SID"$val$match);
                        break;
                    case 
"TYPE":
                        if (
is_array($val)) $val implode(" | ",$val);
                        
$match = ($arFilter[$key."_EXACT_MATCH"]=="Y" && $match_value_set) ? "N" "Y";
                        
$arSqlSearch[] = GetFilterQuery("B.TYPE_SID, T.NAME, T.DESCRIPTION"$val$match);
                        break;
                    case 
"SHOW_USER_GROUP":
                        if(
$val=="Y")
                            
$arSqlSearch[] = "B.SHOW_USER_GROUP='Y'";
                        else
                            
$arSqlSearch[] = "B.SHOW_USER_GROUP <> 'Y'";
                        break;
                    case 
"NAME":
                    case 
"CODE":
                    case 
"COMMENTS":
                        
$match = ($arFilter[$key."_EXACT_MATCH"]=="Y" && $match_value_set) ? "N" "Y";
                        
$arSqlSearch[] = GetFilterQuery("B.".$key$val$match);
                        break;

                    
// совместимость со старой версией
                    
case "LANG":
                    case 
"FIRST_SITE_ID":
                        
$arSqlSearch[] = GetFilterQuery("B.FIRST_SITE_ID",$val,"N");
                        break;
                }
            }
        }

        if (
$by == "s_id"$strSqlOrder " ORDER BY B.ID ";
        elseif (
$by == "s_lamp"$strSqlOrder " ORDER BY LAMP ";
        elseif (
$by == "s_name"$strSqlOrder " ORDER BY B.NAME ";
        elseif (
$by == "s_type_sid"$strSqlOrder " ORDER BY B.TYPE_SID ";
        elseif (
$by == "s_contract_id"$strSqlOrder " ORDER BY B.CONTRACT_ID ";
        elseif (
$by == "s_group_sid"$strSqlOrder " ORDER BY B.GROUP_SID ";
        elseif (
$by == "s_visitor_count"$strSqlOrder " ORDER BY B.VISITOR_COUNT ";
        elseif (
$by == "s_max_visitor_count"$strSqlOrder " ORDER BY ifnull(B.MAX_VISITOR_COUNT,0) ";
        elseif (
$by == "s_show_count"$strSqlOrder " ORDER BY B.SHOW_COUNT ";
        elseif (
$by == "s_max_show_count"$strSqlOrder " ORDER BY ifnull(B.MAX_SHOW_COUNT,0) ";
        elseif (
$by == "s_date_last_show"$strSqlOrder " ORDER BY B.DATE_LAST_SHOW ";
        elseif (
$by == "s_click_count"$strSqlOrder " ORDER BY B.CLICK_COUNT ";
        elseif (
$by == "s_max_click_count"$strSqlOrder " ORDER BY ifnull(B.MAX_CLICK_COUNT,0) ";
        elseif (
$by == "s_date_last_click"$strSqlOrder " ORDER BY B.DATE_LAST_CLICK ";
        elseif (
$by == "s_active"$strSqlOrder " ORDER BY B.ACTIVE ";
        elseif (
$by == "s_weight"$strSqlOrder " ORDER BY B.WEIGHT ";
        elseif (
$by == "s_status_sid"$strSqlOrder " ORDER BY B.STATUS_SID ";
        elseif (
$by == "s_date_show_from"$strSqlOrder " ORDER BY B.DATE_SHOW_FROM ";
        elseif (
$by == "s_date_show_to"$strSqlOrder " ORDER BY B.DATE_SHOW_TO ";
        elseif (
$by == "s_dropdown"$strSqlOrder " ORDER BY B.CONTRACT_ID desc, B.ID ";
        elseif (
$by == "s_ctr"$strSqlOrder " ORDER BY CTR ";
        elseif (
$by == "s_date_create"$strSqlOrder " ORDER BY B.DATE_CREATE ";
        elseif (
$by == "s_date_modify"$strSqlOrder " ORDER BY B.DATE_MODIFY ";
        else
        {
            
$strSqlOrder " ORDER BY B.ID ";
            
$by "s_id";
        }

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

        
$strSqlSearch GetFilterSqlSearch($arSqlSearch);

        if (
$isAdmin || $isDemo || $isManager)
        {
            
$strSql "
                SELECT DISTINCT
                    
$lamp                                                                LAMP,
                    B.*,
                    B.FIRST_SITE_ID,
                    B.FIRST_SITE_ID                                                        LID,
                    if(B.SHOW_COUNT<=0,0,round((B.CLICK_COUNT*100)/B.SHOW_COUNT,2))        CTR,
                    "
.$DB->DateToCharFunction("B.DATE_LAST_SHOW")."                        DATE_LAST_SHOW,
                    "
.$DB->DateToCharFunction("B.DATE_LAST_CLICK")."                    DATE_LAST_CLICK,
                    "
.$DB->DateToCharFunction("B.DATE_SHOW_FROM")."            DATE_SHOW_FROM,
                    "
.$DB->DateToCharFunction("B.DATE_SHOW_TO")."                DATE_SHOW_TO,
                    "
.$DB->DateToCharFunction("B.DATE_SHOW_FIRST")."            DATE_SHOW_FIRST,
                    "
.$DB->DateToCharFunction("B.DATE_CREATE")."                        DATE_CREATE,
                    "
.$DB->DateToCharFunction("B.DATE_MODIFY")."                        DATE_MODIFY,
                    C.NAME                                                                CONTRACT_NAME,
                    T.NAME                                                                TYPE_NAME
                FROM
                    b_adv_banner B
                INNER JOIN b_adv_type T ON (T.SID = B.TYPE_SID)
                INNER JOIN b_adv_contract C ON (C.ID = B.CONTRACT_ID)
                
$left_join
                WHERE
                
$strSqlSearch
                
$strSqlOrder
                "
;
        }
        else
        {
            
$strSql "
                SELECT DISTINCT
                    
$lamp                                                                LAMP,
                    B.*,
                    B.FIRST_SITE_ID,
                    B.FIRST_SITE_ID                                                        LID,
                    if(B.SHOW_COUNT<=0,0,round((B.CLICK_COUNT*100)/B.SHOW_COUNT,2))        CTR,
                    "
.$DB->DateToCharFunction("B.DATE_LAST_SHOW")."                        DATE_LAST_SHOW,
                    "
.$DB->DateToCharFunction("B.DATE_LAST_CLICK")."                    DATE_LAST_CLICK,
                    "
.$DB->DateToCharFunction("B.DATE_SHOW_FROM")."            DATE_SHOW_FROM,
                    "
.$DB->DateToCharFunction("B.DATE_SHOW_TO")."                DATE_SHOW_TO,
                    "
.$DB->DateToCharFunction("B.DATE_SHOW_FIRST")."            DATE_SHOW_FIRST,
                    "
.$DB->DateToCharFunction("B.DATE_CREATE")."                        DATE_CREATE,
                    "
.$DB->DateToCharFunction("B.DATE_MODIFY")."                        DATE_MODIFY,
                    C.NAME                                                                CONTRACT_NAME,
                    T.NAME                                                                TYPE_NAME
                FROM
                    b_adv_banner B
                INNER JOIN b_adv_type T ON (T.SID = B.TYPE_SID)
                INNER JOIN b_adv_contract C ON (C.ID = B.CONTRACT_ID)
                INNER JOIN b_adv_contract_2_user CU ON (CU.CONTRACT_ID=C.ID and CU.USER_ID=
$USER_ID)
                
$left_join
                WHERE
                
$strSqlSearch
                
$strSqlOrder
                "
;
        }
        
$res $DB->Query($strSqlfalse$err_mess.__LINE__);
        
$is_filtered = (IsFiltered($strSqlSearch));
        return 
$res;
    }