updated some mining ledger functions, and removed duplicate functionality

This commit is contained in:
2021-01-24 21:15:46 +09:00
parent 314dd1c931
commit 416f4abd03
5 changed files with 113 additions and 168 deletions
+12 -42
View File
@@ -64,37 +64,25 @@ class AssetHelper {
* Store a new asset record in the database
*/
public function StoreNewAsset($asset) {
//See if we find any assets which already exist
$found = Asset::where([
Asset::updateOrCreate([
'item_id' => $asset->item_id,
])->count();
//If nothing is found
if($found == 0) {
$item = new Asset;
if(isset($asset->is_blueprint_copy)) {
$item->is_blueprint_copy = $asset->is_blueprint_copy;
}
$item->is_singleton = $asset->is_singleton;
$item->item_id = $asset->item_id;
$item->location_flag = $asset->location_flag;
$item->location_id = $asset->location_id;
$item->location_type = $asset->location_type;
$item->quantity = $asset->quantity;
$item->type_id = $asset->type_id;
$item->save();
} else {
$this->UpdateAsset($asset);
}
], [
'is_blueprint_copy' => $asset->is_blueprint_copy,
'is_singleton' => $asset->is_singleton,
'item_id' => $asset->item_id,
'location_flag' => $asset->location_flag,
'location_id' => $asset->location_id,
'location_type' => $asset->location_type,
'quantity' => $asset->quantity,
'type_id' => $asset->type_id,
]);
}
/**
* Purge old data, so we don't run into data issues
*/
public function PurgeStaleData() {
$date = Carbon::now()->subDay(1);
Asset::where('updated_at', '<', $date)->delete();
Asset::where('updated_at', '<', Carbon::now()->subDay())->delete();
}
/**
@@ -120,24 +108,6 @@ class AssetHelper {
return $asset['quantity'];
}
}
/**
* Update an existing asset based off the esi pull
*/
private function UpdateAsset($asset) {
Asset::where([
'item_id' => $asset->item_id,
])->update([
'is_singleton' => $asset->is_singleton,
'location_flag' => $asset->location_flag,
'location_id' => $asset->location_id,
'location_type' => $asset->location_type,
'quantity' => $asset->quantity,
'type_id' => $asset->type_id,
'updated_at' => Carbon::now(),
]);
}
}
?>
-67
View File
@@ -78,73 +78,6 @@ class Esi {
return $corporation;
}
public function GetCharacterName($charId) {
$esi = $this->SetupEsiAuthentication;
try {
$character = $esi->invoke('get', '/characters/{character_id}/', [
'character_id' => $charId,
]);
} catch(RequestFailedException $e) {
return null;
}
return $character->name;
}
public function FindCharacterId($name) {
$config = config('esi');
$esi = $this->SetupEsiAuthentication();
try {
$character = $esi->setBody(array(
$name,
))->invoke('post', '/universe/ids/');
} catch(RequestFailedException $e) {
return null;
}
if(isset($character->characters[0]->id)) {
return $character->characters[0]->id;
} else {
return null;
}
}
public function FindCorporationId($charId) {
$esi = $this->SetupEsiAuthentication();
try {
$character = $esi->invoke('get', '/characters/{character_id}/', [
'character_id' => $charId,
]);
} catch(RequestFailedException $e) {
return null;
}
return $character->corporation_id;
}
public function FindCorporationName($charId) {
$esi = $this->SetupEsiAuthentication();
try {
$character = $esi->invoke('get', '/characters/{character_id}/', [
'character_id' => $charId,
]);
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
'corporation_id' => $character->corporation_id,
]);
} catch(RequestFailedException $e) {
return null;
}
return $corporation->name;
}
public function DecodeDate($date) {
//Find the end of the date
$dateEnd = strpos($date, "T");
+3 -56
View File
@@ -80,6 +80,7 @@ class MiningLedgerHelper {
public function GetMiningStructureInfo($observerId) {
//Declare variables
$esiHelper = new Esi;
$lookup = new LookupHelper;
//Check for ESI scopes
if(!$esiHelper->HaveEsiScope($this->charId, 'esi-universe.read_structures.v1')) {
@@ -98,7 +99,7 @@ class MiningLedgerHelper {
return null;
}
$system = $this->GetSolarSystemName($info->solar_system_id);
$system = $lookup->SystemIdToName($info->solar_system_id);
return [
'name' => $info->name,
@@ -161,7 +162,7 @@ class MiningLedgerHelper {
//Sort through the array and replace character id with name and item id with name
foreach($items as $item) {
$charName = $lookup->CharacterIdToName($item->character_id);
$typeName = $this->GetItemName($item->type_id);
$typeName = $lookup->ItemIdToName($item->type_id);
$corpName = $lookup->CorporationIdToName($item->recorded_corporation_id);
if(isset($final[$charName])) {
@@ -183,59 +184,5 @@ class MiningLedgerHelper {
return $final;
}
/**
* Get the type id and return the name of the ore
*
* @var typeId
* @return string
*/
private function GetItemName($typeId) {
//Setup the esi helper variable
$esiHelper = new Esi;
//Setup the authentication container for ESI
$esi = $esiHelper->SetupEsiAuthentication();
try {
$item = $esi->invoke('get', '/universe/types/{type_id}/', [
'type_id' => $typeId,
]);
} catch(RequestFailedException $e) {
return null;
}
return $item->name;
}
/**
* Get the solar system name
*
* @var systemId
* @return string
*/
private function GetSolarSystemName($systemId) {
//Setup the esi helper variable
$esiHelper = new Esi;
//Setup the authentication container for ESI
$esi = $esiHelper->SetupEsiAuthentication();
//Attempt to get the solar system name from ESI
try {
$solar = $esi->invoke('get', '/universe/systems/{system_id}/', [
'system_id' => $systemId,
]);
} catch(RequestFailedException $e) {
$solar = null;
}
if($solar != null) {
return $solar->name;
} else {
return null;
}
}
}
?>