added function to search for a pilot's name, and add pilot by name

This commit is contained in:
2018-11-17 17:38:00 -06:00
parent 31d4141093
commit 472ff6632d
2 changed files with 50 additions and 3 deletions

View File

@@ -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() {

View File

@@ -1,9 +1,17 @@
<?php
use App\Models\EsiScope;
use DB;
use App\Models\EsiScope;
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
/**
* This class represents a few ESI helper functions for the program
*/
class Esi {
/**
@@ -25,6 +33,27 @@ class Esi {
return false;
}
public function FindCharacterId($name) {
$config = config('esi');
//Create the esi authentication container
$authentication = new EsiAuthentication([
'client_id' => $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'];
}
}
?>