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
|
|
|
|
13
|
3 |
|
protected function getDescrizioneFiltro(&$descrizionefiltri, $filtrocorrente, $criteria) |
14
|
|
|
{ |
15
|
3 |
|
if ($filtrocorrente["prefiltro"] === false) { |
|
|
|
|
16
|
2 |
|
$descrizionefiltri = $descrizionefiltri . ", " . $criteria->getDescrizioneFiltro(); |
|
|
|
|
17
|
|
|
} |
18
|
3 |
|
} |
19
|
3 |
|
protected function getFieldValue($fieldvalue) |
20
|
|
|
{ |
21
|
3 |
|
if (isset($fieldvalue["date"])) { |
|
|
|
|
22
|
1 |
|
return new \Datetime($fieldvalue["date"]); |
|
|
|
|
23
|
|
|
} else { |
24
|
3 |
|
return $fieldvalue; |
25
|
|
|
} |
26
|
|
|
} |
27
|
3 |
|
protected function getOperator($operator) |
28
|
|
|
{ |
29
|
|
|
|
30
|
3 |
|
switch (strtoupper($operator)) { |
31
|
3 |
|
case "LIKE": |
|
|
|
|
32
|
1 |
|
$operator = Comparison::CONTAINS; |
33
|
1 |
|
break; |
34
|
3 |
|
case "IN": |
|
|
|
|
35
|
1 |
|
$operator = Comparison::IN; |
36
|
1 |
|
break; |
37
|
3 |
|
case "NOT IN": |
|
|
|
|
38
|
1 |
|
$operator = Comparison::NIN; |
39
|
1 |
|
break; |
40
|
|
|
default: |
41
|
3 |
|
break; |
42
|
|
|
} |
43
|
|
|
|
44
|
3 |
|
return $operator; |
45
|
|
|
} |
46
|
12 |
|
protected function generaAlias($nometabella, $nomepadre = false, $ancestors = array()) |
47
|
|
|
{ |
48
|
12 |
|
$nometabellapulito = preg_replace('/[^a-z0-9\.]/i', '', $nometabella); |
49
|
12 |
|
$primalettera = strtolower(substr($nometabellapulito, 0, 1)); |
|
|
|
|
50
|
12 |
|
if ($nomepadre && !in_array($nomepadre, $ancestors)) { |
51
|
|
|
$ancestors[] = $nomepadre; |
52
|
|
|
} |
53
|
12 |
|
if (!in_array($nometabella, $ancestors)) { |
54
|
12 |
|
$ancestors[] = $nometabella; |
55
|
|
|
} |
56
|
|
|
|
57
|
12 |
|
if (isset($this->aliasGenerati[$primalettera])) { |
58
|
3 |
|
$risposta = $primalettera . $this->aliasGenerati[$primalettera]; |
|
|
|
|
59
|
3 |
|
$this->aliasGenerati[$primalettera] = $this->aliasGenerati[$primalettera] + 1; |
60
|
|
|
} else { |
61
|
12 |
|
$risposta = $primalettera; |
|
|
|
|
62
|
12 |
|
$this->aliasGenerati[$primalettera] = 1; |
63
|
|
|
} |
64
|
|
|
|
65
|
12 |
|
$this->decodificaAlias[ucfirst(implode(".", $ancestors))] = array("alias" => $risposta); |
|
|
|
|
66
|
|
|
|
67
|
12 |
|
return $risposta; |
68
|
|
|
} |
69
|
3 |
|
protected function findAliasByTablename($tablename) |
70
|
|
|
{ |
71
|
3 |
|
if (!array_key_exists($tablename, $this->decodificaAlias)) { |
72
|
|
|
$ex = "Fifree: table or association " . $tablename . " not found, did you mean one of these:\n" . |
|
|
|
|
73
|
|
|
implode("\n", array_keys($this->decodificaAlias)) . |
74
|
|
|
" ?"; |
|
|
|
|
75
|
|
|
throw new \Exception($ex); |
76
|
|
|
} |
77
|
3 |
|
return $this->getAliasGenerato($tablename); |
78
|
|
|
} |
79
|
3 |
|
protected function findFieldnameByAlias($nomecampo) |
80
|
|
|
{ |
81
|
3 |
|
if (!array_key_exists($nomecampo, $this->configurazionecolonnetabella)) { |
82
|
|
|
$ex = "Fifree: field or association " . $nomecampo . " not found, did you mean one of these:\n" . |
|
|
|
|
83
|
|
|
implode("\n", array_keys($this->configurazionecolonnetabella)) . |
84
|
|
|
" ?"; |
|
|
|
|
85
|
|
|
throw new \Exception($ex); |
86
|
|
|
} |
87
|
3 |
|
return $this->configurazionecolonnetabella[$nomecampo]; |
88
|
|
|
} |
89
|
10 |
|
public function getAliasGenerato($tablename) |
90
|
|
|
{ |
91
|
10 |
|
return $this->decodificaAlias[$tablename]["alias"]; |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
PHP provides two ways to mark string literals. Either with single quotes
'literal'
or with double quotes"literal"
. The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\'
) and the backslash (\\
). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is Value
If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.