1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
| --------------------------------------------------------------------------------------------------------------- |
4
|
|
|
| Main Helper of CRUDBooster |
5
|
|
|
| Do not edit or modify this helper unless your modification will be replace if any update from CRUDBooster. |
6
|
|
|
| |
7
|
|
|
| Homepage : http://crudbooster.com |
8
|
|
|
| --------------------------------------------------------------------------------------------------------------- |
9
|
|
|
| |
10
|
|
|
*/ |
11
|
|
|
if (! function_exists('cbModulesNS')) { |
12
|
|
|
function cbModulesNS(string $path = ''): string |
13
|
|
|
{ |
14
|
|
|
return \crocodicstudio\crudbooster\helpers\CbStructure::cbModulesNS($path); |
15
|
|
|
} |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
if (! function_exists('cbStartMarker')) { |
19
|
|
|
function cbStartMarker(string $section): string |
20
|
|
|
{ |
21
|
|
|
return "# START $section DO NOT REMOVE THIS LINE"; |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
if (! function_exists('cbEndMarker')) { |
26
|
|
|
function cbEndMarker(string $section): string |
27
|
|
|
{ |
28
|
|
|
return "# END $section DO NOT REMOVE THIS LINE"; |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
if (! function_exists('cbAdminPath')) { |
33
|
|
|
function cbAdminPath(): string |
34
|
|
|
{ |
35
|
|
|
return cbConfig('ADMIN_PATH'); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if (! function_exists('ctrlNamespace')) { |
40
|
|
|
function ctrlNamespace(): string |
41
|
|
|
{ |
42
|
|
|
return \crocodicstudio\crudbooster\helpers\CbStructure::ctrlNamespace(); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if (! function_exists('cbControllersNS')) { |
47
|
|
|
function cbControllersNS(): string |
48
|
|
|
{ |
49
|
|
|
return \crocodicstudio\crudbooster\helpers\CbStructure::cbControllersNS(); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if (! function_exists('is_checked')) { |
54
|
|
|
/** |
55
|
|
|
* @param $format |
56
|
|
|
* @param $value |
57
|
|
|
* @param $option_value |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
function is_checked(string $format, $value, $option_value): string |
61
|
|
|
{ |
62
|
|
|
if ($format == 'JSON') { |
63
|
|
|
$valueFormat = json_decode($value, true); |
64
|
|
|
} elseif ($format == 'COMMA_SEPARATOR') { |
65
|
|
|
$valueFormat = explode(', ', $value); |
66
|
|
|
} elseif ($format == 'SEMICOLON_SEPARATOR') { |
67
|
|
|
$valueFormat = explode('; ', $value); |
68
|
|
|
} else { |
69
|
|
|
$valueFormat = []; |
70
|
|
|
} |
71
|
|
|
$checked = (in_array($option_value, $valueFormat)) ? "checked" : ""; |
72
|
|
|
|
73
|
|
|
return $checked; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
if (! function_exists('CbComponentsPath')) { |
78
|
|
|
function CbComponentsPath(string $type = ''): string |
79
|
|
|
{ |
80
|
|
|
return \crocodicstudio\crudbooster\helpers\CbStructure::componentsPath($type); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if (! function_exists('CbPublishedComponentsPath')) { |
85
|
|
|
function CbPublishedComponentsPath(string $type = ''): string |
86
|
|
|
{ |
87
|
|
|
return \crocodicstudio\crudbooster\helpers\CbStructure::publishedComponentsPath($type); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if (! function_exists('controllers_dir')) { |
92
|
|
|
function controllers_dir(): string |
93
|
|
|
{ |
94
|
|
|
return \crocodicstudio\crudbooster\helpers\CbStructure::controllersDir(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if (! function_exists('controller_path')) { |
99
|
|
|
function controller_path(string $controller): string |
100
|
|
|
{ |
101
|
|
|
return \crocodicstudio\crudbooster\helpers\CbStructure::controllerPath($controller); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
if (! function_exists('now')) { |
106
|
|
|
function now() |
107
|
|
|
{ |
108
|
|
|
return date('Y-m-d H:i:s'); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/* |
113
|
|
|
| -------------------------------------------------------------------------------------------------------------- |
114
|
|
|
| Get data from input post/get more simply |
115
|
|
|
| -------------------------------------------------------------------------------------------------------------- |
116
|
|
|
| $name = name of input |
117
|
|
|
| |
118
|
|
|
*/ |
119
|
|
|
if (! function_exists('g')) { |
120
|
|
|
function g($name) |
121
|
|
|
{ |
122
|
|
|
return Request::get($name); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
if (! function_exists('cbTrans')) { |
127
|
|
|
/** |
128
|
|
|
* Translate the given message. |
129
|
|
|
* |
130
|
|
|
* @param string $key |
131
|
|
|
* @param array $replace |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
function cbTrans($key, $replace = []) |
135
|
|
|
{ |
136
|
|
|
return trans('crudbooster.'.$key, $replace); |
|
|
|
|
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
if (! function_exists('cbAsset')) { |
141
|
|
|
function cbAsset($key) |
142
|
|
|
{ |
143
|
|
|
return asset('vendor/crudbooster/assets/'.$key); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
if (! function_exists('cbScript')) { |
148
|
|
|
function cbScript($key) |
149
|
|
|
{ |
150
|
|
|
return '<script src="'.cbAsset($key).'" type="text/javascript"></script>'; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
if (! function_exists('cbStyleSheet')) { |
155
|
|
|
function cbStyleSheet($key) |
156
|
|
|
{ |
157
|
|
|
return '<link rel="stylesheet" type="text/css" href="'.cbAsset($key).'"/>'; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
if (! function_exists('cbConfig')) { |
162
|
|
|
function cbConfig($key, $default = null) |
163
|
|
|
{ |
164
|
|
|
return config('crudbooster.'.$key, $default); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
if (! function_exists('makeValidationForHTML')) { |
168
|
|
|
function makeValidationForHTML($rules) |
169
|
|
|
{ |
170
|
|
|
$validation = []; |
171
|
|
|
$validation_raw = $rules ? explode('|', $rules) : []; |
172
|
|
|
foreach ($validation_raw as $vr) { |
173
|
|
|
$vr_a = explode(':', $vr); |
174
|
|
|
if ($vr_a[1]) { |
175
|
|
|
$validation[$vr_a[0]] = $vr_a[1]; |
176
|
|
|
} else { |
177
|
|
|
$validation[$vr] = true; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
return $validation; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
if (! function_exists('findSelected')) { |
186
|
|
|
/** |
187
|
|
|
* @param $rawvalue |
188
|
|
|
* @param $form |
189
|
|
|
* @param $optionValue |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
|
|
function findSelected($rawvalue, $form, $optionValue) |
193
|
|
|
{ |
194
|
|
|
if (! $rawvalue) { |
195
|
|
|
return ''; |
196
|
|
|
} |
197
|
|
|
$value = $rawvalue; |
198
|
|
|
|
199
|
|
|
if ($form['options']['multiple'] !== true) { |
200
|
|
|
return ($optionValue == $value) ? "selected" : ""; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
$val = $form['options']['multiple_result_format']; |
204
|
|
|
if ($val == 'JSON') { |
205
|
|
|
$selected = (json_decode($rawvalue, true) ?: []); |
206
|
|
|
} elseif ($val == 'SEMICOLON_SEPARATOR') { |
207
|
|
|
$selected = explode('; ', $rawvalue); |
208
|
|
|
} else { |
209
|
|
|
$selected = explode(', ', $rawvalue); |
210
|
|
|
} |
211
|
|
|
in_array($optionValue, $selected) ? "selected" : ""; |
212
|
|
|
|
213
|
|
|
return $selected; |
|
|
|
|
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
if (! function_exists('array_get_keys')) { |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param array $_array |
220
|
|
|
* @param array $keys |
221
|
|
|
* @param mixed $default |
222
|
|
|
* @return array |
223
|
|
|
*/ |
224
|
|
|
function array_get_keys(array $_array, array $keys, $default = null) |
225
|
|
|
{ |
226
|
|
|
$_defaults = array_fill_keys($keys, $default); |
227
|
|
|
|
228
|
|
|
return array_merge($_defaults, array_intersect_key($_array, $_defaults)); |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
if (! function_exists('cbGetSetting')) { |
233
|
|
|
function cbGetSetting($name) |
234
|
|
|
{ |
235
|
|
|
return \crocodicstudio\crudbooster\Modules\SettingModule\SettingRepo::getSetting($name); |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
if (! function_exists('backWithMsg')) { |
240
|
|
|
function backWithMsg($msg, $type = 'success') |
241
|
|
|
{ |
242
|
|
|
sendAndTerminate(redirect()->back()->with(['message' => $msg, 'message_type' => $type,])); |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
if (! function_exists('underField')) { |
247
|
|
|
function underField($help, $error) |
248
|
|
|
{ |
249
|
|
|
$error = $error ? "<i class='fa fa-info-circle'></i> $error" : ''; |
250
|
|
|
|
251
|
|
|
return "<div class='text-danger'>$error</div><p class='help-block'>$help</p>"; |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
if (! function_exists('cbIcon')) { |
255
|
|
|
function cbIcon($icon) |
256
|
|
|
{ |
257
|
|
|
return '<i class=\'fa fa-'.$icon.'\'></i>'; |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
if (! function_exists('YmdHis')) { |
262
|
|
|
function YmdHis() |
263
|
|
|
{ |
264
|
|
|
return date('Y-m-d H:i:s'); |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
if (! function_exists('cbUser')) { |
269
|
|
|
function cbUser() |
270
|
|
|
{ |
271
|
|
|
return auth('cbAdmin')->user(); |
272
|
|
|
} |
273
|
|
|
} |