Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
find.php
1
<?php
2
3
namespace
Bitrix\Location\Repository\Location\Strategy
;
4
5
use
Bitrix\Location\Entity\Location
;
6
use
Bitrix\Location\Entity\Generic\Collection
;
7
use
Bitrix\Location\Entity\Location\Parents
;
8
use
Bitrix\Location\Repository\Location\Capability\IFindByExternalId
;
9
use
Bitrix\Location\Repository\Location\Capability\IFindById
;
10
use
Bitrix\Location\Repository\Location\Capability\IFindByText
;
11
use
Bitrix\Location\Repository\Location\Capability\IFindParents
;
12
use
Bitrix\Location\Repository\Location\Capability\ISupportAutocomplete
;
13
use
Bitrix\Location\Repository\Location\IScope
;
14
use
Bitrix\Location\Repository\Location\IRepository
;
15
use
Bitrix\Location\Repository\Location\ICache
;
16
use
Bitrix\Location\Repository\Location\IDatabase
;
17
22
class
Find
extends
Base
23
{
25
public
function
findById
(
int
$id,
string
$languageId,
int
$searchScope)
26
{
27
return
$this->
find
(IFindById::class,
'findById'
, [$id, $languageId], $searchScope);
28
}
29
31
public
function
findByExternalId
(
string
$externalId,
string
$sourceCode,
string
$languageId,
int
$searchScope)
32
{
33
return
$this->
find
(IFindByExternalId::class,
'findByExternalId'
, [$externalId, $sourceCode, $languageId], $searchScope);
34
}
35
37
public
function
findByText
(
string
$text,
string
$languageId,
int
$searchScope)
38
{
39
return
$this->
find
(IFindByText::class,
'findByText'
, [$text, $languageId], $searchScope) ??
new
Location\Collection
();
40
}
41
42
public
function
autocomplete
(array $params,
int
$searchScope)
43
{
44
return
$this->
find
(ISupportAutocomplete::class,
'autocomplete'
, [$params], $searchScope) ?? [];
45
}
46
47
public
function
findParents
(
Location
$location,
string
$languageId,
int
$searchScope)
48
{
49
return
$this->
find
(IFindParents::class,
'findParents'
, [$location, $languageId], $searchScope) ??
new
Parents
();
50
}
51
53
public
function
setLocationRepositories
(array
$locationRepositories
):
Base
54
{
55
$idx = 0;
56
57
foreach
(
$locationRepositories
as $repository)
58
{
59
if
($repository instanceof
IFindById
60
|| $repository instanceof
IFindByExternalId
61
|| $repository instanceof
IFindByText
62
|| $repository instanceof
IFindParents
63
)
64
{
65
$key = (string)$this->
getRepoPriority
($repository) . (string)($idx++);
66
$this->locationRepositories[$key] = $repository;
67
}
68
}
69
70
ksort($this->locationRepositories);
71
return
$this;
72
}
73
81
protected
function
find
(
string
$interface,
string
$method, array $params,
int
$searchScope)
82
{
83
$result =
null
;
84
85
foreach
($this->locationRepositories as $repository)
86
{
87
if
($repository instanceof
IScope
)
88
{
89
if
(!$repository->isScopeSatisfy($searchScope))
90
{
91
continue
;
92
}
93
}
94
95
if
($repository instanceof $interface)
96
{
97
$result = call_user_func_array([$repository, $method], $params);
98
99
if
($result)
100
{
101
if
(!($result instanceof
Location
\
Collection
) || $result->count() > 0)
102
{
103
return
$result;
104
}
105
}
106
}
107
}
108
109
return
null
;
110
}
111
116
protected
function
getRepoPriority
(
IRepository
$repository)
117
{
118
if
($repository instanceof
ICache
)
119
{
120
$result =
self::REPO_PRIORITY_A
;
121
}
122
elseif($repository instanceof
IDatabase
)
123
{
124
$result =
self::REPO_PRIORITY_B
;
125
}
126
else
127
{
128
$result =
self::REPO_PRIORITY_C
;
129
}
130
131
return
$result;
132
}
133
134
135
136
}
Bitrix\Location\Entity\Generic\Collection
Definition
collection.php:12
Bitrix\Location\Entity\Location\Collection
Definition
collection.php:15
Bitrix\Location\Entity\Location\Parents
Definition
parents.php:13
Bitrix\Location\Entity\Location
Definition
location.php:20
Bitrix\Location\Repository\Location\Strategy\Base
Definition
base.php:13
Bitrix\Location\Repository\Location\Strategy\Base\REPO_PRIORITY_C
const REPO_PRIORITY_C
Definition
base.php:19
Bitrix\Location\Repository\Location\Strategy\Base\$locationRepositories
$locationRepositories
Definition
base.php:15
Bitrix\Location\Repository\Location\Strategy\Base\REPO_PRIORITY_B
const REPO_PRIORITY_B
Definition
base.php:18
Bitrix\Location\Repository\Location\Strategy\Base\REPO_PRIORITY_A
const REPO_PRIORITY_A
Definition
base.php:17
Bitrix\Location\Repository\Location\Strategy\Find
Definition
find.php:23
Bitrix\Location\Repository\Location\Strategy\Find\getRepoPriority
getRepoPriority(IRepository $repository)
Definition
find.php:116
Bitrix\Location\Repository\Location\Strategy\Find\find
find(string $interface, string $method, array $params, int $searchScope)
Definition
find.php:81
Bitrix\Location\Repository\Location\Strategy\Find\findById
findById(int $id, string $languageId, int $searchScope)
Definition
find.php:25
Bitrix\Location\Repository\Location\Strategy\Find\findByExternalId
findByExternalId(string $externalId, string $sourceCode, string $languageId, int $searchScope)
Definition
find.php:31
Bitrix\Location\Repository\Location\Strategy\Find\setLocationRepositories
setLocationRepositories(array $locationRepositories)
Definition
find.php:53
Bitrix\Location\Repository\Location\Strategy\Find\autocomplete
autocomplete(array $params, int $searchScope)
Definition
find.php:42
Bitrix\Location\Repository\Location\Strategy\Find\findByText
findByText(string $text, string $languageId, int $searchScope)
Definition
find.php:37
Bitrix\Location\Repository\Location\Strategy\Find\findParents
findParents(Location $location, string $languageId, int $searchScope)
Definition
find.php:47
Bitrix\Location\Repository\Location\Capability\IFindByExternalId
Definition
ifindbyexternalid.php:12
Bitrix\Location\Repository\Location\Capability\IFindById
Definition
ifindbyid.php:12
Bitrix\Location\Repository\Location\Capability\IFindByText
Definition
ifindbytext.php:12
Bitrix\Location\Repository\Location\Capability\IFindParents
Definition
ifindparents.php:13
Bitrix\Location\Repository\Location\Capability\ISupportAutocomplete
Definition
isupportautocomplete.php:6
Bitrix\Location\Repository\Location\ICache
Definition
icache.php:13
Bitrix\Location\Repository\Location\IDatabase
Definition
idatabase.php:11
Bitrix\Location\Repository\Location\IRepository
Definition
irepository.php:11
Bitrix\Location\Repository\Location\IScope
Definition
iscope.php:6
Bitrix\Location\Entity\Location
Definition
collection.php:3
Bitrix\Location\Repository\Location\Strategy
Definition
base.php:3
modules
location
lib
repository
location
strategy
find.php
Создано системой
1.10.0