3namespace Bitrix\Location\Repository\Location;
5use Bitrix\Location\Entity\Address\Normalizer\Builder;
6use Bitrix\Location\Entity\Location;
7use Bitrix\Location\Model;
8use Bitrix\Location\Entity\Location\Parents;
9use Bitrix\Location\Repository\Location\Capability\ISave;
10use Bitrix\Location\Repository\Location\Capability\IDelete;
11use Bitrix\Location\Repository\Location\Capability\IFindByExternalId;
12use Bitrix\Location\Repository\Location\Capability\IFindById;
13use Bitrix\Location\Repository\Location\Capability\IFindByText;
14use Bitrix\Location\Repository\Location\Capability\IFindParents;
15use Bitrix\Location\Repository\Location\Capability\ISaveParents;
16use Bitrix\Main\ArgumentNullException;
18use Bitrix\Main\Localization\Loc;
19use Bitrix\Main\Result;
55 public function findByExternalId(
string $externalId,
string $sourceCode,
string $languageId)
62 $result = $this->createQuery($languageId)
63 ->addFilter(
'=EXTERNAL_ID', $externalId)
64 ->addFilter(
'=SOURCE_CODE', $sourceCode)
69 $result = \Bitrix\Location\Entity\Location\Converter\OrmConverter::createLocation(
$result, $languageId);
77 public function findById(
int $id,
string $languageId)
85 $res = $this->createQuery($languageId)
86 ->addFilter(
'=ID', $id)
91 $result = \Bitrix\Location\Entity\Location\Converter\OrmConverter::createLocation(
$res, $languageId);
107 $text = Builder::build($languageId)->normalize(
$text);
109 $result = $this->createQuery($languageId)
110 ->addFilter(
'%NAME.NAME_NORMALIZE',
$text)
113 return \Bitrix\Location\Entity\Location\Converter\OrmConverter::createCollection(
$result, $languageId);
124 $ormCollection = $this->hierarchyTable::getList([
127 '=ANCESTOR.NAME.LANGUAGE_ID' => $languageId,
129 'order' => [
'LEVEL' =>
'ASC'],
135 ])->fetchCollection();
137 $result = \Bitrix\Location\Entity\Location\Converter\OrmConverter::createParentCollection($ormCollection, $languageId);
146 $query = $this->locationTable::query()
147 ->where(
'EXTERNAL_ID',
$location->getExternalId())
148 ->where(
'SOURCE_CODE',
$location->getSourceCode())
162 return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
163 mt_rand(0, 0xffff), mt_rand(0, 0xffff),
165 mt_rand(0, 0x0fff) | 0x4000,
166 mt_rand(0, 0x3fff) | 0x8000,
167 mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
176 $isNewLocation =
false;
203 $isNewLocation =
true;
215 if(!
$res->isSuccess())
222 if(!
$res->isSuccess())
238 $fieldsCollection = Location\Converter\OrmConverter::convertFieldsToOrm(
$location);
240 $this->fieldTable::deleteByLocationId(
$location->getId());
241 return $fieldsCollection->save();
246 $fields = Location\Converter\DbFieldConverter::convertNameToDbFields(
$location);
251 $itemExist = $this->locationNameTable::getById([
252 'LOCATION_ID' =>
$fields[
'LOCATION_ID'],
253 'LANGUAGE_ID' =>
$fields[
'LANGUAGE_ID']]
259 $result = $this->locationNameTable::update([
260 'LOCATION_ID' =>
$fields[
'LOCATION_ID'],
261 'LANGUAGE_ID' =>
$fields[
'LANGUAGE_ID']
282 $res = $this->addressTable::getList([
283 'filter' => [
'LOCATION_ID' => (
int)$id]
286 if($row =
$res->fetch())
291 Loc::getMessage(
'LOCATION_REPO_DB_EXIST_LINKED_ADDRESS')
296 $result = $this->locationTable::delete($id);
300 $this->locationNameTable::deleteByLocationId($id);
301 $this->hierarchyTable::deleteByLocationId($id);
302 $this->fieldTable::deleteByLocationId($id);
318 if($parents->
count() <= 0)
336 foreach(
$items as $level => $parentLocation)
338 if($parentLocation->getId() <= 0)
340 $res = $parentLocation->save();
342 if(!
$res->isSuccess())
351 'ANCESTOR_ID' => (int)$parentLocation->getId(),
352 'LEVEL' => (int)$level,
358 $this->hierarchyTable::insertBatch(
$data);
364 private function createQuery(
string $languageId)
366 return $this->locationTable::query()
367 ->addFilter(
'=NAME.LANGUAGE_ID', $languageId)
370 ->addSelect(
'FIELDS');
static convertToDbFields(Entity\Location $location)
findParents(Location $location, string $languageId)
obtainLocationKeys(Location $location)
findByExternalId(string $externalId, string $sourceCode, string $languageId)
findByText(string $text, string $languageId)
isScopeSatisfy(int $scope)
findById(int $id, string $languageId)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
saveParents(Location\Parents $parents)
const LOCATION_SEARCH_SCOPE_ALL
const LOCATION_SEARCH_SCOPE_INTERNAL