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