47 return 'b_sale_location';
59 public static function getByCode($code =
'', $parameters = array())
61 $code = Assert::expectStringNotNull($code,
'$code');
63 if(!is_array($parameters))
64 $parameters = array();
66 $parameters[
'filter'][
'=CODE'] = $code;
67 $parameters[
'limit'] = 1;
69 return self::getList($parameters);
74 parent::checkFields($result, $primary, $data);
76 foreach(static::getEntity()->getFields() as $field)
80 if($field->getName() ==
'LATITUDE' && mb_strlen($data[
'LATITUDE']))
83 if(!is_numeric($data[
'LATITUDE']))
84 $error =
Loc::getMessage(
'SALE_LOCATION_LOCATION_ENTITY_LATITUDE_TYPE_ERROR');
85 elseif(($latitude = floatval($data[
'LATITUDE'])) && ($latitude < -90 || $latitude > 90))
86 $error =
Loc::getMessage(
'SALE_LOCATION_LOCATION_ENTITY_LATITUDE_RANGE_ERROR');
89 if($field->getName() ==
'LONGITUDE' && mb_strlen($data[
'LONGITUDE']))
92 if(!is_numeric($data[
'LONGITUDE']))
93 $error =
Loc::getMessage(
'SALE_LOCATION_LOCATION_ENTITY_LONGITUDE_TYPE_ERROR');
94 elseif(($longitude = floatval($data[
'LONGITUDE'])) && ($longitude < -180 || $longitude > 180))
95 $error =
Loc::getMessage(
'SALE_LOCATION_LOCATION_ENTITY_LONGITUDE_RANGE_ERROR');
103 Entity\FieldError::INVALID_VALUE
109 public static function add(array $data)
138 public static function addExtended(array $data, array $additional = array())
140 $resetLegacy = !isset($additional[
'RESET_LEGACY']) || $additional[
'RESET_LEGACY'] !==
false;
142 if(isset($data[
'EXTERNAL']))
144 $external = $data[
'EXTERNAL'];
145 unset($data[
'EXTERNAL']);
148 if(isset($data[
'NAME']))
150 $name = $data[
'NAME'];
151 unset($data[
'NAME']);
155 if(isset($data[
'CODE']))
156 $data[
'CODE'] = ToLower($data[
'CODE']);
162 $addResult = parent::addExtended($data, $additional);
165 if($addResult->isSuccess())
167 $primary = $addResult->getId();
175 Name\LocationTable::addMultipleForOwner($primary, $name);
177 if(intval($data[
'TYPE_ID']) > 0 && $resetLegacy)
180 Search\Finder::setIndexInvalid();
181 $GLOBALS[
'CACHE_MANAGER']->ClearByTag(
'sale-location-data');
189 $type = TypeTable::getList(array(
'filter' => array(
'=ID' => $typeId),
'select' => array(
'CODE')))->fetch();
190 if(mb_strlen($type[
'CODE']) && in_array($type[
'CODE'], array(
'COUNTRY',
'REGION',
'CITY')))
191 static::resetLegacyPath();
194 public static function update($primary, array $data)
223 public static function updateExtended($primary, array $data, array $additional = array())
225 $primary = Assert::expectIntegerPositive($primary,
'$primary');
226 $resetLegacy = !isset($additional[
'RESET_LEGACY']) || $additional[
'RESET_LEGACY'] !==
false;
230 if(isset($data[
'EXTERNAL']))
232 $external = $data[
'EXTERNAL'];
233 unset($data[
'EXTERNAL']);
236 if(isset($data[
'NAME']))
238 $name = $data[
'NAME'];
239 unset($data[
'NAME']);
243 if(isset($data[
'CODE']))
244 $data[
'CODE'] = ToLower($data[
'CODE']);
249 $updResult = parent::updateExtended($primary, $data, $additional);
252 if($updResult->isSuccess())
260 Name\LocationTable::updateMultipleForOwner($primary, $name);
262 if($resetLegacy && (intval($data[
'TYPE_ID']) > 0 || isset($data[
'PARENT_ID'])))
265 $GLOBALS[
'CACHE_MANAGER']->ClearByTag(
'sale-location-data');
267 if(isset($name) || isset($data[
'PARENT_ID']))
268 Search\Finder::setIndexInvalid();
274 public static function delete($primary)
290 $primary = Assert::expectIntegerPositive($primary,
'$primary');
291 $resetLegacy = !isset($additional[
'RESET_LEGACY']) || $additional[
'RESET_LEGACY'] !==
false;
292 $deleteSubtree = !isset($additional[
'DELETE_SUBTREE']) || $additional[
'DELETE_SUBTREE'] !==
false;
297 $rangeSql = parent::getSubtreeRangeSqlForNode($primary);
298 Name\LocationTable::deleteMultipleByParentRangeSql($rangeSql);
303 $data = static::getList(array(
'filter' => array(
'=ID' => $primary),
'select' => array(
'TYPE_ID')))->fetch();
305 $delResult = parent::deleteExtended($primary, $additional);
308 if($delResult->isSuccess())
310 Name\LocationTable::deleteMultipleForOwner($primary);
313 if($resetLegacy && intval($data[
'TYPE_ID']))
315 $type = TypeTable::getList(array(
'filter' => array(
'=ID' => $data[
'TYPE_ID']),
'select' => array(
'CODE')))->fetch();
316 if(mb_strlen($type[
'CODE']) && in_array($type[
'CODE'], array(
'COUNTRY',
'REGION',
'CITY')))
317 static::resetLegacyPath();
320 $GLOBALS[
'CACHE_MANAGER']->ClearByTag(
'sale-location-data');
321 Search\Finder::setIndexInvalid();
334 $primary = Assert::expectIntegerPositive($primary,
'$primary');
336 if(!is_array($parameters) || empty($parameters))
337 $parameters = array();
339 $parameters[
'filter'][
'LOCATION_ID'] = $primary;
341 return ExternalTable::getList($parameters);
354 $code = Assert::expectStringNotNull($code,
'$code');
359 public static function checkNodeIsParentOfNode($primary, $childPrimary, $behaviour = array(
'ACCEPT_CODE' =>
false,
'CHECK_DIRECT' =>
false))
361 if(!$behaviour[
'ACCEPT_CODE'])
362 return static::checkNodeIsParentOfNodeById($primary, $childPrimary, $behaviour);
364 $primary = Assert::expectStringNotNull($primary,
'$primary');
365 $childPrimary = Assert::expectStringNotNull($childPrimary,
'$childPrimary');
367 return static::checkNodeIsParentOfNodeByFilters(array(
'=CODE' => $primary), array(
'=CODE' => $childPrimary), $behaviour);
372 $dbConnection = Main\HttpApplication::getConnection();
373 $locTable = static::getTableName();
376 $res = TypeTable::getList(array(
377 'filter' => array(
'CODE' => array(
'COUNTRY',
'REGION',
'CITY')),
378 'select' => array(
'ID',
'CODE')
380 while($item = $res->fetch())
381 $types[$item[
'CODE']] = $item[
'ID'];
385 if(!$dbConnection->isTableExists(
'b_sale_loc_rebind'))
386 $dbConnection->query(
"create table b_sale_loc_rebind (TARGET_ID ".Helper::getSqlForDataType(
'int').
", LOCATION_ID ".Helper::getSqlForDataType(
'int').
")");
388 $dbConnection->query(
"truncate table b_sale_loc_rebind");
391 foreach($types as $code => $id)
392 $sqlWhere[] =
"'".intval($id).
"'";
394 $dbConnection->query(
"update ".$locTable.
" set COUNTRY_ID = NULL, REGION_ID = NULL, CITY_ID = NULL where TYPE_ID in (".implode(
', ', $sqlWhere).
")");
396 if(intval($types[
'REGION']) && intval($types[
'COUNTRY']))
399 $dbConnection->query(
"insert into b_sale_loc_rebind (TARGET_ID, LOCATION_ID) select A.ID as ONE, B.ID as TWO from ".$locTable.
" A inner join ".$locTable.
" B on A.TYPE_ID = '".intval($types[
'REGION']).
"' and B.TYPE_ID = '".intval($types[
'COUNTRY']).
"' and B.LEFT_MARGIN <= A.LEFT_MARGIN and B.RIGHT_MARGIN >= A.RIGHT_MARGIN");
400 Helper::mergeTables($locTable,
'b_sale_loc_rebind', array(
'COUNTRY_ID' =>
'LOCATION_ID'), array(
'ID' =>
'TARGET_ID'));
401 $dbConnection->query(
"truncate table b_sale_loc_rebind");
404 if(intval($types[
'REGION']) && intval($types[
'CITY']))
407 $dbConnection->query(
"insert into b_sale_loc_rebind (TARGET_ID, LOCATION_ID) select A.ID as ONE, B.ID as TWO from ".$locTable.
" A inner join ".$locTable.
" B on A.TYPE_ID = '".intval($types[
'CITY']).
"' and B.TYPE_ID = '".intval($types[
'REGION']).
"' and B.LEFT_MARGIN <= A.LEFT_MARGIN and B.RIGHT_MARGIN >= A.RIGHT_MARGIN");
408 Helper::mergeTables($locTable,
'b_sale_loc_rebind', array(
'REGION_ID' =>
'LOCATION_ID'), array(
'ID' =>
'TARGET_ID'));
409 $dbConnection->query(
"truncate table b_sale_loc_rebind");
412 if(intval($types[
'COUNTRY']) && intval($types[
'CITY']))
415 $dbConnection->query(
"insert into b_sale_loc_rebind (TARGET_ID, LOCATION_ID) select A.ID as ONE, B.ID as TWO from ".$locTable.
" A inner join ".$locTable.
" B on A.TYPE_ID = '".intval($types[
'CITY']).
"' and B.TYPE_ID = '".intval($types[
'COUNTRY']).
"' and B.LEFT_MARGIN <= A.LEFT_MARGIN and B.RIGHT_MARGIN >= A.RIGHT_MARGIN");
416 Helper::mergeTables($locTable,
'b_sale_loc_rebind', array(
'COUNTRY_ID' =>
'LOCATION_ID'), array(
'ID' =>
'TARGET_ID'));
419 Helper::dropTable(
'b_sale_loc_rebind');
421 if(intval($types[
'COUNTRY']))
422 $dbConnection->query(
"update ".$locTable.
" set COUNTRY_ID = ID where TYPE_ID = '".intval($types[
'COUNTRY']).
"'");
424 if(intval($types[
'REGION']))
425 $dbConnection->query(
"update ".$locTable.
" set REGION_ID = ID where TYPE_ID = '".intval($types[
'REGION']).
"'");
427 if(intval($types[
'CITY']))
428 $dbConnection->query(
"update ".$locTable.
" set CITY_ID = ID where TYPE_ID = '".intval($types[
'CITY']).
"'");
435 new Entity\Validator\Unique(),
444 'data_type' =>
'integer',
446 'autocomplete' =>
true,
450 'data_type' =>
'string',
451 'title' =>
Loc::getMessage(
'SALE_LOCATION_LOCATION_ENTITY_CODE_FIELD'),
453 'validation' => array(__CLASS__,
'getCodeValidators')
456 'LEFT_MARGIN' => array(
457 'data_type' =>
'integer',
459 'RIGHT_MARGIN' => array(
460 'data_type' =>
'integer',
462 'DEPTH_LEVEL' => array(
463 'data_type' =>
'integer',
466 'data_type' =>
'integer',
467 'default_value' => 100,
470 'PARENT_ID' => array(
471 'data_type' =>
'integer',
472 'default_value' => 0,
473 'title' =>
Loc::getMessage(
'SALE_LOCATION_LOCATION_ENTITY_PARENT_ID_FIELD')
476 'data_type' =>
'integer',
478 'title' =>
Loc::getMessage(
'SALE_LOCATION_LOCATION_ENTITY_TYPE_ID_FIELD')
481 'data_type' =>
'float',
482 'title' =>
Loc::getMessage(
'SALE_LOCATION_LOCATION_ENTITY_LATITUDE_FIELD')
484 'LONGITUDE' => array(
485 'data_type' =>
'float',
486 'title' =>
Loc::getMessage(
'SALE_LOCATION_LOCATION_ENTITY_LONGITUDE_FIELD')
491 'data_type' =>
'Bitrix\Sale\Location\Type',
492 'reference' => array(
493 '=this.TYPE_ID' =>
'ref.ID'
495 'join_type' =>
"inner"
498 'data_type' =>
'Bitrix\Sale\Location\Name\Location',
499 'reference' => array(
500 '=this.ID' =>
'ref.LOCATION_ID'
502 'join_type' =>
"inner"
505 'data_type' =>
'Bitrix\Sale\Location\Location',
506 'reference' => array(
507 '=this.PARENT_ID' =>
'ref.ID'
511 'data_type' =>
'Bitrix\Sale\Location\Location',
512 'reference' => array(
513 '<=ref.LEFT_MARGIN' =>
'this.LEFT_MARGIN',
514 '>=ref.RIGHT_MARGIN' =>
'this.RIGHT_MARGIN'
518 'data_type' =>
'Bitrix\Sale\Location\Location',
519 'reference' => array(
520 '=this.ID' =>
'ref.PARENT_ID'
524 'data_type' =>
'Bitrix\Sale\Location\External',
525 'reference' => array(
526 '=this.ID' =>
'ref.LOCATION_ID'
529 'DEFAULT_SITE' => array(
530 'data_type' =>
'Bitrix\Sale\Location\DefaultSite',
531 'reference' => array(
532 '=this.CODE' =>
'ref.LOCATION_CODE'
537 'data_type' =>
'integer',
538 'expression' => array(
542 'CHILDREN_CNT' => array(
543 'data_type' =>
'integer',
544 'expression' => array(
549 'IS_PARENT' => array(
550 'data_type' =>
'boolean',
551 'expression' => array(
552 'case when count(%s) > 0 then 1 else 0 end',
558 'COUNTRY_ID' => array(
559 'data_type' =>
'integer',
561 'REGION_ID' => array(
562 'data_type' =>
'integer',
565 'data_type' =>
'integer',
567 'LOC_DEFAULT' => array(
568 'data_type' =>
'string',
573 'data_type' =>
'Bitrix\Sale\Location\Location',
574 'reference' => array(
575 '=this.ID' =>
'ref.PARENT_ID'
578 'CHILD_CNT' => array(
579 'data_type' =>
'integer',
580 'expression' => array(
585 'DEFAULT_SORT' => array(
586 'data_type' =>
'Bitrix\Sale\Location\DefaultSiteTable',
587 'reference' => array(
588 '=this.CODE' =>
'ref.LOCATION_CODE'
602 if(isset($parameters[
'filter'][
'NAME']))
604 $parameters[
'filter'][
'PHRASE'] = $parameters[
'filter'][
'NAME'];
605 unset($parameters[
'filter'][
'NAME']);
608 if(isset($parameters[
'filter'][
'LANGUAGE_ID']))
610 $parameters[
'filter'][
'NAME.LANGUAGE_ID'] = $parameters[
'filter'][
'LANGUAGE_ID'];
611 unset($parameters[
'filter'][
'LANGUAGE_ID']);
614 return \Bitrix\Sale\Location\Search\Finder::find($parameters, array(
'USE_INDEX' =>
false,
'USE_ORM' =>
false));
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static updateMultipleForOwner($primaryOwner, $external)
static deleteMultipleForOwner($primaryOwner)
static addMultipleForOwner($primaryOwner, $external=array())
static deleteMultipleByParentRangeSql($sql)
static updateExtended($primary, array $data, array $additional=array())
static getExternalData($primary, $parameters=array())
static getCodeValidators()
static getListFast($parameters=array())
static resetLegacy($typeId)
static getByCode($code='', $parameters=array())
static checkFields(Entity\Result $result, $primary, array $data)
static addExtended(array $data, array $additional=array())
static checkNodeIsParentOfNode($primary, $childPrimary, $behaviour=array('ACCEPT_CODE'=> false, 'CHECK_DIRECT'=> false))
static deleteExtended($primary, array $additional=array())
static update($primary, array $data)
static getPathToNodeByCode($code, $parameters, $behaviour=array('SHOW_LEAF'=> true))
static applyRestrictions(&$data)
static getPathToNodeByCondition($filter, $parameters=array(), $behaviour=array('SHOW_LEAF'=> true))
$GLOBALS['____1444769544']