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
|
|
|
/* |
106
|
|
|
| -------------------------------------------------------------------------------------------------------------- |
107
|
|
|
| Get data from input post/get more simply |
108
|
|
|
| -------------------------------------------------------------------------------------------------------------- |
109
|
|
|
| $name = name of input |
110
|
|
|
| |
111
|
|
|
*/ |
112
|
|
|
if (! function_exists('g')) { |
113
|
|
|
function g($name) |
114
|
|
|
{ |
115
|
|
|
return Request::get($name); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
if (! function_exists('cbTrans')) { |
120
|
|
|
/** |
121
|
|
|
* Translate the given message. |
122
|
|
|
* |
123
|
|
|
* @param string $key |
124
|
|
|
* @param array $replace |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
|
|
function cbTrans($key, $replace = []) |
128
|
|
|
{ |
129
|
|
|
return trans('crudbooster.'.$key, $replace); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
if (! function_exists('cbAsset')) { |
134
|
|
|
function cbAsset($key) |
135
|
|
|
{ |
136
|
|
|
return asset('vendor/crudbooster/assets/'.$key); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
if(! function_exists('cbAnchor')) { |
141
|
|
|
function cbAnchor($url,$label,$attribute="") { |
142
|
|
|
return "<a href='".$url."' ".$attribute." >".$label."</a>"; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
if (! function_exists('cbScript')) { |
147
|
|
|
function cbScript($key) |
148
|
|
|
{ |
149
|
|
|
return '<script src="'.cbAsset($key).'" type="text/javascript"></script>'; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
if (! function_exists('cbStyleSheet')) { |
154
|
|
|
function cbStyleSheet($key) |
155
|
|
|
{ |
156
|
|
|
return '<link rel="stylesheet" type="text/css" href="'.cbAsset($key).'"/>'; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
if (! function_exists('cbConfig')) { |
161
|
|
|
function cbConfig($key, $default = null) |
162
|
|
|
{ |
163
|
|
|
return config('crudbooster.'.$key, $default); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
if (! function_exists('makeValidationForHTML')) { |
167
|
|
|
function makeValidationForHTML($rules) |
168
|
|
|
{ |
169
|
|
|
$validation = []; |
170
|
|
|
$validation_raw = is_string($rules)? explode('|', $rules) : $rules; |
171
|
|
|
foreach ($validation_raw as $vr) { |
172
|
|
|
$vr_a = explode(':', $vr); |
173
|
|
|
if (isset($vr_a[1])) { |
174
|
|
|
$validation[$vr_a[0]] = $vr_a[1]; |
175
|
|
|
} else { |
176
|
|
|
$validation[$vr] = true; |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
return $validation + ['max' => '']; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
if (! function_exists('findSelected')) { |
185
|
|
|
/** |
186
|
|
|
* @param $rawvalue |
187
|
|
|
* @param $form |
188
|
|
|
* @param $optionValue |
189
|
|
|
* @return string |
190
|
|
|
*/ |
191
|
|
|
function findSelected($rawvalue, $form, $optionValue) |
192
|
|
|
{ |
193
|
|
|
if (! $rawvalue) { |
194
|
|
|
return ''; |
195
|
|
|
} |
196
|
|
|
$value = $rawvalue; |
197
|
|
|
|
198
|
|
|
if ($form['options']['multiple'] !== true) { |
199
|
|
|
return ($optionValue == $value) ? "selected" : ""; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
$val = $form['options']['multiple_result_format']; |
203
|
|
|
if ($val == 'JSON') { |
204
|
|
|
$selected = (json_decode($rawvalue, true) ?: []); |
205
|
|
|
} elseif ($val == 'SEMICOLON_SEPARATOR') { |
206
|
|
|
$selected = explode('; ', $rawvalue); |
207
|
|
|
} else { |
208
|
|
|
$selected = explode(', ', $rawvalue); |
209
|
|
|
} |
210
|
|
|
in_array($optionValue, $selected) ? "selected" : ""; |
211
|
|
|
|
212
|
|
|
return $selected; |
|
|
|
|
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
if (! function_exists('array_get_keys')) { |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param array $_array |
219
|
|
|
* @param array $keys |
220
|
|
|
* @param mixed $default |
221
|
|
|
* @return array |
222
|
|
|
*/ |
223
|
|
|
function array_get_keys(array $_array, array $keys, $default = null) |
224
|
|
|
{ |
225
|
|
|
$_defaults = array_fill_keys($keys, $default); |
226
|
|
|
|
227
|
|
|
return array_merge($_defaults, array_intersect_key($_array, $_defaults)); |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
if (! function_exists('cbGetSetting')) { |
232
|
|
|
function cbGetSetting($name) |
233
|
|
|
{ |
234
|
|
|
return \Crocodicstudio\Crudbooster\Modules\SettingModule\SettingRepo::getSetting($name); |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
if (! function_exists('backWithMsg')) { |
239
|
|
|
function backWithMsg($msg, $type = 'success') |
240
|
|
|
{ |
241
|
|
|
respondWith(redirect()->back()->with(['message' => $msg, 'message_type' => $type,])); |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
if (! function_exists('underField')) { |
246
|
|
|
function underField($help, $error) |
247
|
|
|
{ |
248
|
|
|
$error = $error ? "<i class='fa fa-info-circle'></i> $error" : ''; |
249
|
|
|
|
250
|
|
|
return "<div class='text-danger'>$error</div><p class='help-block'>$help</p>"; |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
if (! function_exists('cbIcon')) { |
254
|
|
|
function cbIcon($icon) |
255
|
|
|
{ |
256
|
|
|
return '<i class=\'fa fa-'.$icon.'\'></i>'; |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
if (! function_exists('YmdHis')) { |
261
|
|
|
function YmdHis() |
262
|
|
|
{ |
263
|
|
|
return date('Y-m-d H:i:s'); |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
if (! function_exists('cbUser')) { |
268
|
|
|
function cbUser() |
269
|
|
|
{ |
270
|
|
|
return auth('cbAdmin')->user(); |
271
|
|
|
} |
272
|
|
|
} |