Completed
Push — master ( c74a31...d374e8 )
by WEBEWEB
01:21
created

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