created function for registering structures which should only be accessible by those with the correct scope.
This commit is contained in:
@@ -21,6 +21,7 @@ use App\Models\Lookups\ItemLookup;
|
||||
use App\Models\MoonRent\MoonRental;
|
||||
use App\Models\Moon\RentalMoon;
|
||||
use App\Models\Moon\CorpObserversRegistered;
|
||||
use App\Models\Moon\CorpMoonObserver;
|
||||
|
||||
class MoonLedgerController extends Controller
|
||||
{
|
||||
@@ -29,9 +30,70 @@ class MoonLedgerController extends Controller
|
||||
$this->middleware('role:User');
|
||||
}
|
||||
|
||||
public function registerStructureLedger() {
|
||||
public function registerStructures() {
|
||||
//Declare variables
|
||||
|
||||
$esiHelper = new Esi;
|
||||
$lookup = new LookupHelper;
|
||||
$skipped = false;
|
||||
|
||||
$charId = auth()->user()->getId();
|
||||
|
||||
//Check for the esi scope to be registered already
|
||||
if(!$esiHelper->HaveEsiScope($charId, 'esi-industry.read_corporation_mining.v1') || !$esiHelper->HaveEsiScope($charId, 'Need to add scope for esi-universe.read_structures.v1')) {
|
||||
return redirect('/dashboard')->with('error', 'Please register corporation mining and universe structures scopes before continuing.');
|
||||
}
|
||||
|
||||
//Get the refresh token for the user
|
||||
$refreshToken = $esiHelper->GetRefreshToken($charId);
|
||||
|
||||
//Setup the esi container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
||||
|
||||
//Get the character data from the lookup table if possible or from esi
|
||||
$character = $lookup->GetCharacterInfo($charId);
|
||||
//Get the corporation info from the lookup table
|
||||
$corporation = $lookup->GetCorporationInfo($character->corporation_id);
|
||||
|
||||
//Try to get the mining observers for the corporation from esi
|
||||
try {
|
||||
$responses = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/', [
|
||||
'corporation_id' => $character->corporation_id,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
//If an exception has occurred for some reason redirect back to the dashboard with an error message
|
||||
return redirect('/dashboard')->with('error', 'Failed to get mining structures.');
|
||||
}
|
||||
|
||||
foreach($responses as $response) {
|
||||
//Try to get the structure information from esi
|
||||
try {
|
||||
$structureInfo = $esi->invoke('get', '/universe/structures/{structure_id}/', [
|
||||
'structure_id' => $response->observer_id,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
Log::warning('Failed to get the structure information in MoonLedgerController. Skipping structure');
|
||||
$skipped = true;
|
||||
}
|
||||
|
||||
if($skipper == false) {
|
||||
$observer = new CorpMoonObserver;
|
||||
$observer->corporation_id = $character->corporation_id;
|
||||
$observer->corporation_name = $corporation->name;
|
||||
$observer->observer_id = $response->observer_id;
|
||||
$observer->observer_name = $structureInfo->name;
|
||||
$observer->observer_type = $response->observer_type;
|
||||
$observer->observer_owner_id = $structureInfo->owner_id;
|
||||
$observer->solar_system_id = $structureInfo->solar_system_id;
|
||||
$observer->observer_type_id = $structureInfo->observer_type_id;
|
||||
$observer->last_updated = $response->last_updated;
|
||||
$observer->save();
|
||||
}
|
||||
|
||||
//Reset the skipped variable
|
||||
$skipped = false;
|
||||
}
|
||||
|
||||
return redirect('/dashboard')->with('success', 'Added mining structures to the database');
|
||||
}
|
||||
|
||||
public function displayMoonLedger() {
|
||||
|
||||
@@ -26,6 +26,9 @@ class CorpMoonObserver extends Model
|
||||
'observer_id',
|
||||
'observer_name',
|
||||
'observer_type',
|
||||
'observer_owner_id',
|
||||
'solar_system_id',
|
||||
'observer_type_id',
|
||||
'last_updated',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Moon;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CorpObserversRegistered extends Model
|
||||
{
|
||||
//Table Name
|
||||
protected $table = 'corp_mining_observers_registered';
|
||||
|
||||
//Primary Key
|
||||
public $primaryKey = 'id';
|
||||
|
||||
//Timestamps
|
||||
public $timestamps = true;
|
||||
|
||||
/**
|
||||
* Attributes that are mass assignable
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'character_id',
|
||||
'character_name',
|
||||
'corporation_id',
|
||||
'corporation_name',
|
||||
];
|
||||
}
|
||||
@@ -53,6 +53,9 @@ class CreateRentalMoonLedgerTables extends Migration
|
||||
$table->unsignedBigInteger('observer_id');
|
||||
$table->string('observer_name');
|
||||
$table->string('observer_type');
|
||||
$table->unsignedBigInteger('observer_owner_id');
|
||||
$table->unsignedBigInteger('solar_system_id');
|
||||
$table->unsignedBigInteger('observer_type_id');
|
||||
$table->dateTime('last_updated');
|
||||
$table->timestamps();
|
||||
});
|
||||
@@ -76,17 +79,6 @@ class CreateRentalMoonLedgerTables extends Migration
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
if(!Schema::hasTable('corp_mining_observers_registered')) {
|
||||
Schema::create('corp_mining_observers_registered', function(Blueprint $table) {
|
||||
$table->unsignedBigIncrements('id');
|
||||
$table->unsignedBigInteger('character_id');
|
||||
$table->string('character_name');
|
||||
$table->unsignedBigInteger('corporation_id');
|
||||
$table->string('corporation_name');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -135,6 +135,7 @@ Route::group(['middleware' => ['auth']], function(){
|
||||
*/
|
||||
Route::get('/moons/ledger/display/moons', 'Moons\MoonLedgerController@displayMoonLedger');
|
||||
Route::get('/moons/ledger/display/rentals', 'Moons\MoonLedgerController@displayRentalMoonLedger');
|
||||
Route::get('/moons/ledger/register', 'Moons\MoonLedgerController@registerStructures');
|
||||
|
||||
/**
|
||||
* Scopes Controller display pages
|
||||
|
||||
Reference in New Issue
Block a user