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
|
|
|
|
9
|
|
|
class BaseParametriQueryTabellaDecoder |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
protected $fieldname; |
13
|
|
|
protected $fieldoperator; |
14
|
|
|
protected $fieldvalue; |
15
|
|
|
protected $fieldqueryparameter; |
16
|
|
|
protected $criteria; |
17
|
|
|
protected $parameters; |
18
|
|
|
|
19
|
2 |
|
public function __construct($fieldname, $fieldoperator, $fieldvalue, $fieldqueryparameter, $fieldinfo) |
20
|
|
|
{ |
21
|
2 |
|
$this->fieldname = $fieldname; |
|
|
|
|
22
|
2 |
|
$this->fieldoperator = $fieldoperator; |
23
|
2 |
|
if (is_string($fieldvalue)) { |
24
|
1 |
|
$this->fieldvalue = urldecode($fieldvalue); |
25
|
|
|
} else { |
26
|
2 |
|
$this->fieldvalue = $fieldvalue; |
27
|
|
|
} |
28
|
2 |
|
$this->fieldqueryparameter = $fieldqueryparameter; |
29
|
2 |
|
$this->fieldinfo = $fieldinfo; |
|
|
|
|
30
|
2 |
|
$this->parameters = array(); |
|
|
|
|
31
|
2 |
|
$this->buildQuery(); |
|
|
|
|
32
|
2 |
|
} |
33
|
|
|
|
34
|
2 |
|
public function getQueryCriteria() |
35
|
|
|
{ |
36
|
2 |
|
return $this->criteria; |
37
|
|
|
} |
38
|
|
|
|
39
|
2 |
|
public function getQueryParameters() |
40
|
|
|
{ |
41
|
2 |
|
return $this->parameters; |
42
|
|
|
} |
43
|
|
|
|
44
|
2 |
|
public function getDescrizioneFiltro() |
45
|
|
|
{ |
46
|
2 |
|
$descrizionevalore = ""; |
|
|
|
|
47
|
|
|
|
48
|
|
|
switch (true) { |
49
|
2 |
|
case $this->getDescrizioneFiltroIsNull($descrizionevalore): |
50
|
1 |
|
break; |
51
|
2 |
|
case $this->getDescrizioneFiltroBoolean($descrizionevalore): |
52
|
1 |
|
break; |
53
|
1 |
|
case $this->getDescrizioneFiltroDate($descrizionevalore): |
54
|
1 |
|
break; |
55
|
1 |
|
case $this->getDescrizioneFiltroArray($descrizionevalore): |
56
|
1 |
|
break; |
57
|
1 |
|
case $this->getDescrizioneFiltroString($descrizionevalore): |
58
|
|
|
break; |
59
|
|
|
default: |
60
|
1 |
|
$this->getDescrizioneFiltroAltro($descrizionevalore); |
61
|
1 |
|
break; |
62
|
|
|
} |
63
|
2 |
|
$nomecampo = substr($this->fieldname, stripos($this->fieldname, ".") + 1); |
|
|
|
|
64
|
2 |
|
$filtro = $nomecampo . " " . $this->operatorToString($this->fieldoperator) . " " . $descrizionevalore; |
|
|
|
|
65
|
|
|
|
66
|
2 |
|
return $filtro; |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
protected function getDescrizioneFiltroAltro(&$descrizionevalore) |
70
|
|
|
{ |
71
|
1 |
|
if ($descrizionevalore == "") { |
|
|
|
|
72
|
1 |
|
$descrizionevalore = "'" . $this->fieldvalue . "'"; |
73
|
|
|
} |
74
|
1 |
|
} |
75
|
|
|
|
76
|
1 |
|
protected function getDescrizioneFiltroDate(&$descrizionevalore) |
77
|
|
|
{ |
78
|
1 |
|
$trovato = false; |
79
|
1 |
|
if ($this->fieldinfo["tipocampo"] == 'date') { |
|
|
|
|
80
|
1 |
|
if (is_a($this->fieldvalue, "\DateTime")) { |
|
|
|
|
81
|
1 |
|
$descrizionevalore = $this->fieldvalue->format("d/m/Y"); |
|
|
|
|
82
|
|
|
} else { |
83
|
1 |
|
$descrizionevalore = \DateTime::createFromFormat("Y-m-d", $this->fieldvalue)->format("d/m/Y"); |
|
|
|
|
84
|
|
|
} |
85
|
1 |
|
$trovato = true; |
86
|
|
|
} |
87
|
1 |
|
if ($this->fieldinfo["tipocampo"] == 'datetime') { |
|
|
|
|
88
|
1 |
|
if (is_a($this->fieldvalue, "\DateTime")) { |
|
|
|
|
89
|
1 |
|
$descrizionevalore = $this->fieldvalue->format("d/m/Y H:i:s"); |
|
|
|
|
90
|
|
|
} else { |
91
|
|
|
$descrizionevalore = \DateTime::createFromFormat("Y-m-d", $this->fieldvalue)->format("d/m/Y"); |
|
|
|
|
92
|
|
|
} |
93
|
1 |
|
$trovato = true; |
94
|
|
|
} |
95
|
1 |
|
return $trovato; |
96
|
|
|
} |
97
|
|
|
|
98
|
1 |
|
protected function getDescrizioneFiltroString(&$descrizionevalore) |
99
|
|
|
{ |
100
|
1 |
|
$trovato = false; |
101
|
1 |
|
if (is_string($this->fieldvalue)) { |
102
|
|
|
$descrizionevalore = $descrizionevalore = "'" . $this->fieldvalue . "'"; |
103
|
|
|
$trovato = true; |
|
|
|
|
104
|
|
|
} |
105
|
1 |
|
return $trovato; |
106
|
|
|
} |
107
|
|
|
|
108
|
2 |
|
protected function getDescrizioneFiltroIsNull(&$descrizionevalore) |
109
|
|
|
{ |
110
|
2 |
|
$trovato = false; |
111
|
2 |
|
if (is_null($this->fieldvalue)) { |
112
|
1 |
|
$descrizionevalore = "(vuoto)"; |
|
|
|
|
113
|
1 |
|
$trovato = true; |
|
|
|
|
114
|
|
|
} |
115
|
2 |
|
return $trovato; |
116
|
|
|
} |
117
|
|
|
|
118
|
2 |
|
protected function getDescrizioneFiltroBoolean(&$descrizionevalore) |
119
|
|
|
{ |
120
|
2 |
|
$trovato = false; |
121
|
2 |
|
if (is_bool($this->fieldvalue)) { |
122
|
1 |
|
$descrizionevalore = $this->fieldvalue ? "SI" : "NO"; |
|
|
|
|
123
|
1 |
|
$trovato = true; |
|
|
|
|
124
|
|
|
} |
125
|
2 |
|
return $trovato; |
126
|
|
|
} |
127
|
|
|
|
128
|
1 |
|
protected function getDescrizioneFiltroArray(&$descrizionevalore) |
129
|
|
|
{ |
130
|
1 |
|
$trovato = false; |
131
|
1 |
|
if (is_array($this->fieldvalue)) { |
132
|
1 |
|
foreach ($this->fieldvalue as $value) { |
133
|
1 |
|
if (is_numeric($value)) { |
134
|
1 |
|
$descrizionevalore = $descrizionevalore . ", " . $value; |
|
|
|
|
135
|
|
|
} else { |
136
|
|
|
$descrizionevalore = $descrizionevalore . "'" . $value . "', "; |
137
|
|
|
} |
138
|
1 |
|
$trovato = true; |
139
|
|
|
} |
140
|
1 |
|
$descrizionevalore = substr($descrizionevalore, 0, -2); |
141
|
|
|
} |
142
|
1 |
|
return $trovato; |
143
|
|
|
} |
144
|
|
|
|
145
|
2 |
|
protected function operatorToString($operator) |
146
|
|
|
{ |
147
|
2 |
|
$operatoredecodificato = ""; |
|
|
|
|
148
|
|
|
switch ($operator) { |
149
|
2 |
|
case Comparison::LT: |
150
|
|
|
$operatoredecodificato = "minore di"; |
|
|
|
|
151
|
|
|
break; |
152
|
2 |
|
case Comparison::LTE: |
153
|
1 |
|
$operatoredecodificato = "minore o uguale di"; |
|
|
|
|
154
|
1 |
|
break; |
155
|
2 |
|
case Comparison::GT: |
156
|
|
|
$operatoredecodificato = "maggiore di"; |
|
|
|
|
157
|
|
|
break; |
158
|
2 |
|
case Comparison::GTE: |
159
|
1 |
|
$operatoredecodificato = "maggiore o uguale di"; |
|
|
|
|
160
|
1 |
|
break; |
161
|
2 |
|
case Comparison::CONTAINS: |
162
|
|
|
$operatoredecodificato = "contiene"; |
|
|
|
|
163
|
|
|
break; |
164
|
2 |
|
case Comparison::STARTS_WITH: |
165
|
|
|
$operatoredecodificato = "inizia con"; |
|
|
|
|
166
|
|
|
break; |
167
|
2 |
|
case Comparison::ENDS_WITH: |
168
|
|
|
$operatoredecodificato = "finisce con"; |
|
|
|
|
169
|
|
|
break; |
170
|
2 |
|
case Comparison::IN: |
171
|
1 |
|
$operatoredecodificato = "compreso tra"; |
|
|
|
|
172
|
1 |
|
break; |
173
|
2 |
|
case Comparison::NIN: |
174
|
1 |
|
$operatoredecodificato = "non compreso tra"; |
|
|
|
|
175
|
1 |
|
break; |
176
|
2 |
|
case Comparison::EQ: |
177
|
2 |
|
$operatoredecodificato = "uguale a"; |
|
|
|
|
178
|
2 |
|
break; |
179
|
1 |
|
case Comparison::NEQ: |
180
|
1 |
|
$operatoredecodificato = "diverso da"; |
|
|
|
|
181
|
1 |
|
break; |
182
|
|
|
default: |
183
|
|
|
break; |
184
|
|
|
} |
185
|
2 |
|
return $operatoredecodificato; |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.