@@ -31,14 +31,14 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function getIndex() { |
| 33 | 33 | |
| 34 | - if(request("refresh")) { |
|
| 35 | - $this->fetchPluginData(false ); |
|
| 36 | - return cb()->redirectBack("Plugin list has been refreshed!","success"); |
|
| 34 | + if (request("refresh")) { |
|
| 35 | + $this->fetchPluginData(false); |
|
| 36 | + return cb()->redirectBack("Plugin list has been refreshed!", "success"); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $data = []; |
| 40 | 40 | $data['result'] = $this->fetchPluginData(); |
| 41 | - return view($this->view.'.index',$data); |
|
| 41 | + return view($this->view.'.index', $data); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | public function postLoginAccount() { |
@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | ]); |
| 54 | 54 | $response = $curl->send(); |
| 55 | 55 | |
| 56 | - if($respArray = json_decode($response, true)) { |
|
| 57 | - if($respArray['status'] && isset($respArray['token'])) { |
|
| 56 | + if ($respArray = json_decode($response, true)) { |
|
| 57 | + if ($respArray['status'] && isset($respArray['token'])) { |
|
| 58 | 58 | session(['account_token'=>$respArray['token']]); |
| 59 | 59 | } |
| 60 | - return response()->make($response,200,["Content-Type"=>"application/json"]); |
|
| 60 | + return response()->make($response, 200, ["Content-Type"=>"application/json"]); |
|
| 61 | 61 | } else { |
| 62 | - return response()->json(['status'=>false,'message'=>'failed']); |
|
| 62 | + return response()->json(['status'=>false, 'message'=>'failed']); |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
@@ -76,15 +76,15 @@ discard block |
||
| 76 | 76 | ]); |
| 77 | 77 | $response = $curl->send(); |
| 78 | 78 | |
| 79 | - if($respArray = json_decode($response, true)) { |
|
| 80 | - if($respArray['status']) { |
|
| 79 | + if ($respArray = json_decode($response, true)) { |
|
| 80 | + if ($respArray['status']) { |
|
| 81 | 81 | $form = base64_decode($respArray['payment']); |
| 82 | - return response()->json(['status'=>true,'form'=>$form]); |
|
| 82 | + return response()->json(['status'=>true, 'form'=>$form]); |
|
| 83 | 83 | } else { |
| 84 | 84 | return response()->json($respArray); |
| 85 | 85 | } |
| 86 | 86 | } else { |
| 87 | - return response()->json(['status'=>false,'message'=>'failed','raw'=>$response]); |
|
| 87 | + return response()->json(['status'=>false, 'message'=>'failed', 'raw'=>$response]); |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | { |
| 93 | 93 | $pluginData = $this->fetchPluginData(); |
| 94 | 94 | |
| 95 | - if(isset($pluginData[$key])) { |
|
| 96 | - if(file_exists(app_path("CBPlugins/".$key))) { |
|
| 95 | + if (isset($pluginData[$key])) { |
|
| 96 | + if (file_exists(app_path("CBPlugins/".$key))) { |
|
| 97 | 97 | |
| 98 | - if(isset($pluginData['source']) && $pluginData['source'] == 'composer') { |
|
| 99 | - if(isset($pluginData['package'])) { |
|
| 98 | + if (isset($pluginData['source']) && $pluginData['source'] == 'composer') { |
|
| 99 | + if (isset($pluginData['package'])) { |
|
| 100 | 100 | ComposerHelper::composerRemove($pluginData['package']); |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -104,24 +104,24 @@ discard block |
||
| 104 | 104 | rrmdir(app_path("CBPlugins/".$key)); |
| 105 | 105 | |
| 106 | 106 | return response()->json(['status'=>true, 'message'=>'Plugin has been uninstalled!']); |
| 107 | - }else{ |
|
| 108 | - return response()->json(['status'=>false,'message'=>'Failed to uninstall, plugin is not found']); |
|
| 107 | + } else { |
|
| 108 | + return response()->json(['status'=>false, 'message'=>'Failed to uninstall, plugin is not found']); |
|
| 109 | 109 | } |
| 110 | - }else { |
|
| 111 | - return response()->json(['status'=>false,'message'=>'Failed to uninstall, plugin key is not found']); |
|
| 110 | + } else { |
|
| 111 | + return response()->json(['status'=>false, 'message'=>'Failed to uninstall, plugin key is not found']); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - private function recursiveCopy($src,$dst) { |
|
| 115 | + private function recursiveCopy($src, $dst) { |
|
| 116 | 116 | $dir = opendir($src); |
| 117 | 117 | @mkdir($dst); |
| 118 | - while(false !== ( $file = readdir($dir)) ) { |
|
| 119 | - if (( $file != '.' ) && ( $file != '..' )) { |
|
| 120 | - if ( is_dir($src . '/' . $file) ) { |
|
| 121 | - $this->recursiveCopy($src . '/' . $file,$dst . '/' . $file); |
|
| 118 | + while (false !== ($file = readdir($dir))) { |
|
| 119 | + if (($file != '.') && ($file != '..')) { |
|
| 120 | + if (is_dir($src.'/'.$file)) { |
|
| 121 | + $this->recursiveCopy($src.'/'.$file, $dst.'/'.$file); |
|
| 122 | 122 | } |
| 123 | 123 | else { |
| 124 | - copy($src . '/' . $file,$dst . '/' . $file); |
|
| 124 | + copy($src.'/'.$file, $dst.'/'.$file); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | } |
@@ -130,26 +130,26 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | public function getInstall($key) |
| 132 | 132 | { |
| 133 | - ini_set("memory_limit","192M"); |
|
| 133 | + ini_set("memory_limit", "192M"); |
|
| 134 | 134 | set_time_limit(500); |
| 135 | 135 | |
| 136 | 136 | $pluginData = $this->fetchPluginData(); |
| 137 | 137 | |
| 138 | 138 | try { |
| 139 | - if(isset($pluginData[$key])) { |
|
| 139 | + if (isset($pluginData[$key])) { |
|
| 140 | 140 | $plugin = $pluginData[$key]; |
| 141 | 141 | |
| 142 | - if(isset($plugin['source']) && $plugin['source'] == "composer") { |
|
| 142 | + if (isset($plugin['source']) && $plugin['source'] == "composer") { |
|
| 143 | 143 | |
| 144 | - if(isset($plugin['package']) && isset($plugin['service_provider'])) { |
|
| 144 | + if (isset($plugin['package']) && isset($plugin['service_provider'])) { |
|
| 145 | 145 | // Make a composer |
| 146 | 146 | $output = ComposerHelper::composerRequire($plugin['package'], $plugin['service_provider']); |
| 147 | 147 | |
| 148 | 148 | Artisan::call("migrate"); |
| 149 | 149 | |
| 150 | - return response()->json(['status'=>true,'message'=>$output]); |
|
| 150 | + return response()->json(['status'=>true, 'message'=>$output]); |
|
| 151 | 151 | } else { |
| 152 | - return response()->json(['status'=>true,'message'=>'Installation is failed, there is no package and or service provider']); |
|
| 152 | + return response()->json(['status'=>true, 'message'=>'Installation is failed, there is no package and or service provider']); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | } else { |
@@ -168,16 +168,16 @@ discard block |
||
| 168 | 168 | fclose($temp); |
| 169 | 169 | |
| 170 | 170 | // Rename |
| 171 | - if(file_exists(app_path("CBPlugins/".$key))) rrmdir(app_path("CBPlugins/".$key)); |
|
| 171 | + if (file_exists(app_path("CBPlugins/".$key))) rrmdir(app_path("CBPlugins/".$key)); |
|
| 172 | 172 | rename(app_path("CBPlugins/".$dirName), app_path("CBPlugins/".$key)); |
| 173 | 173 | |
| 174 | 174 | // Read Plugin JSON |
| 175 | 175 | $pluginJson = json_decode(file_get_contents(app_path("CBPlugins/".$key."/plugin.json")), true); |
| 176 | 176 | |
| 177 | 177 | // Check if has asset |
| 178 | - if($pluginJson && $pluginJson['asset']) { |
|
| 178 | + if ($pluginJson && $pluginJson['asset']) { |
|
| 179 | 179 | // Check destination folder is ready |
| 180 | - if(file_exists(public_path("cb_asset/".$key))) { |
|
| 180 | + if (file_exists(public_path("cb_asset/".$key))) { |
|
| 181 | 181 | rrmdir(public_path("cb_asset/".$key)); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -191,31 +191,31 @@ discard block |
||
| 191 | 191 | //Migrate |
| 192 | 192 | Artisan::call("migrate"); |
| 193 | 193 | |
| 194 | - return response()->json(['status'=>true,'message'=>'Install / update plugin has been succesfull!']); |
|
| 194 | + return response()->json(['status'=>true, 'message'=>'Install / update plugin has been succesfull!']); |
|
| 195 | 195 | |
| 196 | 196 | } else { |
| 197 | - return response()->json(['status'=>false,'message'=>"Failed to install/update, can't open the plugin archive"]); |
|
| 197 | + return response()->json(['status'=>false, 'message'=>"Failed to install/update, can't open the plugin archive"]); |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - }else{ |
|
| 202 | - return response()->json(['status'=>false,'message'=>'Failed to install/update, plugin key is not found']); |
|
| 201 | + } else { |
|
| 202 | + return response()->json(['status'=>false, 'message'=>'Failed to install/update, plugin key is not found']); |
|
| 203 | 203 | } |
| 204 | 204 | } catch (\Exception $e) { |
| 205 | - return response()->json(['status'=>false,'message'=>'Something went wrong!']); |
|
| 205 | + return response()->json(['status'=>false, 'message'=>'Something went wrong!']); |
|
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | private function fetchPluginData($cache = true) |
| 210 | 210 | { |
| 211 | - if($cache === true && $data = Cache::get("plugin_store_data")) { |
|
| 211 | + if ($cache === true && $data = Cache::get("plugin_store_data")) { |
|
| 212 | 212 | return $data; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | $result = []; |
| 216 | 216 | |
| 217 | 217 | try { |
| 218 | - $no_cache = ($cache)?0:1; |
|
| 218 | + $no_cache = ($cache) ? 0 : 1; |
|
| 219 | 219 | $opts = [ |
| 220 | 220 | "http" => [ |
| 221 | 221 | "method" => "GET", |
@@ -224,17 +224,17 @@ discard block |
||
| 224 | 224 | "No-Cache: ".$no_cache |
| 225 | 225 | ] |
| 226 | 226 | ]; |
| 227 | - Log::debug("Headers: ".print_r($opts,true)); |
|
| 227 | + Log::debug("Headers: ".print_r($opts, true)); |
|
| 228 | 228 | $context = stream_context_create($opts); |
| 229 | 229 | $data = file_get_contents(base64_decode("aHR0cDovL2NydWRib29zdGVyLmNvbS9hcGkvcGx1Z2luP2FjY2Vzc190b2tlbj1iVmMvWm5wWU5TWnJNVlpZT0hFNVUydHFjU1U9"), false, $context); |
| 230 | 230 | Log::debug("Plugin API : ".$data); |
| 231 | - if($data) { |
|
| 231 | + if ($data) { |
|
| 232 | 232 | $data = json_decode($data, true); |
| 233 | - if($data['status']==true) { |
|
| 233 | + if ($data['status'] == true) { |
|
| 234 | 234 | |
| 235 | - foreach($data['data'] as $item) { |
|
| 235 | + foreach ($data['data'] as $item) { |
|
| 236 | 236 | $key = $item['key']; |
| 237 | - $result[ $key ] = $item; |
|
| 237 | + $result[$key] = $item; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | $result = collect($result)->sortBy("name")->all(); |
@@ -32,13 +32,13 @@ discard block |
||
| 32 | 32 | public function getIndex() { |
| 33 | 33 | $data = []; |
| 34 | 34 | $data['result'] = DB::table("cb_modules")->get(); |
| 35 | - return view($this->view.'.index',$data); |
|
| 35 | + return view($this->view.'.index', $data); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function getAdd() { |
| 39 | 39 | $data = []; |
| 40 | 40 | $data['tables'] = cb()->listAllTable(); |
| 41 | - $data['module'] = (request('modules_id'))?cb()->find("cb_modules", request("modules_id")):null; |
|
| 41 | + $data['module'] = (request('modules_id')) ?cb()->find("cb_modules", request("modules_id")) : null; |
|
| 42 | 42 | return view($this->view.'.add', $data); |
| 43 | 43 | } |
| 44 | 44 | |
@@ -51,17 +51,17 @@ discard block |
||
| 51 | 51 | $data = cb()->listAllColumns($table); |
| 52 | 52 | $pk = cb()->findPrimaryKey($table); |
| 53 | 53 | $result = []; |
| 54 | - foreach($data as $item) { |
|
| 54 | + foreach ($data as $item) { |
|
| 55 | 55 | |
| 56 | - if(Str::contains(strtolower($item),["title","name","label"])) { |
|
| 56 | + if (Str::contains(strtolower($item), ["title", "name", "label"])) { |
|
| 57 | 57 | $display = true; |
| 58 | - }else{ |
|
| 58 | + } else { |
|
| 59 | 59 | $display = false; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | $result[] = [ |
| 63 | 63 | "column"=>$item, |
| 64 | - "primary_key"=>($pk==$item)?true:false, |
|
| 64 | + "primary_key"=>($pk == $item) ?true:false, |
|
| 65 | 65 | "display"=>$display |
| 66 | 66 | ]; |
| 67 | 67 | } |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | public function getColumns($table) |
| 72 | 72 | { |
| 73 | - if(request("modules_id")) { |
|
| 74 | - $module = cb()->find("cb_modules",request("modules_id")); |
|
| 75 | - if($module->last_column_build) { |
|
| 73 | + if (request("modules_id")) { |
|
| 74 | + $module = cb()->find("cb_modules", request("modules_id")); |
|
| 75 | + if ($module->last_column_build) { |
|
| 76 | 76 | return response()->json(json_decode($module->last_column_build)); |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -80,56 +80,56 @@ discard block |
||
| 80 | 80 | $columns = cb()->listAllColumns($table); |
| 81 | 81 | $pk = cb()->findPrimaryKey($table); |
| 82 | 82 | $result = []; |
| 83 | - foreach($columns as $column) { |
|
| 84 | - if($column != $pk) { |
|
| 83 | + foreach ($columns as $column) { |
|
| 84 | + if ($column != $pk) { |
|
| 85 | 85 | |
| 86 | 86 | // Skip Column |
| 87 | - if($column == 'deleted_at') continue; |
|
| 87 | + if ($column == 'deleted_at') continue; |
|
| 88 | 88 | |
| 89 | 89 | // Check if any relation table candidate |
| 90 | 90 | $optionTable = ""; |
| 91 | - if(Str::substr(strtolower($column),-3,3) == "_id") { |
|
| 92 | - $relationTable = Str::substr($column,0,-3); |
|
| 93 | - if(Schema::hasTable($relationTable)) { |
|
| 91 | + if (Str::substr(strtolower($column), -3, 3) == "_id") { |
|
| 92 | + $relationTable = Str::substr($column, 0, -3); |
|
| 93 | + if (Schema::hasTable($relationTable)) { |
|
| 94 | 94 | $optionTable = $relationTable; |
| 95 | 95 | } |
| 96 | - }elseif (Str::substr(strtolower($column),0,3) == "id_") { |
|
| 97 | - $relationTable = Str::substr($column,3); |
|
| 98 | - if(Schema::hasTable($relationTable)) { |
|
| 96 | + }elseif (Str::substr(strtolower($column), 0, 3) == "id_") { |
|
| 97 | + $relationTable = Str::substr($column, 3); |
|
| 98 | + if (Schema::hasTable($relationTable)) { |
|
| 99 | 99 | $optionTable = $relationTable; |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $label = trim(Str::title(str_replace(["id_","_id","_"]," ",$column))); |
|
| 103 | + $label = trim(Str::title(str_replace(["id_", "_id", "_"], " ", $column))); |
|
| 104 | 104 | $label = Str::singular($label); |
| 105 | 105 | $type = "text"; |
| 106 | 106 | |
| 107 | - if(Str::contains(strtolower($label),["photo","image","picture","gambar"])) { |
|
| 107 | + if (Str::contains(strtolower($label), ["photo", "image", "picture", "gambar"])) { |
|
| 108 | 108 | $type = "image"; |
| 109 | - }elseif (Str::contains(strtolower($label),["email","mail"])) { |
|
| 109 | + }elseif (Str::contains(strtolower($label), ["email", "mail"])) { |
|
| 110 | 110 | $type = "email"; |
| 111 | - }elseif (Str::contains(strtolower($label),["description","content","detail"])) { |
|
| 112 | - $type = "wysiwyg"; |
|
| 113 | - }elseif (Str::contains(strtolower($label),["price","money","grand_total","tax"])) { |
|
| 111 | + }elseif (Str::contains(strtolower($label), ["description", "content", "detail"])) { |
|
| 112 | + $type = "wysiwyg"; |
|
| 113 | + }elseif (Str::contains(strtolower($label), ["price", "money", "grand_total", "tax"])) { |
|
| 114 | 114 | $type = "money"; |
| 115 | - }elseif (Str::contains(strtolower($label),["quantity","qty","total","phone","telp"])) { |
|
| 115 | + }elseif (Str::contains(strtolower($label), ["quantity", "qty", "total", "phone", "telp"])) { |
|
| 116 | 116 | $type = "number"; |
| 117 | - }elseif (Str::contains(strtolower($label),["date"])) { |
|
| 117 | + }elseif (Str::contains(strtolower($label), ["date"])) { |
|
| 118 | 118 | $type = "date"; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - if (Str::substr(strtolower($column),-3,3) == "_id") { |
|
| 121 | + if (Str::substr(strtolower($column), -3, 3) == "_id") { |
|
| 122 | 122 | $type = "select_table"; |
| 123 | 123 | } elseif (Str::substr($column, -3, 3) == "_at") { |
| 124 | 124 | $type = "datetime"; |
| 125 | - } elseif (Str::substr($column,0, 3) == "id_") { |
|
| 125 | + } elseif (Str::substr($column, 0, 3) == "id_") { |
|
| 126 | 126 | $type = "select_table"; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | $columnAdd = "on"; |
| 130 | 130 | $columnEdit = "on"; |
| 131 | 131 | $columnMandatory = "on"; |
| 132 | - if(in_array($column,['created_at','updated_at'])) { |
|
| 132 | + if (in_array($column, ['created_at', 'updated_at'])) { |
|
| 133 | 133 | $columnAdd = ""; |
| 134 | 134 | $columnEdit = ""; |
| 135 | 135 | $columnMandatory = ""; |
@@ -174,41 +174,41 @@ discard block |
||
| 174 | 174 | public function postCreateMigration() |
| 175 | 175 | { |
| 176 | 176 | try { |
| 177 | - cb()->validation(['table_name','structures']); |
|
| 177 | + cb()->validation(['table_name', 'structures']); |
|
| 178 | 178 | |
| 179 | 179 | $tableName = request("table_name"); |
| 180 | 180 | |
| 181 | - if(!Schema::hasTable($tableName)) { |
|
| 181 | + if (!Schema::hasTable($tableName)) { |
|
| 182 | 182 | $filenameMigration = date("Y_m_d_His")."_".$tableName.".php"; |
| 183 | 183 | $createTemplate = file_get_contents(base_path("vendor/laravel/framework/src/Illuminate/Database/Migrations/stubs/create.stub")); |
| 184 | 184 | $className = Str::studly($tableName); |
| 185 | 185 | $createTemplate = str_replace("DummyClass", $className, $createTemplate); |
| 186 | 186 | $createTemplate = str_replace("DummyTable", $tableName, $createTemplate); |
| 187 | - $createTemplate = str_replace("\$table->increments('id');","",$createTemplate); |
|
| 188 | - $createTemplate = str_replace("\$table->bigIncrements('id');","",$createTemplate); |
|
| 189 | - $createTemplate = str_replace("\$table->timestamps();","{structure}",$createTemplate); |
|
| 187 | + $createTemplate = str_replace("\$table->increments('id');", "", $createTemplate); |
|
| 188 | + $createTemplate = str_replace("\$table->bigIncrements('id');", "", $createTemplate); |
|
| 189 | + $createTemplate = str_replace("\$table->timestamps();", "{structure}", $createTemplate); |
|
| 190 | 190 | |
| 191 | 191 | $structureItems = ""; |
| 192 | 192 | |
| 193 | - if(request("timestamp")) { |
|
| 193 | + if (request("timestamp")) { |
|
| 194 | 194 | $structureItems .= "\$table->timestamps();\n\t\t\t"; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - if(request("soft_deletes")) { |
|
| 197 | + if (request("soft_deletes")) { |
|
| 198 | 198 | $structureItems .= "\$table->softDeletes();\n\t\t\t"; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - foreach(request("structures") as $item) { |
|
| 201 | + foreach (request("structures") as $item) { |
|
| 202 | 202 | |
| 203 | 203 | $nullable = ""; |
| 204 | 204 | |
| 205 | - if(!in_array($item['type_data'],["bigIncrements","increments","mediumIncrements","smallIncrements"])) { |
|
| 205 | + if (!in_array($item['type_data'], ["bigIncrements", "increments", "mediumIncrements", "smallIncrements"])) { |
|
| 206 | 206 | $nullable = "->nullable()"; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - if($item['length']) { |
|
| 209 | + if ($item['length']) { |
|
| 210 | 210 | $structureItems .= "\$table->".$item['type_data']."('".$item['field_name']."', ".$item['length'].")$nullable;\n\t\t\t"; |
| 211 | - }else{ |
|
| 211 | + } else { |
|
| 212 | 212 | $structureItems .= "\$table->".$item['type_data']."('".$item['field_name']."')$nullable;\n\t\t\t"; |
| 213 | 213 | } |
| 214 | 214 | } |
@@ -227,12 +227,12 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | } catch (CBValidationException $e) { |
| 230 | - return response()->json(['status'=>false,'message'=>$e->getMessage()]); |
|
| 230 | + return response()->json(['status'=>false, 'message'=>$e->getMessage()]); |
|
| 231 | 231 | } catch (\Exception $e) { |
| 232 | - return response()->json(['status'=>false,'message'=>$e->getMessage()]); |
|
| 232 | + return response()->json(['status'=>false, 'message'=>$e->getMessage()]); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - return response()->json(['status'=>true,'message'=>'Migration successfully!']); |
|
| 235 | + return response()->json(['status'=>true, 'message'=>'Migration successfully!']); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | public function postCheckExistModule() |
@@ -240,12 +240,12 @@ discard block |
||
| 240 | 240 | try { |
| 241 | 241 | cb()->validation(['name', 'table']); |
| 242 | 242 | |
| 243 | - if(DB::table("cb_modules")->where("table_name",request("table"))->where("name",request("name"))->count()) { |
|
| 243 | + if (DB::table("cb_modules")->where("table_name", request("table"))->where("name", request("name"))->count()) { |
|
| 244 | 244 | return response()->json(['status'=>true]); |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | } catch (CBValidationException $e) { |
| 248 | - return response()->json(['status'=>false,'message'=>$e->getMessage()]); |
|
| 248 | + return response()->json(['status'=>false, 'message'=>$e->getMessage()]); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | return response()->json(['status'=>false]); |
@@ -254,30 +254,30 @@ discard block |
||
| 254 | 254 | public function postAddSave() { |
| 255 | 255 | |
| 256 | 256 | try { |
| 257 | - cb()->validation(['name', 'table','icon','columns']); |
|
| 257 | + cb()->validation(['name', 'table', 'icon', 'columns']); |
|
| 258 | 258 | |
| 259 | 259 | $module = (new ModuleGenerator(request('table'), request('name'), request('icon'), request("columns"), request("rebuild")))->make(); |
| 260 | 260 | |
| 261 | 261 | } catch (CBValidationException $e) { |
| 262 | - return response()->json(['status'=>false,'message'=>$e->getMessage()]); |
|
| 262 | + return response()->json(['status'=>false, 'message'=>$e->getMessage()]); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | return response()->json(['status'=>true, 'message'=>'Please remember that you can still modify the structure by edit the controller file '.$module['controller'].' :)']); |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | public function getDelete($id) { |
| 269 | - $module = cb()->find("cb_modules",$id); |
|
| 269 | + $module = cb()->find("cb_modules", $id); |
|
| 270 | 270 | @unlink(app_path("Http/Controllers/".$module->controller.".php")); |
| 271 | 271 | DB::table("cb_modules")->where("id", $id)->delete(); |
| 272 | 272 | DB::table("cb_menus")->where("cb_modules_id", $id)->delete(); |
| 273 | - return cb()->redirectBack("The module has been deleted!","success"); |
|
| 273 | + return cb()->redirectBack("The module has been deleted!", "success"); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | public function getDeleteSoft($id) { |
| 277 | - $module = cb()->find("cb_modules",$id); |
|
| 277 | + $module = cb()->find("cb_modules", $id); |
|
| 278 | 278 | DB::table("cb_modules")->where("id", $id)->delete(); |
| 279 | 279 | DB::table("cb_menus")->where("cb_modules_id", $id)->delete(); |
| 280 | - return cb()->redirectBack("The module has been deleted!","success"); |
|
| 280 | + return cb()->redirectBack("The module has been deleted!", "success"); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | } |
| 284 | 284 | \ No newline at end of file |
@@ -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')) { |
|
| 156 | + if ($this->controller_class && method_exists($this->controller_class, 'getEdit')) { |
|
| 157 | 157 | return action($this->controller.'@getEdit')."/".$id; |
| 158 | - }else{ |
|
| 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')) { |
|
| 165 | + if (method_exists($this->controller_class, 'postEditSave')) { |
|
| 166 | 166 | return action($this->controller.'@postEditSave')."/".$id; |
| 167 | - }else{ |
|
| 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')) { |
|
| 174 | + if ($this->controller_class && method_exists($this->controller_class, 'getDetail')) { |
|
| 175 | 175 | return action($this->controller.'@getDetail')."/".$id; |
| 176 | - }else{ |
|
| 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')) { |
|
| 183 | + if ($this->controller_class && method_exists($this->controller_class, 'getDelete')) { |
|
| 184 | 184 | return action($this->controller.'@getDelete')."/".$id; |
| 185 | - }else{ |
|
| 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 | } |