1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_mapper\Search; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_mapper\Interfaces\IQueryBuilder; |
7
|
|
|
use kalanis\kw_mapper\MapperException; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Search |
12
|
|
|
* @package kalanis\kw_mapper\Search |
13
|
|
|
* Complex searching |
14
|
|
|
*/ |
15
|
|
|
class Search extends ASearch |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Property is not exact to the value |
19
|
|
|
* @param string $property |
20
|
|
|
* @param string $value |
21
|
|
|
* @throws MapperException |
22
|
|
|
* @return $this |
23
|
|
|
*/ |
24
|
1 |
|
public function notExact(string $property, $value) |
25
|
|
|
{ |
26
|
1 |
|
list($table, $column) = $this->parseProperty($property); |
27
|
1 |
|
$this->connector->notExact($table, $column, $value); |
28
|
1 |
|
return $this; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Property is exact to the value |
33
|
|
|
* @param string $property |
34
|
|
|
* @param string $value |
35
|
|
|
* @throws MapperException |
36
|
|
|
* @return $this |
37
|
|
|
*/ |
38
|
7 |
|
public function exact(string $property, $value) |
39
|
|
|
{ |
40
|
7 |
|
list($table, $column) = $this->parseProperty($property); |
41
|
7 |
|
$this->connector->exact($table, $column, $value); |
42
|
6 |
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $property |
47
|
|
|
* @param string $value |
48
|
|
|
* @param bool $equals |
49
|
|
|
* @throws MapperException |
50
|
|
|
* @return $this |
51
|
|
|
*/ |
52
|
1 |
|
public function from(string $property, $value, bool $equals = true) |
53
|
|
|
{ |
54
|
1 |
|
list($table, $column) = $this->parseProperty($property); |
55
|
1 |
|
$this->connector->from($table, $column, $value, $equals); |
56
|
1 |
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $property |
61
|
|
|
* @param string $value |
62
|
|
|
* @param bool $equals |
63
|
|
|
* @throws MapperException |
64
|
|
|
* @return $this |
65
|
|
|
*/ |
66
|
1 |
|
public function to(string $property, $value, bool $equals = true) |
67
|
|
|
{ |
68
|
1 |
|
list($table, $column) = $this->parseProperty($property); |
69
|
1 |
|
$this->connector->to($table, $column, $value, $equals); |
70
|
1 |
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Property is like value |
75
|
|
|
* @param string $property |
76
|
|
|
* @param string $value |
77
|
|
|
* @throws MapperException |
78
|
|
|
* @return $this |
79
|
|
|
*/ |
80
|
5 |
|
public function like(string $property, $value) |
81
|
|
|
{ |
82
|
5 |
|
list($table, $column) = $this->parseProperty($property); |
83
|
5 |
|
$this->connector->like($table, $column, $value); |
84
|
4 |
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Property is not like value |
89
|
|
|
* @param string $property |
90
|
|
|
* @param string $value |
91
|
|
|
* @throws MapperException |
92
|
|
|
* @return $this |
93
|
|
|
*/ |
94
|
1 |
|
public function notLike(string $property, $value) |
95
|
|
|
{ |
96
|
1 |
|
list($table, $column) = $this->parseProperty($property); |
97
|
1 |
|
$this->connector->notLike($table, $column, $value); |
98
|
1 |
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Property match regexp pattern - DATABASE DEPENDENT |
103
|
|
|
* @param string $property |
104
|
|
|
* @param string $pattern |
105
|
|
|
* @throws MapperException |
106
|
|
|
* @return $this |
107
|
|
|
*/ |
108
|
1 |
|
public function regexp(string $property, string $pattern) |
109
|
|
|
{ |
110
|
1 |
|
list($table, $column) = $this->parseProperty($property); |
111
|
1 |
|
$this->connector->regexp($table, $column, $pattern); |
112
|
1 |
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Property is between values |
117
|
|
|
* @param string $property |
118
|
|
|
* @param string $min |
119
|
|
|
* @param string $max |
120
|
|
|
* @throws MapperException |
121
|
|
|
* @return $this |
122
|
|
|
*/ |
123
|
1 |
|
public function between(string $property, $min, $max) |
124
|
|
|
{ |
125
|
1 |
|
list($table, $column) = $this->parseProperty($property); |
126
|
1 |
|
$this->connector->between($table, $column, $min, $max); |
127
|
1 |
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Property is null |
132
|
|
|
* @param string $property |
133
|
|
|
* @throws MapperException |
134
|
|
|
* @return $this |
135
|
|
|
*/ |
136
|
1 |
|
public function null(string $property) |
137
|
|
|
{ |
138
|
1 |
|
list($table, $column) = $this->parseProperty($property); |
139
|
1 |
|
$this->connector->null($table, $column); |
140
|
1 |
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Property is not null |
145
|
|
|
* @param string $property |
146
|
|
|
* @throws MapperException |
147
|
|
|
* @return $this |
148
|
|
|
*/ |
149
|
1 |
|
public function notNull(string $property) |
150
|
|
|
{ |
151
|
1 |
|
list($table, $column) = $this->parseProperty($property); |
152
|
1 |
|
$this->connector->notNull($table, $column); |
153
|
1 |
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Property is in values |
158
|
|
|
* @param string $property |
159
|
|
|
* @param array<string|int|float> $values |
160
|
|
|
* @throws MapperException |
161
|
|
|
* @return $this |
162
|
|
|
*/ |
163
|
1 |
|
public function in(string $property, array $values) |
164
|
|
|
{ |
165
|
1 |
|
list($table, $column) = $this->parseProperty($property); |
166
|
1 |
|
$this->connector->in($table, $column, $values); |
167
|
1 |
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Property is not in values |
172
|
|
|
* @param string $property |
173
|
|
|
* @param array<string|int|float> $values |
174
|
|
|
* @throws MapperException |
175
|
|
|
* @return $this |
176
|
|
|
*/ |
177
|
1 |
|
public function notIn(string $property, array $values) |
178
|
|
|
{ |
179
|
1 |
|
list($table, $column) = $this->parseProperty($property); |
180
|
1 |
|
$this->connector->notIn($table, $column, $values); |
181
|
1 |
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Need fulfill all conditions |
186
|
|
|
* @return $this |
187
|
|
|
*/ |
188
|
1 |
|
public function useAnd() |
189
|
|
|
{ |
190
|
1 |
|
$this->connector->useAnd(); |
191
|
1 |
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Need fulfill only one condition |
196
|
|
|
* @return $this |
197
|
|
|
*/ |
198
|
1 |
|
public function useOr() |
199
|
|
|
{ |
200
|
1 |
|
$this->connector->useOr(); |
201
|
1 |
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Paging limit |
206
|
|
|
* @param int|null $limit |
207
|
|
|
* @return $this |
208
|
|
|
*/ |
209
|
1 |
|
public function limit(?int $limit) |
210
|
|
|
{ |
211
|
1 |
|
$this->connector->limit($limit); |
212
|
1 |
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Paging offset |
217
|
|
|
* @param int|null $offset |
218
|
|
|
* @return $this |
219
|
|
|
*/ |
220
|
1 |
|
public function offset(?int $offset) |
221
|
|
|
{ |
222
|
1 |
|
$this->connector->offset($offset); |
223
|
1 |
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Add ordering by property |
228
|
|
|
* @param string $property |
229
|
|
|
* @param string $direction |
230
|
|
|
* @throws MapperException |
231
|
|
|
* @return $this |
232
|
|
|
*/ |
233
|
1 |
|
public function orderBy(string $property, string $direction = IQueryBuilder::ORDER_ASC) |
234
|
|
|
{ |
235
|
1 |
|
list($table, $column) = $this->parseProperty($property); |
236
|
1 |
|
$this->connector->orderBy($table, $column, $direction); |
237
|
1 |
|
return $this; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Add grouping by property |
242
|
|
|
* @param string $property |
243
|
|
|
* @throws MapperException |
244
|
|
|
* @return $this |
245
|
|
|
*/ |
246
|
1 |
|
public function groupBy(string $property) |
247
|
|
|
{ |
248
|
1 |
|
list($table, $column) = $this->parseProperty($property); |
249
|
1 |
|
$this->connector->groupBy($table, $column); |
250
|
1 |
|
return $this; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Add child which will be mounted to the results |
255
|
|
|
* @param string $childAlias |
256
|
|
|
* @param string $joinType |
257
|
|
|
* @param string $parentAlias |
258
|
|
|
* @param string $customAlias |
259
|
|
|
* @throws MapperException |
260
|
|
|
* @return $this |
261
|
|
|
*/ |
262
|
5 |
|
public function child(string $childAlias, string $joinType = IQueryBuilder::JOIN_LEFT, string $parentAlias = '', string $customAlias = '') |
263
|
|
|
{ |
264
|
5 |
|
$this->connector->child($childAlias, $joinType, $parentAlias, $customAlias); |
265
|
3 |
|
return $this; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* That child is not set for chosen parent |
270
|
|
|
* @param string $childAlias |
271
|
|
|
* @param string $property |
272
|
|
|
* @throws MapperException |
273
|
|
|
* @return $this |
274
|
|
|
*/ |
275
|
3 |
|
public function childNotExist(string $childAlias, string $property) |
276
|
|
|
{ |
277
|
3 |
|
list($table, $column) = $this->parseProperty($property); |
278
|
3 |
|
$this->connector->childNotExist($childAlias, $table, $column); |
279
|
1 |
|
return $this; |
280
|
|
|
} |
281
|
|
|
} |
282
|
|
|
|