diff --git a/app/Http/Controllers/Moons/MoonLedgerController.php b/app/Http/Controllers/Moons/MoonLedgerController.php new file mode 100644 index 000000000..b2a4e063b --- /dev/null +++ b/app/Http/Controllers/Moons/MoonLedgerController.php @@ -0,0 +1,55 @@ +middleware('auth'); + $this->middleware('role:User'); + $this->middleware('permission:corp.lead'); + } + + public function displaySelection() { + //Declare variables + $structures = array(); + + + + return view('moons.ledger.displayselect')->with('structures', $structures); + } + + public function displayLedger(Request $request) { + //Validate the request + $this->validate($request, [ + 'id' => 'required', + ]); + + //Declare variables + $esiHelper = new Esi; + + //Create the authentication container for ESI, and check for the correct scopes + $config = config('esi'); + } +} diff --git a/app/Library/Esi/Esi.php b/app/Library/Esi/Esi.php index 70a222e19..01acfa854 100644 --- a/app/Library/Esi/Esi.php +++ b/app/Library/Esi/Esi.php @@ -172,6 +172,33 @@ class Esi { return $token->refresh_token; } + + public function SetupEsiAuthentication($token = null) { + //Get the platform configuration + $config = config('esi'); + + //Declare some variables + $authentication = null; + + if($token === null) { + $authentication = new EsiAuthentication([ + 'client_id' => $config['client_id'], + 'secret' => $config['secret'], + ]); + } else { + $authentication = new EsiAuthentication([ + 'client_id' => $config['client_id'], + 'secret' => $config['secret'], + 'refresh_token' => $token, + ]); + } + + //Setup the esi variable + $esi = new Eseye($authentication); + + //Return the created variable + return $esi; + } } ?> \ No newline at end of file diff --git a/app/Library/Moons/MiningLedgerHelper.php b/app/Library/Moons/MiningLedgerHelper.php new file mode 100644 index 000000000..ee52a6385 --- /dev/null +++ b/app/Library/Moons/MiningLedgerHelper.php @@ -0,0 +1,145 @@ +charId = $charId; + $this->corpId = $corpID; + } + + public function GetCorpMiningStructures() { + //Declare variables + $esiHelper = new Esi; + + //Check if the character has the correct ESI Scope. If the character doesn't, then return false, but + //also send a notice eve mail to the user. The HaveEsiScope sends a mail for us. + if(!$esiHelper->HaveEsiScope($this->charId, 'esi-industry.read_corporation_mining.v1')) { + + return null; + } + + //Get the refresh token from the database and setup the esi authenticaiton container + $esi = $esiHelper->SetupEsiAuthentication($esiHelper->GetRefreshToken($this->charId)); + + //Get a list of the mining observers, which are structures + try { + $observers = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/', [ + 'corporation_id' => $this->corpId, + ]); + } catch(RequestFailedException $e) { + Log::warning('Could not find any mining observers for corporation: ' . $this->corpId); + return null; + } + + return $observers; + } + + public function GetMiningStructureInfo($observerId) { + //Declare variables + $esiHelper = new Esi; + + //Check for ESI scopes + if(!$esiHelper->HaveEsiScope($this->charId, 'esi-universe.read_structures.v1')) { + return null; + } + + //Get the refresh token and setup the esi authentication container + $esi = $esiHelper->SetupEsiAuthentication($esiHelper->GetRefreshToken($this->charId)); + + //Try to get the structure information + try { + $info = $esi->invoke('get', '/universe/structures/{struture_id}/', [ + 'structure_id' => $observerId, + ]); + } catch(RequestFailedExcept $e) { + return null; + } + + $system = $this->GetSolarSystemName($info->solar_system_id); + + return [ + 'name' => $info->name, + 'system' => $system, + ]; + } + + public function GetMiningLedger($observerId) { + //Declare variables + $esiHelper = new Esi; + + //Check for ESI Scopes + if(!$esiHelper->HaveEsiScope($this->charId, 'esi-industry.read_corporation_mining.v1')) { + return null; + } + + //Get the refresh token and setup the esi authentication container + $esi = $esiHelper->SetupEsiAuthentication($esiHelper->GetRefreshToken($charId)); + + //Get the mining ledger + try { + $ledger = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/{observer_id}/', [ + 'corporation_id' => $corpId, + 'observer_id' => $observerId, + ]); + } catch(RequestFailedException $e) { + return null; + } + + return $ledger; + } + + 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; + } + } + +} +?> \ No newline at end of file diff --git a/resources/views/moons/ledger/displayledger.blade.php b/resources/views/moons/ledger/displayledger.blade.php new file mode 100644 index 000000000..7cf47edd1 --- /dev/null +++ b/resources/views/moons/ledger/displayledger.blade.php @@ -0,0 +1,4 @@ +@extends('layouts.b4') +@section('content') + +@endsection \ No newline at end of file diff --git a/resources/views/moons/ledger/displayselect.blade.php b/resources/views/moons/ledger/displayselect.blade.php new file mode 100644 index 000000000..7cf47edd1 --- /dev/null +++ b/resources/views/moons/ledger/displayselect.blade.php @@ -0,0 +1,4 @@ +@extends('layouts.b4') +@section('content') + +@endsection \ No newline at end of file