From c18ebcba2270f350c1fcd75cd8026edea756f9a8 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Mon, 21 Oct 2019 00:55:58 -0500 Subject: [PATCH] citadel lookup --- .../Dashboard/DashboardController.php | 21 +++++- app/Library/Lookups/LookupHelper.php | 69 ++++++++++++++++++- app/Models/Lookups/CitadelLookup.php | 29 ++++++++ ..._21_054444_create_citadel_lookup_table.php | 40 +++++++++++ vendor/composer/ClassLoader.php | 2 +- vendor/composer/autoload_classmap.php | 1 + vendor/composer/autoload_static.php | 1 + 7 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 app/Models/Lookups/CitadelLookup.php create mode 100644 database/migrations/2019_10_21_054444_create_citadel_lookup_table.php diff --git a/app/Http/Controllers/Dashboard/DashboardController.php b/app/Http/Controllers/Dashboard/DashboardController.php index e7d0390..26301c5 100644 --- a/app/Http/Controllers/Dashboard/DashboardController.php +++ b/app/Http/Controllers/Dashboard/DashboardController.php @@ -39,17 +39,32 @@ class DashboardController extends Controller foreach($tempContracts as $con) { if($con->status == 'outstanding') { + //Find the start station or citadel + if($con->start_location_id) { + $startStation = $lookupHelper->GetCitadelDetails($con->start_location_id); + } else if($con->start_location_id) { + $startStation = $lookupHelper->GetStationDetails($con->start_location_id); + } else { + $startSystem = 'N/A'; + } - //Find start and end station. Need to work on how to tell citadels later. - $startStation = $lookupHelper->GetStationDetails($con->start_location_id); - $endStation = $lookupHelper->GetStationDetails($con->end_location_id); + //Find the end station or citadel + if($con->end_location_id) { + $endStation = $lookupHelper->GetCitadelDetails($con->end_location_id); + } else if($con->end_location_id) { + $endStation = $lookupHelper->GetStationDetails($con->end_location_id); + } else { + $endSystem = 'N/A'; + } + //Find the system via it's id. if(isset($startStation->system_id)) { $startSystem = $lookupHelper->GetSolarSystemName($startStation->system_id); } else { $startSystem = 'N/A'; } + //Find the system via it's id. if(isset($endStation->system_id)) { $endSystem = $lookupHelper->GetSolarSystemName($endStation->system_id); } else { diff --git a/app/Library/Lookups/LookupHelper.php b/app/Library/Lookups/LookupHelper.php index 4fc5d6e..5b5e9cd 100644 --- a/app/Library/Lookups/LookupHelper.php +++ b/app/Library/Lookups/LookupHelper.php @@ -748,7 +748,7 @@ class LookupHelper { } else if( $name != null) { $count = StationLookup::where(['name' => $name])->count(); - if($coutn > 0) { + if($count > 0) { $station = StationLookup::where(['name' => $name])->first(); } else { return null; @@ -781,6 +781,73 @@ class LookupHelper { $station->type_id = $response->type_id; $station->save(); } + + public function GetCitadelDetails($citadelId) { + //Check if the citadel is stored in the database + $citadel = $this->LookupCitadel($citadelId, null); + + //If the citadel id is null, then we didn't find it, and we run esi + //to find the details if possible + if($citadel != null) { + return $citadel; + } else { + try { + $citadel = $this->esi->invoke('get', '/universe/structures/{structure_id}/', [ + 'structure_id' => $citadelId, + ]); + } catch(RequestFailedException $e) { + Log::warning("Failed to get citadel details from /universe/structures/{structure_id}/"); + return null; + } + + //Save the citadel in the database + $this->SaveCitadel($citadel, $citadelId); + + return $citadel; + } + } + + public function LookupCitadel($id = null, $name = null) { + //If both the id and name are null, then there is nothing to look up + if($id == null && $name == null) { + return null; + } + + //Run through the checks to try to find the station either by id first, + //then from the citadel name + if($id != null) { + $count = CitadelLookup::where(['structure_id' => $id])->count(); + + if($count > 0) { + $citadel = CitadelLookup::where(['structure_id' => $id])->first(); + } else { + return null; + } + } else if($name != null) { + $count = CitadelLookup::where(['name' => $name])->count(); + + if($count > 0) { + $citadel = CitadelLookup::where(['name' => $name])->first(); + } else { + return null; + } + } + + //Return the details of the station if they were found + return $citadel; + } + + private function SaveCitadel($response, $id) { + $citadel = new CitadelLookup; + $citadel->structure_id = $id; + $citadel->name = $response->name; + $citadel->position_x = $response->position->x; + $citadel->position_y = $response->position->y; + $citadel->position_z = $response->position->z; + $citadel->solar_system_id = $response->solar_system_id; + $citadel->type_id = $response->type_id; + $citadel->save(); + } } ?> \ No newline at end of file diff --git a/app/Models/Lookups/CitadelLookup.php b/app/Models/Lookups/CitadelLookup.php new file mode 100644 index 0000000..99b798f --- /dev/null +++ b/app/Models/Lookups/CitadelLookup.php @@ -0,0 +1,29 @@ +bigIncrements('id'); + $table->unsignedBigInteger('structure_id'); + $table->string('name'); + $table->bigInteger('position_x'); + $table->bigInteger('position_y'); + $table->bigInteger('position_z'); + $table->unsignedBigInteger('solar_system_id'); + $table->unsignedBigInteger('type_id'); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('citadel_lookup'); + } +} diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php index fce8549..95f7e09 100644 --- a/vendor/composer/ClassLoader.php +++ b/vendor/composer/ClassLoader.php @@ -279,7 +279,7 @@ class ClassLoader */ public function setApcuPrefix($apcuPrefix) { - $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null; } /** diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index d96e523..5252275 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( + 'App\\CitadelLookup' => $baseDir . '/app/Models/Lookups/CitadelLookup.php', 'App\\Console\\Kernel' => $baseDir . '/app/Console/Kernel.php', 'App\\Exceptions\\Handler' => $baseDir . '/app/Exceptions/Handler.php', 'App\\Http\\Controllers\\Auth\\EsiScopeController' => $baseDir . '/app/Http/Controllers/Auth/EsiScopeController.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 7e4072a..588775a 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -486,6 +486,7 @@ class ComposerStaticInit33afb8ba5b252c3933eb137784fa7f04 ); public static $classMap = array ( + 'App\\CitadelLookup' => __DIR__ . '/../..' . '/app/Models/Lookups/CitadelLookup.php', 'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.php', 'App\\Exceptions\\Handler' => __DIR__ . '/../..' . '/app/Exceptions/Handler.php', 'App\\Http\\Controllers\\Auth\\EsiScopeController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/EsiScopeController.php',