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
|
|
|
|
10
|
|
|
class TabellaOpzioni extends TabellaDecoder |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
protected $maxordine = 0; |
14
|
|
|
|
15
|
12 |
|
protected function getOpzionitabellaFromCore() |
16
|
|
|
{ |
17
|
12 |
|
$repoopzionitabelle = $this->em->getRepository(Opzionitabelle::class); |
18
|
12 |
|
$repocolonnetabelle = $this->em->getRepository(Colonnetabelle::class); |
19
|
12 |
|
$opzionitabella = $repoopzionitabelle->findOpzioniTabella($this->tablename); |
|
|
|
|
20
|
12 |
|
$colonnetabella = $repocolonnetabelle->findOpzioniColonnetabella($this->tablename, $this->user); |
|
|
|
|
21
|
|
|
|
22
|
12 |
|
return array("opzionitabella" => $opzionitabella, "colonnetabella" => $colonnetabella); |
|
|
|
|
23
|
|
|
} |
24
|
12 |
|
protected function getAllOpzioniTabella() |
25
|
|
|
{ |
26
|
12 |
|
$opzionibuilder = array(); |
27
|
12 |
|
foreach ($this->colonnedatabase as $colonnadatabase) { |
28
|
|
|
// Inserire dati da definizione entity |
29
|
12 |
|
$this->setOpzioniTabellaDefault($colonnadatabase, $opzionibuilder, null, false); |
30
|
|
|
} |
31
|
12 |
|
$this->setOpzioniTabellaFromModellocolonne($opzionibuilder); |
32
|
12 |
|
$this->setOpzioniTabellaFromCore($colonnadatabase, $opzionibuilder); |
|
|
|
|
33
|
12 |
|
$this->setOrdinaColonneTabella($opzionibuilder); |
34
|
12 |
|
return $opzionibuilder; |
35
|
|
|
} |
36
|
12 |
|
protected function setOpzioniTabellaFromModellocolonne(&$opzionibuilder) |
37
|
|
|
{ |
38
|
12 |
|
foreach ($this->modellocolonne as $modellocolonna) { |
39
|
4 |
|
$campo = $this->bonificaNomeCampo($modellocolonna["nomecampo"]); |
|
|
|
|
40
|
4 |
|
foreach ($modellocolonna as $key => $value) { |
41
|
4 |
|
if (!array_key_exists($campo, $opzionibuilder)) { |
42
|
|
|
$ex = "Fifree: " . $campo . " field table option not found, did you mean one of these:\n" . |
|
|
|
|
43
|
|
|
implode("\n", array_keys($opzionibuilder)) . |
44
|
|
|
" ?"; |
|
|
|
|
45
|
|
|
throw new \Exception($ex); |
46
|
|
|
} |
47
|
4 |
|
if ($key == 'ordine') { |
48
|
3 |
|
$this->setMaxOrdine($value); |
49
|
|
|
} |
50
|
4 |
|
$opzionibuilder[$campo][$key] = $value; |
51
|
|
|
} |
52
|
|
|
} |
53
|
12 |
|
} |
54
|
12 |
|
protected function setOpzioniTabellaFromCore($colonnadatabase, &$opzionibuilder) |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
|
57
|
12 |
|
$colonnetabellacore = $this->opzionitabellacore["colonnetabella"]; |
|
|
|
|
58
|
|
|
//$nomecolonna = $this->tablename . "." . $colonnadatabase["fieldName"]; |
|
|
|
|
59
|
|
|
/* @var $colonnatabellacore \Fi\CoreBundle\Entity\Colonnetabelle */ |
60
|
12 |
|
foreach ($colonnetabellacore as $colonnatabellacore) { |
61
|
3 |
|
$campodabonificare = $colonnatabellacore->getNometabella() . "." . $colonnatabellacore->getNomecampo(); |
|
|
|
|
62
|
3 |
|
$campo = $this->bonificaNomeCampo($campodabonificare); |
|
|
|
|
63
|
3 |
|
if (null !== ($colonnatabellacore->getEtichettaindex())) { |
64
|
3 |
|
$opzionibuilder[$campo]["etichetta"] = $colonnatabellacore->getEtichettaindex(); |
|
|
|
|
65
|
|
|
} |
66
|
3 |
|
if (null !== ($colonnatabellacore->getLarghezzaindex())) { |
67
|
3 |
|
$opzionibuilder[$campo]["larghezza"] = $colonnatabellacore->getLarghezzaindex(); |
|
|
|
|
68
|
|
|
} |
69
|
3 |
|
if (null !== ($colonnatabellacore->getMostraindex())) { |
70
|
3 |
|
$opzionibuilder[$campo]["escluso"] = !$colonnatabellacore->getMostraindex(); |
|
|
|
|
71
|
|
|
} |
72
|
3 |
|
if (null !== ($colonnatabellacore->getOrdineindex())) { |
73
|
3 |
|
$opzionibuilder[$campo]["ordine"] = $colonnatabellacore->getOrdineindex(); |
|
|
|
|
74
|
3 |
|
$this->setMaxOrdine($colonnatabellacore->getOrdineindex()); |
75
|
|
|
} |
76
|
|
|
} |
77
|
12 |
|
} |
78
|
12 |
|
protected function setOpzioniTabellaDefault($infoentity, &$opzionibuilder, $jointable = null, $ricursione = false, $ancestors = array()) |
79
|
|
|
{ |
80
|
12 |
|
$nometabella = ((isset($jointable)) ? $jointable : $this->tablename); |
81
|
12 |
|
if (!in_array($nometabella, $ancestors)) { |
82
|
12 |
|
$ancestors[] = $nometabella; |
83
|
|
|
} |
84
|
12 |
|
$nomecolonna = ucfirst(implode(".", $ancestors)) . "." . $infoentity["fieldName"]; |
|
|
|
|
85
|
|
|
|
86
|
12 |
|
$this->elaboraColonneOpzioniTabellaMancanti($opzionibuilder, $infoentity, $nometabella, $nomecolonna, $ricursione); |
87
|
|
|
|
88
|
12 |
|
if (isset($infoentity["association"])) { |
|
|
|
|
89
|
6 |
|
$this->elaboraJoin($opzionibuilder, $infoentity, $ancestors); |
90
|
|
|
} |
91
|
12 |
|
} |
92
|
12 |
|
private function elaboraColonneOpzioniTabellaMancanti(&$opzionibuilder, $colonnadatabase, $nometabella, $nomecolonna, $ricursione) |
93
|
|
|
{ |
94
|
12 |
|
$opzionibuilder[$nomecolonna] = array( |
95
|
12 |
|
"tipocampo" => isset($colonnadatabase["association"]) ? 'join' : $colonnadatabase["type"], |
|
|
|
|
96
|
12 |
|
"nomecampo" => $nomecolonna, |
|
|
|
|
97
|
12 |
|
"nometabella" => $nometabella, |
|
|
|
|
98
|
12 |
|
"entityclass" => $colonnadatabase["entityClass"], |
|
|
|
|
99
|
12 |
|
"sourceentityclass" => isset($colonnadatabase["sourceEntityClass"]) ? $colonnadatabase["sourceEntityClass"] : null, |
|
|
|
|
100
|
|
|
"ordine" => null, |
|
|
|
|
101
|
12 |
|
"etichetta" => ucfirst($colonnadatabase["columnName"]), |
|
|
|
|
102
|
12 |
|
"larghezza" => 100, |
|
|
|
|
103
|
12 |
|
"association" => isset($colonnadatabase["association"]) ? $colonnadatabase["association"] : false, |
|
|
|
|
104
|
12 |
|
"associationtable" => isset($colonnadatabase["associationtable"]) ? $colonnadatabase["associationtable"] : null, |
|
|
|
|
105
|
12 |
|
"escluso" => ($ricursione === true) ? true : substr($colonnadatabase["fieldName"], -3) == "_id" ? true : false, |
|
|
|
|
106
|
|
|
); |
107
|
12 |
|
} |
108
|
6 |
|
private function elaboraJoin(&$opzionibuilder, $colonnadatabase, $ancestors) |
109
|
|
|
{ |
110
|
6 |
|
$entitycollegata = $colonnadatabase["associationtable"]["targetEntity"]; |
|
|
|
|
111
|
6 |
|
$utils = new EntityUtils($this->em, $entitycollegata); |
|
|
|
|
112
|
6 |
|
$tablecollegataname = $this->em->getClassMetadata($entitycollegata)->getTableName(); |
113
|
6 |
|
$colonnecollegate = $utils->getEntityColumns($entitycollegata); |
|
|
|
|
114
|
6 |
|
foreach ($colonnecollegate as $colonnacorrente) { |
115
|
6 |
|
if (!isset($colonnacorrente["type"])) { |
|
|
|
|
116
|
5 |
|
$this->setOpzioniTabellaDefault($colonnacorrente, $opzionibuilder, $tablecollegataname, true, $ancestors); |
117
|
5 |
|
continue; |
118
|
|
|
} |
119
|
|
|
|
120
|
6 |
|
if (!in_array($tablecollegataname, $ancestors)) { |
121
|
6 |
|
$ancestors[] = $tablecollegataname; |
122
|
|
|
} |
123
|
6 |
|
$nomecampo = ucfirst(implode(".", $ancestors)) . "." . $colonnacorrente["fieldName"]; |
|
|
|
|
124
|
6 |
|
$opzionibuilder[$nomecampo] = array( |
125
|
6 |
|
"tipocampo" => $colonnacorrente["type"], |
|
|
|
|
126
|
6 |
|
"nomecampo" => $nomecampo, |
|
|
|
|
127
|
6 |
|
"nometabella" => $tablecollegataname, |
|
|
|
|
128
|
6 |
|
"entityclass" => $colonnadatabase["entityClass"], |
|
|
|
|
129
|
6 |
|
"sourceentityclass" => isset($colonnadatabase["sourceEntityClass"]) ? $colonnadatabase["sourceEntityClass"] : null, |
|
|
|
|
130
|
|
|
"ordine" => null, |
|
|
|
|
131
|
6 |
|
"etichetta" => ucfirst($colonnacorrente["columnName"]), |
|
|
|
|
132
|
6 |
|
"larghezza" => 0, |
|
|
|
|
133
|
|
|
"association" => null, |
|
|
|
|
134
|
|
|
"associationtable" => null, |
|
|
|
|
135
|
|
|
"escluso" => true, |
|
|
|
|
136
|
|
|
); |
137
|
|
|
} |
138
|
6 |
|
} |
139
|
12 |
|
protected function setOrdinaColonneTabella(&$opzionibuilder) |
140
|
|
|
{ |
141
|
12 |
|
foreach ($opzionibuilder as $key => $opzione) { |
142
|
12 |
|
if ($opzione["ordine"] === null) { |
|
|
|
|
143
|
12 |
|
$newordine = $this->getMaxOrdine() + 10; |
|
|
|
|
144
|
12 |
|
$opzionibuilder[$key]["ordine"] = $newordine; |
|
|
|
|
145
|
12 |
|
$this->setMaxOrdine($newordine); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
// Ordinamento per colonna ordine |
149
|
12 |
|
ArrayUtils::sortMultiAssociativeArray($opzionibuilder, "ordine", true); |
|
|
|
|
150
|
12 |
|
} |
151
|
12 |
|
protected function setMaxOrdine($ordinecorrente) |
152
|
|
|
{ |
153
|
12 |
|
if ($ordinecorrente > $this->maxordine) { |
154
|
12 |
|
$this->maxordine = $ordinecorrente; |
155
|
|
|
} |
156
|
12 |
|
} |
157
|
12 |
|
protected function getMaxOrdine() |
158
|
|
|
{ |
159
|
12 |
|
return $this->maxordine; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
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.