created fleets table

create sessions table
modified register fleet in fleetscontroller
modified addpilot in fleetscontroller
modified render fleet display
modified update fleet function
created set fleet end time function
modified fleet class
created set fleet uri function
modified function to see if a token has a particular scope for Fleet
This commit is contained in:
2018-11-10 03:10:22 -06:00
parent 619180243e
commit b241f5509d
8 changed files with 260 additions and 76 deletions

View File

@@ -4,6 +4,12 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
use DB;
use App\Library\Fleet;
class FleetsController extends Controller
{
public function __construct() {
@@ -16,22 +22,69 @@ class FleetsController extends Controller
}
public function displayStandingFleet() {
return view('fleets.displaystanding');
//Retrieve the fleet from the session
$fleet = $request->session()->get('fleet');
//Display standing fleets
$display = $fleet->RenderFleetDisplay();
//Return the view with the array of the fleet
return view('fleets.displaystanding')->with('display', $display);
}
public function registerFleet() {
public function registerFleet(Request $request) {
$fleet = new App\Library\Fleet(Auth::user()->character_id);
$fleetUri = $fleet->SetFleetUri($request->fleetUri);
//Check for the fleet in the database
$check = DB::table('Fleets')->where('fleet')->first();
//If we do not find the fleet, let's create it.
if($check !== null) {
$current = Carbon::now();
//If we are between 00:00 and 05:00, we want to set the end time for 0500
if($current->hour > 0 && $current->hour < 5) {
//Figure out the hours to add to the fleet before purging it.
$hour = $current->hour;
$endTime = Carbon::now();
$endTime->hour = 5 - $hour;
} else {
//Figure out the hours to add to the fleet before purging it.
$endTime = Carbon::now();
$endTime->day++;
$endTime->hour = 5;
$endTime->minute = 0;
$endTime->second = 0;
}
// Insert the fleet into the table
DB::table('Fleets')->insert([
'character_id' => Auth::$user->character_id,
'fleet' => $fleetUri,
'creation_time' => $current,
'fleet_end' => $endTime,
]);
$fleet->SetFleetEndTime($endTime);
//Set the fleet into the session to be used later
session(['fleet' => $fleet]);
//Return the view with the success message
return view('fleets.displaystanding')->with('success', 'Fleet registered.');
} else {
//Return the view with the error message of the fleet has been found already.
return view('fleets.displaystanding')->with('error', 'Fleet already in the database.');
}
}
public function createWing() {
}
public function createSquad() {
}
public function addPilot() {
public function addPilot(Request $request) {
//Retrieve the fleet from the session
$fleet = $request->session()->get('fleet');
//Add a pilot to the fleet
$error = $fleet->AddPilot(Auth::user()->character_id);
if($error) {
return view('fleets.displaystanding')->with('error', 'Unable to add to fleet.');
} else {
return view('fleets.displaystanding')->with('success', 'Pilot added to fleet.');
}
}
}