|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Fi\CoreBundle\Utils; |
|
4
|
|
|
|
|
5
|
|
|
class GrigliaUtils |
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
public static $decodificaop; |
|
9
|
|
|
public static $precarattere; |
|
10
|
|
|
public static $postcarattere; |
|
11
|
|
|
|
|
12
|
|
|
const LARGHEZZAMASSIMA = 500; |
|
|
|
|
|
|
13
|
|
|
const MOLTIPLICATORELARGHEZZA = 10; |
|
14
|
|
|
|
|
15
|
1 |
|
public static function init() |
|
16
|
|
|
{ |
|
17
|
|
|
// i possibili operatori di ciascuna ricerca sono |
|
18
|
|
|
//questi: ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc', 'nu', 'nn'] |
|
|
|
|
|
|
19
|
|
|
//significano questo |
|
20
|
|
|
//['equal','not equal', 'less', 'less or equal','greater','greater or equal', |
|
|
|
|
|
|
21
|
|
|
//'begins with','does not begin with','is in','is not in','ends with','does not end with', |
|
|
|
|
|
|
22
|
|
|
//'contains','does not contain', 'is null', 'is not null'] |
|
|
|
|
|
|
23
|
|
|
//sulla base dell'operatore impostato per la singola ricerca si impostano tre vettori |
|
24
|
|
|
//il promo contiene l'operatore da usare in query |
|
25
|
|
|
|
|
26
|
1 |
|
self::$decodificaop = array( |
|
27
|
1 |
|
'eq' => '=', |
|
28
|
1 |
|
'ne' => '<>', |
|
29
|
1 |
|
'lt' => '<', |
|
30
|
1 |
|
'le' => '<=', |
|
31
|
1 |
|
'gt' => '>', |
|
32
|
1 |
|
'ge' => '>=', |
|
33
|
1 |
|
'bw' => 'LIKE', |
|
34
|
1 |
|
'bn' => 'NOT LIKE', |
|
35
|
1 |
|
'in' => 'IN', |
|
36
|
1 |
|
'ni' => 'NOT IN', |
|
37
|
1 |
|
'ew' => 'LIKE', |
|
38
|
1 |
|
'en' => 'NOT LIKE', |
|
39
|
1 |
|
'cn' => 'LIKE', |
|
40
|
1 |
|
'nc' => 'NOT LIKE', |
|
41
|
1 |
|
'nu' => 'IS', |
|
42
|
1 |
|
'nn' => 'IS NOT', |
|
43
|
1 |
|
'nt' => '<>', |
|
44
|
1 |
|
); |
|
45
|
|
|
// questo contiene il carattere da usare prima del campo dati in query dipendentemente dal tipo di operatore |
|
46
|
1 |
|
self::$precarattere = array( |
|
47
|
1 |
|
'eq' => '', |
|
48
|
1 |
|
'ne' => '', |
|
49
|
1 |
|
'lt' => '', |
|
50
|
1 |
|
'le' => '', |
|
51
|
1 |
|
'gt' => '', |
|
52
|
1 |
|
'ge' => '', |
|
53
|
1 |
|
'bw' => 'lower(\'', |
|
54
|
1 |
|
'bn' => 'lower(\'', |
|
55
|
1 |
|
'in' => '(', |
|
56
|
1 |
|
'ni' => '(', |
|
57
|
1 |
|
'ew' => 'lower(\'%', |
|
58
|
1 |
|
'en' => 'lower(\'%', |
|
59
|
1 |
|
'cn' => 'lower(\'%', |
|
60
|
1 |
|
'nc' => 'lower(\'%', |
|
61
|
1 |
|
'nu' => 'NULL', |
|
62
|
1 |
|
'nn' => 'NULL', |
|
63
|
1 |
|
'nt' => 'TRUE', |
|
64
|
1 |
|
); |
|
65
|
|
|
|
|
66
|
|
|
// questo contiene il carattere da usare dopo il campo dati in query dipendentemente dal tipo di operatore |
|
67
|
1 |
|
self::$postcarattere = array( |
|
68
|
1 |
|
'eq' => '', |
|
69
|
1 |
|
'ne' => '', |
|
70
|
1 |
|
'lt' => '', |
|
71
|
1 |
|
'le' => '', |
|
72
|
1 |
|
'gt' => '', |
|
73
|
1 |
|
'ge' => '', |
|
74
|
1 |
|
'bw' => '%\')', |
|
75
|
1 |
|
'bn' => '%\')', |
|
76
|
1 |
|
'in' => ')', |
|
77
|
1 |
|
'ni' => ')', |
|
78
|
1 |
|
'ew' => '\')', |
|
79
|
1 |
|
'en' => '\')', |
|
80
|
1 |
|
'cn' => '%\')', |
|
81
|
1 |
|
'nc' => '%\')', |
|
82
|
1 |
|
'nu' => '', |
|
83
|
1 |
|
'nn' => '', |
|
84
|
1 |
|
'nt' => '',); |
|
85
|
1 |
|
} |
|
86
|
|
|
|
|
87
|
1 |
|
public static function setVettoriPerData() |
|
88
|
|
|
{ |
|
89
|
1 |
|
self::$precarattere['eq'] = "'"; |
|
|
|
|
|
|
90
|
1 |
|
self::$precarattere['ne'] = "'"; |
|
|
|
|
|
|
91
|
1 |
|
self::$precarattere['lt'] = "'"; |
|
|
|
|
|
|
92
|
1 |
|
self::$precarattere['le'] = "'"; |
|
|
|
|
|
|
93
|
1 |
|
self::$precarattere['gt'] = "'"; |
|
|
|
|
|
|
94
|
1 |
|
self::$precarattere['ge'] = "'"; |
|
|
|
|
|
|
95
|
1 |
|
self::$postcarattere['eq'] = "'"; |
|
96
|
1 |
|
self::$postcarattere['ne'] = "'"; |
|
97
|
1 |
|
self::$postcarattere['lt'] = "'"; |
|
98
|
1 |
|
self::$postcarattere['le'] = "'"; |
|
99
|
1 |
|
self::$postcarattere['gt'] = "'"; |
|
100
|
1 |
|
self::$postcarattere['ge'] = "'"; |
|
101
|
1 |
|
} |
|
102
|
|
|
|
|
103
|
|
|
public static function setVettoriPerBoolean() |
|
104
|
|
|
{ |
|
105
|
|
|
self::setVettoriPerData(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
1 |
|
public static function setVettoriPerStringa() |
|
109
|
|
|
{ |
|
110
|
1 |
|
self::$precarattere['eq'] = "lower('"; |
|
|
|
|
|
|
111
|
1 |
|
self::$precarattere['ne'] = "lower('"; |
|
|
|
|
|
|
112
|
1 |
|
self::$precarattere['lt'] = "lower('"; |
|
|
|
|
|
|
113
|
1 |
|
self::$precarattere['le'] = "lower('"; |
|
|
|
|
|
|
114
|
1 |
|
self::$precarattere['gt'] = "lower('"; |
|
|
|
|
|
|
115
|
1 |
|
self::$precarattere['ge'] = "lower('"; |
|
|
|
|
|
|
116
|
1 |
|
self::$postcarattere['eq'] = "')"; |
|
117
|
1 |
|
self::$postcarattere['ne'] = "')"; |
|
118
|
1 |
|
self::$postcarattere['lt'] = "')"; |
|
119
|
1 |
|
self::$postcarattere['le'] = "')"; |
|
120
|
1 |
|
self::$postcarattere['gt'] = "')"; |
|
121
|
1 |
|
self::$postcarattere['ge'] = "')"; |
|
122
|
1 |
|
} |
|
123
|
|
|
|
|
124
|
1 |
|
public static function setVettoriPerNumero() |
|
125
|
|
|
{ |
|
126
|
1 |
|
self::$precarattere['eq'] = ''; |
|
|
|
|
|
|
127
|
1 |
|
self::$precarattere['ne'] = ''; |
|
|
|
|
|
|
128
|
1 |
|
self::$precarattere['lt'] = ''; |
|
|
|
|
|
|
129
|
1 |
|
self::$precarattere['le'] = ''; |
|
|
|
|
|
|
130
|
1 |
|
self::$precarattere['gt'] = ''; |
|
|
|
|
|
|
131
|
1 |
|
self::$precarattere['ge'] = ''; |
|
|
|
|
|
|
132
|
1 |
|
self::$postcarattere['eq'] = ''; |
|
133
|
1 |
|
self::$postcarattere['ne'] = ''; |
|
134
|
1 |
|
self::$postcarattere['lt'] = ''; |
|
135
|
1 |
|
self::$postcarattere['le'] = ''; |
|
136
|
1 |
|
self::$postcarattere['gt'] = ''; |
|
137
|
1 |
|
self::$postcarattere['ge'] = ''; |
|
138
|
1 |
|
} |
|
139
|
|
|
|
|
140
|
4 |
|
public static function getCampiEsclusi($riga, $output) |
|
141
|
|
|
{ |
|
142
|
4 |
|
$campoescluso = null; |
|
143
|
4 |
|
if ($output == 'stampa') { |
|
144
|
|
|
if ($riga->hasMostrastampa() == false) { |
|
145
|
|
|
$campoescluso = $riga->getNomecampo(); |
|
146
|
|
|
} |
|
147
|
|
|
} else { |
|
148
|
4 |
|
if ($riga->hasMostraindex() == false) { |
|
149
|
|
|
$campoescluso = $riga->getNomecampo(); |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
4 |
|
return $campoescluso; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
13 |
|
public static function getUserCustomTableFields($em, $nometabella, $operatore) |
|
157
|
|
|
{ |
|
158
|
13 |
|
$q = $em->getRepository('FiCoreBundle:Tabelle')->findBy(array('operatori_id' => $operatore['id'], 'nometabella' => $nometabella)); |
|
159
|
|
|
|
|
160
|
13 |
|
if (!$q) { |
|
161
|
13 |
|
unset($q); |
|
162
|
13 |
|
$q = $em->getRepository('FiCoreBundle:Tabelle')->findBy(array('operatori_id' => null, 'nometabella' => $nometabella)); |
|
163
|
13 |
|
} |
|
164
|
|
|
|
|
165
|
13 |
|
return $q; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
13 |
|
public static function etichettecampi($parametri = array()) |
|
169
|
|
|
{ |
|
170
|
13 |
|
if (!isset($parametri['nometabella'])) { |
|
171
|
|
|
return false; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
13 |
|
$output = GrigliaParametriUtils::getOuputType($parametri); |
|
175
|
|
|
|
|
176
|
13 |
|
$nometabella = $parametri['nometabella']; |
|
177
|
|
|
|
|
178
|
13 |
|
$doctrine = GrigliaParametriUtils::getDoctrineByEm($parametri); |
|
|
|
|
|
|
179
|
13 |
|
$doctrineficore = GrigliaParametriUtils::getDoctrineFiCoreByEm($parametri, $doctrine); |
|
|
|
|
|
|
180
|
13 |
|
$container = $parametri['container']; |
|
|
|
|
|
|
181
|
13 |
|
$gestionepermessi = $container->get("ficorebundle.gestionepermessi"); |
|
|
|
|
|
|
182
|
|
|
|
|
183
|
13 |
|
$operatorecorrente = $gestionepermessi->utentecorrente(); |
|
184
|
|
|
|
|
185
|
13 |
|
$etichette = array(); |
|
186
|
|
|
|
|
187
|
13 |
|
$q = self::getUserCustomTableFields($doctrineficore, $nometabella, $operatorecorrente); |
|
188
|
|
|
|
|
189
|
13 |
|
if ($q) { |
|
190
|
4 |
|
foreach ($q as $riga) { |
|
191
|
4 |
|
if ($output == 'stampa') { |
|
192
|
|
|
$etichette[$riga->getNomecampo()] = $riga->getEtichettastampa(); |
|
193
|
|
|
} else { |
|
194
|
4 |
|
$etichette[$riga->getNomecampo()] = $riga->getEtichettaindex(); |
|
195
|
|
|
} |
|
196
|
4 |
|
} |
|
197
|
4 |
|
} |
|
198
|
|
|
|
|
199
|
13 |
|
return $etichette; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
13 |
|
public static function larghezzecampi($parametri = array()) |
|
203
|
|
|
{ |
|
204
|
13 |
|
if (!isset($parametri['nometabella'])) { |
|
205
|
|
|
return false; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
13 |
|
$output = GrigliaParametriUtils::getOuputType($parametri); |
|
209
|
|
|
|
|
210
|
13 |
|
$nometabella = $parametri['nometabella']; |
|
211
|
|
|
|
|
212
|
13 |
|
$doctrine = GrigliaParametriUtils::getDoctrineByEm($parametri); |
|
|
|
|
|
|
213
|
13 |
|
$doctrineficore = GrigliaParametriUtils::getDoctrineFiCoreByEm($parametri, $doctrine); |
|
214
|
|
|
|
|
215
|
13 |
|
$container = $parametri['container']; |
|
|
|
|
|
|
216
|
13 |
|
$gestionepermessi = $container->get("ficorebundle.gestionepermessi"); |
|
|
|
|
|
|
217
|
13 |
|
$operatorecorrente = $gestionepermessi->utentecorrente(); |
|
218
|
|
|
|
|
219
|
13 |
|
$etichette = array(); |
|
220
|
|
|
|
|
221
|
13 |
|
$q = self::getUserCustomTableFields($doctrineficore, $nometabella, $operatorecorrente); |
|
222
|
|
|
|
|
223
|
13 |
|
if (!$q) { |
|
224
|
9 |
|
return $etichette; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
4 |
|
foreach ($q as $riga) { |
|
228
|
4 |
|
if ($output == 'stampa') { |
|
229
|
|
|
$etichette[$riga->getNomecampo()] = $riga->getLarghezzastampa(); |
|
230
|
|
|
} else { |
|
231
|
4 |
|
$etichette[$riga->getNomecampo()] = $riga->getLarghezzaindex(); |
|
232
|
|
|
} |
|
233
|
4 |
|
} |
|
234
|
|
|
|
|
235
|
4 |
|
return $etichette; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
13 |
|
public static function ordinecolonne($parametri = array()) |
|
239
|
|
|
{ |
|
240
|
13 |
|
if (!isset($parametri['nometabella'])) { |
|
241
|
|
|
return false; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
13 |
|
$output = GrigliaParametriUtils::getOuputType($parametri); |
|
245
|
|
|
|
|
246
|
13 |
|
$nometabella = $parametri['nometabella']; |
|
247
|
|
|
|
|
248
|
13 |
|
$doctrine = GrigliaParametriUtils::getDoctrineByEm($parametri); |
|
|
|
|
|
|
249
|
13 |
|
$doctrineficore = GrigliaParametriUtils::getDoctrineFiCoreByEm($parametri, $doctrine); |
|
250
|
13 |
|
$container = $parametri['container']; |
|
|
|
|
|
|
251
|
|
|
|
|
252
|
13 |
|
$gestionepermessi = $container->get("ficorebundle.gestionepermessi"); |
|
|
|
|
|
|
253
|
|
|
|
|
254
|
13 |
|
$operatorecorrente = $gestionepermessi->utentecorrente(); |
|
255
|
|
|
|
|
256
|
13 |
|
$ordine = array(); |
|
257
|
|
|
|
|
258
|
13 |
|
$q = self::getUserCustomTableFields($doctrineficore, $nometabella, $operatorecorrente); |
|
259
|
|
|
|
|
260
|
13 |
|
if ($q) { |
|
261
|
4 |
|
foreach ($q as $riga) { |
|
262
|
4 |
|
if ($output == 'stampa') { |
|
263
|
|
|
if ($riga->getOrdinestampa()) { |
|
264
|
|
|
$ordine[$riga->getOrdinestampa()] = $riga->getNomecampo(); |
|
265
|
|
|
} |
|
266
|
|
|
} else { |
|
267
|
4 |
|
if ($riga->getOrdineindex()) { |
|
268
|
|
|
$ordine[$riga->getOrdineindex()] = $riga->getNomecampo(); |
|
269
|
|
|
} |
|
270
|
|
|
} |
|
271
|
4 |
|
} |
|
272
|
4 |
|
if (count($ordine) > 0) { |
|
273
|
|
|
ksort($ordine); |
|
274
|
|
|
} |
|
275
|
4 |
|
} |
|
276
|
|
|
|
|
277
|
13 |
|
$ordinecolonne = GrigliaColonneUtils::getColonneOrdinate($ordine); |
|
278
|
|
|
|
|
279
|
13 |
|
return $ordinecolonne; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* Translates a string with underscores into camel case (e.g. first_name -> firstName). |
|
284
|
|
|
* |
|
285
|
|
|
* @param array $parametri |
|
286
|
|
|
* |
|
287
|
|
|
* @return string $str translated into camel caps |
|
288
|
|
|
*/ |
|
289
|
13 |
|
public static function toCamelCase($parametri = array()) |
|
290
|
|
|
{ |
|
291
|
13 |
|
$str = $parametri['str']; |
|
|
|
|
|
|
292
|
13 |
|
$capitalise_first_char = isset($parametri['primamaiuscola']) ? $parametri['primamaiuscola'] : false; |
|
293
|
|
|
|
|
294
|
13 |
|
if ($capitalise_first_char) { |
|
295
|
13 |
|
$str[0] = strtoupper($str[0]); |
|
296
|
13 |
|
} |
|
297
|
13 |
|
$func = function ($matches) { |
|
298
|
4 |
|
return strtoupper($matches[1]); |
|
299
|
13 |
|
}; |
|
300
|
|
|
|
|
301
|
13 |
|
return preg_replace_callback('/_([a-z])/', $func, $str); |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
13 |
|
public static function getOpzioniTabella($doctrineficore, $nometabella, &$testata) |
|
305
|
|
|
{ |
|
306
|
|
|
/* @var $qb \Doctrine\ORM\QueryBuilder */ |
|
307
|
13 |
|
$qb = $doctrineficore->createQueryBuilder(); |
|
308
|
13 |
|
$qb->select(array('a')); |
|
309
|
13 |
|
$qb->from('FiCoreBundle:OpzioniTabella', 'a'); |
|
310
|
13 |
|
$qb->leftJoin('a.tabelle', 't'); |
|
311
|
13 |
|
$qb->where("t.nometabella = '*' or t.nometabella = :tabella"); |
|
312
|
13 |
|
$qb->andWhere("t.nomecampo is null or t.nomecampo = ''"); |
|
313
|
13 |
|
$qb->orderBy('t.nometabella'); |
|
314
|
13 |
|
$qb->setParameter('tabella', $nometabella); |
|
315
|
13 |
|
$opzioni = $qb->getQuery()->getResult(); |
|
316
|
13 |
|
foreach ($opzioni as $opzione) { |
|
317
|
13 |
|
$testata[$opzione->getParametro()] = str_replace('%tabella%', $nometabella, $opzione->getValore()); |
|
318
|
13 |
|
} |
|
319
|
13 |
|
} |
|
320
|
|
|
|
|
321
|
13 |
|
public static function getNomiColonne($nomicolonne) |
|
322
|
|
|
{ |
|
323
|
13 |
|
ksort($nomicolonne); |
|
324
|
13 |
|
$nomicolonnesorted = array(); |
|
325
|
13 |
|
foreach ($nomicolonne as $value) { |
|
326
|
13 |
|
$nomicolonnesorted[] = $value; |
|
327
|
13 |
|
} |
|
328
|
|
|
|
|
329
|
13 |
|
return $nomicolonnesorted; |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
13 |
|
public static function getModelloColonne($modellocolonne) |
|
333
|
|
|
{ |
|
334
|
13 |
|
ksort($modellocolonne); |
|
335
|
13 |
|
$modellocolonnesorted = array(); |
|
336
|
13 |
|
foreach ($modellocolonne as $value) { |
|
337
|
13 |
|
$modellocolonnesorted[] = $value; |
|
338
|
13 |
|
} |
|
339
|
|
|
|
|
340
|
13 |
|
return $modellocolonnesorted; |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
13 |
|
public static function getPermessiTabella($paricevuti, &$testata) |
|
344
|
|
|
{ |
|
345
|
13 |
|
if (!isset($paricevuti['container'])) { |
|
346
|
|
|
return; |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
13 |
|
$container = $paricevuti['container']; |
|
|
|
|
|
|
350
|
13 |
|
$nometabella = $paricevuti['nometabella']; |
|
|
|
|
|
|
351
|
13 |
|
$gestionepermessi = $container->get("ficorebundle.gestionepermessi"); |
|
|
|
|
|
|
352
|
|
|
|
|
353
|
13 |
|
$vettorepermessi = $gestionepermessi->impostaPermessi(array('modulo' => $nometabella)); |
|
354
|
|
|
|
|
355
|
13 |
|
return array_merge($testata, $vettorepermessi); |
|
356
|
|
|
} |
|
357
|
|
|
} |
|
358
|
|
|
|
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.