1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mado\QueryBundle\Queries; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
|
|
|
6
|
|
|
|
7
|
|
|
class QueryBuilderFactory extends AbstractQuery |
8
|
|
|
{ |
9
|
|
|
const DIRECTION_AZ = 'asc'; |
10
|
|
|
|
11
|
|
|
const DIRECTION_ZA = 'desc'; |
12
|
|
|
|
13
|
|
|
const DEFAULT_OPERATOR = 'eq'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var QueryBuilder |
17
|
|
|
*/ |
18
|
|
|
protected $qBuilder; |
19
|
|
|
|
20
|
|
|
protected $fields; |
21
|
|
|
|
22
|
|
|
protected $filtering; |
23
|
|
|
|
24
|
|
|
protected $orFiltering; |
25
|
|
|
|
26
|
|
|
protected $relationEntityAlias; |
27
|
|
|
|
28
|
|
|
protected $sorting; |
29
|
|
|
|
30
|
|
|
protected $joins; |
31
|
|
|
|
32
|
|
|
protected $rel; |
33
|
|
|
|
34
|
|
|
protected $printing; |
35
|
|
|
|
36
|
|
|
protected $page; |
37
|
|
|
|
38
|
|
|
protected $pageLength; |
39
|
|
|
|
40
|
|
|
protected $select; |
41
|
|
|
|
42
|
|
|
/** @todo move this file in configuration */ |
43
|
|
|
/** @todo type number|text */ |
44
|
|
|
private static $operatorMap = [ |
45
|
|
|
//'eq' => [ |
46
|
|
|
//'filtro' => '=', |
47
|
|
|
//'tipo' => 'data|numero|stringa', |
48
|
|
|
//'meta' => '%{foo}%' |
49
|
|
|
//], |
50
|
|
|
'eq' => [ |
51
|
|
|
'meta' => '=', |
52
|
|
|
], |
53
|
|
|
'neq' => [ |
54
|
|
|
'meta' => '!=', |
55
|
|
|
], |
56
|
|
|
'gt' => [ |
57
|
|
|
'meta' => '>', |
58
|
|
|
], |
59
|
|
|
'gte' => [ |
60
|
|
|
'meta' => '>=', |
61
|
|
|
], |
62
|
|
|
'lt' => [ |
63
|
|
|
'meta' => '<', |
64
|
|
|
], |
65
|
|
|
'lte' => [ |
66
|
|
|
'meta' => '<=', |
67
|
|
|
], |
68
|
|
|
'startswith' => [ |
69
|
|
|
'meta' => 'LIKE', |
70
|
|
|
'substitution_pattern' => '{string}%' |
71
|
|
|
], |
72
|
|
|
'contains' => [ |
73
|
|
|
'meta' => 'LIKE', |
74
|
|
|
'substitution_pattern' => '%{string}%' |
75
|
|
|
], |
76
|
1 |
|
'notcontains' => [ |
77
|
|
|
'meta' => 'NOT LIKE', |
78
|
1 |
|
'substitution_pattern' => '%{string}%' |
79
|
|
|
], |
80
|
|
|
'endswith' => [ |
81
|
|
|
'meta' => 'LIKE', |
82
|
|
|
'substitution_pattern' => '%{string}' |
83
|
|
|
], |
84
|
|
|
'list' => [ |
85
|
|
|
'meta' => 'IN', |
86
|
|
|
'substitution_pattern' => '({string})', |
87
|
|
|
], |
88
|
|
|
'field_eq' => [ |
89
|
|
|
'meta' => '=', |
90
|
|
|
], |
91
|
|
|
]; |
92
|
|
|
|
93
|
|
|
public function getAvailableFilters() |
94
|
|
|
{ |
95
|
|
|
return array_keys(static::$operatorMap); |
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function setFields(array $fields = []) |
99
|
|
|
{ |
100
|
|
|
$this->fields = $fields; |
101
|
|
|
|
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function getFields() |
106
|
|
|
{ |
107
|
|
|
if (null === $this->fields) { |
108
|
|
|
throw new \RuntimeException( |
109
|
|
|
'Oops! Fields are not defined' |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return $this->fields; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function setFilters(array $filtering = []) |
117
|
|
|
{ |
118
|
|
|
$this->filtering = $filtering; |
119
|
|
|
|
120
|
|
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function setOrFilters(array $orFiltering = []) |
124
|
|
|
{ |
125
|
|
|
$this->orFiltering = $orFiltering; |
126
|
|
|
|
127
|
|
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function setSorting(array $sorting = []) |
131
|
|
|
{ |
132
|
|
|
$this->sorting = $sorting; |
133
|
|
|
|
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function getFilters() |
138
|
|
|
{ |
139
|
|
|
return $this->filtering; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function getOrFilters() |
143
|
|
|
{ |
144
|
|
|
return $this->orFiltering; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
private function noExistsJoin($prevEntityAlias, $currentEntityAlias) |
148
|
|
|
{ |
149
|
|
|
if (null === $this->joins) { |
150
|
|
|
$this->joins = []; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
$needle = $prevEntityAlias . "_" . $currentEntityAlias; |
154
|
|
|
|
155
|
|
|
return ! in_array($needle, $this->joins); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
private function storeJoin($prevEntityAlias, $currentEntityAlias) |
159
|
|
|
{ |
160
|
|
|
$needle = $prevEntityAlias . "_" . $currentEntityAlias; |
161
|
|
|
$this->joins[$needle] = $needle; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param String $relation Nome della relazione semplice (groups.name) o con embedded (_embedded.groups.name) |
166
|
|
|
* @return $this |
167
|
|
|
*/ |
168
|
|
|
public function join(String $relation) |
169
|
|
|
{ |
170
|
|
|
$relation = explode('|', $relation)[0]; |
171
|
|
|
$relations = [$relation]; |
172
|
|
|
|
173
|
|
|
if (strstr($relation, '_embedded.')) { |
174
|
|
|
$embeddedFields = explode('.', $relation); |
175
|
|
|
$relation = $this->parser->camelize($embeddedFields[1]); |
|
|
|
|
176
|
|
|
|
177
|
|
|
// elimino l'ultimo elemento che dovrebbe essere il nome del campo |
178
|
|
|
unset($embeddedFields[count($embeddedFields) - 1]); |
179
|
|
|
|
180
|
|
|
// elimino il primo elemento _embedded |
181
|
|
|
unset($embeddedFields[0]); |
182
|
|
|
|
183
|
|
|
$relations = $embeddedFields; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
$entityName = $this->getEntityName(); |
187
|
|
|
$entityAlias = $this->entityAlias; |
188
|
|
|
|
189
|
|
|
foreach ($relations as $relation) { |
190
|
|
|
|
191
|
|
|
$relation = $this->parser->camelize($relation); |
192
|
|
|
$relationEntityAlias = 'table_' . $relation; |
193
|
|
|
|
194
|
|
|
$metadata = $this->manager->getClassMetadata($entityName); |
195
|
|
|
|
196
|
|
|
if ($metadata->hasAssociation($relation)) { |
197
|
|
|
|
198
|
|
|
$association = $metadata->getAssociationMapping($relation); |
199
|
|
|
|
200
|
|
|
$fieldName = $this->parser->camelize($association['fieldName']); |
201
|
|
|
|
202
|
|
|
if ($this->noExistsJoin($relationEntityAlias, $relation)) { |
203
|
|
|
|
204
|
|
|
$this->qBuilder |
205
|
|
|
->join($entityAlias . "." . $fieldName, $relationEntityAlias); |
206
|
|
|
|
207
|
|
|
$this->storeJoin($relationEntityAlias, $relation); |
208
|
|
|
} |
209
|
|
|
$entityName = $association['targetEntity']; |
210
|
|
|
$entityAlias = $relationEntityAlias; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
$this->setRelationEntityAlias($relationEntityAlias); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function filter() |
220
|
|
|
{ |
221
|
|
|
if (null === $this->filtering) { |
222
|
|
|
throw new \RuntimeException( |
223
|
|
|
'Oops! Filtering is not defined' |
224
|
|
|
); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
if (!$this->fields) { |
228
|
|
|
throw new \RuntimeException( |
229
|
|
|
'Oops! Fields are not defined' |
230
|
|
|
); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
foreach ($this->filtering as $filter => $value) { |
234
|
|
|
$this->applyFilterAnd($filter, $value); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
if (null !== $this->orFiltering) { |
238
|
|
|
$orFilter = []; |
239
|
|
|
$orFilter['orCondition'] = null; |
240
|
|
|
$orFilter['parameters'] = []; |
241
|
|
|
|
242
|
|
|
foreach ($this->orFiltering as $filter => $value) { |
243
|
|
|
$orFilter = $this->applyFilterOr($filter, $value, $orFilter); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
if ((count($orFilter) > 0) && ($orFilter['orCondition'] != null)) { |
247
|
|
|
$this->qBuilder->andWhere($orFilter['orCondition']); |
248
|
|
|
|
249
|
|
|
foreach ($orFilter['parameters'] as $parameter) { |
250
|
|
|
$this->qBuilder->setParameter($parameter['field'], $parameter['value']); |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
return $this; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
private function applyFilterAnd($filter, $value) |
259
|
|
|
{ |
260
|
|
|
$whereCondition = null; |
261
|
|
|
$filterAndOperator = explode('|',$filter); |
262
|
|
|
|
263
|
|
|
$fieldName = $filterAndOperator[0]; |
264
|
|
|
$fieldName = $this->parser->camelize($fieldName); |
265
|
|
|
|
266
|
|
|
$operator = self::$operatorMap[self::DEFAULT_OPERATOR]; |
267
|
|
|
if(isset($filterAndOperator[1])){ |
268
|
|
|
$operator = self::$operatorMap[$filterAndOperator[1]]; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
// controllo se il filtro che mi arriva dalla richiesta è una proprietà di questa entità |
272
|
|
|
// esempio per users: filtering[username|contains]=mado |
273
|
|
|
if (in_array($fieldName, $this->fields)) { |
274
|
|
|
|
275
|
|
|
$salt = ''; |
276
|
|
View Code Duplication |
foreach ($this->qBuilder->getParameters() as $parameter) { |
|
|
|
|
277
|
|
|
if ($parameter->getName() == 'field_' . $fieldName) { |
278
|
|
|
$salt = '_' . rand(111, 999); |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
// filtering[foo|bar] |
283
|
|
|
// $filterAndOperator[0] = 'foo' |
284
|
|
|
// $filterAndOperator[1] = 'bar' |
285
|
|
View Code Duplication |
if (isset($filterAndOperator[1])) { |
|
|
|
|
286
|
|
|
if ('list' == $filterAndOperator[1]) { |
287
|
|
|
$whereCondition = $this->entityAlias.'.'.$fieldName.' '.$operator['meta'].' (:field_'.$fieldName . $salt . ')'; |
288
|
|
|
} else if ('field_eq' == $filterAndOperator[1]) { |
289
|
|
|
$whereCondition = |
290
|
|
|
$this->entityAlias . '.' . $fieldName . ' '. |
291
|
|
|
$operator['meta'] . '' . |
292
|
|
|
$this->entityAlias . '.' . $value |
293
|
|
|
; |
294
|
|
|
//} else { |
295
|
|
|
//throw new \RuntimeException( |
296
|
|
|
//'Oops! Eccezzione' |
297
|
|
|
//); |
298
|
|
|
} else { |
299
|
|
|
$whereCondition = $this->entityAlias.'.'.$fieldName.' '.$operator['meta'].' :field_'.$fieldName . $salt; |
300
|
|
|
} |
301
|
|
|
} else { |
302
|
|
|
$whereCondition = $this->entityAlias.'.'.$fieldName.' = :field_'.$fieldName . $salt; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
$this->qBuilder->andWhere($whereCondition); |
306
|
|
|
|
307
|
|
View Code Duplication |
if (isset($operator['substitution_pattern'])) { |
|
|
|
|
308
|
|
|
if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) { |
309
|
|
|
$value = explode(',', $value); |
310
|
|
|
} else { |
311
|
|
|
$value = str_replace( |
312
|
|
|
'{string}', |
313
|
|
|
$value, |
314
|
|
|
$operator['substitution_pattern'] |
315
|
|
|
); |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
$this->qBuilder->setParameter('field_' . $fieldName . $salt, $value); |
320
|
|
|
} else { |
321
|
|
|
$isNotARelation = 0 !== strpos($fieldName, 'Embedded.'); |
322
|
|
|
if ($isNotARelation) { |
323
|
|
|
$whereCondition = $this->entityAlias.'.'.$fieldName.' '.$operator['meta'].' ' . $this->entityAlias . '.' . $value; |
324
|
|
|
$this->qBuilder->andWhere($whereCondition); |
325
|
|
|
} |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
// controllo se il filtro si riferisce ad una relazione dell'entità quindi devo fare dei join |
329
|
|
|
// esempio per users: filtering[_embedded.groups.name|eq]=admin |
330
|
|
|
if (strstr($filter, '_embedded.')) { |
331
|
|
|
|
332
|
|
|
$this->join($filter); |
333
|
|
|
$relationEntityAlias = $this->getRelationEntityAlias(); |
334
|
|
|
|
335
|
|
|
$embeddedFields = explode('.', $fieldName); |
336
|
|
|
$fieldName = $this->parser->camelize($embeddedFields[count($embeddedFields)-1]); |
337
|
|
|
|
338
|
|
|
$salt = ''; |
339
|
|
View Code Duplication |
foreach ($this->qBuilder->getParameters() as $parameter) { |
|
|
|
|
340
|
|
|
if ($parameter->getName() == 'field_' . $fieldName) { |
341
|
|
|
$salt = '_' . rand(111, 999); |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
|
345
|
|
View Code Duplication |
if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) { |
|
|
|
|
346
|
|
|
$whereCondition = $relationEntityAlias.'.'.$fieldName.' '.$operator['meta'].' (:field_'.$fieldName . $salt . ')'; |
347
|
|
|
} else { |
348
|
|
|
$whereCondition = $relationEntityAlias.'.'.$fieldName.' '.$operator['meta'].' :field_'.$fieldName . $salt; |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
$this->qBuilder->andWhere($whereCondition); |
352
|
|
View Code Duplication |
if (isset($operator['substitution_pattern'])) { |
|
|
|
|
353
|
|
|
if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) { |
354
|
|
|
$value = explode(',', $value); |
|
|
|
|
355
|
|
|
} else { |
356
|
|
|
$value = str_replace( |
357
|
|
|
'{string}', |
358
|
|
|
$value, |
359
|
|
|
$operator['substitution_pattern'] |
360
|
|
|
); |
361
|
|
|
} |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
$this->qBuilder->setParameter('field_' . $fieldName . $salt, $value); |
365
|
|
|
} |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
private function applyFilterOr($filter, $value, $orCondition) |
369
|
|
|
{ |
370
|
|
|
$whereCondition = null; |
371
|
|
|
$filterAndOperator = explode('|',$filter); |
372
|
|
|
|
373
|
|
|
$fieldName = $filterAndOperator[0]; |
374
|
|
|
$fieldName = $this->parser->camelize($fieldName); |
375
|
|
|
|
376
|
|
|
$operator = self::$operatorMap[self::DEFAULT_OPERATOR]; |
377
|
|
|
if(isset($filterAndOperator[1])){ |
378
|
|
|
$operator = self::$operatorMap[$filterAndOperator[1]]; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
// controllo se il filtro che mi arriva dalla richiesta è una proprietà di questa entità |
382
|
|
|
// esempio per users: filtering[username|contains]=mado |
383
|
|
|
if (in_array($fieldName, $this->fields)) { |
384
|
|
|
|
385
|
|
|
$salt = ''; |
386
|
|
View Code Duplication |
foreach ($this->qBuilder->getParameters() as $parameter) { |
|
|
|
|
387
|
|
|
if ($parameter->getName() == 'field_' . $fieldName) { |
388
|
|
|
$salt = '_' . rand(111, 999); |
389
|
|
|
} |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
if ($salt == '') { |
393
|
|
|
$salt = '_' . rand(111, 999); |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
// filtering[foo|bar] |
397
|
|
|
// $filterAndOperator[0] = 'foo' |
398
|
|
|
// $filterAndOperator[1] = 'bar' |
399
|
|
View Code Duplication |
if (isset($filterAndOperator[1])) { |
|
|
|
|
400
|
|
|
if ('list' == $filterAndOperator[1]) { |
401
|
|
|
$whereCondition = $this->entityAlias.'.'.$fieldName.' '.$operator['meta'].' (:field_'.$fieldName . $salt . ')'; |
402
|
|
|
} else if ('field_eq' == $filterAndOperator[1]) { |
403
|
|
|
$whereCondition = |
404
|
|
|
$this->entityAlias . '.' . $fieldName . ' '. |
405
|
|
|
$operator['meta'] . '' . |
406
|
|
|
$this->entityAlias . '.' . $value |
407
|
|
|
; |
408
|
|
|
//} else { |
409
|
|
|
//throw new \RuntimeException( |
410
|
|
|
//'Oops! Eccezzione' |
411
|
|
|
//); |
412
|
|
|
} else { |
413
|
|
|
$whereCondition = $this->entityAlias.'.'.$fieldName.' '.$operator['meta'].' :field_'.$fieldName . $salt; |
414
|
|
|
} |
415
|
|
|
} else { |
416
|
|
|
$whereCondition = $this->entityAlias.'.'.$fieldName.' = :field_'.$fieldName . $salt; |
417
|
|
|
} |
418
|
|
|
|
419
|
|
View Code Duplication |
if ($orCondition['orCondition'] != null) { |
|
|
|
|
420
|
|
|
$orCondition['orCondition'] .= ' OR ' . $whereCondition; |
421
|
|
|
} else { |
422
|
|
|
$orCondition['orCondition'] = $whereCondition; |
423
|
|
|
} |
424
|
|
|
|
425
|
|
View Code Duplication |
if (isset($operator['substitution_pattern'])) { |
|
|
|
|
426
|
|
|
if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) { |
427
|
|
|
$value = explode(',', $value); |
428
|
|
|
} else { |
429
|
|
|
$value = str_replace( |
430
|
|
|
'{string}', |
431
|
|
|
$value, |
432
|
|
|
$operator['substitution_pattern'] |
433
|
|
|
); |
434
|
|
|
} |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
$orCondition['parameters'][] = [ |
438
|
|
|
'field' => 'field_' . $fieldName . $salt, |
439
|
|
|
'value' => $value |
440
|
|
|
]; |
441
|
|
|
} else { |
442
|
|
|
$isNotARelation = 0 !== strpos($fieldName, 'Embedded.'); |
443
|
|
|
if ($isNotARelation) { |
444
|
|
|
$whereCondition = $this->entityAlias.'.'.$fieldName.' '.$operator['meta'].' ' . $this->entityAlias . '.' . $value; |
445
|
|
View Code Duplication |
if ($orCondition['orCondition'] != null) { |
|
|
|
|
446
|
|
|
$orCondition['orCondition'] .= ' OR ' . $whereCondition; |
447
|
|
|
} else { |
448
|
|
|
$orCondition['orCondition'] = $whereCondition; |
449
|
|
|
} |
450
|
|
|
} |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
// controllo se il filtro si riferisce ad una relazione dell'entità quindi devo fare dei join |
454
|
|
|
// esempio per users: filtering[_embedded.groups.name|eq]=admin |
455
|
|
|
if (strstr($filter, '_embedded.')) { |
456
|
|
|
|
457
|
|
|
$this->join($filter); |
458
|
|
|
$relationEntityAlias = $this->getRelationEntityAlias(); |
459
|
|
|
|
460
|
|
|
$embeddedFields = explode('.', $fieldName); |
461
|
|
|
$fieldName = $this->parser->camelize($embeddedFields[count($embeddedFields)-1]); |
462
|
|
|
|
463
|
|
|
$salt = ''; |
464
|
|
View Code Duplication |
foreach ($this->qBuilder->getParameters() as $parameter) { |
|
|
|
|
465
|
|
|
if ($parameter->getName() == 'field_' . $fieldName) { |
466
|
|
|
$salt = '_' . rand(111, 999); |
467
|
|
|
} |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
if ($salt == '') { |
471
|
|
|
$salt = '_' . rand(111, 999); |
472
|
|
|
} |
473
|
|
|
|
474
|
|
View Code Duplication |
if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) { |
|
|
|
|
475
|
|
|
$whereCondition = $relationEntityAlias.'.'.$fieldName.' '.$operator['meta'].' (:field_'.$fieldName . $salt . ')'; |
476
|
|
|
} else { |
477
|
|
|
$whereCondition = $relationEntityAlias.'.'.$fieldName.' '.$operator['meta'].' :field_'.$fieldName . $salt; |
478
|
|
|
} |
479
|
|
|
|
480
|
|
View Code Duplication |
if ($orCondition['orCondition'] != null) { |
|
|
|
|
481
|
|
|
$orCondition['orCondition'] .= ' OR ' . $whereCondition; |
482
|
|
|
} else { |
483
|
|
|
$orCondition['orCondition'] = $whereCondition; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
View Code Duplication |
if (isset($operator['substitution_pattern'])) { |
|
|
|
|
487
|
|
|
if (isset($filterAndOperator[1]) && 'list' == $filterAndOperator[1]) { |
488
|
|
|
$value = explode(',', $value); |
|
|
|
|
489
|
|
|
} else { |
490
|
|
|
$value = str_replace( |
491
|
|
|
'{string}', |
492
|
|
|
$value, |
493
|
|
|
$operator['substitution_pattern'] |
494
|
|
|
); |
495
|
|
|
} |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
$orCondition['parameters'][] = [ |
499
|
|
|
'field' => 'field_' . $fieldName . $salt, |
500
|
|
|
'value' => $value |
501
|
|
|
]; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
return $orCondition; |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
public function sort() |
508
|
|
|
{ |
509
|
|
|
if (!$this->fields) { |
510
|
|
|
throw new \RuntimeException( |
511
|
|
|
'Oops! Fields are not defined' |
512
|
|
|
); |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
if (null === $this->sorting) { |
516
|
|
|
throw new \RuntimeException( |
517
|
|
|
'Oops! Sorting is not defined' |
518
|
|
|
); |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
foreach ($this->sorting as $sort => $val) { |
522
|
|
|
$val = strtolower($val); |
523
|
|
|
|
524
|
|
|
$fieldName = $this->parser->camelize($sort); |
525
|
|
|
|
526
|
|
|
if (in_array($fieldName, $this->fields)) { |
527
|
|
|
$direction = ($val === self::DIRECTION_AZ) ? self::DIRECTION_AZ : self::DIRECTION_ZA; |
528
|
|
|
$this->qBuilder->addOrderBy($this->entityAlias .'.'. $fieldName, $direction); |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
if (strstr($sort, '_embedded.')) { |
532
|
|
|
$this->join($sort); |
533
|
|
|
$relationEntityAlias = $this->getRelationEntityAlias(); |
534
|
|
|
|
535
|
|
|
$embeddedFields = explode('.', $sort); |
536
|
|
|
$fieldName = $this->parser->camelize($embeddedFields[2]); |
537
|
|
|
$direction = ($val === self::DIRECTION_AZ) ? self::DIRECTION_AZ : self::DIRECTION_ZA; |
538
|
|
|
|
539
|
|
|
$this->qBuilder->addOrderBy($relationEntityAlias.'.'.$fieldName, $direction); |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
return $this; |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
public function getQueryBuilder() |
548
|
|
|
{ |
549
|
|
|
if (!$this->qBuilder) { |
550
|
|
|
throw new \RuntimeException( |
551
|
|
|
"Oops! Query builder was never initialized! call ::createQueryBuilder('entityName', 'alias') to start." |
552
|
|
|
); |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
return $this->qBuilder; |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
public function buildSelectValue() : string |
559
|
|
|
{ |
560
|
|
|
if ("" == $this->getSelect()) { |
561
|
|
|
return $this->getEntityAlias( |
|
|
|
|
562
|
|
|
$this->getEntityName() |
563
|
|
|
); |
564
|
|
|
} |
565
|
|
|
|
566
|
|
|
return $this->getSelect(); |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
private function setRelationEntityAlias(string $relationEntityAlias) |
570
|
|
|
{ |
571
|
|
|
$this->relationEntityAlias = $relationEntityAlias; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
private function getRelationEntityAlias() |
575
|
|
|
{ |
576
|
|
|
return $this->relationEntityAlias; |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
public function setRel($rel) |
580
|
|
|
{ |
581
|
|
|
$this->rel = $rel; |
582
|
|
|
|
583
|
|
|
return $this; |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
public function getRel() |
587
|
|
|
{ |
588
|
|
|
return $this->rel; |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
public function setPrinting($printing) |
592
|
|
|
{ |
593
|
|
|
$this->printing = $printing; |
594
|
|
|
|
595
|
|
|
return $this; |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
public function getPrinting() |
599
|
|
|
{ |
600
|
|
|
return $this->printing; |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
public function setPage($page) |
604
|
|
|
{ |
605
|
|
|
$this->page = $page; |
606
|
|
|
|
607
|
|
|
return $this; |
608
|
|
|
} |
609
|
|
|
|
610
|
|
|
public function getPage() |
611
|
|
|
{ |
612
|
|
|
return $this->page; |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
public function setPageLength($pageLength) |
616
|
|
|
{ |
617
|
|
|
$this->pageLength = $pageLength; |
618
|
|
|
|
619
|
|
|
return $this; |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
public function getPageLength() |
623
|
|
|
{ |
624
|
|
|
return $this->pageLength; |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
public function setSelect( $select) : QueryBuilderFactory |
628
|
|
|
{ |
629
|
|
|
$this->select = $select; |
630
|
|
|
|
631
|
|
|
return $this; |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
public function getSelect() |
635
|
|
|
{ |
636
|
|
|
return $this->select; |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
public function getEntityManager() |
640
|
|
|
{ |
641
|
|
|
return $this->manager; |
642
|
|
|
} |
643
|
|
|
} |
644
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths