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();
|
$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) {
|
public function SystemNameToId($system) {
|
||||||
//Check if the solar system is stored in our own database first
|
//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) {
|
private function LookupSolarSystem($system) {
|
||||||
$solar = SolarSystem::where([
|
$solar = SolarSystem::where([
|
||||||
'name' => $system,
|
'name' => $system,
|
||||||
@@ -141,10 +170,22 @@ class LookupHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function StoreSolarSystem($system) {
|
private function StoreSolarSystem($system) {
|
||||||
$solar = new SolarSystem;
|
if(isset($system->id)) {
|
||||||
$solar->name = $system->name;
|
SolarSystem::insertOrIgnore([
|
||||||
$solar->solar_system_id = $system->id;
|
'name' => $system->name,
|
||||||
$solar->save();
|
'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) {
|
public function GetCharacterInfo($charId) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use Log;
|
|||||||
use App\Jobs\Library\JobHelper;
|
use App\Jobs\Library\JobHelper;
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
use App\Library\Esi\Esi;
|
use App\Library\Esi\Esi;
|
||||||
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
|
||||||
//App Models
|
//App Models
|
||||||
use App\Models\Jobs\JobProcessStructure;
|
use App\Models\Jobs\JobProcessStructure;
|
||||||
@@ -50,8 +51,6 @@ class StructureHelper {
|
|||||||
$this->esi = $esiHelper->SetupEsiAuthentication($token);
|
$this->esi = $esiHelper->SetupEsiAuthentication($token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Try to get the ESI data
|
//Try to get the ESI data
|
||||||
try {
|
try {
|
||||||
$structures = $this->esi->page($page)
|
$structures = $this->esi->page($page)
|
||||||
@@ -90,6 +89,7 @@ class StructureHelper {
|
|||||||
private function GetSolarSystemName($systemId) {
|
private function GetSolarSystemName($systemId) {
|
||||||
//Declare some variables
|
//Declare some variables
|
||||||
$esiHelper = new Esi;
|
$esiHelper = new Esi;
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
|
||||||
if($this->esi == null) {
|
if($this->esi == null) {
|
||||||
//Get the refresh token
|
//Get the refresh token
|
||||||
@@ -97,19 +97,11 @@ class StructureHelper {
|
|||||||
//Setup the esi authentication container
|
//Setup the esi authentication container
|
||||||
$this->esi = $esiHelper->SetupEsiAuthentication($token);
|
$this->esi = $esiHelper->SetupEsiAuthentication($token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Attempt to get the solar system name from ESI
|
$solar = $lookup->SystemIdToName($systemId);
|
||||||
try {
|
|
||||||
$solar = $this->esi->invoke('get', '/universe/systems/{system_id}/', [
|
|
||||||
'system_id' => $systemId,
|
|
||||||
]);
|
|
||||||
} catch(RequestFailedException $e) {
|
|
||||||
$solar = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($solar != null) {
|
if($solar != null) {
|
||||||
return $solar->name;
|
return $solar;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user