Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
location.php
1<?php
2
4
9use \Bitrix\Location\Entity;
11
18{
19 protected function getDefaultPreFilters()
20 {
21 return [];
22 }
23
29 public function findByIdAction(int $locationId, string $languageId)
30 {
31 $result = null;
32 $location = Service\LocationService::getInstance()->findById($locationId, $languageId);
33
34 if($location)
35 {
36 $result = $location->toArray();
37 }
38 elseif($location === false)
39 {
40 if(ErrorService::getInstance()->hasErrors())
41 {
42 $result = AjaxJson::createError(
43 ErrorService::getInstance()->getErrors()
44 );
45 }
46 }
47
48 return $result;
49 }
50
55 public function autocompleteAction(array $params)
56 {
57 return Service\LocationService::getInstance()->autocomplete($params, LOCATION_SEARCH_SCOPE_EXTERNAL);
58 }
59
65 public function findParentsAction(array $location)
66 {
67 $result = new Parents();
68 $entity = Entity\Location::fromArray($location);
69
70 if($entity)
71 {
72 $parents = $entity->getParents();
73
74 if($parents)
75 {
76 $result = \Bitrix\Location\Entity\Location\Converter\ArrayConverter::convertParentsToArray($parents);
77 }
78 else if($parents === false)
79 {
80 if(ErrorService::getInstance()->hasErrors())
81 {
82 $result = AjaxJson::createError(
83 ErrorService::getInstance()->getErrors()
84 );
85 }
86 }
87 }
88
89 return $result;
90 }
91
92
97 public function findByExternalIdAction(string $externalId, string $sourceCode, string $languageId)
98 {
99 $result = null;
100 $location = Service\LocationService::getInstance()->findByExternalId($externalId, $sourceCode, $languageId);
101
102 /* Temporary. To decrease the usage of the Google API */
103 if($location && $location->getId() > 0)
104 {
105 $externalLocation = Service\LocationService::getInstance()->findByExternalId(
106 $externalId,
107 $sourceCode,
108 $languageId,
109 LOCATION_SEARCH_SCOPE_EXTERNAL
110 );
111
112 if($externalLocation)
113 {
114 $location->setAddress($externalLocation->getAddress());
115 }
116 }
117 /* */
118
119 if($location)
120 {
121 $result = \Bitrix\Location\Entity\Location\Converter\ArrayConverter::convertToArray($location);
122 }
123 else
124 {
125 if(ErrorService::getInstance()->hasErrors())
126 {
127 $result = AjaxJson::createError(
128 ErrorService::getInstance()->getErrors()
129 );
130 }
131 }
132
133 return $result;
134 }
135
136 public static function saveAction(array $location)
137 {
138 $entity = Entity\Location::fromArray($location);
139 $result = $entity->save();
140
141 return [
142 'isSuccess' => $result->isSuccess(),
143 'errors' => $result->getErrorMessages(),
144 'location' => \Bitrix\Location\Entity\Location\Converter\ArrayConverter::convertToArray($entity)
145 ];
146 }
147
152 public function deleteAction(array $location)
153 {
154 return Service\LocationService::getInstance()->delete(
155 Entity\Location::fromArray($location)
156 );
157 }
158}
findByIdAction(int $locationId, string $languageId)
Definition location.php:29
findByExternalIdAction(string $externalId, string $sourceCode, string $languageId)
Definition location.php:97
static saveAction(array $location)
Definition location.php:136
static fromArray(array $location)
Definition location.php:550