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
This commit is contained in:
2018-12-03 13:00:58 -06:00
parent ae8f29c7ef
commit 8bbd83da90
10 changed files with 208 additions and 60 deletions

View File

@@ -0,0 +1,41 @@
<?php
namespace Commands\Library;
use DB;
use Carbon\Carbon;
class CommandHelper {
private $job_name;
private $job_state;
private $system_time;
public function __construct($name) {
$this->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',
]);
}
}
?>

View File

@@ -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();
}
}

View File

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

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
use Carbon\Carbon;
use App\Models\ScheduleJob;
class dumpFleets extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'services:dumpfleets';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command to remove all current fleets from the database';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
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();
//Mark the job as finished
$task->SetStopStatus();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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');

View File

@@ -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;
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class FleetActivity extends Model
{
//
}