From 8bbd83da909774afcf1611443178ddfecff6b6d0 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Mon, 3 Dec 2018 13:00:58 -0600 Subject: [PATCH] added fleet activity model created new commands helper class to help with certain task across all scheduled task updated the task to use the new class partially updated fleet controller --- app/Console/Commands/Library/helper.php | 41 +++++++++++ app/Console/Commands/UpdateMoonPricing.php | 18 ++--- app/Console/Commands/corpJournal.php | 17 ++--- app/Console/Commands/dumpFleets.php | 56 +++++++++++++++ app/Console/Commands/getCorps.php | 18 ++--- app/Console/Commands/getLogisticContracts.php | 17 ++--- app/Console/Commands/sendmail.php | 18 ++--- app/Http/Controllers/FleetsController.php | 69 +++++++++++++++++-- app/Library/{Fleets.php => FleetHelper.php} | 4 +- app/Models/Fleet/FleetActivity.php | 10 +++ 10 files changed, 208 insertions(+), 60 deletions(-) create mode 100644 app/Console/Commands/Library/helper.php create mode 100644 app/Console/Commands/dumpFleets.php rename app/Library/{Fleets.php => FleetHelper.php} (98%) create mode 100644 app/Models/Fleet/FleetActivity.php diff --git a/app/Console/Commands/Library/helper.php b/app/Console/Commands/Library/helper.php new file mode 100644 index 000000000..e6bac15b5 --- /dev/null +++ b/app/Console/Commands/Library/helper.php @@ -0,0 +1,41 @@ +job_name = $name; + $this->job_status = 'Starting'; + $this->system_time = Carbon::now(); + } + + public function SetStartStatus() { + //Add an entry into the jobs table + $job = new ScheduleJob; + $job->job_name = $this->job_name; + $job->state = $this->job_state; + $job->system_time = $this->system_time; + $job->save(); + } + + public function SetStopStatus() { + //Mark the job as finished + DB::table('schedule_jobs')->where([ + 'system_time' => $this->system_time, + 'job_name' => $this->job_name, + ])->update([ + 'job_state' => 'Finished', + ]); + } + +} + +?> \ No newline at end of file diff --git a/app/Console/Commands/UpdateMoonPricing.php b/app/Console/Commands/UpdateMoonPricing.php index 2119fd890..956d5697d 100644 --- a/app/Console/Commands/UpdateMoonPricing.php +++ b/app/Console/Commands/UpdateMoonPricing.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use DB; use Carbon\Carbon; +use Commands\Library\CommandHelper; use App\Library\MoonCalc; @@ -41,20 +42,15 @@ class UpdateMoonPricing extends Command */ public function handle() { - //Set the time the job has started - $job = new ScheduleJob; - $time = Carbon::now(); - $job->job_name = 'CorpJournal'; - $job->job_state = 'Starting'; - $job->system_time = $time; - $job->save(); + //Create the command helper container + $task = new CommandHelper('CorpJournal'); + //Add the entry into the jobs table saying the job is starting + $task->SetStartStatus(); $moonCalc = new MoonCalc(); $moonCalc->FetchNewPrices(); - //Set the state of the job as finished - DB::table('schedule_jobs')->where('system_time', $time)->update([ - 'job_state' => 'Finished', - ]); + //Mark the job as finished + $task->SetStopStatus(); } } diff --git a/app/Console/Commands/corpJournal.php b/app/Console/Commands/corpJournal.php index f04e6f26a..10f7fbc40 100644 --- a/app/Console/Commands/corpJournal.php +++ b/app/Console/Commands/corpJournal.php @@ -6,6 +6,8 @@ use Illuminate\Console\Command; use DB; +use Commands\Library\CommandHelper; + use App\Library\Finances; use App\Library\Esi; @@ -49,13 +51,10 @@ class CorpJournal extends Command */ public function handle() { - //Add an entry into the jobs table - $job = new ScheduleJob; - $time = Carbon::now(); - $job->job_name = 'CorpJournal'; - $job->job_state = 'Starting'; - $job->system_time = $time; - $job->save(); + //Create the command helper container + $task = new CommandHelper('CorpJournal'); + //Add the entry into the jobs table saying the job is starting + $task->SetStartStatus(); //Setup the Finances Container $finance = new Finances(); //Setup an array to store corporations which have been logged so we don't keep calling the same ones. We need @@ -90,9 +89,7 @@ class CorpJournal extends Command } //Mark the job as finished - DB::table('schedule_jobs')->where('system_time', $time)->update([ - 'job_state' => 'Finished', - ]); + $task->SetStopStatus(); } private function GetJournal($charId) { diff --git a/app/Console/Commands/dumpFleets.php b/app/Console/Commands/dumpFleets.php new file mode 100644 index 000000000..a41069a15 --- /dev/null +++ b/app/Console/Commands/dumpFleets.php @@ -0,0 +1,56 @@ +job_name = 'CorpJournal'; + $job->job_state = 'Starting'; + $job->system_time = $time; + $job->save(); + + //Mark the job as finished + $task->SetStopStatus(); + } +} diff --git a/app/Console/Commands/getCorps.php b/app/Console/Commands/getCorps.php index 4a37421e8..5c5a1a7ca 100644 --- a/app/Console/Commands/getCorps.php +++ b/app/Console/Commands/getCorps.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use DB; use Carbon\Carbon; +use Commands\Library\CommandHelper; use App\Models\AllianceCorp; use App\Models\ScheduleJob; @@ -47,13 +48,10 @@ class GetCorps extends Command */ public function handle() { - //Add an entry into the jobs table - $job = new ScheduleJob; - $time = Carbon::now(); - $job->job_name = 'GetCorps'; - $job->job_state = 'Starting'; - $job->system_time = $time; - $job->save(); + //Create the command helper container + $task = new CommandHelper('CorpJournal'); + //Add the entry into the jobs table saying the job is starting + $task->SetStartStatus(); //Set the parameters for ESI $configuration = Configuration::getInstance(); $configuration->logfile_location = 'var/www/w4rpservices/storage/logs/eseye'; @@ -83,9 +81,7 @@ class GetCorps extends Command $entry->save(); } - //If the job is finished we need to mark it in the table - DB::table('schedule_jobs')->where('system_time', $time)->update([ - 'job_state' => 'Finished', - ]); + //Mark the job as finished + $task->SetStopStatus(); } } diff --git a/app/Console/Commands/getLogisticContracts.php b/app/Console/Commands/getLogisticContracts.php index 0cbd334d3..b8bd4cf20 100644 --- a/app/Console/Commands/getLogisticContracts.php +++ b/app/Console/Commands/getLogisticContracts.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use DB; use Carbon\Carbon; +use Commands\Library\Helper; use App\Models\Logistics\Contract; use App\Models\ScheduleJob; @@ -47,18 +48,14 @@ class getLogisticContracts extends Command */ public function handle() { - $job = new ScheduleJob; - $time = Carbon::now(); - $job->job_name = "GetLogisticsContracts"; - $job->job_state = 'Starting'; - $job->system_time = $time; - $job-save(); + //Create the command helper container + $task = new CommandHelper('CorpJournal'); + //Add the entry into the jobs table saying the job is starting + $task->SetStartStatus(); //Create functionality to record contracts for logistical services - //If the job is finished we need to mark it in the table - DB::table('schedule_jobs')->where('system_time', $time)->update([ - 'job_state' => 'Finished', - ]); + //Mark the job as finished + $task->SetStopStatus(); } } diff --git a/app/Console/Commands/sendmail.php b/app/Console/Commands/sendmail.php index 0c1a4524b..af6071de0 100644 --- a/app/Console/Commands/sendmail.php +++ b/app/Console/Commands/sendmail.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use Carbon\Carbon; use DB; +use Commands\Library\CommandHelper; use App\Library\Esi; use App\Library\Mail; @@ -51,19 +52,14 @@ class sendMail extends Command */ public function handle() { - //Add an entry into the jobs table - $job = new ScheduleJob; - $time = Carbon::now(); - $job->job_name = 'SendMail'; - $job->job_state = 'Starting'; - $job->system_time = $time; - $job->save(); + //Create the command helper container + $task = new CommandHelper('CorpJournal'); + //Add the entry into the jobs table saying the job is starting + $task->SetStartStatus(); //Put our task in this section - //If the job is finished we need to mark it in the table - DB::table('schedule_jobs')->where('system_time', $time)->update([ - 'job_state' => 'Finished', - ]); + //Mark the job as finished + $task->SetStopStatus(); } } diff --git a/app/Http/Controllers/FleetsController.php b/app/Http/Controllers/FleetsController.php index 155a3dd54..8117096a2 100644 --- a/app/Http/Controllers/FleetsController.php +++ b/app/Http/Controllers/FleetsController.php @@ -8,28 +8,58 @@ use Auth; use DB; use Carbon\Carbon; -use App\Library\Fleets; +use App\Library\FleetHelper; use App\Library\Esi; use App\Models\Fleet\Fleet; +use App\Models\Fleet\FleetActivity; class FleetsController extends Controller { + /** + * Construction function + * + * returns nothing + */ public function __construct() { $this->middleware('auth'); $this->middleware('role:User'); } + + /** + * Records fleet activity when requested from the fleet info page + * + * @var fleetId + */ + public function recordFleetActivity($fleetId) { + $fleet = new FleetHelper(); + } + /** + * Displays the blade for registering a fleet + * + * @var (none) + */ public function displayRegisterFleet() { return view('fleets.registerfleet'); } + /** + * Work in progress. Doesn't do anything yet. + * + * @var (none) + */ public function displayFleetSetup() { return 0; } + /** + * Displays all currently recorded fleets + * + * @var (none) + */ public function displayFleets() { $fleets = Fleet::all(); $data = array(); @@ -55,16 +85,21 @@ class FleetsController extends Controller return view('fleets.displayfleets')->with('data', $data); } + /** + * Allows a person to register a fleet through services. + * + * @var Request + */ public function registerFleet(Request $request) { //Register a new instance of the fleet class - $fleet = new Fleets(Auth::user()->character_id); + $fleet = new FleetHelper(Auth::user()->character_id, $request->fleetUri); $esiHelper = new Esi(); if(!$esiHelper->HaveEsiScope(Auth::user()->character_id, 'esi-fleets.write_fleet.v1')) { return view('inc.error')->with('error', 'User does not have the write fleet scope.'); } //Make the fleet uri so we can call later functions - $fleetUri = $fleet->SetFleetUri($request->fleetUri); + $fleetUri = $fleet->GetFleetUri(); //Check for the fleet in the database $check = DB::table('Fleets')->where('fleet', $fleetUri)->first(); @@ -94,20 +129,31 @@ class FleetsController extends Controller 'creation_time' => $current, 'fleet_end' => $endTime, ]); - + //Is this line needed? $fleet->SetFleetEndTime($endTime); } return redirect('/fleets/display'); } + /** + * Deletes a fleet of fleetId + * + * @var fleetId + */ public function deleteFleet($fleetId) { DB::table('Fleets')->where('fleet', $fleetId)->delete(); return redirect('/fleets/display'); } + /** + * Add a pilot to the fleet + * + * @var fleetId + * @var charId + */ public function addPilot($fleetId, $charId) { - $newPilot = new Fleets(); + $newPilot = new FleetHelper(); //Retrieve the fleet data $fleet = DB::table('Fleets')->where('fleet', $fleetId)->get(); @@ -127,8 +173,14 @@ class FleetsController extends Controller } } + /** + * Add a pilot by his name rather than allowing him to click on the link + * + * @var fleetId + * @var name + */ public function addPilotName($fleetId, $name) { - $newPilot = new Fleets(); + $newPilot = new FleetHelper(); $esiHelper = new Esi(); //Retrieve the fleet data @@ -151,6 +203,11 @@ class FleetsController extends Controller } } + /** + * Update a fleet based on a session variable + * + * @var session + */ public function updateFleet() { //Retrieve the fleet from the session $fleet = session('fleet'); diff --git a/app/Library/Fleets.php b/app/Library/FleetHelper.php similarity index 98% rename from app/Library/Fleets.php rename to app/Library/FleetHelper.php index 7a6b3685a..48004bcb2 100644 --- a/app/Library/Fleets.php +++ b/app/Library/FleetHelper.php @@ -15,7 +15,7 @@ use Seat\Eseye\Configuration; use Seat\Eseye\Containers\EsiAuthentication; use Seat\Eseye\Eseye; -class Fleets { +class FleetHelper { private $fleet; private $fcId; @@ -42,7 +42,9 @@ class Fleets { //Trim the right side of the fleet number $fleetUri = rtrim($uris[1], '/?datasource=tranquility'); $this->fleet = $fleetUri; + } + public function GetFleetUri() { return $this->fleet; } diff --git a/app/Models/Fleet/FleetActivity.php b/app/Models/Fleet/FleetActivity.php new file mode 100644 index 000000000..26cf3cace --- /dev/null +++ b/app/Models/Fleet/FleetActivity.php @@ -0,0 +1,10 @@ +