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($path = '') |
13
|
|
|
{ |
14
|
|
|
return '\crocodicstudio\crudbooster\Modules\\'.$path; |
15
|
|
|
} |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
if (! function_exists('cbAdminPath')) { |
19
|
|
|
function cbAdminPath() |
20
|
|
|
{ |
21
|
|
|
return cbConfig('ADMIN_PATH'); |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
if (! function_exists('ctrlNamespace')) { |
26
|
|
|
function ctrlNamespace() |
27
|
|
|
{ |
28
|
|
|
return 'App\Http\Controllers'; |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
if (! function_exists('is_checked')) { |
33
|
|
|
/** |
34
|
|
|
* @param $format |
35
|
|
|
* @param $value |
36
|
|
|
* @param $option_value |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
function is_checked($format, $value, $option_value) |
40
|
|
|
{ |
41
|
|
|
if ($format == 'JSON') { |
42
|
|
|
$valueFormat = json_decode($value, true); |
43
|
|
|
} elseif ($format == 'COMMA_SEPARATOR') { |
44
|
|
|
$valueFormat = explode(', ', $value); |
45
|
|
|
} elseif ($format == 'SEMICOLON_SEPARATOR') { |
46
|
|
|
$valueFormat = explode('; ', $value); |
47
|
|
|
} else { |
48
|
|
|
$valueFormat = []; |
49
|
|
|
} |
50
|
|
|
$checked = (in_array($option_value, $valueFormat)) ? "checked" : ""; |
51
|
|
|
|
52
|
|
|
return $checked; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if (! function_exists('controllers_dir')) { |
57
|
|
|
function controllers_dir() |
58
|
|
|
{ |
59
|
|
|
$_ = DIRECTORY_SEPARATOR; |
60
|
|
|
return 'app'.$_.'Http'.$_.'Controllers'.$_; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if (! function_exists('controller_path')) { |
65
|
|
|
function controller_path($controller) |
66
|
|
|
{ |
67
|
|
|
$_ = DIRECTORY_SEPARATOR; |
68
|
|
|
return app_path('Http'.$_.'Controllers'.$_.$controller.'.php'); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (! function_exists('extract_unit')) { |
73
|
|
|
/* |
74
|
|
|
Credits: Bit Repository |
75
|
|
|
URL: http://www.bitrepository.com/extract-content-between-two-delimiters-with-php.html |
76
|
|
|
*/ |
77
|
|
|
function extract_unit($string, $start, $end) |
78
|
|
|
{ |
79
|
|
|
$pos = stripos($string, $start); |
80
|
|
|
$str = substr($string, $pos); |
81
|
|
|
$str_two = substr($str, strlen($start)); |
82
|
|
|
$second_pos = stripos($str_two, $end); |
83
|
|
|
$str_three = substr($str_two, 0, $second_pos); |
84
|
|
|
$unit = trim($str_three); // remove whitespaces |
85
|
|
|
|
86
|
|
|
return $unit; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if (! function_exists('now')) { |
91
|
|
|
function now() |
92
|
|
|
{ |
93
|
|
|
return date('Y-m-d H:i:s'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/* |
98
|
|
|
| -------------------------------------------------------------------------------------------------------------- |
99
|
|
|
| Get data from input post/get more simply |
100
|
|
|
| -------------------------------------------------------------------------------------------------------------- |
101
|
|
|
| $name = name of input |
102
|
|
|
| |
103
|
|
|
*/ |
104
|
|
|
if (! function_exists('g')) { |
105
|
|
|
function g($name) |
106
|
|
|
{ |
107
|
|
|
return Request::get($name); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
if (! function_exists('min_var_export')) { |
112
|
|
|
function min_var_export($input, $indent = "") |
113
|
|
|
{ |
114
|
|
|
if (! is_array($input)) { |
115
|
|
|
return var_export($input, true); |
116
|
|
|
} |
117
|
|
|
$buffer = []; |
118
|
|
|
foreach ($input as $key => $value) { |
119
|
|
|
$buffer[] = $indent.var_export($key, true)."=>".min_var_export($value, ($indent."\t")); |
120
|
|
|
} |
121
|
|
|
if (count($buffer) == 0) { |
122
|
|
|
return "[]"; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return "[\n".implode(",\n", $buffer)."\n$indent]"; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
if (! function_exists('cbTrans')) { |
130
|
|
|
function cbTrans($key, $params = []) |
131
|
|
|
{ |
132
|
|
|
return trans('crudbooster.'.$key, $params); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
if (! function_exists('cbAsset')) { |
137
|
|
|
function cbAsset($key) |
138
|
|
|
{ |
139
|
|
|
return asset('vendor/crudbooster/assets/'.$key); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
if (! function_exists('cbScript')) { |
144
|
|
|
function cbScript($key) |
145
|
|
|
{ |
146
|
|
|
return '<script src="'.cbAsset($key).'" type="text/javascript"></script>'; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
if (! function_exists('cbStyleSheet')) { |
151
|
|
|
function cbStyleSheet($key) |
152
|
|
|
{ |
153
|
|
|
return '<link rel="stylesheet" type="text/css" href="'.cbAsset($key).'"/>'; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
if (! function_exists('cbConfig')) { |
158
|
|
|
function cbConfig($key, $default = null) |
159
|
|
|
{ |
160
|
|
|
return config('crudbooster.'.$key, $default); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
if (! function_exists('makeValidationForHTML')) { |
164
|
|
|
function makeValidationForHTML($rules) |
165
|
|
|
{ |
166
|
|
|
$validation = []; |
167
|
|
|
$validation_raw = $rules ? explode('|', $rules) : []; |
168
|
|
|
foreach ($validation_raw as $vr) { |
169
|
|
|
$vr_a = explode(':', $vr); |
170
|
|
|
if ($vr_a[1]) { |
171
|
|
|
$validation[$vr_a[0]] = $vr_a[1]; |
172
|
|
|
} else { |
173
|
|
|
$validation[$vr] = true; |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
return $validation; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
if (! function_exists('findSelected')) { |
182
|
|
|
/** |
183
|
|
|
* @param $rawvalue |
184
|
|
|
* @param $form |
185
|
|
|
* @param $optionValue |
186
|
|
|
* @return string |
187
|
|
|
*/ |
188
|
|
|
function findSelected($rawvalue, $form, $optionValue) |
189
|
|
|
{ |
190
|
|
|
if (! $rawvalue) { |
191
|
|
|
return ''; |
192
|
|
|
} |
193
|
|
|
$value = $rawvalue; |
194
|
|
|
|
195
|
|
|
if ($form['options']['multiple'] !== true) { |
196
|
|
|
return ($optionValue == $value) ? "selected" : ""; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
$val = $form['options']['multiple_result_format']; |
200
|
|
|
if ($val == 'JSON') { |
201
|
|
|
$selected = (json_decode($rawvalue, true) ?: []); |
202
|
|
|
} elseif ($val == 'SEMICOLON_SEPARATOR') { |
203
|
|
|
$selected = explode('; ', $rawvalue); |
204
|
|
|
} else { |
205
|
|
|
$selected = explode(', ', $rawvalue); |
206
|
|
|
} |
207
|
|
|
in_array($optionValue, $selected) ? "selected" : ""; |
208
|
|
|
|
209
|
|
|
return $selected; |
|
|
|
|
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
if (! function_exists('array_get_keys')) { |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param array $_array |
216
|
|
|
* @param array $keys |
217
|
|
|
* @param null $default |
|
|
|
|
218
|
|
|
* @return array |
219
|
|
|
*/ |
220
|
|
|
function array_get_keys(array $_array, array $keys, $default = null) |
221
|
|
|
{ |
222
|
|
|
$_defaults = array_fill_keys($keys, $default); |
223
|
|
|
|
224
|
|
|
return array_merge($_defaults, array_intersect_key($_array, $_defaults)); |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
if (! function_exists('cbGetSetting')) { |
229
|
|
|
function cbGetSetting($name) |
230
|
|
|
{ |
231
|
|
|
return \crocodicstudio\crudbooster\Modules\SettingModule\SettingRepo::getSetting($name); |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
if (! function_exists('backWithMsg')) { |
236
|
|
|
function backWithMsg($msg, $type = 'success') |
237
|
|
|
{ |
238
|
|
|
sendAndTerminate(redirect()->back()->with(['message_type' => $type, 'message' => $msg])); |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
if (! function_exists('underField')) { |
243
|
|
|
function underField($help, $error) |
244
|
|
|
{ |
245
|
|
|
$error = $error ? "<i class='fa fa-info-circle'></i> $error":'' ; |
246
|
|
|
return "<div class='text-danger'>$error</div><p class='help-block'>$help</p>"; |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|