Completed
Push — master ( 3f5d51...85b3b0 )
by Arjay
01:13
created

HasOptions::rowId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Yajra\DataTables\Html;
4
5
use Yajra\DataTables\Html\Options;
6
7
/**
8
 * DataTables - Options builder.
9
 *
10
 * @see https://datatables.net/reference/option/
11
 */
12
trait HasOptions
13
{
14
    use Options\HasFeatures;
15
    use Options\HasData;
16
    use Options\HasCallbacks;
17
    use Options\HasColumns;
18
    use Options\HasInternationalisation;
19
    use Options\Plugins\AutoFill;
20
    use Options\Plugins\Buttons;
21
    use Options\Plugins\ColReorder;
22
    use Options\Plugins\FixedColumns;
23
    use Options\Plugins\FixedHeader;
24
    use Options\Plugins\KeyTable;
25
    use Options\Plugins\Responsive;
26
    use Options\Plugins\RowGroup;
27
    use Options\Plugins\RowReorder;
28
    use Options\Plugins\Scroller;
29
    use Options\Plugins\Select;
30
31
    /**
32
     * Set deferLoading option value.
33
     *
34
     * @param mixed $value
35
     * @return $this
36
     * @see https://datatables.net/reference/option/deferLoading
37
     */
38
    public function deferLoading($value = null)
39
    {
40
        $this->attributes['deferLoading'] = $value;
0 ignored issues
show
Bug introduced by
The property attributes does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
41
42
        return $this;
43
    }
44
45
    /**
46
     * Set destroy option value.
47
     *
48
     * @param bool $value
49
     * @return $this
50
     * @see https://datatables.net/reference/option/destroy
51
     */
52
    public function destroy(bool $value = false)
53
    {
54
        $this->attributes['destroy'] = $value;
55
56
        return $this;
57
    }
58
59
    /**
60
     * Set displayStart option value.
61
     *
62
     * @param int $value
63
     * @return $this
64
     * @see https://datatables.net/reference/option/displayStart
65
     */
66
    public function displayStart(int $value = 0)
67
    {
68
        $this->attributes['displayStart'] = $value;
69
70
        return $this;
71
    }
72
73
    /**
74
     * Set dom option value.
75
     *
76
     * @param string $value
77
     * @return $this
78
     * @see https://datatables.net/reference/option/dom
79
     */
80
    public function dom(string $value)
81
    {
82
        $this->attributes['dom'] = $value;
83
84
        return $this;
85
    }
86
87
    /**
88
     * Set lengthMenu option value.
89
     *
90
     * @param array $value
91
     * @return $this
92
     * @see https://datatables.net/reference/option/lengthMenu
93
     */
94
    public function lengthMenu(array $value = [10, 25, 50, 100])
95
    {
96
        $this->attributes['lengthMenu'] = $value;
97
98
        return $this;
99
    }
100
101
    /**
102
     * Set orders option value.
103
     *
104
     * @param array $value
105
     * @return $this
106
     * @see https://datatables.net/reference/option/order
107
     */
108
    public function orders(array $value)
109
    {
110
        $this->attributes['order'] = $value;
111
112
        return $this;
113
    }
114
115
    /**
116
     * Set orderCellsTop option value.
117
     *
118
     * @param bool $value
119
     * @return $this
120
     * @see https://datatables.net/reference/option/orderCellsTop
121
     */
122
    public function orderCellsTop(bool $value = false)
123
    {
124
        $this->attributes['orderCellsTop'] = $value;
125
126
        return $this;
127
    }
128
129
    /**
130
     * Set orderClasses option value.
131
     *
132
     * @param bool $value
133
     * @return $this
134
     * @see https://datatables.net/reference/option/orderClasses
135
     */
136
    public function orderClasses(bool $value = true)
137
    {
138
        $this->attributes['orderClasses'] = $value;
139
140
        return $this;
141
    }
142
143
    /**
144
     * Order option builder.
145
     *
146
     * @param int|array $index
147
     * @param string $direction
148
     * @return $this
149
     * @see https://datatables.net/reference/option/order
150
     */
151 View Code Duplication
    public function orderBy($index, $direction = 'desc')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152
    {
153
        if ($direction != 'desc') {
154
            $direction = 'asc';
155
        }
156
157
        if (is_array($index)) {
158
            $this->attributes['order'][] = $index;
159
        } else {
160
            $this->attributes['order'][] = [$index, $direction];
161
        }
162
163
        return $this;
164
    }
165
166
    /**
167
     * Order Fixed option builder.
168
     *
169
     * @param int|array $index
170
     * @param string $direction
171
     * @return $this
172
     * @see https://datatables.net/reference/option/orderFixed
173
     */
174 View Code Duplication
    public function orderByFixed($index, $direction = 'desc')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
175
    {
176
        if ($direction != 'desc') {
177
            $direction = 'asc';
178
        }
179
180
        if (is_array($index)) {
181
            $this->attributes['orderFixed'][] = $index;
182
        } else {
183
            $this->attributes['orderFixed'][] = [$index, $direction];
184
        }
185
186
        return $this;
187
    }
188
189
    /**
190
     * Set orderMulti option value.
191
     *
192
     * @param bool $value
193
     * @return $this
194
     * @see https://datatables.net/reference/option/orderMulti
195
     */
196
    public function orderMulti(bool $value = true)
197
    {
198
        $this->attributes['orderMulti'] = $value;
199
200
        return $this;
201
    }
202
203
    /**
204
     * Set pageLength option value.
205
     *
206
     * @param int $value
207
     * @return $this
208
     * @see https://datatables.net/reference/option/pageLength
209
     */
210
    public function pageLength(int $value = 10)
211
    {
212
        $this->attributes['pageLength'] = $value;
213
214
        return $this;
215
    }
216
217
    /**
218
     * Set pagingType option value.
219
     *
220
     * @param string $value
221
     * @return $this
222
     * @see https://datatables.net/reference/option/pagingType
223
     */
224
    public function pagingType(string $value = 'simple_numbers')
225
    {
226
        $this->attributes['pagingType'] = $value;
227
228
        return $this;
229
    }
230
231
    /**
232
     * Set renderer option value.
233
     *
234
     * @param mixed $value
235
     * @return $this
236
     * @see https://datatables.net/reference/option/renderer
237
     */
238
    public function renderer($value = 'bootstrap')
239
    {
240
        $this->attributes['renderer'] = $value;
241
242
        return $this;
243
    }
244
245
    /**
246
     * Set retrieve option value.
247
     *
248
     * @param bool $value
249
     * @return $this
250
     * @see https://datatables.net/reference/option/retrieve
251
     */
252
    public function retrieve(bool $value = false)
253
    {
254
        $this->attributes['retrieve'] = $value;
255
256
        return $this;
257
    }
258
259
    /**
260
     * Set rowId option value.
261
     *
262
     * @param string $value
263
     * @return $this
264
     * @see https://datatables.net/reference/option/rowId
265
     */
266
    public function rowId(string $value = 'DT_RowId')
267
    {
268
        $this->attributes['rowId'] = $value;
269
270
        return $this;
271
    }
272
273
    /**
274
     * Set scrollCollapse option value.
275
     *
276
     * @param mixed $value
277
     * @return $this
278
     * @see https://datatables.net/reference/option/scrollCollapse
279
     */
280
    public function scrollCollapse($value = false)
281
    {
282
        $this->attributes['scrollCollapse'] = $value;
283
284
        return $this;
285
    }
286
287
    /**
288
     * Set search option value.
289
     *
290
     * @param array $value
291
     * @return $this
292
     * @see https://datatables.net/reference/option/search
293
     */
294
    public function search(array $value)
295
    {
296
        $this->attributes['search'] = $value;
297
298
        return $this;
299
    }
300
301
    /**
302
     * Set searchCols option value.
303
     *
304
     * @param array $value
305
     * @return $this
306
     * @see https://datatables.net/reference/option/searchCols
307
     */
308
    public function searchCols(array $value)
309
    {
310
        $this->attributes['searchCols'] = $value;
311
312
        return $this;
313
    }
314
315
    /**
316
     * Set searchDelay option value.
317
     *
318
     * @param int $value
319
     * @return $this
320
     * @see https://datatables.net/reference/option/searchDelay
321
     */
322
    public function searchDelay(int $value)
323
    {
324
        $this->attributes['searchDelay'] = $value;
325
326
        return $this;
327
    }
328
329
    /**
330
     * Set stateDuration option value.
331
     *
332
     * @param int $value
333
     * @return $this
334
     * @see https://datatables.net/reference/option/stateDuration
335
     */
336
    public function stateDuration(int $value)
337
    {
338
        $this->attributes['stateDuration'] = $value;
339
340
        return $this;
341
    }
342
343
    /**
344
     * Set stripeClasses option value.
345
     *
346
     * @param array $value
347
     * @return $this
348
     * @see https://datatables.net/reference/option/stripeClasses
349
     */
350
    public function stripeClasses(array $value)
351
    {
352
        $this->attributes['stripeClasses'] = $value;
353
354
        return $this;
355
    }
356
357
    /**
358
     * Set tabIndex option value.
359
     *
360
     * @param int $value
361
     * @return $this
362
     * @see https://datatables.net/reference/option/tabIndex
363
     */
364
    public function tabIndex(int $value = 0)
365
    {
366
        $this->attributes['tabIndex'] = $value;
367
368
        return $this;
369
    }
370
}
371