Passed
Push — master ( 4b0fbb...f6367b )
by Iman
03:27
created

extract_unit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 3
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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\helpers\CbStructure::cbModulesNS($path);
15
    }
16
}
17
18
if (! function_exists('cbStartMarker')) {
19
    function cbStartMarker($section)
20
    {
21
        return "# START $section DO NOT REMOVE THIS LINE";
22
    }
23
}
24
25
if (! function_exists('cbEndMarker')) {
26
    function cbEndMarker($section)
27
    {
28
        return "# END $section DO NOT REMOVE THIS LINE";
29
    }
30
}
31
32
if (! function_exists('cbAdminPath')) {
33
    function cbAdminPath()
34
    {
35
        return cbConfig('ADMIN_PATH');
36
    }
37
}
38
39
if (! function_exists('ctrlNamespace')) {
40
    function ctrlNamespace()
41
    {
42
        return \crocodicstudio\crudbooster\helpers\CbStructure::ctrlNamespace();
43
    }
44
}
45
46
if (! function_exists('is_checked')) {
47
    /**
48
     * @param $format
49
     * @param $value
50
     * @param $option_value
51
     * @return string
52
     */
53
    function is_checked($format, $value, $option_value)
54
    {
55
        if ($format == 'JSON') {
56
            $valueFormat = json_decode($value, true);
57
        } elseif ($format == 'COMMA_SEPARATOR') {
58
            $valueFormat = explode(', ', $value);
59
        } elseif ($format == 'SEMICOLON_SEPARATOR') {
60
            $valueFormat = explode('; ', $value);
61
        } else {
62
            $valueFormat = [];
63
        }
64
        $checked = (in_array($option_value, $valueFormat)) ? "checked" : "";
65
66
        return $checked;
67
    }
68
}
69
70
if (! function_exists('CbComponentsPath')) {
71
    function CbComponentsPath($type = '')
72
    {
73
        return \crocodicstudio\crudbooster\helpers\CbStructure::componentsPath($type);
74
    }
75
}
76
77
if (! function_exists('CbPublishedComponentsPath')) {
78
    function CbPublishedComponentsPath($type = '')
79
    {
80
        return \crocodicstudio\crudbooster\helpers\CbStructure::publishedComponentsPath($type);
81
    }
82
}
83
84
if (! function_exists('controllers_dir')) {
85
    function controllers_dir()
86
    {
87
        return \crocodicstudio\crudbooster\helpers\CbStructure::controllersDir();
88
    }
89
}
90
91
if (! function_exists('controller_path')) {
92
    function controller_path($controller)
93
    {
94
        return \crocodicstudio\crudbooster\helpers\CbStructure::controllerPath($controller);
95
    }
96
}
97
98
if (! function_exists('now')) {
99
    function now()
100
    {
101
        return date('Y-m-d H:i:s');
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);
0 ignored issues
show
Bug Best Practice introduced by
The expression return trans('crudbooster.' . $key, $replace) also could return the type array which is incompatible with the documented return type string.
Loading history...
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('cbScript')) {
141
    function cbScript($key)
142
    {
143
        return '<script src="'.cbAsset($key).'" type="text/javascript"></script>';
144
    }
145
}
146
147
if (! function_exists('cbStyleSheet')) {
148
    function cbStyleSheet($key)
149
    {
150
        return '<link rel="stylesheet" type="text/css" href="'.cbAsset($key).'"/>';
151
    }
152
}
153
154
if (! function_exists('cbConfig')) {
155
    function cbConfig($key, $default = null)
156
    {
157
        return config('crudbooster.'.$key, $default);
158
    }
159
}
160
if (! function_exists('makeValidationForHTML')) {
161
    function makeValidationForHTML($rules)
162
    {
163
        $validation = [];
164
        $validation_raw = $rules ? explode('|', $rules) : [];
165
        foreach ($validation_raw as $vr) {
166
            $vr_a = explode(':', $vr);
167
            if ($vr_a[1]) {
168
                $validation[$vr_a[0]] = $vr_a[1];
169
            } else {
170
                $validation[$vr] = true;
171
            }
172
        }
173
174
        return $validation;
175
    }
176
}
177
178
if (! function_exists('findSelected')) {
179
    /**
180
     * @param $rawvalue
181
     * @param $form
182
     * @param $optionValue
183
     * @return string
184
     */
185
    function findSelected($rawvalue, $form, $optionValue)
186
    {
187
        if (! $rawvalue) {
188
            return '';
189
        }
190
        $value = $rawvalue;
191
192
        if ($form['options']['multiple'] !== true) {
193
            return ($optionValue == $value) ? "selected" : "";
194
        }
195
196
        $val = $form['options']['multiple_result_format'];
197
        if ($val == 'JSON') {
198
            $selected = (json_decode($rawvalue, true) ?: []);
199
        } elseif ($val == 'SEMICOLON_SEPARATOR') {
200
            $selected = explode('; ', $rawvalue);
201
        } else {
202
            $selected = explode(', ', $rawvalue);
203
        }
204
        in_array($optionValue, $selected) ? "selected" : "";
205
206
        return $selected;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $selected also could return the type array|string[] which is incompatible with the documented return type string.
Loading history...
207
    }
208
}
209
if (! function_exists('array_get_keys')) {
210
211
    /**
212
     * @param array $_array
213
     * @param array $keys
214
     * @param null $default
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
215
     * @return array
216
     */
217
    function array_get_keys(array $_array, array $keys, $default = null)
218
    {
219
        $_defaults = array_fill_keys($keys, $default);
220
221
        return array_merge($_defaults, array_intersect_key($_array, $_defaults));
222
    }
223
}
224
225
if (! function_exists('cbGetSetting')) {
226
    function cbGetSetting($name)
227
    {
228
        return \crocodicstudio\crudbooster\Modules\SettingModule\SettingRepo::getSetting($name);
229
    }
230
}
231
232
if (! function_exists('backWithMsg')) {
233
    function backWithMsg($msg, $type = 'success')
234
    {
235
        sendAndTerminate(redirect()->back()->with(['message_type' => $type, 'message' => $msg]));
236
    }
237
}
238
239
if (! function_exists('underField')) {
240
    function underField($help, $error)
241
    {
242
        $error = $error ? "<i class='fa fa-info-circle'></i> $error":'' ;
243
        return "<div class='text-danger'>$error</div><p class='help-block'>$help</p>";
244
    }
245
}
246
if (! function_exists('cbIcon')) {
247
    function cbIcon($icon)
248
    {
249
        return '<i class=\'fa fa-'.$icon.'\'></i>';
250
    }
251
}