mining ledger helper
This commit is contained in:
@@ -19,6 +19,7 @@ use Seat\Eseye\Containers\EsiAuthentication;
|
||||
use Seat\Eseye\Eseye;
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
use App\Library\Esi\Esi;
|
||||
use App\Library\Lookups\NewLookupHelper;
|
||||
|
||||
//App Models
|
||||
use App\Models\Structure\Structure;
|
||||
@@ -32,11 +33,23 @@ class MiningLedgerHelper {
|
||||
private $charId;
|
||||
private $corpId;
|
||||
|
||||
/**
|
||||
* Constructor function
|
||||
*
|
||||
* @var $charId
|
||||
* @var $corpId
|
||||
*/
|
||||
public function __construct($charId, $corpId) {
|
||||
$this->charId = $charId;
|
||||
$this->corpId = $corpID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the corporation's mining structures.
|
||||
* These structures consist of Athanors and Tataras
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetCorpMiningStructures() {
|
||||
//Declare variables
|
||||
$esiHelper = new Esi;
|
||||
@@ -64,6 +77,11 @@ class MiningLedgerHelper {
|
||||
return $observers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mining struture information
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetMiningStructureInfo($observerId) {
|
||||
//Declare variables
|
||||
$esiHelper = new Esi;
|
||||
@@ -93,6 +111,12 @@ class MiningLedgerHelper {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mining ledger for a particular structure
|
||||
*
|
||||
* @var observerId
|
||||
* @return array
|
||||
*/
|
||||
public function GetMiningLedger($observerId) {
|
||||
//Declare variables
|
||||
$esiHelper = new Esi;
|
||||
@@ -118,6 +142,92 @@ class MiningLedgerHelper {
|
||||
return $ledger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the mining ledger into something more readable for humans
|
||||
*
|
||||
* @var array
|
||||
* @return array
|
||||
*/
|
||||
public function ProcessMiningLedger($ledger, $date) {
|
||||
//Declare some variables
|
||||
$items = array();
|
||||
$notSorted = array();
|
||||
$final = array();
|
||||
$lookup = new NewLookupHelper;
|
||||
|
||||
|
||||
//In the first iteration of the array get rid of the extra items we don't want
|
||||
foreach($ledger as $ledg) {
|
||||
if($ledg->last_updated == $date) {
|
||||
array_push($items, $ledg);
|
||||
}
|
||||
}
|
||||
|
||||
//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);
|
||||
$corpName = $lookup->CorporationIdToName($item->recorded_corporation_id);
|
||||
|
||||
if(isset($final[$charName])) {
|
||||
$final[$charName] = [
|
||||
'ore' => $typeName,
|
||||
'quantity' => $item->quantity,
|
||||
'date' => $item->last_updated,
|
||||
];
|
||||
} else {
|
||||
$temp = [
|
||||
'ore' => $typeName,
|
||||
'quantity' => $item->quantity,
|
||||
'date' => $item->last_updated,
|
||||
];
|
||||
|
||||
array_push($final[$charName], $temp);
|
||||
}
|
||||
|
||||
return $final;
|
||||
}
|
||||
|
||||
/**
|
||||
* final[] = [
|
||||
* 'character' = [
|
||||
* 'item_name',
|
||||
* 'quantity',
|
||||
* ],
|
||||
* ];
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
Reference in New Issue
Block a user