diff --git a/app/Library/Lookups/NewLookupHelper.php b/app/Library/Lookups/NewLookupHelper.php index 06a116f1a..1655d733b 100644 --- a/app/Library/Lookups/NewLookupHelper.php +++ b/app/Library/Lookups/NewLookupHelper.php @@ -16,6 +16,9 @@ use Seat\Eseye\Exceptions\RequestFailedException; //Models use App\Models\Lookups\CharacterToCorporation; use App\Models\Lookups\CorporationToAlliance; +use App\Models\Lookups\CharacterLookup; +use App\Models\Lookups\CorporationLookup; +use App\Models\Lookups\AllianceLookup; class NewLookupHelper { @@ -27,8 +30,290 @@ class NewLookupHelper { $this->esi = new Eseye(); } + public function GetCharacterInfo($charId) { + try { + $character = $this->esi->invoke('get', '/characters/{character_id}/', [ + 'character_id' => $charId, + ]); + } catch(RequestFailedException $e) { + return null; + } + return $character; + } + public function CharacterIdToName($charId) { + //Check if the character is stored in our own database first + $char = $this->LookupCharacter($charId, null); + //If the char is null, then we did not find the character in our own database + if($char != null) { + return $char->name; + } else { + //Get the character id from esi + try { + $character = $this->esi->invoke('get', '/characters/{character_id}/', [ + 'character_id' => $charId, + ]); + } catch(RequestFailedException $e) { + Log::warning('Failed to get character name from /characters/{character_id}/ in lookup helper.'); + return null; + } + + if(isset($character->name)) { + //Store the character name for the lookup table + $this->StoreCharacterLookup(null, $character->name); + //Return the character name to the calling function + return $character->name; + } else { + //If we don't find any information return null + return null; + } + } + } + + public function CharacterNameToId($charName) { + //Check if the character is stored in our own database first + $char = $this->LookupCharacter(null, $charName); + if($char != null) { + return $char->character_id; + } else { + try { + $response = $this->esi->setBody(array( + $charName, + ))->invoke('post', '/universe/ids/'); + } catch(RequestFailedException $e) { + Log::warning('Failed to get character name from /universe/ids/ in lookup helper.'); + return null; + } + + if(isset($response->characters[0]->id)) { + $this->StoreCharacterLookup($response->characters[0]->id, null); + + return $response->characters[0]->id; + } else { + return -1; + } + } + } + + public function CorporationIdToName($corpId) { + //Check if the corporation is stored in our own database first + $corp = $this->LookupCorporation($corpId, null); + if($corp != null) { + return $corp->name; + } else { + //Try to get the corporation details from ESI + try { + $corporation = $this->esi->invoke('get', '/corporations/{corporation_id}/', [ + 'corporation_id' => $corpId, + ]); + } catch(RequestFailedException $e) { + //Log the issue + Log::warning('Failed to get corporation name from /corporations/{corporation_id}/ in lookup helper.'); + return null; + } + + if(isset($corporation->name)) { + //Store the corporation name for the lookup table + $this->StoreCorporationLookup(null, $corporation->name); + //Return the corporation name to the calling function + return $corporation->name; + } else { + //If nothing is found and ESI didn't work, return null to the calling function + return null; + } + } + } + + public function CorporationNameToId($corpName) { + //Check if the corporation is stored in our own database first + $corp = $this->LookupCorporation(null, $corpName); + if($corp != null) { + return $corp->corporation_id; + } else { + //Try to get the corporation details from ESI + try { + $corporation = $this->esi->setBody(array( + $corpName, + ))->invoke('post', '/universe/ids/'); + } catch(RequestFailedException $e) { + Log::warning('Failed to get the corporation id from /universe/ids/ in lookup helper.'); + return null; + } + + if(isset($response->corporations[0]->id)) { + $this->StoreCorporationLookup($response->corporations[0]->id, null); + + return $response->corporations[0]->id; + } else { + return -1; + } + } + } + + public function AllianceIdToName($allianceId) { + //Check if the alliance is stored in our own database first + $alliance = $this->LookupAlliance($allianceId, null); + if($alliance != null) { + return $alliance->alliance_id; + } else { + //Try to get the alliance details from ESI + try { + $alliance = $this->esi->invoke('get', '/alliances/{alliance_id}/', [ + 'alliance_id' => $allianceId, + ]); + } catch(RequestFailedException $e) { + Log::warning('Failed to get the alliance name from /alliances/{alliance_id}/ in lookup helper.'); + return null; + } + + if(isset($alliance->name)) { + $this->StoreAllianceLookup(null, $alliance->name); + + return $alliance->name; + } else { + return null; + } + } + } + + public function AllianceNameToId($allianceName) { + //Check if the alliance is stored in our own database first + $alliance = $this->LookupAlliance(null, $allianceName); + if($alliance != null) { + return $alliance->name; + } else { + //Try to get the alliance details from ESI + try { + $response = $this->esi->setBody(array( + $allianceName, + ))->invoke('post', '/universe/ids/'); + } catch(RequestFailedException $e) { + Log::warning('Failed to get the alliance id from /universe/ids/ in lookup helper.'); + return null; + } + + //If the data is pulled from ESI store the data, and send the data back to the calling function + if(isset($response->alliances[0]->id)) { + $this->StoreAllianceLookup($response->alliances[0]->id, null); + + return $response->alliances[0]->id; + } else { + return -1; + } + } + } + + public function LookupCharacter($id = null, $name = null) { + //If both the id and name are null, then there is nothing to lookup + if($id == null & $name == null) { + return null; + } + + $character = null; + + //If the id is null attempt to lookup the character + if($id != null) { + $count = CharacterLookup::where(['character_id' => $id])->count(); + if($count > 0) { + $character = CharacterLookup::where(['character_id' => $id])->first(); + } else { + $character = null; + } + } else if($name != null) { + //If the name is not null then attemp to lookup the character + $count = CharacterLookup::where(['name' => $name])->count(); + if($count > 0) { + $character = CharacterLookup::where(['name' => $name])->first(); + } else { + $character = null; + } + } + + //Return the character details to the calling function + return $character; + } + + public function LookupCorporation($id = null, $name = null) { + if($id == null && $name == null) { + return null; + } + + $corporation = null; + + //If the id is not null attempt to lookup the character + if($id != null) { + $count = CorporationLookup::where(['corporation_id' => $id])->count(); + if($count > 0) { + $corporation = CorporationLookup::where(['corporation_id' => $id])->first(); + } else { + $corporation = null; + } + } else if($name != null) { + $count = CorporationLookup::where(['name' => $name])->count(); + if($count > 0) { + $corporation = CorporationLookup::where(['name' => $name])->count(); + } else { + $corporation = null; + } + } + + return $corporation; + } + + public function LookupAlliance($id = null, $name = null) { + if($id == null && $name == null) { + return null; + } + + $alliance = null; + + if($id != null) { + $count = AllianceLookup::where(['alliance_id' => $id])->count(); + if($count > 0) { + $alliance = AllianceLookup::where(['alliance_id' => $id])->first(); + } else { + $alliance = null; + } + } else if($name != null) { + $count = AllianceLookup::where(['name' => $name])->count(); + if($count > 0) { + $alliance = AllianceLookup::where(['name' => $name])->first(); + } else { + $alliance = null; + } + } + + return $alliance; + } + + private function StoreCharacterLookup($id = null, $name = null) { + if($id == null && $name == null) { + return null; + } + + + } + + private function UpdateCharacter($id = null, $name = null) { + + } + + private function StoreCorporationLookup($id = null, $name = null) { + + } + + private function UpdateCorporation($id = null, $name = null) { + + } + + private function StoreAllianceLookup($id = null, $name = null) { + + } + + private function UpdateAlliance($id = null, $name = null) { + + } } ?> \ No newline at end of file diff --git a/app/Models/Lookups/AllianceLookup.php b/app/Models/Lookups/AllianceLookup.php new file mode 100644 index 000000000..e1df3ab64 --- /dev/null +++ b/app/Models/Lookups/AllianceLookup.php @@ -0,0 +1,30 @@ +unsignedInteger('character_id'); + $table->unsignedInteger('alliance_id'); + $table->unsignedInteger('ancestry_id')->nullable(); + $table->string('birthday'); + $table->unsignedInteger('bloodline_id'); + $table->unsignedInteger('corporation_id'); + $table->string('description')->nullable(); + $table->unsignedInteger('faction_id')->nullable(); + $table->string('gender'); + $table->string('name'); + $table->unsignedInteger('race_id'); + $table->float('security_status'); + $table->string('title'); + }); + } + + if(!Schema::hasTable('corporation_lookup')) { + Schema::create('corporation_lookup', function (Blueprint $table) { + $table->unsignedInteger('corporation_id'); + $table->unsignedInteger('alliance_id')->nullable(); + $table->unsignedInteger('ceo_id'); + $table->unsignedInteger('creator_id'); + $table->string('date_founded')->nullable(); + $table->string('description')->nullable(); + $table->unsignedInteger('faction_id')->nullable(); + $table->unsignedInteger('home_station_id')->nullable(); + $table->unsignedInteger('member_count'); + $table->string('name'); + $table->unsignedInteger('shares')->nullable(); + $table->decimal('tax_rate', 20, 2); + $table->string('ticker'); + $table->string('url')->nullable(); + $table->boolean('war_eligible'); + }); + } + + if(!Schema::hasTable('alliance_lookup')) { + Schema::create('alliance_lookup', function (Blueprint $table) { + $table->unsignedInteger('alliance_id'); + $table->unsignedInteger('creator_corporation_id'); + $table->unsignedInteger('creator_id'); + $table->dateTime('date_founded'); + $table->unsignedInteger('executor_corporation_id')->nullable(); + $table->unsignedInteger('faction_id')->nullable(); + $table->string('name'); + $table->string('ticker'); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('character_lookup'); + Schema::dropIfExists('corporation_lookup'); + Schema::dropIfExists('alliance_lookup'); + } +} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 7bb1c8b0c..949bf8354 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -6,6 +6,8 @@ $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( + 'App\\AllianceLookup' => $baseDir . '/app/Models/Lookups/AllianceLookup.php', + 'App\\CharacterLookup' => $baseDir . '/app/Models/Lookups/CharacterLookup.php', 'App\\Charts\\StructureFuelGauge' => $baseDir . '/app/Charts/StructureFuelGauge.php', 'App\\Console\\Commands\\CleanStaleDataCommand' => $baseDir . '/app/Console/Commands/Data/CleanStaleDataCommand.php', 'App\\Console\\Commands\\CorpFinances' => $baseDir . '/app/Console/Commands/Finances/CorpFinances.php', @@ -21,6 +23,7 @@ return array( 'App\\Console\\Commands\\UpdateMoonRental' => $baseDir . '/app/Console/Commands/Moons/UpdateMoonRental.php', 'App\\Console\\Kernel' => $baseDir . '/app/Console/Kernel.php', 'App\\CorpMarketStructure' => $baseDir . '/app/Models/Finances/CorpMarketStructure.php', + 'App\\CorporationLookup' => $baseDir . '/app/Models/Lookups/CorporationLookup.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', @@ -74,6 +77,7 @@ return array( 'App\\Library\\Finances\\ReprocessingTax' => $baseDir . '/app/Library/Finances/ReprocessingTax.php', 'App\\Library\\Finances\\StructureIndustryTax' => $baseDir . '/app/Library/Finances/StructureIndustryTax.php', 'App\\Library\\Lookups\\LookupHelper' => $baseDir . '/app/Library/Lookups/LookupHelper.php', + 'App\\Library\\Lookups\\NewLookupHelper' => $baseDir . '/app/Library/Lookups/NewLookupHelper.php', 'App\\Library\\Moons\\MoonCalc' => $baseDir . '/app/Library/Moons/MoonCalc.php', 'App\\Library\\SRP\\SRPHelper' => $baseDir . '/app/Library/SRP/SRPHelper.php', 'App\\Library\\Structures\\StructureHelper' => $baseDir . '/app/Library/Structures/StructureHelper.php', @@ -136,6 +140,8 @@ return array( 'App\\Models\\User\\UserAlt' => $baseDir . '/app/Models/User/UserAlt.php', 'App\\Models\\User\\UserPermission' => $baseDir . '/app/Models/User/UserPermission.php', 'App\\Models\\User\\UserRole' => $baseDir . '/app/Models/User/UserRole.php', + 'App\\Models\\Wormholes\\AllianceWormhole' => $baseDir . '/app/Models/Wormholes/AllianceWormhole.php', + 'App\\Models\\Wormholes\\WormholeType' => $baseDir . '/app/Models/Wormholes/WormholeType.php', 'App\\Providers\\AppServiceProvider' => $baseDir . '/app/Providers/AppServiceProvider.php', 'App\\Providers\\AuthServiceProvider' => $baseDir . '/app/Providers/AuthServiceProvider.php', 'App\\Providers\\BroadcastServiceProvider' => $baseDir . '/app/Providers/BroadcastServiceProvider.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 664f902d2..1f82f8fcf 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -469,6 +469,8 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 ); public static $classMap = array ( + 'App\\AllianceLookup' => __DIR__ . '/../..' . '/app/Models/Lookups/AllianceLookup.php', + 'App\\CharacterLookup' => __DIR__ . '/../..' . '/app/Models/Lookups/CharacterLookup.php', 'App\\Charts\\StructureFuelGauge' => __DIR__ . '/../..' . '/app/Charts/StructureFuelGauge.php', 'App\\Console\\Commands\\CleanStaleDataCommand' => __DIR__ . '/../..' . '/app/Console/Commands/Data/CleanStaleDataCommand.php', 'App\\Console\\Commands\\CorpFinances' => __DIR__ . '/../..' . '/app/Console/Commands/Finances/CorpFinances.php', @@ -484,6 +486,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Console\\Commands\\UpdateMoonRental' => __DIR__ . '/../..' . '/app/Console/Commands/Moons/UpdateMoonRental.php', 'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.php', 'App\\CorpMarketStructure' => __DIR__ . '/../..' . '/app/Models/Finances/CorpMarketStructure.php', + 'App\\CorporationLookup' => __DIR__ . '/../..' . '/app/Models/Lookups/CorporationLookup.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', @@ -537,6 +540,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Library\\Finances\\ReprocessingTax' => __DIR__ . '/../..' . '/app/Library/Finances/ReprocessingTax.php', 'App\\Library\\Finances\\StructureIndustryTax' => __DIR__ . '/../..' . '/app/Library/Finances/StructureIndustryTax.php', 'App\\Library\\Lookups\\LookupHelper' => __DIR__ . '/../..' . '/app/Library/Lookups/LookupHelper.php', + 'App\\Library\\Lookups\\NewLookupHelper' => __DIR__ . '/../..' . '/app/Library/Lookups/NewLookupHelper.php', 'App\\Library\\Moons\\MoonCalc' => __DIR__ . '/../..' . '/app/Library/Moons/MoonCalc.php', 'App\\Library\\SRP\\SRPHelper' => __DIR__ . '/../..' . '/app/Library/SRP/SRPHelper.php', 'App\\Library\\Structures\\StructureHelper' => __DIR__ . '/../..' . '/app/Library/Structures/StructureHelper.php', @@ -599,6 +603,8 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Models\\User\\UserAlt' => __DIR__ . '/../..' . '/app/Models/User/UserAlt.php', 'App\\Models\\User\\UserPermission' => __DIR__ . '/../..' . '/app/Models/User/UserPermission.php', 'App\\Models\\User\\UserRole' => __DIR__ . '/../..' . '/app/Models/User/UserRole.php', + 'App\\Models\\Wormholes\\AllianceWormhole' => __DIR__ . '/../..' . '/app/Models/Wormholes/AllianceWormhole.php', + 'App\\Models\\Wormholes\\WormholeType' => __DIR__ . '/../..' . '/app/Models/Wormholes/WormholeType.php', 'App\\Providers\\AppServiceProvider' => __DIR__ . '/../..' . '/app/Providers/AppServiceProvider.php', 'App\\Providers\\AuthServiceProvider' => __DIR__ . '/../..' . '/app/Providers/AuthServiceProvider.php', 'App\\Providers\\BroadcastServiceProvider' => __DIR__ . '/../..' . '/app/Providers/BroadcastServiceProvider.php',