Passed
Push — master ( b5951c...045b84 )
by Ferry
03:37
created

DefaultOption::onClick()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 11
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\models\ColumnModel;
12
13
trait DefaultOption
14
{
15
    private $index;
16
17
    public function __construct($index = null)
18
    {
19
        $this->index = $index;
20
    }
21
22
    public function visible($boolean = true)
23
    {
24
        /** @var ColumnModel $data */
25
        $data = ColumnSingleton()->getColumn($this->index);
26
        $data->setVisible($boolean);
27
28
        // Save back
29
        columnSingleton()->setColumn($this->index, $data);
30
31
        return $this;
32
    }
33
34
    public function defaultValue($value)
35
    {
36
        /** @var ColumnModel $data */
37
        $data = ColumnSingleton()->getColumn($this->index);
38
        $data->setDefaultValue($value);
39
40
        // Save Back
41
        columnSingleton()->setColumn($this->index, $data);
42
43
        return $this;
44
    }
45
46
    /**
47
     * @param callable $transform
48
     */
49
    public function indexDisplayTransform(callable $transform) {
50
        $data = columnSingleton()->getColumn($this->index);
51
        /** @var ColumnModel $data */
52
        $data->setIndexDisplayTransform($transform);
53
        columnSingleton()->setColumn($this->index, $data);
54
        return $this;
55
    }
56
57
    /**
58
     * @param callable $transform
59
     */
60
    public function detailDisplayTransform(callable $transform) {
61
        $data = columnSingleton()->getColumn($this->index);
62
        /** @var ColumnModel $data */
63
        $data->setDetailDisplayTransform($transform);
64
        columnSingleton()->setColumn($this->index, $data);
65
        return $this;
66
    }
67
68
    public function inputWidth($width)
69
    {
70
        /** @var ColumnModel $data */
71
        $data = columnSingleton()->getColumn($this->index);
72
        $data->setInputWidth($width);
73
74
        // Save back
75
        columnSingleton()->setColumn($this->index, $data);
76
77
        return $this;
78
    }
79
80
    public function columnWidth($width)
81
    {
82
        /** @var ColumnModel $data */
83
        $data = ColumnSingleton()->getColumn($this->index);
84
        $data->setColumnWidth($width);
85
86
        // Save back
87
        columnSingleton()->setColumn($this->index, $data);
88
89
        return $this;
90
    }
91
92
    public function required($boolean = true)
93
    {
94
        /** @var ColumnModel $data */
95
        $data = ColumnSingleton()->getColumn($this->index);
96
        $data->setRequired($boolean);
97
98
        // Save back
99
        columnSingleton()->setColumn($this->index, $data);
100
101
        return $this;
102
    }
103
104
    public function help($helpText = null)
105
    {
106
        /** @var ColumnModel $data */
107
        $data = ColumnSingleton()->getColumn($this->index);
108
        $data->setHelp($helpText);
109
110
        // Save back
111
        columnSingleton()->setColumn($this->index, $data);
112
113
        return $this;
114
    }
115
116
    public function placeholder($placeholderText = null)
117
    {
118
        /** @var ColumnModel $data */
119
        $data = ColumnSingleton()->getColumn($this->index);
120
        $data->setPlaceholder($placeholderText);
121
122
        // Save back
123
        columnSingleton()->setColumn($this->index, $data);
124
125
        return $this;
126
    }
127
128
    public function readonly($boolean = true)
129
    {
130
        /** @var ColumnModel $data */
131
        $data = ColumnSingleton()->getColumn($this->index);
132
        $data->setReadonly($boolean);
133
134
        // Save back
135
        columnSingleton()->setColumn($this->index, $data);
136
137
        return $this;
138
    }
139
140
    public function disabled($boolean = true)
141
    {
142
        /** @var ColumnModel $data */
143
        $data = ColumnSingleton()->getColumn($this->index);
144
        $data->setDisabled($boolean);
145
146
        // Save back
147
        columnSingleton()->setColumn($this->index, $data);
148
149
        return $this;
150
    }
151
152
    public function onClick($js_function_name, callable $js_function = null)
0 ignored issues
show
Unused Code introduced by
The parameter $js_function is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

152
    public function onClick($js_function_name, /** @scrutinizer ignore-unused */ callable $js_function = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
153
    {
154
        /** @var ColumnModel $data */
155
        $data = ColumnSingleton()->getColumn($this->index);
156
        $data->setOnclickJsFunctionName($js_function_name);
157
        $data->setOnclickJsFunctionCallback($js);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $js seems to be never defined.
Loading history...
158
159
        // Save back
160
        columnSingleton()->setColumn($this->index, $data);
161
162
        return $this;
163
    }
164
165
    public function onBlur($js_function_name, callable $js_function = null)
0 ignored issues
show
Unused Code introduced by
The parameter $js_function is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

165
    public function onBlur($js_function_name, /** @scrutinizer ignore-unused */ callable $js_function = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
166
    {
167
        /** @var ColumnModel $data */
168
        $data = ColumnSingleton()->getColumn($this->index);
169
        $data->setOnblurJsFunctionName($js_function_name);
170
        $data->setOnblurJsFunctionCallback($js);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $js seems to be never defined.
Loading history...
171
172
        // Save back
173
        columnSingleton()->setColumn($this->index, $data);
174
175
        return $this;
176
    }
177
178
    public function onChange($js_function_name, callable $js_function = null)
0 ignored issues
show
Unused Code introduced by
The parameter $js_function is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

178
    public function onChange($js_function_name, /** @scrutinizer ignore-unused */ callable $js_function = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
179
    {
180
        /** @var ColumnModel $data */
181
        $data = ColumnSingleton()->getColumn($this->index);
182
        $data->setOnchangeJsFunctionName($js_function_name);
183
        $data->setOnchangeJsFunctionCallback($js);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $js seems to be never defined.
Loading history...
184
185
        // Save back
186
        columnSingleton()->setColumn($this->index, $data);
187
188
        return $this;
189
    }
190
191
    public function validation($rule = null, $custom_messages = [])
192
    {
193
        /** @var ColumnModel $data */
194
        $data = ColumnSingleton()->getColumn($this->index);
195
        $data->setValidation($rule);
196
        $data->setValidationMessages($custom_messages);
197
198
        // Save back
199
        columnSingleton()->setColumn($this->index, $data);
200
201
        return $this;
202
    }
203
204
    public function showIndex($show = true)
205
    {
206
        /** @var ColumnModel $data */
207
        $data = ColumnSingleton()->getColumn($this->index);
208
        $data->setShowIndex($show);
209
210
        // Save back
211
        columnSingleton()->setColumn($this->index, $data);
212
213
        return $this;
214
    }
215
216
    public function showEdit($show = true)
217
    {
218
        /** @var ColumnModel $data */
219
        $data = ColumnSingleton()->getColumn($this->index);
220
        $data->setShowEdit($show);
221
222
        // Save back
223
        columnSingleton()->setColumn($this->index, $data);
224
225
        return $this;
226
    }
227
228
    public function showAdd($show = true)
229
    {
230
        /** @var ColumnModel $data */
231
        $data = ColumnSingleton()->getColumn($this->index);
232
        $data->setShowAdd($show);
233
234
        // Save back
235
        columnSingleton()->setColumn($this->index, $data);
236
237
        return $this;
238
    }
239
240
    public function showDetail($show = true)
241
    {
242
        /** @var ColumnModel $data */
243
        $data = ColumnSingleton()->getColumn($this->index);
244
        $data->setShowDetail($show);
245
246
        // Save back
247
        columnSingleton()->setColumn($this->index, $data);
248
249
        return $this;
250
    }
251
252
}