|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the jquery-datatables-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2018 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\DataTablesBundle\Model; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
|
15
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesColumnInterface; |
|
16
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesOrderInterface; |
|
17
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesRequestInterface; |
|
18
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesSearchInterface; |
|
19
|
|
|
use WBW\Library\Core\Network\HTTP\HttpInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* DataTables request. |
|
23
|
|
|
* |
|
24
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
25
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Model |
|
26
|
|
|
*/ |
|
27
|
|
|
class DataTablesRequest implements DataTablesRequestInterface, HttpInterface { |
|
28
|
|
|
|
|
29
|
|
|
use DataTablesWrapperTrait { |
|
30
|
|
|
setWrapper as public; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Columns. |
|
35
|
|
|
* |
|
36
|
|
|
* @var DataTablesColumnInterface[] |
|
37
|
|
|
*/ |
|
38
|
|
|
private $columns; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Draw. |
|
42
|
|
|
* |
|
43
|
|
|
* @var int |
|
44
|
|
|
*/ |
|
45
|
|
|
private $draw; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Length. |
|
49
|
|
|
* |
|
50
|
|
|
* @var int |
|
51
|
|
|
*/ |
|
52
|
|
|
private $length; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Order. |
|
56
|
|
|
* |
|
57
|
|
|
* @var DataTablesOrderInterface[] |
|
58
|
|
|
*/ |
|
59
|
|
|
private $order; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Query. |
|
63
|
|
|
* |
|
64
|
|
|
* @var ParameterBag |
|
65
|
|
|
*/ |
|
66
|
|
|
private $query; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Request. |
|
70
|
|
|
* |
|
71
|
|
|
* @var ParameterBag |
|
72
|
|
|
*/ |
|
73
|
|
|
private $request; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Search. |
|
77
|
|
|
* |
|
78
|
|
|
* @var DataTablesSearchInterface|null |
|
79
|
|
|
*/ |
|
80
|
|
|
private $search; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Start. |
|
84
|
|
|
* |
|
85
|
|
|
* @var int |
|
86
|
|
|
*/ |
|
87
|
|
|
private $start; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Constructor. |
|
91
|
|
|
*/ |
|
92
|
|
|
public function __construct() { |
|
93
|
|
|
$this->setColumns([]); |
|
94
|
|
|
$this->setDraw(0); |
|
95
|
|
|
$this->setLength(10); |
|
96
|
|
|
$this->setOrder([]); |
|
97
|
|
|
$this->setQuery(new ParameterBag()); |
|
98
|
|
|
$this->setRequest(new ParameterBag()); |
|
99
|
|
|
$this->setStart(0); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* {@inheritDoc} |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getColumn(string $data): ?DataTablesColumnInterface { |
|
106
|
|
|
foreach ($this->columns as $current) { |
|
107
|
|
|
if ($data === $current->getData()) { |
|
108
|
|
|
return $current; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
return null; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* {@inheritDoc} |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getColumns(): array { |
|
118
|
|
|
return $this->columns; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* {@inheritDoc} |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getDraw(): int { |
|
125
|
|
|
return $this->draw; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* {@inheritDoc} |
|
130
|
|
|
*/ |
|
131
|
|
|
public function getLength(): int { |
|
132
|
|
|
return $this->length; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* {@inheritDoc} |
|
137
|
|
|
*/ |
|
138
|
|
|
public function getOrder(): array { |
|
139
|
|
|
return $this->order; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* {@inheritDoc} |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getQuery(): ParameterBag { |
|
146
|
|
|
return $this->query; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* {@inheritDoc} |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getRequest(): ParameterBag { |
|
153
|
|
|
return $this->request; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* {@inheritDoc} |
|
158
|
|
|
*/ |
|
159
|
|
|
public function getSearch(): ?DataTablesSearchInterface { |
|
160
|
|
|
return $this->search; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* {@inheritDoc} |
|
165
|
|
|
*/ |
|
166
|
|
|
public function getStart(): int { |
|
167
|
|
|
return $this->start; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Set the columns. |
|
172
|
|
|
* |
|
173
|
|
|
* @param DataTablesColumnInterface[] $columns The columns. |
|
174
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
175
|
|
|
*/ |
|
176
|
|
|
public function setColumns(array $columns): DataTablesRequestInterface { |
|
177
|
|
|
$this->columns = $columns; |
|
178
|
|
|
return $this; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Set the draw. |
|
183
|
|
|
* |
|
184
|
|
|
* @param int $draw The draw. |
|
185
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
186
|
|
|
*/ |
|
187
|
|
|
public function setDraw(int $draw): DataTablesRequestInterface { |
|
188
|
|
|
$this->draw = $draw; |
|
189
|
|
|
return $this; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Set the length. |
|
194
|
|
|
* |
|
195
|
|
|
* @param int $length The length. |
|
196
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
197
|
|
|
*/ |
|
198
|
|
|
public function setLength(int $length): DataTablesRequestInterface { |
|
199
|
|
|
$this->length = $length; |
|
200
|
|
|
return $this; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Set the order. |
|
205
|
|
|
* |
|
206
|
|
|
* @param DataTablesOrderInterface[] $order The order. |
|
207
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
208
|
|
|
*/ |
|
209
|
|
|
public function setOrder(array $order): DataTablesRequestInterface { |
|
210
|
|
|
$this->order = $order; |
|
211
|
|
|
return $this; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Set the request. |
|
216
|
|
|
* |
|
217
|
|
|
* @param ParameterBag $query The query. |
|
218
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
219
|
|
|
*/ |
|
220
|
|
|
protected function setQuery(ParameterBag $query): DataTablesRequestInterface { |
|
221
|
|
|
$this->query = $query; |
|
222
|
|
|
return $this; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* Set the request. |
|
227
|
|
|
* |
|
228
|
|
|
* @param ParameterBag $request The request. |
|
229
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
230
|
|
|
*/ |
|
231
|
|
|
protected function setRequest(ParameterBag $request): DataTablesRequestInterface { |
|
232
|
|
|
$this->request = $request; |
|
233
|
|
|
return $this; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* Set the search. |
|
238
|
|
|
* |
|
239
|
|
|
* @param DataTablesSearchInterface|null $search The search. |
|
240
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
241
|
|
|
*/ |
|
242
|
|
|
public function setSearch(?DataTablesSearchInterface $search): DataTablesRequestInterface { |
|
243
|
|
|
$this->search = $search; |
|
244
|
|
|
return $this; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* Set the start. |
|
249
|
|
|
* |
|
250
|
|
|
* @param int $start The start. |
|
251
|
|
|
* @return DataTablesRequestInterface Returns this request. |
|
252
|
|
|
*/ |
|
253
|
|
|
public function setStart(int $start): DataTablesRequestInterface { |
|
254
|
|
|
$this->start = $start; |
|
255
|
|
|
return $this; |
|
256
|
|
|
} |
|
257
|
|
|
} |
|
258
|
|
|
|