Completed
Push — master ( de1426...00195f )
by Arjay
01:21
created

Select::addClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Yajra\DataTables\Html\Options\Plugins;
4
5
use Yajra\DataTables\Html\Builder;
6
7
/**
8
 * DataTables - Select plugin option builder.
9
 *
10
 * @see https://datatables.net/extensions/select
11
 * @see https://datatables.net/reference/option/select
12
 */
13
trait Select
14
{
15
    /**
16
     * Set select option value.
17
     *
18
     * @param bool|array $value
19
     * @return $this
20
     * @see https://datatables.net/reference/option/select
21
     */
22
    public function select($value = true)
23
    {
24
        $this->attributes['select'] = $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...
25
26
        return $this;
27
    }
28
29
    /**
30
     * Set select blurable option value.
31
     *
32
     * @param bool $value
33
     * @return $this
34
     * @see https://datatables.net/reference/option/select.blurable
35
     */
36
    public function selectBlurable(bool $value = true)
37
    {
38
        $this->attributes['select']['blurable'] = $value;
39
40
        return $this;
41
    }
42
43
    /**
44
     * Set select className option value.
45
     *
46
     * @param string $value
47
     * @return $this
48
     * @see https://datatables.net/reference/option/select.className
49
     */
50
    public function selectClassName($value = 'selected')
51
    {
52
        $this->attributes['select']['className'] = $value;
53
54
        return $this;
55
    }
56
57
    /**
58
     * Append a class name to className option value.
59
     *
60
     * @param string $class
61
     * @return $this
62
     */
63 View Code Duplication
    public function addClass($class)
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...
64
    {
65
        if (! isset($this->attributes['className'])) {
66
            $this->attributes['className'] = $class;
67
        } else {
68
            $this->attributes['className'] .= " $class";
69
        }
70
        return $this;
71
    }
72
73
74
    /**
75
     * Set select info option value.
76
     *
77
     * @param bool $value
78
     * @return $this
79
     * @see https://datatables.net/reference/option/select.info
80
     */
81
    public function selectInfo(bool $value = true)
82
    {
83
        $this->attributes['select']['info'] = $value;
84
85
        return $this;
86
    }
87
88
    /**
89
     * Set select items option value.
90
     *
91
     * @param string $value
92
     * @return $this
93
     * @see https://datatables.net/reference/option/select.items
94
     */
95
    public function selectItems($value = 'row')
96
    {
97
        $this->attributes['select']['items'] = $value;
98
99
        return $this;
100
    }
101
102
    /**
103
     * Set select items option value to row.
104
     *
105
     * @return $this
106
     * @see https://datatables.net/reference/option/select.items
107
     */
108
    public function selectItemsRow()
109
    {
110
        $this->attributes['select']['items'] = Builder::SELECT_ITEMS_ROW;
111
112
        return $this;
113
    }
114
115
    /**
116
     * Set select items option value to column.
117
     *
118
     * @return $this
119
     * @see https://datatables.net/reference/option/select.items
120
     */
121
    public function selectItemsColumn()
122
    {
123
        $this->attributes['select']['items'] = Builder::SELECT_ITEMS_COLUMN;
124
125
        return $this;
126
    }
127
128
    /**
129
     * Set select items option value to cell.
130
     *
131
     * @return $this
132
     * @see https://datatables.net/reference/option/select.items
133
     */
134
    public function selectItemsCell()
135
    {
136
        $this->attributes['select']['items'] = Builder::SELECT_ITEMS_CELL;
137
138
        return $this;
139
    }
140
141
    /**
142
     * Set select selector option value.
143
     *
144
     * @param string $value
145
     * @return $this
146
     * @see https://datatables.net/reference/option/select.selector
147
     */
148
    public function selectSelector($value = 'td')
149
    {
150
        $this->attributes['select']['selector'] = $value;
151
152
        return $this;
153
    }
154
155
    /**
156
     * Set select style option value.
157
     *
158
     * @param string $value
159
     * @return $this
160
     * @see https://datatables.net/reference/option/select.style
161
     */
162
    public function selectStyle($value = 'os')
163
    {
164
        $this->attributes['select']['style'] = $value;
165
166
        return $this;
167
    }
168
169
    /**
170
     * Set select style option value to api.
171
     *
172
     * @return $this
173
     * @see https://datatables.net/reference/option/select.style
174
     */
175
    public function selectStyleApi()
176
    {
177
        $this->attributes['select']['style'] = Builder::SELECT_STYLE_API;
178
179
        return $this;
180
    }
181
182
    /**
183
     * Set select style option value to single.
184
     *
185
     * @return $this
186
     * @see https://datatables.net/reference/option/select.style
187
     */
188
    public function selectStyleSingle()
189
    {
190
        $this->attributes['select']['style'] = Builder::SELECT_STYLE_SINGLE;
191
192
        return $this;
193
    }
194
195
    /**
196
     * Set select style option value to multi.
197
     *
198
     * @return $this
199
     * @see https://datatables.net/reference/option/select.style
200
     */
201
    public function selectStyleMulti()
202
    {
203
        $this->attributes['select']['style'] = Builder::SELECT_STYLE_MULTI;
204
205
        return $this;
206
    }
207
208
    /**
209
     * Set select style option value to os.
210
     *
211
     * @return $this
212
     * @see https://datatables.net/reference/option/select.style
213
     */
214
    public function selectStyleOS()
215
    {
216
        $this->attributes['select']['style'] = Builder::SELECT_STYLE_OS;
217
218
        return $this;
219
    }
220
221
    /**
222
     * Set select style option value to multi+shift.
223
     *
224
     * @return $this
225
     * @see https://datatables.net/reference/option/select.style
226
     */
227
    public function selectStyleMultiShift()
228
    {
229
        $this->attributes['select']['style'] = Builder::SELECT_STYLE_MULTI_SHIFT;
230
231
        return $this;
232
    }
233
}
234