1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\DoctrineORMAdminBundle\Tests\Filter; |
13
|
|
|
|
14
|
|
|
use \Doctrine\ORM\Query\Expr\Orx; |
15
|
|
|
|
16
|
|
|
class QueryBuilder |
17
|
|
|
{ |
18
|
|
|
public $parameters = array(); |
19
|
|
|
|
20
|
|
|
public $query = array(); |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param string $name |
24
|
|
|
* @param mixed $value |
25
|
|
|
*/ |
26
|
|
|
public function setParameter($name, $value) |
27
|
|
|
{ |
28
|
|
|
$this->parameters[$name] = $value; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $query |
33
|
|
|
*/ |
34
|
|
|
public function andWhere($query) |
35
|
|
|
{ |
36
|
|
|
$this->query[] = $query; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return QueryBuilder |
41
|
|
|
*/ |
42
|
|
|
public function expr() |
43
|
|
|
{ |
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $name |
49
|
|
|
* @param string $value |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function in($name, $value) |
54
|
|
|
{ |
55
|
|
|
$this->query[] = 'in_'.$name; |
56
|
|
|
|
57
|
|
|
if (is_array($value)) { |
58
|
|
|
return sprintf('%s IN ("%s")', $name, implode(',', $value)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return sprintf('%s IN %s', 'in_'.$name, $value); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getDQLPart($queryPart) |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
return array(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
public function getRootAlias() |
73
|
|
|
{ |
74
|
|
|
return 'o'; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string $parameter |
79
|
|
|
* @param string $alias |
80
|
|
|
*/ |
81
|
|
|
public function leftJoin($parameter, $alias) |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
$this->query[] = $parameter; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return Orx |
88
|
|
|
*/ |
89
|
|
|
public function orX($x = null) |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
return new Orx(func_get_args()); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $alias |
96
|
|
|
* @param string $parameter |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function neq($alias, $parameter) |
100
|
|
|
{ |
101
|
|
|
return sprintf('%s <> %s', $alias, $parameter); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param string $queryPart |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function isNull($queryPart) |
109
|
|
|
{ |
110
|
|
|
return $queryPart.' IS NULL'; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $alias |
115
|
|
|
* @param string $parameter |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public function notIn($alias, $parameter) |
119
|
|
|
{ |
120
|
|
|
return sprintf('%s NOT IN %s', $alias, $parameter); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return array |
125
|
|
|
*/ |
126
|
|
|
public function getAllAliases() |
127
|
|
|
{ |
128
|
|
|
return array($this->getRootAlias()); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.