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