Fix formatting and interfaces in nearly every file
This commit is contained in:
@@ -2,20 +2,25 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Interfaces\Service;
|
||||
use App\Models\Enums\AnalyticsDimensions;
|
||||
use DB;
|
||||
use Irazasyed\LaravelGAMP\Facades\GAMP;
|
||||
use Log;
|
||||
use PDO;
|
||||
|
||||
class AnalyticsService
|
||||
/**
|
||||
* Class AnalyticsService
|
||||
* @package App\Services
|
||||
*/
|
||||
class AnalyticsService extends Service
|
||||
{
|
||||
/**
|
||||
* Send out some stats about the install
|
||||
*/
|
||||
public function sendInstall()
|
||||
{
|
||||
if(config('app.analytics') === false) {
|
||||
if (config('app.analytics') === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -38,5 +43,4 @@ class AnalyticsService
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,16 +2,21 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Interfaces\Service;
|
||||
use App\Support\ClassLoader;
|
||||
use Module;
|
||||
|
||||
class AwardService
|
||||
/**
|
||||
* Class AwardService
|
||||
* @package App\Services
|
||||
*/
|
||||
class AwardService extends Service
|
||||
{
|
||||
/**
|
||||
* Find any of the award classes
|
||||
* @return \App\Interfaces\AwardInterface[]
|
||||
* @return \App\Interfaces\Award[]
|
||||
*/
|
||||
public function findAllAwardClasses()
|
||||
public function findAllAwardClasses(): array
|
||||
{
|
||||
$awards = [];
|
||||
$formatted_awards = [];
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
class BaseService {
|
||||
|
||||
}
|
||||
@@ -2,16 +2,19 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Interfaces\Service;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Webpatser\Uuid\Uuid;
|
||||
|
||||
|
||||
class DatabaseService extends BaseService
|
||||
/**
|
||||
* Class DatabaseService
|
||||
* @package App\Services
|
||||
*/
|
||||
class DatabaseService extends Service
|
||||
{
|
||||
|
||||
protected $time_fields = [
|
||||
'created_at',
|
||||
'updated_at'
|
||||
@@ -23,55 +26,57 @@ class DatabaseService extends BaseService
|
||||
'pireps',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function time(): string
|
||||
{
|
||||
return Carbon::now('UTC')->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $yaml_file
|
||||
* @param $yaml_file
|
||||
* @param bool $ignore_errors
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function seed_from_yaml_file($yaml_file, $ignore_errors=false): array
|
||||
public function seed_from_yaml_file($yaml_file, $ignore_errors = false): array
|
||||
{
|
||||
$yml = file_get_contents($yaml_file);
|
||||
|
||||
return $this->seed_from_yaml($yml, $ignore_errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $yml
|
||||
* @param $yml
|
||||
* @param bool $ignore_errors
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function seed_from_yaml($yml, $ignore_errors=false): array
|
||||
public function seed_from_yaml($yml, $ignore_errors = false): array
|
||||
{
|
||||
$imported = [];
|
||||
$yml = Yaml::parse($yml);
|
||||
foreach ($yml as $table => $rows) {
|
||||
|
||||
$imported[$table] = 0;
|
||||
|
||||
foreach ($rows as $row) {
|
||||
|
||||
# see if this table uses a UUID as the PK
|
||||
# if no ID is specified
|
||||
if(in_array($table, $this->uuid_tables)) {
|
||||
if(!array_key_exists('id', $row)) {
|
||||
if (in_array($table, $this->uuid_tables)) {
|
||||
if (!array_key_exists('id', $row)) {
|
||||
$row['id'] = Uuid::generate()->string;
|
||||
}
|
||||
}
|
||||
|
||||
# encrypt any password fields
|
||||
if(array_key_exists('password', $row)) {
|
||||
if (array_key_exists('password', $row)) {
|
||||
$row['password'] = bcrypt($row['password']);
|
||||
}
|
||||
|
||||
# if any time fields are == to "now", then insert the right time
|
||||
foreach($this->time_fields as $tf) {
|
||||
if(array_key_exists($tf, $row) && strtolower($row[$tf]) === 'now') {
|
||||
foreach ($this->time_fields as $tf) {
|
||||
if (array_key_exists($tf, $row) && strtolower($row[$tf]) === 'now') {
|
||||
$row[$tf] = $this->time();
|
||||
}
|
||||
}
|
||||
@@ -79,8 +84,8 @@ class DatabaseService extends BaseService
|
||||
try {
|
||||
DB::table($table)->insert($row);
|
||||
++$imported[$table];
|
||||
} catch(QueryException $e) {
|
||||
if($ignore_errors) {
|
||||
} catch (QueryException $e) {
|
||||
if ($ignore_errors) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Interfaces\Service;
|
||||
use App\Models\Fare;
|
||||
use App\Models\Flight;
|
||||
use App\Models\Pirep;
|
||||
@@ -14,7 +15,7 @@ use Illuminate\Support\Collection;
|
||||
* Class FareService
|
||||
* @package App\Services
|
||||
*/
|
||||
class FareService extends BaseService
|
||||
class FareService extends Service
|
||||
{
|
||||
/**
|
||||
* Get the fares for a particular flight, with an optional subfleet
|
||||
@@ -23,13 +24,13 @@ class FareService extends BaseService
|
||||
* final "authoritative" list of the fares for a flight.
|
||||
*
|
||||
* If a subfleet is passed in,
|
||||
* @param Flight|null $flight
|
||||
* @param Flight|null $flight
|
||||
* @param Subfleet|null $subfleet
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllFares($flight, $subfleet)
|
||||
{
|
||||
if(!$flight) {
|
||||
if (!$flight) {
|
||||
$flight_fares = collect();
|
||||
} else {
|
||||
$flight_fares = $this->getForFlight($flight);
|
||||
@@ -39,10 +40,9 @@ class FareService extends BaseService
|
||||
|
||||
# Go through all of the fares assigned by the subfleet
|
||||
# See if any of the same fares are assigned to the flight
|
||||
$fares = $subfleet_fares->map(function($fare, $idx) use ($flight_fares)
|
||||
{
|
||||
$fares = $subfleet_fares->map(function ($fare, $idx) use ($flight_fares) {
|
||||
$flight_fare = $flight_fares->whereStrict('id', $fare->id)->first();
|
||||
if(!$flight_fare) {
|
||||
if (!$flight_fare) {
|
||||
return $fare;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class FareService extends BaseService
|
||||
* Attach a fare to an flight
|
||||
*
|
||||
* @param Flight $flight
|
||||
* @param Fare $fare
|
||||
* @param Fare $fare
|
||||
* @param array set the price/cost/capacity
|
||||
* @return Flight
|
||||
*/
|
||||
@@ -105,6 +105,7 @@ class FareService extends BaseService
|
||||
|
||||
$flight->save();
|
||||
$flight->refresh();
|
||||
|
||||
return $flight;
|
||||
}
|
||||
|
||||
@@ -126,13 +127,14 @@ class FareService extends BaseService
|
||||
|
||||
/**
|
||||
* @param Flight $flight
|
||||
* @param Fare $fare
|
||||
* @param Fare $fare
|
||||
* @return Flight
|
||||
*/
|
||||
public function delFareFromFlight(Flight $flight, Fare $fare)
|
||||
{
|
||||
$flight->fares()->detach($fare->id);
|
||||
$flight->refresh();
|
||||
|
||||
return $flight;
|
||||
}
|
||||
|
||||
@@ -144,17 +146,18 @@ class FareService extends BaseService
|
||||
* @param array set the price/cost/capacity
|
||||
* @return Subfleet
|
||||
*/
|
||||
public function setForSubfleet(Subfleet $subfleet, Fare $fare, array $override=[]): Subfleet
|
||||
public function setForSubfleet(Subfleet $subfleet, Fare $fare, array $override = []): Subfleet
|
||||
{
|
||||
$subfleet->fares()->syncWithoutDetaching([$fare->id]);
|
||||
|
||||
# modify any pivot values?
|
||||
if(count($override) > 0) {
|
||||
if (count($override) > 0) {
|
||||
$subfleet->fares()->updateExistingPivot($fare->id, $override);
|
||||
}
|
||||
|
||||
$subfleet->save();
|
||||
$subfleet->refresh();
|
||||
|
||||
return $subfleet;
|
||||
}
|
||||
|
||||
@@ -167,7 +170,7 @@ class FareService extends BaseService
|
||||
*/
|
||||
public function getForSubfleet(Subfleet $subfleet)
|
||||
{
|
||||
$fares = $subfleet->fares->map(function($fare) {
|
||||
$fares = $subfleet->fares->map(function ($fare) {
|
||||
return $this->getFares($fare);
|
||||
});
|
||||
|
||||
@@ -177,13 +180,14 @@ class FareService extends BaseService
|
||||
/**
|
||||
* Delete the fare from a subfleet
|
||||
* @param Subfleet $subfleet
|
||||
* @param Fare $fare
|
||||
* @param Fare $fare
|
||||
* @return Subfleet|null|static
|
||||
*/
|
||||
public function delFareFromSubfleet(Subfleet &$subfleet, Fare &$fare)
|
||||
{
|
||||
$subfleet->fares()->detach($fare->id);
|
||||
$subfleet->refresh();
|
||||
|
||||
return $subfleet;
|
||||
}
|
||||
|
||||
@@ -197,6 +201,7 @@ class FareService extends BaseService
|
||||
{
|
||||
$fares = [];
|
||||
$found_fares = PirepFare::where('pirep_id', $pirep->id)->get();
|
||||
|
||||
return $found_fares;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
namespace App\Services\Finance;
|
||||
|
||||
use App\Events\Expenses as ExpensesEvent;
|
||||
use App\Interfaces\Service;
|
||||
use App\Models\Enums\ExpenseType;
|
||||
use App\Models\Enums\PirepSource;
|
||||
use App\Models\Expense;
|
||||
use App\Models\Pirep;
|
||||
use App\Repositories\ExpenseRepository;
|
||||
use App\Repositories\JournalRepository;
|
||||
use App\Services\BaseService;
|
||||
use App\Services\FareService;
|
||||
use App\Services\PirepService;
|
||||
use App\Support\Math;
|
||||
@@ -21,7 +21,7 @@ use Log;
|
||||
* @package App\Services
|
||||
*
|
||||
*/
|
||||
class PirepFinanceService extends BaseService
|
||||
class PirepFinanceService extends Service
|
||||
{
|
||||
private $expenseRepo,
|
||||
$fareSvc,
|
||||
@@ -31,16 +31,17 @@ class PirepFinanceService extends BaseService
|
||||
/**
|
||||
* FinanceService constructor.
|
||||
* @param ExpenseRepository $expenseRepo
|
||||
* @param FareService $fareSvc
|
||||
* @param FareService $fareSvc
|
||||
* @param JournalRepository $journalRepo
|
||||
* @param PirepService $pirepSvc
|
||||
* @param PirepService $pirepSvc
|
||||
*/
|
||||
public function __construct(
|
||||
ExpenseRepository $expenseRepo,
|
||||
FareService $fareSvc,
|
||||
JournalRepository $journalRepo,
|
||||
PirepService $pirepSvc
|
||||
) {
|
||||
)
|
||||
{
|
||||
$this->expenseRepo = $expenseRepo;
|
||||
$this->fareSvc = $fareSvc;
|
||||
$this->journalRepo = $journalRepo;
|
||||
@@ -59,7 +60,7 @@ class PirepFinanceService extends BaseService
|
||||
*/
|
||||
public function processFinancesForPirep(Pirep $pirep)
|
||||
{
|
||||
if(!$pirep->airline->journal) {
|
||||
if (!$pirep->airline->journal) {
|
||||
$pirep->airline->journal = $pirep->airline->initJournal(config('phpvms.currency'));
|
||||
}
|
||||
|
||||
@@ -108,7 +109,6 @@ class PirepFinanceService extends BaseService
|
||||
$fares = $this->getReconciledFaresForPirep($pirep);
|
||||
/** @var \App\Models\Fare $fare */
|
||||
foreach ($fares as $fare) {
|
||||
|
||||
Log::info('Finance: PIREP: '.$pirep->id.', fare:', $fare->toArray());
|
||||
|
||||
$credit = Money::createFromAmount($fare->count * $fare->price);
|
||||
@@ -119,8 +119,8 @@ class PirepFinanceService extends BaseService
|
||||
$credit,
|
||||
$debit,
|
||||
$pirep,
|
||||
'Fares ' . $fare->code . $fare->count
|
||||
.'; price: '.$fare->price.', cost: '.$fare->cost,
|
||||
'Fares '.$fare->code.$fare->count
|
||||
.'; price: '.$fare->price.', cost: '.$fare->cost,
|
||||
null,
|
||||
'Fares',
|
||||
'fare'
|
||||
@@ -145,8 +145,7 @@ class PirepFinanceService extends BaseService
|
||||
/**
|
||||
* Go through the expenses and apply a mulitplier if present
|
||||
*/
|
||||
$expenses->map(function ($expense, $i) use ($pirep)
|
||||
{
|
||||
$expenses->map(function ($expense, $i) use ($pirep) {
|
||||
/*if ($expense->multiplier) {
|
||||
# TODO: Modify the amount
|
||||
}*/
|
||||
@@ -157,7 +156,7 @@ class PirepFinanceService extends BaseService
|
||||
# This way it can be more dynamic and don't have to add special
|
||||
# tables or specific expense calls to accomodate all of these
|
||||
$klass = 'Expense';
|
||||
if($expense->ref_class) {
|
||||
if ($expense->ref_class) {
|
||||
$ref = explode('\\', $expense->ref_class);
|
||||
$klass = end($ref);
|
||||
}
|
||||
@@ -240,7 +239,7 @@ class PirepFinanceService extends BaseService
|
||||
null,
|
||||
$debit,
|
||||
$pirep,
|
||||
'Expense: ' . $expense->name,
|
||||
'Expense: '.$expense->name,
|
||||
null,
|
||||
$expense->transaction_group ?? 'Expenses',
|
||||
'expense'
|
||||
@@ -284,7 +283,7 @@ class PirepFinanceService extends BaseService
|
||||
{
|
||||
$pilot_pay = $this->getPilotPay($pirep);
|
||||
$pilot_pay_rate = $this->getPilotPayRateForPirep($pirep);
|
||||
$memo = 'Pilot Payment @ ' . $pilot_pay_rate;
|
||||
$memo = 'Pilot Payment @ '.$pilot_pay_rate;
|
||||
|
||||
Log::info('Finance: PIREP: '.$pirep->id
|
||||
.'; pilot pay: '.$pilot_pay_rate.', total: '.$pilot_pay);
|
||||
@@ -329,29 +328,27 @@ class PirepFinanceService extends BaseService
|
||||
{
|
||||
# Collect all of the fares and prices
|
||||
$flight_fares = $this->fareSvc->getForPirep($pirep);
|
||||
Log::info('Finance: PIREP: ' . $pirep->id . ', flight fares: ', $flight_fares->toArray());
|
||||
Log::info('Finance: PIREP: '.$pirep->id.', flight fares: ', $flight_fares->toArray());
|
||||
|
||||
$all_fares = $this->fareSvc->getAllFares($pirep->flight, $pirep->aircraft->subfleet);
|
||||
|
||||
$fares = $all_fares->map(function($fare, $i) use ($flight_fares, $pirep) {
|
||||
|
||||
$fares = $all_fares->map(function ($fare, $i) use ($flight_fares, $pirep) {
|
||||
$fare_count = $flight_fares
|
||||
->where('fare_id', $fare->id)
|
||||
->first();
|
||||
|
||||
if($fare_count) {
|
||||
|
||||
Log::info('Finance: PIREP: ' . $pirep->id . ', fare count: '. $fare_count);
|
||||
if ($fare_count) {
|
||||
Log::info('Finance: PIREP: '.$pirep->id.', fare count: '.$fare_count);
|
||||
|
||||
# If the count is greater than capacity, then just set it
|
||||
# to the maximum amount
|
||||
if($fare_count->count > $fare->capacity) {
|
||||
if ($fare_count->count > $fare->capacity) {
|
||||
$fare->count = $fare->capacity;
|
||||
} else {
|
||||
$fare->count = $fare_count->count;
|
||||
}
|
||||
} else {
|
||||
Log::info('Finance: PIREP: ' . $pirep->id . ', no fare count found', $fare->toArray());
|
||||
Log::info('Finance: PIREP: '.$pirep->id.', no fare count found', $fare->toArray());
|
||||
}
|
||||
|
||||
return $fare;
|
||||
@@ -368,9 +365,10 @@ class PirepFinanceService extends BaseService
|
||||
*/
|
||||
public function getGroundHandlingCost(Pirep $pirep)
|
||||
{
|
||||
if(filled($pirep->aircraft->subfleet->ground_handling_multiplier)) {
|
||||
if (filled($pirep->aircraft->subfleet->ground_handling_multiplier)) {
|
||||
// force into percent mode
|
||||
$multiplier = $pirep->aircraft->subfleet->ground_handling_multiplier.'%';
|
||||
|
||||
return Math::applyAmountOrPercent(
|
||||
$pirep->arr_airport->ground_handling_cost,
|
||||
$multiplier
|
||||
@@ -397,28 +395,28 @@ class PirepFinanceService extends BaseService
|
||||
->where('subfleet_id', $subfleet_id)
|
||||
->first();
|
||||
|
||||
if($override_rate) {
|
||||
if ($override_rate) {
|
||||
$override_rate = $override_rate->pivot;
|
||||
}
|
||||
|
||||
if($pirep->source === PirepSource::ACARS) {
|
||||
if ($pirep->source === PirepSource::ACARS) {
|
||||
Log::debug('Source is ACARS');
|
||||
$base_rate = $rank->acars_base_pay_rate;
|
||||
|
||||
if($override_rate) {
|
||||
if ($override_rate) {
|
||||
$override_rate = $override_rate->acars_pay;
|
||||
}
|
||||
|
||||
} else {
|
||||
Log::debug('Source is Manual');
|
||||
$base_rate = $rank->manual_base_pay_rate;
|
||||
|
||||
if($override_rate) {
|
||||
if ($override_rate) {
|
||||
$override_rate = $override_rate->manual_pay;
|
||||
}
|
||||
}
|
||||
|
||||
Log::debug('pilot pay: base rate=' . $base_rate . ', override=' . $override_rate);
|
||||
Log::debug('pilot pay: base rate='.$base_rate.', override='.$override_rate);
|
||||
|
||||
return Math::applyAmountOrPercent(
|
||||
$base_rate,
|
||||
$override_rate
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Services\Finance;
|
||||
|
||||
use App\Interfaces\Service;
|
||||
use App\Models\Airline;
|
||||
use App\Models\Enums\ExpenseType;
|
||||
use App\Models\Expense;
|
||||
use App\Models\JournalTransaction;
|
||||
use App\Repositories\JournalRepository;
|
||||
use App\Services\BaseService;
|
||||
use App\Support\Money;
|
||||
use Log;
|
||||
|
||||
@@ -15,10 +15,14 @@ use Log;
|
||||
* Process all of the daily expenses and charge them
|
||||
* @package App\Services\Finance
|
||||
*/
|
||||
class RecurringFinanceService extends BaseService
|
||||
class RecurringFinanceService extends Service
|
||||
{
|
||||
private $journalRepo;
|
||||
|
||||
/**
|
||||
* RecurringFinanceService constructor.
|
||||
* @param JournalRepository $journalRepo
|
||||
*/
|
||||
public function __construct(JournalRepository $journalRepo)
|
||||
{
|
||||
$this->journalRepo = $journalRepo;
|
||||
@@ -32,14 +36,14 @@ class RecurringFinanceService extends BaseService
|
||||
*/
|
||||
protected function findJournals(Expense $expense)
|
||||
{
|
||||
if($expense->airline_id) {
|
||||
if ($expense->airline_id) {
|
||||
$airline = Airline::find($expense->airline_id)->first(['id', 'icao']);
|
||||
Log::info('Charging to ' . $airline->icao);
|
||||
Log::info('Charging to '.$airline->icao);
|
||||
yield $airline->journal;
|
||||
} else {
|
||||
$airlines = Airline::all(['id', 'icao']);
|
||||
foreach($airlines as $airline) {
|
||||
Log::info('Charging to ' . $airline->icao);
|
||||
foreach ($airlines as $airline) {
|
||||
Log::info('Charging to '.$airline->icao);
|
||||
yield $airline->journal;
|
||||
}
|
||||
}
|
||||
@@ -76,7 +80,6 @@ class RecurringFinanceService extends BaseService
|
||||
return [$memo, $transaction_group];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run all of the daily expense/financials
|
||||
* @param int $type
|
||||
@@ -84,12 +87,12 @@ class RecurringFinanceService extends BaseService
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*/
|
||||
public function processExpenses($type=ExpenseType::DAILY): void
|
||||
public function processExpenses($type = ExpenseType::DAILY): void
|
||||
{
|
||||
$expenses = Expense::where(['type' => $type])->get();
|
||||
|
||||
$tag = 'expense_recurring';
|
||||
if($type === ExpenseType::DAILY) {
|
||||
if ($type === ExpenseType::DAILY) {
|
||||
$tag = 'expenses_daily';
|
||||
} elseif ($type === ExpenseType::MONTHLY) {
|
||||
$tag === 'expenses_monthly';
|
||||
@@ -99,18 +102,16 @@ class RecurringFinanceService extends BaseService
|
||||
* @var $expenses Expense[]
|
||||
*/
|
||||
foreach ($expenses as $expense) {
|
||||
|
||||
# Apply the expenses to the appropriate journals
|
||||
$journals = $this->findJournals($expense);
|
||||
foreach($journals as $journal) {
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$amount = $expense->amount;
|
||||
|
||||
# Has this expense already been charged? Check
|
||||
# against this specific journal, on today
|
||||
$w = [
|
||||
'journal_id' => $journal->id,
|
||||
'ref_class' => Expense::class,
|
||||
'journal_id' => $journal->id,
|
||||
'ref_class' => Expense::class,
|
||||
'ref_class_id' => $expense->id,
|
||||
];
|
||||
|
||||
@@ -118,7 +119,7 @@ class RecurringFinanceService extends BaseService
|
||||
->whereDate('post_date', '=', \Carbon::now('UTC')->toDateString())
|
||||
->count(['id']);
|
||||
|
||||
if($found > 0) {
|
||||
if ($found > 0) {
|
||||
Log::info('Expense "'.$expense->name.'" already charged for today, skipping');
|
||||
continue;
|
||||
}
|
||||
@@ -136,7 +137,7 @@ class RecurringFinanceService extends BaseService
|
||||
$tag
|
||||
);
|
||||
|
||||
Log::info('Expense memo: "'.$memo.'"; group: "'. $ta_group. '" charged!');
|
||||
Log::info('Expense memo: "'.$memo.'"; group: "'.$ta_group.'" charged!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,27 +2,33 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Interfaces\Service;
|
||||
use App\Models\Rank;
|
||||
use App\Models\Subfleet;
|
||||
|
||||
class FleetService extends BaseService
|
||||
/**
|
||||
* Class FleetService
|
||||
* @package App\Services
|
||||
*/
|
||||
class FleetService extends Service
|
||||
{
|
||||
/**
|
||||
* @param Subfleet $subfleet
|
||||
* @param Rank $rank
|
||||
* @param array $overrides
|
||||
* @param Rank $rank
|
||||
* @param array $overrides
|
||||
* @return Subfleet
|
||||
*/
|
||||
public function addSubfleetToRank(Subfleet $subfleet, Rank $rank, array $overrides=[])
|
||||
public function addSubfleetToRank(Subfleet $subfleet, Rank $rank, array $overrides = [])
|
||||
{
|
||||
$subfleet->ranks()->syncWithoutDetaching([$rank->id]);
|
||||
|
||||
if($overrides) {
|
||||
if ($overrides) {
|
||||
$subfleet->ranks()->updateExistingPivot($rank->id, $overrides);
|
||||
}
|
||||
|
||||
$subfleet->save();
|
||||
$subfleet->refresh();
|
||||
|
||||
return $subfleet;
|
||||
}
|
||||
|
||||
@@ -32,6 +38,7 @@ class FleetService extends BaseService
|
||||
|
||||
$subfleet->save();
|
||||
$subfleet->refresh();
|
||||
|
||||
return $subfleet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Exceptions\BidExists;
|
||||
use App\Models\Flight;
|
||||
use App\Models\Subfleet;
|
||||
use App\Models\User;
|
||||
use App\Interfaces\Service;
|
||||
use App\Models\Bid;
|
||||
use App\Models\Flight;
|
||||
use App\Models\User;
|
||||
use App\Repositories\FlightRepository;
|
||||
use App\Repositories\NavdataRepository;
|
||||
use Log;
|
||||
@@ -15,20 +15,26 @@ use Log;
|
||||
* Class FlightService
|
||||
* @package App\Services
|
||||
*/
|
||||
class FlightService extends BaseService
|
||||
class FlightService extends Service
|
||||
{
|
||||
private $fareSvc,
|
||||
$flightRepo,
|
||||
$navDataRepo,
|
||||
$userSvc;
|
||||
$flightRepo,
|
||||
$navDataRepo,
|
||||
$userSvc;
|
||||
|
||||
/**
|
||||
* FlightService constructor.
|
||||
* @param FareService $fareSvc
|
||||
* @param FlightRepository $flightRepo
|
||||
* @param NavdataRepository $navdataRepo
|
||||
* @param UserService $userSvc
|
||||
*/
|
||||
public function __construct(
|
||||
FareService $fareSvc,
|
||||
FlightRepository $flightRepo,
|
||||
NavdataRepository $navdataRepo,
|
||||
UserService $userSvc
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->fareSvc = $fareSvc;
|
||||
$this->flightRepo = $flightRepo;
|
||||
$this->navDataRepo = $navdataRepo;
|
||||
@@ -59,7 +65,6 @@ class FlightService extends BaseService
|
||||
*/
|
||||
public function filterSubfleets($user, $flight)
|
||||
{
|
||||
|
||||
$subfleets = $flight->subfleets;
|
||||
|
||||
/**
|
||||
@@ -135,7 +140,7 @@ class FlightService extends BaseService
|
||||
/**
|
||||
* Allow a user to bid on a flight. Check settings and all that good stuff
|
||||
* @param Flight $flight
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
* @return Bid|null
|
||||
* @throws \App\Exceptions\BidExists
|
||||
*/
|
||||
@@ -143,7 +148,7 @@ class FlightService extends BaseService
|
||||
{
|
||||
# If it's already been bid on, then it can't be bid on again
|
||||
if ($flight->has_bid && setting('bids.disable_flight_on_bid')) {
|
||||
Log::info($flight->id . ' already has a bid, skipping');
|
||||
Log::info($flight->id.' already has a bid, skipping');
|
||||
throw new BidExists();
|
||||
}
|
||||
|
||||
@@ -151,14 +156,14 @@ class FlightService extends BaseService
|
||||
if (!setting('bids.allow_multiple_bids')) {
|
||||
$user_bids = Bid::where(['user_id' => $user->id])->first();
|
||||
if ($user_bids) {
|
||||
Log::info('User "' . $user->id . '" already has bids, skipping');
|
||||
Log::info('User "'.$user->id.'" already has bids, skipping');
|
||||
throw new BidExists();
|
||||
}
|
||||
}
|
||||
|
||||
# See if this user has this flight bid on already
|
||||
$bid_data = [
|
||||
'user_id' => $user->id,
|
||||
'user_id' => $user->id,
|
||||
'flight_id' => $flight->id
|
||||
];
|
||||
|
||||
@@ -178,7 +183,7 @@ class FlightService extends BaseService
|
||||
/**
|
||||
* Remove a bid from a given flight
|
||||
* @param Flight $flight
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
*/
|
||||
public function removeBid(Flight $flight, User $user)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Interfaces\Service;
|
||||
use App\Models\Acars;
|
||||
use App\Models\Enums\AcarsType;
|
||||
use App\Models\Flight;
|
||||
@@ -19,10 +20,15 @@ use Log;
|
||||
* Class GeoService
|
||||
* @package App\Services
|
||||
*/
|
||||
class GeoService extends BaseService
|
||||
class GeoService extends Service
|
||||
{
|
||||
private $acarsRepo, $navRepo;
|
||||
|
||||
/**
|
||||
* GeoService constructor.
|
||||
* @param AcarsRepository $acarsRepo
|
||||
* @param NavdataRepository $navRepo
|
||||
*/
|
||||
public function __construct(
|
||||
AcarsRepository $acarsRepo,
|
||||
NavdataRepository $navRepo
|
||||
@@ -44,7 +50,7 @@ class GeoService extends BaseService
|
||||
$geotools = new Geotools();
|
||||
$start = new Coordinate($coordStart);
|
||||
|
||||
foreach($all_coords as $coords) {
|
||||
foreach ($all_coords as $coords) {
|
||||
$coord = new Coordinate($coords);
|
||||
$dist = $geotools->distance()->setFrom($start)->setTo($coord);
|
||||
$distance[] = $dist->greatCircle();
|
||||
@@ -52,7 +58,8 @@ class GeoService extends BaseService
|
||||
|
||||
$distance = collect($distance);
|
||||
$min = $distance->min();
|
||||
return $all_coords[ $distance->search($min, true) ];
|
||||
|
||||
return $all_coords[$distance->search($min, true)];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,10 +77,13 @@ class GeoService extends BaseService
|
||||
$coords = [];
|
||||
$filter_points = [$dep_icao, $arr_icao, 'SID', 'STAR'];
|
||||
|
||||
$split_route = collect(explode(' ', $route))->transform(function($point) {
|
||||
if(empty($point)) { return false; }
|
||||
$split_route = collect(explode(' ', $route))->transform(function ($point) {
|
||||
if (empty($point)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strtoupper(trim($point));
|
||||
})->filter(function($point) use ($filter_points) {
|
||||
})->filter(function ($point) use ($filter_points) {
|
||||
return !(empty($point) || \in_array($point, $filter_points, true));
|
||||
});
|
||||
|
||||
@@ -81,13 +91,12 @@ class GeoService extends BaseService
|
||||
* @var $split_route Collection
|
||||
* @var $route_point Acars
|
||||
*/
|
||||
foreach ($split_route as $route_point)
|
||||
{
|
||||
Log::debug('Looking for ' . $route_point);
|
||||
foreach ($split_route as $route_point) {
|
||||
Log::debug('Looking for '.$route_point);
|
||||
|
||||
try {
|
||||
$points = $this->navRepo->findWhere(['id' => $route_point]);
|
||||
} catch(ModelNotFoundException $e){
|
||||
} catch (ModelNotFoundException $e) {
|
||||
continue;
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
@@ -100,13 +109,13 @@ class GeoService extends BaseService
|
||||
continue;
|
||||
} elseif ($size === 1) {
|
||||
$point = $points[0];
|
||||
Log::debug('name: ' . $point->id . ' - ' . $point->lat . 'x' . $point->lon);
|
||||
Log::debug('name: '.$point->id.' - '.$point->lat.'x'.$point->lon);
|
||||
$coords[] = $point;
|
||||
continue;
|
||||
}
|
||||
|
||||
# Find the point with the shortest distance
|
||||
Log::info('found ' . $size . ' for '. $route_point);
|
||||
Log::info('found '.$size.' for '.$route_point);
|
||||
|
||||
# Get the start point and then reverse the lat/lon reference
|
||||
# If the first point happens to have multiple possibilities, use
|
||||
@@ -121,14 +130,14 @@ class GeoService extends BaseService
|
||||
# Put all of the lat/lon sets into an array to pick of what's clsest
|
||||
# to the starting point
|
||||
$potential_coords = [];
|
||||
foreach($points as $point) {
|
||||
foreach ($points as $point) {
|
||||
$potential_coords[] = [$point->lat, $point->lon];
|
||||
}
|
||||
|
||||
# returns an array with the closest lat/lon to start point
|
||||
$closest_coords = $this->getClosestCoords($start_point, $potential_coords);
|
||||
foreach($points as $point) {
|
||||
if($point->lat === $closest_coords[0] && $point->lon === $closest_coords[1]) {
|
||||
foreach ($points as $point) {
|
||||
if ($point->lat === $closest_coords[0] && $point->lon === $closest_coords[1]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -181,14 +190,13 @@ class GeoService extends BaseService
|
||||
foreach ($pirep->acars as $point) {
|
||||
$route->addPoint($point->lat, $point->lon, [
|
||||
'pirep_id' => $pirep->id,
|
||||
'name' => $point->altitude,
|
||||
'popup' => $counter . '<br />GS: ' . $point->gs . '<br />Alt: ' . $point->altitude,
|
||||
'name' => $point->altitude,
|
||||
'popup' => $counter.'<br />GS: '.$point->gs.'<br />Alt: '.$point->altitude,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
return [
|
||||
'line' => $route->getLine(),
|
||||
'line' => $route->getLine(),
|
||||
'points' => $route->getPoints()
|
||||
];
|
||||
}
|
||||
@@ -203,22 +211,21 @@ class GeoService extends BaseService
|
||||
/**
|
||||
* @var Pirep $pirep
|
||||
*/
|
||||
foreach($pireps as $pirep) {
|
||||
|
||||
foreach ($pireps as $pirep) {
|
||||
/**
|
||||
* @var $point \App\Models\Acars
|
||||
*/
|
||||
$point = $pirep->position;
|
||||
if(!$point) {
|
||||
if (!$point) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$flight->addPoint($point->lat, $point->lon, [
|
||||
'pirep_id' => $pirep->id,
|
||||
'gs' => $point->gs,
|
||||
'alt' => $point->altitude,
|
||||
'heading' => $point->heading ?: 0,
|
||||
'popup' => $pirep->ident . '<br />GS: ' . $point->gs . '<br />Alt: ' . $point->altitude,
|
||||
'pirep_id' => $pirep->id,
|
||||
'gs' => $point->gs,
|
||||
'alt' => $point->altitude,
|
||||
'heading' => $point->heading ?: 0,
|
||||
'popup' => $pirep->ident.'<br />GS: '.$point->gs.'<br />Alt: '.$point->altitude,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -236,12 +243,12 @@ class GeoService extends BaseService
|
||||
|
||||
## Departure Airport
|
||||
$route->addPoint($flight->dpt_airport->lat, $flight->dpt_airport->lon, [
|
||||
'name' => $flight->dpt_airport->icao,
|
||||
'name' => $flight->dpt_airport->icao,
|
||||
'popup' => $flight->dpt_airport->full_name,
|
||||
'icon' => 'airport',
|
||||
'icon' => 'airport',
|
||||
]);
|
||||
|
||||
if($flight->route) {
|
||||
if ($flight->route) {
|
||||
$all_route_points = $this->getCoordsFromRoute(
|
||||
$flight->dpt_airport->icao,
|
||||
$flight->arr_airport->icao,
|
||||
@@ -249,10 +256,10 @@ class GeoService extends BaseService
|
||||
$flight->route);
|
||||
|
||||
// lat, lon needs to be reversed for GeoJSON
|
||||
foreach($all_route_points as $point) {
|
||||
foreach ($all_route_points as $point) {
|
||||
$route->addPoint($point->lat, $point->lon, [
|
||||
'name' => $point->name,
|
||||
'popup' => $point->name . ' (' . $point->name . ')',
|
||||
'popup' => $point->name.' ('.$point->name.')',
|
||||
'icon' => ''
|
||||
]);
|
||||
}
|
||||
@@ -265,8 +272,8 @@ class GeoService extends BaseService
|
||||
]);
|
||||
|
||||
return [
|
||||
'route_points' => $route->getPoints(),
|
||||
'planned_route_line' => $route->getLine(),
|
||||
'route_points' => $route->getPoints(),
|
||||
'planned_route_line' => $route->getLine(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -284,22 +291,22 @@ class GeoService extends BaseService
|
||||
* PLANNED ROUTE
|
||||
*/
|
||||
$planned->addPoint($pirep->dpt_airport->lat, $pirep->dpt_airport->lon, [
|
||||
'name' => $pirep->dpt_airport->icao,
|
||||
'name' => $pirep->dpt_airport->icao,
|
||||
'popup' => $pirep->dpt_airport->full_name,
|
||||
]);
|
||||
|
||||
$planned_route = $this->acarsRepo->forPirep($pirep->id, AcarsType::ROUTE);
|
||||
foreach($planned_route as $point) {
|
||||
foreach ($planned_route as $point) {
|
||||
$planned->addPoint($point->lat, $point->lon, [
|
||||
'name' => $point->name,
|
||||
'popup' => $point->name . ' (' . $point->name . ')',
|
||||
'name' => $point->name,
|
||||
'popup' => $point->name.' ('.$point->name.')',
|
||||
]);
|
||||
}
|
||||
|
||||
$planned->addPoint($pirep->arr_airport->lat, $pirep->arr_airport->lon, [
|
||||
'name' => $pirep->arr_airport->icao,
|
||||
'name' => $pirep->arr_airport->icao,
|
||||
'popup' => $pirep->arr_airport->full_name,
|
||||
'icon' => 'airport',
|
||||
'icon' => 'airport',
|
||||
]);
|
||||
|
||||
/**
|
||||
@@ -309,14 +316,14 @@ class GeoService extends BaseService
|
||||
foreach ($actual_route as $point) {
|
||||
$actual->addPoint($point->lat, $point->lon, [
|
||||
'pirep_id' => $pirep->id,
|
||||
'name' => $point->altitude,
|
||||
'popup' => 'GS: ' . $point->gs . '<br />Alt: ' . $point->altitude,
|
||||
'name' => $point->altitude,
|
||||
'popup' => 'GS: '.$point->gs.'<br />Alt: '.$point->altitude,
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
'planned_rte_points' => $planned->getPoints(),
|
||||
'planned_rte_line' => $planned->getLine(),
|
||||
'planned_rte_points' => $planned->getPoints(),
|
||||
'planned_rte_line' => $planned->getLine(),
|
||||
|
||||
'actual_route_points' => $actual->getPoints(),
|
||||
'actual_route_line' => $actual->getLine(),
|
||||
|
||||
@@ -2,16 +2,21 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Interfaces\Service;
|
||||
use App\Repositories\FlightRepository;
|
||||
|
||||
/**
|
||||
* Class ImporterService
|
||||
* @package App\Services
|
||||
*/
|
||||
class ImporterService extends BaseService
|
||||
class ImporterService extends Service
|
||||
{
|
||||
protected $flightRepo;
|
||||
|
||||
/**
|
||||
* ImporterService constructor.
|
||||
* @param FlightRepository $flightRepo
|
||||
*/
|
||||
public function __construct(
|
||||
FlightRepository $flightRepo
|
||||
) {
|
||||
@@ -20,13 +25,13 @@ class ImporterService extends BaseService
|
||||
|
||||
/**
|
||||
* Set a key-value pair to an array
|
||||
* @param $kvp_str
|
||||
* @param $kvp_str
|
||||
* @param array $arr
|
||||
*/
|
||||
protected function setKvp($kvp_str, array &$arr)
|
||||
{
|
||||
$item = explode('=', $kvp_str);
|
||||
if(\count($item) === 1) { # just a list?
|
||||
if (\count($item) === 1) { # just a list?
|
||||
$arr[] = trim($item[0]);
|
||||
} else { # actually a key-value pair
|
||||
$k = trim($item[0]);
|
||||
@@ -52,15 +57,14 @@ class ImporterService extends BaseService
|
||||
$split_values = explode(';', $field);
|
||||
|
||||
# No multiple values in here, just a straight value
|
||||
if(\count($split_values) === 1) {
|
||||
if (\count($split_values) === 1) {
|
||||
return $split_values[0];
|
||||
}
|
||||
|
||||
foreach($split_values as $value) {
|
||||
|
||||
foreach ($split_values as $value) {
|
||||
# This isn't in the query string format, so it's
|
||||
# just a straight key-value pair set
|
||||
if(strpos($value, '?') === false) {
|
||||
if (strpos($value, '?') === false) {
|
||||
$this->setKvp($value, $ret);
|
||||
continue;
|
||||
}
|
||||
@@ -73,7 +77,7 @@ class ImporterService extends BaseService
|
||||
|
||||
$children = [];
|
||||
$kvp = explode('&', trim($query_str[1]));
|
||||
foreach($kvp as $items) {
|
||||
foreach ($kvp as $items) {
|
||||
$this->setKvp($items, $children);
|
||||
}
|
||||
|
||||
@@ -85,11 +89,10 @@ class ImporterService extends BaseService
|
||||
|
||||
/**
|
||||
* Import flights
|
||||
* @param $csv_str
|
||||
* @param $csv_str
|
||||
* @param bool $delete_previous
|
||||
*/
|
||||
public function importFlights($csv_str, bool $delete_previous=true)
|
||||
public function importFlights($csv_str, bool $delete_previous = true)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,23 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class ModuleService extends BaseService
|
||||
use App\Interfaces\Service;
|
||||
|
||||
/**
|
||||
* Class ModuleService
|
||||
* @package App\Services
|
||||
*/
|
||||
class ModuleService extends Service
|
||||
{
|
||||
protected static $adminLinks = [];
|
||||
|
||||
/**
|
||||
* @var array 0 == logged out, 1 == logged in
|
||||
*/
|
||||
protected static $frontendLinks = [0 => [], 1 => []];
|
||||
|
||||
protected static $frontendLinks = [
|
||||
0 => [],
|
||||
1 => []
|
||||
];
|
||||
|
||||
/**
|
||||
* Add a module link in the frontend
|
||||
@@ -18,12 +26,12 @@ class ModuleService extends BaseService
|
||||
* @param string $url
|
||||
* @param string $icon
|
||||
*/
|
||||
public function addFrontendLink(string $title, string $url, string $icon = '', $logged_in=true)
|
||||
public function addFrontendLink(string $title, string $url, string $icon = '', $logged_in = true)
|
||||
{
|
||||
self::$frontendLinks[$logged_in][] = [
|
||||
'title' => $title,
|
||||
'url' => $url,
|
||||
'icon' => 'pe-7s-users',
|
||||
'url' => $url,
|
||||
'icon' => 'pe-7s-users',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -42,12 +50,12 @@ class ModuleService extends BaseService
|
||||
* @param string $url
|
||||
* @param string $icon
|
||||
*/
|
||||
public function addAdminLink(string $title, string $url, string $icon='')
|
||||
public function addAdminLink(string $title, string $url, string $icon = '')
|
||||
{
|
||||
self::$adminLinks[] = [
|
||||
'title' => $title,
|
||||
'url' => $url,
|
||||
'icon' => 'pe-7s-users'
|
||||
'url' => $url,
|
||||
'icon' => 'pe-7s-users'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Events\PirepAccepted;
|
||||
use App\Events\PirepFiled;
|
||||
use App\Events\PirepRejected;
|
||||
use App\Events\UserStatsChanged;
|
||||
use App\Interfaces\Service;
|
||||
use App\Models\Acars;
|
||||
use App\Models\Bid;
|
||||
use App\Models\Enums\AcarsType;
|
||||
@@ -27,23 +28,23 @@ use Log;
|
||||
* Class PirepService
|
||||
* @package App\Services
|
||||
*/
|
||||
class PirepService extends BaseService
|
||||
class PirepService extends Service
|
||||
{
|
||||
private $acarsRepo,
|
||||
$flightRepo,
|
||||
$geoSvc,
|
||||
$navRepo,
|
||||
$pilotSvc,
|
||||
$pirepRepo;
|
||||
$flightRepo,
|
||||
$geoSvc,
|
||||
$navRepo,
|
||||
$pilotSvc,
|
||||
$pirepRepo;
|
||||
|
||||
/**
|
||||
* PirepService constructor.
|
||||
* @param AcarsRepository $acarsRepo
|
||||
* @param FlightRepository $flightRepo
|
||||
* @param GeoService $geoSvc
|
||||
* @param AcarsRepository $acarsRepo
|
||||
* @param FlightRepository $flightRepo
|
||||
* @param GeoService $geoSvc
|
||||
* @param NavdataRepository $navRepo
|
||||
* @param PirepRepository $pirepRepo
|
||||
* @param UserService $pilotSvc
|
||||
* @param PirepRepository $pirepRepo
|
||||
* @param UserService $pilotSvc
|
||||
*/
|
||||
public function __construct(
|
||||
AcarsRepository $acarsRepo,
|
||||
@@ -52,8 +53,7 @@ class PirepService extends BaseService
|
||||
NavdataRepository $navRepo,
|
||||
PirepRepository $pirepRepo,
|
||||
UserService $pilotSvc
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->acarsRepo = $acarsRepo;
|
||||
$this->flightRepo = $flightRepo;
|
||||
$this->geoSvc = $geoSvc;
|
||||
@@ -74,8 +74,8 @@ class PirepService extends BaseService
|
||||
$time_limit = Carbon::now()->subMinutes($minutes)->toDateTimeString();
|
||||
|
||||
$where = [
|
||||
'user_id' => $pirep->user_id,
|
||||
'airline_id' => $pirep->airline_id,
|
||||
'user_id' => $pirep->user_id,
|
||||
'airline_id' => $pirep->airline_id,
|
||||
'flight_number' => $pirep->flight_number,
|
||||
];
|
||||
|
||||
@@ -114,7 +114,7 @@ class PirepService extends BaseService
|
||||
# Delete all the existing nav points
|
||||
Acars::where([
|
||||
'pirep_id' => $pirep->id,
|
||||
'type' => AcarsType::ROUTE,
|
||||
'type' => AcarsType::ROUTE,
|
||||
])->delete();
|
||||
|
||||
# See if a route exists
|
||||
@@ -123,7 +123,8 @@ class PirepService extends BaseService
|
||||
}
|
||||
|
||||
if (!filled($pirep->dpt_airport)) {
|
||||
Log::error('saveRoute: dpt_airport not found: ' . $pirep->dpt_airport_id);
|
||||
Log::error('saveRoute: dpt_airport not found: '.$pirep->dpt_airport_id);
|
||||
|
||||
return $pirep;
|
||||
}
|
||||
|
||||
@@ -203,7 +204,7 @@ class PirepService extends BaseService
|
||||
|
||||
/**
|
||||
* Update any custom PIREP fields
|
||||
* @param $pirep_id
|
||||
* @param $pirep_id
|
||||
* @param array $field_values
|
||||
*/
|
||||
public function updateCustomFields($pirep_id, array $field_values)
|
||||
@@ -211,10 +212,10 @@ class PirepService extends BaseService
|
||||
foreach ($field_values as $fv) {
|
||||
PirepFieldValues::updateOrCreate(
|
||||
['pirep_id' => $pirep_id,
|
||||
'name' => $fv['name']
|
||||
'name' => $fv['name']
|
||||
],
|
||||
['value' => $fv['value'],
|
||||
'source' => $fv['source']
|
||||
['value' => $fv['value'],
|
||||
'source' => $fv['source']
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -222,12 +223,12 @@ class PirepService extends BaseService
|
||||
|
||||
/**
|
||||
* @param Pirep $pirep
|
||||
* @param int $new_state
|
||||
* @param int $new_state
|
||||
* @return Pirep
|
||||
*/
|
||||
public function changeState(Pirep $pirep, int $new_state)
|
||||
{
|
||||
Log::info('PIREP ' . $pirep->id . ' state change from ' . $pirep->state . ' to ' . $new_state);
|
||||
Log::info('PIREP '.$pirep->id.' state change from '.$pirep->state.' to '.$new_state);
|
||||
|
||||
if ($pirep->state === $new_state) {
|
||||
return $pirep;
|
||||
@@ -249,12 +250,14 @@ class PirepService extends BaseService
|
||||
*/
|
||||
elseif ($pirep->state === PirepState::ACCEPTED) {
|
||||
$pirep = $this->reject($pirep);
|
||||
|
||||
return $pirep;
|
||||
} /**
|
||||
* Move from REJECTED to ACCEPTED
|
||||
*/
|
||||
elseif ($pirep->state === PirepState::REJECTED) {
|
||||
$pirep = $this->accept($pirep);
|
||||
|
||||
return $pirep;
|
||||
}
|
||||
|
||||
@@ -285,7 +288,7 @@ class PirepService extends BaseService
|
||||
$pirep->save();
|
||||
$pirep->refresh();
|
||||
|
||||
Log::info('PIREP ' . $pirep->id . ' state change to ACCEPTED');
|
||||
Log::info('PIREP '.$pirep->id.' state change to ACCEPTED');
|
||||
|
||||
# Update the aircraft
|
||||
$pirep->aircraft->flight_time += $pirep->flight_time;
|
||||
@@ -330,7 +333,7 @@ class PirepService extends BaseService
|
||||
$pirep->aircraft->flight_time -= $pirep->flight_time;
|
||||
$pirep->aircraft->save();
|
||||
|
||||
Log::info('PIREP ' . $pirep->id . ' state change to REJECTED');
|
||||
Log::info('PIREP '.$pirep->id.' state change to REJECTED');
|
||||
|
||||
event(new PirepRejected($pirep));
|
||||
|
||||
@@ -366,16 +369,16 @@ class PirepService extends BaseService
|
||||
}
|
||||
|
||||
$flight = $pirep->flight;
|
||||
if(!$flight) {
|
||||
if (!$flight) {
|
||||
return;
|
||||
}
|
||||
|
||||
$bid = Bid::where([
|
||||
'user_id' => $pirep->user->id,
|
||||
'user_id' => $pirep->user->id,
|
||||
'flight_id' => $flight->id,
|
||||
]);
|
||||
|
||||
if($bid) {
|
||||
if ($bid) {
|
||||
Log::info('Bid for user: '.$pirep->user->pilot_id.' on flight '.$flight->ident);
|
||||
$bid->delete();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace App\Services;
|
||||
use App\Events\UserRegistered;
|
||||
use App\Events\UserStateChanged;
|
||||
use App\Events\UserStatsChanged;
|
||||
use App\Facades\Utils;
|
||||
use App\Interfaces\Service;
|
||||
use App\Models\Enums\UserState;
|
||||
use App\Models\Rank;
|
||||
use App\Models\Role;
|
||||
@@ -16,9 +16,14 @@ use App\Support\Units\Time;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
class UserService extends BaseService
|
||||
/**
|
||||
* Class UserService
|
||||
* @package App\Services
|
||||
*/
|
||||
class UserService extends Service
|
||||
{
|
||||
protected $aircraftRepo, $subfleetRepo;
|
||||
private $aircraftRepo,
|
||||
$subfleetRepo;
|
||||
|
||||
/**
|
||||
* UserService constructor.
|
||||
@@ -36,15 +41,15 @@ class UserService extends BaseService
|
||||
/**
|
||||
* Register a pilot. Also attaches the initial roles
|
||||
* required, and then triggers the UserRegistered event
|
||||
* @param User $user User model
|
||||
* @param User $user User model
|
||||
* @param array $groups Additional groups to assign
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createPilot(User $user, array $groups=null)
|
||||
public function createPilot(User $user, array $groups = null)
|
||||
{
|
||||
# Determine if we want to auto accept
|
||||
if(setting('pilots.auto_accept') === true) {
|
||||
if (setting('pilots.auto_accept') === true) {
|
||||
$user->state = UserState::ACTIVE;
|
||||
} else {
|
||||
$user->state = UserState::PENDING;
|
||||
@@ -56,7 +61,7 @@ class UserService extends BaseService
|
||||
$role = Role::where('name', 'user')->first();
|
||||
$user->attachRole($role);
|
||||
|
||||
if(!empty($groups) && \is_array($groups)) {
|
||||
if (!empty($groups) && \is_array($groups)) {
|
||||
foreach ($groups as $group) {
|
||||
$role = Role::where('name', $group)->first();
|
||||
$user->attachRole($role);
|
||||
@@ -80,11 +85,12 @@ class UserService extends BaseService
|
||||
*/
|
||||
public function getAllowableSubfleets($user)
|
||||
{
|
||||
if($user === null || setting('pireps.restrict_aircraft_to_rank') === false) {
|
||||
if ($user === null || setting('pireps.restrict_aircraft_to_rank') === false) {
|
||||
return $this->subfleetRepo->with('aircraft')->all();
|
||||
}
|
||||
|
||||
$subfleets = $user->rank->subfleets();
|
||||
|
||||
return $subfleets->with('aircraft')->get();
|
||||
}
|
||||
|
||||
@@ -107,18 +113,18 @@ class UserService extends BaseService
|
||||
* Change the user's state. PENDING to ACCEPTED, etc
|
||||
* Send out an email
|
||||
* @param User $user
|
||||
* @param $old_state
|
||||
* @param $old_state
|
||||
* @return User
|
||||
*/
|
||||
public function changeUserState(User $user, $old_state): User
|
||||
{
|
||||
if($user->state === $old_state) {
|
||||
if ($user->state === $old_state) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
Log::info('User ' . $user->pilot_id . ' state changing from '
|
||||
. UserState::label($old_state) . ' to '
|
||||
. UserState::label($user->state));
|
||||
Log::info('User '.$user->pilot_id.' state changing from '
|
||||
.UserState::label($old_state).' to '
|
||||
.UserState::label($user->state));
|
||||
|
||||
event(new UserStateChanged($user, $old_state));
|
||||
|
||||
@@ -129,7 +135,7 @@ class UserService extends BaseService
|
||||
* Adjust the number of flights a user has. Triggers
|
||||
* UserStatsChanged event
|
||||
* @param User $user
|
||||
* @param int $count
|
||||
* @param int $count
|
||||
* @return User
|
||||
*/
|
||||
public function adjustFlightCount(User $user, int $count): User
|
||||
@@ -147,7 +153,7 @@ class UserService extends BaseService
|
||||
/**
|
||||
* Update a user's flight times
|
||||
* @param User $user
|
||||
* @param int $minutes
|
||||
* @param int $minutes
|
||||
* @return User
|
||||
*/
|
||||
public function adjustFlightTime(User $user, int $minutes): User
|
||||
@@ -159,7 +165,6 @@ class UserService extends BaseService
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See if a pilot's rank has change. Triggers the UserStatsChanged event
|
||||
* @param User $user
|
||||
@@ -171,7 +176,7 @@ class UserService extends BaseService
|
||||
|
||||
# If their current rank is one they were assigned, then
|
||||
# don't change away from it automatically.
|
||||
if($user->rank && $user->rank->auto_promote === false) {
|
||||
if ($user->rank && $user->rank->auto_promote === false) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
@@ -180,7 +185,7 @@ class UserService extends BaseService
|
||||
# The current rank's hours are over the pilot's current hours,
|
||||
# so assume that they were "placed" here by an admin so don't
|
||||
# bother with updating it
|
||||
if($user->rank && $user->rank->hours > $pilot_hours->hours) {
|
||||
if ($user->rank && $user->rank->hours > $pilot_hours->hours) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
@@ -188,10 +193,10 @@ class UserService extends BaseService
|
||||
$original_rank_id = $user->rank_id;
|
||||
|
||||
$ranks = Rank::where('auto_promote', true)
|
||||
->orderBy('hours', 'asc')->get();
|
||||
->orderBy('hours', 'asc')->get();
|
||||
|
||||
foreach ($ranks as $rank) {
|
||||
if($rank->hours > $pilot_hours->hours) {
|
||||
if ($rank->hours > $pilot_hours->hours) {
|
||||
break;
|
||||
} else {
|
||||
$user->rank_id = $rank->id;
|
||||
@@ -199,7 +204,7 @@ class UserService extends BaseService
|
||||
}
|
||||
|
||||
// Only trigger the event/update if there's been a change
|
||||
if($user->rank_id !== $original_rank_id) {
|
||||
if ($user->rank_id !== $original_rank_id) {
|
||||
$user->save();
|
||||
$user->refresh();
|
||||
event(new UserStatsChanged($user, 'rank', $old_rank));
|
||||
|
||||
Reference in New Issue
Block a user