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.');
}
}
}

View File

@@ -2,96 +2,116 @@
namespace App\Library;
use Auth;
use Session;
use DB;
use App\Models\EsiToken;
use App\Library\Fleet;
use Carbon\Carbon;
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
class Fleet {
/**
* Get fleet information
*/
public function GetFleetInfo($uri) {
private $fleet;
private $endTime;
private $fcId;
/**
* Constructor
*
* @param fcId
*/
public function __construct($charId) {
$this->fcId = $charId;
}
/**
* Update fleet information
* Set Fleet number
*
* @param fleetUri
*/
public function UpdateFleet($fleet) {
public function SetFleetUri($fleetUri) {
//Trim the left side of the fleet number
$fleetUri = ltrim($fleetUri, 'https://esi.tech.ccp.is/v1/fleets/');
//Trim the right side of the fleet number
$fleetUri = rtrim($fleetUri, '/?datasource=tranquility');
$this->fleet = $fleetUri;
return $this->fleet;
}
/**
* Create a standing fleet from a registered fleet.
* Set the fleet's end time
*
* @param endTime
*/
public function CreateStandingFleet($fleet) {
public function SetFleetEndTime($endTime) {
$this->endTime = $endTime;
}
/**
* Join the standing fleet
*/
public function JoinStandingFleet($fleet, $charId) {
public function UpdateFleet($isFreeMove, $motd) {
//Check if the fc has the right scope
if(!$this->HaveEsiScope($this->fcId, 'esi-fleets.write_fleet.v1')) {
return false;
}
//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);
$error = $esi->invoke('put', '/fleets/{fleet_id}/', [
'fleet_id' => $this->fleet,
'new_settings' => [
'is_free_move' => $isFreeMove,
'motd' => $motd,
],
]);
}
/**
* Leave the standing fleet
*/
public function LeaveStandingFleet($fleet, $charId) {
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,
]);
}
/**
* Create new wing in a fleet
*/
public function CreateNewWing($fleet) {
}
/**
* Create new squad in a fleet
*/
public function CreateNewSquad($fleet) {
}
/**
* Modify the MotD of a fleet
*/
public function ModifyMOTD($fleet) {
}
/**
* Get a fleet's squads
*/
public function GetSquads($fleet) {
}
/**
* Rename a fleet's squad
*/
public function RenameSquad($fleet, $squad, $name) {
}
/**
* Get fleet's wings
*/
public function GetWings($fleet) {
}
/**
* Rename a fleet wing
*/
public function RenameWing($fleet, $wing, $name) {
private function HaveEsiScope($charId, $scope) {
//Check for an esi scope
$checks = DB::table('EsiScopes')->where('character_id')->get();
foreach($checks as $check) {
if($check->scope === $scope) {
return true;
}
}
return false;
}
}

29
app/Models/Fleet.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Fleet extends Model
{
// Table Name
protected $table = 'Fleets';
// Primary Key
public $primaryKey = 'id';
// Timestamps
public $timestamps = false;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'character_id',
'fleet',
'creation_time',
'time_left',
];
}

View File

@@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateFleetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!Schema::hasTable('Fleets')) {
Schema::create('Fleets', function (Blueprint $table) {
$table->increments('id');
$table->string('character_id');
$table->string('fleet')->unique();
$table->dateTime('creation_time');
$table->dateTime('fleet_end');
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('Fleets');
}
}

View File

@@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSessionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!Schema::hasTable('sessions')) {
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->unique();
$table->unisgnedInteger('user_id')->nullable();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->text('payload');
$table->integer('last_activity');
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('sessions');
}
}

View File

@@ -26,6 +26,9 @@
</li>
</ul>
<ul class="navbar-nav m1-auto">
<li class="nav-item">
<a class="nav-link" href="/scopes/select">Add Esi Scopes</a>
</li>
@can('isAdmin')
<li class="nav-item">
<a class="nav-link" href="/admin/dashboard">Admin</a>

View File

