1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Utils\Tabella; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\Expr\Comparison; |
6
|
|
|
|
7
|
|
|
trait TabellaDecoderTrait |
8
|
|
|
{ |
9
|
|
|
private $aliasGenerati; |
10
|
|
|
private $decodificaAlias; |
11
|
|
|
|
12
|
3 |
|
protected function getDescrizioneFiltro(&$descrizionefiltri, $filtrocorrente, $criteria) |
13
|
|
|
{ |
14
|
3 |
|
if (false === $filtrocorrente['prefiltro']) { |
15
|
2 |
|
$descrizionefiltri = $descrizionefiltri.', '.$criteria->getDescrizioneFiltro(); |
16
|
|
|
} |
17
|
3 |
|
} |
18
|
|
|
|
19
|
4 |
|
protected function getFieldValue($fieldvalue) |
20
|
|
|
{ |
21
|
4 |
|
if (isset($fieldvalue['date'])) { |
22
|
1 |
|
return new \Datetime($fieldvalue['date']); |
23
|
|
|
} else { |
24
|
4 |
|
return $fieldvalue; |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
4 |
|
protected function getOperator($operator) |
29
|
|
|
{ |
30
|
4 |
|
switch (strtoupper($operator)) { |
31
|
4 |
|
case 'LIKE': |
32
|
1 |
|
$operator = Comparison::CONTAINS; |
33
|
1 |
|
break; |
34
|
4 |
|
case 'IN': |
35
|
1 |
|
$operator = Comparison::IN; |
36
|
1 |
|
break; |
37
|
4 |
|
case 'NOT IN': |
38
|
1 |
|
$operator = Comparison::NIN; |
39
|
1 |
|
break; |
40
|
|
|
default: |
41
|
4 |
|
break; |
42
|
|
|
} |
43
|
|
|
|
44
|
4 |
|
return $operator; |
45
|
|
|
} |
46
|
|
|
|
47
|
12 |
|
protected function generaAlias($nometabella, $nomepadre = false, $ancestors = array()) |
48
|
|
|
{ |
49
|
12 |
|
$nometabellapulito = preg_replace('/[^a-z0-9\.]/i', '', $nometabella); |
50
|
12 |
|
$primalettera = strtolower(substr($nometabellapulito, 0, 1)); |
|
|
|
|
51
|
12 |
|
if ($nomepadre && !in_array($nomepadre, $ancestors)) { |
52
|
|
|
$ancestors[] = $nomepadre; |
53
|
|
|
} |
54
|
12 |
|
if (!in_array($nometabella, $ancestors)) { |
55
|
12 |
|
$ancestors[] = $nometabella; |
56
|
|
|
} |
57
|
|
|
|
58
|
12 |
|
if (isset($this->aliasGenerati[$primalettera])) { |
59
|
3 |
|
$risposta = $primalettera.$this->aliasGenerati[$primalettera]; |
|
|
|
|
60
|
3 |
|
$this->aliasGenerati[$primalettera] = $this->aliasGenerati[$primalettera] + 1; |
61
|
|
|
} else { |
62
|
12 |
|
$risposta = $primalettera; |
|
|
|
|
63
|
12 |
|
$this->aliasGenerati[$primalettera] = 1; |
64
|
|
|
} |
65
|
|
|
|
66
|
12 |
|
$this->decodificaAlias[ucfirst(implode('.', $ancestors))] = array('alias' => $risposta); |
67
|
|
|
|
68
|
12 |
|
return $risposta; |
69
|
|
|
} |
70
|
|
|
|
71
|
4 |
|
protected function findAliasByTablename($tablename) |
72
|
|
|
{ |
73
|
4 |
|
if (!array_key_exists($tablename, $this->decodificaAlias)) { |
74
|
1 |
|
$ex = 'BiCore: table or association '.$tablename." not found, did you mean one of these:\n". |
75
|
1 |
|
implode("\n", array_keys($this->decodificaAlias)). |
76
|
1 |
|
' ?'; |
77
|
1 |
|
throw new \Exception($ex); |
78
|
|
|
} |
79
|
|
|
|
80
|
4 |
|
return $this->getAliasGenerato($tablename); |
81
|
|
|
} |
82
|
|
|
|
83
|
4 |
|
protected function findFieldnameByAlias($nomecampo) |
84
|
|
|
{ |
85
|
4 |
|
if (!array_key_exists($nomecampo, $this->configurazionecolonnetabella)) { |
86
|
1 |
|
$ex = 'BiCore: field or association '.$nomecampo." not found, did you mean one of these:\n". |
87
|
1 |
|
implode("\n", array_keys($this->configurazionecolonnetabella)). |
88
|
1 |
|
' ?'; |
89
|
1 |
|
throw new \Exception($ex); |
90
|
|
|
} |
91
|
|
|
|
92
|
3 |
|
return $this->configurazionecolonnetabella[$nomecampo]; |
93
|
|
|
} |
94
|
|
|
|
95
|
10 |
|
public function getAliasGenerato($tablename) |
96
|
|
|
{ |
97
|
10 |
|
return $this->decodificaAlias[$tablename]['alias']; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
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.