1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fi\CoreBundle\Utils\Tabella; |
4
|
|
|
|
5
|
|
|
use \Doctrine\Common\Collections\Expr\Comparison; |
6
|
|
|
use Fi\CoreBundle\Utils\Tabella\ParametriTabella; |
7
|
|
|
|
8
|
|
|
class BaseTabellaDecoder |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
protected $parametri; |
12
|
|
|
protected $entityname; |
13
|
|
|
protected $tablename; |
14
|
|
|
protected $colonnedatabase; |
15
|
|
|
protected $modellocolonne; |
16
|
|
|
protected $paginacorrente; |
17
|
|
|
protected $righeperpagina; |
18
|
|
|
protected $estraituttirecords; |
19
|
|
|
protected $prefiltri; |
20
|
|
|
protected $filtri; |
21
|
|
|
protected $wheremanuale; |
22
|
|
|
protected $colonneordinamento; |
23
|
|
|
protected $opzionitabellacore; |
24
|
|
|
protected $configurazionecolonnetabella; |
25
|
|
|
private $aliasGenerati; |
26
|
|
|
private $decodificaAlias; |
27
|
11 |
|
|
28
|
|
|
protected function parseParameters() |
29
|
11 |
|
{ |
30
|
11 |
|
$this->tablename = ParametriTabella::getParameter($this->parametri['tablename']); |
|
|
|
|
31
|
11 |
|
$this->entityname = ParametriTabella::getParameter($this->parametri['entityclass']); |
|
|
|
|
32
|
11 |
|
$this->entityname = str_replace("FiCoreBundle", "CoreBundle", $this->entityname); |
|
|
|
|
33
|
11 |
|
$this->permessi = json_decode(ParametriTabella::getParameter($this->parametri['permessi'])); |
|
|
|
|
34
|
11 |
|
$this->modellocolonne = isset($this->parametri['modellocolonne']) ? |
|
|
|
|
35
|
11 |
|
json_decode(ParametriTabella::getParameter($this->parametri['modellocolonne']), true) : array(); |
36
|
11 |
|
$this->paginacorrente = ParametriTabella::getParameter($this->parametri['paginacorrente']); |
|
|
|
|
37
|
11 |
|
$this->paginetotali = ParametriTabella::getParameter($this->parametri['paginetotali']); |
|
|
|
|
38
|
11 |
|
$this->righeperpagina = isset($this->parametri['righeperpagina']) ? |
|
|
|
|
39
|
11 |
|
ParametriTabella::getParameter($this->parametri['righeperpagina']) : 15; |
40
|
11 |
|
$this->estraituttirecords = isset($this->parametri['estraituttirecords']) && |
41
|
11 |
|
ParametriTabella::getParameter($this->parametri['estraituttirecords'])==="1" ? |
|
|
|
|
42
|
11 |
|
true : false; |
43
|
11 |
|
$this->colonneordinamento = isset($this->parametri['colonneordinamento']) ? |
44
|
11 |
|
json_decode(ParametriTabella::getParameter($this->parametri['colonneordinamento']), true) : array(); |
45
|
11 |
|
$this->prefiltri = isset($this->parametri['prefiltri']) ? |
|
|
|
|
46
|
11 |
|
json_decode(ParametriTabella::getParameter($this->parametri['prefiltri']), true) : array(); |
47
|
11 |
|
$this->filtri = isset($this->parametri['filtri']) ? |
|
|
|
|
48
|
3 |
|
json_decode(ParametriTabella::getParameter($this->parametri['filtri']), true) : array(); |
49
|
|
|
$this->wheremanuale = isset($this->parametri['wheremanuale']) ? ParametriTabella::getParameter($this->parametri['wheremanuale']) : null; |
|
|
|
|
50
|
3 |
|
$this->user = $this->parametri['user']; |
|
|
|
|
51
|
2 |
|
} |
52
|
|
|
protected function getDescrizioneFiltro(&$descrizionefiltri, $filtrocorrente, $criteria) |
53
|
3 |
|
{ |
54
|
3 |
|
if ($filtrocorrente["prefiltro"] === false) { |
|
|
|
|
55
|
|
|
$descrizionefiltri = $descrizionefiltri . ", " . $criteria->getDescrizioneFiltro(); |
|
|
|
|
56
|
3 |
|
} |
57
|
|
|
} |
58
|
1 |
|
protected function getFieldValue($fieldvalue) |
59
|
|
|
{ |
60
|
3 |
|
if (isset($fieldvalue["date"])) { |
|
|
|
|
61
|
|
|
//StdClassUtils::arrayToObject($fieldvalue, DatetimeTabella::class); |
|
|
|
|
62
|
|
|
return new \Datetime($fieldvalue["date"]); |
|
|
|
|
63
|
3 |
|
} else { |
64
|
|
|
return $fieldvalue; |
65
|
|
|
} |
66
|
3 |
|
} |
67
|
3 |
|
protected function getOperator($operator) |
68
|
1 |
|
{ |
69
|
1 |
|
|
70
|
3 |
|
switch (strtoupper($operator)) { |
71
|
1 |
|
case "LIKE": |
|
|
|
|
72
|
1 |
|
$operator = Comparison::CONTAINS; |
73
|
3 |
|
break; |
74
|
1 |
|
case "IN": |
|
|
|
|
75
|
1 |
|
$operator = Comparison::IN; |
76
|
|
|
break; |
77
|
3 |
|
case "NOT IN": |
|
|
|
|
78
|
|
|
$operator = Comparison::NIN; |
79
|
|
|
break; |
80
|
3 |
|
default: |
81
|
|
|
break; |
82
|
5 |
|
} |
83
|
|
|
|
84
|
5 |
|
return $operator; |
85
|
5 |
|
} |
86
|
5 |
|
protected function bonificanomecampo($nomecampo) |
87
|
5 |
|
{ |
88
|
5 |
|
$parti = explode(".", $nomecampo); |
|
|
|
|
89
|
|
|
$campo = ""; |
|
|
|
|
90
|
5 |
|
for ($index = 0; $index < count($parti); $index++) { |
|
|
|
|
91
|
|
|
if ($index == count($parti) - 1) { |
92
|
|
|
$campo .= "." . lcfirst($parti[$index]); |
|
|
|
|
93
|
5 |
|
} else { |
94
|
|
|
$campo .= "." . ucfirst($parti[$index]); |
|
|
|
|
95
|
11 |
|
} |
96
|
|
|
} |
97
|
11 |
|
return substr($campo, 1); |
98
|
11 |
|
} |
99
|
11 |
|
protected function generaAlias($nometabella, $nomepadre = false, $ancestors = array()) |
100
|
|
|
{ |
101
|
|
|
$nometabellapulito = preg_replace('/[^a-z0-9\.]/i', '', $nometabella); |
102
|
11 |
|
$primalettera = strtolower(substr($nometabellapulito, 0, 1)); |
|
|
|
|
103
|
11 |
|
if ($nomepadre && !in_array($nomepadre, $ancestors)) { |
104
|
|
|
$ancestors[] = $nomepadre; |
105
|
|
|
} |
106
|
11 |
|
if (!in_array($nometabella, $ancestors)) { |
107
|
2 |
|
$ancestors[] = $nometabella; |
108
|
2 |
|
} |
109
|
|
|
|
110
|
11 |
|
if (isset($this->aliasGenerati[$primalettera])) { |
111
|
11 |
|
$risposta = $primalettera . $this->aliasGenerati[$primalettera]; |
|
|
|
|
112
|
|
|
$this->aliasGenerati[$primalettera] = $this->aliasGenerati[$primalettera] + 1; |
113
|
|
|
} else { |
114
|
11 |
|
$risposta = $primalettera; |
|
|
|
|
115
|
|
|
$this->aliasGenerati[$primalettera] = 1; |
116
|
11 |
|
} |
117
|
|
|
|
118
|
3 |
|
$this->decodificaAlias[ucfirst(implode(".", $ancestors))] = array("alias" => $risposta); |
|
|
|
|
119
|
|
|
|
120
|
3 |
|
return $risposta; |
121
|
|
|
} |
122
|
|
|
protected function findAliasByTablename($tablename) |
123
|
|
|
{ |
124
|
|
|
if (!array_key_exists($tablename, $this->decodificaAlias)) { |
125
|
|
|
$ex = "Fifree: table or association " . $tablename . " not found, did you mean one of these:\n" . |
|
|
|
|
126
|
3 |
|
implode("\n", array_keys($this->decodificaAlias)) . |
127
|
|
|
" ?"; |
|
|
|
|
128
|
3 |
|
throw new \Exception($ex); |
129
|
|
|
} |
130
|
3 |
|
return $this->getAliasGenerato($tablename); |
131
|
|
|
} |
132
|
|
|
protected function findFieldnameByAlias($nomecampo) |
133
|
|
|
{ |
134
|
|
|
if (!array_key_exists($nomecampo, $this->configurazionecolonnetabella)) { |
135
|
|
|
$ex = "Fifree: field or association " . $nomecampo . " not found, did you mean one of these:\n" . |
|
|
|
|
136
|
3 |
|
implode("\n", array_keys($this->configurazionecolonnetabella)) . |
137
|
|
|
" ?"; |
|
|
|
|
138
|
|
|
throw new \Exception($ex); |
139
|
9 |
|
} |
140
|
|
|
return $this->configurazionecolonnetabella[$nomecampo]; |
141
|
9 |
|
} |
142
|
|
|
|
143
|
|
|
public function getAliasGenerato($tablename) |
144
|
|
|
{ |
145
|
|
|
return $this->decodificaAlias[$tablename]["alias"]; |
|
|
|
|
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
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.