|
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
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* jQuery QueryBuilder validation. |
|
18
|
|
|
* |
|
19
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
20
|
|
|
* @package WBW\Bundle\JQuery\QueryBuilderBundle\API |
|
21
|
|
|
*/ |
|
22
|
|
|
class QueryBuilderValidation implements JsonSerializable { |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Allow empty value. |
|
26
|
|
|
* |
|
27
|
|
|
* @var boolean |
|
28
|
|
|
*/ |
|
29
|
|
|
private $allowEmptyValue; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Callback. |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
private $callback; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Format. |
|
40
|
|
|
* |
|
41
|
|
|
* @var string|array |
|
42
|
|
|
*/ |
|
43
|
|
|
private $format; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Max. |
|
47
|
|
|
* |
|
48
|
|
|
* @var integer|float|string |
|
49
|
|
|
*/ |
|
50
|
|
|
private $max; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Messages. |
|
54
|
|
|
* |
|
55
|
|
|
* @var array |
|
56
|
|
|
*/ |
|
57
|
|
|
private $messages; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Min. |
|
61
|
|
|
* |
|
62
|
|
|
* @var integer|float|string |
|
63
|
|
|
*/ |
|
64
|
|
|
private $min; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Step. |
|
68
|
|
|
* |
|
69
|
|
|
* @var integer|float |
|
70
|
|
|
*/ |
|
71
|
|
|
private $step; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Constructor. |
|
75
|
|
|
*/ |
|
76
|
|
|
public function __construct() { |
|
77
|
|
|
// NOTHING TO DO. |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get the allow empty value. |
|
82
|
|
|
* |
|
83
|
|
|
* @return boolean Returns the allow empty value. |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getAllowEmptyValue() { |
|
86
|
|
|
return $this->allowEmptyValue; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get the callback. |
|
91
|
|
|
* |
|
92
|
|
|
* @return string |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getCallback() { |
|
95
|
|
|
return $this->callback; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Get the format. |
|
100
|
|
|
* |
|
101
|
|
|
* @return string|array Returns the dormat. |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getFormat() { |
|
104
|
|
|
return $this->format; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Get the max. |
|
109
|
|
|
* |
|
110
|
|
|
* @return integer|float|string Returns the max. |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getMax() { |
|
113
|
|
|
return $this->max; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Get the messages. |
|
118
|
|
|
* |
|
119
|
|
|
* @return array Returns the messages. |
|
120
|
|
|
*/ |
|
121
|
|
|
public function getMessages() { |
|
122
|
|
|
return $this->messages; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Get the min. |
|
127
|
|
|
* |
|
128
|
|
|
* @return integer|float|string Returns the min. |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getMin() { |
|
131
|
|
|
return $this->min; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Get the step. |
|
136
|
|
|
* |
|
137
|
|
|
* @return integer|float Returns the step/ |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getStep() { |
|
140
|
|
|
return $this->step; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Serialize this instance. |
|
145
|
|
|
* |
|
146
|
|
|
* @return array Returns an array representing this instance. |
|
147
|
|
|
*/ |
|
148
|
|
|
public function jsonSerialize() { |
|
149
|
|
|
return $this->toArray(); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Set the allow empty value. |
|
154
|
|
|
* |
|
155
|
|
|
* @param boolean $allowEmptyValue The allow empty value. |
|
156
|
|
|
* @return QueryBuilderValidation Returns the jQuery QueryBuilder validation. |
|
157
|
|
|
*/ |
|
158
|
|
|
public function setAllowEmptyValue($allowEmptyValue) { |
|
159
|
|
|
$this->allowEmptyValue = $allowEmptyValue; |
|
160
|
|
|
return $this; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Set the callback. |
|
165
|
|
|
* |
|
166
|
|
|
* @param string $callback The callback. |
|
167
|
|
|
* @return QueryBuilderValidation Returns the jQuery QueryBuilder validation. |
|
168
|
|
|
*/ |
|
169
|
|
|
public function setCallback($callback) { |
|
170
|
|
|
$this->callback = $callback; |
|
171
|
|
|
return $this; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Set the format. |
|
176
|
|
|
* |
|
177
|
|
|
* @param string|array $format The format. |
|
178
|
|
|
* @return QueryBuilderValidation Returns the jQuery QueryBuilder validation. |
|
179
|
|
|
*/ |
|
180
|
|
|
public function setFormat($format) { |
|
181
|
|
|
$this->format = $format; |
|
182
|
|
|
return $this; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Set the max. |
|
187
|
|
|
* |
|
188
|
|
|
* @param integer|float|string $max The max. |
|
189
|
|
|
* @return QueryBuilderValidation Returns the jQuery QueryBuilder validation. |
|
190
|
|
|
*/ |
|
191
|
|
|
public function setMax($max) { |
|
192
|
|
|
$this->max = $max; |
|
193
|
|
|
return $this; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Set the messages. |
|
198
|
|
|
* |
|
199
|
|
|
* @param array $messages The messages. |
|
200
|
|
|
* @return QueryBuilderValidation Returns the jQuery QueryBuilder validation. |
|
201
|
|
|
*/ |
|
202
|
|
|
public function setMessages(array $messages = []) { |
|
203
|
|
|
$this->messages = $messages; |
|
204
|
|
|
return $this; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Set the min. |
|
209
|
|
|
* |
|
210
|
|
|
* @param integer|float|string $min The min. |
|
211
|
|
|
* @return QueryBuilderValidation Returns the jQuery QueryBuilder validation. |
|
212
|
|
|
*/ |
|
213
|
|
|
public function setMin($min) { |
|
214
|
|
|
$this->min = $min; |
|
215
|
|
|
return $this; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Set the step. |
|
220
|
|
|
* |
|
221
|
|
|
* @param integer|float $step The step. |
|
222
|
|
|
* @return QueryBuilderValidation Returns the jQuery QueryBuilder validation. |
|
223
|
|
|
*/ |
|
224
|
|
|
public function setStep($step) { |
|
225
|
|
|
$this->step = $step; |
|
226
|
|
|
return $this; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* Convert into an array representing this instance. |
|
231
|
|
|
* |
|
232
|
|
|
* @return array Returns an array representing this instance. |
|
233
|
|
|
*/ |
|
234
|
|
|
public function toArray() { |
|
235
|
|
|
|
|
236
|
|
|
// Initialize the output. |
|
237
|
|
|
$output = []; |
|
238
|
|
|
|
|
239
|
|
|
// Check the format. |
|
240
|
|
|
if (null !== $this->format) { |
|
241
|
|
|
$output["format"] = $this->format; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
// Check the min. |
|
245
|
|
|
if (null !== $this->min) { |
|
246
|
|
|
$output["min"] = $this->min; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
// Check the max. |
|
250
|
|
|
if (null !== $this->max) { |
|
251
|
|
|
$output["max"] = $this->max; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
// Check the step. |
|
255
|
|
|
if (null !== $this->step) { |
|
256
|
|
|
$output["step"] = $this->step; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
// Check the messages. |
|
260
|
|
|
if (null !== $this->messages) { |
|
261
|
|
|
$output["messages"] = $this->messages; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
// Check the allow empty value. |
|
265
|
|
|
if (null !== $this->allowEmptyValue) { |
|
266
|
|
|
$output["allow_empty_value"] = $this->allowEmptyValue; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
// Check the callback. |
|
270
|
|
|
if (null !== $this->callback) { |
|
271
|
|
|
$output["callback"] = $this->callback; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
// Return the output. |
|
275
|
|
|
return $output; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
} |
|
279
|
|
|
|