Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
nosqlprimaryselector.php
1
<?php
9
namespace
Bitrix\Main\ORM\Query
;
10
use
Bitrix\Main\ORM\Fields\ExpressionField
;
11
17
class
NosqlPrimarySelector
18
{
25
public
static
function
checkQuery
(\
Bitrix
\Main\Data\
Connection
$connection,
Query
$query)
26
{
27
// check interface
28
if
(!($connection instanceof
INosqlPrimarySelector
))
29
{
30
return
false
;
31
}
32
33
// no expressions in select
34
foreach
($query->
getSelectChains
() as $selectChain)
35
{
36
if
($selectChain->getLastElement()->getValue() instanceof
ExpressionField
)
37
{
38
return
false
;
39
}
40
}
41
42
// skip empty select - useless case for nosql api
43
if
(empty($query->
getSelect
()))
44
{
45
return
false
;
46
}
47
48
// if empty joinmap, group, order and simple filter
49
if
(!count($query->
getJoinMap
()) && !count($query->
getGroupChains
()) && !count($query->
getOrderChains
()) && !count($query->
getHavingChains
()))
50
{
51
$entityPrimary = $query->
getEntity
()->getPrimary();
52
53
// check for primary singularity
54
if
(!is_array($entityPrimary))
55
{
56
// check if only primary is in filter
57
if
(count($query->
getFilterChains
()) == 1 && key($query->
getFilterChains
()) === $entityPrimary)
58
{
59
$passFilter =
true
;
60
61
// check if only equality operations & 1-level filter
62
if
($query->
getFilter
())
63
{
64
foreach
($query->
getFilter
() as $filterElement => $filterValue)
65
{
66
if
(is_numeric($filterElement) && is_array($filterValue))
67
{
68
// filter has subfilters. not ok
69
$passFilter =
false
;
70
break
;
71
}
72
73
// no multiple values for HSPHP
74
if
(is_array($filterValue))
75
{
76
$passFilter =
false
;
77
break
;
78
}
79
80
// skip system keys
81
if
($filterElement ===
'LOGIC'
)
82
{
83
continue
;
84
}
85
86
$operation = substr($filterElement, 0, 1);
87
88
if
($operation !==
'='
)
89
{
90
// only equal operation allowed. not ok
91
$passFilter =
false
;
92
break
;
93
}
94
}
95
}
96
elseif ($query->
getFilterHandler
()->hasConditions())
97
{
98
foreach
($query->
getFilterHandler
()->getConditions() as $condition)
99
{
100
if
($condition->getOperator() !==
'='
|| !is_scalar($condition->getValue()))
101
{
102
$passFilter =
false
;
103
break
;
104
}
105
}
106
}
107
108
109
// fine!
110
if
($passFilter)
111
{
112
return
true
;
113
}
114
}
115
}
116
}
117
118
return
false
;
119
}
120
121
public
static
function
relayQuery
(\
Bitrix
\Main\Data\
Connection
$connection,
Query
$query)
122
{
123
// prepare select
124
$select = array();
125
126
foreach
($query->
getSelectChains
() as $selectChain)
127
{
128
$select[] = $selectChain->getLastElement()->getValue()->getName();
129
}
130
131
// prepare filter
132
$filter = array();
133
134
if
($query->
getFilter
())
135
{
136
foreach
($query->
getFilter
() as $filterElem)
137
{
138
if
(is_array($filterElem))
139
{
140
$filter = array_merge($filter, $filterElem);
141
}
142
else
143
{
144
$filter[] = $filterElem;
145
}
146
}
147
}
148
elseif ($query->
getFilterHandler
()->hasConditions())
149
{
150
foreach
($query->
getFilterHandler
()->getConditions() as $condition)
151
{
152
$filter[] = $condition->getValue();
153
}
154
}
155
156
$result = $connection->getEntityByPrimary($query->
getEntity
(), $filter, $select);
157
158
return
$result;
159
}
160
}
Bitrix\Main\DB\Connection
Definition
connection.php:18
Bitrix\Main\ORM\Fields\ExpressionField
Definition
expressionfield.php:25
Bitrix\Main\ORM\Query\NosqlPrimarySelector
Definition
nosqlprimaryselector.php:18
Bitrix\Main\ORM\Query\NosqlPrimarySelector\relayQuery
static relayQuery(\Bitrix\Main\Data\Connection $connection, Query $query)
Definition
nosqlprimaryselector.php:121
Bitrix\Main\ORM\Query\NosqlPrimarySelector\checkQuery
static checkQuery(\Bitrix\Main\Data\Connection $connection, Query $query)
Definition
nosqlprimaryselector.php:25
Bitrix\Main\ORM\Query\Query
Definition
query.php:118
Bitrix\Main\ORM\Query\Query\getEntity
getEntity()
Definition
query.php:3853
Bitrix\Main\ORM\Query\Query\getOrderChains
getOrderChains()
Definition
query.php:3795
Bitrix\Main\ORM\Query\Query\getFilter
getFilter()
Definition
query.php:370
Bitrix\Main\ORM\Query\Query\getFilterChains
getFilterChains()
Definition
query.php:3787
Bitrix\Main\ORM\Query\Query\getJoinMap
getJoinMap()
Definition
query.php:3824
Bitrix\Main\ORM\Query\Query\getSelect
getSelect()
Definition
query.php:327
Bitrix\Main\ORM\Query\Query\getHavingChains
getHavingChains()
Definition
query.php:3779
Bitrix\Main\ORM\Query\Query\getFilterHandler
getFilterHandler()
Definition
query.php:411
Bitrix\Main\ORM\Query\Query\getSelectChains
getSelectChains()
Definition
query.php:3803
Bitrix\Main\ORM\Query\Query\getGroupChains
getGroupChains()
Definition
query.php:3763
Bitrix\Main\ORM\Query\INosqlPrimarySelector
Definition
inosqlprimaryselector.php:14
Bitrix\Main\ORM\Query
Definition
chain.php:3
Bitrix
modules
main
lib
orm
query
nosqlprimaryselector.php
Создано системой
1.10.0