1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fi\CoreBundle\Utils; |
4
|
|
|
|
5
|
|
|
use Fi\CoreBundle\Controller\FiUtilita; |
6
|
|
|
|
7
|
|
|
class GrigliaRegoleUtils |
8
|
|
|
{ |
9
|
|
|
|
10
|
1 |
|
public static function getTipoRegola(&$tipo, &$regola, $parametri) |
11
|
|
|
{ |
12
|
1 |
|
$doctrine = $parametri['doctrine']; |
|
|
|
|
13
|
1 |
|
$nometabella = $parametri['nometabella']; |
14
|
1 |
|
$entityName = $parametri['entityName']; |
|
|
|
|
15
|
1 |
|
$bundle = $parametri['bundle']; |
|
|
|
|
16
|
|
|
|
17
|
1 |
|
$elencocampi = $doctrine->getClassMetadata($entityName)->getFieldNames(); |
18
|
|
|
|
19
|
1 |
|
if (strrpos($regola['field'], '.') == 0) { |
20
|
1 |
|
if (in_array($regola['field'], $elencocampi) === true) { |
21
|
1 |
|
$type = $doctrine->getClassMetadata($entityName)->getFieldMapping($regola['field']); |
22
|
1 |
|
$tipo = $type['type']; |
23
|
|
|
|
24
|
|
|
//Si aggiunge l'alias al campo altrimenti da Doctrine2 fallisce la query |
25
|
1 |
|
$regola['field'] = $nometabella . '.' . $regola['field']; |
26
|
1 |
|
} |
27
|
1 |
|
} else { |
28
|
|
|
//Altrimenti stiamo analizzando il campo di una tabella in leftjoin pertanto si cercano le informazioni sul tipo |
29
|
|
|
//dei campi nella tabella "joinata" |
30
|
1 |
|
$tablejoined = substr($regola['field'], 0, strrpos($regola['field'], '.')); |
31
|
1 |
|
$fieldjoined = substr($regola['field'], strrpos($regola['field'], '.') + 1); |
32
|
|
|
|
33
|
1 |
|
$entityNametablejoined = $bundle . ':' . $tablejoined; |
34
|
|
|
|
35
|
1 |
|
$type = $doctrine->getClassMetadata($entityNametablejoined)->getFieldMapping($fieldjoined); |
36
|
1 |
|
$tipo = $type['type']; |
37
|
|
|
} |
38
|
1 |
|
} |
39
|
|
|
|
40
|
1 |
|
public static function getRegolaPerData(&$regola) |
41
|
|
|
{ |
42
|
1 |
|
if (isset($regola) && count($regola) > 0) { |
43
|
1 |
|
if ((substr($regola['data'], 0, 1) == "'") && (substr($regola['data'], strlen($regola['data']) - 1, 1) == "'")) { |
44
|
|
|
$regola['data'] = substr($regola['data'], 1, strlen($regola['data']) - 2); |
45
|
|
|
} |
46
|
1 |
|
} |
47
|
1 |
|
} |
48
|
|
|
|
49
|
1 |
|
public static function setRegole(&$q, &$primo, $parametri = array()) |
|
|
|
|
50
|
|
|
{ |
51
|
1 |
|
$regole = $parametri['regole']; |
52
|
1 |
|
$tipof = $parametri['tipof']; |
|
|
|
|
53
|
1 |
|
$tipo = null; |
|
|
|
|
54
|
1 |
|
foreach ($regole as $regola) { |
55
|
|
|
//Se il campo non ha il . significa che è necessario aggiungere il nometabella |
56
|
1 |
|
self::getTipoRegola($tipo, $regola, $parametri); |
57
|
|
|
|
58
|
1 |
|
$regola = self::setSingolaRegola($tipo, $regola); |
59
|
1 |
|
if (!$regola) { |
60
|
|
|
continue; |
61
|
|
|
} |
62
|
1 |
|
if ($tipof == 'OR') { |
63
|
|
|
$condizioneOR = $regola['field'] . ' ' . |
64
|
|
|
GrigliaUtils::$decodificaop[$regola['op']] . ' ' . |
65
|
|
|
GrigliaUtils::$precarattere[$regola['op']] . |
66
|
|
|
str_replace("'", "''", $regola['data']) . |
67
|
|
|
GrigliaUtils::$postcarattere[$regola['op']]; |
68
|
|
|
$q->orWhere($condizioneOR); |
69
|
|
|
} else { |
70
|
1 |
|
$condizioneAND = $regola['field'] . ' ' . |
71
|
1 |
|
GrigliaUtils::$decodificaop[$regola['op']] . ' ' . |
72
|
1 |
|
GrigliaUtils::$precarattere[$regola['op']] . |
73
|
1 |
|
str_replace("'", "''", $regola['data']) . |
74
|
1 |
|
GrigliaUtils::$postcarattere[$regola['op']]; |
75
|
1 |
|
$q->andWhere($condizioneAND); |
76
|
|
|
} |
77
|
1 |
|
} |
78
|
1 |
|
} |
79
|
|
|
|
80
|
1 |
|
public static function setSingolaRegola($tipo, $regola) |
81
|
|
|
{ |
82
|
1 |
|
if (!$tipo || $tipo == "integer" || $tipo == "float") { |
|
|
|
|
83
|
1 |
|
GrigliaUtils::setVettoriPerNumero(); |
84
|
1 |
|
} |
85
|
1 |
|
if ($tipo == 'date' || $tipo == 'datetime') { |
86
|
1 |
|
GrigliaUtils::setVettoriPerData(); |
87
|
1 |
|
$regola['data'] = FiUtilita::data2db($regola['data']); |
88
|
1 |
|
} elseif ($tipo == 'string') { |
89
|
1 |
|
GrigliaUtils::setVettoriPerStringa(); |
90
|
1 |
|
$regola['field'] = 'lower(' . $regola['field'] . ')'; |
91
|
1 |
|
} |
92
|
1 |
|
if ($tipo == 'boolean') { |
93
|
|
|
self::setTipoBoolean($regola, $tipo); |
94
|
|
|
} |
95
|
|
|
|
96
|
1 |
|
self::getRegolaPerData($regola); |
97
|
|
|
|
98
|
1 |
|
return $regola; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public static function setTipoBoolean(&$regola, $tipo) |
102
|
|
|
{ |
103
|
|
|
if ($regola['data'] === 'false' || $regola['data'] === false) { |
104
|
|
|
GrigliaUtils::setVettoriPerBoolean(); |
105
|
|
|
$regola['op'] = 'eq'; |
|
|
|
|
106
|
|
|
$regola['data'] = "0"; |
|
|
|
|
107
|
|
|
} |
108
|
|
|
if ($regola['data'] === 'true' || $regola['data'] === true) { |
109
|
|
|
GrigliaUtils::setVettoriPerBoolean(); |
110
|
|
|
$regola['op'] = 'eq'; |
|
|
|
|
111
|
|
|
$regola['data'] = "1"; |
|
|
|
|
112
|
|
|
} |
113
|
|
|
if ($tipo == 'boolean' && $regola['data'] == 'null') { |
114
|
|
|
$regola = array(); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
13 |
|
public static function campiesclusi($parametri = array()) |
119
|
|
|
{ |
120
|
13 |
|
if (!isset($parametri['nometabella'])) { |
121
|
|
|
return false; |
122
|
|
|
} |
123
|
|
|
|
124
|
13 |
|
$output = GrigliaParametriUtils::getOuputType($parametri); |
125
|
|
|
|
126
|
13 |
|
$nometabella = $parametri['nometabella']; |
127
|
|
|
|
128
|
13 |
|
$doctrine = GrigliaParametriUtils::getDoctrineByEm($parametri); |
|
|
|
|
129
|
13 |
|
$doctrineficore = GrigliaParametriUtils::getDoctrineFiCoreByEm($parametri, $doctrine); |
130
|
13 |
|
$container = $parametri['container']; |
|
|
|
|
131
|
|
|
|
132
|
13 |
|
$gestionepermessi = $container->get("ficorebundle.gestionepermessi"); |
|
|
|
|
133
|
13 |
|
$operatorecorrente = $gestionepermessi->utentecorrente(); |
134
|
|
|
|
135
|
13 |
|
$escludi = array(); |
136
|
13 |
|
$q = GrigliaUtils::getUserCustomTableFields($doctrineficore, $nometabella, $operatorecorrente); |
|
|
|
|
137
|
13 |
|
if (!$q) { |
138
|
9 |
|
return $escludi; |
139
|
|
|
} |
140
|
|
|
|
141
|
4 |
|
foreach ($q as $riga) { |
142
|
4 |
|
$campo = GrigliaUtils::getCampiEsclusi($riga, $output); |
143
|
4 |
|
if ($campo) { |
144
|
|
|
$escludi[] = $campo; |
145
|
|
|
} |
146
|
4 |
|
} |
147
|
|
|
|
148
|
4 |
|
return $escludi; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
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.