diff --git a/app/Http/Controllers/FleetsController.php b/app/Http/Controllers/FleetsController.php index 49456c69a..9787e9691 100644 --- a/app/Http/Controllers/FleetsController.php +++ b/app/Http/Controllers/FleetsController.php @@ -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 { diff --git a/app/Library/Fleet.php b/app/Library/Fleet.php index 83569b816..e9f7050a3 100644 --- a/app/Library/Fleet.php +++ b/app/Library/Fleet.php @@ -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) { diff --git a/database/migrations/2018_11_09_051006_create_fleets_table.php b/database/migrations/2018_11_09_051006_create_fleets_table.php index d815b0668..4d8664588 100644 --- a/database/migrations/2018_11_09_051006_create_fleets_table.php +++ b/database/migrations/2018_11_09_051006_create_fleets_table.php @@ -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'); }); diff --git a/resources/views/fleets/displayfleets.blade.php b/resources/views/fleets/displayfleets.blade.php index 223f3b93f..056071923 100644 --- a/resources/views/fleets/displayfleets.blade.php +++ b/resources/views/fleets/displayfleets.blade.php @@ -2,8 +2,9 @@ @section('content')