1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Utils\Tabella; |
4
|
|
|
|
5
|
|
|
use Cdf\BiCoreBundle\Utils\Entity\EntityUtils; |
6
|
|
|
use Cdf\BiCoreBundle\Utils\Arrays\ArrayUtils; |
7
|
|
|
|
8
|
|
|
trait TabellaOpzioniTrait |
9
|
|
|
{ |
10
|
|
|
use TabellaOpzioniFromCoreTrait, TabellaOpzioniFromModelloColonneTrait; |
11
|
|
|
|
12
|
12 |
|
protected function getAllOpzioniTabella() |
13
|
|
|
{ |
14
|
12 |
|
$opzionibuilder = array(); |
15
|
12 |
|
foreach ($this->colonnedatabase as $colonnadatabase) { |
16
|
|
|
// Inserire dati da definizione entity |
17
|
12 |
|
$this->setOpzioniTabellaDefault($colonnadatabase, $opzionibuilder, null, false); |
18
|
|
|
} |
19
|
12 |
|
$this->setOpzioniTabellaFromModellocolonne($opzionibuilder); |
20
|
12 |
|
$this->setOpzioniTabellaFromCore($colonnadatabase, $opzionibuilder); |
|
|
|
|
21
|
12 |
|
$this->setOrdinaColonneTabella($opzionibuilder); |
22
|
12 |
|
$this->setLarghezzaColonneTabella($opzionibuilder); |
23
|
|
|
|
24
|
12 |
|
return $opzionibuilder; |
25
|
|
|
} |
26
|
|
|
|
27
|
4 |
|
private function getOpzionitabellaCampiExtra($campo, $modellocolonna, &$opzionibuilder) |
28
|
|
|
{ |
29
|
4 |
|
if ((isset($modellocolonna['campoextra']) && true == $modellocolonna['campoextra'])) { |
30
|
1 |
|
$opzionibuilder[$campo] = array( |
31
|
1 |
|
'tipocampo' => $modellocolonna['tipocampo'], |
32
|
1 |
|
'nomecampo' => $campo, |
33
|
1 |
|
'nometabella' => $modellocolonna['nometabella'], |
34
|
|
|
'entityclass' => null, |
35
|
|
|
'sourceentityclass' => null, |
36
|
|
|
'ordine' => null, |
37
|
1 |
|
'etichetta' => $campo, |
38
|
1 |
|
'larghezza' => 5, |
39
|
|
|
'editabile' => false, |
40
|
|
|
'campoextra' => true, |
41
|
|
|
'association' => null, |
42
|
|
|
'associationtable' => null, |
43
|
|
|
'escluso' => false, |
44
|
|
|
); |
45
|
|
|
} |
46
|
4 |
|
} |
47
|
|
|
|
48
|
12 |
|
protected function setOpzioniTabellaDefault($infoentity, &$opzionibuilder, $jointable = null, $ricursione = false, $ancestors = array()) |
49
|
|
|
{ |
50
|
12 |
|
$nometabella = ((isset($jointable)) ? $jointable : $this->tablename); |
51
|
12 |
|
if (!in_array($nometabella, $ancestors)) { |
52
|
12 |
|
$ancestors[] = $nometabella; |
53
|
|
|
} |
54
|
12 |
|
$nomecolonna = ucfirst(implode('.', $ancestors)).'.'.$infoentity['fieldName']; |
55
|
|
|
|
56
|
12 |
|
$this->elaboraColonneOpzioniTabellaMancanti($opzionibuilder, $infoentity, $nometabella, $nomecolonna, $ricursione); |
57
|
|
|
|
58
|
12 |
|
if (isset($infoentity['association'])) { |
59
|
6 |
|
$this->elaboraJoin($opzionibuilder, $infoentity, $ancestors); |
60
|
|
|
} |
61
|
12 |
|
} |
62
|
|
|
|
63
|
12 |
|
private function elaboraColonneOpzioniTabellaMancanti(&$opzionibuilder, $colonnadatabase, $nometabella, $nomecolonna, $ricursione) |
64
|
|
|
{ |
65
|
12 |
|
$opzionibuilder[$nomecolonna] = array( |
66
|
12 |
|
'tipocampo' => isset($colonnadatabase['association']) ? 'join' : $colonnadatabase['type'], |
67
|
12 |
|
'nomecampo' => $nomecolonna, |
68
|
12 |
|
'nometabella' => $nometabella, |
69
|
12 |
|
'entityclass' => $colonnadatabase['entityClass'], |
70
|
12 |
|
'sourceentityclass' => isset($colonnadatabase['sourceEntityClass']) ? $colonnadatabase['sourceEntityClass'] : null, |
71
|
|
|
'ordine' => null, |
72
|
12 |
|
'etichetta' => ucfirst($colonnadatabase['columnName']), |
73
|
12 |
|
'larghezza' => 10, |
74
|
|
|
'editabile' => true, |
75
|
|
|
'campoextra' => false, |
76
|
12 |
|
'association' => isset($colonnadatabase['association']) ? $colonnadatabase['association'] : false, |
77
|
12 |
|
'associationtable' => isset($colonnadatabase['associationtable']) ? $colonnadatabase['associationtable'] : null, |
78
|
|
|
'decodifiche' => null, |
79
|
12 |
|
'escluso' => (true === $ricursione) ? true : '_id' == substr($colonnadatabase['fieldName'], -3) ? true : false, |
80
|
|
|
); |
81
|
12 |
|
} |
82
|
|
|
|
83
|
12 |
|
private function getLarghezzaColonneTabellaTotalePercentuale($opzionibuilder) |
84
|
|
|
{ |
85
|
12 |
|
$larghezzatotalepercentuale = 0; |
86
|
12 |
|
foreach ($opzionibuilder as $opzione) { |
87
|
12 |
|
if (false === $opzione['escluso']) { |
88
|
12 |
|
$larghezzatotalepercentuale += $opzione['larghezza']; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
12 |
|
return $larghezzatotalepercentuale; |
93
|
|
|
} |
94
|
|
|
|
95
|
12 |
|
private function getLarghezzaColonneTabellaPercentualeFinale() |
96
|
|
|
{ |
97
|
|
|
// il 5% si lascia per la ruzzolina in fondo alla riga, il 3% si lascia per il checkbox in testa alla riga, |
98
|
|
|
// quindi per le colonne dati resta il 92% |
99
|
12 |
|
$percentualefinale = 95; // il 5% si lascia per la ruzzolina in fondo |
100
|
12 |
|
if (true === $this->getTabellaParameter('multiselezione')) { |
|
|
|
|
101
|
|
|
$percentualefinale -= 3; |
102
|
|
|
} |
103
|
|
|
|
104
|
12 |
|
return $percentualefinale; |
105
|
|
|
} |
106
|
|
|
|
107
|
12 |
|
private function setLarghezzaColonneTabella(&$opzionibuilder) |
108
|
|
|
{ |
109
|
12 |
|
$larghezzatotalepercentuale = $this->getLarghezzaColonneTabellaTotalePercentuale($opzionibuilder); |
110
|
12 |
|
$percentualefinale = $this->getLarghezzaColonneTabellaPercentualeFinale(); |
|
|
|
|
111
|
12 |
|
$percentualerelativatotale = $percentualefinale * 100 / $larghezzatotalepercentuale; |
|
|
|
|
112
|
12 |
|
if (0 != $percentualefinale - $larghezzatotalepercentuale) { |
113
|
12 |
|
foreach ($opzionibuilder as $key => $opzione) { |
114
|
12 |
|
if (false === $opzione['escluso']) { |
115
|
12 |
|
$larghezzapercentualericalcolata = ceil($opzione['larghezza'] * $percentualerelativatotale / 100); |
|
|
|
|
116
|
12 |
|
$opzionibuilder[$key]['larghezza'] = ($larghezzapercentualericalcolata < 5 ? 5 : $larghezzapercentualericalcolata); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
12 |
|
} |
121
|
|
|
|
122
|
6 |
|
private function elaboraJoin(&$opzionibuilder, $colonnadatabase, $ancestors) |
123
|
|
|
{ |
124
|
6 |
|
$entitycollegata = $colonnadatabase['associationtable']['targetEntity']; |
|
|
|
|
125
|
6 |
|
$utils = new EntityUtils($this->em, $entitycollegata); |
|
|
|
|
126
|
6 |
|
$tablecollegataname = $this->em->getClassMetadata($entitycollegata)->getTableName(); |
127
|
6 |
|
$colonnecollegate = $utils->getEntityColumns($entitycollegata); |
|
|
|
|
128
|
6 |
|
foreach ($colonnecollegate as $colonnacorrente) { |
129
|
6 |
|
if (!isset($colonnacorrente['type'])) { |
130
|
5 |
|
$this->setOpzioniTabellaDefault($colonnacorrente, $opzionibuilder, $tablecollegataname, true, $ancestors); |
131
|
5 |
|
continue; |
132
|
|
|
} |
133
|
|
|
|
134
|
6 |
|
if (!in_array($tablecollegataname, $ancestors)) { |
135
|
6 |
|
$ancestors[] = $tablecollegataname; |
136
|
|
|
} |
137
|
6 |
|
$nomecampo = ucfirst(implode('.', $ancestors)).'.'.$colonnacorrente['fieldName']; |
|
|
|
|
138
|
6 |
|
$opzionibuilder[$nomecampo] = array( |
139
|
6 |
|
'tipocampo' => $colonnacorrente['type'], |
140
|
6 |
|
'nomecampo' => $nomecampo, |
141
|
6 |
|
'nometabella' => $tablecollegataname, |
142
|
6 |
|
'entityclass' => $colonnadatabase['entityClass'], |
143
|
6 |
|
'sourceentityclass' => isset($colonnadatabase['sourceEntityClass']) ? $colonnadatabase['sourceEntityClass'] : null, |
144
|
|
|
'ordine' => null, |
145
|
6 |
|
'etichetta' => ucfirst($colonnacorrente['columnName']), |
146
|
6 |
|
'larghezza' => 0, |
147
|
|
|
'editabile' => false, |
148
|
|
|
'campoextra' => false, |
149
|
|
|
'association' => null, |
150
|
|
|
'associationtable' => null, |
151
|
|
|
'escluso' => true, |
152
|
|
|
); |
153
|
|
|
} |
154
|
6 |
|
} |
155
|
|
|
|
156
|
12 |
|
protected function setOrdinaColonneTabella(&$opzionibuilder) |
157
|
|
|
{ |
158
|
12 |
|
foreach ($opzionibuilder as $key => $opzione) { |
159
|
12 |
|
if (null === $opzione['ordine']) { |
160
|
12 |
|
$newordine = $this->getMaxOrdine() + 10; |
|
|
|
|
161
|
12 |
|
$opzionibuilder[$key]['ordine'] = $newordine; |
162
|
12 |
|
$this->setMaxOrdine($newordine); |
|
|
|
|
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
// Ordinamento per colonna ordine |
166
|
12 |
|
ArrayUtils::sortMultiAssociativeArray($opzionibuilder, 'ordine', true); |
167
|
12 |
|
} |
168
|
|
|
|
169
|
5 |
|
private function bonificaNomeCampo($nomecampo) |
170
|
|
|
{ |
171
|
5 |
|
$parti = explode('.', $nomecampo); |
172
|
5 |
|
$campo = ''; |
173
|
5 |
|
for ($index = 0; $index < count($parti); ++$index) { |
|
|
|
|
174
|
5 |
|
if ($index == count($parti) - 1) { |
175
|
5 |
|
$campo .= '.'.lcfirst($parti[$index]); |
176
|
|
|
} else { |
177
|
5 |
|
$campo .= '.'.ucfirst($parti[$index]); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
181
|
5 |
|
return substr($campo, 1); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|