Completed
Push — master ( 5d7a16...eaa238 )
by WEBEWEB
29:29
created

DataTablesWrapper::getMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\API;
13
14
use WBW\Bundle\JQuery\DataTablesBundle\Provider\DataTablesProviderInterface;
15
use WBW\Library\Core\Network\HTTP\HTTPInterface;
16
17
/**
18
 * DataTables wrapper.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\JQuery\DataTablesBundle\API
22
 */
23
class DataTablesWrapper implements DataTablesWrapperInterface, HTTPInterface {
24
25
    /**
26
     * Columns.
27
     *
28
     * @var DataTablesColumnInterface[]
29
     */
30
    private $columns;
31
32
    /**
33
     * Mapping.
34
     *
35
     * @var DataTablesMappingInterface
36
     */
37
    private $mapping;
38
39
    /**
40
     * Method.
41
     *
42
     * @var string
43
     */
44
    private $method;
45
46
    /**
47
     * Name.
48
     *
49
     * @var string
50
     */
51
    private $name;
52
53
    /**
54
     * Options.
55
     *
56
     * @var DataTablesOptionsInterface
57
     */
58
    private $options;
59
60
    /**
61
     * Order.
62
     *
63
     * @var array
64
     */
65
    private $order;
66
67
    /**
68
     * Processing.
69
     *
70
     * @var bool
71
     */
72
    private $processing;
73
74
    /**
75
     * Provider.
76
     *
77
     * @var DataTablesProviderInterface
78
     */
79
    private $provider;
80
81
    /**
82
     * Request.
83
     *
84
     * @var DataTablesRequestInterface
85
     */
86
    private $request;
87
88
    /**
89
     * Response.
90
     *
91
     * @var DataTablesResponseInterface
92
     */
93
    private $response;
94
95
    /**
96
     * Server side.
97
     *
98
     * @var bool
99
     */
100
    private $serverSide;
101
102
    /**
103
     * URL.
104
     *
105
     * @var string
106
     */
107
    private $url;
108
109
    /**
110
     * Constructor.
111
     *
112
     * @param string $method The method.
113
     * @param string $url The URL.
114
     * @param string $name The name.
115
     */
116
    public function __construct($method, $url, $name) {
117
        $this->setColumns([]);
118
        $this->setMethod($method);
119
        $this->setMapping(new DataTablesMapping());
120
        $this->setName($name);
121
        $this->setOrder([]);
122
        $this->setProcessing(true);
123
        $this->setServerSide(true);
124
        $this->setUrl($url);
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130
    public function addColumn(DataTablesColumnInterface $column) {
131
        if (null === $column->getMapping()->getPrefix()) {
132
            $column->getMapping()->setPrefix($this->mapping->getPrefix());
133
        }
134
        $this->columns[$column->getData()] = $column;
135
        return $this;
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     */
141
    public function getColumn($data) {
142
        if (true === array_key_exists($data, $this->columns)) {
143
            return $this->columns[$data];
144
        }
145
        return null;
146
    }
147
148
    /**
149
     * {@inheritdoc}
150
     */
151
    public function getColumns() {
152
        return $this->columns;
153
    }
154
155
    /**
156
     * {@inheritdoc}
157
     */
158
    public function getMapping() {
159
        return $this->mapping;
160
    }
161
162
    /**
163
     * {@inheritdoc}
164
     */
165
    public function getMethod() {
166
        return $this->method;
167
    }
168
169
    /**
170
     * {@inheritdoc}
171
     */
172
    public function getName() {
173
        return $this->name;
174
    }
175
176
    /**
177
     * {@inheritdoc}
178
     */
179
    public function getOptions() {
180
        return $this->options;
181
    }
182
183
    /**
184
     * {@inheritdoc}
185
     */
186
    public function getOrder() {
187
        return $this->order;
188
    }
189
190
    /**
191
     * {@inheritdoc}
192
     */
193
    public function getProcessing() {
194
        return $this->processing;
195
    }
196
197
    /**
198
     * {@inheritdoc}
199
     */
200
    public function getProvider() {
201
        return $this->provider;
202
    }
203
204
    /**
205
     * {@inheritdoc}
206
     */
207
    public function getRequest() {
208
        return $this->request;
209
    }
210
211
    /**
212
     * {@inheritdoc}
213
     */
214
    public function getResponse() {
215
        return $this->response;
216
    }
217
218
    /**
219
     * {@inheritdoc}
220
     */
221
    public function getServerSide() {
222
        return $this->serverSide;
223
    }
224
225
    /**
226
     * {@inheritdoc}
227
     */
228
    public function getUrl() {
229
        return $this->url;
230
    }
231
232
    /**
233
     * Remove a column.
234
     *
235
     * @param DataTablesColumnInterface $column The column.
236
     * @return DataTablesWrapperInterface Returns this wrapper.
237
     */
238
    public function removeColumn(DataTablesColumnInterface $column) {
239
        if (true === array_key_exists($column->getData(), $this->columns)) {
240
            $this->columns[$column->getData()]->getMapping()->setPrefix(null);
241
            unset($this->columns[$column->getData()]);
242
        }
243
        return $this;
244
    }
245
246
    /**
247
     * Set the columns.
248
     *
249
     * @param DataTablesColumnInterface[] $columns The columns.
250
     * @return DataTablesWrapperInterface Returns this wrapper.
251
     */
252
    private function setColumns(array $columns) {
253
        $this->columns = $columns;
254
        return $this;
255
    }
256
257
    /**
258
     * Set the method.
259
     *
260
     * @param string $method The method.
261
     * @return DataTablesWrapperInterface Returns this wrapper.
262
     */
263
    public function setMethod($method) {
264
        $this->method = (true === in_array($method, [self::HTTP_METHOD_GET, self::HTTP_METHOD_POST]) ? $method : self::HTTP_METHOD_POST);
265
        return $this;
266
    }
267
268
    /**
269
     * Set the mapping.
270
     *
271
     * @param DataTablesMappingInterface $mapping The mapping
272
     * @return DataTablesWrapperInterface Returns this wrapper.
273
     */
274
    public function setMapping(DataTablesMappingInterface $mapping) {
275
        $this->mapping = $mapping;
276
        return $this;
277
    }
278
279
    /**
280
     * Set the name.
281
     *
282
     * @param string $name The name.
283
     * @return DataTablesWrapperInterface Returns this wrapper.
284
     */
285
    public function setName($name) {
286
        $this->name = $name;
287
        return $this;
288
    }
289
290
    /**
291
     * Set the options.
292
     *
293
     * @param DataTablesOptionsInterface $options The options.
294
     * @return DataTablesWrapperInterface Returns this wrapper.
295
     */
296
    public function setOptions(DataTablesOptionsInterface $options) {
297
        $this->options = $options;
298
        return $this;
299
    }
300
301
    /**
302
     * Set the order.
303
     *
304
     * @param array $order The order.
305
     * @return DataTablesWrapperInterface Returns this wrapper.
306
     */
307
    public function setOrder(array $order) {
308
        $this->order = $order;
309
        return $this;
310
    }
311
312
    /**
313
     * Set the processing.
314
     *
315
     * @param bool $processing The processing.
316
     * @return DataTablesWrapperInterface Returns this wrapper.
317
     */
318
    public function setProcessing($processing) {
319
        $this->processing = (false === $processing ? false : true);
320
        return $this;
321
    }
322
323
    /**
324
     * Set the provider.
325
     *
326
     * @param DataTablesProviderInterface $provider The provider.
327
     * @return DataTablesWrapperInterface Returns this wrapper.
328
     */
329
    public function setProvider(DataTablesProviderInterface $provider) {
330
        $this->provider = $provider;
331
        return $this;
332
    }
333
334
    /**
335
     * Set the request.
336
     *
337
     * @param DataTablesRequestInterface $request The request.
338
     * @return DataTablesWrapperInterface Returns this wrapper.
339
     */
340
    public function setRequest(DataTablesRequestInterface $request) {
341
        $this->request = $request;
342
        return $this;
343
    }
344
345
    /**
346
     * Set the response.
347
     *
348
     * @param DataTablesResponseInterface $response The response.
349
     * @return DataTablesWrapperInterface Returns this wrapper.
350
     */
351
    public function setResponse(DataTablesResponseInterface $response) {
352
        $this->response = $response;
353
        return $this;
354
    }
355
356
    /**
357
     * Set the server side.
358
     *
359
     * @param bool $serverSide The server side.
360
     * @return DataTablesWrapperInterface Returns this wrapper.
361
     */
362
    public function setServerSide($serverSide) {
363
        $this->serverSide = (false === $serverSide ? false : true);
364
        return $this;
365
    }
366
367
    /**
368
     * Set the URL.
369
     *
370
     * @param string $url The UTL.
371
     * @return DataTablesWrapperInterface Returns this wrapper.
372
     */
373
    public function setUrl($url) {
374
        $this->url = $url;
375
        return $this;
376
    }
377
378
}
379