|
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 JsonSerializable; |
|
15
|
|
|
use WBW\Bundle\JQuery\QueryBuilderBundle\Data\AbstractQueryBuilderData; |
|
16
|
|
|
use WBW\Library\Core\Exception\Argument\IllegalArgumentException; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* jQuery QueryBuilder filter. |
|
20
|
|
|
* |
|
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
22
|
|
|
* @package WBW\Bundle\JQuery\QueryBuilderBundle\API |
|
23
|
|
|
*/ |
|
24
|
|
|
class QueryBuilderFilter extends AbstractQueryBuilderData implements JsonSerializable, QueryBuilderOperatorInterface { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Label. |
|
28
|
|
|
* |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
private $label = ""; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Multiple. |
|
35
|
|
|
* |
|
36
|
|
|
* @var boolean |
|
37
|
|
|
*/ |
|
38
|
|
|
private $multiple = false; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Operators. |
|
42
|
|
|
* |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
private $operators; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Validation. |
|
49
|
|
|
* |
|
50
|
|
|
* @var QueryBuilderValidation |
|
51
|
|
|
*/ |
|
52
|
|
|
private $validation; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Values. |
|
56
|
|
|
* |
|
57
|
|
|
* @var array |
|
58
|
|
|
*/ |
|
59
|
|
|
private $values; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Constructor. |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $id The id. |
|
65
|
|
|
* @param string $type The type. |
|
66
|
|
|
* @param array $operators The operators. |
|
67
|
|
|
* @throws IllegalArgumentException Throws an illegal argument exception if an argument is invalid. |
|
68
|
|
|
*/ |
|
69
|
|
|
public function __construct($id, $type, array $operators) { |
|
70
|
|
|
parent::__construct($id, $type); |
|
71
|
|
|
$this->setOperators($operators); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get the label. |
|
76
|
|
|
* |
|
77
|
|
|
* @return Return the label. |
|
78
|
|
|
*/ |
|
79
|
|
|
final public function getLabel() { |
|
80
|
|
|
return $this->label; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get the multiple. |
|
85
|
|
|
* |
|
86
|
|
|
* @return boolean Returns the multiple. |
|
87
|
|
|
*/ |
|
88
|
|
|
final public function getMultiple() { |
|
89
|
|
|
return $this->multiple; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Get the operators. |
|
94
|
|
|
* |
|
95
|
|
|
* @return array Returns the operators. |
|
96
|
|
|
*/ |
|
97
|
|
|
final public function getOperators() { |
|
98
|
|
|
return $this->operators; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get the validation. |
|
103
|
|
|
* |
|
104
|
|
|
* @return QueryBuilderValidation Returns the validation. |
|
105
|
|
|
*/ |
|
106
|
|
|
final public function getValidation() { |
|
107
|
|
|
return $this->validation; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Get the values. |
|
112
|
|
|
* |
|
113
|
|
|
* @return array Returns the values. |
|
114
|
|
|
*/ |
|
115
|
|
|
final public function getValues() { |
|
116
|
|
|
return $this->values; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Serialize this instance. |
|
121
|
|
|
* |
|
122
|
|
|
* @return array Returns an array representing this instance. |
|
123
|
|
|
*/ |
|
124
|
|
|
final public function jsonSerialize() { |
|
125
|
|
|
return $this->toArray(); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Set the label. |
|
130
|
|
|
* |
|
131
|
|
|
* @param string $label The label. |
|
132
|
|
|
* @return QueryBuilderFilter Returns the jQuery QueryBuilder filter. |
|
133
|
|
|
*/ |
|
134
|
|
|
final public function setLabel($label) { |
|
135
|
|
|
$this->label = $label; |
|
136
|
|
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Set the multiple. |
|
141
|
|
|
* |
|
142
|
|
|
* @param boolean $multiple The multiple. |
|
143
|
|
|
* @return QueryBuilderFilter Returns the jQuery QueryBuilder filter. |
|
144
|
|
|
*/ |
|
145
|
|
|
final public function setMultiple($multiple = false) { |
|
146
|
|
|
$this->multiple = $multiple; |
|
147
|
|
|
return $this; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Set the operators. |
|
152
|
|
|
* |
|
153
|
|
|
* @param array $operators The operators. |
|
154
|
|
|
* @return QueryBuilderFilter Returns the jQuery QueryBuilder filter. |
|
155
|
|
|
*/ |
|
156
|
|
|
final public function setOperators(array $operators = []) { |
|
157
|
|
|
foreach ($operators as $current) { |
|
158
|
|
|
if (false === array_key_exists($current, self::OPERATORS)) { |
|
159
|
|
|
throw new IllegalArgumentException("The operator \"" . $current . "\" is invalid"); |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
$this->operators = $operators; |
|
163
|
|
|
return $this; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Set the validation. |
|
168
|
|
|
* |
|
169
|
|
|
* @param QueryBuilderValidation $validation The validation. |
|
170
|
|
|
* @return QueryBuilderFilter Returns the jQuery QueryBuilder filter. |
|
171
|
|
|
*/ |
|
172
|
|
|
final public function setValidation(QueryBuilderValidation $validation = null) { |
|
173
|
|
|
$this->validation = $validation; |
|
174
|
|
|
return $this; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Set the values. |
|
179
|
|
|
* |
|
180
|
|
|
* @param array $values The values. |
|
181
|
|
|
* @return QueryBuilderFilter Returns the jQuery QueryBuilder filter. |
|
182
|
|
|
*/ |
|
183
|
|
|
final public function setValues(array $values = []) { |
|
184
|
|
|
$this->values = $values; |
|
185
|
|
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Convert into an array representing this instance. |
|
190
|
|
|
* |
|
191
|
|
|
* @return array Returns an array representing this instance. |
|
192
|
|
|
*/ |
|
193
|
|
|
final public function toArray() { |
|
194
|
|
|
|
|
195
|
|
|
// Initialiaze the output. |
|
196
|
|
|
$output = []; |
|
197
|
|
|
|
|
198
|
|
|
$output["id"] = $this->getId(); |
|
199
|
|
|
|
|
200
|
|
|
if (null !== $this->getField()) { |
|
201
|
|
|
$output["field"] = $this->getField(); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
$output["label"] = $this->label; |
|
205
|
|
|
$output["type"] = $this->getType(); |
|
206
|
|
|
|
|
207
|
|
|
if (null !== $this->getInput()) { |
|
208
|
|
|
$output["input"] = $this->getInput(); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
if (null !== $this->values) { |
|
212
|
|
|
$output["values"] = $this->values; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
if (null !== $this->multiple && true === $this->multiple) { |
|
216
|
|
|
$output["multiple"] = $this->multiple; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
if (null !== $this->validation) { |
|
220
|
|
|
$output["validation"] = $this->validation->toArray(); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
$output["operators"] = $this->operators; |
|
224
|
|
|
|
|
225
|
|
|
// Return the output. |
|
226
|
|
|
return $output; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
} |
|
230
|
|
|
|