|
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 $em; |
|
27
|
|
|
|
|
28
|
2 |
|
protected function parseParameters() |
|
29
|
|
|
{ |
|
30
|
2 |
|
$this->tablename = ParametriTabella::getParameter($this->parametri['tablename']); |
|
|
|
|
|
|
31
|
2 |
|
$this->entityname = ParametriTabella::getParameter($this->parametri['entityclass']); |
|
|
|
|
|
|
32
|
2 |
|
$this->entityname = str_replace("FiCoreBundle", "CoreBundle", $this->entityname); |
|
|
|
|
|
|
33
|
2 |
|
$this->permessi = json_decode(ParametriTabella::getParameter($this->parametri['permessi'])); |
|
|
|
|
|
|
34
|
2 |
|
$this->modellocolonne = isset($this->parametri['modellocolonne']) ? |
|
|
|
|
|
|
35
|
2 |
|
json_decode(ParametriTabella::getParameter($this->parametri['modellocolonne']), true) : array(); |
|
36
|
2 |
|
$this->paginacorrente = ParametriTabella::getParameter($this->parametri['paginacorrente']); |
|
|
|
|
|
|
37
|
2 |
|
$this->paginetotali = ParametriTabella::getParameter($this->parametri['paginetotali']); |
|
|
|
|
|
|
38
|
2 |
|
$this->righeperpagina = isset($this->parametri['righeperpagina']) ? |
|
|
|
|
|
|
39
|
2 |
|
ParametriTabella::getParameter($this->parametri['righeperpagina']) : 15; |
|
40
|
2 |
|
$this->colonneordinamento = isset($this->parametri['colonneordinamento']) ? |
|
41
|
2 |
|
json_decode(ParametriTabella::getParameter($this->parametri['colonneordinamento']), true) : array(); |
|
42
|
2 |
|
$this->prefiltri = isset($this->parametri['prefiltri']) ? |
|
|
|
|
|
|
43
|
2 |
|
json_decode(ParametriTabella::getParameter($this->parametri['prefiltri']), true) : array(); |
|
44
|
2 |
|
$this->filtri = isset($this->parametri['filtri']) ? |
|
|
|
|
|
|
45
|
2 |
|
json_decode(ParametriTabella::getParameter($this->parametri['filtri']), true) : array(); |
|
46
|
2 |
|
$this->wheremanuale = isset($this->parametri['wheremanuale']) ? ParametriTabella::getParameter($this->parametri['wheremanuale']) : null; |
|
|
|
|
|
|
47
|
2 |
|
} |
|
48
|
2 |
|
protected function getOpzionitabellaFromCore() |
|
49
|
|
|
{ |
|
50
|
2 |
|
$repoopzionitabelle = $this->em->getRepository(Opzionitabelle::class); |
|
51
|
2 |
|
$repocolonnetabelle = $this->em->getRepository(Colonnetabelle::class); |
|
52
|
2 |
|
$opzionitabella = $repoopzionitabelle->findOpzioniTabella($this->tablename); |
|
|
|
|
|
|
53
|
2 |
|
$colonnetabella = $repocolonnetabelle->findOpzioniColonnetabella($this->tablename); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
2 |
|
return array("opzionitabella" => $opzionitabella, "colonnetabella" => $colonnetabella); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
2 |
|
protected function getAllOpzioniTabella() |
|
58
|
|
|
{ |
|
59
|
2 |
|
$opzionibuilder = array(); |
|
60
|
2 |
|
foreach ($this->colonnedatabase as $colonnadatabase) { |
|
61
|
2 |
|
$nomecolonna = $this->tablename . "." . $colonnadatabase["fieldName"]; |
|
|
|
|
|
|
62
|
2 |
|
if (array_key_exists($this->tablename . "." . $colonnadatabase["fieldName"], $this->modellocolonne)) { |
|
|
|
|
|
|
63
|
1 |
|
$this->setOpzioniTabellaFromEntity($colonnadatabase, $opzionibuilder); |
|
64
|
|
|
} else { |
|
65
|
2 |
|
$this->setOpzioniTabellaFromCore($colonnadatabase, $opzionibuilder); |
|
66
|
|
|
} |
|
67
|
2 |
|
if (!array_key_exists($nomecolonna, $opzionibuilder)) { |
|
68
|
|
|
// Inserire dati da definizione db |
|
69
|
2 |
|
$this->setOpzioniTabellaMancanti($colonnadatabase, $opzionibuilder, null, false, 0); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
2 |
|
$this->getOpzioniTabellaOrdinate($opzionibuilder); |
|
|
|
|
|
|
74
|
|
|
//dump($opzionibuilder);Exit; |
|
|
|
|
|
|
75
|
2 |
|
return $opzionibuilder; |
|
76
|
|
|
} |
|
77
|
1 |
|
protected function setOpzioniTabellaFromEntity($colonnadatabase, &$opzionibuilder) |
|
78
|
|
|
{ |
|
79
|
1 |
|
$nomecolonna = $this->tablename . "." . $colonnadatabase["fieldName"]; |
|
|
|
|
|
|
80
|
1 |
|
$modellocolonna = $this->modellocolonne[$nomecolonna]; |
|
81
|
1 |
|
$etichetta = isset($modellocolonna["etichetta"]) && $modellocolonna["etichetta"] ? |
|
|
|
|
|
|
82
|
1 |
|
$modellocolonna["etichetta"] : ucfirst($colonnadatabase["fieldName"]); |
|
|
|
|
|
|
83
|
1 |
|
$larghezza = isset($modellocolonna["larghezza"]) && $modellocolonna["larghezza"] ? |
|
|
|
|
|
|
84
|
1 |
|
$modellocolonna["larghezza"] : 100; |
|
|
|
|
|
|
85
|
1 |
|
$escluso = isset($modellocolonna["escluso"]) && $modellocolonna["escluso"] ? |
|
|
|
|
|
|
86
|
1 |
|
$modellocolonna["escluso"] : false; |
|
|
|
|
|
|
87
|
1 |
|
$ordine = isset($modellocolonna["ordine"]) && $modellocolonna["ordine"] ? |
|
|
|
|
|
|
88
|
1 |
|
$modellocolonna["ordine"] : null; |
|
|
|
|
|
|
89
|
1 |
|
$this->setMaxOrdine($ordine); |
|
|
|
|
|
|
90
|
1 |
|
$opzionibuilder[$nomecolonna] = array( |
|
91
|
1 |
|
"tipocampo" => $colonnadatabase["type"], |
|
|
|
|
|
|
92
|
1 |
|
"nomecampo" => $colonnadatabase["fieldName"], |
|
|
|
|
|
|
93
|
1 |
|
"nometabella" => $modellocolonna["nometabella"], |
|
|
|
|
|
|
94
|
1 |
|
"entityclass" => $colonnadatabase["entityClass"], |
|
|
|
|
|
|
95
|
1 |
|
"livello" => 0, |
|
|
|
|
|
|
96
|
|
|
"sourceentityclass" => null, |
|
|
|
|
|
|
97
|
1 |
|
"ordine" => $ordine, |
|
|
|
|
|
|
98
|
1 |
|
"etichetta" => $etichetta, |
|
|
|
|
|
|
99
|
1 |
|
"larghezza" => $larghezza, |
|
|
|
|
|
|
100
|
|
|
"association" => false, |
|
|
|
|
|
|
101
|
1 |
|
"escluso" => $escluso, |
|
|
|
|
|
|
102
|
|
|
); |
|
103
|
1 |
|
} |
|
104
|
2 |
|
protected function setOpzioniTabellaFromCore($colonnadatabase, &$opzionibuilder) |
|
105
|
|
|
{ |
|
106
|
2 |
|
$colonnetabellacore = $this->opzionitabellacore["colonnetabella"]; |
|
|
|
|
|
|
107
|
2 |
|
$nomecolonna = $this->tablename . "." . $colonnadatabase["fieldName"]; |
|
|
|
|
|
|
108
|
|
|
/* @var $colonnatabellacore \Fi\CoreBundle\Entity\Colonnetabelle */ |
|
109
|
2 |
|
foreach ($colonnetabellacore as $colonnatabellacore) { |
|
110
|
2 |
|
if ($nomecolonna == $colonnatabellacore->getNometabella() . "." . $colonnatabellacore->getNomecampo()) { |
|
|
|
|
|
|
111
|
1 |
|
$etichetta = $colonnatabellacore->getEtichettaindex() ? |
|
112
|
1 |
|
$colonnatabellacore->getEtichettaindex() : ucfirst($colonnadatabase["fieldName"]); |
|
|
|
|
|
|
113
|
1 |
|
$larghezza = $colonnatabellacore->getLarghezzaindex() ? |
|
114
|
1 |
|
$colonnatabellacore->getLarghezzaindex() : 100; |
|
115
|
1 |
|
$escluso = $colonnatabellacore->getMostraindex() === null ? false : !$colonnatabellacore->getMostraindex(); |
|
|
|
|
|
|
116
|
1 |
|
$ordine = $colonnatabellacore->getOrdineindex() ? $colonnatabellacore->getOrdineindex() : null; |
|
|
|
|
|
|
117
|
1 |
|
$this->setMaxOrdine($ordine); |
|
118
|
|
|
|
|
119
|
1 |
|
$opzionibuilder[$nomecolonna] = array( |
|
120
|
1 |
|
"tipocampo" => $colonnadatabase["type"], |
|
|
|
|
|
|
121
|
1 |
|
"nomecampo" => $colonnadatabase["fieldName"], |
|
|
|
|
|
|
122
|
1 |
|
"nometabella" => $colonnatabellacore->getNometabella(), |
|
|
|
|
|
|
123
|
1 |
|
"entityclass" => $colonnadatabase["entityClass"], |
|
|
|
|
|
|
124
|
1 |
|
"livello" => 0, |
|
|
|
|
|
|
125
|
|
|
"sourceentityclass" => null, |
|
|
|
|
|
|
126
|
1 |
|
"ordine" => $ordine, |
|
|
|
|
|
|
127
|
1 |
|
"etichetta" => $etichetta, |
|
|
|
|
|
|
128
|
1 |
|
"larghezza" => $larghezza, |
|
|
|
|
|
|
129
|
|
|
"association" => false, |
|
|
|
|
|
|
130
|
1 |
|
"escluso" => $escluso, |
|
|
|
|
|
|
131
|
|
|
); |
|
132
|
2 |
|
break; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
2 |
|
} |
|
136
|
2 |
|
protected function setOpzioniTabellaMancanti($colonnadatabase, &$opzionibuilder, $tabellacollegata = null, $ricursione = false, $livello = 0) |
|
137
|
|
|
{ |
|
138
|
2 |
|
$nometabella = ((isset($tabellacollegata)) ? $tabellacollegata : $this->tablename); |
|
139
|
2 |
|
$nomecolonna = $nometabella . "." . $colonnadatabase["fieldName"]; |
|
|
|
|
|
|
140
|
|
|
|
|
141
|
2 |
|
$this->elaboraColonneOpzioniTabellaMancanti($opzionibuilder, $colonnadatabase, $nometabella, $nomecolonna, $livello, $ricursione); |
|
142
|
|
|
|
|
143
|
2 |
|
if (isset($colonnadatabase["association"])) { |
|
|
|
|
|
|
144
|
|
|
$this->elaboraJoin($opzionibuilder, $colonnadatabase, $livello); |
|
145
|
|
|
} |
|
146
|
2 |
|
} |
|
147
|
2 |
|
private function elaboraColonneOpzioniTabellaMancanti(&$opzionibuilder, $colonnadatabase, $nometabella, $nomecolonna, $livello, $ricursione) |
|
148
|
|
|
{ |
|
149
|
2 |
|
$opzionibuilder[$nomecolonna] = array( |
|
150
|
2 |
|
"tipocampo" => isset($colonnadatabase["association"]) ? 'join' : $colonnadatabase["type"], |
|
|
|
|
|
|
151
|
2 |
|
"nomecampo" => $colonnadatabase["fieldName"], |
|
|
|
|
|
|
152
|
2 |
|
"nometabella" => $nometabella, |
|
|
|
|
|
|
153
|
2 |
|
"entityclass" => $colonnadatabase["entityClass"], |
|
|
|
|
|
|
154
|
2 |
|
"livello" => $livello, |
|
|
|
|
|
|
155
|
2 |
|
"sourceentityclass" => isset($colonnadatabase["sourceEntityClass"]) ? $colonnadatabase["sourceEntityClass"] : null, |
|
|
|
|
|
|
156
|
|
|
"ordine" => null, |
|
|
|
|
|
|
157
|
2 |
|
"etichetta" => ucfirst($colonnadatabase["columnName"]), |
|
|
|
|
|
|
158
|
2 |
|
"larghezza" => 100, |
|
|
|
|
|
|
159
|
2 |
|
"association" => isset($colonnadatabase["association"]) ? $colonnadatabase["association"] : false, |
|
|
|
|
|
|
160
|
2 |
|
"associationtable" => isset($colonnadatabase["associationtable"]) ? $colonnadatabase["associationtable"] : null, |
|
|
|
|
|
|
161
|
2 |
|
"escluso" => ($ricursione === true) ? true : substr($colonnadatabase["fieldName"], -3) == "_id" ? true : false, |
|
|
|
|
|
|
162
|
|
|
); |
|
163
|
2 |
|
} |
|
164
|
|
|
private function elaboraJoin(&$opzionibuilder, $colonnadatabase, $livello) |
|
165
|
|
|
{ |
|
166
|
|
|
$entitycollegata = $colonnadatabase["associationtable"]["targetEntity"]; |
|
|
|
|
|
|
167
|
|
|
$utils = new EntityUtils($this->em, $entitycollegata); |
|
|
|
|
|
|
168
|
|
|
$tablecollegataname = $this->em->getClassMetadata($entitycollegata)->getTableName(); |
|
169
|
|
|
$colonnecollegate = $utils->getEntityColumns($entitycollegata); |
|
|
|
|
|
|
170
|
|
|
foreach ($colonnecollegate as $colonnacorrente) { |
|
171
|
|
|
if (!isset($colonnacorrente["type"])) { |
|
|
|
|
|
|
172
|
|
|
$this->setOpzioniTabellaMancanti($colonnacorrente, $opzionibuilder, $tablecollegataname, true, $livello + 1); |
|
173
|
|
|
continue; |
|
174
|
|
|
} |
|
175
|
|
|
//dump($tablecollegataname);exit; |
|
|
|
|
|
|
176
|
|
|
$opzionibuilder[$tablecollegataname . "." . $colonnacorrente["fieldName"]] = array( |
|
|
|
|
|
|
177
|
|
|
"tipocampo" => $colonnacorrente["type"], |
|
|
|
|
|
|
178
|
|
|
"nomecampo" => $tablecollegataname . "." . $colonnacorrente["fieldName"], |
|
|
|
|
|
|
179
|
|
|
"nometabella" => $tablecollegataname, |
|
|
|
|
|
|
180
|
|
|
"entityclass" => $colonnadatabase["entityClass"], |
|
|
|
|
|
|
181
|
|
|
"livello" => $livello, |
|
|
|
|
|
|
182
|
|
|
"sourceentityclass" => isset($colonnadatabase["sourceEntityClass"]) ? $colonnadatabase["sourceEntityClass"] : null, |
|
|
|
|
|
|
183
|
|
|
"ordine" => null, |
|
|
|
|
|
|
184
|
|
|
"etichetta" => ucfirst($colonnacorrente["columnName"]), |
|
|
|
|
|
|
185
|
|
|
"larghezza" => 0, |
|
|
|
|
|
|
186
|
|
|
"association" => null, |
|
|
|
|
|
|
187
|
|
|
"associationtable" => null, |
|
|
|
|
|
|
188
|
|
|
"escluso" => true, |
|
|
|
|
|
|
189
|
|
|
); |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|
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.