updated solar system name functions in structure helper. added new functions to lookup helper.
This commit is contained in:
@@ -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,11 +170,23 @@ class LookupHelper {
|
||||
}
|
||||
|
||||
private function StoreSolarSystem($system) {
|
||||
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) {
|
||||
//Check our own database first
|
||||
|
||||
@@ -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
|
||||
@@ -98,18 +98,10 @@ class StructureHelper {
|
||||
$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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user