Passed
Push — master ( db0af9...5e9f02 )
by Ferry
03:57
created

DefaultOption::filterable()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 1
nop 3
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: User
5
 * Date: 1/26/2019
6
 * Time: 6:00 PM
7
 */
8
9
namespace crocodicstudio\crudbooster\controllers\scaffolding\traits;
10
11
use crocodicstudio\crudbooster\controllers\scaffolding\singletons\ColumnSingleton;
12
use crocodicstudio\crudbooster\models\ColumnModel;
13
14
trait DefaultOption
15
{
16
    private $index;
17
18
    public function __construct($index = null)
19
    {
20
        $this->index = $index;
21
    }
22
23
    public function filterable($boolean = false, $help_info = null, $placeholder = null) {
24
        $data = ColumnSingleton()->getColumn($this->index);
25
        $data->setFilterable($boolean);
26
        $data->setFilterHelp($help_info);
27
        $data->setFilterPlaceholder($placeholder?:"Filter by ".$data->getLabel());
28
        // Save back
29
        columnSingleton()->setColumn($this->index, $data);
30
31
        return $this;
32
    }
33
34
    public function visible($boolean = true)
35
    {
36
        /** @var ColumnModel $data */
37
        $data = ColumnSingleton()->getColumn($this->index);
38
        $data->setVisible($boolean);
39
40
        // Save back
41
        columnSingleton()->setColumn($this->index, $data);
42
43
        return $this;
44
    }
45
46
    public function defaultValue($value)
47
    {
48
        /** @var ColumnModel $data */
49
        $data = ColumnSingleton()->getColumn($this->index);
50
        $data->setDefaultValue($value);
51
52
        // Save Back
53
        columnSingleton()->setColumn($this->index, $data);
54
55
        return $this;
56
    }
57
58
    /**
59
     * @param callable $transform
60
     */
61
    public function indexDisplayTransform(callable $transform) {
62
        $data = columnSingleton()->getColumn($this->index);
63
        /** @var ColumnModel $data */
64
        $data->setIndexDisplayTransform($transform);
65
        columnSingleton()->setColumn($this->index, $data);
66
        return $this;
67
    }
68
69
    /**
70
     * @param callable $transform
71
     */
72
    public function detailDisplayTransform(callable $transform) {
73
        $data = columnSingleton()->getColumn($this->index);
74
        /** @var ColumnModel $data */
75
        $data->setDetailDisplayTransform($transform);
76
        columnSingleton()->setColumn($this->index, $data);
77
        return $this;
78
    }
79
80
    public function inputWidth($width)
81
    {
82
        /** @var ColumnModel $data */
83
        $data = columnSingleton()->getColumn($this->index);
84
        $data->setInputWidth($width);
85
86
        // Save back
87
        columnSingleton()->setColumn($this->index, $data);
88
89
        return $this;
90
    }
91
92
    public function columnWidth($width)
93
    {
94
        /** @var ColumnModel $data */
95
        $data = ColumnSingleton()->getColumn($this->index);
96
        $data->setColumnWidth($width);
97
98
        // Save back
99
        columnSingleton()->setColumn($this->index, $data);
100
101
        return $this;
102
    }
103
104
    public function required($boolean = true)
105
    {
106
        /** @var ColumnModel $data */
107
        $data = ColumnSingleton()->getColumn($this->index);
108
        $data->setRequired($boolean);
109
110
        // Save back
111
        columnSingleton()->setColumn($this->index, $data);
112
113
        return $this;
114
    }
115
116
    public function help($helpText = null)
117
    {
118
        /** @var ColumnModel $data */
119
        $data = ColumnSingleton()->getColumn($this->index);
120
        $data->setHelp($helpText);
121
122
        // Save back
123
        columnSingleton()->setColumn($this->index, $data);
124
125
        return $this;
126
    }
127
128
    public function placeholder($placeholderText = null)
129
    {
130
        /** @var ColumnModel $data */
131
        $data = ColumnSingleton()->getColumn($this->index);
132
        $data->setPlaceholder($placeholderText);
133
134
        // Save back
135
        columnSingleton()->setColumn($this->index, $data);
136
137
        return $this;
138
    }
139
140
    public function readonly($boolean = true)
141
    {
142
        /** @var ColumnModel $data */
143
        $data = ColumnSingleton()->getColumn($this->index);
144
        $data->setReadonly($boolean);
145
146
        // Save back
147
        columnSingleton()->setColumn($this->index, $data);
148
149
        return $this;
150
    }
151
152
    public function disabled($boolean = true)
153
    {
154
        /** @var ColumnModel $data */
155
        $data = ColumnSingleton()->getColumn($this->index);
156
        $data->setDisabled($boolean);
157
158
        // Save back
159
        columnSingleton()->setColumn($this->index, $data);
160
161
        return $this;
162
    }
163
164
    public function onClick($js_function_name, callable $js_function = null)
165
    {
166
        /** @var ColumnModel $data */
167
        $data = ColumnSingleton()->getColumn($this->index);
168
        $data->setOnclickJsFunctionName($js_function_name);
169
        $data->setOnclickJsFunctionCallback($js_function);
170
171
        // Save back
172
        columnSingleton()->setColumn($this->index, $data);
173
174
        return $this;
175
    }
176
177
    public function onBlur($js_function_name, callable $js_function = null)
178
    {
179
        /** @var ColumnModel $data */
180
        $data = ColumnSingleton()->getColumn($this->index);
181
        $data->setOnblurJsFunctionName($js_function_name);
182
        $data->setOnblurJsFunctionCallback($js_function);
183
184
        // Save back
185
        columnSingleton()->setColumn($this->index, $data);
186
187
        return $this;
188
    }
189
190
    public function onChange($js_function_name, callable $js_function = null)
191
    {
192
        /** @var ColumnModel $data */
193
        $data = ColumnSingleton()->getColumn($this->index);
194
        $data->setOnchangeJsFunctionName($js_function_name);
195
        $data->setOnchangeJsFunctionCallback($js_function);
196
197
        // Save back
198
        columnSingleton()->setColumn($this->index, $data);
199
200
        return $this;
201
    }
202
203
    public function validation($rule = null, $custom_messages = [])
204
    {
205
        /** @var ColumnModel $data */
206
        $data = ColumnSingleton()->getColumn($this->index);
207
        $data->setValidation($rule);
208
        $data->setValidationMessages($custom_messages);
209
210
        // Save back
211
        columnSingleton()->setColumn($this->index, $data);
212
213
        return $this;
214
    }
215
216
    public function showIndex($show = true)
217
    {
218
        /** @var ColumnModel $data */
219
        $data = ColumnSingleton()->getColumn($this->index);
220
        $data->setShowIndex($show);
221
222
        // Save back
223
        columnSingleton()->setColumn($this->index, $data);
224
225
        return $this;
226
    }
227
228
    public function showEdit($show = true)
229
    {
230
        /** @var ColumnModel $data */
231
        $data = ColumnSingleton()->getColumn($this->index);
232
        $data->setShowEdit($show);
233
234
        // Save back
235
        columnSingleton()->setColumn($this->index, $data);
236
237
        return $this;
238
    }
239
240
    public function showAdd($show = true)
241
    {
242
        /** @var ColumnModel $data */
243
        $data = ColumnSingleton()->getColumn($this->index);
244
        $data->setShowAdd($show);
245
246
        // Save back
247
        columnSingleton()->setColumn($this->index, $data);
248
249
        return $this;
250
    }
251
252
    public function showDetail($show = true)
253
    {
254
        /** @var ColumnModel $data */
255
        $data = ColumnSingleton()->getColumn($this->index);
256
        $data->setShowDetail($show);
257
258
        // Save back
259
        columnSingleton()->setColumn($this->index, $data);
260
261
        return $this;
262
    }
263
264
}