From 59c0de75c4682f5160dea0fa6bb71c3d439e6aa3 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Sun, 26 Apr 2020 01:26:11 -0500 Subject: [PATCH] corp rental moons --- .../Moons/MoonLedgerController.php | 144 ++++++++---------- app/Models/User/User.php | 13 ++ resources/views/layouts/navbar.blade.php | 5 +- .../moons/ledger/displayledger.blade.php | 69 +++++---- ...moons.blade.php => rentalledger.blade.php} | 0 routes/web.php | 3 +- 6 files changed, 119 insertions(+), 115 deletions(-) rename resources/views/moons/ledger/{corpmoons.blade.php => rentalledger.blade.php} (100%) diff --git a/app/Http/Controllers/Moons/MoonLedgerController.php b/app/Http/Controllers/Moons/MoonLedgerController.php index 6baf47bf7..f1fb16827 100644 --- a/app/Http/Controllers/Moons/MoonLedgerController.php +++ b/app/Http/Controllers/Moons/MoonLedgerController.php @@ -17,8 +17,6 @@ use App\Library\Lookups\LookupHelper; //App Models use App\Models\Esi\EsiToken; use App\Models\Esi\EsiScope; -use App\Models\Structure\Structure; -use App\Models\Structure\Service; use App\Models\Lookups\ItemLookup; use App\Models\MoonRent\MoonRental; use App\Models\Moon\Moon; @@ -31,10 +29,6 @@ class MoonLedgerController extends Controller $this->middleware('permission:corp.lead'); } - public function displayRentalMoon() { - - } - public function displayMoonLedger() { //Declare variables $structures = array(); @@ -135,35 +129,41 @@ class MoonLedgerController extends Controller ->with('structures', $structures); } - public function displaySelection() { + public function displayRentalMoonLedger() { //Declare variables $structures = array(); + $miningLedgers = array(); + $tempMiningLedger = array(); + $tempMining = array(); $esiHelper = new Esi; $lookup = new LookupHelper; $response = null; $structureInfo = null; + //Get the configuration for the main site + $config = config('esi'); + //Check for the esi scope - if(!$esiHelper->HaveEsiScope(auth()->user()->getId(), 'esi-industry.read_corporation_mining.v1')) { - return redirect('/dashboard')->with('error', 'Need to add scopes for esi-industry.read_corporation_mining.v1'); + if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1')) { + return redirect('/dashboard')->with('error', 'Tell the nub Minerva to register the ESI for the holding corp.'); } else { - if(!$esiHelper->HaveEsiScope(auth()->user()->getId(), 'esi-universe.read_structures.v1')) { - return redirect('/dashboard')->with('error', 'Need to add scope for esi-universe.read_structures.v1'); + if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-universe.read_structures.v1')) { + return redirect('/dashboard')->with('error', 'Tell the nub Minerva to register the ESI for the holding corp.'); } } - + //Get the refresh token if scope checks have passed - $refreshToken = $esiHelper->GetRefreshToken(auth()->user()->getId()); + $refreshToken = $esiHelper->GetRefreshToken($config['primary']); //Setup the esi container $esi = $esiHelper->SetupEsiAuthentication($refreshToken); //Get the character data from the lookup table if possible or esi - $character = $lookup->GetCharacterInfo(auth()->user()->getId()); - + $character = $lookup->GetCharacterInfo($config['primary']); + //Try to get the mining observers for the corporation from esi try { - $response = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/', [ + $responses = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/', [ 'corporation_id' => $character->corporation_id, ]); } catch(RequestFailedException $e) { @@ -171,88 +171,64 @@ class MoonLedgerController extends Controller return redirect('/dashboard')->with('error', 'Failed to get mining structures.'); } - foreach($response as $resp) { + //For each mining observer, let's build the array of data to show on the page + foreach($responses as $response) { //Try to get the structure information from esi try { $structureInfo = $esi->invoke('get', '/universe/structures/{structure_id}/', [ - 'structure_id' => $resp->observer_id, + 'structure_id' => $response->observer_id, ]); } catch(RequestFailedException $e) { //If an exception has occurred, then do nothing } - $structures[$resp->observer_id] = $structureInfo->name; + //We don't really care about the key, but it is better than just 0 through whatever number + $structures[$response->observer_id] = $structureInfo->name; } - return view('moons.ledger.displayselect')->with('structures', $structures); - } + //For each of the structures we want to address it by it's key value pair. + //This will allow us to do some interesting things in the display. + foreach($structures as $key => $value) { + try { + $ledgers = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/{observer_id}/', [ + 'corporation_id' => $character->corporation_id, + 'observer_id' => $key, + ]); + } catch(RequestFailedException $e) { + $ledgers = null; + } - public function displayLedger(Request $request) { - //Declare variables - $esiHelper = new Esi; - $lookup = new LookupHelper; - $tempMining = array(); - $mining = array(); - $temp = array(); - $ledgerEntries = array(); + if($ledgers != null) { + foreach($ledgers as $ledger) { + //Declare a variable that will need to be cleared each time the foreach processes + $tempArray = array(); - //Check for the esi scope - if(!$esiHelper->HaveEsiScope(auth()->user()->getId(), 'esi-industry.read_corporation_mining.v1')) { - //If the scope check fails, return with a redirect and error message - return redirect('/dashboar')->with('error', 'Could not find the scope for esi-industry.read_corporation_mining.v1'); - } + //Get the character information from the character id + $charInfo = $lookup->GetCharacterInfo($ledger->character_id); + //Get the corp ticker + $corpInfo = $lookup->GetCorporationInfo($charInfo->corporation_id); + //Get the ore name from the type id + $ore = $lookup->ItemIdToName($ledger->type_id); - $refreshToken = $esiHelper->GetRefreshToken(auth()->user()->getId()); - $esi = $esiHelper->SetupEsiAuthentication($refreshToken); - - //Get the character data from the lookup table if possible or esi - $character = $lookup->GetCharacterInfo(auth()->user()->getId()); - - //Try to get the mining ledger for the corporation observer - try { - $ledgers = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/{observer_id}/', [ - 'corporation_id' => $character->corporation_id, - 'observer_id' => $request->structure, - ]); - } catch(RequestFailedException $e) { - return redirect('/dashboard')->with('error', 'Failed to get the mining ledger.'); - } - - //Cycle through each ledger entry and create a new array - foreach($ledgers as $ledger) { - //Get the character information from the character id - $charInfo = $lookup->GetCharacterInfo($ledger->character_id); - //Get the corp ticker - $corpInfo = $lookup->GetCorporationInfo($charInfo->corporation_id); - //Get the ore name from the type id - $ore = $lookup->ItemIdToName($ledger->type_id); - - //Push the data onto the mining arary - array_push($tempMining, [ - 'character' => $charInfo->name, - 'corpTicker' => $corpInfo->ticker, - 'ore' => $ore, - 'quantity' => $ledger->quantity, - 'updated' => $ledger->last_updated, - ]); - } - - //Sort through the array and reverse it so the last day is shown first - $tempMining = array_reverse($tempMining, true); - - //Create the current time based on the current time and then subtract 30 days - $sortTime = Carbon::now()->subDays(30); - - //Sort through the array and discard anything that is further than 30 days out. - foreach($tempMining as $entry) { - //Create the current time stamp from the current legder before sorting - $current = Carbon::createFromFormat('Y-m-d', $entry['updated']); - if($current->greaterThanOrEqualTo($sortTime)) { - array_push($mining, $entry); + //We only want to push the mining ledger entry into the array if it matches + //the date within 30 days + $sortTime = Carbon::now()->subDays(30); + $current = Carbon::createFromFormat('Y-m-d', $ledger->last_updated); + if($current->greaterThanOrEqualTo($sortTime)) { + array_push($miningLedgers, [ + 'structure' => $value, + 'character' => $charInfo->name, + 'corpTicker' => $corpInfo->ticker, + 'ore' => $ore, + 'quantity' => $ledger->quantity, + 'updated' => $ledger->last_updated, + ]); + } + } } } - - //Return the view with the data - return view('moons.ledger.displayledger')->with('mining', $mining); + + return view('moons.ledger.corpmoons')->with('miningLedgers', $miningLedgers) + ->with('structures', $structures); } } diff --git a/app/Models/User/User.php b/app/Models/User/User.php index 2e152b729..df31058b3 100644 --- a/app/Models/User/User.php +++ b/app/Models/User/User.php @@ -10,6 +10,7 @@ use App\Models\User\UserRole; use App\Models\User\UserPermission; use App\Models\Esi\EsiScope; use App\Models\Esi\EsiToken; +use App\Models\MoonRent\MoonRental; class User extends Authenticatable { @@ -117,4 +118,16 @@ class User extends Authenticatable return $role->role; } + + public function isMoonRenter() { + $moonRental = MoonRent::where([ + 'Contact' => $this->character_id, + ])->first(); + + if($moonRental != null) { + return true; + } else { + return false; + } + } } diff --git a/resources/views/layouts/navbar.blade.php b/resources/views/layouts/navbar.blade.php index adeea113a..01f90003a 100644 --- a/resources/views/layouts/navbar.blade.php +++ b/resources/views/layouts/navbar.blade.php @@ -14,7 +14,10 @@ Moon Worth Moon Reservation @if(auth()->user()->hasPermission('corp.lead') && auth()->user()->hasEsiScope('esi-industry.read_corporation_mining.v1')) - Mining Ledger + Mining Ledger + @endif + @if(auth()->user()->isMoonRenter()) + Moon Rental Ledger @endif diff --git a/resources/views/moons/ledger/displayledger.blade.php b/resources/views/moons/ledger/displayledger.blade.php index 5639ab961..7a2216554 100644 --- a/resources/views/moons/ledger/displayledger.blade.php +++ b/resources/views/moons/ledger/displayledger.blade.php @@ -1,34 +1,47 @@ @extends('layouts.b4') @section('content') -
-
-
-
-

