Passed
Push — master ( db1581...a5af1f )
by Ferry
04:30
created

ControllerSetting::setPermalink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: User
5
 * Date: 2/3/2019
6
 * Time: 7:37 PM
7
 */
8
9
namespace crocodicstudio\crudbooster\controllers\traits;
10
11
use Closure;
12
use crocodicstudio\crudbooster\controllers\partials\ButtonColor;
13
use crocodicstudio\crudbooster\controllers\partials\SidebarStyle;
14
use crocodicstudio\crudbooster\models\AddActionButtonModel;
15
use crocodicstudio\crudbooster\models\IndexActionButtonModel;
16
17
trait ControllerSetting
18
{
19
20
    private $data = [];
21
22
23
    public function setPermalink($path)
24
    {
25
        $this->data['permalink'] = $path;
26
    }
27
28
    public function disableSoftDelete()
29
    {
30
        $this->data['disable_soft_delete'] = true;
31
    }
32
33
    /**
34
     * @param Closure $callbackQuery
35
     */
36
    public function hookIndexQuery(Closure $callbackQuery)
37
    {
38
        $this->data['hook_index_query'] = $callbackQuery;
39
    }
40
41
    /**
42
     * @param Closure $callback
43
     */
44
    public function hookAfterInsert(Closure $callback)
45
    {
46
        $this->data['hook_after_insert'] = $callback;
47
    }
48
49
    /**
50
     * @param Closure $callback
51
     */
52
    public function hookBeforeInsert(Closure $callback)
53
    {
54
        $this->data['hook_before_insert'] = $callback;
55
    }
56
57
    /**
58
     * @param Closure $callback
59
     */
60
    public function hookBeforeUpdate(Closure $callback)
61
    {
62
        $this->data['hook_before_update'] = $callback;
63
    }
64
65
    /**
66
     * @param Closure $callback
67
     */
68
    public function hookAfterUpdate(Closure $callback)
69
    {
70
        $this->data['hook_after_update'] = $callback;
71
    }
72
73
    /**
74
     * @param Closure $callbackQuery
75
     */
76
    public function hookSearchQuery(Closure $callbackQuery)
77
    {
78
        $this->data['hook_search_query'] = $callbackQuery;
79
    }
80
81
    /**
82
     * @param string $label
83
     * @param string $actionURL
84
     * @param string $fontAwesome_icon
85
     * @param ButtonColor $color
86
     * @param string $attributes
87
     */
88
    public function addIndexActionButton($label, $actionURL, $fontAwesome_icon=null, $color=null, $attributes = null)
89
    {
90
        $color = ($color)?:ButtonColor::DARK_BLUE;
91
92
        $model = new IndexActionButtonModel();
93
        $model->setLabel($label);
94
        $model->setIcon($fontAwesome_icon);
95
        $model->setColor($color);
96
        $model->setUrl($actionURL);
97
        $model->setAttributes($attributes);
98
99
        $this->data['index_action_button'][] = $model;
100
    }
101
102
    public function setOrderBy($field, $sort = 'desc')
103
    {
104
        $this->data['order_by'] = [$field, $sort];
105
        return $this;
106
    }
107
108
    /**
109
     * @param mixed $button_save
110
     * @return ControllerSetting
111
     */
112
    public function setButtonSave($button_save)
113
    {
114
        $this->data['button_save'] = $button_save;
115
        return $this;
116
    }
117
118
    public function setButtonCancel($button_cancel)
119
    {
120
        $this->data['button_cancel'] = $button_cancel;
121
        return $this;
122
    }
123
124
125
    /**
126
     * @param $label
127
     * @param Callback|string $url_target
128
     * @param callback|string $condition_callback
129
     * @param $fontAwesome_icon
130
     * @param ButtonColor|string $color
131
     */
132
    public function addActionButton($label, $url_target, $condition_callback=null, $fontAwesome_icon=null, $color=null, $confirmation = false)
133
    {
134
        $new = new AddActionButtonModel();
135
        $new->setLabel($label);
136
        $new->setIcon($fontAwesome_icon?:"fa fa-bars");
137
        $new->setColor($color?:"primary");
138
        $new->setUrl($url_target);
139
        $new->setCondition($condition_callback);
140
        $new->setConfirmation($confirmation);
141
        $this->data['add_action_button'][] = $new;
142
    }
143
    /**
144
     * @param mixed $button_edit
145
     * @param null $condition_callback
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $condition_callback is correct as it would always require null to be passed?
Loading history...
146
     * @return ControllerSetting
147
     */
148
    public function setButtonEdit($button_edit, $condition_callback = null)
149
    {
150
        $this->data['button_edit'] = $button_edit;
151
        $this->data['button_edit_callback'] = $condition_callback;
152
        return $this;
153
    }
154
155
    /**
156
     * @param mixed $button_detail
157
     * @param null $condition_callback
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $condition_callback is correct as it would always require null to be passed?
Loading history...
158
     * @return ControllerSetting
159
     */
160
    public function setButtonDetail($button_detail, $condition_callback = null)
161
    {
162
        $this->data['button_detail'] = $button_detail;
163
        $this->data['button_detail_callback'] = $condition_callback;
164
        return $this;
165
    }
166
167
    /**
168
     * @param mixed $button_delete
169
     * @param null $condition_callback
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $condition_callback is correct as it would always require null to be passed?
Loading history...
170
     * @return ControllerSetting
171
     */
172
    public function setButtonDelete($button_delete, $condition_callback = null)
173
    {
174
        $this->data['button_delete'] = $button_delete;
175
        $this->data['button_delete_callback'] = $condition_callback;
176
        return $this;
177
    }
178
179
180
181
    /**
182
     * @param string $alert_message
183
     * @return ControllerSetting
184
     */
185
    public function setAlertMessage($alert_message)
186
    {
187
        $this->data['alert_message'] = $alert_message;
188
        return $this;
189
    }
190
191
192
    /**
193
     * @param mixed $before_index_table
194
     * @return ControllerSetting
195
     */
196
    public function setBeforeIndexTable($before_index_table)
197
    {
198
        $this->data['before_index_table'] = $before_index_table;
199
        return $this;
200
    }
201
202
    /**
203
     * @param mixed $after_index_table
204
     * @return ControllerSetting
205
     */
206
    public function setAfterIndexTable($after_index_table)
207
    {
208
        $this->data['after_index_table'] = $after_index_table;
209
        return $this;
210
    }
211
212
    /**
213
     * @param mixed $before_detail_form
214
     * @return ControllerSetting
215
     */
216
    public function setBeforeDetailForm($before_detail_form)
217
    {
218
        $this->data['before_detail_form'] = $before_detail_form;
219
        return $this;
220
    }
221
222
    /**
223
     * @param mixed $after_detail_form
224
     * @return ControllerSetting
225
     */
226
    public function setAfterDetailForm($after_detail_form)
227
    {
228
        $this->data['after_detail_form'] = $after_detail_form;
229
        return $this;
230
    }
231
232
233
    /**
234
     * @param mixed $page_title
235
     * @return ControllerSetting
236
     */
237
    public function setPageTitle($page_title)
238
    {
239
        $this->data['page_title'] = $page_title;
240
        return $this;
241
    }
242
243
244
    /**
245
     * @param mixed $icon
246
     * @return ControllerSetting
247
     */
248
    public function setPageIcon($icon = "fa fa-table")
249
    {
250
        $this->data['page_icon'] = $icon;
251
        return $this;
252
    }
253
254
    /**
255
     * @param mixed $table
256
     * @return ControllerSetting
257
     */
258
    public function setTable($table)
259
    {
260
        $this->data['table'] = $table;
261
        return $this;
262
    }
263
264
    /**
265
     * @param int $limit
266
     * @return ControllerSetting
267
     */
268
    public function setLimit($limit)
269
    {
270
        $this->data['limit'] = $limit;
271
        return $this;
272
    }
273
274
    /**
275
     * @param bool $button_filter
276
     * @return ControllerSetting
277
     */
278
    public function setButtonFilter($button_filter)
279
    {
280
        $this->data['button_filter'] = $button_filter;
281
        return $this;
282
    }
283
284
285
    /**
286
     * @param bool $button_add_more
287
     * @return ControllerSetting
288
     */
289
    public function setButtonAddMore($button_add_more)
290
    {
291
        $this->data['button_add_more'] = $button_add_more;
292
        return $this;
293
    }
294
295
    /**
296
     * @param bool $button_add
297
     * @return ControllerSetting
298
     */
299
    public function setButtonAdd($button_add)
300
    {
301
        $this->data['button_add'] = $button_add;
302
        return $this;
303
    }
304
305
    /**
306
     * @param string $head_html
307
     * @return ControllerSetting
308
     */
309
    public function setHeadHtml($head_html)
310
    {
311
        $this->data['head_html'] = $head_html;
312
        return $this;
313
    }
314
315
    /**
316
     * @param string $bottom_html
317
     * @return ControllerSetting
318
     */
319
    public function setBottomHtml($bottom_html)
320
    {
321
        $this->data['bottom_html'] = $bottom_html;
322
        return $this;
323
    }
324
325
    /**
326
     * @param SidebarStyle|string $sidebar_style
327
     * @return ControllerSetting
328
     */
329
    public function setSidebarStyle($sidebar_style)
330
    {
331
        $this->data['sidebar_style'] = $sidebar_style;
332
        return $this;
333
    }
334
335
}