@@ -26,14 +26,14 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | public function __call($method, $parameters) |
| 28 | 28 | { |
| 29 | - if($method == "getData") { |
|
| 29 | + if ($method == "getData") { |
|
| 30 | 30 | $key = $parameters[0]; |
| 31 | - if(isset($this->data[$key])) { |
|
| 31 | + if (isset($this->data[$key])) { |
|
| 32 | 32 | return $this->data[$key]; |
| 33 | - }else{ |
|
| 33 | + } else { |
|
| 34 | 34 | return null; |
| 35 | 35 | } |
| 36 | - }else{ |
|
| 36 | + } else { |
|
| 37 | 37 | return null; |
| 38 | 38 | } |
| 39 | 39 | } |
@@ -48,19 +48,19 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | $query->addSelect($this->data['table'].'.'.cb()->pk($this->data['table']).' as primary_key'); |
| 50 | 50 | |
| 51 | - if(isset($this->data['hook_query_index']) && is_callable($this->data['hook_query_index'])) |
|
| 51 | + if (isset($this->data['hook_query_index']) && is_callable($this->data['hook_query_index'])) |
|
| 52 | 52 | { |
| 53 | 53 | $query = call_user_func($this->data['hook_query_index'], $query); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - $softDelete = isset($this->data['disable_soft_delete'])?$this->data['disable_soft_delete']:true; |
|
| 57 | - if($softDelete === true && Schema::hasColumn($this->data['table'],'deleted_at')) { |
|
| 56 | + $softDelete = isset($this->data['disable_soft_delete']) ? $this->data['disable_soft_delete'] : true; |
|
| 57 | + if ($softDelete === true && Schema::hasColumn($this->data['table'], 'deleted_at')) { |
|
| 58 | 58 | $query->whereNull($this->data['table'].'.deleted_at'); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | |
| 62 | - if(isset($joins)) { |
|
| 63 | - foreach($joins as $join) |
|
| 62 | + if (isset($joins)) { |
|
| 63 | + foreach ($joins as $join) |
|
| 64 | 64 | { |
| 65 | 65 | $query->join($join['target_table'], |
| 66 | 66 | $join['target_table_primary'], |
@@ -70,12 +70,12 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - foreach($columns as $column) { |
|
| 73 | + foreach ($columns as $column) { |
|
| 74 | 74 | /** @var ColumnModel $column */ |
| 75 | - if($column->getType() != "custom") { |
|
| 76 | - if(strpos($column->getField(),".") === false) { |
|
| 75 | + if ($column->getType() != "custom") { |
|
| 76 | + if (strpos($column->getField(), ".") === false) { |
|
| 77 | 77 | $query->addSelect($this->data['table'].'.'.$column->getField()); |
| 78 | - }else{ |
|
| 78 | + } else { |
|
| 79 | 79 | $query->addSelect($column->getField()); |
| 80 | 80 | } |
| 81 | 81 | } |
@@ -83,20 +83,20 @@ discard block |
||
| 83 | 83 | $query = getTypeHook($column->getType())->query($query, $column); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if(request()->has('q')) |
|
| 86 | + if (request()->has('q')) |
|
| 87 | 87 | { |
| 88 | - if(isset($this->data['hook_search_query'])) { |
|
| 88 | + if (isset($this->data['hook_search_query'])) { |
|
| 89 | 89 | $query = call_user_func($this->data['hook_search_query'], $query); |
| 90 | - }else{ |
|
| 91 | - $query->where(function ($where) use ($columns) { |
|
| 90 | + } else { |
|
| 91 | + $query->where(function($where) use ($columns) { |
|
| 92 | 92 | /** |
| 93 | 93 | * @var $where Builder |
| 94 | 94 | */ |
| 95 | - foreach($columns as $column) |
|
| 95 | + foreach ($columns as $column) |
|
| 96 | 96 | { |
| 97 | - if(strpos($column->getField(),".") === false) { |
|
| 97 | + if (strpos($column->getField(), ".") === false) { |
|
| 98 | 98 | $field = $this->data['table'].'.'.$column->getField(); |
| 99 | - }else{ |
|
| 99 | + } else { |
|
| 100 | 100 | $field = $column->getField(); |
| 101 | 101 | } |
| 102 | 102 | $where->orWhere($field, 'like', '%'.request('q').'%'); |
@@ -105,17 +105,17 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if(isset($this->data['hook_query_index']) && is_callable($this->data['hook_query_index'])) { |
|
| 108 | + if (isset($this->data['hook_query_index']) && is_callable($this->data['hook_query_index'])) { |
|
| 109 | 109 | $query = call_user_func($this->data['hook_query_index'], $query); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
| 113 | - if(request()->has(['order_by','order_sort'])) |
|
| 113 | + if (request()->has(['order_by', 'order_sort'])) |
|
| 114 | 114 | { |
| 115 | - if(in_array(request('order_by'),columnSingleton()->getColumnNameOnly())) { |
|
| 115 | + if (in_array(request('order_by'), columnSingleton()->getColumnNameOnly())) { |
|
| 116 | 116 | $query->orderBy(request('order_by'), request('order_sort')); |
| 117 | 117 | } |
| 118 | - }else{ |
|
| 118 | + } else { |
|
| 119 | 119 | $query->orderBy($this->data['table'].'.'.cb()->findPrimaryKey($this->data['table']), "desc"); |
| 120 | 120 | } |
| 121 | 121 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | public function getIndex() |
| 126 | 126 | { |
| 127 | - if(!module()->canBrowse()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area"); |
|
| 127 | + if (!module()->canBrowse()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area"); |
|
| 128 | 128 | |
| 129 | 129 | $query = $this->repository(); |
| 130 | 130 | $result = $query->paginate(20); |
@@ -139,29 +139,29 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | private function validation() |
| 141 | 141 | { |
| 142 | - if(isset($this->data['validation'])) { |
|
| 142 | + if (isset($this->data['validation'])) { |
|
| 143 | 143 | $validator = Validator::make(request()->all(), @$this->data['validation'], @$this->data['validation_messages']); |
| 144 | 144 | if ($validator->fails()) { |
| 145 | 145 | $message = $validator->messages(); |
| 146 | 146 | $message_all = $message->all(); |
| 147 | - throw new CBValidationException(implode(', ',$message_all)); |
|
| 147 | + throw new CBValidationException(implode(', ', $message_all)); |
|
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | public function getAdd() |
| 153 | 153 | { |
| 154 | - if(!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area"); |
|
| 154 | + if (!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area"); |
|
| 155 | 155 | |
| 156 | 156 | $data = []; |
| 157 | 157 | $data['page_title'] = $this->data['page_title'].' : Add'; |
| 158 | 158 | $data['action_url'] = module()->addSaveURL(); |
| 159 | - return view('crudbooster::module.form.form',array_merge($data, $this->data)); |
|
| 159 | + return view('crudbooster::module.form.form', array_merge($data, $this->data)); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | public function postAddSave() |
| 163 | 163 | { |
| 164 | - if(!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area"); |
|
| 164 | + if (!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area"); |
|
| 165 | 165 | |
| 166 | 166 | try { |
| 167 | 167 | $this->validation(); |
@@ -169,28 +169,28 @@ discard block |
||
| 169 | 169 | $data = columnSingleton()->getAssignmentData(); |
| 170 | 170 | |
| 171 | 171 | //Clear data from Primary Key |
| 172 | - unset($data[ cb()->pk($this->data['table']) ]); |
|
| 172 | + unset($data[cb()->pk($this->data['table'])]); |
|
| 173 | 173 | |
| 174 | - if(Schema::hasColumn($this->data['table'], 'created_at')) { |
|
| 174 | + if (Schema::hasColumn($this->data['table'], 'created_at')) { |
|
| 175 | 175 | $data['created_at'] = date('Y-m-d H:i:s'); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - if(isset($this->data['hook_before_insert']) && is_callable($this->data['hook_before_insert'])) { |
|
| 178 | + if (isset($this->data['hook_before_insert']) && is_callable($this->data['hook_before_insert'])) { |
|
| 179 | 179 | $data = call_user_func($this->data['hook_before_insert'], $data); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | $id = DB::table($this->data['table'])->insertGetId($data); |
| 183 | 183 | |
| 184 | - if(isset($this->data['hook_after_insert']) && is_callable($this->data['hook_after_insert'])) { |
|
| 184 | + if (isset($this->data['hook_after_insert']) && is_callable($this->data['hook_after_insert'])) { |
|
| 185 | 185 | call_user_func($this->data['hook_after_insert'], $id); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | } catch (CBValidationException $e) { |
| 189 | 189 | Log::debug($e); |
| 190 | - return cb()->redirectBack($e->getMessage(),'info'); |
|
| 190 | + return cb()->redirectBack($e->getMessage(), 'info'); |
|
| 191 | 191 | } catch (\Exception $e) { |
| 192 | 192 | Log::error($e); |
| 193 | - return cb()->redirectBack($e->getMessage(),'warning'); |
|
| 193 | + return cb()->redirectBack($e->getMessage(), 'warning'); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | if (request('submit') == trans('crudbooster.button_save_more')) { |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | public function getEdit($id) |
| 204 | 204 | { |
| 205 | - if(!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area"); |
|
| 205 | + if (!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area"); |
|
| 206 | 206 | |
| 207 | 207 | $data = []; |
| 208 | 208 | $data['row'] = $this->repository()->where($this->data['table'].'.'.getPrimaryKey($this->data['table']), $id)->first(); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | public function postEditSave($id) |
| 215 | 215 | { |
| 216 | - if(!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area"); |
|
| 216 | + if (!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area"); |
|
| 217 | 217 | |
| 218 | 218 | try { |
| 219 | 219 | $this->validation(); |
@@ -221,13 +221,13 @@ discard block |
||
| 221 | 221 | $data = columnSingleton()->getAssignmentData(); |
| 222 | 222 | |
| 223 | 223 | //Clear data from Primary Key |
| 224 | - unset($data[ cb()->pk($this->data['table']) ]); |
|
| 224 | + unset($data[cb()->pk($this->data['table'])]); |
|
| 225 | 225 | |
| 226 | - if(Schema::hasColumn($this->data['table'], 'updated_at')) { |
|
| 226 | + if (Schema::hasColumn($this->data['table'], 'updated_at')) { |
|
| 227 | 227 | $data['updated_at'] = date('Y-m-d H:i:s'); |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if(isset($this->data['hook_before_update']) && is_callable($this->data['hook_before_update'])) { |
|
| 230 | + if (isset($this->data['hook_before_update']) && is_callable($this->data['hook_before_update'])) { |
|
| 231 | 231 | $data = call_user_func($this->data['hook_before_update'], $id, $data); |
| 232 | 232 | } |
| 233 | 233 | |
@@ -235,16 +235,16 @@ discard block |
||
| 235 | 235 | ->where(cb()->pk($this->data['table']), $id) |
| 236 | 236 | ->update($data); |
| 237 | 237 | |
| 238 | - if(isset($this->data['hook_after_update']) && is_callable($this->data['hook_after_update'])) { |
|
| 238 | + if (isset($this->data['hook_after_update']) && is_callable($this->data['hook_after_update'])) { |
|
| 239 | 239 | call_user_func($this->data['hook_after_update'], $id); |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | } catch (CBValidationException $e) { |
| 243 | 243 | Log::debug($e); |
| 244 | - return cb()->redirectBack($e->getMessage(),'info'); |
|
| 244 | + return cb()->redirectBack($e->getMessage(), 'info'); |
|
| 245 | 245 | } catch (\Exception $e) { |
| 246 | 246 | Log::error($e); |
| 247 | - return cb()->redirectBack($e->getMessage(),'warning'); |
|
| 247 | + return cb()->redirectBack($e->getMessage(), 'warning'); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -257,15 +257,15 @@ discard block |
||
| 257 | 257 | |
| 258 | 258 | public function getDelete($id) |
| 259 | 259 | { |
| 260 | - if(!module()->canDelete()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area"); |
|
| 260 | + if (!module()->canDelete()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area"); |
|
| 261 | 261 | |
| 262 | - if(isset($this->data['hook_before_delete']) && is_callable($this->data['hook_before_delete'])) { |
|
| 262 | + if (isset($this->data['hook_before_delete']) && is_callable($this->data['hook_before_delete'])) { |
|
| 263 | 263 | call_user_func($this->data['hook_before_delete'], $id); |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - $softDelete = isset($this->data['disable_soft_delete'])?$this->data['disable_soft_delete']:true; |
|
| 266 | + $softDelete = isset($this->data['disable_soft_delete']) ? $this->data['disable_soft_delete'] : true; |
|
| 267 | 267 | |
| 268 | - if ($softDelete === true && Schema::hasColumn($this->data['table'],'deleted_at')) { |
|
| 268 | + if ($softDelete === true && Schema::hasColumn($this->data['table'], 'deleted_at')) { |
|
| 269 | 269 | DB::table($this->data['table']) |
| 270 | 270 | ->where(getPrimaryKey($this->data['table']), $id) |
| 271 | 271 | ->update(['deleted_at' => date('Y-m-d H:i:s')]); |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | ->delete(); |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if(isset($this->data['hook_after_delete']) && is_callable($this->data['hook_after_delete'])) { |
|
| 278 | + if (isset($this->data['hook_after_delete']) && is_callable($this->data['hook_after_delete'])) { |
|
| 279 | 279 | call_user_func($this->data['hook_after_delete'], $id); |
| 280 | 280 | } |
| 281 | 281 | |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | |
| 285 | 285 | public function getDetail($id) |
| 286 | 286 | { |
| 287 | - if(!module()->canRead()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area"); |
|
| 287 | + if (!module()->canRead()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area"); |
|
| 288 | 288 | |
| 289 | 289 | $data = []; |
| 290 | 290 | $data['row'] = $this->repository()->where($this->data['table'].'.'.getPrimaryKey($this->data['table']), $id)->first(); |