1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fi\CoreBundle\Utils\Tabella; |
4
|
|
|
|
5
|
|
|
//use Doctrine\ORM\QueryBuilder; |
6
|
|
|
use Doctrine\Common\Collections\Expr\Comparison; |
7
|
|
|
use Doctrine\ORM\Query\Expr; |
8
|
|
|
use Fi\CoreBundle\Utils\FieldType\FieldTypeUtils; |
9
|
|
|
|
10
|
|
|
class ParametriQueryTabellaDecoder extends BaseParametriQueryTabellaDecoder |
11
|
|
|
{ |
12
|
3 |
|
protected function buildQuery() |
13
|
|
|
{ |
14
|
3 |
|
switch ($this->fieldoperator) { |
15
|
3 |
|
case Comparison::EQ: |
16
|
3 |
|
$this->setEqCriteria(); |
17
|
3 |
|
break; |
18
|
2 |
|
case Comparison::NEQ: |
19
|
1 |
|
$this->setNeqCriteria(); |
20
|
1 |
|
break; |
21
|
2 |
|
case Comparison::IN: |
22
|
1 |
|
$this->setInCriteria(); |
23
|
1 |
|
break; |
24
|
2 |
|
case Comparison::NIN: |
25
|
1 |
|
$this->setNinCriteria(); |
26
|
1 |
|
break; |
27
|
2 |
|
case Comparison::CONTAINS: |
28
|
1 |
|
$this->setContainsCriteria(); |
29
|
1 |
|
break; |
30
|
2 |
|
case Comparison::STARTS_WITH: |
31
|
|
|
$this->setStartswithCriteria(); |
32
|
|
|
break; |
33
|
2 |
|
case Comparison::ENDS_WITH: |
34
|
1 |
|
$this->setEndswithCriteria(); |
35
|
1 |
|
break; |
36
|
|
|
default: |
37
|
2 |
|
$this->criteria = null; |
38
|
2 |
|
break; |
39
|
|
|
} |
40
|
3 |
|
} |
41
|
3 |
|
protected function setEqCriteria() |
42
|
|
|
{ |
43
|
3 |
|
$expr = new Expr(); |
44
|
|
|
|
45
|
3 |
|
if ($this->fieldvalue === null) { |
46
|
1 |
|
$this->criteria = $expr->isnull($this->fieldname); |
47
|
|
|
} else { |
48
|
3 |
|
if (is_a(FieldTypeUtils::extractDateTime($this->fieldvalue), "\DateTime")) { |
|
|
|
|
49
|
1 |
|
$this->criteria = $expr->eq($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
50
|
|
|
} else { |
51
|
3 |
|
if (is_string($this->fieldvalue)) { |
52
|
1 |
|
$this->criteria = $expr->eq("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
53
|
|
|
} else { |
54
|
2 |
|
$this->criteria = $expr->eq($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
} |
57
|
3 |
|
$this->parameters = array($this->fieldqueryparameter => $this->fieldvalue); |
58
|
|
|
} |
59
|
3 |
|
} |
60
|
1 |
|
protected function setNeqCriteria() |
61
|
|
|
{ |
62
|
1 |
|
$expr = new Expr(); |
63
|
|
|
|
64
|
1 |
|
if ($this->fieldvalue === null) { |
65
|
1 |
|
$this->criteria = $expr->isnotnull($this->fieldname); |
66
|
|
|
} else { |
67
|
1 |
|
if (is_a(FieldTypeUtils::extractDateTime($this->fieldvalue), "\DateTime")) { |
|
|
|
|
68
|
1 |
|
$this->criteria = $expr->neq($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
69
|
|
|
} else { |
70
|
|
|
if (is_string($this->fieldvalue)) { |
71
|
|
|
$this->criteria = $expr->neq("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
72
|
|
|
} else { |
73
|
|
|
$this->criteria = $expr->neq($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
1 |
|
$this->parameters = array($this->fieldqueryparameter => $this->fieldvalue); |
77
|
|
|
} |
78
|
1 |
|
} |
79
|
1 |
|
protected function setNinCriteria() |
80
|
|
|
{ |
81
|
1 |
|
$expr = new Expr(); |
82
|
|
|
|
83
|
1 |
|
if (is_string($this->fieldvalue)) { |
84
|
|
|
$this->criteria = $expr->notin("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
85
|
|
|
} else { |
86
|
1 |
|
$this->criteria = $expr->notin($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
87
|
|
|
} |
88
|
1 |
|
$this->parameters = array($this->fieldqueryparameter => $this->fieldvalue); |
89
|
1 |
|
} |
90
|
1 |
|
protected function setInCriteria() |
91
|
|
|
{ |
92
|
1 |
|
$expr = new Expr(); |
93
|
|
|
|
94
|
1 |
|
if (is_string($this->fieldvalue)) { |
95
|
|
|
$this->criteria = $expr->in("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
96
|
|
|
} else { |
97
|
1 |
|
$this->criteria = $expr->in($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
98
|
|
|
} |
99
|
1 |
|
$this->parameters = array($this->fieldqueryparameter => $this->fieldvalue); |
100
|
1 |
|
} |
101
|
1 |
|
protected function setContainsCriteria() |
102
|
|
|
{ |
103
|
1 |
|
$expr = new Expr(); |
104
|
1 |
|
if (is_string($this->fieldvalue)) { |
105
|
1 |
|
$this->criteria = $expr->like("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
106
|
|
|
} else { |
107
|
|
|
$this->criteria = $expr->like($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
108
|
|
|
} |
109
|
1 |
|
$this->parameters = array($this->fieldqueryparameter => '%' . $this->fieldvalue . '%'); |
110
|
1 |
|
} |
111
|
|
|
protected function setStartswithCriteria() |
112
|
|
|
{ |
113
|
|
|
$expr = new Expr(); |
114
|
|
|
if (is_string($this->fieldvalue)) { |
115
|
|
|
$this->criteria = $expr->like("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
116
|
|
|
} else { |
117
|
|
|
$this->criteria = $expr->like($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
118
|
|
|
} |
119
|
|
|
$this->parameters = array($this->fieldqueryparameter => $this->fieldvalue . '%'); |
120
|
|
|
} |
121
|
1 |
|
protected function setEndswithCriteria() |
122
|
|
|
{ |
123
|
1 |
|
$expr = new Expr(); |
124
|
1 |
|
if (is_string($this->fieldvalue)) { |
125
|
1 |
|
$this->criteria = $expr->like("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
126
|
|
|
} else { |
127
|
|
|
$this->criteria = $expr->like($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
128
|
|
|
} |
129
|
1 |
|
$this->parameters = array($this->fieldqueryparameter => '%' . $this->fieldvalue); |
130
|
1 |
|
} |
131
|
|
|
} |
132
|
|
|
|