/** * The function select all cities * * @param array $arOrder sorting an array of results * @param array $arFilter filtered an array of results * @param string $strLang language regions of the sample * @return true false */ function GetCityList($arOrder = Array("NAME_LANG"=>"ASC"), $arFilter=Array(), $strLang = LANGUAGE_ID) { if(self::isLocationProMigrated()) return parent::GetLocationTypeList('CITY', $arOrder, $arFilter, $strLang); global $DB; $arSqlSearch = Array(); if(!is_array($arFilter)) $filter_keys = Array(); else $filter_keys = array_keys($arFilter); $countFilterKey = count($filter_keys); for($i=0; $i < $countFilterKey; $i++) { $val = $DB->ForSql($arFilter[$filter_keys[$i]]); if (strlen($val)<=0) continue; $key = $filter_keys[$i]; if ($key[0]=="!") { $key = substr($key, 1); $bInvert = true; } else $bInvert = false; switch(ToUpper($key)) { case "ID": $arSqlSearch[] = "C.ID ".($bInvert?"<>":"=")." ".IntVal($val)." "; break; case "NAME": $arSqlSearch[] = "C.NAME ".($bInvert?"<>":"=")." '".$val."' "; break; case "REGION_ID": $arSqlSearch[] = "SL.REGION_ID ".($bInvert?"<>":"=")." '".$val."' "; break; } } $strSqlSearch = ""; $countSqlSearch = count($arSqlSearch); for($i=0; $i < $countSqlSearch; $i++) { $strSqlSearch .= " AND "; $strSqlSearch .= " (".$arSqlSearch[$i].") "; } $strSql = "SELECT C.ID, C.NAME as NAME_ORIG, C.SHORT_NAME, CL.NAME as NAME, ". " IF(CL.ID IS NULL, C.NAME, CL.NAME) as NAME_LANG ". "FROM b_sale_location_city C ". " LEFT JOIN b_sale_location_city_lang CL ON (C.ID = CL.CITY_ID AND CL.LID = '".$DB->ForSql($strLang, 2)."') ". " LEFT JOIN b_sale_location SL ON (SL.CITY_ID = C.ID) ". "WHERE 1 = 1 ". " ".$strSqlSearch." "; $arSqlOrder = Array(); foreach ($arOrder as $by=>$order) { $by = ToUpper($by); $order = ToUpper($order); if ($order!="ASC") $order = "DESC"; if ($by == "SORT") $arSqlOrder[] = " SL.SORT ".$order; elseif ($by == "ID") $arSqlOrder[] = " C.ID ".$order." "; elseif ($by == "NAME") $arSqlOrder[] = " C.NAME ".$order." "; elseif ($by == "SHORT_NAME") $arSqlOrder[] = " C.SHORT_NAME ".$order." "; else { $arSqlOrder[] = " CL.NAME ".$order." "; $by = "NAME_LANG"; } } $strSqlOrder = ""; DelDuplicateSort($arSqlOrder); $countSqlOrder = count($arSqlOrder); for ($i=0; $i < $countSqlOrder; $i++) { if ($i==0) $strSqlOrder = " ORDER BY "; else $strSqlOrder .= ", "; $strSqlOrder .= $arSqlOrder[$i]; } $strSql .= $strSqlOrder; $db_res = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); return $db_res; }
/** * <p>Метод возвращает параметры местоположения с кодом ID, включая параметры страны и города. Параметры, зависящие от языка, возвращаются для языка strLang. Метод динамичный.</p> * * * @param int $ID Код местоположения. </h * * @param string $strLang = LANGUAGE_ID Язык параметров, зависящих от языка. По умолчанию равен текущему * языку. * * @return array <p>Возвращает ассоциативный массив с ключами:</p> <table class="tnormal" * width="100%"> <tr> <th width="15%">Ключ</th> <th>Описание</th> <th>С версии</th> </tr> <tr> * <td>ID</td> <td>Код местоположения.</td> <td></td> </tr> <tr> <td>COUNTRY_ID</td> <td>Код * страны.</td> <td></td> </tr> <tr> <td>CITY_ID</td> <td>Код города.</td> <td></td> </tr> <tr> * <td>SORT</td> <td>Индекс сортировки.</td> <td></td> </tr> <tr> <td>COUNTRY_NAME_ORIG</td> * <td>Языконезависимое название страны.</td> <td></td> </tr> <tr> * <td>COUNTRY_SHORT_NAME</td> <td>Языконезависимое сокращенное название * страны.</td> <td></td> </tr> <tr> <td>COUNTRY_NAME_LANG</td> <td>Языкозависимое название * страны.</td> <td></td> </tr> <tr> <td>CITY_NAME_ORIG</td> <td>Языконезависимое название * города.</td> <td></td> </tr> <tr> <td>CITY_SHORT_NAME</td> <td>Языконезависимое * сокращенное название города.</td> <td></td> </tr> <tr> <td>CITY_NAME_LANG</td> * <td>Языкозависимое название города.</td> <td></td> </tr> <tr> <td>REGION_ID</td> <td>Код * региона.</td> <td></td> </tr> <tr> <td>REGION_NAME_ORIG</td> <td>Языконезависимое * название региона.</td> <td>12.5 </td> </tr> <tr> <td>REGION_SHORT_NAME</td> * <td>Языконезависимое сокращенное название региона.</td> <td>12.5 </td> </tr> * <tr> <td>REGION_NAME_LANG</td> <td>Языкозависимое название региона.</td> <td>12.5 </td> * </tr> <tr> <td>COUNTRY_NAME</td> <td>Языкозависимое название страны, если оно * есть. Иначе - языконезависимое название страны.</td> <td></td> </tr> <tr> * <td>CITY_NAME</td> <td>Языкозависимое название города, если оно есть. Иначе * - языконезависимое название города.</td> <td></td> </tr> <tr> <td>REGION_NAME</td> * <td>Языкозависимое название региона, если оно есть. Иначе - * языконезависимое название региона.</td> <td>12.5 </td> </tr> </table> <p> </p<a * name="examples"></a> * * <h4>Example</h4> * <pre> * <? * $arLocs = CSaleLocation::GetByID(22, LANGUAGE_ID); * echo $arLocs["COUNTRY_NAME"]." - ".$arLocs["CITY_NAME"];<br>?> * </pre> * * * @static * @link http://dev.1c-bitrix.ru/api_help/sale/classes/csalelocation/csalelocation__getbyid.bbc61011.php * @author Bitrix */ public static function GetByID($ID, $strLang = LANGUAGE_ID) { if (self::isLocationProMigrated()) { return parent::GetByID($ID, $strLang); } global $DB; $ID = IntVal($ID); /*$strSql = "SELECT L.ID, L.COUNTRY_ID, L.CITY_ID, L.SORT, ". " LC.NAME as COUNTRY_NAME_ORIG, LC.SHORT_NAME as COUNTRY_SHORT_NAME, LCL.NAME as COUNTRY_NAME_LANG, ". " LG.NAME as CITY_NAME_ORIG, LG.SHORT_NAME as CITY_SHORT_NAME, LGL.NAME as CITY_NAME_LANG, ". " IF(LCL.ID IS NULL, LC.NAME, LCL.NAME) as COUNTRY_NAME, ". " IF(LGL.ID IS NULL, LG.NAME, LGL.NAME) as CITY_NAME ". "FROM b_sale_location L ". " LEFT JOIN b_sale_location_country LC ON (L.COUNTRY_ID = LC.ID) ". " LEFT JOIN b_sale_location_city LG ON (L.CITY_ID = LG.ID) ". " LEFT JOIN b_sale_location_country_lang LCL ON (LC.ID = LCL.COUNTRY_ID AND LCL.LID = '".$DB->ForSql($strLang, 2)."') ". " LEFT JOIN b_sale_location_city_lang LGL ON (LG.ID = LGL.CITY_ID AND LGL.LID = '".$DB->ForSql($strLang, 2)."') ". "WHERE L.ID = ".$ID." ";*/ $strSql = "\n\t\tSELECT L.ID, L.COUNTRY_ID, L.CITY_ID, L.SORT, LC.NAME as COUNTRY_NAME_ORIG, LC.SHORT_NAME as COUNTRY_SHORT_NAME, LCL.NAME as COUNTRY_NAME_LANG,\n\t\tLG.NAME as CITY_NAME_ORIG, LG.SHORT_NAME as CITY_SHORT_NAME, LGL.NAME as CITY_NAME_LANG,\n\t\tL.REGION_ID, LR.NAME as REGION_NAME_ORIG, LR.SHORT_NAME as REGION_SHORT_NAME, LRL.NAME as REGION_NAME_LANG,\n\t\tIF(LCL.ID IS NULL, LC.NAME, LCL.NAME) as COUNTRY_NAME,\n\t\tIF(LGL.ID IS NULL, LG.NAME, LGL.NAME) as CITY_NAME,\n\t\tIF(LRL.ID IS NULL, LR.NAME, LRL.NAME) as REGION_NAME\n\t\tFROM b_sale_location L\n\t\t\tLEFT JOIN b_sale_location_country LC ON (L.COUNTRY_ID = LC.ID)\n\t\t\tLEFT JOIN b_sale_location_city LG ON (L.CITY_ID = LG.ID)\n\t\t\tLEFT JOIN b_sale_location_country_lang LCL ON (LC.ID = LCL.COUNTRY_ID AND LCL.LID = '" . $DB->ForSql($strLang, 2) . "')\n\t\t\tLEFT JOIN b_sale_location_city_lang LGL ON (LG.ID = LGL.CITY_ID AND LGL.LID = '" . $DB->ForSql($strLang, 2) . "')\n\t\t\tLEFT JOIN b_sale_location_region LR ON (L.REGION_ID = LR.ID)\n\t\t\tLEFT JOIN b_sale_location_region_lang LRL ON (LR.ID = LRL.REGION_ID AND LRL.LID = '" . $DB->ForSql($strLang, 2) . "')\n\t\tWHERE L.ID = " . $ID . " "; $db_res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($res = $db_res->Fetch()) { return $res; } return False; }
function AddLocation($arFields) { global $DB; if (!CSaleLocation::LocationCheckFields("ADD", $arFields)) { return false; } if (self::isLocationProMigrated()) { return parent::RebindLocationTriplet($arFields); } // make IX_B_SALE_LOC_CODE feel happy $arFields['CODE'] = 'randstr' . rand(999, 99999); foreach (GetModuleEvents('sale', 'OnBeforeLocationAdd', true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($arFields)) === false) { return false; } } $arInsert = $DB->PrepareInsert("b_sale_location", $arFields); $strSql = "INSERT INTO b_sale_location(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $ID = IntVal($DB->LastID()); // make IX_B_SALE_LOC_CODE feel happy Location\LocationTable::update($ID, array('CODE' => $ID)); foreach (GetModuleEvents('sale', 'OnLocationAdd', true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($ID, $arFields)); } return $ID; }