1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fi\CoreBundle\Controller; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Insieme di funzioni utili |
7
|
|
|
* FiUtilita. |
8
|
|
|
* |
9
|
|
|
* @author Emidio Picariello |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
use Fi\CoreBundle\DependencyInjection\PercentualiStringhe; |
13
|
|
|
|
14
|
|
|
class FiUtilita |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
public function percentualiConfrontoStringheVettore($parametri = array()) |
18
|
|
|
{ |
19
|
|
|
$percentuali = new PercentualiStringhe(); |
20
|
|
|
|
21
|
|
|
return $percentuali->percentualiConfrontoStringheVettore($parametri); |
22
|
|
|
} |
23
|
|
|
|
24
|
1 |
|
public function percentualiConfrontoStringhe($parametri = array()) |
25
|
|
|
{ |
26
|
1 |
|
$percentuali = new PercentualiStringhe(); |
27
|
|
|
|
28
|
1 |
|
return $percentuali->percentualiConfrontoStringhe($parametri); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function sommaMinuti($parametri = array()) |
32
|
|
|
{ |
33
|
|
|
//parametri obbligatori |
34
|
|
|
if (!isset($parametri['minuti'])) { |
35
|
|
|
return false; |
36
|
|
|
} |
37
|
|
|
$restotminuti = array(); |
|
|
|
|
38
|
|
|
$resminuti = 0; |
|
|
|
|
39
|
|
|
$resore = 0; |
|
|
|
|
40
|
|
|
|
41
|
|
|
$minuti = $parametri['minuti']; |
42
|
|
|
|
43
|
|
|
$totminuti = array_sum($minuti); |
44
|
|
|
$resminuti = $totminuti % 60; |
45
|
|
|
$resore = ($totminuti - $resminuti) / 60; |
46
|
|
|
|
47
|
|
|
$restotminuti = array('ore' => $resore, 'minuti' => $resminuti); |
48
|
|
|
|
49
|
|
|
return $restotminuti; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param array $parametri |
54
|
|
|
* @param string $parametri["tipo"] |
|
|
|
|
55
|
|
|
* |
56
|
|
|
* @return Array("segnouno"=>"xx", "segnodue"=>"yy") dove segnodue non obbligatorio |
|
|
|
|
57
|
|
|
*/ |
58
|
|
|
public function operatoreQuery($parametri = array()) |
59
|
|
|
{ |
60
|
|
|
$risposta = array(); |
61
|
|
|
|
62
|
|
|
if (isset($parametri['tipo'])) { |
63
|
|
|
$tipocampo = $parametri['tipo']; |
64
|
|
|
} else { |
65
|
|
|
return array('segnouno' => '='); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
switch ($tipocampo) { |
69
|
|
|
case 'date': |
70
|
|
|
case 'integer': |
71
|
|
|
case 'double': |
72
|
|
|
$operatore = '>='; |
73
|
|
|
$operatoredue = '<='; |
74
|
|
|
break; |
75
|
|
|
case 'string': |
76
|
|
|
case 'text': |
77
|
|
|
$operatore = 'LIKE'; |
78
|
|
|
break; |
79
|
|
|
default: |
80
|
|
|
$operatore = '='; |
81
|
|
|
break; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$risposta['segnouno'] = $operatore; |
85
|
|
|
if (isset($operatoredue)) { |
86
|
|
|
$risposta['segnodue'] = $operatoredue; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $risposta; |
90
|
|
|
} |
91
|
|
|
|
92
|
2 |
|
public static function data2db($giorno, $invertito = false, $senzalinea = false) |
93
|
|
|
{ |
94
|
2 |
|
if ($giorno == '') { |
95
|
|
|
return null; |
96
|
|
|
} |
97
|
|
|
|
98
|
2 |
|
if (substr($giorno, 4, 1) == '-') { |
99
|
1 |
|
return $giorno; |
100
|
|
|
} |
101
|
|
|
|
102
|
1 |
|
$barragiorno = strpos($giorno, '/'); |
103
|
1 |
|
$gg = substr($giorno, 0, $barragiorno); |
104
|
1 |
|
$restante = substr($giorno, $barragiorno + 1); |
105
|
|
|
|
106
|
1 |
|
$barra = strpos($restante, '/'); |
107
|
1 |
|
$mm = substr($restante, 0, $barra); |
108
|
1 |
|
$aaaa = substr($restante, $barra + 1); |
109
|
|
|
|
110
|
1 |
|
$appogg = ($invertito ? $mm : $gg); |
111
|
1 |
|
$mm = ($invertito ? $gg : $mm); |
112
|
1 |
|
$gg = $appogg; |
113
|
|
|
|
114
|
1 |
|
$formattata = self::getDataFormattata($aaaa, $mm, $gg, $senzalinea); |
115
|
|
|
|
116
|
1 |
|
return $formattata; |
117
|
|
|
} |
118
|
|
|
|
119
|
1 |
|
private static function getDataFormattata($aaaa, $mm, $gg, $senzalinea) |
120
|
|
|
{ |
121
|
1 |
|
$separatore = ($senzalinea ? '' : '-'); |
122
|
|
|
|
123
|
1 |
|
$nuovadata = $aaaa . $separatore . $mm . $separatore . $gg; |
124
|
|
|
|
125
|
1 |
|
return strlen($gg) == 0 ? '' : $nuovadata; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public static function db2data($giorno, $senzalinea = false) |
129
|
|
|
{ |
130
|
|
|
if (substr($giorno, 2, 1) == '/') { |
131
|
|
|
return $giorno; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
if ($senzalinea) { |
135
|
|
|
$formattata = self::senzalinea($giorno); |
136
|
|
|
} else { |
137
|
|
|
$barra = strpos($giorno, '-'); |
138
|
|
|
$aaaa = substr($giorno, 0, $barra); |
139
|
|
|
$restante = substr($giorno, $barra + 1); |
140
|
|
|
$barra = strpos($restante, '-'); |
141
|
|
|
$mm = substr($restante, 0, $barra); |
142
|
|
|
$gg = substr($restante, $barra + 1); |
143
|
|
|
|
144
|
|
|
$formattata = (strlen($gg) == 0 ? '' : "$gg/$mm/$aaaa"); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return $formattata; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
private static function senzalinea($giorno) |
151
|
|
|
{ |
152
|
|
|
$aaaa = substr($giorno, 0, 4); |
153
|
|
|
$mm = substr($giorno, 4, 2); |
154
|
|
|
$gg = substr($giorno, 6, 2); |
155
|
|
|
|
156
|
|
|
$formattata = (strlen($gg) == 0 ? '' : "$gg/$mm/$aaaa"); |
157
|
|
|
|
158
|
|
|
return $formattata; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @param array $parametri |
163
|
|
|
* @param string $parametri["nomecodice"] default = "codice" |
|
|
|
|
164
|
|
|
* @param string $parametri["nomedescrizione"] default = "descrizione" |
|
|
|
|
165
|
|
|
* @param array $parametri["elementi"] Array([0]=>("codice"=>1, "descrizione"=>"blaa"), [1]=>...) |
|
|
|
|
166
|
|
|
* @param string $parametri["selezionato"] opzionale |
|
|
|
|
167
|
|
|
* |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
1 |
|
public function proSelect($parametri = array()) |
171
|
|
|
{ |
172
|
1 |
|
$stringaproselect = ''; |
173
|
1 |
|
if (!isset($parametri['elementi'])) { |
174
|
|
|
return false; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
//parametri obbligatori |
178
|
1 |
|
$elementi = $parametri['elementi']; |
179
|
1 |
|
$attributi = $this->getProSelectAttribute($parametri); |
180
|
1 |
|
$selezionato = $attributi['selezionato']; |
181
|
1 |
|
$nomecodice = $attributi['nomecodice']; |
182
|
1 |
|
$nomedescrizione = $attributi['nomedescrizione']; |
183
|
|
|
|
184
|
1 |
|
foreach ($elementi as $elemento) { |
185
|
1 |
|
$elementonomecodice = $elemento[$nomecodice]; |
186
|
1 |
|
$elementonomedescrizione = $elemento[$nomedescrizione]; |
187
|
1 |
|
$elementoselezionato = ($elementonomecodice === $selezionato ? " selected='yes'" : ''); |
188
|
1 |
|
$stringaproselect .= '<option value="' . $elementonomecodice . '"' . $elementoselezionato . '>' . $elementonomedescrizione . '</option>'; |
189
|
1 |
|
} |
190
|
|
|
|
191
|
1 |
|
return $stringaproselect; |
192
|
|
|
} |
193
|
|
|
|
194
|
1 |
|
public function getProSelectAttribute($parametri) |
195
|
|
|
{ |
196
|
1 |
|
$arrayritorno = array(); |
197
|
1 |
|
$arrayritorno['selezionato'] = (isset($parametri['selezionato']) ? $parametri['selezionato'] : false); |
198
|
1 |
|
$arrayritorno['nomecodice'] = (isset($parametri['nomecodice']) ? $parametri['nomecodice'] : 'codice'); |
199
|
1 |
|
$arrayritorno['nomedescrizione'] = (isset($parametri['nomedescrizione']) ? $parametri['nomedescrizione'] : 'descrizione'); |
200
|
|
|
|
201
|
1 |
|
return $arrayritorno; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @param $parametri["vettore"] |
206
|
|
|
* @param $parametri["chiave"] |
207
|
|
|
* @param $parametri["valore"] |
208
|
|
|
* |
209
|
|
|
* @return $vettorenuovo |
|
|
|
|
210
|
|
|
*/ |
211
|
|
|
public function cancellaDaVettore($parametri = array()) |
212
|
|
|
{ |
213
|
|
|
|
214
|
|
|
//parametri obbligatori |
215
|
|
|
if (isset($parametri['vettore'])) { |
216
|
|
|
$vettore = $parametri['vettore']; |
217
|
|
|
} else { |
218
|
|
|
return false; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
//parametri obbligatori |
222
|
|
|
if (isset($parametri['chiave'])) { |
223
|
|
|
$chiave = $parametri['chiave']; |
224
|
|
|
} else { |
225
|
|
|
return $vettore; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
//parametri obbligatori |
229
|
|
|
if (isset($parametri['valore'])) { |
230
|
|
|
$valore = $parametri['valore']; |
231
|
|
|
} else { |
232
|
|
|
return $vettore; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
$vettorenuovo = array(); |
236
|
|
|
|
237
|
|
|
foreach ($vettore as $elemento) { |
238
|
|
|
if (!($elemento[$chiave] == $valore)) { |
239
|
|
|
$vettorenuovo[] = $elemento; |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
return $vettorenuovo; |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.