1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the jquery-querybuilder-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2017 WEBEWEB |
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 WBW\Bundle\JQuery\QueryBuilderBundle\API; |
13
|
|
|
|
14
|
|
|
use UnexpectedValueException; |
15
|
|
|
use WBW\Bundle\JQuery\QueryBuilderBundle\Normalizer\QueryBuilderNormalizer; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* QueryBuilder filter. |
19
|
|
|
* |
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
21
|
|
|
* @package WBW\Bundle\JQuery\QueryBuilderBundle\API |
22
|
|
|
*/ |
23
|
|
|
class QueryBuilderFilter extends AbstractQueryBuilder implements QueryBuilderFilterInterface, QueryBuilderOperatorInterface { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Label. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $label; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Multiple. |
34
|
|
|
* |
35
|
|
|
* @var bool |
36
|
|
|
*/ |
37
|
|
|
private $multiple; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Operators. |
41
|
|
|
* |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
private $operators; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Validation. |
48
|
|
|
* |
49
|
|
|
* @var QueryBuilderValidationInterface |
50
|
|
|
*/ |
51
|
|
|
private $validation; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Values. |
55
|
|
|
* |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
private $values; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Constructor. |
62
|
|
|
* |
63
|
|
|
* @param string $id The id. |
64
|
|
|
* @param string $type The type. |
65
|
|
|
* @param array $operators The operators. |
66
|
|
|
* @throws UnexpectedValueException Throws an unexpected value exception if an argument is invalid. |
67
|
|
|
*/ |
68
|
|
|
public function __construct($id, $type, array $operators) { |
69
|
|
|
parent::__construct(); |
70
|
|
|
$this->setId($id); |
71
|
|
|
$this->setLabel(""); |
72
|
|
|
$this->setMultiple(false); |
73
|
|
|
$this->setOperators($operators); |
74
|
|
|
$this->setType($type); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritDoc} |
79
|
|
|
*/ |
80
|
|
|
public function getLabel() { |
81
|
|
|
return $this->label; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritDoc} |
86
|
|
|
*/ |
87
|
|
|
public function getMultiple() { |
88
|
|
|
return $this->multiple; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritDoc} |
93
|
|
|
*/ |
94
|
|
|
public function getOperators() { |
95
|
|
|
return $this->operators; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* {@inheritDoc} |
100
|
|
|
*/ |
101
|
|
|
public function getValidation() { |
102
|
|
|
return $this->validation; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritDoc} |
107
|
|
|
*/ |
108
|
|
|
public function getValues() { |
109
|
|
|
return $this->values; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* {@inheritDoc} |
114
|
|
|
*/ |
115
|
|
|
public function jsonSerialize() { |
116
|
|
|
return QueryBuilderNormalizer::normalizeQueryBuilderFilter($this); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Set the label. |
121
|
|
|
* |
122
|
|
|
* @param string $label The label. |
123
|
|
|
* @return QueryBuilderFilterInterface Returns this filter. |
124
|
|
|
*/ |
125
|
|
|
public function setLabel($label) { |
126
|
|
|
$this->label = $label; |
127
|
|
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Set the multiple. |
132
|
|
|
* |
133
|
|
|
* @param bool $multiple The multiple. |
134
|
|
|
* @return QueryBuilderFilterInterface Returns this filter. |
135
|
|
|
*/ |
136
|
|
|
public function setMultiple($multiple) { |
137
|
|
|
$this->multiple = $multiple; |
138
|
|
|
return $this; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Set the operators. |
143
|
|
|
* |
144
|
|
|
* @param array $operators The operators. |
145
|
|
|
* @return QueryBuilderFilterInterface Returns this filter. |
146
|
|
|
* @throws UnexpectedValueException Throws an unexpected value exception if an operator is invalid. |
147
|
|
|
*/ |
148
|
|
|
public function setOperators(array $operators) { |
149
|
|
|
foreach ($operators as $current) { |
150
|
|
|
if (null !== $current && false === array_key_exists($current, QueryBuilderEnumerator::enumOperators())) { |
151
|
|
|
throw new UnexpectedValueException(sprintf("The operator \"%s\" is invalid", $current)); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
$this->operators = $operators; |
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Set the validation. |
160
|
|
|
* |
161
|
|
|
* @param QueryBuilderValidationInterface|null $validation The validation. |
162
|
|
|
* @return QueryBuilderFilterInterface Returns this filter. |
163
|
|
|
*/ |
164
|
|
|
public function setValidation(QueryBuilderValidationInterface $validation = null) { |
165
|
|
|
$this->validation = $validation; |
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Set the values. |
171
|
|
|
* |
172
|
|
|
* @param array $values The values. |
173
|
|
|
* @return QueryBuilderFilterInterface Returns this filter. |
174
|
|
|
*/ |
175
|
|
|
public function setValues(array $values) { |
176
|
|
|
$this->values = $values; |
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|