@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | public function getIndex() { |
22 | 22 | $data = []; |
23 | 23 | $data['result'] = DB::table("cb_modules")->get(); |
24 | - return view($this->view.'.index',$data); |
|
24 | + return view($this->view.'.index', $data); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | public function getAdd() { |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | |
33 | 33 | public function postAddSave() { |
34 | 34 | try { |
35 | - cb()->validation(['name', 'table','icon']); |
|
35 | + cb()->validation(['name', 'table', 'icon']); |
|
36 | 36 | |
37 | 37 | (new ModuleGenerator(request('table'), request('name'), request('icon')))->make(); |
38 | 38 | |
39 | - return cb()->redirect(action("DeveloperModulesController@getIndex"),"New module has been created!","success"); |
|
39 | + return cb()->redirect(action("DeveloperModulesController@getIndex"), "New module has been created!", "success"); |
|
40 | 40 | |
41 | 41 | } catch (CBValidationException $e) { |
42 | 42 | return cb()->redirectBack($e->getMessage()); |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | try { |
54 | 54 | cb()->validation(['name', 'icon']); |
55 | 55 | |
56 | - cb()->updateCompact("cb_modules", $id, ['name','icon']); |
|
56 | + cb()->updateCompact("cb_modules", $id, ['name', 'icon']); |
|
57 | 57 | |
58 | - return cb()->redirect(action("DeveloperModulesController@getIndex"),"Module has been updated!","success"); |
|
58 | + return cb()->redirect(action("DeveloperModulesController@getIndex"), "Module has been updated!", "success"); |
|
59 | 59 | |
60 | 60 | } catch (CBValidationException $e) { |
61 | 61 | return cb()->redirectBack($e->getMessage()); |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | public function getDelete($id) { |
66 | - $module = cb()->find("cb_modules",$id); |
|
66 | + $module = cb()->find("cb_modules", $id); |
|
67 | 67 | @unlink(app_path("Http/Controllers/".$module->controller)); |
68 | 68 | DB::table("cb_modules")->where("id", $id)->delete(); |
69 | 69 | DB::table("cb_menus")->where("cb_modules_id", $id)->delete(); |
70 | 70 | |
71 | - return cb()->redirectBack("The module has been deleted!","success"); |
|
71 | + return cb()->redirectBack("The module has been deleted!", "success"); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | } |
75 | 75 | \ No newline at end of file |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | public function postUpdate() { |
16 | - validator(request()->all(),[ |
|
16 | + validator(request()->all(), [ |
|
17 | 17 | 'name'=>'required|max:255|min:3', |
18 | 18 | 'email'=>'required|email', |
19 | 19 | 'photo'=>'image', |
@@ -24,19 +24,19 @@ discard block |
||
24 | 24 | $data = []; |
25 | 25 | $data['name'] = request('name'); |
26 | 26 | $data['email'] = request('email'); |
27 | - if(request()->has('password')) { |
|
27 | + if (request()->has('password')) { |
|
28 | 28 | $data['password'] = Hash::make(request('password')); |
29 | 29 | } |
30 | - if(request()->hasFile('photo')) { |
|
30 | + if (request()->hasFile('photo')) { |
|
31 | 31 | $data['photo'] = cb()->uploadFile('photo', true, 200, 200); |
32 | 32 | } |
33 | 33 | DB::table("users")->where("id", auth()->id())->update($data); |
34 | - }catch (\Exception $e) { |
|
34 | + } catch (\Exception $e) { |
|
35 | 35 | Log::error($e); |
36 | - return cb()->redirectBack("Something went wrong!","warning"); |
|
36 | + return cb()->redirectBack("Something went wrong!", "warning"); |
|
37 | 37 | } |
38 | 38 | |
39 | - return cb()->redirectBack("The profile data has been updated!","success"); |
|
39 | + return cb()->redirectBack("The profile data has been updated!", "success"); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | $data['photo'] = cb()->uploadFile('photo', true, 200, 200); |
32 | 32 | } |
33 | 33 | DB::table("users")->where("id", auth()->id())->update($data); |
34 | - }catch (\Exception $e) { |
|
34 | + } catch (\Exception $e) { |
|
35 | 35 | Log::error($e); |
36 | 36 | return cb()->redirectBack("Something went wrong!","warning"); |
37 | 37 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | |
8 | 8 | public function getLogin() |
9 | 9 | { |
10 | - if(!auth()->guest()) return redirect(getAdminURL()); |
|
10 | + if (!auth()->guest()) return redirect(getAdminURL()); |
|
11 | 11 | |
12 | 12 | cbHook()->hookGetLogin(); |
13 | 13 | |
@@ -16,20 +16,20 @@ discard block |
||
16 | 16 | |
17 | 17 | public function postLogin() |
18 | 18 | { |
19 | - try{ |
|
19 | + try { |
|
20 | 20 | cb()->validation([ |
21 | 21 | 'email'=>'required|email', |
22 | 22 | 'password'=>'required' |
23 | 23 | ]); |
24 | - $credential = request()->only(['email','password']); |
|
24 | + $credential = request()->only(['email', 'password']); |
|
25 | 25 | if (auth()->attempt($credential)) { |
26 | 26 | cbHook()->hookPostLogin(); |
27 | 27 | return redirect(getAdminURL()); |
28 | 28 | } else { |
29 | - return redirect(getAdminLoginURL())->with(['message'=>__('crudbooster.alert_password_wrong'),'message_type'=>'warning']); |
|
29 | + return redirect(getAdminLoginURL())->with(['message'=>__('crudbooster.alert_password_wrong'), 'message_type'=>'warning']); |
|
30 | 30 | } |
31 | - }catch (CBValidationException $e) { |
|
32 | - return cb()->redirect(getAdminLoginURL(),$e->getMessage(),'warning'); |
|
31 | + } catch (CBValidationException $e) { |
|
32 | + return cb()->redirect(getAdminLoginURL(), $e->getMessage(), 'warning'); |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
@@ -44,25 +44,25 @@ discard block |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | public function postLoginDeveloper() { |
47 | - try{ |
|
47 | + try { |
|
48 | 48 | cb()->validation([ |
49 | 49 | 'username'=>'required', |
50 | 50 | 'password'=>'required' |
51 | 51 | ]); |
52 | 52 | |
53 | - if(request('username') == config('crudbooster.DEV_USERNAME') |
|
53 | + if (request('username') == config('crudbooster.DEV_USERNAME') |
|
54 | 54 | && request('password') == config('crudbooster.DEV_PASSWORD')) { |
55 | 55 | |
56 | 56 | session(['developer'=>1]); |
57 | 57 | |
58 | 58 | return redirect(cb()->getDeveloperUrl()); |
59 | 59 | |
60 | - }else{ |
|
60 | + } else { |
|
61 | 61 | return cb()->redirectBack("Username and or password is wrong!"); |
62 | 62 | } |
63 | 63 | |
64 | - }catch (CBValidationException $e) { |
|
65 | - return cb()->redirect(getAdminLoginURL(),$e->getMessage(),'warning'); |
|
64 | + } catch (CBValidationException $e) { |
|
65 | + return cb()->redirect(getAdminLoginURL(), $e->getMessage(), 'warning'); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 |
@@ -7,7 +7,9 @@ discard block |
||
7 | 7 | |
8 | 8 | public function getLogin() |
9 | 9 | { |
10 | - if(!auth()->guest()) return redirect(getAdminURL()); |
|
10 | + if(!auth()->guest()) { |
|
11 | + return redirect(getAdminURL()); |
|
12 | + } |
|
11 | 13 | |
12 | 14 | cbHook()->hookGetLogin(); |
13 | 15 | |
@@ -28,7 +30,7 @@ discard block |
||
28 | 30 | } else { |
29 | 31 | return redirect(getAdminLoginURL())->with(['message'=>__('crudbooster.alert_password_wrong'),'message_type'=>'warning']); |
30 | 32 | } |
31 | - }catch (CBValidationException $e) { |
|
33 | + } catch (CBValidationException $e) { |
|
32 | 34 | return cb()->redirect(getAdminLoginURL(),$e->getMessage(),'warning'); |
33 | 35 | } |
34 | 36 | } |
@@ -57,11 +59,11 @@ discard block |
||
57 | 59 | |
58 | 60 | return redirect(cb()->getDeveloperUrl()); |
59 | 61 | |
60 | - }else{ |
|
62 | + } else{ |
|
61 | 63 | return cb()->redirectBack("Username and or password is wrong!"); |
62 | 64 | } |
63 | 65 | |
64 | - }catch (CBValidationException $e) { |
|
66 | + } catch (CBValidationException $e) { |
|
65 | 67 | return cb()->redirect(getAdminLoginURL(),$e->getMessage(),'warning'); |
66 | 68 | } |
67 | 69 | } |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | $this->controller = class_basename($routeArray['controller']); |
27 | 27 | $this->controller_class = new ("\App\Http\Controllers\\".$this->controller)(); |
28 | 28 | |
29 | - $this->module = cb()->find("cb_modules",["controller"=>$this->controller]); |
|
30 | - $this->menu = cb()->find("cb_menus",["cb_modules_id"=>$this->module->id]); |
|
31 | - $this->menu = (!$this->menu)?cb()->find("cb_menus",["type"=>"path","path"=>request()->segment(2)]):$this->menu; |
|
29 | + $this->module = cb()->find("cb_modules", ["controller"=>$this->controller]); |
|
30 | + $this->menu = cb()->find("cb_menus", ["cb_modules_id"=>$this->module->id]); |
|
31 | + $this->menu = (!$this->menu) ?cb()->find("cb_menus", ["type"=>"path", "path"=>request()->segment(2)]) : $this->menu; |
|
32 | 32 | $this->privilege = DB::table("cb_role_privileges") |
33 | 33 | ->where("cb_menus_id", $this->menu->id) |
34 | 34 | ->where("cb_roles_id", cb()->session()->roleId()) |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | public function getPageTitle() |
47 | 47 | { |
48 | - return $this->controller_class->getData("page_title")?:env('APP_NAME'); |
|
48 | + return $this->controller_class->getData("page_title") ?: env('APP_NAME'); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | public function getTable() |
@@ -55,113 +55,113 @@ discard block |
||
55 | 55 | |
56 | 56 | public function getIcon() |
57 | 57 | { |
58 | - return $this->controller_class->getData('icon')?:"fa fa-bars"; |
|
58 | + return $this->controller_class->getData('icon') ?: "fa fa-bars"; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | public function canBrowse() { |
62 | - if($this->privilege) { |
|
63 | - if($this->privilege->can_browse) return true; |
|
62 | + if ($this->privilege) { |
|
63 | + if ($this->privilege->can_browse) return true; |
|
64 | 64 | else return false; |
65 | - }else{ |
|
65 | + } else { |
|
66 | 66 | return true; |
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | 70 | public function canCreate() { |
71 | - if($this->privilege) { |
|
72 | - if($this->privilege->can_create) return true; |
|
71 | + if ($this->privilege) { |
|
72 | + if ($this->privilege->can_create) return true; |
|
73 | 73 | else return false; |
74 | - }else{ |
|
74 | + } else { |
|
75 | 75 | return true; |
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
79 | 79 | public function canRead() { |
80 | - if($this->privilege) { |
|
81 | - if($this->privilege->can_read) return true; |
|
80 | + if ($this->privilege) { |
|
81 | + if ($this->privilege->can_read) return true; |
|
82 | 82 | else return false; |
83 | - }else{ |
|
83 | + } else { |
|
84 | 84 | return true; |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | 88 | public function canUpdate() { |
89 | - if($this->privilege) { |
|
90 | - if($this->privilege->can_update) return true; |
|
89 | + if ($this->privilege) { |
|
90 | + if ($this->privilege->can_update) return true; |
|
91 | 91 | else return false; |
92 | - }else{ |
|
92 | + } else { |
|
93 | 93 | return true; |
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | 97 | public function canDelete() { |
98 | - if($this->privilege) { |
|
99 | - if($this->privilege->can_delete) return true; |
|
98 | + if ($this->privilege) { |
|
99 | + if ($this->privilege->can_delete) return true; |
|
100 | 100 | else return false; |
101 | - }else{ |
|
101 | + } else { |
|
102 | 102 | return true; |
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | 106 | public function addURL() |
107 | 107 | { |
108 | - if(method_exists($this->controller_class, 'getAdd')) { |
|
108 | + if (method_exists($this->controller_class, 'getAdd')) { |
|
109 | 109 | return action($this->controller.'@getAdd'); |
110 | - }else{ |
|
110 | + } else { |
|
111 | 111 | return null; |
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | 115 | public function addSaveURL() |
116 | 116 | { |
117 | - if(method_exists($this->controller_class, 'postAddSave')) { |
|
117 | + if (method_exists($this->controller_class, 'postAddSave')) { |
|
118 | 118 | return action($this->controller.'@postAddSave'); |
119 | - }else{ |
|
119 | + } else { |
|
120 | 120 | return null; |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | 124 | public function editURL($id = null) |
125 | 125 | { |
126 | - if(method_exists($this->controller_class, 'getEdit')) { |
|
127 | - return action($this->controller.'@getEdit',['id'=>$id]); |
|
128 | - }else{ |
|
126 | + if (method_exists($this->controller_class, 'getEdit')) { |
|
127 | + return action($this->controller.'@getEdit', ['id'=>$id]); |
|
128 | + } else { |
|
129 | 129 | return null; |
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | 133 | public function editSaveURL($id = null) |
134 | 134 | { |
135 | - if(method_exists($this->controller_class, 'postEditSave')) { |
|
136 | - return action($this->controller.'@postEditSave',['id'=>$id]); |
|
137 | - }else{ |
|
135 | + if (method_exists($this->controller_class, 'postEditSave')) { |
|
136 | + return action($this->controller.'@postEditSave', ['id'=>$id]); |
|
137 | + } else { |
|
138 | 138 | return null; |
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
142 | - public function detailURL($id=null) |
|
142 | + public function detailURL($id = null) |
|
143 | 143 | { |
144 | - if(method_exists($this->controller_class, 'getDetail')) { |
|
145 | - return action($this->controller.'@getDetail',['id'=>$id]); |
|
146 | - }else{ |
|
144 | + if (method_exists($this->controller_class, 'getDetail')) { |
|
145 | + return action($this->controller.'@getDetail', ['id'=>$id]); |
|
146 | + } else { |
|
147 | 147 | return null; |
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | - public function deleteURL($id=null) |
|
151 | + public function deleteURL($id = null) |
|
152 | 152 | { |
153 | - if(method_exists($this->controller_class, 'getDelete')) { |
|
154 | - return action($this->controller.'@getDelete',['id'=>$id]); |
|
155 | - }else{ |
|
153 | + if (method_exists($this->controller_class, 'getDelete')) { |
|
154 | + return action($this->controller.'@getDelete', ['id'=>$id]); |
|
155 | + } else { |
|
156 | 156 | return null; |
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
160 | 160 | public function url($path = null) |
161 | 161 | { |
162 | - if(method_exists($this->controller_class, 'getIndex')) { |
|
163 | - return trim(action($this->controller.'@getIndex').'/'.$path,'/'); |
|
164 | - }else{ |
|
162 | + if (method_exists($this->controller_class, 'getIndex')) { |
|
163 | + return trim(action($this->controller.'@getIndex').'/'.$path, '/'); |
|
164 | + } else { |
|
165 | 165 | return null; |
166 | 166 | } |
167 | 167 | } |
@@ -60,45 +60,60 @@ discard block |
||
60 | 60 | |
61 | 61 | public function canBrowse() { |
62 | 62 | if($this->privilege) { |
63 | - if($this->privilege->can_browse) return true; |
|
64 | - else return false; |
|
65 | - }else{ |
|
63 | + if($this->privilege->can_browse) { |
|
64 | + return true; |
|
65 | + } else { |
|
66 | + return false; |
|
67 | + } |
|
68 | + } else{ |
|
66 | 69 | return true; |
67 | 70 | } |
68 | 71 | } |
69 | 72 | |
70 | 73 | public function canCreate() { |
71 | 74 | if($this->privilege) { |
72 | - if($this->privilege->can_create) return true; |
|
73 | - else return false; |
|
74 | - }else{ |
|
75 | + if($this->privilege->can_create) { |
|
76 | + return true; |
|
77 | + } else { |
|
78 | + return false; |
|
79 | + } |
|
80 | + } else{ |
|
75 | 81 | return true; |
76 | 82 | } |
77 | 83 | } |
78 | 84 | |
79 | 85 | public function canRead() { |
80 | 86 | if($this->privilege) { |
81 | - if($this->privilege->can_read) return true; |
|
82 | - else return false; |
|
83 | - }else{ |
|
87 | + if($this->privilege->can_read) { |
|
88 | + return true; |
|
89 | + } else { |
|
90 | + return false; |
|
91 | + } |
|
92 | + } else{ |
|
84 | 93 | return true; |
85 | 94 | } |
86 | 95 | } |
87 | 96 | |
88 | 97 | public function canUpdate() { |
89 | 98 | if($this->privilege) { |
90 | - if($this->privilege->can_update) return true; |
|
91 | - else return false; |
|
92 | - }else{ |
|
99 | + if($this->privilege->can_update) { |
|
100 | + return true; |
|
101 | + } else { |
|
102 | + return false; |
|
103 | + } |
|
104 | + } else{ |
|
93 | 105 | return true; |
94 | 106 | } |
95 | 107 | } |
96 | 108 | |
97 | 109 | public function canDelete() { |
98 | 110 | if($this->privilege) { |
99 | - if($this->privilege->can_delete) return true; |
|
100 | - else return false; |
|
101 | - }else{ |
|
111 | + if($this->privilege->can_delete) { |
|
112 | + return true; |
|
113 | + } else { |
|
114 | + return false; |
|
115 | + } |
|
116 | + } else{ |
|
102 | 117 | return true; |
103 | 118 | } |
104 | 119 | } |
@@ -107,7 +122,7 @@ discard block |
||
107 | 122 | { |
108 | 123 | if(method_exists($this->controller_class, 'getAdd')) { |
109 | 124 | return action($this->controller.'@getAdd'); |
110 | - }else{ |
|
125 | + } else{ |
|
111 | 126 | return null; |
112 | 127 | } |
113 | 128 | } |
@@ -116,7 +131,7 @@ discard block |
||
116 | 131 | { |
117 | 132 | if(method_exists($this->controller_class, 'postAddSave')) { |
118 | 133 | return action($this->controller.'@postAddSave'); |
119 | - }else{ |
|
134 | + } else{ |
|
120 | 135 | return null; |
121 | 136 | } |
122 | 137 | } |
@@ -125,7 +140,7 @@ discard block |
||
125 | 140 | { |
126 | 141 | if(method_exists($this->controller_class, 'getEdit')) { |
127 | 142 | return action($this->controller.'@getEdit',['id'=>$id]); |
128 | - }else{ |
|
143 | + } else{ |
|
129 | 144 | return null; |
130 | 145 | } |
131 | 146 | } |
@@ -134,7 +149,7 @@ discard block |
||
134 | 149 | { |
135 | 150 | if(method_exists($this->controller_class, 'postEditSave')) { |
136 | 151 | return action($this->controller.'@postEditSave',['id'=>$id]); |
137 | - }else{ |
|
152 | + } else{ |
|
138 | 153 | return null; |
139 | 154 | } |
140 | 155 | } |
@@ -143,7 +158,7 @@ discard block |
||
143 | 158 | { |
144 | 159 | if(method_exists($this->controller_class, 'getDetail')) { |
145 | 160 | return action($this->controller.'@getDetail',['id'=>$id]); |
146 | - }else{ |
|
161 | + } else{ |
|
147 | 162 | return null; |
148 | 163 | } |
149 | 164 | } |
@@ -152,7 +167,7 @@ discard block |
||
152 | 167 | { |
153 | 168 | if(method_exists($this->controller_class, 'getDelete')) { |
154 | 169 | return action($this->controller.'@getDelete',['id'=>$id]); |
155 | - }else{ |
|
170 | + } else{ |
|
156 | 171 | return null; |
157 | 172 | } |
158 | 173 | } |
@@ -161,7 +176,7 @@ discard block |
||
161 | 176 | { |
162 | 177 | if(method_exists($this->controller_class, 'getIndex')) { |
163 | 178 | return trim(action($this->controller.'@getIndex').'/'.$path,'/'); |
164 | - }else{ |
|
179 | + } else{ |
|
165 | 180 | return null; |
166 | 181 | } |
167 | 182 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace crocodicstudio\crudbooster\helpers; |
3 | 3 | |
4 | -class UserSession { |
|
4 | +class UserSession { |
|
5 | 5 | |
6 | 6 | public function user() |
7 | 7 | { |
@@ -21,14 +21,14 @@ discard block |
||
21 | 21 | public function photo() |
22 | 22 | { |
23 | 23 | $user = $this->user(); |
24 | - return ($user->photo)?asset($user->photo):asset(dummyPhoto()); |
|
24 | + return ($user->photo) ?asset($user->photo) : asset(dummyPhoto()); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | public function roleName() |
28 | 28 | { |
29 | 29 | $user = $this->user(); |
30 | 30 | $role = cb()->find("cb_roles", $user->roles_id); |
31 | - if($role) return $role->name; |
|
31 | + if ($role) return $role->name; |
|
32 | 32 | else return null; |
33 | 33 | } |
34 | 34 |
@@ -28,8 +28,11 @@ |
||
28 | 28 | { |
29 | 29 | $user = $this->user(); |
30 | 30 | $role = cb()->find("cb_roles", $user->roles_id); |
31 | - if($role) return $role->name; |
|
32 | - else return null; |
|
31 | + if($role) { |
|
32 | + return $role->name; |
|
33 | + } else { |
|
34 | + return null; |
|
35 | + } |
|
33 | 36 | } |
34 | 37 | |
35 | 38 | public function roleId() |
@@ -118,49 +118,49 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | if(!function_exists('assetThumbnail')) { |
121 | - function assetThumbnail($path) { |
|
122 | - $path = str_replace('uploads/','uploads_thumbnail/',$path); |
|
123 | - return asset($path); |
|
124 | - } |
|
121 | + function assetThumbnail($path) { |
|
122 | + $path = str_replace('uploads/','uploads_thumbnail/',$path); |
|
123 | + return asset($path); |
|
124 | + } |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | if(!function_exists('assetResize')) { |
128 | - function assetResize($path,$width,$height=null,$quality=70) { |
|
129 | - $basename = basename($path); |
|
130 | - $pathWithoutName = str_replace($basename, '', $path); |
|
131 | - $newLocation = $pathWithoutName.'/w_'.$width.'_h_'.$height.'_'.$basename; |
|
132 | - if(Storage::exists($newLocation)) { |
|
133 | - return asset($newLocation); |
|
134 | - }else{ |
|
135 | - $img = Image::make(storage_path($path))->fit($width,$height); |
|
136 | - $img->save(storage_path($newLocation),$quality); |
|
137 | - return asset($newLocation); |
|
138 | - } |
|
139 | - } |
|
128 | + function assetResize($path,$width,$height=null,$quality=70) { |
|
129 | + $basename = basename($path); |
|
130 | + $pathWithoutName = str_replace($basename, '', $path); |
|
131 | + $newLocation = $pathWithoutName.'/w_'.$width.'_h_'.$height.'_'.$basename; |
|
132 | + if(Storage::exists($newLocation)) { |
|
133 | + return asset($newLocation); |
|
134 | + }else{ |
|
135 | + $img = Image::make(storage_path($path))->fit($width,$height); |
|
136 | + $img->save(storage_path($newLocation),$quality); |
|
137 | + return asset($newLocation); |
|
138 | + } |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | if(!function_exists('extract_unit')) { |
143 | - /* |
|
143 | + /* |
|
144 | 144 | Credits: Bit Repository |
145 | 145 | URL: http://www.bitrepository.com/extract-content-between-two-delimiters-with-php.html |
146 | 146 | */ |
147 | - function extract_unit($string, $start, $end) |
|
148 | - { |
|
149 | - $pos = stripos($string, $start); |
|
150 | - $str = substr($string, $pos); |
|
151 | - $str_two = substr($str, strlen($start)); |
|
152 | - $second_pos = stripos($str_two, $end); |
|
153 | - $str_three = substr($str_two, 0, $second_pos); |
|
154 | - $unit = trim($str_three); // remove whitespaces |
|
155 | - return $unit; |
|
156 | - } |
|
147 | + function extract_unit($string, $start, $end) |
|
148 | + { |
|
149 | + $pos = stripos($string, $start); |
|
150 | + $str = substr($string, $pos); |
|
151 | + $str_two = substr($str, strlen($start)); |
|
152 | + $second_pos = stripos($str_two, $end); |
|
153 | + $str_three = substr($str_two, 0, $second_pos); |
|
154 | + $unit = trim($str_three); // remove whitespaces |
|
155 | + return $unit; |
|
156 | + } |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | |
160 | 160 | if(!function_exists('now')) { |
161 | - function now() { |
|
162 | - return date('Y-m-d H:i:s'); |
|
163 | - } |
|
161 | + function now() { |
|
162 | + return date('Y-m-d H:i:s'); |
|
163 | + } |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /* |
@@ -324,22 +324,22 @@ discard block |
||
324 | 324 | } |
325 | 325 | |
326 | 326 | if(!function_exists('rrmdir')) { |
327 | - /* |
|
327 | + /* |
|
328 | 328 | * http://stackoverflow.com/questions/3338123/how-do-i-recursively-delete-a-directory-and-its-entire-contents-files-sub-dir |
329 | 329 | */ |
330 | - function rrmdir($dir) { |
|
331 | - if (is_dir($dir)) { |
|
332 | - $objects = scandir($dir); |
|
333 | - foreach ($objects as $object) { |
|
334 | - if ($object != "." && $object != "..") { |
|
335 | - if (is_dir($dir."/".$object)) |
|
336 | - rrmdir($dir."/".$object); |
|
337 | - else |
|
338 | - unlink($dir."/".$object); |
|
339 | - } |
|
340 | - } |
|
341 | - rmdir($dir); |
|
342 | - } |
|
343 | - } |
|
330 | + function rrmdir($dir) { |
|
331 | + if (is_dir($dir)) { |
|
332 | + $objects = scandir($dir); |
|
333 | + foreach ($objects as $object) { |
|
334 | + if ($object != "." && $object != "..") { |
|
335 | + if (is_dir($dir."/".$object)) |
|
336 | + rrmdir($dir."/".$object); |
|
337 | + else |
|
338 | + unlink($dir."/".$object); |
|
339 | + } |
|
340 | + } |
|
341 | + rmdir($dir); |
|
342 | + } |
|
343 | + } |
|
344 | 344 | } |
345 | 345 |
@@ -9,13 +9,13 @@ discard block |
||
9 | 9 | | |
10 | 10 | */ |
11 | 11 | |
12 | -if(!function_exists('slug')) { |
|
12 | +if (!function_exists('slug')) { |
|
13 | 13 | function slug($string, $separator = '-') { |
14 | 14 | return \Illuminate\Support\Str::slug($string, $separator); |
15 | 15 | } |
16 | 16 | } |
17 | 17 | |
18 | -if(!function_exists('columnSingleton')) { |
|
18 | +if (!function_exists('columnSingleton')) { |
|
19 | 19 | /** |
20 | 20 | * @return \crocodicstudio\crudbooster\controllers\scaffolding\singletons\ColumnSingleton |
21 | 21 | */ |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
27 | -if(!function_exists('cbHook')) |
|
27 | +if (!function_exists('cbHook')) |
|
28 | 28 | { |
29 | 29 | /** |
30 | 30 | * @return crocodicstudio\crudbooster\hooks\CBHook |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
38 | -if(!function_exists('getTypeHook')) |
|
38 | +if (!function_exists('getTypeHook')) |
|
39 | 39 | { |
40 | 40 | /** |
41 | 41 | * @param string $type |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | -if(!function_exists('getPrimaryKey')) |
|
50 | +if (!function_exists('getPrimaryKey')) |
|
51 | 51 | { |
52 | 52 | function getPrimaryKey($table_name) |
53 | 53 | { |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | -if(!function_exists('cb')) |
|
58 | +if (!function_exists('cb')) |
|
59 | 59 | { |
60 | 60 | function cb() |
61 | 61 | { |
@@ -63,25 +63,25 @@ discard block |
||
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
66 | -if(!function_exists('cbAsset')) { |
|
66 | +if (!function_exists('cbAsset')) { |
|
67 | 67 | function cbAsset($path) { |
68 | 68 | return asset("cb_asset/".$path); |
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | -if(!function_exists("cbConfig")) { |
|
72 | +if (!function_exists("cbConfig")) { |
|
73 | 73 | function cbConfig($name) { |
74 | 74 | return config("crudbooster.".$name); |
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
78 | -if(!function_exists("strRandom")) { |
|
78 | +if (!function_exists("strRandom")) { |
|
79 | 79 | function strRandom($length = 5) { |
80 | 80 | return \Illuminate\Support\Str::random($length); |
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | -if(!function_exists('module')) { |
|
84 | +if (!function_exists('module')) { |
|
85 | 85 | function module() |
86 | 86 | { |
87 | 87 | $module = new \crocodicstudio\crudbooster\helpers\Module(); |
@@ -89,57 +89,57 @@ discard block |
||
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | -if(!function_exists('getAdminLoginURL')) { |
|
92 | +if (!function_exists('getAdminLoginURL')) { |
|
93 | 93 | function getAdminLoginURL() |
94 | 94 | { |
95 | 95 | return url(config('crudbooster.ADMIN_LOGIN_PATH')); |
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | -if(!function_exists('getAdminPath')) { |
|
100 | - function getAdminURL($path=null) |
|
99 | +if (!function_exists('getAdminPath')) { |
|
100 | + function getAdminURL($path = null) |
|
101 | 101 | { |
102 | - return trim(url(config('crudbooster.ADMIN_PATH').'/'.$path),'/'); |
|
102 | + return trim(url(config('crudbooster.ADMIN_PATH').'/'.$path), '/'); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | -if(!function_exists('getAdminPath')) { |
|
107 | - function getAdminPath($path=null) |
|
106 | +if (!function_exists('getAdminPath')) { |
|
107 | + function getAdminPath($path = null) |
|
108 | 108 | { |
109 | 109 | return config('crudbooster.ADMIN_PATH'); |
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | -if(!function_exists('dummyPhoto')) { |
|
113 | +if (!function_exists('dummyPhoto')) { |
|
114 | 114 | function dummyPhoto() |
115 | 115 | { |
116 | 116 | return config('crudbooster.DUMMY_PHOTO'); |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | -if(!function_exists('assetThumbnail')) { |
|
120 | +if (!function_exists('assetThumbnail')) { |
|
121 | 121 | function assetThumbnail($path) { |
122 | - $path = str_replace('uploads/','uploads_thumbnail/',$path); |
|
122 | + $path = str_replace('uploads/', 'uploads_thumbnail/', $path); |
|
123 | 123 | return asset($path); |
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
127 | -if(!function_exists('assetResize')) { |
|
128 | - function assetResize($path,$width,$height=null,$quality=70) { |
|
127 | +if (!function_exists('assetResize')) { |
|
128 | + function assetResize($path, $width, $height = null, $quality = 70) { |
|
129 | 129 | $basename = basename($path); |
130 | 130 | $pathWithoutName = str_replace($basename, '', $path); |
131 | 131 | $newLocation = $pathWithoutName.'/w_'.$width.'_h_'.$height.'_'.$basename; |
132 | - if(Storage::exists($newLocation)) { |
|
132 | + if (Storage::exists($newLocation)) { |
|
133 | 133 | return asset($newLocation); |
134 | - }else{ |
|
135 | - $img = Image::make(storage_path($path))->fit($width,$height); |
|
136 | - $img->save(storage_path($newLocation),$quality); |
|
134 | + } else { |
|
135 | + $img = Image::make(storage_path($path))->fit($width, $height); |
|
136 | + $img->save(storage_path($newLocation), $quality); |
|
137 | 137 | return asset($newLocation); |
138 | 138 | } |
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
142 | -if(!function_exists('extract_unit')) { |
|
142 | +if (!function_exists('extract_unit')) { |
|
143 | 143 | /* |
144 | 144 | Credits: Bit Repository |
145 | 145 | URL: http://www.bitrepository.com/extract-content-between-two-delimiters-with-php.html |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | |
160 | -if(!function_exists('now')) { |
|
160 | +if (!function_exists('now')) { |
|
161 | 161 | function now() { |
162 | 162 | return date('Y-m-d H:i:s'); |
163 | 163 | } |
@@ -171,13 +171,13 @@ discard block |
||
171 | 171 | | |
172 | 172 | */ |
173 | 173 | |
174 | -if(!function_exists('putSetting')) { |
|
174 | +if (!function_exists('putSetting')) { |
|
175 | 175 | function putSetting($key, $value) |
176 | 176 | { |
177 | - if(file_exists(storage_path('.cbconfig'))) { |
|
177 | + if (file_exists(storage_path('.cbconfig'))) { |
|
178 | 178 | $settings = file_get_contents(storage_path('.cbconfig')); |
179 | 179 | $settings = unserialize($settings); |
180 | - }else{ |
|
180 | + } else { |
|
181 | 181 | $settings = []; |
182 | 182 | } |
183 | 183 | |
@@ -188,25 +188,25 @@ discard block |
||
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | -if(!function_exists('getSetting')) { |
|
191 | +if (!function_exists('getSetting')) { |
|
192 | 192 | function getSetting($key, $default = null) |
193 | 193 | { |
194 | - if(file_exists(storage_path('.cbconfig'))) { |
|
194 | + if (file_exists(storage_path('.cbconfig'))) { |
|
195 | 195 | $settings = file_get_contents(storage_path('.cbconfig')); |
196 | 196 | $settings = unserialize($settings); |
197 | - }else{ |
|
197 | + } else { |
|
198 | 198 | $settings = []; |
199 | 199 | } |
200 | 200 | |
201 | - if(isset($settings[$key])) { |
|
202 | - return $settings[$key]?:$default; |
|
203 | - }else{ |
|
201 | + if (isset($settings[$key])) { |
|
202 | + return $settings[$key] ?: $default; |
|
203 | + } else { |
|
204 | 204 | return $default; |
205 | 205 | } |
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
209 | -if(!function_exists('timeAgo')) { |
|
209 | +if (!function_exists('timeAgo')) { |
|
210 | 210 | function timeAgo($datetime_to, $datetime_from = null, $full = false) |
211 | 211 | { |
212 | 212 | $datetime_from = ($datetime_from) ?: date('Y-m-d H:i:s'); |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | - if (! $full) { |
|
240 | + if (!$full) { |
|
241 | 241 | $string = array_slice($string, 0, 1); |
242 | 242 | } |
243 | 243 | |
@@ -245,22 +245,22 @@ discard block |
||
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
248 | -if(!function_exists("array_map_r")) { |
|
249 | - function array_map_r( $func, $arr ) |
|
248 | +if (!function_exists("array_map_r")) { |
|
249 | + function array_map_r($func, $arr) |
|
250 | 250 | { |
251 | 251 | $newArr = array(); |
252 | 252 | |
253 | - foreach( $arr as $key => $value ) |
|
253 | + foreach ($arr as $key => $value) |
|
254 | 254 | { |
255 | 255 | $key = $func($key); |
256 | - $newArr[ $key ] = ( is_array( $value ) ? array_map_r( $func, $value ) : ( is_array($func) ? call_user_func_array($func, $value) : $func( $value ) ) ); |
|
256 | + $newArr[$key] = (is_array($value) ? array_map_r($func, $value) : (is_array($func) ? call_user_func_array($func, $value) : $func($value))); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | return $newArr; |
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
263 | -if(!function_exists("sanitizeXSS")) |
|
263 | +if (!function_exists("sanitizeXSS")) |
|
264 | 264 | { |
265 | 265 | function sanitizeXSS($value) |
266 | 266 | { |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
275 | -if(!function_exists("requestAll")) { |
|
275 | +if (!function_exists("requestAll")) { |
|
276 | 276 | function requestAll() { |
277 | 277 | $all = array_map_r("sanitizeXSS", request()->all()); |
278 | 278 | return $all; |
@@ -281,22 +281,22 @@ discard block |
||
281 | 281 | |
282 | 282 | |
283 | 283 | |
284 | -if(!function_exists('getURLFormat')) { |
|
284 | +if (!function_exists('getURLFormat')) { |
|
285 | 285 | function getURLFormat($name) { |
286 | 286 | $url = request($name); |
287 | - if(filter_var($url, FILTER_VALIDATE_URL)) { |
|
287 | + if (filter_var($url, FILTER_VALIDATE_URL)) { |
|
288 | 288 | return $url; |
289 | - }else{ |
|
289 | + } else { |
|
290 | 290 | return request()->url(); |
291 | 291 | } |
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
295 | -if(!function_exists('g')) { |
|
295 | +if (!function_exists('g')) { |
|
296 | 296 | function g($name, $safe = true) { |
297 | - if($safe == true) { |
|
297 | + if ($safe == true) { |
|
298 | 298 | $response = request($name); |
299 | - if(is_string($response)) { |
|
299 | + if (is_string($response)) { |
|
300 | 300 | $response = sanitizeXSS($response); |
301 | 301 | }elseif (is_array($response)) { |
302 | 302 | array_walk_recursive($response, function(&$response) { |
@@ -305,25 +305,25 @@ discard block |
||
305 | 305 | } |
306 | 306 | |
307 | 307 | return $response; |
308 | - }else{ |
|
308 | + } else { |
|
309 | 309 | return Request::get($name); |
310 | 310 | } |
311 | 311 | } |
312 | 312 | } |
313 | 313 | |
314 | -if(!function_exists('min_var_export')) { |
|
314 | +if (!function_exists('min_var_export')) { |
|
315 | 315 | function min_var_export($input) { |
316 | - if(is_array($input)) { |
|
316 | + if (is_array($input)) { |
|
317 | 317 | $buffer = []; |
318 | - foreach($input as $key => $value) |
|
318 | + foreach ($input as $key => $value) |
|
319 | 319 | $buffer[] = var_export($key, true)."=>".min_var_export($value); |
320 | - return "[".implode(",",$buffer)."]"; |
|
320 | + return "[".implode(",", $buffer)."]"; |
|
321 | 321 | } else |
322 | 322 | return var_export($input, true); |
323 | 323 | } |
324 | 324 | } |
325 | 325 | |
326 | -if(!function_exists('rrmdir')) { |
|
326 | +if (!function_exists('rrmdir')) { |
|
327 | 327 | /* |
328 | 328 | * http://stackoverflow.com/questions/3338123/how-do-i-recursively-delete-a-directory-and-its-entire-contents-files-sub-dir |
329 | 329 | */ |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $newLocation = $pathWithoutName.'/w_'.$width.'_h_'.$height.'_'.$basename; |
132 | 132 | if(Storage::exists($newLocation)) { |
133 | 133 | return asset($newLocation); |
134 | - }else{ |
|
134 | + } else{ |
|
135 | 135 | $img = Image::make(storage_path($path))->fit($width,$height); |
136 | 136 | $img->save(storage_path($newLocation),$quality); |
137 | 137 | return asset($newLocation); |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | if(file_exists(storage_path('.cbconfig'))) { |
178 | 178 | $settings = file_get_contents(storage_path('.cbconfig')); |
179 | 179 | $settings = unserialize($settings); |
180 | - }else{ |
|
180 | + } else{ |
|
181 | 181 | $settings = []; |
182 | 182 | } |
183 | 183 | |
@@ -194,13 +194,13 @@ discard block |
||
194 | 194 | if(file_exists(storage_path('.cbconfig'))) { |
195 | 195 | $settings = file_get_contents(storage_path('.cbconfig')); |
196 | 196 | $settings = unserialize($settings); |
197 | - }else{ |
|
197 | + } else{ |
|
198 | 198 | $settings = []; |
199 | 199 | } |
200 | 200 | |
201 | 201 | if(isset($settings[$key])) { |
202 | 202 | return $settings[$key]?:$default; |
203 | - }else{ |
|
203 | + } else{ |
|
204 | 204 | return $default; |
205 | 205 | } |
206 | 206 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | $url = request($name); |
287 | 287 | if(filter_var($url, FILTER_VALIDATE_URL)) { |
288 | 288 | return $url; |
289 | - }else{ |
|
289 | + } else{ |
|
290 | 290 | return request()->url(); |
291 | 291 | } |
292 | 292 | } |
@@ -298,14 +298,14 @@ discard block |
||
298 | 298 | $response = request($name); |
299 | 299 | if(is_string($response)) { |
300 | 300 | $response = sanitizeXSS($response); |
301 | - }elseif (is_array($response)) { |
|
301 | + } elseif (is_array($response)) { |
|
302 | 302 | array_walk_recursive($response, function(&$response) { |
303 | 303 | $response = sanitizeXSS($response); |
304 | 304 | }); |
305 | 305 | } |
306 | 306 | |
307 | 307 | return $response; |
308 | - }else{ |
|
308 | + } else{ |
|
309 | 309 | return Request::get($name); |
310 | 310 | } |
311 | 311 | } |
@@ -315,11 +315,13 @@ discard block |
||
315 | 315 | function min_var_export($input) { |
316 | 316 | if(is_array($input)) { |
317 | 317 | $buffer = []; |
318 | - foreach($input as $key => $value) |
|
319 | - $buffer[] = var_export($key, true)."=>".min_var_export($value); |
|
318 | + foreach($input as $key => $value) { |
|
319 | + $buffer[] = var_export($key, true)."=>".min_var_export($value); |
|
320 | + } |
|
320 | 321 | return "[".implode(",",$buffer)."]"; |
321 | - } else |
|
322 | - return var_export($input, true); |
|
322 | + } else { |
|
323 | + return var_export($input, true); |
|
324 | + } |
|
323 | 325 | } |
324 | 326 | } |
325 | 327 | |
@@ -332,10 +334,11 @@ discard block |
||
332 | 334 | $objects = scandir($dir); |
333 | 335 | foreach ($objects as $object) { |
334 | 336 | if ($object != "." && $object != "..") { |
335 | - if (is_dir($dir."/".$object)) |
|
336 | - rrmdir($dir."/".$object); |
|
337 | - else |
|
338 | - unlink($dir."/".$object); |
|
337 | + if (is_dir($dir."/".$object)) { |
|
338 | + rrmdir($dir."/".$object); |
|
339 | + } else { |
|
340 | + unlink($dir."/".$object); |
|
341 | + } |
|
339 | 342 | } |
340 | 343 | } |
341 | 344 | rmdir($dir); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $template = file_get_contents(__DIR__."/../templates/FooBarController.stub"); |
44 | 44 | |
45 | 45 | //Replace table |
46 | - $template = str_replace("{table}",'"'.$this->table.'"', $template); |
|
46 | + $template = str_replace("{table}", '"'.$this->table.'"', $template); |
|
47 | 47 | |
48 | 48 | //Replace permalink |
49 | 49 | $template = str_replace("{permalink}", '"'.$this->table.'"', $template); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | //Replace scaffolding |
52 | 52 | $fields = DB::getSchemaBuilder()->getColumnListing(); |
53 | 53 | $scaffold = ""; |
54 | - foreach($fields as $field) { |
|
54 | + foreach ($fields as $field) { |
|
55 | 55 | $scaffold .= '$this->addText("'.$field.'");'."\n"; |
56 | 56 | } |
57 | 57 | $template = str_replace("{scaffolding}", $scaffold, $template); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | //Save to database |
64 | 64 | $module = []; |
65 | - $module['name'] = ($this->name)?:ucwords(str_replace("_"," ",$this->table)); |
|
65 | + $module['name'] = ($this->name) ?: ucwords(str_replace("_", " ", $this->table)); |
|
66 | 66 | $module['icon'] = $this->icon; |
67 | 67 | $module['table_name'] = $this->table; |
68 | 68 | $module['controller'] = $filename; |
@@ -41,7 +41,7 @@ |
||
41 | 41 | } |
42 | 42 | |
43 | 43 | public function send() { |
44 | - Mail::send("crudbooster::emails.blank", ['content' => $this->content], function ($message) { |
|
44 | + Mail::send("crudbooster::emails.blank", ['content' => $this->content], function($message) { |
|
45 | 45 | $message->priority(1); |
46 | 46 | $message->to($this->to_email); |
47 | 47 | $message->from($this->sender_email, $this->sender_name); |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | private function assignToModel($menu) { |
22 | 22 | $model = new SidebarModel(); |
23 | 23 | $model->setId($menu->id); |
24 | - if($menu->type == "url") { |
|
24 | + if ($menu->type == "url") { |
|
25 | 25 | $model->setUrl($menu->path); |
26 | 26 | $model->setIcon($menu->icon); |
27 | 27 | $model->setName($menu->name); |
@@ -45,22 +45,22 @@ discard block |
||
45 | 45 | |
46 | 46 | private function loadData($parent_id = null) { |
47 | 47 | $menus = DB::table("cb_menus"); |
48 | - if($parent_id) { |
|
49 | - $menus->where("parent_cb_menus_id",$parent_id); |
|
50 | - }else{ |
|
48 | + if ($parent_id) { |
|
49 | + $menus->where("parent_cb_menus_id", $parent_id); |
|
50 | + } else { |
|
51 | 51 | $menus->whereNull("parent_cb_menus_id"); |
52 | 52 | } |
53 | - return $menus->orderBy("sort_number","asc")->get(); |
|
53 | + return $menus->orderBy("sort_number", "asc")->get(); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | private function rolePrivilege($cb_roles_id, $cb_menus_id) { |
57 | - return cb()->find("cb_role_privileges",['cb_roles_id'=>$cb_roles_id,'cb_menus_id'=>$cb_menus_id]); |
|
57 | + return cb()->find("cb_role_privileges", ['cb_roles_id'=>$cb_roles_id, 'cb_menus_id'=>$cb_menus_id]); |
|
58 | 58 | } |
59 | 59 | |
60 | - private function checkPrivilege($roles_id,$menu) { |
|
61 | - if($roles_id) { |
|
60 | + private function checkPrivilege($roles_id, $menu) { |
|
61 | + if ($roles_id) { |
|
62 | 62 | $privilege = $this->rolePrivilege($roles_id, $menu->id); |
63 | - if(!$privilege->can_browse) { |
|
63 | + if (!$privilege->can_browse) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 | } |
@@ -72,23 +72,23 @@ discard block |
||
72 | 72 | $roles_id = cb()->session()->roleId(); |
73 | 73 | $menus = $this->loadData(); |
74 | 74 | $result = []; |
75 | - foreach($menus as $menu) { |
|
75 | + foreach ($menus as $menu) { |
|
76 | 76 | |
77 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu)) continue; |
|
77 | + if ($withPrivilege && !$this->checkPrivilege($roles_id, $menu)) continue; |
|
78 | 78 | |
79 | 79 | $sidebarModel = $this->assignToModel($menu); |
80 | - if($menus2 = $this->loadData($menu->id)) { |
|
80 | + if ($menus2 = $this->loadData($menu->id)) { |
|
81 | 81 | $sub1 = []; |
82 | 82 | foreach ($menus2 as $menu2) { |
83 | 83 | |
84 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu2)) continue; |
|
84 | + if ($withPrivilege && !$this->checkPrivilege($roles_id, $menu2)) continue; |
|
85 | 85 | |
86 | 86 | $sidebarModel2 = $this->assignToModel($menu2); |
87 | - if($menus3 = $this->loadData($menu2->id)) { |
|
87 | + if ($menus3 = $this->loadData($menu2->id)) { |
|
88 | 88 | $sub2 = []; |
89 | 89 | foreach ($menus3 as $menu3) { |
90 | 90 | |
91 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu3)) continue; |
|
91 | + if ($withPrivilege && !$this->checkPrivilege($roles_id, $menu3)) continue; |
|
92 | 92 | |
93 | 93 | $sidebarModel3 = $this->assignToModel($menu3); |
94 | 94 | $sub2[] = $sidebarModel3; |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | $model->setIcon($menu->icon); |
27 | 27 | $model->setName($menu->name); |
28 | 28 | $model->setBasepath(basename($model->getUrl())); |
29 | - }elseif ($menu->type == "module") { |
|
29 | + } elseif ($menu->type == "module") { |
|
30 | 30 | $module = cb()->find("cb_modules", $menu->cb_modules_id); |
31 | 31 | $controllerClass = new ('\App\Http\Controllers\\'.$module->controller)(); |
32 | 32 | /** @var CBController $controllerClass */ |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | $model->setIcon($module->icon); |
35 | 35 | $model->setName($module->name); |
36 | 36 | $model->setBasepath(basename($model->getUrl())); |
37 | - }elseif ($menu->type == "path") { |
|
37 | + } elseif ($menu->type == "path") { |
|
38 | 38 | $model->setUrl(cb()->getAdminUrl($menu->path)); |
39 | 39 | $model->setIcon($menu->icon); |
40 | 40 | $model->setName($menu->name); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $menus = DB::table("cb_menus"); |
48 | 48 | if($parent_id) { |
49 | 49 | $menus->where("parent_cb_menus_id",$parent_id); |
50 | - }else{ |
|
50 | + } else{ |
|
51 | 51 | $menus->whereNull("parent_cb_menus_id"); |
52 | 52 | } |
53 | 53 | return $menus->orderBy("sort_number","asc")->get(); |
@@ -74,21 +74,27 @@ discard block |
||
74 | 74 | $result = []; |
75 | 75 | foreach($menus as $menu) { |
76 | 76 | |
77 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu)) continue; |
|
77 | + if($withPrivilege && !$this->checkPrivilege($roles_id, $menu)) { |
|
78 | + continue; |
|
79 | + } |
|
78 | 80 | |
79 | 81 | $sidebarModel = $this->assignToModel($menu); |
80 | 82 | if($menus2 = $this->loadData($menu->id)) { |
81 | 83 | $sub1 = []; |
82 | 84 | foreach ($menus2 as $menu2) { |
83 | 85 | |
84 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu2)) continue; |
|
86 | + if($withPrivilege && !$this->checkPrivilege($roles_id, $menu2)) { |
|
87 | + continue; |
|
88 | + } |
|
85 | 89 | |
86 | 90 | $sidebarModel2 = $this->assignToModel($menu2); |
87 | 91 | if($menus3 = $this->loadData($menu2->id)) { |
88 | 92 | $sub2 = []; |
89 | 93 | foreach ($menus3 as $menu3) { |
90 | 94 | |
91 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu3)) continue; |
|
95 | + if($withPrivilege && !$this->checkPrivilege($roles_id, $menu3)) { |
|
96 | + continue; |
|
97 | + } |
|
92 | 98 | |
93 | 99 | $sidebarModel3 = $this->assignToModel($menu3); |
94 | 100 | $sub2[] = $sidebarModel3; |