|
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
|
2 |
|
$this->getDescrizioneFiltroIsNull($descrizionevalore); |
|
49
|
|
|
|
|
50
|
2 |
|
$this->getDescrizioneFiltroBoolean($descrizionevalore); |
|
51
|
|
|
|
|
52
|
2 |
|
$this->getDescrizioneFiltroArray($descrizionevalore); |
|
53
|
|
|
|
|
54
|
2 |
|
$this->getDescrizioneFiltroString($descrizionevalore); |
|
55
|
|
|
|
|
56
|
2 |
|
$this->getDescrizioneFiltroDate($descrizionevalore); |
|
57
|
|
|
|
|
58
|
2 |
|
$this->getDescrizioneFiltroAltro($descrizionevalore); |
|
59
|
2 |
|
$nomecampo = substr($this->fieldname, stripos($this->fieldname, ".")+1); |
|
|
|
|
|
|
60
|
2 |
|
$filtro = $nomecampo . " " . $this->operatorToString($this->fieldoperator) . " " . $descrizionevalore; |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
2 |
|
return $filtro; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
2 |
|
protected function getDescrizioneFiltroAltro(&$descrizionevalore) |
|
66
|
|
|
{ |
|
67
|
2 |
|
if ($descrizionevalore == "") { |
|
|
|
|
|
|
68
|
1 |
|
$descrizionevalore = "'" . $this->fieldvalue . "'"; |
|
69
|
|
|
} |
|
70
|
2 |
|
} |
|
71
|
|
|
|
|
72
|
2 |
|
protected function getDescrizioneFiltroDate(&$descrizionevalore) |
|
73
|
|
|
{ |
|
74
|
2 |
|
if ($this->fieldinfo["tipocampo"] == 'date') { |
|
|
|
|
|
|
75
|
1 |
|
if (is_a($this->fieldvalue, "\DateTime")) { |
|
|
|
|
|
|
76
|
1 |
|
$descrizionevalore = $this->fieldvalue->format("d/m/Y"); |
|
|
|
|
|
|
77
|
|
|
} else { |
|
78
|
1 |
|
$descrizionevalore = \DateTime::createFromFormat("Y-m-d", $this->fieldvalue)->format("d/m/Y"); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
2 |
|
if ($this->fieldinfo["tipocampo"] == 'datetime') { |
|
|
|
|
|
|
82
|
1 |
|
if (is_a($this->fieldvalue, "\DateTime")) { |
|
|
|
|
|
|
83
|
1 |
|
$descrizionevalore = $this->fieldvalue->format("d/m/Y H:i:s"); |
|
|
|
|
|
|
84
|
|
|
} else { |
|
85
|
|
|
$descrizionevalore = \DateTime::createFromFormat("Y-m-d", $this->fieldvalue)->format("d/m/Y"); |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
2 |
|
} |
|
89
|
|
|
|
|
90
|
2 |
|
protected function getDescrizioneFiltroString(&$descrizionevalore) |
|
91
|
|
|
{ |
|
92
|
2 |
|
if (is_string($this->fieldvalue)) { |
|
93
|
1 |
|
$descrizionevalore = $descrizionevalore = "'" . $this->fieldvalue . "'"; |
|
94
|
|
|
} |
|
95
|
2 |
|
} |
|
96
|
|
|
|
|
97
|
2 |
|
protected function getDescrizioneFiltroIsNull(&$descrizionevalore) |
|
98
|
|
|
{ |
|
99
|
2 |
|
if (is_null($this->fieldvalue)) { |
|
100
|
1 |
|
$descrizionevalore = "(vuoto)"; |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
2 |
|
} |
|
103
|
|
|
|
|
104
|
2 |
|
protected function getDescrizioneFiltroBoolean(&$descrizionevalore) |
|
105
|
|
|
{ |
|
106
|
2 |
|
if (is_bool($this->fieldvalue)) { |
|
107
|
1 |
|
$descrizionevalore = $this->fieldvalue ? "SI" : "NO"; |
|
|
|
|
|
|
108
|
|
|
} |
|
109
|
2 |
|
} |
|
110
|
|
|
|
|
111
|
2 |
|
protected function getDescrizioneFiltroArray(&$descrizionevalore) |
|
112
|
|
|
{ |
|
113
|
2 |
|
if (is_array($this->fieldvalue)) { |
|
114
|
1 |
|
foreach ($this->fieldvalue as $value) { |
|
115
|
1 |
|
if (is_numeric($value)) { |
|
116
|
1 |
|
$descrizionevalore = $descrizionevalore . ", " . $value; |
|
|
|
|
|
|
117
|
|
|
} else { |
|
118
|
1 |
|
$descrizionevalore = $descrizionevalore . "'" . $value . "', "; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
1 |
|
$descrizionevalore = substr($descrizionevalore, 0, -2); |
|
122
|
|
|
} |
|
123
|
2 |
|
} |
|
124
|
|
|
|
|
125
|
2 |
|
protected function operatorToString($operator) |
|
126
|
|
|
{ |
|
127
|
2 |
|
$operatoredecodificato = ""; |
|
|
|
|
|
|
128
|
|
|
switch ($operator) { |
|
129
|
2 |
|
case Comparison::LT: |
|
130
|
|
|
$operatoredecodificato = "minore di"; |
|
|
|
|
|
|
131
|
|
|
break; |
|
132
|
2 |
|
case Comparison::LTE: |
|
133
|
1 |
|
$operatoredecodificato = "minore o uguale di"; |
|
|
|
|
|
|
134
|
1 |
|
break; |
|
135
|
2 |
|
case Comparison::GT: |
|
136
|
|
|
$operatoredecodificato = "maggiore di"; |
|
|
|
|
|
|
137
|
|
|
break; |
|
138
|
2 |
|
case Comparison::GTE: |
|
139
|
1 |
|
$operatoredecodificato = "maggiore o uguale di"; |
|
|
|
|
|
|
140
|
1 |
|
break; |
|
141
|
2 |
|
case Comparison::CONTAINS: |
|
142
|
|
|
$operatoredecodificato = "contiene"; |
|
|
|
|
|
|
143
|
|
|
break; |
|
144
|
2 |
|
case Comparison::STARTS_WITH: |
|
145
|
|
|
$operatoredecodificato = "inizia con"; |
|
|
|
|
|
|
146
|
|
|
break; |
|
147
|
2 |
|
case Comparison::ENDS_WITH: |
|
148
|
|
|
$operatoredecodificato = "finisce con"; |
|
|
|
|
|
|
149
|
|
|
break; |
|
150
|
2 |
|
case Comparison::IN: |
|
151
|
1 |
|
$operatoredecodificato = "compreso tra"; |
|
|
|
|
|
|
152
|
1 |
|
break; |
|
153
|
2 |
|
case Comparison::NIN: |
|
154
|
1 |
|
$operatoredecodificato = "non compreso tra"; |
|
|
|
|
|
|
155
|
1 |
|
break; |
|
156
|
2 |
|
case Comparison::EQ: |
|
157
|
2 |
|
$operatoredecodificato = "uguale a"; |
|
|
|
|
|
|
158
|
2 |
|
break; |
|
159
|
1 |
|
case Comparison::NEQ: |
|
160
|
1 |
|
$operatoredecodificato = "diverso da"; |
|
|
|
|
|
|
161
|
1 |
|
break; |
|
162
|
|
|
default: |
|
163
|
|
|
break; |
|
164
|
|
|
} |
|
165
|
2 |
|
return $operatoredecodificato; |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|
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.