|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Fi\CoreBundle\Utils\Tabella; |
|
4
|
|
|
|
|
5
|
|
|
use Fi\CoreBundle\Utils\Entity\EntityUtils; |
|
6
|
|
|
use Fi\CoreBundle\Entity\Opzionitabelle; |
|
7
|
|
|
use Fi\CoreBundle\Entity\Colonnetabelle; |
|
8
|
|
|
use Fi\CoreBundle\Utils\Arrays\ArrayUtils; |
|
9
|
|
|
use Fi\CoreBundle\Utils\Tabella\ParametriTabella; |
|
10
|
|
|
|
|
11
|
|
|
class BaseTabella |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
protected $parametri; |
|
15
|
|
|
protected $entityname; |
|
16
|
|
|
protected $tablename; |
|
17
|
|
|
protected $colonnedatabase; |
|
18
|
|
|
protected $records; |
|
19
|
|
|
protected $modellocolonne; |
|
20
|
|
|
protected $prefiltri; |
|
21
|
|
|
protected $filtri; |
|
22
|
|
|
protected $wheremanuale; |
|
23
|
|
|
protected $colonneordinamento; |
|
24
|
|
|
protected $opzionitabellacore; |
|
25
|
|
|
protected $configurazionecolonnetabella; |
|
26
|
|
|
protected $maxordine = 0; |
|
27
|
|
|
protected $em; |
|
28
|
|
|
protected $user; |
|
29
|
|
|
|
|
30
|
8 |
|
protected function parseParameters() |
|
31
|
|
|
{ |
|
32
|
8 |
|
$this->tablename = ParametriTabella::getParameter($this->parametri['tablename']); |
|
|
|
|
|
|
33
|
8 |
|
$this->entityname = ParametriTabella::getParameter($this->parametri['entityclass']); |
|
|
|
|
|
|
34
|
8 |
|
$this->entityname = str_replace("FiCoreBundle", "CoreBundle", $this->entityname); |
|
|
|
|
|
|
35
|
8 |
|
$this->permessi = json_decode(ParametriTabella::getParameter($this->parametri['permessi'])); |
|
|
|
|
|
|
36
|
8 |
|
$this->modellocolonne = isset($this->parametri['modellocolonne']) ? |
|
|
|
|
|
|
37
|
8 |
|
json_decode(ParametriTabella::getParameter($this->parametri['modellocolonne']), true) : array(); |
|
38
|
8 |
|
$this->paginacorrente = ParametriTabella::getParameter($this->parametri['paginacorrente']); |
|
|
|
|
|
|
39
|
8 |
|
$this->paginetotali = ParametriTabella::getParameter($this->parametri['paginetotali']); |
|
|
|
|
|
|
40
|
8 |
|
$this->righeperpagina = isset($this->parametri['righeperpagina']) ? |
|
|
|
|
|
|
41
|
8 |
|
ParametriTabella::getParameter($this->parametri['righeperpagina']) : 15; |
|
42
|
8 |
|
$this->colonneordinamento = isset($this->parametri['colonneordinamento']) ? |
|
43
|
8 |
|
json_decode(ParametriTabella::getParameter($this->parametri['colonneordinamento']), true) : array(); |
|
44
|
8 |
|
$this->prefiltri = isset($this->parametri['prefiltri']) ? |
|
|
|
|
|
|
45
|
8 |
|
json_decode(ParametriTabella::getParameter($this->parametri['prefiltri']), true) : array(); |
|
46
|
8 |
|
$this->filtri = isset($this->parametri['filtri']) ? |
|
|
|
|
|
|
47
|
8 |
|
json_decode(ParametriTabella::getParameter($this->parametri['filtri']), true) : array(); |
|
48
|
8 |
|
$this->wheremanuale = isset($this->parametri['wheremanuale']) ? ParametriTabella::getParameter($this->parametri['wheremanuale']) : null; |
|
|
|
|
|
|
49
|
8 |
|
$this->user = $this->parametri['user']; |
|
|
|
|
|
|
50
|
8 |
|
} |
|
51
|
|
|
|
|
52
|
8 |
|
protected function getOpzionitabellaFromCore() |
|
53
|
|
|
{ |
|
54
|
8 |
|
$repoopzionitabelle = $this->em->getRepository(Opzionitabelle::class); |
|
55
|
8 |
|
$repocolonnetabelle = $this->em->getRepository(Colonnetabelle::class); |
|
56
|
8 |
|
$opzionitabella = $repoopzionitabelle->findOpzioniTabella($this->tablename); |
|
|
|
|
|
|
57
|
8 |
|
$colonnetabella = $repocolonnetabelle->findOpzioniColonnetabella($this->tablename, $this->user); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
8 |
|
return array("opzionitabella" => $opzionitabella, "colonnetabella" => $colonnetabella); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
8 |
|
protected function getAllOpzioniTabella() |
|
63
|
|
|
{ |
|
64
|
8 |
|
$opzionibuilder = array(); |
|
65
|
8 |
|
foreach ($this->colonnedatabase as $colonnadatabase) { |
|
66
|
|
|
// Inserire dati da definizione entity |
|
67
|
8 |
|
$this->setOpzioniTabellaDefault($colonnadatabase, $opzionibuilder, null, false); |
|
68
|
|
|
} |
|
69
|
8 |
|
$this->setOpzioniTabellaFromCore($colonnadatabase, $opzionibuilder); |
|
|
|
|
|
|
70
|
8 |
|
$this->setOpzioniTabellaFromModellocolonne($opzionibuilder); |
|
71
|
8 |
|
$this->setOrdinaColonneTabella($opzionibuilder); |
|
72
|
8 |
|
return $opzionibuilder; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
4 |
|
private function bonificanomecampo($nomecampo) |
|
76
|
|
|
{ |
|
77
|
4 |
|
$parti = explode(".", $nomecampo); |
|
|
|
|
|
|
78
|
4 |
|
$campo = ""; |
|
|
|
|
|
|
79
|
4 |
|
for ($index = 0; $index < count($parti); $index++) { |
|
|
|
|
|
|
80
|
4 |
|
if ($index == count($parti) - 1) { |
|
81
|
4 |
|
$campo .= "." . lcfirst($parti[$index]); |
|
|
|
|
|
|
82
|
|
|
} else { |
|
83
|
4 |
|
$campo .= "." . ucfirst($parti[$index]); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
4 |
|
return substr($campo, 1); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
8 |
|
protected function setOpzioniTabellaFromModellocolonne(&$opzionibuilder) |
|
90
|
|
|
{ |
|
91
|
8 |
|
foreach ($this->modellocolonne as $modellocolonna) { |
|
92
|
3 |
|
$campo = $this->bonificanomecampo($modellocolonna["nomecampo"]); |
|
|
|
|
|
|
93
|
3 |
|
foreach ($modellocolonna as $key => $value) { |
|
94
|
3 |
|
if (!array_key_exists($campo, $opzionibuilder)) { |
|
95
|
|
|
$ex = "Fifree: " . $campo . " field table option not found, did you mean one of these:\n" . |
|
|
|
|
|
|
96
|
|
|
implode("\n", array_keys($opzionibuilder)) . |
|
97
|
|
|
" ?"; |
|
|
|
|
|
|
98
|
|
|
throw new \Exception($ex); |
|
99
|
|
|
} |
|
100
|
3 |
|
if ($key=='ordine') { |
|
101
|
2 |
|
$this->setMaxOrdine($value); |
|
102
|
|
|
} |
|
103
|
3 |
|
$opzionibuilder[$campo][$key] = $value; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
8 |
|
} |
|
107
|
|
|
|
|
108
|
8 |
|
protected function setOpzioniTabellaFromCore($colonnadatabase, &$opzionibuilder) |
|
|
|
|
|
|
109
|
|
|
{ |
|
110
|
|
|
|
|
111
|
8 |
|
$colonnetabellacore = $this->opzionitabellacore["colonnetabella"]; |
|
|
|
|
|
|
112
|
|
|
//$nomecolonna = $this->tablename . "." . $colonnadatabase["fieldName"]; |
|
|
|
|
|
|
113
|
|
|
/* @var $colonnatabellacore \Fi\CoreBundle\Entity\Colonnetabelle */ |
|
114
|
8 |
|
foreach ($colonnetabellacore as $colonnatabellacore) { |
|
115
|
3 |
|
$campodabonificare = $colonnatabellacore->getNometabella() . "." . $colonnatabellacore->getNomecampo(); |
|
|
|
|
|
|
116
|
3 |
|
$campo = $this->bonificanomecampo($campodabonificare); |
|
|
|
|
|
|
117
|
3 |
|
if (null !== ($colonnatabellacore->getEtichettaindex())) { |
|
118
|
3 |
|
$opzionibuilder[$campo]["etichetta"] = $colonnatabellacore->getEtichettaindex(); |
|
|
|
|
|
|
119
|
|
|
} |
|
120
|
3 |
|
if (null !== ($colonnatabellacore->getLarghezzaindex())) { |
|
121
|
3 |
|
$opzionibuilder[$campo]["larghezza"] = $colonnatabellacore->getLarghezzaindex(); |
|
|
|
|
|
|
122
|
|
|
} |
|
123
|
3 |
|
if (null !== ($colonnatabellacore->getMostraindex())) { |
|
124
|
3 |
|
$opzionibuilder[$campo]["escluso"] = !$colonnatabellacore->getMostraindex(); |
|
|
|
|
|
|
125
|
|
|
} |
|
126
|
3 |
|
if (null !== ($colonnatabellacore->getOrdineindex())) { |
|
127
|
3 |
|
$opzionibuilder[$campo]["ordine"] = $colonnatabellacore->getOrdineindex(); |
|
|
|
|
|
|
128
|
3 |
|
$this->setMaxOrdine($colonnatabellacore->getOrdineindex()); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
8 |
|
} |
|
132
|
|
|
|
|
133
|
8 |
|
protected function setOpzioniTabellaDefault($infoentity, &$opzionibuilder, $jointable = null, $ricursione = false, $ancestors = array()) |
|
134
|
|
|
{ |
|
135
|
8 |
|
$nometabella = ((isset($jointable)) ? $jointable : $this->tablename); |
|
136
|
8 |
|
if (!in_array($nometabella, $ancestors)) { |
|
137
|
8 |
|
$ancestors[] = $nometabella; |
|
138
|
|
|
} |
|
139
|
8 |
|
$nomecolonna = ucfirst(implode(".", $ancestors)) . "." . $infoentity["fieldName"]; |
|
|
|
|
|
|
140
|
|
|
|
|
141
|
8 |
|
$this->elaboraColonneOpzioniTabellaMancanti($opzionibuilder, $infoentity, $nometabella, $nomecolonna, $ricursione); |
|
142
|
|
|
|
|
143
|
8 |
|
if (isset($infoentity["association"])) { |
|
|
|
|
|
|
144
|
2 |
|
$this->elaboraJoin($opzionibuilder, $infoentity, $ancestors); |
|
145
|
|
|
} |
|
146
|
8 |
|
} |
|
147
|
|
|
|
|
148
|
8 |
|
private function elaboraColonneOpzioniTabellaMancanti(&$opzionibuilder, $colonnadatabase, $nometabella, $nomecolonna, $ricursione) |
|
149
|
|
|
{ |
|
150
|
8 |
|
$opzionibuilder[$nomecolonna] = array( |
|
151
|
8 |
|
"tipocampo" => isset($colonnadatabase["association"]) ? 'join' : $colonnadatabase["type"], |
|
|
|
|
|
|
152
|
8 |
|
"nomecampo" => $nomecolonna, |
|
|
|
|
|
|
153
|
8 |
|
"nometabella" => $nometabella, |
|
|
|
|
|
|
154
|
8 |
|
"entityclass" => $colonnadatabase["entityClass"], |
|
|
|
|
|
|
155
|
8 |
|
"sourceentityclass" => isset($colonnadatabase["sourceEntityClass"]) ? $colonnadatabase["sourceEntityClass"] : null, |
|
|
|
|
|
|
156
|
|
|
"ordine" => null, |
|
|
|
|
|
|
157
|
8 |
|
"etichetta" => ucfirst($colonnadatabase["columnName"]), |
|
|
|
|
|
|
158
|
8 |
|
"larghezza" => 100, |
|
|
|
|
|
|
159
|
8 |
|
"association" => isset($colonnadatabase["association"]) ? $colonnadatabase["association"] : false, |
|
|
|
|
|
|
160
|
8 |
|
"associationtable" => isset($colonnadatabase["associationtable"]) ? $colonnadatabase["associationtable"] : null, |
|
|
|
|
|
|
161
|
8 |
|
"escluso" => ($ricursione === true) ? true : substr($colonnadatabase["fieldName"], -3) == "_id" ? true : false, |
|
|
|
|
|
|
162
|
|
|
); |
|
163
|
8 |
|
} |
|
164
|
|
|
|
|
165
|
2 |
|
private function elaboraJoin(&$opzionibuilder, $colonnadatabase, $ancestors) |
|
166
|
|
|
{ |
|
167
|
2 |
|
$entitycollegata = $colonnadatabase["associationtable"]["targetEntity"]; |
|
|
|
|
|
|
168
|
2 |
|
$utils = new EntityUtils($this->em, $entitycollegata); |
|
|
|
|
|
|
169
|
2 |
|
$tablecollegataname = $this->em->getClassMetadata($entitycollegata)->getTableName(); |
|
170
|
2 |
|
$colonnecollegate = $utils->getEntityColumns($entitycollegata); |
|
|
|
|
|
|
171
|
2 |
|
foreach ($colonnecollegate as $colonnacorrente) { |
|
172
|
2 |
|
if (!isset($colonnacorrente["type"])) { |
|
|
|
|
|
|
173
|
2 |
|
$this->setOpzioniTabellaDefault($colonnacorrente, $opzionibuilder, $tablecollegataname, true, $ancestors); |
|
174
|
2 |
|
continue; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
2 |
|
if (!in_array($tablecollegataname, $ancestors)) { |
|
178
|
2 |
|
$ancestors[] = $tablecollegataname; |
|
179
|
|
|
} |
|
180
|
2 |
|
$nomecampo = ucfirst(implode(".", $ancestors)) . "." . $colonnacorrente["fieldName"]; |
|
|
|
|
|
|
181
|
2 |
|
$opzionibuilder[$nomecampo] = array( |
|
182
|
2 |
|
"tipocampo" => $colonnacorrente["type"], |
|
|
|
|
|
|
183
|
2 |
|
"nomecampo" => $nomecampo, |
|
|
|
|
|
|
184
|
2 |
|
"nometabella" => $tablecollegataname, |
|
|
|
|
|
|
185
|
2 |
|
"entityclass" => $colonnadatabase["entityClass"], |
|
|
|
|
|
|
186
|
2 |
|
"sourceentityclass" => isset($colonnadatabase["sourceEntityClass"]) ? $colonnadatabase["sourceEntityClass"] : null, |
|
|
|
|
|
|
187
|
|
|
"ordine" => null, |
|
|
|
|
|
|
188
|
2 |
|
"etichetta" => ucfirst($colonnacorrente["columnName"]), |
|
|
|
|
|
|
189
|
2 |
|
"larghezza" => 0, |
|
|
|
|
|
|
190
|
|
|
"association" => null, |
|
|
|
|
|
|
191
|
|
|
"associationtable" => null, |
|
|
|
|
|
|
192
|
|
|
"escluso" => true, |
|
|
|
|
|
|
193
|
|
|
); |
|
194
|
|
|
} |
|
195
|
2 |
|
} |
|
196
|
|
|
|
|
197
|
8 |
|
protected function setOrdinaColonneTabella(&$opzionibuilder) |
|
198
|
|
|
{ |
|
199
|
8 |
|
foreach ($opzionibuilder as $key => $opzione) { |
|
200
|
8 |
|
if ($opzione["ordine"] === null) { |
|
|
|
|
|
|
201
|
8 |
|
$newordine = $this->getMaxOrdine() + 10; |
|
|
|
|
|
|
202
|
8 |
|
$opzionibuilder[$key]["ordine"] = $newordine; |
|
|
|
|
|
|
203
|
8 |
|
$this->setMaxOrdine($newordine); |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
// Ordinamento per colonna ordine |
|
207
|
8 |
|
ArrayUtils::sortMultiAssociativeArray($opzionibuilder, "ordine", true); |
|
|
|
|
|
|
208
|
8 |
|
} |
|
209
|
|
|
|
|
210
|
8 |
|
protected function setMaxOrdine($ordinecorrente) |
|
211
|
|
|
{ |
|
212
|
8 |
|
if ($ordinecorrente > $this->maxordine) { |
|
213
|
8 |
|
$this->maxordine = $ordinecorrente; |
|
214
|
|
|
} |
|
215
|
8 |
|
} |
|
216
|
|
|
|
|
217
|
8 |
|
protected function getMaxOrdine() |
|
218
|
|
|
{ |
|
219
|
8 |
|
return $this->maxordine; |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|
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.