Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
locationservice.php
1<?php
2
4
9use \Bitrix\Location\Repository\LocationRepository;
10use \Bitrix\Location\Infrastructure\Service\Config;
11
19final class LocationService extends BaseService
20{
21 use \Bitrix\Location\Common\RepositoryTrait;
22
24 protected static $instance;
25
27 protected $repository = null;
28
37 public function findById(int $locationId, string $languageId, int $searchScope = LOCATION_SEARCH_SCOPE_ALL)
38 {
39 $result = false;
40
41 try
42 {
43 $result = $this->repository->findById($locationId, $languageId, $searchScope);
44 }
45 catch (RuntimeException $exception)
46 {
47 $this->processException($exception);
48 }
49
50 return $result;
51 }
52
62 public function findByExternalId(string $externalId, string $sourceCode, string $languageId, int $searchScope = LOCATION_SEARCH_SCOPE_ALL)
63 {
64 $result = false;
65
66 try
67 {
68 $result = $this->repository->findByExternalId($externalId, $sourceCode, $languageId, $searchScope);
69 }
70 catch (RuntimeException $exception)
71 {
72 $this->processException($exception);
73 }
74
75 return $result;
76 }
77
83 public function autocomplete(array $params, int $searchScope = LOCATION_SEARCH_SCOPE_ALL)
84 {
85 $result = [];
86
87 try
88 {
89 $result = $this->repository->autocomplete($params, $searchScope);
90 }
91 catch (RuntimeException $exception)
92 {
93 $this->processException($exception);
94 }
95
96 return $result;
97 }
98
108 public function findParents(Entity\Location $location, string $languageId, int $searchScope = LOCATION_SEARCH_SCOPE_ALL)
109 {
110 $result = false;
111
112 try
113 {
114 $result = $this->repository->findParents($location, $languageId, $searchScope);
115 }
116 catch (RuntimeException $exception)
117 {
118 $this->processException($exception);
119 }
120
121 return $result;
122 }
123
130 public function save(Entity\Location $location): Result
131 {
132 return $this->repository->save($location);
133 }
134
141 public function delete(Entity\Location $location): Result
142 {
143 return $this->repository->delete($location);
144 }
145
151 protected function __construct(Config\Container $config)
152 {
153 $this->setRepository($config->get('repository'));
154 parent::__construct($config);
155 }
156
164 public function saveParents(Entity\Location\Parents $parents): Result
165 {
166 return $this->repository->saveParents($parents);
167 }
168}
processException(\Exception $exception)
findByExternalId(string $externalId, string $sourceCode, string $languageId, int $searchScope=LOCATION_SEARCH_SCOPE_ALL)
findById(int $locationId, string $languageId, int $searchScope=LOCATION_SEARCH_SCOPE_ALL)
findParents(Entity\Location $location, string $languageId, int $searchScope=LOCATION_SEARCH_SCOPE_ALL)
saveParents(Entity\Location\Parents $parents)
autocomplete(array $params, int $searchScope=LOCATION_SEARCH_SCOPE_ALL)