From 472ff6632da027af80ce64755ff0870c3c11297d Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Sat, 17 Nov 2018 17:38:00 -0600 Subject: [PATCH] added function to search for a pilot's name, and add pilot by name --- app/Http/Controllers/FleetsController.php | 20 +++++++++++++- app/Library/Esi.php | 33 +++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/FleetsController.php b/app/Http/Controllers/FleetsController.php index 11cf0fbc5..89aee1b71 100644 --- a/app/Http/Controllers/FleetsController.php +++ b/app/Http/Controllers/FleetsController.php @@ -9,6 +9,7 @@ use DB; use Carbon\Carbon; use App\Library\Fleet; +use App\Library\Esi; class FleetsController extends Controller @@ -113,8 +114,25 @@ class FleetsController extends Controller } else { return view('inc.error')->with('error', $error); } + } - + public function addPilotName($fleetId, $name) { + $newPilot = new Fleet(); + $esiHelper = new Esi(); + + //Retrieve the fleet data + $fleet = DB::table('Fleets')->where('fleet', $fleetId)->get(); + //Search for the pilot's character id through his name + $charId = $esiHelper->FindCharacterId($name); + //Add the pilot to the fleet + $error = $newPilot->AddPilot($fleet[0]->character_id, $charId, $fleetId); + //If we don't have an error go back to the dashboard, + //Otherwise, send the user to the error screen and print the error out. + if($error === null) { + return view('/dashboard')->with('success', 'Invite for fleet sent.'); + } else { + return view('inc.error')->with('error', $error); + } } public function updateFleet() { diff --git a/app/Library/Esi.php b/app/Library/Esi.php index db63f3c74..b93c0f1f2 100644 --- a/app/Library/Esi.php +++ b/app/Library/Esi.php @@ -1,9 +1,17 @@ $config['esi']['client_id'], + 'secret' => $config['esi']['secret'], + ]); + //Create the esi container + $esi = new Eseye($authentication); + $character = $esi->setQueryString([ + 'categories' => 'character', + 'language' => 'en-us', + 'search' => $name, + 'strict' => 'true', + ])->invoke('get', '/search/'); + + $character = json_decode($character, true); + + return $character['character']; + } + } ?> \ No newline at end of file