modified the way characters are looked up in the database versus esi

This commit is contained in:
2019-12-11 23:44:24 -06:00
parent e6173a7f17
commit 21a85add82
5 changed files with 72 additions and 17 deletions

View File

@@ -231,7 +231,7 @@ class ContractController extends Controller
$characterId = auth()->user()->getId();
$characterName = auth()->user()->getName();
//Use the lookup helper in order to find the user's corporation id and name
$char = $looup->LookupCharacter($characterId, null);
$char = $lookup->GetCharacterInfo($characterId);
$corporationId = $char->corporation_id;
//use the lookup helper in order to find the corporation's name from it's id.
$corp = $lookup->LookupCorporation($corporationId, null);

View File

@@ -257,7 +257,7 @@ class MoonsAdminController extends Controller
}
//Let's find the corporation and alliance information to ascertain whethery they are in Warped Intentions or another Legacy Alliance
$char = $lookup->LookupCharacter($contact, null);
$char = $lookup->GetCharacterInfo($contact);
$corp = $lookup->LookupCorporation($char->character_id, null);
$allianceId = $corp->alliance_id;

View File

@@ -49,7 +49,7 @@ class WikiController extends Controller
$charId = $charIdTemp[0]->character_id;
//Set the corp id
$char = $lookup->LookupCharacter($charId, null);
$char = $lookup->GetCharacterInfo($charId);
$corpId = $char->corporation_id;
//Set the alliance id

View File

@@ -62,7 +62,8 @@ class FinanceHelper {
}
//Reference to see if the character is in our look up table for corporations and characters
$corpId = $lookup->LookupCharacter($charId, null);
$char = $lookup->GetCharacterInfo($charId);
$corpId = $char->corporation_id;
//Create an ESI authentication container
$esi = $esiHelper->SetupEsiAuthentication($token);
@@ -136,7 +137,8 @@ class FinanceHelper {
}
//Refrence to see if the character is in our look up table for corporation and characters
$corpId = $lookup->LookupCharacter($charId, null);
$char = $lookup->GetCharacterInfo($charId);
$corpId = $char->corporation_id;
//Create the ESI authentication container
$esi = $esiHelper->SetupEsiAuthentication($token);
@@ -221,7 +223,8 @@ class FinanceHelper {
}
//Reference to see if the character is in our look up table for corporations and characters
$char = $lookup->LookupCharacter($charId, null);
$char = $lookup->GetCharacterInfo($charId);
$corpId = $char->corporation_id;
//Create an ESI authentication container

View File

@@ -147,15 +147,67 @@ class LookupHelper {
}
public function GetCharacterInfo($charId) {
try {
$character = $this->esi->invoke('get', '/characters/{character_id}/', [
'character_id' => $charId,
]);
} catch(RequestFailedException $e) {
return null;
}
//Check our own database first
$char = $this->LookupCharacter($charId, null);
return $character;
//if the character was not found in the database, then get the information and store it in our database for later
if($char == null) {
try {
$character = $this->esi->invoke('get', '/characters/{character_id}/', [
'character_id' => $charId,
]);
} catch(RequestFailedException $e) {
Log::warning('Failed to get character information in GetCharacterInfo in Lookup');
return null;
}
//Store the character in our database
$this->SaveCharacter($character, $charId);
//Return the character details to the calling function
return $character;
} else {
//Return what was pulled from the database
return $char;
}
}
public function GetCorporationInfo($corpId) {
//Check our own database first
$corp = $this->LookupCorporation($corpId, null);
//If the corporation was not found in the database, then get the information and store it in our database for later
if($corp == null) {
try {
$corporation = $this->esi->invoke('get', '/corporations/{corporation_id}/', [
'corporation_id' => $corpId,
]);
} catch(RequestFailedException $e) {
Log::warning('Failed to get corporation information in GetCorporationInfo in Lookup');
return null;
}
} else {
//Return what was pulled from the database
return $corp;
}
}
public function GetAllianceInfo($allianceId) {
//Check our own database first
$ally = $this->LookupAlliance($corpId, null);
if($ally == null) {
try {
$alliance = $this->esi->invoke('get', '/alliances/{alliance_id}/', [
'alliance_id' => $allianceId,
]);
} catch(RequestFailedException $e) {
Log::warning('Failed to get alliance information in GetAllianceInfo in Lookup');
return null;
}
} else {
return $ally;
}
}
public function CharacterIdToName($charId) {
@@ -321,7 +373,7 @@ class LookupHelper {
}
}
public function LookupCharacter($id = null, $name = null) {
private 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;
@@ -351,7 +403,7 @@ class LookupHelper {
return $character;
}
public function LookupCorporation($id = null, $name = null) {
private function LookupCorporation($id = null, $name = null) {
if($id == null && $name == null) {
return null;
}
@@ -378,7 +430,7 @@ class LookupHelper {
return $corporation;
}
public function LookupAlliance($id = null, $name = null) {
private function LookupAlliance($id = null, $name = null) {
if($id == null && $name == null) {
return null;
}