1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\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
|
3 |
|
public function __construct($fieldname, $fieldoperator, $fieldvalue, $fieldqueryparameter, $fieldinfo) |
20
|
|
|
{ |
21
|
3 |
|
$this->fieldname = $fieldname; |
|
|
|
|
22
|
3 |
|
$this->fieldoperator = $fieldoperator; |
23
|
3 |
|
if (is_string($fieldvalue)) { |
24
|
2 |
|
$this->fieldvalue = urldecode($fieldvalue); |
25
|
|
|
} else { |
26
|
3 |
|
$this->fieldvalue = $fieldvalue; |
27
|
|
|
} |
28
|
3 |
|
$this->fieldqueryparameter = $fieldqueryparameter; |
29
|
3 |
|
$this->fieldinfo = $fieldinfo; |
|
|
|
|
30
|
3 |
|
$this->parameters = array(); |
|
|
|
|
31
|
3 |
|
$this->buildQuery(); |
|
|
|
|
32
|
3 |
|
} |
33
|
|
|
|
34
|
3 |
|
public function getQueryCriteria() |
35
|
|
|
{ |
36
|
3 |
|
return $this->criteria; |
37
|
|
|
} |
38
|
|
|
|
39
|
3 |
|
public function getQueryParameters() |
40
|
|
|
{ |
41
|
3 |
|
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->getDescrizioneFiltroDecodifiche($descrizionevalore): |
52
|
|
|
break; |
53
|
2 |
|
case $this->getDescrizioneFiltroBoolean($descrizionevalore): |
54
|
1 |
|
break; |
55
|
1 |
|
case $this->getDescrizioneFiltroDate($descrizionevalore): |
56
|
1 |
|
break; |
57
|
1 |
|
case $this->getDescrizioneFiltroArray($descrizionevalore): |
58
|
1 |
|
break; |
59
|
1 |
|
case $this->getDescrizioneFiltroString($descrizionevalore): |
60
|
1 |
|
break; |
61
|
|
|
default: |
62
|
1 |
|
$this->getDescrizioneFiltroAltro($descrizionevalore); |
63
|
1 |
|
break; |
64
|
|
|
} |
65
|
2 |
|
$nomecampo = substr($this->fieldname, stripos($this->fieldname, '.') + 1); |
66
|
2 |
|
$filtro = $nomecampo . " " . $this->operatorToString($this->fieldoperator) . " " . $descrizionevalore; |
|
|
|
|
67
|
|
|
|
68
|
2 |
|
return $filtro; |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
protected function getDescrizioneFiltroAltro(&$descrizionevalore) |
72
|
|
|
{ |
73
|
1 |
|
if ($descrizionevalore == "") { |
|
|
|
|
74
|
1 |
|
$descrizionevalore = "'" . $this->fieldvalue . "'"; |
75
|
|
|
} |
76
|
1 |
|
} |
77
|
|
|
|
78
|
1 |
|
protected function getDescrizioneFiltroDate(&$descrizionevalore) |
79
|
|
|
{ |
80
|
1 |
|
$trovato = false; |
81
|
1 |
|
if ($this->fieldinfo["tipocampo"] == 'date') { |
|
|
|
|
82
|
1 |
|
if (is_a($this->fieldvalue, "\DateTime")) { |
|
|
|
|
83
|
1 |
|
$descrizionevalore = $this->fieldvalue->format("d/m/Y"); |
|
|
|
|
84
|
|
|
} else { |
85
|
1 |
|
$descrizionevalore = \DateTime::createFromFormat("Y-m-d", $this->fieldvalue)->format("d/m/Y"); |
|
|
|
|
86
|
|
|
} |
87
|
1 |
|
$trovato = true; |
88
|
|
|
} |
89
|
1 |
|
if ($this->fieldinfo["tipocampo"] == 'datetime') { |
|
|
|
|
90
|
1 |
|
if (is_a($this->fieldvalue, "\DateTime")) { |
|
|
|
|
91
|
1 |
|
$descrizionevalore = $this->fieldvalue->format("d/m/Y H:i:s"); |
|
|
|
|
92
|
|
|
} else { |
93
|
|
|
$descrizionevalore = \DateTime::createFromFormat("Y-m-d", $this->fieldvalue)->format("d/m/Y"); |
|
|
|
|
94
|
|
|
} |
95
|
1 |
|
$trovato = true; |
96
|
|
|
} |
97
|
1 |
|
return $trovato; |
98
|
|
|
} |
99
|
|
|
|
100
|
1 |
|
protected function getDescrizioneFiltroString(&$descrizionevalore) |
101
|
|
|
{ |
102
|
1 |
|
$trovato = false; |
103
|
1 |
|
if (is_string($this->fieldvalue)) { |
104
|
1 |
|
$descrizionevalore = $descrizionevalore = "'" . $this->fieldvalue . "'"; |
105
|
1 |
|
$trovato = true; |
|
|
|
|
106
|
|
|
} |
107
|
1 |
|
return $trovato; |
108
|
|
|
} |
109
|
|
|
|
110
|
2 |
|
protected function getDescrizioneFiltroDecodifiche(&$descrizionevalore) |
111
|
|
|
{ |
112
|
2 |
|
$trovato = false; |
113
|
2 |
|
if (isset($this->fieldinfo["decodifiche"])) { |
|
|
|
|
114
|
|
|
$decodifiche = $this->fieldinfo["decodifiche"]; |
|
|
|
|
115
|
|
|
if ($decodifiche) { |
116
|
|
|
if (is_array($this->fieldvalue)) { |
117
|
|
|
foreach ($this->fieldvalue as $value) { |
118
|
|
|
$descrizionevalore = $descrizionevalore . "'" . $decodifiche[$value] . "', "; |
119
|
|
|
} |
120
|
|
|
} else { |
121
|
|
|
if (isset($decodifiche[$this->fieldvalue])) { |
122
|
|
|
$descrizionevalore = $descrizionevalore = "'" . $decodifiche[$this->fieldvalue] . "'"; |
123
|
|
|
} else { |
124
|
|
|
$descrizionevalore = $descrizionevalore = "'" . $this->fieldvalue . "'"; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
$trovato = true; |
128
|
|
|
} |
129
|
|
|
} |
130
|
2 |
|
return $trovato; |
131
|
|
|
} |
132
|
|
|
|
133
|
2 |
|
protected function getDescrizioneFiltroIsNull(&$descrizionevalore) |
134
|
|
|
{ |
135
|
2 |
|
$trovato = false; |
136
|
2 |
|
if (is_null($this->fieldvalue)) { |
137
|
1 |
|
$descrizionevalore = "(vuoto)"; |
|
|
|
|
138
|
1 |
|
$trovato = true; |
|
|
|
|
139
|
|
|
} |
140
|
2 |
|
return $trovato; |
141
|
|
|
} |
142
|
|
|
|
143
|
2 |
|
protected function getDescrizioneFiltroBoolean(&$descrizionevalore) |
144
|
|
|
{ |
145
|
2 |
|
$trovato = false; |
146
|
2 |
|
if (is_bool($this->fieldvalue)) { |
147
|
1 |
|
$descrizionevalore = $this->fieldvalue ? "SI" : "NO"; |
|
|
|
|
148
|
1 |
|
$trovato = true; |
|
|
|
|
149
|
|
|
} |
150
|
2 |
|
return $trovato; |
151
|
|
|
} |
152
|
|
|
|
153
|
1 |
|
protected function getDescrizioneFiltroArray(&$descrizionevalore) |
154
|
|
|
{ |
155
|
1 |
|
$trovato = false; |
156
|
1 |
|
if (is_array($this->fieldvalue)) { |
157
|
1 |
|
foreach ($this->fieldvalue as $value) { |
158
|
1 |
|
if (is_numeric($value)) { |
159
|
1 |
|
$descrizionevalore = $descrizionevalore . ", " . $value; |
|
|
|
|
160
|
|
|
} else { |
161
|
|
|
$descrizionevalore = $descrizionevalore . "'" . $value . "', "; |
162
|
|
|
} |
163
|
1 |
|
$trovato = true; |
164
|
|
|
} |
165
|
1 |
|
$descrizionevalore = substr($descrizionevalore, 0, -2); |
166
|
|
|
} |
167
|
1 |
|
return $trovato; |
168
|
|
|
} |
169
|
|
|
|
170
|
2 |
|
protected function operatorToString($operator) |
171
|
|
|
{ |
172
|
|
|
$decoder = array( |
173
|
2 |
|
Comparison::LT=>'minore di', |
174
|
2 |
|
Comparison::LTE=>'minore o uguale di', |
175
|
2 |
|
Comparison::GT=>'maggiore di', |
176
|
2 |
|
Comparison::GTE=>'maggiore o uguale di', |
177
|
2 |
|
Comparison::CONTAINS=>'contiene', |
178
|
2 |
|
Comparison::STARTS_WITH=>'inizia con', |
179
|
2 |
|
Comparison::ENDS_WITH=>'finisce con', |
180
|
2 |
|
Comparison::IN=>'compreso tra', |
181
|
2 |
|
Comparison::NIN=>'non compreso tra', |
182
|
2 |
|
Comparison::EQ=>'uguale a', |
183
|
2 |
|
Comparison::NEQ=>'diverso da', |
184
|
|
|
); |
185
|
2 |
|
return $decoder[$operator]; |
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.