updated solar system name functions in structure helper. added new functions to lookup helper.

This commit is contained in:
2020-05-10 17:04:08 -05:00
parent b01bb72c1d
commit 16f808ae53
2 changed files with 49 additions and 16 deletions

View File

@@ -105,6 +105,27 @@ class LookupHelper {
$newItem->save();
}
public function SystemIdToName($systemId) {
//Check if the solar system is stored in our database first
$solarSystem = $this->LookupSolarSystemId($systemId);
if($solarSystem != null) {
return $solarSystem->name;
} else {
try {
$solar = $this->esi->invoke('get', '/universe/systems/{system_id}/', [
'system_id' => $systemId,
]);
} catch(RequestFailedException $e) {
Log::warning('Failed to get system id from /universe/systems in Lookup Helper.');
return null;
}
$this->StoreSolarSystem($solar);
return $solar->name;
}
}
public function SystemNameToId($system) {
//Check if the solar system is stored in our own database first
@@ -132,6 +153,14 @@ class LookupHelper {
}
}
private function LookupSolarSystemId($systemId) {
$solar = SolarSystem::where([
'solar_system_id' => $systemId,
])->first();
return $solar;
}
private function LookupSolarSystem($system) {
$solar = SolarSystem::where([
'name' => $system,
@@ -141,10 +170,22 @@ class LookupHelper {
}
private function StoreSolarSystem($system) {
$solar = new SolarSystem;
$solar->name = $system->name;
$solar->solar_system_id = $system->id;
$solar->save();
if(isset($system->id)) {
SolarSystem::insertOrIgnore([
'name' => $system->name,
'solar_system_id' => $system->id,
]);
} else if(isset($system->system_id)) {
SolarSystem::insertOrIgnore([
'name' => $system->name,
'solar_system_id' => $system->system_id,
]);
} else {
$solar = new SolarSystem;
$solar->name = $system->name;
$solar->solar_system_id = $system->id;
$solar->save();
}
}
public function GetCharacterInfo($charId) {

View File

@@ -16,6 +16,7 @@ use Log;
use App\Jobs\Library\JobHelper;
use Seat\Eseye\Exceptions\RequestFailedException;
use App\Library\Esi\Esi;
use App\Library\Lookups\LookupHelper;
//App Models
use App\Models\Jobs\JobProcessStructure;
@@ -50,8 +51,6 @@ class StructureHelper {
$this->esi = $esiHelper->SetupEsiAuthentication($token);
}
//Try to get the ESI data
try {
$structures = $this->esi->page($page)
@@ -90,6 +89,7 @@ class StructureHelper {
private function GetSolarSystemName($systemId) {
//Declare some variables
$esiHelper = new Esi;
$lookup = new LookupHelper;
if($this->esi == null) {
//Get the refresh token
@@ -97,19 +97,11 @@ class StructureHelper {
//Setup the esi authentication container
$this->esi = $esiHelper->SetupEsiAuthentication($token);
}
//Attempt to get the solar system name from ESI
try {
$solar = $this->esi->invoke('get', '/universe/systems/{system_id}/', [
'system_id' => $systemId,
]);
} catch(RequestFailedException $e) {
$solar = null;
}
$solar = $lookup->SystemIdToName($systemId);
if($solar != null) {
return $solar->name;
return $solar;
} else {
return null;
}