From 18ef68979cdc1479fe4f7ecf83a04bbe2260ce31 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Sat, 12 Oct 2019 22:10:15 -0500 Subject: [PATCH] station lookup tables --- .../Dashboard/DashboardController.php | 9 ++- app/Library/Lookups/LookupHelper.php | 81 +++++++++++++++++++ app/Models/Lookups/SolarSystemDistance.php | 2 +- app/Models/Lookups/StationLookup.php | 38 +++++++++ ..._13_025833_create_station_lookup_table.php | 47 +++++++++++ vendor/composer/ClassLoader.php | 4 +- vendor/composer/autoload_classmap.php | 6 +- vendor/composer/autoload_static.php | 6 +- 8 files changed, 183 insertions(+), 10 deletions(-) create mode 100644 app/Models/Lookups/StationLookup.php create mode 100644 database/migrations/2019_10_13_025833_create_station_lookup_table.php diff --git a/app/Http/Controllers/Dashboard/DashboardController.php b/app/Http/Controllers/Dashboard/DashboardController.php index e0981fb..2f859b5 100644 --- a/app/Http/Controllers/Dashboard/DashboardController.php +++ b/app/Http/Controllers/Dashboard/DashboardController.php @@ -30,9 +30,12 @@ class DashboardController extends Controller foreach($tempContracts as $con) { if($con->status != 'finished') { - dd($con->start_location_id); - $startSystem = $lookupHelper->GetSolarSystemName($con->start_location_id); - $endSystem = $lookupHelper->GetSolarSystemName($con->end_location_id); + + $startStation = $lookupHelper->GetStationDetails($con->start_location_id); + $endStation = $lookupHelper->GetStationDetails($con->end_location_id); + + $startSystem = $lookupHelper->GetSolarSystemName($startStation->system_id); + $endSystem = $lookupHelper->GetSolarSystemName($endStation->system_id); $final = [ 'pickup' => $startSystem, diff --git a/app/Library/Lookups/LookupHelper.php b/app/Library/Lookups/LookupHelper.php index 4606e13..57fc39b 100644 --- a/app/Library/Lookups/LookupHelper.php +++ b/app/Library/Lookups/LookupHelper.php @@ -19,6 +19,7 @@ use App\Models\Lookups\CharacterLookup; use App\Models\Lookups\CorporationLookup; use App\Models\Lookups\AllianceLookup; use App\Models\Lookups\SolarSystem; +use App\Models\Lookups\Station; class LookupHelper { //Variables @@ -703,6 +704,86 @@ class LookupHelper { return 'N/A'; } } + + public function GetStationDetails($stationId) { + //Check if the station is stored in the database + $station = $this->LookupStation($stationId, null); + + //If the station is null, then we didn't find it, and we run the esi to find it. + if($station != null) { + return $station; + } else { + try { + $station = $this->esi->invoke('get', '/universe/stations/{station_id}/', [ + 'station_id' => $stationId, + ]); + } catch(RequestFailedException $e) { + Log::warning('Failed to get station details from /universe/stations/{station_id}/ in lookup helper.'); + return null; + } + + if(isset($station->type_id)) { + //Store the station details for the lookup table + $this->StoreStationLookup($station); + //Return the details of the station + return $station; + } else { + //If we didn't get any details then return null + return null; + } + + } + } + + private function LookupStation($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 the name + if($id != null) { + $count = StationLookup::where(['station_id' => $id])->count(); + if($count > 0) { + $station = StationLookup::where(['station_id' => $id])->get(); + } else { + return null; + } + } else if( $name != null) { + $count = StationLookup::where(['name' => $name])->count(); + if($coutn > 0) { + $station = StationLookup::whre(['name' => $name])->get(); + } else { + return null; + } + } + + //Return the details of the station if they were found + return $station; + } + + private function SaveStation($response) { + $station = new StationLookup; + $station->max_dockable_ship_volume = $response->max_dockable_ship_volume; + $station->name = $response->name; + $station->office_rental_cost = $response->office_rental_cost; + if(isset($response->owner)) { + $station->owner = $response->owner; + } + $station->position_x = $response->position->x; + $station->position_y = $response->position->y; + $station->position_z = $response->position->z; + if(isset($response->race_id)) { + $station->race_id = $response->race_id; + } + $station->reprocessing_efficiency = $response->reprocessing_efficiency; + $station->reprocessing_stations_take = $response->reprocessing_stations_take; + $station->services = $response->services; + $station->station_id = $response->station_id; + $station->system_id = $response->system_id; + $station->type_id = $response->type_id; + $station->save(); + } } ?> \ No newline at end of file diff --git a/app/Models/Lookups/SolarSystemDistance.php b/app/Models/Lookups/SolarSystemDistance.php index eed6035..24770f1 100644 --- a/app/Models/Lookups/SolarSystemDistance.php +++ b/app/Models/Lookups/SolarSystemDistance.php @@ -1,6 +1,6 @@ bigIncrements('id'); + $table->float('max_dockable_ship_volume'); + $table->string('name'); + $table->float('office_rental_cost'); + $table->bigInteger('owner')->nullable(); + $table->double('position_x'); + $table->double('position_y'); + $table->double('position_z'); + $table->bigInteger('race_id')->nullable(); + $table->float('reprocessing_efficiency'); + $table->float('reprocessing_stations_take'); + $table->string('services'); + $table->bigInteger('station_id'); + $table->bigInteger('system_id'); + $table->bigInteger('type_id'); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('station_lookup'); + } +} diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php index dc02dfb..fce8549 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') && ini_get('apc.enabled') ? $apcuPrefix : null; + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; } /** @@ -377,7 +377,7 @@ class ClassLoader $subPath = $class; while (false !== $lastPos = strrpos($subPath, '\\')) { $subPath = substr($subPath, 0, $lastPos); - $search = $subPath.'\\'; + $search = $subPath . '\\'; if (isset($this->prefixDirsPsr4[$search])) { $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); foreach ($this->prefixDirsPsr4[$search] as $dir) { diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 3257e18..cadc93f 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -8,6 +8,7 @@ $baseDir = dirname($vendorDir); return array( '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', 'App\\Http\\Controllers\\Auth\\LoginController' => $baseDir . '/app/Http/Controllers/Auth/LoginController.php', 'App\\Http\\Controllers\\Controller' => $baseDir . '/app/Http/Controllers/Controller.php', 'App\\Http\\Controllers\\Dashboard\\DashboardController' => $baseDir . '/app/Http/Controllers/Dashboard/DashboardController.php', @@ -26,7 +27,7 @@ return array( 'App\\Library\\Contracts\\ContractHelper' => $baseDir . '/app/Library/Contracts/ContractHelper.php', 'App\\Library\\Esi\\Esi' => $baseDir . '/app/Library/Esi/Esi.php', 'App\\Library\\Hauling\\HaulingHelper' => $baseDir . '/app/Library/Hauling/HaulingHelper.php', - 'App\\Library\\Lookups\\NewLookupHelper' => $baseDir . '/app/Library/Lookups/LookupHelper.php', + 'App\\Library\\Lookups\\LookupHelper' => $baseDir . '/app/Library/Lookups/LookupHelper.php', 'App\\Models\\Admin\\AllowedLogin' => $baseDir . '/app/Models/Admin/AllowedLogin.php', 'App\\Models\\Esi\\EsiScope' => $baseDir . '/app/Models/Esi/EsiScope.php', 'App\\Models\\Esi\\EsiToken' => $baseDir . '/app/Models/Esi/EsiToken.php', @@ -36,6 +37,7 @@ return array( 'App\\Models\\Lookups\\CorporationLookup' => $baseDir . '/app/Models/Lookups/CorporationLookup.php', 'App\\Models\\Lookups\\SolarSystem' => $baseDir . '/app/Models/Lookups/SolarSystem.php', 'App\\Models\\User\\AvailableUserPermission' => $baseDir . '/app/Models/User/AvailableUserPermission.php', + 'App\\Models\\User\\User' => $baseDir . '/app/Models/User/User.php', 'App\\Models\\User\\UserPermission' => $baseDir . '/app/Models/User/UserPermission.php', 'App\\Models\\User\\UserRole' => $baseDir . '/app/Models/User/UserRole.php', 'App\\Providers\\AppServiceProvider' => $baseDir . '/app/Providers/AppServiceProvider.php', @@ -47,7 +49,7 @@ return array( 'App\\Providers\\HorizonServiceProvider' => $baseDir . '/app/Providers/HorizonServiceProvider.php', 'App\\Providers\\RouteServiceProvider' => $baseDir . '/app/Providers/RouteServiceProvider.php', 'App\\SolarSystemDistance' => $baseDir . '/app/Models/Lookups/SolarSystemDistance.php', - 'App\\User' => $baseDir . '/app/Models/User/User.php', + 'App\\Traits\\EveOAuth' => $baseDir . '/app/Traits/EveOAuth.php', 'Barryvdh\\Debugbar\\Console\\ClearCommand' => $vendorDir . '/barryvdh/laravel-debugbar/src/Console/ClearCommand.php', 'Barryvdh\\Debugbar\\Controllers\\AssetController' => $vendorDir . '/barryvdh/laravel-debugbar/src/Controllers/AssetController.php', 'Barryvdh\\Debugbar\\Controllers\\BaseController' => $vendorDir . '/barryvdh/laravel-debugbar/src/Controllers/BaseController.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index bb40f88..f6a821f 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -488,6 +488,7 @@ class ComposerStaticInit33afb8ba5b252c3933eb137784fa7f04 public static $classMap = array ( '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', 'App\\Http\\Controllers\\Auth\\LoginController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/LoginController.php', 'App\\Http\\Controllers\\Controller' => __DIR__ . '/../..' . '/app/Http/Controllers/Controller.php', 'App\\Http\\Controllers\\Dashboard\\DashboardController' => __DIR__ . '/../..' . '/app/Http/Controllers/Dashboard/DashboardController.php', @@ -506,7 +507,7 @@ class ComposerStaticInit33afb8ba5b252c3933eb137784fa7f04 'App\\Library\\Contracts\\ContractHelper' => __DIR__ . '/../..' . '/app/Library/Contracts/ContractHelper.php', 'App\\Library\\Esi\\Esi' => __DIR__ . '/../..' . '/app/Library/Esi/Esi.php', 'App\\Library\\Hauling\\HaulingHelper' => __DIR__ . '/../..' . '/app/Library/Hauling/HaulingHelper.php', - 'App\\Library\\Lookups\\NewLookupHelper' => __DIR__ . '/../..' . '/app/Library/Lookups/LookupHelper.php', + 'App\\Library\\Lookups\\LookupHelper' => __DIR__ . '/../..' . '/app/Library/Lookups/LookupHelper.php', 'App\\Models\\Admin\\AllowedLogin' => __DIR__ . '/../..' . '/app/Models/Admin/AllowedLogin.php', 'App\\Models\\Esi\\EsiScope' => __DIR__ . '/../..' . '/app/Models/Esi/EsiScope.php', 'App\\Models\\Esi\\EsiToken' => __DIR__ . '/../..' . '/app/Models/Esi/EsiToken.php', @@ -516,6 +517,7 @@ class ComposerStaticInit33afb8ba5b252c3933eb137784fa7f04 'App\\Models\\Lookups\\CorporationLookup' => __DIR__ . '/../..' . '/app/Models/Lookups/CorporationLookup.php', 'App\\Models\\Lookups\\SolarSystem' => __DIR__ . '/../..' . '/app/Models/Lookups/SolarSystem.php', 'App\\Models\\User\\AvailableUserPermission' => __DIR__ . '/../..' . '/app/Models/User/AvailableUserPermission.php', + 'App\\Models\\User\\User' => __DIR__ . '/../..' . '/app/Models/User/User.php', 'App\\Models\\User\\UserPermission' => __DIR__ . '/../..' . '/app/Models/User/UserPermission.php', 'App\\Models\\User\\UserRole' => __DIR__ . '/../..' . '/app/Models/User/UserRole.php', 'App\\Providers\\AppServiceProvider' => __DIR__ . '/../..' . '/app/Providers/AppServiceProvider.php', @@ -527,7 +529,7 @@ class ComposerStaticInit33afb8ba5b252c3933eb137784fa7f04 'App\\Providers\\HorizonServiceProvider' => __DIR__ . '/../..' . '/app/Providers/HorizonServiceProvider.php', 'App\\Providers\\RouteServiceProvider' => __DIR__ . '/../..' . '/app/Providers/RouteServiceProvider.php', 'App\\SolarSystemDistance' => __DIR__ . '/../..' . '/app/Models/Lookups/SolarSystemDistance.php', - 'App\\User' => __DIR__ . '/../..' . '/app/Models/User/User.php', + 'App\\Traits\\EveOAuth' => __DIR__ . '/../..' . '/app/Traits/EveOAuth.php', 'Barryvdh\\Debugbar\\Console\\ClearCommand' => __DIR__ . '/..' . '/barryvdh/laravel-debugbar/src/Console/ClearCommand.php', 'Barryvdh\\Debugbar\\Controllers\\AssetController' => __DIR__ . '/..' . '/barryvdh/laravel-debugbar/src/Controllers/AssetController.php', 'Barryvdh\\Debugbar\\Controllers\\BaseController' => __DIR__ . '/..' . '/barryvdh/laravel-debugbar/src/Controllers/BaseController.php',