1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fi\CoreBundle\Utils; |
4
|
|
|
|
5
|
|
|
use Fi\CoreBundle\Controller\FiUtilita; |
6
|
|
|
|
7
|
|
|
class GrigliaDatiPrecondizioniUtils |
8
|
|
|
{ |
9
|
|
|
|
10
|
2 |
|
public static function setPrecondizioniAvanzate(&$q, &$primo, $parametri = array()) |
11
|
|
|
{ |
12
|
2 |
|
$doctrine = $parametri['doctrine']; |
|
|
|
|
13
|
2 |
|
$nometabella = $parametri['nometabella']; |
|
|
|
|
14
|
2 |
|
$entityName = $parametri['entityName']; |
|
|
|
|
15
|
2 |
|
$bundle = $parametri['bundle']; |
|
|
|
|
16
|
2 |
|
$precondizioniAvanzate = $parametri['precondizioniAvanzate']; |
17
|
2 |
|
$regole = array(); |
|
|
|
|
18
|
|
|
|
19
|
2 |
|
foreach ($precondizioniAvanzate as $elem) { |
20
|
2 |
|
$nometabellaprecondizione = ''; |
|
|
|
|
21
|
2 |
|
$nomecampoprecondizione = ''; |
|
|
|
|
22
|
2 |
|
$valorecampoprecondizione = ''; |
|
|
|
|
23
|
2 |
|
$operatoreprecondizione = '='; |
|
|
|
|
24
|
2 |
|
$operatorelogicoprecondizione = ''; |
25
|
2 |
|
foreach ($elem as $keypre => $valuepre) { |
26
|
|
|
switch ($keypre) { |
27
|
2 |
|
case 'nometabella': |
28
|
2 |
|
$nometabellaprecondizione = $valuepre; |
29
|
2 |
|
break; |
30
|
2 |
|
case 'nomecampo': |
31
|
2 |
|
$nomecampoprecondizione = $valuepre; |
32
|
2 |
|
break; |
33
|
2 |
|
case 'operatore': |
34
|
2 |
|
$array_operatori = array('=' => 'eq', '<>' => 'ne', '<' => 'lt', |
|
|
|
|
35
|
2 |
|
'<=' => 'le', '>' => 'gt', '>=' => 'ge', |
36
|
2 |
|
'LIKE' => 'bw', 'NOT LIKE' => 'bn', 'IN' => 'in', 'NOT IN' => 'ni', |
37
|
2 |
|
'LIKE' => 'eq', 'NOT LIKE' => 'en', |
38
|
2 |
|
'LIKE' => 'cn', 'NOT LIKE' => 'nc', 'IS' => 'nu', 'IS NOT' => 'nn'); |
39
|
2 |
|
$operatoreprecondizione = $array_operatori[strtoupper($valuepre)]; |
40
|
2 |
|
break; |
41
|
2 |
|
case 'valorecampo': |
42
|
2 |
|
if (is_array($valuepre)) { |
43
|
1 |
|
$type = $doctrine->getClassMetadata($parametri['entityName'])->getFieldMapping($nomecampoprecondizione); |
|
|
|
|
44
|
1 |
|
$valorecampoprecondizione = self::elaboravalorecampo($type, $valuepre); |
45
|
1 |
|
} else { |
46
|
2 |
|
$valorecampoprecondizione = $valuepre; |
47
|
|
|
} |
48
|
2 |
|
break; |
49
|
|
|
case 'operatorelogico': |
50
|
|
|
$operatorelogicoprecondizione = strtoupper($valuepre); |
51
|
|
|
break; |
52
|
|
|
default: |
53
|
|
|
break; |
54
|
|
|
} |
55
|
2 |
|
} |
56
|
|
|
|
57
|
2 |
|
$regole[] = array( |
58
|
2 |
|
'field' => "$nometabellaprecondizione.$nomecampoprecondizione", |
|
|
|
|
59
|
2 |
|
'op' => $operatoreprecondizione, |
60
|
2 |
|
'data' => $valorecampoprecondizione, |
61
|
2 |
|
'typof' => $operatorelogicoprecondizione); |
62
|
2 |
|
} |
63
|
|
|
$regolearray = array( |
64
|
2 |
|
'regole' => $regole, |
65
|
2 |
|
'doctrine' => $doctrine, |
66
|
2 |
|
'nometabella' => $nometabella, |
67
|
2 |
|
'entityName' => $entityName, |
68
|
|
|
'bundle' => $bundle |
69
|
2 |
|
); |
70
|
2 |
|
GrigliaRegoleUtils::setRegole($q, $primo, $regolearray); |
71
|
2 |
|
} |
72
|
|
|
|
73
|
1 |
|
private static function elaboravalorecampo($type, $valuepre) |
74
|
|
|
{ |
75
|
1 |
|
$tipo = $type['type']; |
76
|
1 |
|
if ($tipo && ($tipo == 'date' || $tipo == 'datetime')) { |
77
|
|
|
GrigliaUtils::setVettoriPerData(); |
78
|
|
|
foreach ($valuepre as $chiave => $valore) { |
79
|
|
|
$valuepre[$chiave] = FiUtilita::data2db($valore); |
80
|
|
|
} |
81
|
|
|
return implode(', ', $valuepre); |
82
|
1 |
|
} elseif ($tipo && $tipo == 'string') { |
83
|
1 |
|
GrigliaUtils::setVettoriPerStringa(); |
84
|
1 |
|
foreach ($valuepre as $chiave => $valore) { |
85
|
1 |
|
$valuepre[$chiave] = strtolower($valore); |
86
|
1 |
|
} |
87
|
1 |
|
return implode(', ', $valuepre); |
88
|
|
|
} else { |
89
|
1 |
|
GrigliaUtils::setVettoriPerNumero(); |
90
|
1 |
|
return implode(', ', $valuepre); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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.