|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mado\QueryBundle\Queries; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
|
6
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
7
|
|
|
use Mado\QueryBundle\Component\Meta\Exceptions\UnInitializedQueryBuilderException; |
|
8
|
|
|
use Mado\QueryBundle\Dictionary; |
|
9
|
|
|
use Mado\QueryBundle\Exceptions; |
|
10
|
|
|
use Mado\QueryBundle\Queries\Objects\FilterObject; |
|
11
|
|
|
use Mado\QueryBundle\Queries\QueryBuilderOptions; |
|
12
|
|
|
|
|
13
|
|
|
class QueryBuilderFactory extends AbstractQuery |
|
14
|
|
|
{ |
|
15
|
|
|
const DIRECTION_AZ = 'asc'; |
|
16
|
|
|
|
|
17
|
|
|
const DIRECTION_ZA = 'desc'; |
|
18
|
|
|
|
|
19
|
|
|
const DEFAULT_OPERATOR = 'eq'; |
|
20
|
|
|
|
|
21
|
|
|
protected $qBuilder; |
|
22
|
|
|
|
|
23
|
|
|
protected $fields; |
|
24
|
|
|
|
|
25
|
|
|
/** @deprecated since version 2.3 */ |
|
26
|
|
|
protected $andFilters; |
|
27
|
|
|
|
|
28
|
|
|
/** @deprecated since version 2.3 */ |
|
29
|
|
|
protected $orFilters; |
|
30
|
|
|
|
|
31
|
|
|
private $relationEntityAlias; |
|
32
|
|
|
|
|
33
|
|
|
/** @deprecated since version 2.3 */ |
|
34
|
|
|
protected $sorting; |
|
35
|
|
|
|
|
36
|
|
|
private $joins; |
|
37
|
|
|
|
|
38
|
|
|
protected $rel; |
|
39
|
|
|
|
|
40
|
|
|
protected $printing; |
|
41
|
|
|
|
|
42
|
|
|
protected $page; |
|
43
|
|
|
|
|
44
|
|
|
protected $pageLength; |
|
45
|
|
|
|
|
46
|
|
|
/** @deprecated since version 2.3 */ |
|
47
|
|
|
protected $select; |
|
48
|
|
|
|
|
49
|
1 |
|
public function getAvailableFilters() |
|
50
|
|
|
{ |
|
51
|
1 |
|
return array_keys($this->getValueAvailableFilters()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
2 |
|
public function getValueAvailableFilters() |
|
55
|
|
|
{ |
|
56
|
2 |
|
return Dictionary::getOperators(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
9 |
|
public function setFields(array $fields = []) |
|
60
|
|
|
{ |
|
61
|
9 |
|
$this->fields = $fields; |
|
62
|
|
|
|
|
63
|
9 |
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
2 |
|
public function getFields() |
|
67
|
|
|
{ |
|
68
|
2 |
|
if (null === $this->fields) { |
|
69
|
1 |
|
throw new \RuntimeException( |
|
70
|
1 |
|
'Oops! Fields are not defined' |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
1 |
|
return $this->fields; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** @deprecated since version 2.3 */ |
|
78
|
|
|
public function setFilters(array $andFilters = []) |
|
79
|
|
|
{ |
|
80
|
|
|
$this->andFilters = $andFilters; |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** @since version 2.2 */ |
|
86
|
|
|
public function setAndFilters(array $andFilters = []) |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->setFilters($andFilters); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
1 |
|
public function setOrFilters(array $orFilters = []) |
|
92
|
|
|
{ |
|
93
|
1 |
|
$this->orFilters = $orFilters; |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
1 |
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function setSorting(array $sorting = []) |
|
99
|
|
|
{ |
|
100
|
|
|
$this->sorting = $sorting; |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
return $this; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
1 |
|
public function getAndFilters() |
|
106
|
|
|
{ |
|
107
|
1 |
|
return $this->andFilters; |
|
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
1 |
|
public function getOrFilters() |
|
111
|
|
|
{ |
|
112
|
1 |
|
return $this->orFilters; |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
3 |
|
private function noExistsJoin($prevEntityAlias, $currentEntityAlias) |
|
116
|
|
|
{ |
|
117
|
3 |
|
if (null === $this->joins) { |
|
118
|
3 |
|
$this->joins = []; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
3 |
|
$needle = $prevEntityAlias . '_' . $currentEntityAlias; |
|
122
|
|
|
|
|
123
|
3 |
|
return !in_array($needle, $this->joins); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
3 |
|
private function storeJoin($prevEntityAlias, $currentEntityAlias) |
|
127
|
|
|
{ |
|
128
|
3 |
|
$needle = $prevEntityAlias . '_' . $currentEntityAlias; |
|
129
|
3 |
|
$this->joins[$needle] = $needle; |
|
130
|
3 |
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param String $relation Nome della relazione semplice (groups.name) o con embedded (_embedded.groups.name) |
|
134
|
|
|
* @return $this |
|
135
|
|
|
*/ |
|
136
|
3 |
|
public function join(String $relation) |
|
137
|
|
|
{ |
|
138
|
3 |
|
$relation = explode('|', $relation)[0]; |
|
139
|
3 |
|
$relations = [$relation]; |
|
140
|
|
|
|
|
141
|
3 |
|
if (strstr($relation, '_embedded.')) { |
|
142
|
3 |
|
$embeddedFields = explode('.', $relation); |
|
143
|
3 |
|
$this->parser->camelize($embeddedFields[1]); |
|
144
|
|
|
|
|
145
|
|
|
// elimino l'ultimo elemento che dovrebbe essere il nome del campo |
|
146
|
3 |
|
unset($embeddedFields[count($embeddedFields) - 1]); |
|
147
|
|
|
|
|
148
|
|
|
// elimino il primo elemento _embedded |
|
149
|
3 |
|
unset($embeddedFields[0]); |
|
150
|
|
|
|
|
151
|
3 |
|
$relations = $embeddedFields; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
3 |
|
$entityName = $this->getEntityName(); |
|
155
|
3 |
|
$entityAlias = $this->entityAlias; |
|
156
|
|
|
|
|
157
|
3 |
|
foreach ($relations as $relation) { |
|
158
|
|
|
|
|
159
|
3 |
|
$relation = $this->parser->camelize($relation); |
|
160
|
3 |
|
$relationEntityAlias = 'table_' . $relation; |
|
161
|
|
|
|
|
162
|
3 |
|
$metadata = $this->manager->getClassMetadata($entityName); |
|
163
|
|
|
|
|
164
|
3 |
|
if ($metadata->hasAssociation($relation)) { |
|
165
|
|
|
|
|
166
|
3 |
|
$association = $metadata->getAssociationMapping($relation); |
|
167
|
|
|
|
|
168
|
3 |
|
$fieldName = $this->parser->camelize($association['fieldName']); |
|
169
|
|
|
|
|
170
|
3 |
|
if ($this->noExistsJoin($relationEntityAlias, $relation)) { |
|
171
|
3 |
|
$this->qBuilder->join($entityAlias . "." . $fieldName, $relationEntityAlias); |
|
172
|
3 |
|
$this->storeJoin($relationEntityAlias, $relation); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
3 |
|
$entityName = $association['targetEntity']; |
|
176
|
3 |
|
$entityAlias = $relationEntityAlias; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
3 |
|
$this->setRelationEntityAlias($relationEntityAlias); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
3 |
|
return $this; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
5 |
|
public function filter() |
|
186
|
|
|
{ |
|
187
|
5 |
|
if (null === $this->andFilters && null === $this->orFilters) { |
|
|
|
|
|
|
188
|
1 |
|
throw new Exceptions\MissingFiltersException(); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
4 |
|
if (!$this->fields) { |
|
192
|
|
|
throw new \RuntimeException( |
|
193
|
|
|
'Oops! Fields are not defined' |
|
194
|
|
|
); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
4 |
|
if (null !== $this->andFilters) { |
|
|
|
|
|
|
198
|
3 |
|
foreach ($this->andFilters as $filter => $value) { |
|
|
|
|
|
|
199
|
3 |
|
$this->applyFilterAnd( |
|
200
|
3 |
|
Objects\FilterObject::fromRawFilter($filter), |
|
201
|
3 |
|
$value, |
|
202
|
3 |
|
Objects\Value::fromFilter($value) |
|
203
|
|
|
); |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
4 |
|
if (null !== $this->orFilters) { |
|
|
|
|
|
|
208
|
1 |
|
$orFilter = []; |
|
209
|
1 |
|
$orFilter['orCondition'] = null; |
|
210
|
1 |
|
$orFilter['parameters'] = []; |
|
211
|
|
|
|
|
212
|
1 |
|
foreach ($this->orFilters as $filter => $value) { |
|
|
|
|
|
|
213
|
1 |
|
$orFilter = $this->applyFilterOr( |
|
214
|
1 |
|
Objects\FilterObject::fromRawFilter($filter), |
|
215
|
1 |
|
$value, |
|
216
|
1 |
|
$orFilter |
|
217
|
|
|
); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
1 |
|
if ((count($orFilter) > 0) && (null != $orFilter['orCondition'])) { |
|
221
|
1 |
|
$this->qBuilder->andWhere($orFilter['orCondition']); |
|
222
|
|
|
|
|
223
|
1 |
|
foreach ($orFilter['parameters'] as $parameter) { |
|
224
|
1 |
|
$this->qBuilder->setParameter($parameter['field'], $parameter['value']); |
|
225
|
|
|
} |
|
226
|
|
|
} |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
4 |
|
return $this; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
3 |
|
private function applyFilterAnd( |
|
233
|
|
|
Objects\FilterObject $filterObject, |
|
234
|
|
|
$value, |
|
235
|
|
|
Objects\Value $filterValue |
|
236
|
|
|
) { |
|
237
|
3 |
|
$whereCondition = $this->entityAlias . '.' . $filterObject->getFieldName() . ' ' |
|
238
|
3 |
|
. $filterObject->getOperatorMeta(); |
|
239
|
|
|
|
|
240
|
3 |
|
if (in_array($filterObject->getFieldName(), $this->fields)) { |
|
241
|
2 |
|
$salt = '_' . random_int(111, 999); |
|
242
|
|
|
|
|
243
|
2 |
|
if ($filterObject->isListType()) { |
|
244
|
|
|
$whereCondition .= ' (:field_' . $filterObject->getFieldName() . $salt . ')'; |
|
245
|
2 |
|
} elseif ($filterObject->isFieldEqualityType()) { |
|
246
|
|
|
$whereCondition .= ' ' . $this->entityAlias . '.' . $value; |
|
247
|
|
|
} else { |
|
248
|
2 |
|
$whereCondition .= ' :field_' . $filterObject->getFieldName() . $salt; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
2 |
|
$this->qBuilder->andWhere($whereCondition); |
|
252
|
|
|
|
|
253
|
2 |
|
if ($filterObject->haveOperatorSubstitutionPattern()) { |
|
254
|
|
|
if ($filterObject->isListType()) { |
|
255
|
|
|
$value = explode(',', $value); |
|
256
|
|
|
} else { |
|
257
|
|
|
$value = str_replace( |
|
258
|
|
|
'{string}', |
|
259
|
|
|
$value, |
|
260
|
|
|
$filterObject->getOperatorsSubstitutionPattern() |
|
261
|
|
|
); |
|
262
|
|
|
} |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
2 |
|
$this->qBuilder->setParameter('field_' . $filterObject->getFieldName() . $salt, $value); |
|
266
|
|
|
} else { |
|
267
|
1 |
|
$isNotARelation = 0 !== strpos($filterObject->getFieldName(), 'Embedded.'); |
|
268
|
1 |
|
if ($isNotARelation) { |
|
269
|
|
|
$whereCondition .= ' ' . $this->entityAlias . '.' . $value; |
|
270
|
|
|
$this->qBuilder->andWhere($whereCondition); |
|
271
|
|
|
} |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
// controllo se il filtro si riferisce ad una relazione dell'entità quindi devo fare dei join |
|
275
|
|
|
// esempio per users: filtering[_embedded.groups.name|eq]=admin |
|
276
|
3 |
|
if (strstr($filterObject->getRawFilter(), '_embedded.')) { |
|
277
|
|
|
|
|
278
|
1 |
|
$this->join($filterObject->getRawFilter()); |
|
279
|
1 |
|
$relationEntityAlias = $this->getRelationEntityAlias(); |
|
280
|
|
|
|
|
281
|
1 |
|
$embeddedFields = explode('.', $filterObject->getFieldName()); |
|
282
|
1 |
|
$embeddedFieldName = $this->parser->camelize($embeddedFields[count($embeddedFields) - 1]); |
|
283
|
|
|
|
|
284
|
1 |
|
$salt = '_' . random_int(111, 999); |
|
285
|
|
|
|
|
286
|
1 |
|
$whereCondition = $relationEntityAlias . '.' . $embeddedFieldName . ' ' |
|
287
|
1 |
|
. $filterObject->getOperatorMeta(); |
|
288
|
|
|
|
|
289
|
1 |
|
if ($filterObject->isListType()) { |
|
290
|
|
|
$whereCondition .= ' (:field_' . $embeddedFieldName . $salt . ')'; |
|
291
|
|
|
} else { |
|
292
|
1 |
|
$whereCondition .= ' :field_' . $embeddedFieldName . $salt; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
1 |
|
$this->qBuilder->andWhere($whereCondition); |
|
296
|
1 |
|
if ($filterObject->haveOperatorSubstitutionPattern()) { |
|
297
|
1 |
|
if ($filterObject->isListType()) { |
|
298
|
|
|
$value = explode(',', $filterValue->getFilter()); |
|
299
|
|
|
} else { |
|
300
|
1 |
|
$value = str_replace( |
|
301
|
1 |
|
'{string}', |
|
302
|
1 |
|
$value, |
|
303
|
1 |
|
$filterObject->getOperatorsSubstitutionPattern() |
|
304
|
|
|
); |
|
305
|
|
|
} |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
1 |
|
$this->qBuilder->setParameter('field_' . $embeddedFieldName . $salt, $value); |
|
309
|
|
|
} |
|
310
|
3 |
|
} |
|
311
|
|
|
|
|
312
|
1 |
|
private function applyFilterOr( |
|
313
|
|
|
Objects\FilterObject $filterObject, |
|
314
|
|
|
$value, |
|
315
|
|
|
$orCondition |
|
316
|
|
|
) { |
|
317
|
1 |
|
$whereCondition = $this->entityAlias . '.' . $filterObject->getFieldName() . ' ' |
|
318
|
1 |
|
. $filterObject->getOperatorMeta(); |
|
319
|
|
|
|
|
320
|
|
|
// controllo se il filtro che mi arriva dalla richiesta è una proprietà di questa entità |
|
321
|
|
|
// esempio per users: filtering[username|contains]=mado |
|
322
|
1 |
|
if (in_array($filterObject->getFieldName(), $this->fields)) { |
|
323
|
|
|
$salt = '_' . random_int(111, 999); |
|
324
|
|
|
|
|
325
|
|
|
if ($filterObject->isListType()) { |
|
326
|
|
|
$whereCondition .= ' (:field_' . $filterObject->getFieldName() . $salt . ')'; |
|
327
|
|
|
} else if ($filterObject->isFieldEqualityType()) { |
|
328
|
|
|
$whereCondition .= $this->entityAlias . '.' . $value; |
|
329
|
|
|
} else { |
|
330
|
|
|
$whereCondition .= ' :field_' . $filterObject->getFieldName() . $salt; |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
if (null != $orCondition['orCondition']) { |
|
334
|
|
|
$orCondition['orCondition'] .= ' OR ' . $whereCondition; |
|
335
|
|
|
} else { |
|
336
|
|
|
$orCondition['orCondition'] = $whereCondition; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
if ($filterObject->haveOperatorSubstitutionPattern()) { |
|
340
|
|
|
if ($filterObject->isListType()) { |
|
341
|
|
|
$value = explode(',', $value); |
|
342
|
|
|
} else { |
|
343
|
|
|
$value = str_replace( |
|
344
|
|
|
'{string}', |
|
345
|
|
|
$value, |
|
346
|
|
|
$filterObject->getOperatorsSubstitutionPattern() |
|
347
|
|
|
); |
|
348
|
|
|
} |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
$orCondition['parameters'][] = [ |
|
352
|
|
|
'field' => 'field_' . $filterObject->getFieldName() . $salt, |
|
353
|
|
|
'value' => $value |
|
354
|
|
|
]; |
|
355
|
|
|
} else { |
|
356
|
1 |
|
$isNotARelation = 0 !== strpos($filterObject->getFieldName(), 'Embedded.'); |
|
357
|
1 |
|
if ($isNotARelation) { |
|
358
|
|
|
$whereCondition .= ' ' . $this->entityAlias . '.' . $value; |
|
359
|
|
|
if (null != $orCondition['orCondition']) { |
|
360
|
|
|
$orCondition['orCondition'] .= ' OR ' . $whereCondition; |
|
361
|
|
|
} else { |
|
362
|
|
|
$orCondition['orCondition'] = $whereCondition; |
|
363
|
|
|
} |
|
364
|
|
|
} |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
// controllo se il filtro si riferisce ad una relazione dell'entità quindi devo fare dei join |
|
368
|
|
|
// esempio per users: filtering[_embedded.groups.name|eq]=admin |
|
369
|
1 |
|
if (strstr($filterObject->getRawFilter(), '_embedded.')) { |
|
370
|
|
|
|
|
371
|
1 |
|
$this->join($filterObject->getRawFilter()); |
|
372
|
1 |
|
$relationEntityAlias = $this->getRelationEntityAlias(); |
|
373
|
|
|
|
|
374
|
1 |
|
$embeddedFields = explode('.', $filterObject->getFieldName()); |
|
375
|
1 |
|
$embeddableFieldName = $this->parser->camelize($embeddedFields[count($embeddedFields) - 1]); |
|
376
|
|
|
|
|
377
|
1 |
|
$salt = '_' . random_int(111, 999); |
|
378
|
|
|
|
|
379
|
1 |
|
$whereCondition = $relationEntityAlias . '.' . $embeddableFieldName . ' ' |
|
380
|
1 |
|
. $filterObject->getOperatorMeta(); |
|
381
|
|
|
|
|
382
|
1 |
|
if ($filterObject->isListType()) { |
|
383
|
|
|
$whereCondition .= ' (:field_' . $embeddableFieldName . $salt . ')'; |
|
384
|
|
|
} else { |
|
385
|
1 |
|
$whereCondition .= ' :field_' . $embeddableFieldName . $salt; |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
1 |
|
if (null != $orCondition['orCondition']) { |
|
389
|
1 |
|
$orCondition['orCondition'] .= ' OR ' . $whereCondition; |
|
390
|
|
|
} else { |
|
391
|
1 |
|
$orCondition['orCondition'] = $whereCondition; |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
1 |
|
if ($filterObject->haveOperatorSubstitutionPattern()) { |
|
395
|
1 |
|
if ($filterObject->isListType()) { |
|
396
|
|
|
$value = explode(',', $value); |
|
397
|
|
|
} else { |
|
398
|
1 |
|
$value = str_replace( |
|
399
|
1 |
|
'{string}', |
|
400
|
1 |
|
$value, |
|
401
|
1 |
|
$filterObject->getOperatorsSubstitutionPattern() |
|
402
|
|
|
); |
|
403
|
|
|
} |
|
404
|
|
|
} |
|
405
|
|
|
|
|
406
|
1 |
|
$orCondition['parameters'][] = [ |
|
407
|
1 |
|
'field' => 'field_' . $embeddableFieldName . $salt, |
|
408
|
1 |
|
'value' => $value |
|
409
|
|
|
]; |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
1 |
|
return $orCondition; |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
5 |
|
public function sort() |
|
416
|
|
|
{ |
|
417
|
5 |
|
if (!$this->fields) { |
|
418
|
1 |
|
throw new \RuntimeException( |
|
419
|
1 |
|
'Oops! Fields are not defined' |
|
420
|
|
|
); |
|
421
|
|
|
} |
|
422
|
|
|
|
|
423
|
4 |
|
if (null === $this->sorting) { |
|
|
|
|
|
|
424
|
1 |
|
throw new \RuntimeException( |
|
425
|
1 |
|
'Oops! Sorting is not defined' |
|
426
|
|
|
); |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
3 |
|
foreach ($this->sorting as $sort => $val) { |
|
|
|
|
|
|
430
|
3 |
|
$val = strtolower($val); |
|
431
|
|
|
|
|
432
|
3 |
|
$fieldName = $this->parser->camelize($sort); |
|
433
|
|
|
|
|
434
|
3 |
|
if (in_array($fieldName, $this->fields)) { |
|
435
|
2 |
|
$direction = ($val === self::DIRECTION_AZ) ? self::DIRECTION_AZ : self::DIRECTION_ZA; |
|
436
|
2 |
|
$this->ensureQueryBuilderIsDefined(); |
|
437
|
1 |
|
$this->qBuilder->addOrderBy($this->entityAlias .'.'. $fieldName, $direction); |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
2 |
|
if (strstr($sort, '_embedded.')) { |
|
441
|
1 |
|
$this->join($sort); |
|
442
|
1 |
|
$relationEntityAlias = $this->getRelationEntityAlias(); |
|
443
|
|
|
|
|
444
|
1 |
|
$embeddedFields = explode('.', $sort); |
|
445
|
1 |
|
$fieldName = $this->parser->camelize($embeddedFields[2]); |
|
446
|
1 |
|
$direction = ($val === self::DIRECTION_AZ) ? self::DIRECTION_AZ : self::DIRECTION_ZA; |
|
447
|
|
|
|
|
448
|
2 |
|
$this->qBuilder->addOrderBy($relationEntityAlias . '.' . $fieldName, $direction); |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
} |
|
452
|
|
|
|
|
453
|
2 |
|
return $this; |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
5 |
|
public function getQueryBuilder() :QueryBuilder |
|
457
|
|
|
{ |
|
458
|
5 |
|
if (!$this->qBuilder) { |
|
459
|
1 |
|
throw new UnInitializedQueryBuilderException(); |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
4 |
|
return $this->qBuilder; |
|
463
|
|
|
} |
|
464
|
|
|
|
|
465
|
3 |
|
private function setRelationEntityAlias(string $relationEntityAlias) |
|
466
|
|
|
{ |
|
467
|
3 |
|
$this->relationEntityAlias = $relationEntityAlias; |
|
468
|
3 |
|
} |
|
469
|
|
|
|
|
470
|
3 |
|
private function getRelationEntityAlias() |
|
471
|
|
|
{ |
|
472
|
3 |
|
return $this->relationEntityAlias; |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
/** @deprecated since version 2.3 */ |
|
476
|
|
|
public function setRel($rel) |
|
477
|
|
|
{ |
|
478
|
|
|
$this->rel = $rel; |
|
479
|
|
|
|
|
480
|
|
|
return $this; |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
/** @deprecated since version 2.3 */ |
|
484
|
|
|
public function getRel() |
|
485
|
|
|
{ |
|
486
|
|
|
return $this->rel; |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
public function setPrinting($printing) |
|
490
|
|
|
{ |
|
491
|
|
|
$this->printing = $printing; |
|
492
|
|
|
|
|
493
|
|
|
return $this; |
|
494
|
|
|
} |
|
495
|
|
|
|
|
496
|
|
|
public function getPrinting() |
|
497
|
|
|
{ |
|
498
|
|
|
return $this->printing; |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
2 |
|
public function setPage(int $page) |
|
502
|
|
|
{ |
|
503
|
2 |
|
$this->page = $page; |
|
504
|
|
|
|
|
505
|
2 |
|
return $this; |
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
1 |
|
public function getPage() :int |
|
509
|
|
|
{ |
|
510
|
1 |
|
return $this->page; |
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
2 |
|
public function setPageLength($pageLength) |
|
514
|
|
|
{ |
|
515
|
2 |
|
$this->pageLength = $pageLength; |
|
516
|
|
|
|
|
517
|
2 |
|
return $this; |
|
518
|
|
|
} |
|
519
|
|
|
|
|
520
|
1 |
|
public function getPageLength() |
|
521
|
|
|
{ |
|
522
|
1 |
|
return $this->pageLength; |
|
523
|
|
|
} |
|
524
|
|
|
|
|
525
|
|
|
/** @deprecated since version 2.2 */ |
|
526
|
2 |
|
public function setSelect($select) : QueryBuilderFactory |
|
527
|
|
|
{ |
|
528
|
2 |
|
$this->options = $this->options->with('select', $select); |
|
529
|
2 |
|
$this->select = $this->options->get('select'); |
|
|
|
|
|
|
530
|
|
|
|
|
531
|
2 |
|
return $this; |
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
|
/** @deprecated since version 2.2 */ |
|
535
|
1 |
|
public function getSelect() |
|
536
|
|
|
{ |
|
537
|
1 |
|
return $this->options->get('select'); |
|
538
|
|
|
} |
|
539
|
|
|
|
|
540
|
|
|
/** @since version 2.2 */ |
|
541
|
13 |
|
public function setOptions(QueryBuilderOptions $options) |
|
542
|
|
|
{ |
|
543
|
13 |
|
$this->options = $options; |
|
544
|
|
|
|
|
545
|
|
|
/** @deprecated since version 2.2 */ |
|
546
|
13 |
|
$this->andFilters = $this->options->get(QueryBuilderOptions::FILTER_AND); |
|
|
|
|
|
|
547
|
13 |
|
$this->orFilters = $this->options->get('orFilters'); |
|
|
|
|
|
|
548
|
13 |
|
$this->sorting = $this->options->get('sorting'); |
|
|
|
|
|
|
549
|
13 |
|
$this->printing = $this->options->get('printing'); |
|
550
|
13 |
|
} |
|
551
|
|
|
|
|
552
|
|
|
/** @since version 2.2 */ |
|
553
|
2 |
|
public function getOptions() : QueryBuilderOptions |
|
554
|
|
|
{ |
|
555
|
2 |
|
return $this->options; |
|
556
|
|
|
} |
|
557
|
|
|
} |
|
558
|
|
|
|
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.