1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fi\CoreBundle\Utils\Tabella; |
4
|
|
|
|
5
|
|
|
//use Doctrine\ORM\QueryBuilder; |
6
|
|
|
use Doctrine\Common\Collections\Expr\Comparison; |
7
|
|
|
use Doctrine\ORM\Query\Expr; |
8
|
|
|
|
9
|
|
|
class ParametriQueryTabellaDecoder extends BaseParametriQueryTabellaDecoder |
10
|
|
|
{ |
11
|
2 |
|
protected function buildQuery() |
12
|
|
|
{ |
13
|
2 |
|
switch ($this->fieldoperator) { |
14
|
2 |
|
case Comparison::EQ: |
15
|
2 |
|
$this->setEqCriteria(); |
16
|
2 |
|
break; |
17
|
1 |
|
case Comparison::NEQ: |
18
|
1 |
|
$this->setNeqCriteria(); |
19
|
1 |
|
break; |
20
|
1 |
|
case Comparison::IN: |
21
|
1 |
|
$this->setInCriteria(); |
22
|
1 |
|
break; |
23
|
1 |
|
case Comparison::NIN: |
24
|
1 |
|
$this->setNinCriteria(); |
25
|
1 |
|
break; |
26
|
1 |
|
case Comparison::CONTAINS: |
27
|
|
|
$this->setContainsCriteria(); |
28
|
|
|
break; |
29
|
1 |
|
case Comparison::STARTS_WITH: |
30
|
|
|
$this->setStartswithCriteria(); |
31
|
|
|
break; |
32
|
1 |
|
case Comparison::ENDS_WITH: |
33
|
|
|
$this->setEndswithCriteria(); |
34
|
|
|
break; |
35
|
|
|
default: |
36
|
1 |
|
$this->criteria = null; |
37
|
1 |
|
break; |
38
|
|
|
} |
39
|
2 |
|
} |
40
|
|
|
|
41
|
2 |
|
protected function setEqCriteria() |
42
|
|
|
{ |
43
|
2 |
|
$expr = new Expr(); |
44
|
|
|
|
45
|
2 |
|
if ($this->fieldvalue === null) { |
46
|
1 |
|
$this->criteria = $expr->isnull($this->fieldname); |
47
|
|
|
} else { |
48
|
2 |
|
if (is_a($this->fieldvalue, "\DateTime")) { |
|
|
|
|
49
|
|
|
$this->criteria = $expr->eq($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
50
|
|
|
} else { |
51
|
2 |
|
if (is_string($this->fieldvalue)) { |
52
|
|
|
$this->criteria = $expr->eq("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
53
|
|
|
} else { |
54
|
2 |
|
$this->criteria = $expr->eq($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
} |
57
|
2 |
|
$this->parameters = array($this->fieldqueryparameter => $this->fieldvalue); |
58
|
|
|
} |
59
|
2 |
|
} |
60
|
|
|
|
61
|
1 |
|
protected function setNeqCriteria() |
62
|
|
|
{ |
63
|
1 |
|
$expr = new Expr(); |
64
|
|
|
|
65
|
1 |
|
if ($this->fieldvalue === null) { |
66
|
1 |
|
$this->criteria = $expr->isnotnull($this->fieldname); |
67
|
|
|
} else { |
68
|
|
|
if (is_string($this->fieldvalue)) { |
69
|
|
|
$this->criteria = $expr->neq("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
70
|
|
|
} else { |
71
|
|
|
$this->criteria = $expr->neq($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
$this->parameters = array($this->fieldqueryparameter => $this->fieldvalue); |
74
|
|
|
} |
75
|
1 |
|
} |
76
|
|
|
|
77
|
1 |
|
protected function setNinCriteria() |
78
|
|
|
{ |
79
|
1 |
|
$expr = new Expr(); |
80
|
|
|
|
81
|
1 |
|
if (is_string($this->fieldvalue)) { |
82
|
|
|
$this->criteria = $expr->notin("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
83
|
|
|
} else { |
84
|
1 |
|
$this->criteria = $expr->notin($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
85
|
|
|
} |
86
|
1 |
|
$this->parameters = array($this->fieldqueryparameter => $this->fieldvalue); |
87
|
1 |
|
} |
88
|
|
|
|
89
|
1 |
|
protected function setInCriteria() |
90
|
|
|
{ |
91
|
1 |
|
$expr = new Expr(); |
92
|
|
|
|
93
|
1 |
|
if (is_string($this->fieldvalue)) { |
94
|
|
|
$this->criteria = $expr->in("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
95
|
|
|
} else { |
96
|
1 |
|
$this->criteria = $expr->in($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
97
|
|
|
} |
98
|
1 |
|
$this->parameters = array($this->fieldqueryparameter => $this->fieldvalue); |
99
|
1 |
|
} |
100
|
|
|
|
101
|
|
|
protected function setContainsCriteria() |
102
|
|
|
{ |
103
|
|
|
$expr = new Expr(); |
104
|
|
|
if (is_string($this->fieldvalue)) { |
105
|
|
|
$this->criteria = $expr->like("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
106
|
|
|
} else { |
107
|
|
|
$this->criteria = $expr->like($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
$this->parameters = array($this->fieldqueryparameter => '%' . $this->fieldvalue . '%'); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
protected function setStartswithCriteria() |
113
|
|
|
{ |
114
|
|
|
$expr = new Expr(); |
115
|
|
|
if (is_string($this->fieldvalue)) { |
116
|
|
|
$this->criteria = $expr->like("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
117
|
|
|
} else { |
118
|
|
|
$this->criteria = $expr->like($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
119
|
|
|
} |
120
|
|
|
$this->parameters = array($this->fieldqueryparameter => $this->fieldvalue . '%'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
protected function setEndswithCriteria() |
124
|
|
|
{ |
125
|
|
|
$expr = new Expr(); |
126
|
|
|
if (is_string($this->fieldvalue)) { |
127
|
|
|
$this->criteria = $expr->like("lower(" . $this->fieldname . ")", "lower(:" . $this->fieldqueryparameter . ")"); |
|
|
|
|
128
|
|
|
} else { |
129
|
|
|
$this->criteria = $expr->like($this->fieldname, ":" . $this->fieldqueryparameter); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
$this->parameters = array($this->fieldqueryparameter => '%' . $this->fieldvalue); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
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.