|
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
|
|
|
// Inserire dati da definizione entity |
|
62
|
2 |
|
$this->setOpzioniTabellaDefault($colonnadatabase, $opzionibuilder, null, false); |
|
63
|
|
|
} |
|
64
|
2 |
|
$this->setOpzioniTabellaFromCore($colonnadatabase, $opzionibuilder); |
|
|
|
|
|
|
65
|
2 |
|
$this->setOpzioniTabellaFromModellocolonne($opzionibuilder); |
|
66
|
2 |
|
$this->setOrdinaColonneTabella($opzionibuilder); |
|
67
|
2 |
|
return $opzionibuilder; |
|
68
|
|
|
} |
|
69
|
2 |
|
protected function setOpzioniTabellaFromModellocolonne(&$opzionibuilder) |
|
70
|
|
|
{ |
|
71
|
2 |
|
foreach ($this->modellocolonne as $campo => $modellocolonna) { |
|
72
|
1 |
|
foreach ($modellocolonna as $key => $value) { |
|
73
|
1 |
|
if (!array_key_exists($campo, $opzionibuilder)) { |
|
74
|
|
|
$ex = "Fifree: " . $campo . " field table option not found, did you mean one of these:\n" . |
|
|
|
|
|
|
75
|
|
|
implode("\n", array_keys($opzionibuilder)) . |
|
76
|
|
|
" ?"; |
|
|
|
|
|
|
77
|
|
|
throw new \Exception($ex); |
|
78
|
|
|
} |
|
79
|
1 |
|
$opzionibuilder[$campo][$key] = $value; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
2 |
|
} |
|
83
|
2 |
|
protected function setOpzioniTabellaFromCore($colonnadatabase, &$opzionibuilder) |
|
84
|
|
|
{ |
|
85
|
|
|
|
|
86
|
2 |
|
$colonnetabellacore = $this->opzionitabellacore["colonnetabella"]; |
|
|
|
|
|
|
87
|
2 |
|
$nomecolonna = $this->tablename . "." . $colonnadatabase["fieldName"]; |
|
|
|
|
|
|
88
|
|
|
/* @var $colonnatabellacore \Fi\CoreBundle\Entity\Colonnetabelle */ |
|
89
|
2 |
|
foreach ($colonnetabellacore as $colonnatabellacore) { |
|
90
|
2 |
|
if ($nomecolonna == $colonnatabellacore->getNometabella() . "." . $colonnatabellacore->getNomecampo()) { |
|
|
|
|
|
|
91
|
|
|
$etichetta = $colonnatabellacore->getEtichettaindex() ? |
|
92
|
|
|
$colonnatabellacore->getEtichettaindex() : ucfirst($colonnadatabase["fieldName"]); |
|
|
|
|
|
|
93
|
|
|
$larghezza = $colonnatabellacore->getLarghezzaindex() ? |
|
94
|
|
|
$colonnatabellacore->getLarghezzaindex() : 100; |
|
95
|
|
|
$escluso = $colonnatabellacore->getMostraindex() === null ? false : !$colonnatabellacore->getMostraindex(); |
|
|
|
|
|
|
96
|
|
|
$ordine = $colonnatabellacore->getOrdineindex() ? $colonnatabellacore->getOrdineindex() : null; |
|
|
|
|
|
|
97
|
|
|
$this->setMaxOrdine($ordine); |
|
98
|
|
|
|
|
99
|
|
|
$opzionibuilder[$nomecolonna] = array( |
|
100
|
|
|
"tipocampo" => $colonnadatabase["type"], |
|
|
|
|
|
|
101
|
|
|
"nomecampo" => $colonnadatabase["fieldName"], |
|
|
|
|
|
|
102
|
|
|
"nometabella" => $colonnatabellacore->getNometabella(), |
|
|
|
|
|
|
103
|
|
|
"entityclass" => $colonnadatabase["entityClass"], |
|
|
|
|
|
|
104
|
|
|
"sourceentityclass" => null, |
|
|
|
|
|
|
105
|
|
|
"ordine" => $ordine, |
|
|
|
|
|
|
106
|
|
|
"etichetta" => $etichetta, |
|
|
|
|
|
|
107
|
|
|
"larghezza" => $larghezza, |
|
|
|
|
|
|
108
|
|
|
"association" => false, |
|
|
|
|
|
|
109
|
|
|
"escluso" => $escluso, |
|
|
|
|
|
|
110
|
|
|
); |
|
111
|
2 |
|
break; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
2 |
|
} |
|
115
|
2 |
|
protected function setOpzioniTabellaDefault($infoentity, &$opzionibuilder, $jointable = null, $ricursione = false, $ancestors = array()) |
|
116
|
|
|
{ |
|
117
|
2 |
|
$nometabella = ((isset($jointable)) ? $jointable : $this->tablename); |
|
118
|
2 |
|
if (!in_array($nometabella, $ancestors)) { |
|
119
|
2 |
|
$ancestors[] = $nometabella; |
|
120
|
|
|
} |
|
121
|
2 |
|
$nomecolonna = ucfirst(implode(".", $ancestors)) . "." . $infoentity["fieldName"]; |
|
|
|
|
|
|
122
|
|
|
|
|
123
|
2 |
|
$this->elaboraColonneOpzioniTabellaMancanti($opzionibuilder, $infoentity, $nometabella, $nomecolonna, $ricursione); |
|
124
|
|
|
|
|
125
|
2 |
|
if (isset($infoentity["association"])) { |
|
|
|
|
|
|
126
|
|
|
$this->elaboraJoin($opzionibuilder, $infoentity, $ancestors); |
|
127
|
|
|
} |
|
128
|
2 |
|
} |
|
129
|
2 |
|
private function elaboraColonneOpzioniTabellaMancanti(&$opzionibuilder, $colonnadatabase, $nometabella, $nomecolonna, $ricursione) |
|
130
|
|
|
{ |
|
131
|
2 |
|
$opzionibuilder[$nomecolonna] = array( |
|
132
|
2 |
|
"tipocampo" => isset($colonnadatabase["association"]) ? 'join' : $colonnadatabase["type"], |
|
|
|
|
|
|
133
|
2 |
|
"nomecampo" => $colonnadatabase["fieldName"], |
|
|
|
|
|
|
134
|
2 |
|
"nometabella" => $nometabella, |
|
|
|
|
|
|
135
|
2 |
|
"entityclass" => $colonnadatabase["entityClass"], |
|
|
|
|
|
|
136
|
2 |
|
"sourceentityclass" => isset($colonnadatabase["sourceEntityClass"]) ? $colonnadatabase["sourceEntityClass"] : null, |
|
|
|
|
|
|
137
|
|
|
"ordine" => null, |
|
|
|
|
|
|
138
|
2 |
|
"etichetta" => ucfirst($colonnadatabase["columnName"]), |
|
|
|
|
|
|
139
|
2 |
|
"larghezza" => 100, |
|
|
|
|
|
|
140
|
2 |
|
"association" => isset($colonnadatabase["association"]) ? $colonnadatabase["association"] : false, |
|
|
|
|
|
|
141
|
2 |
|
"associationtable" => isset($colonnadatabase["associationtable"]) ? $colonnadatabase["associationtable"] : null, |
|
|
|
|
|
|
142
|
2 |
|
"escluso" => ($ricursione === true) ? true : substr($colonnadatabase["fieldName"], -3) == "_id" ? true : false, |
|
|
|
|
|
|
143
|
|
|
); |
|
144
|
2 |
|
} |
|
145
|
|
|
private function elaboraJoin(&$opzionibuilder, $colonnadatabase, $ancestors) |
|
146
|
|
|
{ |
|
147
|
|
|
$entitycollegata = $colonnadatabase["associationtable"]["targetEntity"]; |
|
|
|
|
|
|
148
|
|
|
$utils = new EntityUtils($this->em, $entitycollegata); |
|
|
|
|
|
|
149
|
|
|
$tablecollegataname = $this->em->getClassMetadata($entitycollegata)->getTableName(); |
|
150
|
|
|
$colonnecollegate = $utils->getEntityColumns($entitycollegata); |
|
|
|
|
|
|
151
|
|
|
foreach ($colonnecollegate as $colonnacorrente) { |
|
152
|
|
|
if (!isset($colonnacorrente["type"])) { |
|
|
|
|
|
|
153
|
|
|
$this->setOpzioniTabellaDefault($colonnacorrente, $opzionibuilder, $tablecollegataname, true, $ancestors); |
|
154
|
|
|
continue; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
if (!in_array($tablecollegataname, $ancestors)) { |
|
158
|
|
|
$ancestors[] = $tablecollegataname; |
|
159
|
|
|
} |
|
160
|
|
|
$opzionibuilder[ucfirst(implode(".", $ancestors)) . "." . $colonnacorrente["fieldName"]] = array( |
|
|
|
|
|
|
161
|
|
|
"tipocampo" => $colonnacorrente["type"], |
|
|
|
|
|
|
162
|
|
|
"nomecampo" => $tablecollegataname . "." . $colonnacorrente["fieldName"], |
|
|
|
|
|
|
163
|
|
|
"nometabella" => $tablecollegataname, |
|
|
|
|
|
|
164
|
|
|
"entityclass" => $colonnadatabase["entityClass"], |
|
|
|
|
|
|
165
|
|
|
"sourceentityclass" => isset($colonnadatabase["sourceEntityClass"]) ? $colonnadatabase["sourceEntityClass"] : null, |
|
|
|
|
|
|
166
|
|
|
"ordine" => null, |
|
|
|
|
|
|
167
|
|
|
"etichetta" => ucfirst($colonnacorrente["columnName"]), |
|
|
|
|
|
|
168
|
|
|
"larghezza" => 0, |
|
|
|
|
|
|
169
|
|
|
"association" => null, |
|
|
|
|
|
|
170
|
|
|
"associationtable" => null, |
|
|
|
|
|
|
171
|
|
|
"escluso" => true, |
|
|
|
|
|
|
172
|
|
|
); |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
2 |
|
protected function setOrdinaColonneTabella(&$opzionibuilder) |
|
176
|
|
|
{ |
|
177
|
2 |
|
$newordine = $this->getMaxOrdine() + 10; |
|
178
|
2 |
|
foreach ($opzionibuilder as $key => $opzione) { |
|
179
|
2 |
|
if ($opzione["ordine"] === null) { |
|
|
|
|
|
|
180
|
2 |
|
$opzionibuilder[$key]["ordine"] = $newordine; |
|
|
|
|
|
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
// Ordinamento per colonna ordine |
|
184
|
2 |
|
ArrayUtils::sortMultiAssociativeArray($opzionibuilder, "ordine", true); |
|
|
|
|
|
|
185
|
2 |
|
} |
|
186
|
|
|
protected function setMaxOrdine($ordinecorrente) |
|
187
|
|
|
{ |
|
188
|
|
|
if ($ordinecorrente > $this->maxordine) { |
|
189
|
|
|
$this->maxordine = $ordinecorrente; |
|
|
|
|
|
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
2 |
|
protected function getMaxOrdine() |
|
193
|
|
|
{ |
|
194
|
2 |
|
return $this->maxordine; |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
|
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.