|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Utils\Tabella; |
|
4
|
|
|
|
|
5
|
|
|
use Cdf\BiCoreBundle\Service\Permessi\PermessiManager; |
|
6
|
|
|
use Cdf\BiCoreBundle\Utils\Entity\EntityUtils; |
|
7
|
|
|
use Cdf\BiCoreBundle\Utils\Entity\ModelUtils; |
|
8
|
|
|
use Cdf\BiCoreBundle\Utils\Api\ApiUtils; |
|
9
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
10
|
|
|
use Symfony\Component\Security\Core\Security; |
|
11
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
|
12
|
|
|
|
|
13
|
|
|
use Cdf\BiCoreBundle\Service\Api\ApiManager; |
|
14
|
|
|
use Cdf\BiCoreBundle\Service\Api\Oauth2TokenService; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @SuppressWarnings(PHPMD.TooManyFields) |
|
18
|
|
|
*/ |
|
19
|
|
|
class Tabella |
|
20
|
|
|
{ |
|
21
|
|
|
use TabellaQueryTrait, |
|
|
|
|
|
|
22
|
|
|
TabellaOpzioniTrait, |
|
23
|
|
|
TabellaDecoderTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** @var array<mixed> */ |
|
26
|
|
|
protected array $parametri; |
|
27
|
|
|
/** @var array<mixed> */ |
|
28
|
|
|
protected array $colonnedatabase ; |
|
29
|
|
|
/** @var array<mixed> */ |
|
30
|
|
|
protected $opzionitabellacore; |
|
31
|
|
|
/** @var array<mixed> */ |
|
32
|
|
|
protected $configurazionecolonnetabella; |
|
33
|
|
|
protected string $entityname; |
|
34
|
|
|
protected string $tablename; |
|
35
|
|
|
|
|
36
|
|
|
/** @var array<mixed> */ |
|
37
|
|
|
protected array $modellocolonne; |
|
38
|
|
|
protected int $paginacorrente; |
|
39
|
|
|
protected int $righeperpagina; |
|
40
|
|
|
protected bool $estraituttirecords; |
|
41
|
|
|
|
|
42
|
|
|
/** @var array<mixed> */ |
|
43
|
|
|
protected array $prefiltri; |
|
44
|
|
|
/** @var array<mixed> */ |
|
45
|
|
|
protected array $filtri; |
|
46
|
|
|
|
|
47
|
|
|
/** @var string|null */ |
|
48
|
|
|
protected $wheremanuale; |
|
49
|
|
|
/** @var array<mixed> */ |
|
50
|
|
|
protected $colonneordinamento; |
|
51
|
|
|
/** @var mixed */ |
|
52
|
|
|
protected $permessi; |
|
53
|
|
|
/** @var array<mixed> */ |
|
54
|
|
|
protected $records; |
|
55
|
|
|
protected int $paginetotali; |
|
56
|
|
|
protected int $righetotali; |
|
57
|
|
|
|
|
58
|
|
|
/** @var string|null */ |
|
59
|
|
|
protected $traduzionefiltri; |
|
60
|
|
|
protected int $maxordine = 0; |
|
61
|
|
|
protected EntityManagerInterface $em; |
|
62
|
|
|
/** @phpstan-ignore-next-line */ |
|
63
|
|
|
protected $user; |
|
64
|
|
|
protected string $apiController; |
|
65
|
|
|
protected string $apiCollection; |
|
66
|
|
|
protected ApiUtils $apiBook; |
|
67
|
|
|
|
|
68
|
|
|
protected ApiManager $apiManager; |
|
69
|
|
|
protected string $apiProjectCollection; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* |
|
73
|
|
|
* @param ManagerRegistry $doctrine |
|
74
|
|
|
* @param array<mixed> $parametri |
|
75
|
|
|
*/ |
|
76
|
12 |
|
public function __construct(ManagerRegistry $doctrine, array $parametri) |
|
77
|
|
|
{ |
|
78
|
12 |
|
$this->parametri = $parametri; |
|
79
|
12 |
|
if (isset($this->parametri['em'])) { |
|
80
|
|
|
/** @phpstan-ignore-next-line */ |
|
81
|
12 |
|
$this->em = $doctrine->getManager(ParametriTabella::getParameter($this->parametri['em'])); |
|
82
|
|
|
} else { |
|
83
|
|
|
/** @phpstan-ignore-next-line */ |
|
84
|
|
|
$this->em = $doctrine->getManager(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
12 |
|
$this->tablename = $this->getTabellaParameter('tablename'); |
|
88
|
12 |
|
$this->entityname = $this->getTabellaParameter('entityclass'); |
|
89
|
12 |
|
$this->entityname = str_replace('FiBiCoreBundle', 'BiCoreBundle', $this->entityname); |
|
90
|
12 |
|
$this->permessi = json_decode($this->getTabellaParameter('permessi')); |
|
|
|
|
|
|
91
|
12 |
|
$this->modellocolonne = json_decode($this->getTabellaParameter('modellocolonne', '{}'), true); |
|
92
|
12 |
|
$this->paginacorrente = (int) $this->getTabellaParameter('paginacorrente'); |
|
93
|
12 |
|
$this->paginetotali = (int) $this->getTabellaParameter('paginetotali'); |
|
94
|
12 |
|
$this->righeperpagina = (int) $this->getTabellaParameter('righeperpagina', 15); |
|
95
|
|
|
|
|
96
|
12 |
|
$this->estraituttirecords = '1' === $this->getTabellaParameter('estraituttirecords', 0) ? true : false; |
|
97
|
12 |
|
$this->colonneordinamento = json_decode($this->getTabellaParameter('colonneordinamento', '{}'), true); |
|
98
|
12 |
|
$this->prefiltri = json_decode($this->getTabellaParameter('prefiltri', '{}'), true); |
|
99
|
12 |
|
$this->filtri = json_decode($this->getTabellaParameter('filtri', '{}'), true); |
|
100
|
12 |
|
$this->wheremanuale = $this->getTabellaParameter('wheremanuale', null); |
|
101
|
12 |
|
$this->user = $this->parametri['user']; |
|
102
|
|
|
|
|
103
|
12 |
|
if (!isset($this->parametri['isapi'])) { |
|
104
|
|
|
/** @phpstan-ignore-next-line */ |
|
105
|
12 |
|
$utils = new EntityUtils($this->em); |
|
106
|
12 |
|
$this->colonnedatabase = $utils->getEntityColumns($this->entityname); |
|
107
|
|
|
} else { |
|
108
|
|
|
$this->apiController = $this->getTabellaParameter('apicontroller'); |
|
109
|
|
|
$this->apiCollection = $this->getTabellaParameter('apicollection'); |
|
110
|
|
|
|
|
111
|
|
|
$this->apiBook = new ApiUtils($this->apiCollection); |
|
112
|
|
|
|
|
113
|
|
|
$this->apiManager = new ApiManager( |
|
114
|
|
|
$this->getTabellaParameter('oauth2_enabled', "0"), |
|
115
|
|
|
new Oauth2TokenService( |
|
116
|
|
|
$this->getTabellaParameter('oauth2_endpoint', ""), |
|
117
|
|
|
$this->getTabellaParameter('oauth2_clientkey', "")//$this->getParameter("bi_core.oauth2_clientkey") |
|
118
|
|
|
) |
|
119
|
|
|
); |
|
120
|
|
|
|
|
121
|
|
|
$this->apiManager->setProjectName($this->getTabellaParameter('api_project', "no_project_given")); |
|
122
|
|
|
$this->apiProjectCollection = $this->getTabellaParameter('api_project_collection', "no_project_collection_given"); |
|
123
|
|
|
|
|
124
|
|
|
$projectRoot = $this->apiBook->getProjectRoot($this->apiManager->getProjectName()); |
|
125
|
|
|
|
|
126
|
|
|
$projectConfiguration = $projectRoot."Configuration"; |
|
127
|
|
|
$projectHeaderSelector = $projectRoot."HeaderSelector"; |
|
128
|
|
|
|
|
129
|
|
|
$config = $projectConfiguration::getDefaultConfiguration(); |
|
130
|
|
|
$headerSelector = new $projectHeaderSelector($config); |
|
131
|
|
|
|
|
132
|
|
|
$this->apiManager->setApiClientConfigs($headerSelector, $config); |
|
133
|
|
|
|
|
134
|
|
|
$this->apiManager->setApiController($this->apiProjectCollection); |
|
135
|
|
|
|
|
136
|
|
|
//in this moment is not set for API |
|
137
|
|
|
$modelUtils = new ModelUtils(); |
|
138
|
|
|
$this->colonnedatabase = $modelUtils->getEntityColumns($this->entityname); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
12 |
|
$this->opzionitabellacore = $this->getOpzionitabellaFromCore(); |
|
142
|
12 |
|
$this->configurazionecolonnetabella = $this->getAllOpzioniTabella(); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
protected function getCollectionName(): string |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->apiProjectCollection; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* |
|
152
|
|
|
* @param string $name |
|
153
|
|
|
* @param mixed|null $default |
|
154
|
|
|
* @return mixed|null |
|
155
|
|
|
*/ |
|
156
|
12 |
|
private function getTabellaParameter(string $name, $default = null) |
|
157
|
|
|
{ |
|
158
|
12 |
|
$risposta = null; |
|
159
|
12 |
|
if (isset($this->parametri[$name])) { |
|
160
|
12 |
|
$risposta = ParametriTabella::getParameter($this->parametri[$name]); |
|
161
|
|
|
} else { |
|
162
|
12 |
|
$risposta = $default; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
12 |
|
return $risposta; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
12 |
|
public function calcolaPagineTotali(int $limit) : float |
|
169
|
|
|
{ |
|
170
|
12 |
|
if (0 == $this->righetotali) { |
|
171
|
1 |
|
return 1; |
|
172
|
|
|
} |
|
173
|
|
|
/* calcola in mumero di pagine totali necessarie */ |
|
174
|
12 |
|
return ceil($this->righetotali / (0 == $limit ? 1 : $limit)); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
12 |
|
public function getPaginacorrente() : int |
|
178
|
|
|
{ |
|
179
|
12 |
|
return $this->paginacorrente; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
7 |
|
public function getPaginetotali() : int |
|
183
|
|
|
{ |
|
184
|
7 |
|
return $this->paginetotali; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
12 |
|
public function getRigheperpagina() : int |
|
188
|
|
|
{ |
|
189
|
12 |
|
return $this->righeperpagina; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
12 |
|
public function getRighetotali() : int |
|
193
|
|
|
{ |
|
194
|
12 |
|
return $this->righetotali; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* |
|
199
|
|
|
* @return string|null |
|
200
|
|
|
*/ |
|
201
|
7 |
|
public function getTraduzionefiltri() |
|
202
|
|
|
{ |
|
203
|
7 |
|
return $this->traduzionefiltri; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* |
|
208
|
|
|
* @return array<mixed> |
|
209
|
|
|
*/ |
|
210
|
10 |
|
public function getConfigurazionecolonnetabella() : array |
|
211
|
|
|
{ |
|
212
|
10 |
|
return $this->configurazionecolonnetabella; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
12 |
|
protected function setMaxOrdine(int $ordinecorrente) : void |
|
216
|
|
|
{ |
|
217
|
12 |
|
if ($ordinecorrente > $this->maxordine) { |
|
218
|
12 |
|
$this->maxordine = $ordinecorrente; |
|
219
|
|
|
} |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
12 |
|
protected function getMaxOrdine() : int |
|
223
|
|
|
{ |
|
224
|
12 |
|
return $this->maxordine; |
|
225
|
|
|
} |
|
226
|
|
|
} |
|
227
|
|
|
|