This commit is contained in:
2018-11-13 01:20:44 -06:00
parent 3c5c3a04db
commit 054e8e1734
6 changed files with 45 additions and 43 deletions

View File

@@ -24,8 +24,18 @@ class FleetsController extends Controller
public function displayFleets() {
$fleets = DB::table('Fleets')->get();
$fleetIds = array();
$i = 0;
foreach($fleets as $fleet) {
$fleetIds[$i] = [
'fc' => $fleet->character_id,
'fleet' => $fleet->fleet,
'description' => $fleet->description,
];
$i++;
}
//Return the view with the array of the fleet
return view('fleets.displayfleets')->with('fleetId', $fleetId);
return view('fleets.displayfleets')->with('fleetIds', $fleetIds);
}
public function registerFleet(Request $request) {
@@ -56,13 +66,12 @@ class FleetsController extends Controller
DB::table('Fleets')->insert([
'character_id' => Auth::user()->character_id,
'fleet' => $fleetUri,
'description' => $request->description,
'creation_time' => $current,
'fleet_end' => $endTime,
]);
$fleet->SetFleetEndTime($endTime);
//Set the fleet into the session to be used later
Session::put('fleet', $fleet);
//Return the view with the success message
return view('fleets.displayfleets')->with('success', 'Fleet registered.');
} else {
@@ -71,12 +80,11 @@ class FleetsController extends Controller
}
}
public function addPilot($id) {
//Retrieve the fleet from the session
$fleet = Session::get('session');
dd($fleet);
public function addPilot($fleetId, $charId) {
//Retrieve the fleet data
$fleet = DB::table('Fleets')->where('fleet', $fleetId)->get();
//Add a pilot to the fleet
$error = $fleet->AddPilot($id);
$error = $fleet->AddPilot($fleet->character_id, $charId);
if($error) {
return view('fleets.displaystanding')->with('error', 'Unable to add to fleet.');
} else {

View File

@@ -18,17 +18,17 @@ use Seat\Eseye\Eseye;
class Fleet {
private $fleet;
private $endTime;
private $fcId;
private $endTime;
/**
* Constructor
*
* @param fcId
*/
public function __construct($charId) {
public function __construct($charId = null, $fleetId = null) {
$this->fcId = $charId;
$this->fleet = $fleetId;
}
/**
@@ -55,13 +55,16 @@ class Fleet {
$this->endTime = $endTime;
}
public function UpdateFleet($isFreeMove, $motd) {
public function UpdateFleet($fleet, $isFreeMove, $motd) {
//Get the fcid from the datatable
$fc = DB::table('Fleets')->where('fleet', $fleetId)->get();
//Check if the fc has the right scope
if(!$this->HaveEsiScope($this->fcId, 'esi-fleets.write_fleet.v1')) {
return false;
if(!$this->HaveEsiScope($fc->character_id, 'esi-fleets.write_fleet.v1')) {
return 1;
}
//Get the FC's refresh token from the table
$token = DB::table('EsiTokens')->where('character_id', $this->fcId)->first();
$token = DB::table('EsiTokens')->where('character_id', $fc->character_id)->first();
//Create the esi authentication container
$authentication = new \Seat\Eseye\Containers\EsiAuthentication([
'client_id' => env('ESI_CLIENT_ID'),
@@ -71,17 +74,24 @@ class Fleet {
//Create the esi class
$esi = new Eseye($authentication);
$error = $esi->invoke('put', '/fleets/{fleet_id}/', [
'fleet_id' => $this->fleet,
'fleet_id' => $fleet,
'new_settings' => [
'is_free_move' => $isFreeMove,
'motd' => $motd,
],
]);
return $error;
}
public function AddPilot($charId, $fleetId) {
public function AddPilot($fc, $charId) {
//Check if the fc has the right scope
if(!$this->HaveEsiScope($fc, 'esi-fleets.write_fleet.v1')) {
return 1;
}
//Get the ESI token for the FC to add the new pilot
$token = DB::table('EsiTokens')->where('character_id', $this->fcId)->first();
$token = DB::table('EsiTokens')->where('character_id', $fc->character_id)->first();
//Create the ESI Call Container
$authentication = new EsiAuthentication([
'client_id' => env('ESI_CLIENT_ID'),
@@ -103,27 +113,7 @@ class Fleet {
}
public function RenderFleetDisplay() {
if(!$this->HaveEsiScope($this->fcId, 'esi-fleets.read_fleet.v1')) {
return false;
}
$display = array();
//Get the FC's refresh token from the table
$token = DB::table('EsiTokens')->where('character_id', $this->fcId)->first();
//Create the esi authentication container
$authentication = new \Seat\Eseye\Containers\EsiAuthentication([
'client_id' => env('ESI_CLIENT_ID'),
'secret' => env('ESI_SECRET_KEY'),
'refresh_token' => $token->refresh_token,
]);
//Create the esi class
$esi = new Eseye($authentication);
//Get the wings for the fleet wing ids
$wings = $esi->invoke('get', '/fleets/{fleet_id}/wings/', [
'fleet_id' => $this->fleet,
]);
//
}
private function HaveEsiScope($charId, $scope) {

View File

@@ -18,6 +18,7 @@ class CreateFleetsTable extends Migration
$table->increments('id');
$table->string('character_id');
$table->string('fleet')->unique();
$table->text('description')->nullable();
$table->dateTime('creation_time');
$table->dateTime('fleet_end');
});

View File

@@ -2,8 +2,9 @@
@section('content')
<div class="container">
<h1>Work in Progress aka NOTHING WORKS!</h1><br>
<h2>Standing Fleet</h2>
<a href="{{ route('addpilot', [Auth::user()->character_id]) }}">Join Standing Fleet</a>
Display some other cool stuff about the fleet
<h2>Fleets</h2>
@foreach ($fleetIds as $fleet)
<a href="{{ route('addpilot', $fleet['fleet'], [Auth::user()->character_id]) }}">Join {{ $fleet['description'] }}</a>
@endforeach
</div>
@endsection

View File

@@ -6,6 +6,8 @@
<div class="form-group col-md-6">
{{ Form::label('fleetUri', 'Fleet') }}
{{ Form::text('fleetUri', '', ['class' => 'form-control', 'placeholder' => 'Fleet URL']) }}
{{ Form::label('description', 'Fleet Name') }}
{{ Form::text('description', '', ['class' => 'form control', 'placeholder' => 'Fleet Name']) }}
</div>
{{ Form::submit('Submit', ['class' => 'btn btn-primary']) }}
{!! Form::close() !!}

View File

@@ -48,7 +48,7 @@ Route::post('redirectToProvider', 'EsiScopeController@redirectToProvider');
//Fleet Controller display pages
Route::get('/fleets/display', 'FleetsController@displayFleets');
Route::get('/fleets/register', 'FleetsController@displayRegisterFleet');
Route::get('/fleets/addpilot/{id}', 'FleetsController@addPilot')->name('addpilot');
Route::get('/fleets/{fleet_id}/addpilot/{id}', 'FleetsController@addPilot')->name('addpilot');
Route::post('/fleets/registerFleet', 'FleetsController@registerFleet');
//Admin Controller display pages