Moon Ledger


-

Shows mining from the last 30 days.

-
-
- - - - - - - - - - @foreach($mining as $min) - - - - - - - - @endforeach - -
CharacterCorp TickerOre NameQuantityDate
{{ $min['character'] }}{{ $min['corpTicker'] }}{{ $min['ore'] }}{{ $min['quantity'] }}{{ $min['updated'] }}
+
+
+
+

Moon Ledger

+
+ +
+
+ @foreach($structures as $key => $value) +
+ + + + + + + + + + @foreach($miningLedgers as $ledger) + @if($ledger['structure'] == $value) + + + + + + + + @endif + @endforeach + +
CharacterCorp TickerOre NameQuantityDate
{{ $ledger['character'] }}{{ $ledger['corpTicker'] }}{{ $ledger['ore'] }}{{ $ledger['quantity'] }}{{ $ledger['updated'] }}
+
+ @endforeach +
@endsection \ No newline at end of file diff --git a/resources/views/moons/ledger/corpmoons.blade.php b/resources/views/moons/ledger/rentalledger.blade.php similarity index 100% rename from resources/views/moons/ledger/corpmoons.blade.php rename to resources/views/moons/ledger/rentalledger.blade.php diff --git a/routes/web.php b/routes/web.php index 073b1d7dd..fada23d0d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -133,9 +133,8 @@ Route::group(['middleware' => ['auth']], function(){ /** * Moon Ledger Controller display pages */ - Route::post('/moons/ledger/display/', 'Moons\MoonLedgerController@displayLedger'); - Route::get('/moons/ledger/display/select', 'Moons\MoonLedgerController@displaySelection'); Route::get('/moons/ledger/display/moons', 'Moons\MoonLedgerController@displayMoonLedger'); + Route::get('/moons/ledger/display/rentals', 'Moons\MoonLedgerController@displayRentalMoonLedger'); /** * Scopes Controller display pages