@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function optionsFromTable($table, $value_option, $display_option, $SQLCondition = null) { |
43 | 43 | |
44 | - if(strpos($table,"App\Models")!==false) { |
|
44 | + if (strpos($table, "App\Models") !== false) { |
|
45 | 45 | $table = new $table(); |
46 | 46 | $table = $table::$tableName; |
47 | 47 | } |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | |
51 | 51 | $options = []; |
52 | 52 | foreach ($data as $d) { |
53 | - $options[ $d->$value_option ] = $d->$display_option; |
|
53 | + $options[$d->$value_option] = $d->$display_option; |
|
54 | 54 | } |
55 | 55 | $data = columnSingleton()->getColumn($this->index); |
56 | 56 | /** @var $data SelectTableModel */ |
57 | - $data->setOptionsFromTable(["table"=>$table,"key_field"=>$value_option,"display_field"=>$display_option,"sql_condition"=>$SQLCondition]); |
|
57 | + $data->setOptionsFromTable(["table"=>$table, "key_field"=>$value_option, "display_field"=>$display_option, "sql_condition"=>$SQLCondition]); |
|
58 | 58 | columnSingleton()->setColumn($this->index, $data); |
59 | 59 | |
60 | 60 | $this->options($options); |
@@ -14,16 +14,16 @@ discard block |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | public function getSubModule($subModuleKey) { |
17 | - if(!module()->canBrowse()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
18 | - if(!verifyReferalUrl()) return cb()->redirect(module()->url(),"It looks like your url is incorrect"); |
|
17 | + if (!module()->canBrowse()) return cb()->redirect(cb()->getAdminUrl(), cbLang("you_dont_have_privilege_to_this_area")); |
|
18 | + if (!verifyReferalUrl()) return cb()->redirect(module()->url(), "It looks like your url is incorrect"); |
|
19 | 19 | |
20 | - if($subModule = Cache::get("subModule".$subModuleKey)) { |
|
20 | + if ($subModule = Cache::get("subModule".$subModuleKey)) { |
|
21 | 21 | $foreignKey = $subModule['foreignKey']; |
22 | 22 | $foreignValue = $subModule['foreignValue']; |
23 | 23 | |
24 | 24 | $query = $this->repository(); |
25 | 25 | $query->where($foreignKey, $foreignValue); |
26 | - $result = $query->paginate( request("limit")?:cbConfig("LIMIT_TABLE_DATA") ); |
|
26 | + $result = $query->paginate(request("limit") ?: cbConfig("LIMIT_TABLE_DATA")); |
|
27 | 27 | $data['result'] = $result; |
28 | 28 | |
29 | 29 | $data['additionalHeaderTitle'] = $subModule['parentTitle']; |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | return view("crudbooster::module.index.index", array_merge($data, $this->data)); |
34 | 34 | } |
35 | 35 | |
36 | - return cb()->redirect(module()->url(),"It looks like your url is incorrect"); |
|
36 | + return cb()->redirect(module()->url(), "It looks like your url is incorrect"); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | } |
40 | 40 | \ No newline at end of file |
@@ -14,8 +14,12 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | public function getSubModule($subModuleKey) { |
17 | - if(!module()->canBrowse()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
18 | - if(!verifyReferalUrl()) return cb()->redirect(module()->url(),"It looks like your url is incorrect"); |
|
17 | + if(!module()->canBrowse()) { |
|
18 | + return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
19 | + } |
|
20 | + if(!verifyReferalUrl()) { |
|
21 | + return cb()->redirect(module()->url(),"It looks like your url is incorrect"); |
|
22 | + } |
|
19 | 23 | |
20 | 24 | if($subModule = Cache::get("subModule".$subModuleKey)) { |
21 | 25 | $foreignKey = $subModule['foreignKey']; |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | |
33 | 33 | public function getIndex() |
34 | 34 | { |
35 | - if(!module()->canBrowse()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
35 | + if (!module()->canBrowse()) return cb()->redirect(cb()->getAdminUrl(), cbLang("you_dont_have_privilege_to_this_area")); |
|
36 | 36 | |
37 | 37 | $query = $this->repository(); |
38 | - $result = $query->paginate( request("limit")?:cbConfig("LIMIT_TABLE_DATA") ); |
|
38 | + $result = $query->paginate(request("limit") ?: cbConfig("LIMIT_TABLE_DATA")); |
|
39 | 39 | $data['result'] = $result; |
40 | 40 | |
41 | 41 | return view("crudbooster::module.index.index", array_merge($data, $this->data)); |
@@ -43,17 +43,17 @@ discard block |
||
43 | 43 | |
44 | 44 | public function getAdd() |
45 | 45 | { |
46 | - if(!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
46 | + if (!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(), cbLang("you_dont_have_privilege_to_this_area")); |
|
47 | 47 | |
48 | 48 | $data = []; |
49 | 49 | $data['page_title'] = $this->data['page_title'].' : '.cbLang('add'); |
50 | 50 | $data['action_url'] = module()->addSaveURL(); |
51 | - return view('crudbooster::module.form.form',array_merge($data, $this->data)); |
|
51 | + return view('crudbooster::module.form.form', array_merge($data, $this->data)); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | public function postAddSave() |
55 | 55 | { |
56 | - if(!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
56 | + if (!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(), cbLang("you_dont_have_privilege_to_this_area")); |
|
57 | 57 | |
58 | 58 | try { |
59 | 59 | $this->validation(); |
@@ -61,38 +61,38 @@ discard block |
||
61 | 61 | $data = columnSingleton()->getAssignmentData(); |
62 | 62 | |
63 | 63 | //Clear data from Primary Key |
64 | - unset($data[ cb()->pk($this->data['table']) ]); |
|
64 | + unset($data[cb()->pk($this->data['table'])]); |
|
65 | 65 | |
66 | - if(Schema::hasColumn($this->data['table'], 'created_at')) { |
|
66 | + if (Schema::hasColumn($this->data['table'], 'created_at')) { |
|
67 | 67 | $data['created_at'] = date('Y-m-d H:i:s'); |
68 | 68 | } |
69 | 69 | |
70 | - if(Schema::hasColumn($this->data['table'], 'updated_at')) { |
|
70 | + if (Schema::hasColumn($this->data['table'], 'updated_at')) { |
|
71 | 71 | $data['updated_at'] = date('Y-m-d H:i:s'); |
72 | 72 | } |
73 | 73 | |
74 | - if(isset($this->data['hook_before_insert']) && is_callable($this->data['hook_before_insert'])) { |
|
74 | + if (isset($this->data['hook_before_insert']) && is_callable($this->data['hook_before_insert'])) { |
|
75 | 75 | $data = call_user_func($this->data['hook_before_insert'], $data); |
76 | 76 | } |
77 | 77 | |
78 | 78 | $id = DB::table($this->data['table'])->insertGetId($data); |
79 | 79 | |
80 | - if(isset($this->data['hook_after_insert']) && is_callable($this->data['hook_after_insert'])) { |
|
80 | + if (isset($this->data['hook_after_insert']) && is_callable($this->data['hook_after_insert'])) { |
|
81 | 81 | call_user_func($this->data['hook_after_insert'], $id); |
82 | 82 | } |
83 | 83 | |
84 | 84 | } catch (CBValidationException $e) { |
85 | 85 | Log::debug($e); |
86 | - return cb()->redirectBack($e->getMessage(),'info'); |
|
86 | + return cb()->redirectBack($e->getMessage(), 'info'); |
|
87 | 87 | } catch (\Exception $e) { |
88 | 88 | Log::error($e); |
89 | - return cb()->redirectBack(cbLang("something_went_wrong"),'warning'); |
|
89 | + return cb()->redirectBack(cbLang("something_went_wrong"), 'warning'); |
|
90 | 90 | } |
91 | 91 | |
92 | - if (Str::contains(request("submit"),cbLang("more"))) { |
|
92 | + if (Str::contains(request("submit"), cbLang("more"))) { |
|
93 | 93 | return cb()->redirectBack(cbLang("the_data_has_been_added"), 'success'); |
94 | 94 | } else { |
95 | - if(verifyReferalUrl()) { |
|
95 | + if (verifyReferalUrl()) { |
|
96 | 96 | return cb()->redirect(getReferalUrl("url"), cbLang("the_data_has_been_added"), 'success'); |
97 | 97 | } else { |
98 | 98 | return cb()->redirect(module()->url(), cbLang("the_data_has_been_added"), 'success'); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | |
103 | 103 | public function getEdit($id) |
104 | 104 | { |
105 | - if(!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
105 | + if (!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(), cbLang("you_dont_have_privilege_to_this_area")); |
|
106 | 106 | |
107 | 107 | $data = []; |
108 | 108 | $data['row'] = $this->repository()->where($this->data['table'].'.'.getPrimaryKey($this->data['table']), $id)->first(); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | public function postEditSave($id) |
115 | 115 | { |
116 | - if(!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
116 | + if (!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(), cbLang("you_dont_have_privilege_to_this_area")); |
|
117 | 117 | |
118 | 118 | try { |
119 | 119 | $this->validation(); |
@@ -121,40 +121,40 @@ discard block |
||
121 | 121 | $data = columnSingleton()->getAssignmentData(); |
122 | 122 | |
123 | 123 | // Make sure the Primary Key is not included |
124 | - unset($data[ cb()->pk($this->data['table']) ]); |
|
124 | + unset($data[cb()->pk($this->data['table'])]); |
|
125 | 125 | |
126 | - if(Schema::hasColumn($this->data['table'], 'updated_at')) { |
|
126 | + if (Schema::hasColumn($this->data['table'], 'updated_at')) { |
|
127 | 127 | $data['updated_at'] = date('Y-m-d H:i:s'); |
128 | 128 | } |
129 | 129 | |
130 | 130 | unset($data['created_at']); |
131 | 131 | |
132 | - if(isset($this->data['hook_before_update']) && is_callable($this->data['hook_before_update'])) { |
|
132 | + if (isset($this->data['hook_before_update']) && is_callable($this->data['hook_before_update'])) { |
|
133 | 133 | $data = call_user_func($this->data['hook_before_update'], $id, $data); |
134 | 134 | } |
135 | 135 | |
136 | 136 | cb()->update($this->data['table'], $id, $data); |
137 | 137 | |
138 | - if(isset($this->data['hook_after_update']) && is_callable($this->data['hook_after_update'])) { |
|
138 | + if (isset($this->data['hook_after_update']) && is_callable($this->data['hook_after_update'])) { |
|
139 | 139 | call_user_func($this->data['hook_after_update'], $id); |
140 | 140 | } |
141 | 141 | |
142 | 142 | } catch (CBValidationException $e) { |
143 | 143 | Log::debug($e); |
144 | - return cb()->redirectBack($e->getMessage(),'info'); |
|
144 | + return cb()->redirectBack($e->getMessage(), 'info'); |
|
145 | 145 | } catch (\Exception $e) { |
146 | 146 | Log::error($e); |
147 | - return cb()->redirectBack(cbLang("something_went_wrong"),'warning'); |
|
147 | + return cb()->redirectBack(cbLang("something_went_wrong"), 'warning'); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | |
151 | 151 | if (Str::contains(request("submit"), cbLang("more"))) { |
152 | - return cb()->redirectBack( cbLang("the_data_has_been_updated"), 'success'); |
|
152 | + return cb()->redirectBack(cbLang("the_data_has_been_updated"), 'success'); |
|
153 | 153 | } else { |
154 | - if(verifyReferalUrl()) { |
|
155 | - return cb()->redirect(getReferalUrl("url"), cbLang("the_data_has_been_updated"), 'success'); |
|
154 | + if (verifyReferalUrl()) { |
|
155 | + return cb()->redirect(getReferalUrl("url"), cbLang("the_data_has_been_updated"), 'success'); |
|
156 | 156 | } else { |
157 | - return cb()->redirect(module()->url(), cbLang("the_data_has_been_updated"), 'success'); |
|
157 | + return cb()->redirect(module()->url(), cbLang("the_data_has_been_updated"), 'success'); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | } |
@@ -162,15 +162,15 @@ discard block |
||
162 | 162 | |
163 | 163 | public function getDelete($id) |
164 | 164 | { |
165 | - if(!module()->canDelete()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
165 | + if (!module()->canDelete()) return cb()->redirect(cb()->getAdminUrl(), cbLang("you_dont_have_privilege_to_this_area")); |
|
166 | 166 | |
167 | - if(isset($this->data['hook_before_delete']) && is_callable($this->data['hook_before_delete'])) { |
|
167 | + if (isset($this->data['hook_before_delete']) && is_callable($this->data['hook_before_delete'])) { |
|
168 | 168 | call_user_func($this->data['hook_before_delete'], $id); |
169 | 169 | } |
170 | 170 | |
171 | - $softDelete = isset($this->data['disable_soft_delete'])?$this->data['disable_soft_delete']:true; |
|
171 | + $softDelete = isset($this->data['disable_soft_delete']) ? $this->data['disable_soft_delete'] : true; |
|
172 | 172 | |
173 | - if ($softDelete === true && Schema::hasColumn($this->data['table'],'deleted_at')) { |
|
173 | + if ($softDelete === true && Schema::hasColumn($this->data['table'], 'deleted_at')) { |
|
174 | 174 | DB::table($this->data['table']) |
175 | 175 | ->where(getPrimaryKey($this->data['table']), $id) |
176 | 176 | ->update(['deleted_at' => date('Y-m-d H:i:s')]); |
@@ -180,16 +180,16 @@ discard block |
||
180 | 180 | ->delete(); |
181 | 181 | } |
182 | 182 | |
183 | - if(isset($this->data['hook_after_delete']) && is_callable($this->data['hook_after_delete'])) { |
|
183 | + if (isset($this->data['hook_after_delete']) && is_callable($this->data['hook_after_delete'])) { |
|
184 | 184 | call_user_func($this->data['hook_after_delete'], $id); |
185 | 185 | } |
186 | 186 | |
187 | - return cb()->redirectBack( cbLang("the_data_has_been_deleted"), 'success'); |
|
187 | + return cb()->redirectBack(cbLang("the_data_has_been_deleted"), 'success'); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | public function getDetail($id) |
191 | 191 | { |
192 | - if(!module()->canRead()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
192 | + if (!module()->canRead()) return cb()->redirect(cb()->getAdminUrl(), cbLang("you_dont_have_privilege_to_this_area")); |
|
193 | 193 | |
194 | 194 | $data = []; |
195 | 195 | $data['row'] = $this->repository()->where($this->data['table'].'.'.cb()->findPrimaryKey($this->data['table']), $id)->first(); |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public function __call($method, $parameters) |
210 | 210 | { |
211 | - if($method == "getData") { |
|
211 | + if ($method == "getData") { |
|
212 | 212 | $key = $parameters[0]; |
213 | - if(isset($this->data[$key])) { |
|
213 | + if (isset($this->data[$key])) { |
|
214 | 214 | return $this->data[$key]; |
215 | - }else{ |
|
215 | + } else { |
|
216 | 216 | return null; |
217 | 217 | } |
218 | - }else{ |
|
218 | + } else { |
|
219 | 219 | return null; |
220 | 220 | } |
221 | 221 | } |
@@ -32,7 +32,9 @@ discard block |
||
32 | 32 | |
33 | 33 | public function getIndex() |
34 | 34 | { |
35 | - if(!module()->canBrowse()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
35 | + if(!module()->canBrowse()) { |
|
36 | + return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
37 | + } |
|
36 | 38 | |
37 | 39 | $query = $this->repository(); |
38 | 40 | $result = $query->paginate( request("limit")?:cbConfig("LIMIT_TABLE_DATA") ); |
@@ -43,7 +45,9 @@ discard block |
||
43 | 45 | |
44 | 46 | public function getAdd() |
45 | 47 | { |
46 | - if(!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
48 | + if(!module()->canCreate()) { |
|
49 | + return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
50 | + } |
|
47 | 51 | |
48 | 52 | $data = []; |
49 | 53 | $data['page_title'] = $this->data['page_title'].' : '.cbLang('add'); |
@@ -53,7 +57,9 @@ discard block |
||
53 | 57 | |
54 | 58 | public function postAddSave() |
55 | 59 | { |
56 | - if(!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
60 | + if(!module()->canCreate()) { |
|
61 | + return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
62 | + } |
|
57 | 63 | |
58 | 64 | try { |
59 | 65 | $this->validation(); |
@@ -102,7 +108,9 @@ discard block |
||
102 | 108 | |
103 | 109 | public function getEdit($id) |
104 | 110 | { |
105 | - if(!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
111 | + if(!module()->canUpdate()) { |
|
112 | + return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
113 | + } |
|
106 | 114 | |
107 | 115 | $data = []; |
108 | 116 | $data['row'] = $this->repository()->where($this->data['table'].'.'.getPrimaryKey($this->data['table']), $id)->first(); |
@@ -113,7 +121,9 @@ discard block |
||
113 | 121 | |
114 | 122 | public function postEditSave($id) |
115 | 123 | { |
116 | - if(!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
124 | + if(!module()->canUpdate()) { |
|
125 | + return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
126 | + } |
|
117 | 127 | |
118 | 128 | try { |
119 | 129 | $this->validation(); |
@@ -162,7 +172,9 @@ discard block |
||
162 | 172 | |
163 | 173 | public function getDelete($id) |
164 | 174 | { |
165 | - if(!module()->canDelete()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
175 | + if(!module()->canDelete()) { |
|
176 | + return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
177 | + } |
|
166 | 178 | |
167 | 179 | if(isset($this->data['hook_before_delete']) && is_callable($this->data['hook_before_delete'])) { |
168 | 180 | call_user_func($this->data['hook_before_delete'], $id); |
@@ -189,7 +201,9 @@ discard block |
||
189 | 201 | |
190 | 202 | public function getDetail($id) |
191 | 203 | { |
192 | - if(!module()->canRead()) return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
204 | + if(!module()->canRead()) { |
|
205 | + return cb()->redirect(cb()->getAdminUrl(),cbLang("you_dont_have_privilege_to_this_area")); |
|
206 | + } |
|
193 | 207 | |
194 | 208 | $data = []; |
195 | 209 | $data['row'] = $this->repository()->where($this->data['table'].'.'.cb()->findPrimaryKey($this->data['table']), $id)->first(); |
@@ -212,10 +226,10 @@ discard block |
||
212 | 226 | $key = $parameters[0]; |
213 | 227 | if(isset($this->data[$key])) { |
214 | 228 | return $this->data[$key]; |
215 | - }else{ |
|
229 | + } else{ |
|
216 | 230 | return null; |
217 | 231 | } |
218 | - }else{ |
|
232 | + } else{ |
|
219 | 233 | return null; |
220 | 234 | } |
221 | 235 | } |
@@ -18,14 +18,14 @@ |
||
18 | 18 | */ |
19 | 19 | public function columnIntervention() |
20 | 20 | { |
21 | - if(request("sub_module") && Cache::has("subModule".request("sub_module")) && cb()->getCurrentMethod() != "getDetail") { |
|
21 | + if (request("sub_module") && Cache::has("subModule".request("sub_module")) && cb()->getCurrentMethod() != "getDetail") { |
|
22 | 22 | /* |
23 | 23 | * If there is sub module, the column that has same name with foreign key should be remove |
24 | 24 | * And change to hidden. So we can save the foreign Key id from the parent module. |
25 | 25 | */ |
26 | 26 | $subModule = Cache::get("subModule".request("sub_module")); |
27 | 27 | $this->removeColumn($subModule["foreignKey"]) |
28 | - ->addHidden($subModule["foreignKey"],$subModule['foreignKey']) |
|
28 | + ->addHidden($subModule["foreignKey"], $subModule['foreignKey']) |
|
29 | 29 | ->defaultValue($subModule['foreignValue']); |
30 | 30 | } |
31 | 31 | } |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | $parentPath = $this->getData("permalink"); |
203 | 203 | $parentTitle = $this->getData("page_title"); |
204 | 204 | $this->addActionButton($label,function($row) use ($label, $controllerName, $foreignKey, $additionalInfo, $parentPath, $parentTitle) { |
205 | - $actionParameters = [ |
|
206 | - "label"=>$label, |
|
207 | - "foreignKey"=>$foreignKey, |
|
208 | - "foreignValue"=>$row->primary_key, |
|
209 | - "parentPath"=>$parentPath, |
|
210 | - "parentTitle"=>$parentTitle |
|
211 | - ]; |
|
205 | + $actionParameters = [ |
|
206 | + "label"=>$label, |
|
207 | + "foreignKey"=>$foreignKey, |
|
208 | + "foreignValue"=>$row->primary_key, |
|
209 | + "parentPath"=>$parentPath, |
|
210 | + "parentTitle"=>$parentTitle |
|
211 | + ]; |
|
212 | 212 | |
213 | 213 | if(isset($additionalInfo) && is_callable($additionalInfo)) { |
214 | 214 | $additionalInfo = call_user_func($additionalInfo, $row); |
@@ -217,15 +217,15 @@ discard block |
||
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | - $actionHash = md5(serialize($actionParameters)); |
|
221 | - $actionHashToken = Cache::get("subModule".$actionHash); |
|
222 | - if(!$actionHashToken) { |
|
223 | - $actionHashToken = Str::random(5); |
|
224 | - Cache::forever("subModule".$actionHash, $actionHashToken); |
|
225 | - Cache::forever("subModule".$actionHashToken, $actionParameters); |
|
226 | - } |
|
220 | + $actionHash = md5(serialize($actionParameters)); |
|
221 | + $actionHashToken = Cache::get("subModule".$actionHash); |
|
222 | + if(!$actionHashToken) { |
|
223 | + $actionHashToken = Str::random(5); |
|
224 | + Cache::forever("subModule".$actionHash, $actionHashToken); |
|
225 | + Cache::forever("subModule".$actionHashToken, $actionParameters); |
|
226 | + } |
|
227 | 227 | |
228 | - return action(class_basename($controllerName)."@getSubModule",['subModuleKey'=>$actionHashToken])."?ref=".makeReferalUrl($parentTitle); |
|
228 | + return action(class_basename($controllerName)."@getSubModule",['subModuleKey'=>$actionHashToken])."?ref=".makeReferalUrl($parentTitle); |
|
229 | 229 | }, $condition, $font, $color); |
230 | 230 | |
231 | 231 | } |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | $this->setButtonDetail(true); |
33 | 33 | $this->setButtonSave(true); |
34 | 34 | $this->setButtonLimitPage(true); |
35 | - $this->hideButtonDeleteWhen(function ($row) { return false; }); |
|
36 | - $this->hideButtonDetailWhen(function ($row) { return false; }); |
|
37 | - $this->hideButtonEditWhen(function ($row) { return false; }); |
|
38 | - $this->style(function () { return null; }); |
|
39 | - $this->javascript(function () { return null; }); |
|
35 | + $this->hideButtonDeleteWhen(function($row) { return false; }); |
|
36 | + $this->hideButtonDetailWhen(function($row) { return false; }); |
|
37 | + $this->hideButtonEditWhen(function($row) { return false; }); |
|
38 | + $this->style(function() { return null; }); |
|
39 | + $this->javascript(function() { return null; }); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function style(callable $style) { |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | * @param ButtonColor $color |
141 | 141 | * @param string $attributes |
142 | 142 | */ |
143 | - public function addIndexActionButton($label, $actionURL, $fontAwesome_icon=null, $color=null, $attributes = null) |
|
143 | + public function addIndexActionButton($label, $actionURL, $fontAwesome_icon = null, $color = null, $attributes = null) |
|
144 | 144 | { |
145 | - $color = ($color)?:ButtonColor::DARK_BLUE; |
|
145 | + $color = ($color) ?: ButtonColor::DARK_BLUE; |
|
146 | 146 | |
147 | 147 | $model = new IndexActionButtonModel(); |
148 | 148 | $model->setLabel($label); |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | public function addSubModule($label, $controllerName, $foreignKey, callable $additionalInfo = null, callable $condition = null, $font = null, $color = null) { |
202 | 202 | $parentPath = $this->getData("permalink"); |
203 | 203 | $parentTitle = $this->getData("page_title"); |
204 | - $this->addActionButton($label,function($row) use ($label, $controllerName, $foreignKey, $additionalInfo, $parentPath, $parentTitle) { |
|
204 | + $this->addActionButton($label, function($row) use ($label, $controllerName, $foreignKey, $additionalInfo, $parentPath, $parentTitle) { |
|
205 | 205 | $actionParameters = [ |
206 | 206 | "label"=>$label, |
207 | 207 | "foreignKey"=>$foreignKey, |
@@ -210,22 +210,22 @@ discard block |
||
210 | 210 | "parentTitle"=>$parentTitle |
211 | 211 | ]; |
212 | 212 | |
213 | - if(isset($additionalInfo) && is_callable($additionalInfo)) { |
|
213 | + if (isset($additionalInfo) && is_callable($additionalInfo)) { |
|
214 | 214 | $additionalInfo = call_user_func($additionalInfo, $row); |
215 | - if(is_array($additionalInfo)) { |
|
215 | + if (is_array($additionalInfo)) { |
|
216 | 216 | $actionParameters['info'] = $additionalInfo; |
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | 220 | $actionHash = md5(serialize($actionParameters)); |
221 | 221 | $actionHashToken = Cache::get("subModule".$actionHash); |
222 | - if(!$actionHashToken) { |
|
222 | + if (!$actionHashToken) { |
|
223 | 223 | $actionHashToken = Str::random(5); |
224 | 224 | Cache::forever("subModule".$actionHash, $actionHashToken); |
225 | 225 | Cache::forever("subModule".$actionHashToken, $actionParameters); |
226 | 226 | } |
227 | 227 | |
228 | - return action(class_basename($controllerName)."@getSubModule",['subModuleKey'=>$actionHashToken])."?ref=".makeReferalUrl($parentTitle); |
|
228 | + return action(class_basename($controllerName)."@getSubModule", ['subModuleKey'=>$actionHashToken])."?ref=".makeReferalUrl($parentTitle); |
|
229 | 229 | }, $condition, $font, $color); |
230 | 230 | |
231 | 231 | } |
@@ -238,12 +238,12 @@ discard block |
||
238 | 238 | * @param $fontAwesome_icon |
239 | 239 | * @param ButtonColor|string $color |
240 | 240 | */ |
241 | - public function addActionButton($label, $url_target, $condition_callback=null, $fontAwesome_icon=null, $color=null, $confirmation = false) |
|
241 | + public function addActionButton($label, $url_target, $condition_callback = null, $fontAwesome_icon = null, $color = null, $confirmation = false) |
|
242 | 242 | { |
243 | 243 | $new = new AddActionButtonModel(); |
244 | 244 | $new->setLabel($label); |
245 | - $new->setIcon($fontAwesome_icon?:"fa fa-bars"); |
|
246 | - $new->setColor($color?:"primary"); |
|
245 | + $new->setIcon($fontAwesome_icon ?: "fa fa-bars"); |
|
246 | + $new->setColor($color ?: "primary"); |
|
247 | 247 | $new->setUrl($url_target); |
248 | 248 | $new->setCondition($condition_callback); |
249 | 249 | $new->setConfirmation($confirmation); |
@@ -19,12 +19,12 @@ |
||
19 | 19 | */ |
20 | 20 | private function validation() |
21 | 21 | { |
22 | - if(isset($this->data['validation'])) { |
|
22 | + if (isset($this->data['validation'])) { |
|
23 | 23 | $validator = Validator::make(request()->all(), @$this->data['validation'], @$this->data['validation_messages']); |
24 | 24 | if ($validator->fails()) { |
25 | 25 | $message = $validator->messages(); |
26 | 26 | $message_all = $message->all(); |
27 | - throw new CBValidationException(implode(', ',$message_all)); |
|
27 | + throw new CBValidationException(implode(', ', $message_all)); |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | } |
@@ -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); |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | $model->setBasepath(config('crudbooster.ADMIN_PATH').'/'.basename($model->getUrl())); |
45 | 45 | } |
46 | 46 | |
47 | - if(request()->is($model->getBasepath()."*")) { |
|
47 | + if (request()->is($model->getBasepath()."*")) { |
|
48 | 48 | $model->setIsActive(true); |
49 | - }else{ |
|
49 | + } else { |
|
50 | 50 | $model->setIsActive(false); |
51 | 51 | } |
52 | 52 | |
@@ -55,22 +55,22 @@ discard block |
||
55 | 55 | |
56 | 56 | private function loadData($parent_id = null) { |
57 | 57 | $menus = DB::table("cb_menus"); |
58 | - if($parent_id) { |
|
59 | - $menus->where("parent_cb_menus_id",$parent_id); |
|
60 | - }else{ |
|
58 | + if ($parent_id) { |
|
59 | + $menus->where("parent_cb_menus_id", $parent_id); |
|
60 | + } else { |
|
61 | 61 | $menus->whereNull("parent_cb_menus_id"); |
62 | 62 | } |
63 | - return $menus->orderBy("sort_number","asc")->get(); |
|
63 | + return $menus->orderBy("sort_number", "asc")->get(); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | private function rolePrivilege($cb_roles_id, $cb_menus_id) { |
67 | - return cb()->find("cb_role_privileges",['cb_roles_id'=>$cb_roles_id,'cb_menus_id'=>$cb_menus_id]); |
|
67 | + return cb()->find("cb_role_privileges", ['cb_roles_id'=>$cb_roles_id, 'cb_menus_id'=>$cb_menus_id]); |
|
68 | 68 | } |
69 | 69 | |
70 | - private function checkPrivilege($roles_id,$menu) { |
|
71 | - if($roles_id) { |
|
70 | + private function checkPrivilege($roles_id, $menu) { |
|
71 | + if ($roles_id) { |
|
72 | 72 | $privilege = $this->rolePrivilege($roles_id, $menu->id); |
73 | - if($privilege && !$privilege->can_browse) { |
|
73 | + if ($privilege && !$privilege->can_browse) { |
|
74 | 74 | return false; |
75 | 75 | } |
76 | 76 | } |
@@ -79,39 +79,39 @@ discard block |
||
79 | 79 | } |
80 | 80 | |
81 | 81 | public function all($withPrivilege = true) { |
82 | - $roles_id = ($withPrivilege)?cb()->session()->roleId():null; |
|
82 | + $roles_id = ($withPrivilege) ?cb()->session()->roleId() : null; |
|
83 | 83 | $idHash = "menuUser".$roles_id.auth()->id(); |
84 | - if($menu = CacheHelper::getItemInGroup($idHash,"sidebar_menu")) return $menu; |
|
84 | + if ($menu = CacheHelper::getItemInGroup($idHash, "sidebar_menu")) return $menu; |
|
85 | 85 | |
86 | 86 | $menus = $this->loadData(); |
87 | 87 | $result = []; |
88 | 88 | $menus_active = false; |
89 | - foreach($menus as $menu) { |
|
89 | + foreach ($menus as $menu) { |
|
90 | 90 | |
91 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu)) continue; |
|
91 | + if ($withPrivilege && !$this->checkPrivilege($roles_id, $menu)) continue; |
|
92 | 92 | |
93 | 93 | $sidebarModel = $this->assignToModel($menu); |
94 | - if($sidebarModel->getisActive()) $menus_active = true; |
|
95 | - if($menus2 = $this->loadData($menu->id)) { |
|
94 | + if ($sidebarModel->getisActive()) $menus_active = true; |
|
95 | + if ($menus2 = $this->loadData($menu->id)) { |
|
96 | 96 | $sub1 = []; |
97 | 97 | $menus2_active = false; |
98 | 98 | foreach ($menus2 as $menu2) { |
99 | 99 | |
100 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu2)) continue; |
|
100 | + if ($withPrivilege && !$this->checkPrivilege($roles_id, $menu2)) continue; |
|
101 | 101 | |
102 | 102 | $sidebarModel2 = $this->assignToModel($menu2); |
103 | - if($sidebarModel2->getisActive()) $menus2_active = true; |
|
103 | + if ($sidebarModel2->getisActive()) $menus2_active = true; |
|
104 | 104 | |
105 | - if($menus3 = $this->loadData($menu2->id)) { |
|
105 | + if ($menus3 = $this->loadData($menu2->id)) { |
|
106 | 106 | $sub2 = []; |
107 | 107 | $menus3_active = false; |
108 | 108 | foreach ($menus3 as $menu3) { |
109 | 109 | |
110 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu3)) continue; |
|
110 | + if ($withPrivilege && !$this->checkPrivilege($roles_id, $menu3)) continue; |
|
111 | 111 | |
112 | 112 | $sidebarModel3 = $this->assignToModel($menu3); |
113 | 113 | |
114 | - if($sidebarModel3->getisActive()) { |
|
114 | + if ($sidebarModel3->getisActive()) { |
|
115 | 115 | $menus3_active = true; |
116 | 116 | } |
117 | 117 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $result[] = $sidebarModel; |
129 | 129 | } |
130 | 130 | |
131 | - CacheHelper::putInGroup($idHash, $result,"sidebar_menu", 3600); |
|
131 | + CacheHelper::putInGroup($idHash, $result, "sidebar_menu", 3600); |
|
132 | 132 | return $result; |
133 | 133 | } |
134 | 134 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $model->setIcon($menu->icon); |
29 | 29 | $model->setName($menu->name); |
30 | 30 | $model->setBasepath(basename($model->getUrl())); |
31 | - }elseif ($menu->type == "module") { |
|
31 | + } elseif ($menu->type == "module") { |
|
32 | 32 | $module = cb()->find("cb_modules", $menu->cb_modules_id); |
33 | 33 | $className = '\App\Http\Controllers\\'.$module->controller; |
34 | 34 | $controllerClass = new $className(); |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $model->setIcon($module->icon); |
38 | 38 | $model->setName($module->name); |
39 | 39 | $model->setBasepath(config('crudbooster.ADMIN_PATH').'/'.basename($model->getUrl())); |
40 | - }elseif ($menu->type == "path") { |
|
40 | + } elseif ($menu->type == "path") { |
|
41 | 41 | $model->setUrl(cb()->getAdminUrl($menu->path)); |
42 | 42 | $model->setIcon($menu->icon); |
43 | 43 | $model->setName($menu->name); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | |
47 | 47 | if(request()->is($model->getBasepath()."*")) { |
48 | 48 | $model->setIsActive(true); |
49 | - }else{ |
|
49 | + } else{ |
|
50 | 50 | $model->setIsActive(false); |
51 | 51 | } |
52 | 52 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $menus = DB::table("cb_menus"); |
58 | 58 | if($parent_id) { |
59 | 59 | $menus->where("parent_cb_menus_id",$parent_id); |
60 | - }else{ |
|
60 | + } else{ |
|
61 | 61 | $menus->whereNull("parent_cb_menus_id"); |
62 | 62 | } |
63 | 63 | return $menus->orderBy("sort_number","asc")->get(); |
@@ -81,33 +81,45 @@ discard block |
||
81 | 81 | public function all($withPrivilege = true) { |
82 | 82 | $roles_id = ($withPrivilege)?cb()->session()->roleId():null; |
83 | 83 | $idHash = "menuUser".$roles_id.auth()->id(); |
84 | - if($menu = CacheHelper::getItemInGroup($idHash,"sidebar_menu")) return $menu; |
|
84 | + if($menu = CacheHelper::getItemInGroup($idHash,"sidebar_menu")) { |
|
85 | + return $menu; |
|
86 | + } |
|
85 | 87 | |
86 | 88 | $menus = $this->loadData(); |
87 | 89 | $result = []; |
88 | 90 | $menus_active = false; |
89 | 91 | foreach($menus as $menu) { |
90 | 92 | |
91 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu)) continue; |
|
93 | + if($withPrivilege && !$this->checkPrivilege($roles_id, $menu)) { |
|
94 | + continue; |
|
95 | + } |
|
92 | 96 | |
93 | 97 | $sidebarModel = $this->assignToModel($menu); |
94 | - if($sidebarModel->getisActive()) $menus_active = true; |
|
98 | + if($sidebarModel->getisActive()) { |
|
99 | + $menus_active = true; |
|
100 | + } |
|
95 | 101 | if($menus2 = $this->loadData($menu->id)) { |
96 | 102 | $sub1 = []; |
97 | 103 | $menus2_active = false; |
98 | 104 | foreach ($menus2 as $menu2) { |
99 | 105 | |
100 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu2)) continue; |
|
106 | + if($withPrivilege && !$this->checkPrivilege($roles_id, $menu2)) { |
|
107 | + continue; |
|
108 | + } |
|
101 | 109 | |
102 | 110 | $sidebarModel2 = $this->assignToModel($menu2); |
103 | - if($sidebarModel2->getisActive()) $menus2_active = true; |
|
111 | + if($sidebarModel2->getisActive()) { |
|
112 | + $menus2_active = true; |
|
113 | + } |
|
104 | 114 | |
105 | 115 | if($menus3 = $this->loadData($menu2->id)) { |
106 | 116 | $sub2 = []; |
107 | 117 | $menus3_active = false; |
108 | 118 | foreach ($menus3 as $menu3) { |
109 | 119 | |
110 | - if($withPrivilege && !$this->checkPrivilege($roles_id, $menu3)) continue; |
|
120 | + if($withPrivilege && !$this->checkPrivilege($roles_id, $menu3)) { |
|
121 | + continue; |
|
122 | + } |
|
111 | 123 | |
112 | 124 | $sidebarModel3 = $this->assignToModel($menu3); |
113 | 125 |
@@ -23,7 +23,7 @@ |
||
23 | 23 | |
24 | 24 | public function hasData($key) { |
25 | 25 | $data = $this->data; |
26 | - if(isset($data[$key])) return true; |
|
26 | + if (isset($data[$key])) return true; |
|
27 | 27 | else return false; |
28 | 28 | } |
29 | 29 |
@@ -23,8 +23,11 @@ |
||
23 | 23 | |
24 | 24 | public function hasData($key) { |
25 | 25 | $data = $this->data; |
26 | - if(isset($data[$key])) return true; |
|
27 | - else return false; |
|
26 | + if(isset($data[$key])) { |
|
27 | + return true; |
|
28 | + } else { |
|
29 | + return false; |
|
30 | + } |
|
28 | 31 | } |
29 | 32 | |
30 | 33 | public function setData($key, $value): void |
@@ -16,6 +16,6 @@ |
||
16 | 16 | public static function hasColumn($table, $column) |
17 | 17 | { |
18 | 18 | $columns = cb()->listAllColumns($table); |
19 | - return in_array($column,$columns); |
|
19 | + return in_array($column, $columns); |
|
20 | 20 | } |
21 | 21 | } |
22 | 22 | \ No newline at end of file |