@@ -8,6 +8,7 @@ $baseDir = dirname($vendorDir);
return array(
'App\\Console\\Kernel' => $baseDir . '/app/Console/Kernel.php',
'App\\Exceptions\\Handler' => $baseDir . '/app/Exceptions/Handler.php',
'App\\Http\\Controllers\\AdminController' => $baseDir . '/app/Http/Controllers/AdminController.php',
'App\\Http\\Controllers\\Auth\\ForgotPasswordController' => $baseDir . '/app/Http/Controllers/Auth/ForgotPasswordController.php',
'App\\Http\\Controllers\\Auth\\LoginController' => $baseDir . '/app/Http/Controllers/Auth/LoginController.php',
'App\\Http\\Controllers\\Auth\\RegisterController' => $baseDir . '/app/Http/Controllers/Auth/RegisterController.php',
@@ -15,6 +16,7 @@ return array(
'App\\Http\\Controllers\\Auth\\VerificationController' => $baseDir . '/app/Http/Controllers/Auth/VerificationController.php',
'App\\Http\\Controllers\\Controller' => $baseDir . '/app/Http/Controllers/Controller.php',
'App\\Http\\Controllers\\DashboardController' => $baseDir . '/app/Http/Controllers/DashboardController.php',
'App\\Http\\Controllers\\EsiScopeController' => $baseDir . '/app/Http/Controllers/EsiScopeController.php',
'App\\Http\\Controllers\\FinancesController' => $baseDir . '/app/Http/Controllers/FinancesController.php',
'App\\Http\\Controllers\\FleetsController' => $baseDir . '/app/Http/Controllers/FleetsController.php',
'App\\Http\\Controllers\\MoonsController' => $baseDir . '/app/Http/Controllers/MoonsController.php',
@@ -38,8 +40,9 @@ return array(
'App\\Models\\DokuGroupNames' => $baseDir . '/app/Models/DokuGroupNames.php',
'App\\Models\\DokuMember' => $baseDir . '/app/Models/DokuMember.php',
'App\\Models\\DokuUser' => $baseDir . '/app/Models/DokuUser.php',
'App\\Models\\EsiScope' => $baseDir . '/app/Models/UserEsiScope.php',
'App\\Models\\EsiScope' => $baseDir . '/app/Models/EsiScope.php',
'App\\Models\\EsiToken' => $baseDir . '/app/Models/EsiToken.php',
'App\\Models\\Fleet' => $baseDir . '/app/Models/Fleet.php',
'App\\Models\\HoldingCorpJournal' => $baseDir . '/app/Models/HoldingCorpJournal.php',
'App\\Models\\ItemComposition' => $baseDir . '/app/Models/ItemComposition.php',
'App\\Models\\MarketOrder' => $baseDir . '/app/Models/MarketOrder.php',

View File

@@ -403,6 +403,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
public static $classMap = array (
'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.php',
'App\\Exceptions\\Handler' => __DIR__ . '/../..' . '/app/Exceptions/Handler.php',
'App\\Http\\Controllers\\AdminController' => __DIR__ . '/../..' . '/app/Http/Controllers/AdminController.php',
'App\\Http\\Controllers\\Auth\\ForgotPasswordController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/ForgotPasswordController.php',
'App\\Http\\Controllers\\Auth\\LoginController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/LoginController.php',
'App\\Http\\Controllers\\Auth\\RegisterController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/RegisterController.php',
@@ -410,6 +411,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\Http\\Controllers\\Auth\\VerificationController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/VerificationController.php',
'App\\Http\\Controllers\\Controller' => __DIR__ . '/../..' . '/app/Http/Controllers/Controller.php',
'App\\Http\\Controllers\\DashboardController' => __DIR__ . '/../..' . '/app/Http/Controllers/DashboardController.php',
'App\\Http\\Controllers\\EsiScopeController' => __DIR__ . '/../..' . '/app/Http/Controllers/EsiScopeController.php',
'App\\Http\\Controllers\\FinancesController' => __DIR__ . '/../..' . '/app/Http/Controllers/FinancesController.php',
'App\\Http\\Controllers\\FleetsController' => __DIR__ . '/../..' . '/app/Http/Controllers/FleetsController.php',
'App\\Http\\Controllers\\MoonsController' => __DIR__ . '/../..' . '/app/Http/Controllers/MoonsController.php',
@@ -433,8 +435,9 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\Models\\DokuGroupNames' => __DIR__ . '/../..' . '/app/Models/DokuGroupNames.php',
'App\\Models\\DokuMember' => __DIR__ . '/../..' . '/app/Models/DokuMember.php',
'App\\Models\\DokuUser' => __DIR__ . '/../..' . '/app/Models/DokuUser.php',
'App\\Models\\EsiScope' => __DIR__ . '/../..' . '/app/Models/UserEsiScope.php',
'App\\Models\\EsiScope' => __DIR__ . '/../..' . '/app/Models/EsiScope.php',
'App\\Models\\EsiToken' => __DIR__ . '/../..' . '/app/Models/EsiToken.php',
'App\\Models\\Fleet' => __DIR__ . '/../..' . '/app/Models/Fleet.php',
'App\\Models\\HoldingCorpJournal' => __DIR__ . '/../..' . '/app/Models/HoldingCorpJournal.php',
'App\\Models\\ItemComposition' => __DIR__ . '/../..' . '/app/Models/ItemComposition.php',
'App\\Models\\MarketOrder' => __DIR__ . '/../..' . '/app/Models/MarketOrder.php',