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