Completed
Push — master ( d6a5af...93636f )
by Iman
16s
created

cbIcon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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('cbTrans')) {
112
    /**
113
     * Translate the given message.
114
     *
115
     * @param  string $key
116
     * @param array $replace
117
     * @return string
118
     */
119
    function cbTrans($key, $replace = [])
120
    {
121
        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...
122
    }
123
}
124
125
if (! function_exists('cbAsset')) {
126
    function cbAsset($key)
127
    {
128
        return asset('vendor/crudbooster/assets/'.$key);
129
    }
130
}
131
132
if (! function_exists('cbScript')) {
133
    function cbScript($key)
134
    {
135
        return '<script src="'.cbAsset($key).'" type="text/javascript"></script>';
136
    }
137
}
138
139
if (! function_exists('cbStyleSheet')) {
140
    function cbStyleSheet($key)
141
    {
142
        return '<link rel="stylesheet" type="text/css" href="'.cbAsset($key).'"/>';
143
    }
144
}
145
146
if (! function_exists('cbConfig')) {
147
    function cbConfig($key, $default = null)
148
    {
149
        return config('crudbooster.'.$key, $default);
150
    }
151
}
152
if (! function_exists('makeValidationForHTML')) {
153
    function makeValidationForHTML($rules)
154
    {
155
        $validation = [];
156
        $validation_raw = $rules ? explode('|', $rules) : [];
157
        foreach ($validation_raw as $vr) {
158
            $vr_a = explode(':', $vr);
159
            if ($vr_a[1]) {
160
                $validation[$vr_a[0]] = $vr_a[1];
161
            } else {
162
                $validation[$vr] = true;
163
            }
164
        }
165
166
        return $validation;
167
    }
168
}
169
170
if (! function_exists('findSelected')) {
171
    /**
172
     * @param $rawvalue
173
     * @param $form
174
     * @param $optionValue
175
     * @return string
176
     */
177
    function findSelected($rawvalue, $form, $optionValue)
178
    {
179
        if (! $rawvalue) {
180
            return '';
181
        }
182
        $value = $rawvalue;
183
184
        if ($form['options']['multiple'] !== true) {
185
            return ($optionValue == $value) ? "selected" : "";
186
        }
187
188
        $val = $form['options']['multiple_result_format'];
189
        if ($val == 'JSON') {
190
            $selected = (json_decode($rawvalue, true) ?: []);
191
        } elseif ($val == 'SEMICOLON_SEPARATOR') {
192
            $selected = explode('; ', $rawvalue);
193
        } else {
194
            $selected = explode(', ', $rawvalue);
195
        }
196
        in_array($optionValue, $selected) ? "selected" : "";
197
198
        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...
199
    }
200
}
201
if (! function_exists('array_get_keys')) {
202
203
    /**
204
     * @param array $_array
205
     * @param array $keys
206
     * @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...
207
     * @return array
208
     */
209
    function array_get_keys(array $_array, array $keys, $default = null)
210
    {
211
        $_defaults = array_fill_keys($keys, $default);
212
213
        return array_merge($_defaults, array_intersect_key($_array, $_defaults));
214
    }
215
}
216
217
if (! function_exists('cbGetSetting')) {
218
    function cbGetSetting($name)
219
    {
220
        return \crocodicstudio\crudbooster\Modules\SettingModule\SettingRepo::getSetting($name);
221
    }
222
}
223
224
if (! function_exists('backWithMsg')) {
225
    function backWithMsg($msg, $type = 'success')
226
    {
227
        sendAndTerminate(redirect()->back()->with(['message_type' => $type, 'message' => $msg]));
228
    }
229
}
230
231
if (! function_exists('underField')) {
232
    function underField($help, $error)
233
    {
234
        $error = $error ? "<i class='fa fa-info-circle'></i> $error":'' ;
235
        return "<div class='text-danger'>$error</div><p class='help-block'>$help</p>";
236
    }
237
}
238
if (! function_exists('cbIcon')) {
239
    function cbIcon($icon)
240
    {
241
        return '<i class=\'fa fa-'.$icon.'\'></i>';
242
    }
243
}