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