@@ -26,17 +26,17 @@ discard block |
||
26 | 26 | try { |
27 | 27 | $routeArray = request()->route()->getAction(); |
28 | 28 | $this->controller = class_basename($routeArray['controller']); |
29 | - $this->controller = strtok($this->controller,"@"); |
|
29 | + $this->controller = strtok($this->controller, "@"); |
|
30 | 30 | |
31 | 31 | $className = "\\".$routeArray["namespace"]."\\".$this->controller; |
32 | - if(class_exists($className)) { |
|
33 | - $this->module = cb()->find("cb_modules",["controller"=>$this->controller]); |
|
34 | - if($this->module) { |
|
32 | + if (class_exists($className)) { |
|
33 | + $this->module = cb()->find("cb_modules", ["controller"=>$this->controller]); |
|
34 | + if ($this->module) { |
|
35 | 35 | $this->controller_class = new $className(); |
36 | - $this->menu = cb()->find("cb_menus",["cb_modules_id"=>$this->module->id]); |
|
37 | - $this->menu = (!$this->menu)?cb()->find("cb_menus",["type"=>"path","path"=>request()->segment(2)]):$this->menu; |
|
38 | - if($this->menu) { |
|
39 | - $this->privilege = cb()->find("cb_role_privileges",[ |
|
36 | + $this->menu = cb()->find("cb_menus", ["cb_modules_id"=>$this->module->id]); |
|
37 | + $this->menu = (!$this->menu) ?cb()->find("cb_menus", ["type"=>"path", "path"=>request()->segment(2)]) : $this->menu; |
|
38 | + if ($this->menu) { |
|
39 | + $this->privilege = cb()->find("cb_role_privileges", [ |
|
40 | 40 | "cb_menus_id"=>$this->menu->id, |
41 | 41 | "cb_roles_id"=>cb()->session()->roleId() |
42 | 42 | ]); |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | public function getData($key) { |
60 | - if($this->controller_class) { |
|
60 | + if ($this->controller_class) { |
|
61 | 61 | $value = $this->controller_class->getData($key); |
62 | - if(isset($value)) { |
|
62 | + if (isset($value)) { |
|
63 | 63 | return $value; |
64 | 64 | } |
65 | 65 | } |
@@ -70,128 +70,128 @@ discard block |
||
70 | 70 | * @return CBController |
71 | 71 | */ |
72 | 72 | public function getController() { |
73 | - return ($this->controller_class)?$this->controller_class:null; |
|
73 | + return ($this->controller_class) ? $this->controller_class : null; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | public function getPageTitle() |
77 | 77 | { |
78 | - return ($this->controller_class)?$this->controller_class->getData("page_title")?:cb()->getAppName():null; |
|
78 | + return ($this->controller_class) ? $this->controller_class->getData("page_title") ?: cb()->getAppName() : null; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | public function getTable() |
82 | 82 | { |
83 | - return ($this->controller_class)?$this->controller_class->getData("table"):null; |
|
83 | + return ($this->controller_class) ? $this->controller_class->getData("table") : null; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | public function getPageIcon() |
87 | 87 | { |
88 | - return ($this->controller_class)?$this->controller_class->getData('page_icon')?:"fa fa-bars":null; |
|
88 | + return ($this->controller_class) ? $this->controller_class->getData('page_icon') ?: "fa fa-bars" : null; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | public function canBrowse() { |
92 | - if($this->privilege) { |
|
93 | - if($this->privilege->can_browse) return true; |
|
92 | + if ($this->privilege) { |
|
93 | + if ($this->privilege->can_browse) return true; |
|
94 | 94 | else return false; |
95 | - }else{ |
|
95 | + } else { |
|
96 | 96 | return true; |
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | 100 | public function canCreate() { |
101 | - if($this->privilege) { |
|
102 | - if($this->privilege->can_create) return true; |
|
101 | + if ($this->privilege) { |
|
102 | + if ($this->privilege->can_create) return true; |
|
103 | 103 | else return false; |
104 | - }else{ |
|
104 | + } else { |
|
105 | 105 | return true; |
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
109 | 109 | public function canRead() { |
110 | - if($this->privilege) { |
|
111 | - if($this->privilege->can_read) return true; |
|
110 | + if ($this->privilege) { |
|
111 | + if ($this->privilege->can_read) return true; |
|
112 | 112 | else return false; |
113 | - }else{ |
|
113 | + } else { |
|
114 | 114 | return true; |
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | 118 | public function canUpdate() { |
119 | - if($this->privilege) { |
|
120 | - if($this->privilege->can_update) return true; |
|
119 | + if ($this->privilege) { |
|
120 | + if ($this->privilege->can_update) return true; |
|
121 | 121 | else return false; |
122 | - }else{ |
|
122 | + } else { |
|
123 | 123 | return true; |
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
127 | 127 | public function canDelete() { |
128 | - if($this->privilege) { |
|
129 | - if($this->privilege->can_delete) return true; |
|
128 | + if ($this->privilege) { |
|
129 | + if ($this->privilege->can_delete) return true; |
|
130 | 130 | else return false; |
131 | - }else{ |
|
131 | + } else { |
|
132 | 132 | return true; |
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | 136 | public function addURL() |
137 | 137 | { |
138 | - if($this->controller_class && method_exists($this->controller_class, 'getAdd')) { |
|
138 | + if ($this->controller_class && method_exists($this->controller_class, 'getAdd')) { |
|
139 | 139 | return action($this->controller.'@getAdd'); |
140 | - }else{ |
|
140 | + } else { |
|
141 | 141 | return null; |
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
145 | 145 | public function addSaveURL() |
146 | 146 | { |
147 | - if($this->controller_class && method_exists($this->controller_class, 'postAddSave')) { |
|
147 | + if ($this->controller_class && method_exists($this->controller_class, 'postAddSave')) { |
|
148 | 148 | return action($this->controller.'@postAddSave'); |
149 | - }else{ |
|
149 | + } else { |
|
150 | 150 | return null; |
151 | 151 | } |
152 | 152 | } |
153 | 153 | |
154 | 154 | public function editURL($id = null) |
155 | 155 | { |
156 | - if($this->controller_class && method_exists($this->controller_class, 'getEdit')) { |
|
157 | - return action($this->controller.'@getEdit',['id'=>$id]); |
|
158 | - }else{ |
|
156 | + if ($this->controller_class && method_exists($this->controller_class, 'getEdit')) { |
|
157 | + return action($this->controller.'@getEdit', ['id'=>$id]); |
|
158 | + } else { |
|
159 | 159 | return null; |
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | public function editSaveURL($id = null) |
164 | 164 | { |
165 | - if(method_exists($this->controller_class, 'postEditSave')) { |
|
166 | - return action($this->controller.'@postEditSave',['id'=>$id]); |
|
167 | - }else{ |
|
165 | + if (method_exists($this->controller_class, 'postEditSave')) { |
|
166 | + return action($this->controller.'@postEditSave', ['id'=>$id]); |
|
167 | + } else { |
|
168 | 168 | return null; |
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | - public function detailURL($id=null) |
|
172 | + public function detailURL($id = null) |
|
173 | 173 | { |
174 | - if($this->controller_class && method_exists($this->controller_class, 'getDetail')) { |
|
175 | - return action($this->controller.'@getDetail',['id'=>$id]); |
|
176 | - }else{ |
|
174 | + if ($this->controller_class && method_exists($this->controller_class, 'getDetail')) { |
|
175 | + return action($this->controller.'@getDetail', ['id'=>$id]); |
|
176 | + } else { |
|
177 | 177 | return null; |
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | - public function deleteURL($id=null) |
|
181 | + public function deleteURL($id = null) |
|
182 | 182 | { |
183 | - if($this->controller_class && method_exists($this->controller_class, 'getDelete')) { |
|
184 | - return action($this->controller.'@getDelete',['id'=>$id]); |
|
185 | - }else{ |
|
183 | + if ($this->controller_class && method_exists($this->controller_class, 'getDelete')) { |
|
184 | + return action($this->controller.'@getDelete', ['id'=>$id]); |
|
185 | + } else { |
|
186 | 186 | return null; |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | public function url($path = null) |
191 | 191 | { |
192 | - if($this->controller_class && method_exists($this->controller_class, 'getIndex')) { |
|
193 | - return trim(action($this->controller.'@getIndex').'/'.$path,'/'); |
|
194 | - }else{ |
|
192 | + if ($this->controller_class && method_exists($this->controller_class, 'getIndex')) { |
|
193 | + return trim(action($this->controller.'@getIndex').'/'.$path, '/'); |
|
194 | + } else { |
|
195 | 195 | return null; |
196 | 196 | } |
197 | 197 | } |
@@ -15,10 +15,10 @@ discard block |
||
15 | 15 | { |
16 | 16 | public static function putInGroup($key, $value, $group, $duration) { |
17 | 17 | $key = md5($key); |
18 | - $exist = (Cache::get($group))?:[]; |
|
19 | - $exist[ $key ] = ['value'=>$value,'duration'=>$duration]; |
|
18 | + $exist = (Cache::get($group)) ?: []; |
|
19 | + $exist[$key] = ['value'=>$value, 'duration'=>$duration]; |
|
20 | 20 | |
21 | - if($duration == -1) { |
|
21 | + if ($duration == -1) { |
|
22 | 22 | Cache::forever($group, $exist); |
23 | 23 | } else { |
24 | 24 | Cache::put($group, $exist, $duration); |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | public static function getItemInGroup($key, $group) { |
29 | 29 | $groupdata = Cache::get($group); |
30 | 30 | $key = md5($key); |
31 | - if(isset($groupdata[$key])) { |
|
31 | + if (isset($groupdata[$key])) { |
|
32 | 32 | return $groupdata[$key]['value']; |
33 | 33 | } |
34 | 34 | return null; |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | Cache::forget($group); |
39 | 39 | } |
40 | 40 | |
41 | - public static function forgetInGroup($key,$group) { |
|
41 | + public static function forgetInGroup($key, $group) { |
|
42 | 42 | $key = md5($key); |
43 | 43 | $data = Cache::get($group); |
44 | 44 | $duration = null; |
45 | - if(isset($data[$key])) { |
|
45 | + if (isset($data[$key])) { |
|
46 | 46 | $item = $data[$key]; |
47 | 47 | unset($data[$key]); |
48 | 48 | } |
@@ -24,12 +24,12 @@ discard block |
||
24 | 24 | |
25 | 25 | public function getIndex() { |
26 | 26 | $data = []; |
27 | - return view($this->view.".index",$data); |
|
27 | + return view($this->view.".index", $data); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | public function postSave() |
31 | 31 | { |
32 | - if(!isConfigCached()) { |
|
32 | + if (!isConfigCached()) { |
|
33 | 33 | setEnvironmentValue([ |
34 | 34 | "APP_DEBUG"=>request("APP_DEBUG") |
35 | 35 | ]); |
@@ -41,15 +41,15 @@ discard block |
||
41 | 41 | putSetting("AUTO_REDIRECT_TO_LOGIN", request("AUTO_REDIRECT_TO_LOGIN")); |
42 | 42 | putSetting("LOGIN_NOTIFICATION", request("LOGIN_NOTIFICATION")); |
43 | 43 | |
44 | - if(request("htaccess_ServerSignature")) { |
|
44 | + if (request("htaccess_ServerSignature")) { |
|
45 | 45 | putHtaccess("ServerSignature Off"); |
46 | 46 | } |
47 | 47 | |
48 | - if(request("htaccess_IndexIgnore")) { |
|
48 | + if (request("htaccess_IndexIgnore")) { |
|
49 | 49 | putHtaccess("IndexIgnore *"); |
50 | 50 | } |
51 | 51 | |
52 | - if(request("htaccess_dotAccess")) { |
|
52 | + if (request("htaccess_dotAccess")) { |
|
53 | 53 | putHtaccess(" |
54 | 54 | <FilesMatch \"^\.\"> |
55 | 55 | Order allow,deny |
@@ -57,11 +57,11 @@ discard block |
||
57 | 57 | </FilesMatch>"); |
58 | 58 | } |
59 | 59 | |
60 | - if(request("htaccess_preventVendor")) { |
|
60 | + if (request("htaccess_preventVendor")) { |
|
61 | 61 | putHtaccess("RewriteRule ^(.*)/vendor/.*\.(php|rb|py)$ - [F,L,NC]"); |
62 | 62 | } |
63 | 63 | |
64 | 64 | |
65 | - return cb()->redirectBack("Security has been updated!","success"); |
|
65 | + return cb()->redirectBack("Security has been updated!", "success"); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | \ No newline at end of file |
@@ -20,9 +20,9 @@ discard block |
||
20 | 20 | /* |
21 | 21 | * For security reason we have limit the upload file formats bellow |
22 | 22 | */ |
23 | - 'UPLOAD_FILE_EXTENSION_ALLOWED' => ['jpg','jpeg','png','gif','pdf','xls','xlsx','doc','docx','txt','zip','rar','rtf'], |
|
23 | + 'UPLOAD_FILE_EXTENSION_ALLOWED' => ['jpg', 'jpeg', 'png', 'gif', 'pdf', 'xls', 'xlsx', 'doc', 'docx', 'txt', 'zip', 'rar', 'rtf'], |
|
24 | 24 | |
25 | - 'UPLOAD_IMAGE_EXTENSION_ALLOWED' => ['jpg','jpeg','png','gif'], |
|
25 | + 'UPLOAD_IMAGE_EXTENSION_ALLOWED' => ['jpg', 'jpeg', 'png', 'gif'], |
|
26 | 26 | |
27 | 27 | /* |
28 | 28 | * Override Local FileSystem From Storage To Another |
@@ -58,5 +58,5 @@ discard block |
||
58 | 58 | * You can define in this array what the tables you want to include in "php artisan crudbooster:data_migration" |
59 | 59 | * The default is all cb_ prefix will be include in data migration |
60 | 60 | */ |
61 | - 'ADDITIONAL_DATA_MIGRATION'=>['users','migrations'] |
|
61 | + 'ADDITIONAL_DATA_MIGRATION'=>['users', 'migrations'] |
|
62 | 62 | ]; |
63 | 63 | \ No newline at end of file |
@@ -15,26 +15,26 @@ discard block |
||
15 | 15 | |
16 | 16 | public static function has($key) |
17 | 17 | { |
18 | - if(file_exists(app_path("CBPlugins/".$key))) return true; |
|
18 | + if (file_exists(app_path("CBPlugins/".$key))) return true; |
|
19 | 19 | else return false; |
20 | 20 | } |
21 | 21 | |
22 | 22 | public static function isNeedUpgrade($pluginKey, $versionToCompare) |
23 | 23 | { |
24 | 24 | $pluginJson = json_decode(file_get_contents(app_path("CBPlugins/".$pluginKey."/plugin.json")), true); |
25 | - if($pluginJson) { |
|
26 | - return version_compare($pluginJson['version'], $versionToCompare,"!="); |
|
27 | - }else{ |
|
25 | + if ($pluginJson) { |
|
26 | + return version_compare($pluginJson['version'], $versionToCompare, "!="); |
|
27 | + } else { |
|
28 | 28 | return false; |
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
32 | 32 | public static function registerDefaultRoute($dir) |
33 | 33 | { |
34 | - Route::group(['middleware' => ['web',\crocodicstudio\crudbooster\middlewares\CBDeveloper::class], |
|
34 | + Route::group(['middleware' => ['web', \crocodicstudio\crudbooster\middlewares\CBDeveloper::class], |
|
35 | 35 | 'prefix'=>"developer/".getSetting('developer_path'), |
36 | - 'namespace' => 'App\CBPlugins\\'.basename(dirname("./../".$dir)).'\Controllers'], function () use ($dir) { |
|
37 | - cb()->routeController("plugins/".basename(dirname("./../".$dir)),"\App\CBPlugins\\".basename(dirname("./../".$dir))."\Controllers\\".basename(dirname("./../".$dir))."Controller"); |
|
36 | + 'namespace' => 'App\CBPlugins\\'.basename(dirname("./../".$dir)).'\Controllers'], function() use ($dir) { |
|
37 | + cb()->routeController("plugins/".basename(dirname("./../".$dir)), "\App\CBPlugins\\".basename(dirname("./../".$dir))."\Controllers\\".basename(dirname("./../".$dir))."Controller"); |
|
38 | 38 | }); |
39 | 39 | } |
40 | 40 | |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | $plugins_from_master = $this->getAll(__DIR__."/../views/themes"); |
44 | 44 | $result = []; |
45 | 45 | $plugins = array_merge($plugins_from_master, $plugins_from_user); |
46 | - foreach($plugins as $plugin) { |
|
47 | - if($plugin['type'] == "theme") { |
|
46 | + foreach ($plugins as $plugin) { |
|
47 | + if ($plugin['type'] == "theme") { |
|
48 | 48 | $result[] = $plugin; |
49 | 49 | } |
50 | 50 | } |
@@ -53,15 +53,15 @@ discard block |
||
53 | 53 | |
54 | 54 | public function getAll($path = null) |
55 | 55 | { |
56 | - $path = ($path)?:app_path("CBPlugins"); |
|
56 | + $path = ($path) ?: app_path("CBPlugins"); |
|
57 | 57 | $plugins = scandir($path); |
58 | 58 | |
59 | 59 | $result = []; |
60 | - foreach($plugins as $plugin) { |
|
61 | - if($plugin != "." && $plugin != "..") { |
|
60 | + foreach ($plugins as $plugin) { |
|
61 | + if ($plugin != "." && $plugin != "..") { |
|
62 | 62 | $basename = basename($plugin); |
63 | 63 | $row = json_decode(file_get_contents($path.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR."plugin.json"), true); |
64 | - if($row) { |
|
64 | + if ($row) { |
|
65 | 65 | try { |
66 | 66 | $row['url'] = route($basename."ControllerGetIndex"); |
67 | 67 | } catch (\Exception $e) { |
@@ -20,21 +20,21 @@ |
||
20 | 20 | $themes = (new Plugin())->getAllThemes(); |
21 | 21 | $data = []; |
22 | 22 | $data['result'] = $themes; |
23 | - return view($this->view.".index",$data); |
|
23 | + return view($this->view.".index", $data); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | public function getActiveTheme($theme_path) { |
27 | 27 | $theme_path = base64_decode($theme_path); |
28 | 28 | putSetting("theme_path", $theme_path); |
29 | - return cb()->redirectBack("Theme has been activated!","success"); |
|
29 | + return cb()->redirectBack("Theme has been activated!", "success"); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | public function postSaveConfig() { |
33 | 33 | |
34 | - foreach(request()->except("_token") as $key=>$val) { |
|
35 | - putSetting( $key, $val); |
|
34 | + foreach (request()->except("_token") as $key=>$val) { |
|
35 | + putSetting($key, $val); |
|
36 | 36 | } |
37 | 37 | |
38 | - return cb()->redirectBack("Theme config has been saved!","success"); |
|
38 | + return cb()->redirectBack("Theme config has been saved!", "success"); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | \ No newline at end of file |
@@ -11,11 +11,11 @@ discard block |
||
11 | 11 | public function getIndex() { |
12 | 12 | $data = []; |
13 | 13 | $data['page_title'] = cbLang("profile"); |
14 | - return view(getThemePath('profile'),$data); |
|
14 | + return view(getThemePath('profile'), $data); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | public function postUpdate() { |
18 | - validator(request()->all(),[ |
|
18 | + validator(request()->all(), [ |
|
19 | 19 | 'name'=>'required|max:255|min:3', |
20 | 20 | 'email'=>'required|email', |
21 | 21 | 'photo'=>'image', |
@@ -26,20 +26,20 @@ discard block |
||
26 | 26 | $data = []; |
27 | 27 | $data['name'] = request('name'); |
28 | 28 | $data['email'] = request('email'); |
29 | - if(request('password')) { |
|
29 | + if (request('password')) { |
|
30 | 30 | $data['password'] = Hash::make(request('password')); |
31 | 31 | } |
32 | - if(request()->hasFile('photo')) { |
|
32 | + if (request()->hasFile('photo')) { |
|
33 | 33 | $data['photo'] = cb()->uploadFile('photo', true, 200, 200); |
34 | 34 | } |
35 | 35 | |
36 | 36 | DB::table("users")->where("id", auth()->id())->update($data); |
37 | - }catch (\Exception $e) { |
|
37 | + } catch (\Exception $e) { |
|
38 | 38 | Log::error($e); |
39 | - return cb()->redirectBack(cbLang("something_went_wrong"),"warning"); |
|
39 | + return cb()->redirectBack(cbLang("something_went_wrong"), "warning"); |
|
40 | 40 | } |
41 | 41 | |
42 | - return cb()->redirectBack("The profile data has been updated!","success"); |
|
42 | + return cb()->redirectBack("The profile data has been updated!", "success"); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | } |
@@ -18,8 +18,8 @@ |
||
18 | 18 | */ |
19 | 19 | public function handle($request, Closure $next) |
20 | 20 | { |
21 | - if(auth()->guest()) { |
|
22 | - return cb()->redirect(cb()->getLoginUrl("login"),cbLang('please_login_for_first'),'warning'); |
|
21 | + if (auth()->guest()) { |
|
22 | + return cb()->redirect(cb()->getLoginUrl("login"), cbLang('please_login_for_first'), 'warning'); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | (new CBHook())->beforeBackendMiddleware($request); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | private function assignToModel($menu) { |
24 | 24 | $model = new SidebarModel(); |
25 | 25 | $model->setId($menu->id); |
26 | - if($menu->type == "url") { |
|
26 | + if ($menu->type == "url") { |
|
27 | 27 | $model->setUrl($menu->path); |
28 | 28 | $model->setIcon($menu->icon); |
29 | 29 | $model->setName($menu->name); |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | $model->setBasepath(config('crudbooster.ADMIN_PATH').'/'.basename($model->getUrl())); |
47 | 47 | } |
48 | 48 | |
49 | - if(request()->is($model->getBasepath()."*")) { |
|
49 | + if (request()->is($model->getBasepath()."*")) { |
|
50 | 50 | $model->setIsActive(true); |
51 | - }else{ |
|
51 | + } else { |
|
52 | 52 | $model->setIsActive(false); |
53 | 53 | } |
54 | 54 | |
@@ -57,22 +57,22 @@ discard block |
||
57 | 57 | |
58 | 58 | private function loadData($parent_id = null) { |
59 | 59 | $menus = DB::table("cb_menus"); |
60 | - if($parent_id) { |
|
61 | - $menus->where("parent_cb_menus_id",$parent_id); |
|
62 | - }else{ |
|
60 | + if ($parent_id) { |
|
61 | + $menus->where("parent_cb_menus_id", $parent_id); |
|
62 | + } else { |
|
63 | 63 | $menus->whereNull("parent_cb_menus_id"); |
64 | 64 | } |
65 | - return $menus->orderBy("sort_number","asc")->get(); |
|
65 | + return $menus->orderBy("sort_number", "asc")->get(); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | private function rolePrivilege($cb_roles_id, $cb_menus_id) { |
69 | - return cb()->find("cb_role_privileges",['cb_roles_id'=>$cb_roles_id,'cb_menus_id'=>$cb_menus_id]); |
|
69 | + return cb()->find("cb_role_privileges", ['cb_roles_id'=>$cb_roles_id, 'cb_menus_id'=>$cb_menus_id]); |
|
70 | 70 | } |
71 | 71 | |
72 | - private function checkPrivilege($roles_id,$menu) { |
|
73 | - if($roles_id) { |
|
72 | + private function checkPrivilege($roles_id, $menu) { |
|
73 | + if ($roles_id) { |
|
74 | 74 | $privilege = $this->rolePrivilege($roles_id, $menu->id); |
75 | - if($privilege && !$privilege->can_browse) { |
|
75 | + if ($privilege && !$privilege->can_browse) { |
|
76 | 76 | return false; |
77 | 77 | } |
78 | 78 | } |
@@ -81,30 +81,30 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | public function all($withPrivilege = true) { |
84 | - $roles_id = ($withPrivilege)?cb()->session()->roleId():null; |
|
84 | + $roles_id = ($withPrivilege) ?cb()->session()->roleId() : null; |
|
85 | 85 | $idHash = "menuUser".$roles_id.auth()->id(); |
86 | - if($menu = CacheHelper::getItemInGroup($idHash,"sidebar_menu")) return $menu; |
|
86 | + if ($menu = CacheHelper::getItemInGroup($idHash, "sidebar_menu")) return $menu; |
|
87 | 87 | |
88 | 88 | $menus = $this->loadData(); |
89 | 89 | $result = []; |
90 | - foreach($menus as $menu) { |
|
90 | + foreach ($menus as $menu) { |
|
91 | 91 | |
92 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu)) continue; |
|
92 | + if ($withPrivilege && !$this->checkPrivilege($roles_id, $menu)) continue; |
|
93 | 93 | |
94 | 94 | $sidebarModel = $this->assignToModel($menu); |
95 | - if($menus2 = $this->loadData($menu->id)) { |
|
95 | + if ($menus2 = $this->loadData($menu->id)) { |
|
96 | 96 | $sub1 = []; |
97 | 97 | foreach ($menus2 as $menu2) { |
98 | 98 | |
99 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu2)) continue; |
|
99 | + if ($withPrivilege && !$this->checkPrivilege($roles_id, $menu2)) continue; |
|
100 | 100 | |
101 | 101 | $sidebarModel2 = $this->assignToModel($menu2); |
102 | 102 | |
103 | - if($menus3 = $this->loadData($menu2->id)) { |
|
103 | + if ($menus3 = $this->loadData($menu2->id)) { |
|
104 | 104 | $sub2 = []; |
105 | 105 | foreach ($menus3 as $menu3) { |
106 | 106 | |
107 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu3)) continue; |
|
107 | + if ($withPrivilege && !$this->checkPrivilege($roles_id, $menu3)) continue; |
|
108 | 108 | |
109 | 109 | $sidebarModel3 = $this->assignToModel($menu3); |
110 | 110 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $result[] = $sidebarModel; |
120 | 120 | } |
121 | 121 | |
122 | - CacheHelper::putInGroup($idHash, $result,"sidebar_menu", 3600); |
|
122 | + CacheHelper::putInGroup($idHash, $result, "sidebar_menu", 3600); |
|
123 | 123 | return $result; |
124 | 124 | } |
125 | 125 |