Completed
Push — master ( bb22e0...a8c1a4 )
by Iman
15s
created

CbComponentsPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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