mining ledger helper

This commit is contained in:
2019-09-09 20:23:59 -05:00
parent fa4f642498
commit ae87e5b01b
5 changed files with 235 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Http\Controllers\Moons;
//Internal Library
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Log;
use DB;
//App Library
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
use Seat\Eseye\Exceptions\RequestFailedException;
use App\Library\Esi\Esi;
use App\Library\Structures\StructureHelper;
//App Models
use App\Models\Esi\EsiToken;
use App\Models\Esi\EsiScope;
use App\Models\Structure\Structure;
use App\Models\Structure\Service;
class MoonLedgerController extends Controller
{
public function __construct() {
$this->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');
}
}

View File

@@ -172,6 +172,33 @@ class Esi {
return $token->refresh_token; 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;
}
} }
?> ?>

View File

@@ -0,0 +1,145 @@
<?php
/**
* W4RP Services
* GNU Public License
*
*/
namespace App\Library\Moons;
//Internal Library
use Log;
use DB;
//App Library
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
use Seat\Eseye\Exceptions\RequestFailedException;
use App\Library\Esi\Esi;
//App Models
use App\Models\Structure\Structure;
use App\Models\Structure\Service;
use App\Models\Esi\EsiToken;
use App\Models\Esi\EsiScope;
class MiningLedgerHelper {
private $charId;
private $corpId;
public function __construct($charId, $corpId) {
$this->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;
}
}
}
?>

View File

@@ -0,0 +1,4 @@
@extends('layouts.b4')
@section('content')
@endsection

View File

@@ -0,0 +1,4 @@
@extends('layouts.b4')
@section('content')
@endsection