Fix formatting and interfaces in nearly every file

This commit is contained in:
Nabeel Shahzad
2018-03-19 20:50:40 -05:00
parent 04c5b9e7bf
commit ccf56ddec1
331 changed files with 3282 additions and 2492 deletions

View File

@@ -2,9 +2,15 @@
namespace App\Models;
use App\Interfaces\Model;
use App\Models\Traits\HashIdTrait;
class Acars extends BaseModel
/**
* Class Acars
* @param string id
* @package App\Models
*/
class Acars extends Model
{
use HashIdTrait;
@@ -31,21 +37,21 @@ class Acars extends BaseModel
];
public $casts = [
'type' => 'integer',
'order' => 'integer',
'nav_type' => 'integer',
'lat' => 'float',
'lon' => 'float',
'heading' => 'integer',
'altitude' => 'float',
'vs' => 'float',
'gs' => 'float',
'transponder' => 'integer',
'fuel_flow' => 'float',
'type' => 'integer',
'order' => 'integer',
'nav_type' => 'integer',
'lat' => 'float',
'lon' => 'float',
'heading' => 'integer',
'altitude' => 'float',
'vs' => 'float',
'gs' => 'float',
'transponder' => 'integer',
'fuel_flow' => 'float',
];
public static $rules = [
'pirep_id' => 'required',
'pirep_id' => 'required',
];
/**

View File

@@ -2,21 +2,23 @@
namespace App\Models;
use App\Interfaces\Model;
use App\Models\Enums\AircraftStatus;
use App\Models\Traits\ExpensableTrait;
/**
* @property mixed subfleet_id
* @property string name
* @property string icao
* @property string registration
* @property string hex_code
* @property Airport airport
* @property mixed subfleet_id
* @property string name
* @property string icao
* @property string registration
* @property string hex_code
* @property Airport airport
* @property Subfleet subfleet
* @property int status
* @property int state
* @property int status
* @property int state
* @package App\Models
*/
class Aircraft extends BaseModel
class Aircraft extends Model
{
use ExpensableTrait;
@@ -40,10 +42,10 @@ class Aircraft extends BaseModel
* @var array
*/
protected $casts = [
'subfleet_id' => 'integer',
'zfw' => 'float',
'status' => 'integer',
'state' => 'integer',
'subfleet_id' => 'integer',
'zfw' => 'float',
'status' => 'integer',
'state' => 'integer',
];
/**
@@ -53,7 +55,7 @@ class Aircraft extends BaseModel
*/
public static $rules = [
'subfleet_id' => 'required',
'name' => 'required',
'name' => 'required',
];
/**

View File

@@ -2,21 +2,22 @@
namespace App\Models;
use App\Interfaces\Model;
use App\Models\Enums\JournalType;
use App\Models\Traits\JournalTrait;
/**
* Class Airline
* @property string code
* @property string icao
* @property string iata
* @property string name
* @property string logo
* @property string country
* @property string code
* @property string icao
* @property string iata
* @property string name
* @property string logo
* @property string country
* @property Journal journal
* @package App\Models
*/
class Airline extends BaseModel
class Airline extends Model
{
use JournalTrait;
@@ -40,7 +41,6 @@ class Airline extends BaseModel
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
@@ -51,21 +51,21 @@ class Airline extends BaseModel
/**
* Validation rules
*
* @var array
*/
public static $rules = [
'country' => 'nullable',
'iata' => 'nullable|max:5',
'icao' => 'required|max:5',
'logo' => 'nullable',
'name' => 'required',
'country' => 'nullable',
'iata' => 'nullable|max:5',
'icao' => 'required|max:5',
'logo' => 'nullable',
'name' => 'required',
];
/**
* For backwards compatibility
*/
public function getCodeAttribute() {
public function getCodeAttribute()
{
return $this->icao;
}

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use App\Interfaces\Model;
use App\Models\Traits\ExpensableTrait;
/**
@@ -9,10 +10,10 @@ use App\Models\Traits\ExpensableTrait;
* @property string id
* @property string iata
* @property string icao
* @property float ground_handling_cost
* @property float ground_handling_cost
* @package App\Models
*/
class Airport extends BaseModel
class Airport extends Model
{
use ExpensableTrait;
@@ -38,26 +39,26 @@ class Airport extends BaseModel
];
protected $casts = [
'lat' => 'float',
'lon' => 'float',
'hub' => 'boolean',
'lat' => 'float',
'lon' => 'float',
'hub' => 'boolean',
'ground_handling_cost' => 'float',
'fuel_100ll_cost' => 'float',
'fuel_jeta_cost' => 'float',
'fuel_mogas_cost' => 'float',
'fuel_100ll_cost' => 'float',
'fuel_jeta_cost' => 'float',
'fuel_mogas_cost' => 'float',
];
/**
* Validation rules
*/
public static $rules = [
'icao' => 'required',
'iata' => 'nullable',
'name' => 'required',
'location' => 'nullable',
'lat' => 'required|numeric',
'lon' => 'required|numeric',
'ground_handling_cost' => 'nullable|numeric',
'icao' => 'required',
'iata' => 'nullable',
'name' => 'required',
'location' => 'nullable',
'lat' => 'required|numeric',
'lon' => 'required|numeric',
'ground_handling_cost' => 'nullable|numeric',
];
/**
@@ -86,7 +87,7 @@ class Airport extends BaseModel
*/
public function getFullNameAttribute(): string
{
return $this->icao . ' - ' . $this->name;
return $this->icao.' - '.$this->name;
}
/**

View File

@@ -2,14 +2,16 @@
namespace App\Models;
use App\Interfaces\Model;
/**
* The Award model
* @property mixed id
* @property mixed ref_class
* @property mixed id
* @property mixed ref_class
* @property mixed|null ref_class_params
* @package Award\Models
*/
class Award extends BaseModel
class Award extends Model
{
public $table = 'awards';
@@ -22,21 +24,20 @@ class Award extends BaseModel
];
public static $rules = [
'name' => 'required',
'description' => 'nullable',
'image_url' => 'nullable',
'ref_class' => 'required',
'name' => 'required',
'description' => 'nullable',
'image_url' => 'nullable',
'ref_class' => 'required',
'ref_class_params' => 'nullable'
];
/**
* Get the referring object
* @param Award|null $award
* @param User|null $user
* @param User|null $user
* @return null
*/
public function getReference(Award $award=null, User $user=null)
public function getReference(Award $award = null, User $user = null)
{
if (!$this->ref_class) {
return null;

View File

@@ -1,8 +0,0 @@
<?php
namespace App\Models;
class BaseModel extends \Illuminate\Database\Eloquent\Model
{
}

View File

@@ -2,10 +2,12 @@
namespace App\Models;
use App\Interfaces\Model;
/**
* @package App\Models
*/
class Bid extends BaseModel
class Bid extends Model
{
public $table = 'bids';

View File

@@ -11,6 +11,6 @@ use App\Interfaces\Enum;
class AcarsType extends Enum
{
public const FLIGHT_PATH = 0;
public const ROUTE = 1;
public const LOG = 2;
public const ROUTE = 1;
public const LOG = 2;
}

View File

@@ -11,10 +11,10 @@ use App\Interfaces\Enum;
class ActiveState extends Enum
{
public const INACTIVE = 0;
public const ACTIVE = 1;
public const ACTIVE = 1;
public static $labels = [
ActiveState::INACTIVE => 'Inactive',
ActiveState::ACTIVE => 'Active',
ActiveState::INACTIVE => 'Inactive',
ActiveState::ACTIVE => 'Active',
];
}

View File

@@ -15,8 +15,8 @@ class AircraftState extends Enum
public const IN_AIR = 2;
public static $labels = [
AircraftState::PARKED => 'On Ground',
AircraftState::IN_USE => 'In Use',
AircraftState::IN_AIR => 'In Air',
AircraftState::PARKED => 'On Ground',
AircraftState::IN_USE => 'In Use',
AircraftState::IN_AIR => 'In Air',
];
}

View File

@@ -10,17 +10,17 @@ use App\Interfaces\Enum;
*/
class AircraftStatus extends Enum
{
public const STORED = 0;
public const ACTIVE = 1;
public const RETIRED = 2;
public const SCRAPPED = 3;
public const STORED = 0;
public const ACTIVE = 1;
public const RETIRED = 2;
public const SCRAPPED = 3;
public const WRITTEN_OFF = 4;
public static $labels = [
AircraftStatus::STORED => 'Stored',
AircraftStatus::ACTIVE => 'Active',
AircraftStatus::RETIRED => 'Retired',
AircraftStatus::SCRAPPED => 'Scrapped',
AircraftStatus::STORED => 'Stored',
AircraftStatus::ACTIVE => 'Active',
AircraftStatus::RETIRED => 'Retired',
AircraftStatus::SCRAPPED => 'Scrapped',
AircraftStatus::WRITTEN_OFF => 'Written Off',
];
}

View File

@@ -10,7 +10,7 @@ use App\Interfaces\Enum;
*/
class AnalyticsDimensions extends Enum
{
public const PHP_VERSION = 1;
public const PHP_VERSION = 1;
public const DATABASE_VERSION = 2;
public const PHPVMS_VERSION = 3;
public const PHPVMS_VERSION = 3;
}

View File

@@ -6,6 +6,7 @@ use App\Interfaces\Enum;
/**
* Class AnalyticsMetrics
* Metrics IDs used in Google Analytics
* @package App\Models\Enums
*/
class AnalyticsMetrics extends Enum

View File

@@ -8,8 +8,8 @@ use App\Interfaces\Enum;
* Class Days
* @package App\Models\Enums
*/
class Days extends Enum {
class Days extends Enum
{
public const MONDAY = 1 << 0;
public const TUESDAY = 1 << 1;
public const WEDNESDAY = 1 << 2;
@@ -19,12 +19,12 @@ class Days extends Enum {
public const SUNDAY = 1 << 6;
protected static $labels = [
Days::MONDAY => 'system.days.mon',
Days::TUESDAY => 'system.days.tues',
Days::WEDNESDAY => 'system.days.wed',
Days::THURSDAY => 'system.days.thurs',
Days::FRIDAY => 'system.days.fri',
Days::SATURDAY => 'system.days.sat',
Days::SUNDAY => 'system.days.sun',
Days::MONDAY => 'system.days.mon',
Days::TUESDAY => 'system.days.tues',
Days::WEDNESDAY => 'system.days.wed',
Days::THURSDAY => 'system.days.thurs',
Days::FRIDAY => 'system.days.fri',
Days::SATURDAY => 'system.days.sat',
Days::SUNDAY => 'system.days.sun',
];
}

View File

@@ -8,15 +8,15 @@ use App\Interfaces\Enum;
* Class ExpenseType
* @package App\Models\Enums
*/
class ExpenseType extends Enum {
public const FLIGHT = 0;
public const DAILY = 1;
public const MONTHLY = 2;
class ExpenseType extends Enum
{
public const FLIGHT = 0;
public const DAILY = 1;
public const MONTHLY = 2;
protected static $labels = [
ExpenseType::FLIGHT => 'Flight',
ExpenseType::DAILY => 'Daily',
ExpenseType::MONTHLY => 'Monthly',
ExpenseType::FLIGHT => 'Flight',
ExpenseType::DAILY => 'Daily',
ExpenseType::MONTHLY => 'Monthly',
];
}

View File

@@ -8,15 +8,15 @@ use App\Interfaces\Enum;
* Class FlightType
* @package App\Models\Enums
*/
class FlightType extends Enum {
public const PASSENGER = 0;
public const CARGO = 1;
public const CHARTER = 2;
class FlightType extends Enum
{
public const PASSENGER = 0;
public const CARGO = 1;
public const CHARTER = 2;
protected static $labels = [
FlightType::PASSENGER => 'Passenger',
FlightType::CARGO => 'Cargo',
FlightType::CHARTER => 'Charter',
FlightType::PASSENGER => 'Passenger',
FlightType::CARGO => 'Cargo',
FlightType::CHARTER => 'Charter',
];
}

View File

@@ -8,15 +8,15 @@ use App\Interfaces\Enum;
* Class FuelType
* @package App\Models\Enums
*/
class FuelType extends Enum {
public const LOW_LEAD = 0;
public const JET_A = 1;
public const MOGAS = 2;
class FuelType extends Enum
{
public const LOW_LEAD = 0;
public const JET_A = 1;
public const MOGAS = 2;
protected static $labels = [
FuelType::LOW_LEAD => '100LL',
FuelType::JET_A => 'JET A',
FuelType::MOGAS => 'MOGAS',
FuelType::LOW_LEAD => '100LL',
FuelType::JET_A => 'JET A',
FuelType::MOGAS => 'MOGAS',
];
}

View File

@@ -5,11 +5,11 @@ namespace App\Models\Enums;
use App\Interfaces\Enum;
/**
* Class AcarsType
* Class JournalType
* @package App\Models\Enums
*/
class JournalType extends Enum
{
public const AIRLINE = 0;
public const USER = 1;
public const USER = 1;
}

View File

@@ -1,4 +1,5 @@
<?php
namespace App\Models\Enums;
use App\Interfaces\Enum;
@@ -11,19 +12,19 @@ use App\Interfaces\Enum;
*/
class NavaidType extends Enum
{
public const VOR = 1 << 0;
public const VOR_DME = 1 << 1;
public const LOC = 1 << 4;
public const LOC_DME = 1 << 5;
public const NDB = 1 << 6;
public const TACAN = 1 << 7;
public const UNKNOWN = 1 << 8;
public const INNER_MARKER = 1 << 9;
public const OUTER_MARKER = 1 << 10;
public const FIX = 1 << 11;
public const ANY_VOR = NavaidType::VOR | NavaidType::VOR_DME;
public const ANY_LOC = NavaidType::LOC | NavaidType::LOC_DME;
public const ANY = (NavaidType::UNKNOWN << 1) - 1;
public const VOR = 1 << 0;
public const VOR_DME = 1 << 1;
public const LOC = 1 << 4;
public const LOC_DME = 1 << 5;
public const NDB = 1 << 6;
public const TACAN = 1 << 7;
public const UNKNOWN = 1 << 8;
public const INNER_MARKER = 1 << 9;
public const OUTER_MARKER = 1 << 10;
public const FIX = 1 << 11;
public const ANY_VOR = NavaidType::VOR | NavaidType::VOR_DME;
public const ANY_LOC = NavaidType::LOC | NavaidType::LOC_DME;
public const ANY = (NavaidType::UNKNOWN << 1) - 1;
/**
* Names and titles

View File

@@ -11,7 +11,7 @@ use App\Interfaces\Enum;
class PirepSource extends Enum
{
public const MANUAL = 0;
public const ACARS = 1;
public const ACARS = 1;
protected static $labels = [
PirepSource::MANUAL => 'Manual',

View File

@@ -8,21 +8,21 @@ use App\Interfaces\Enum;
* Class PirepState
* @package App\Models\Enums
*/
class PirepState extends Enum {
public const REJECTED = -1;
public const IN_PROGRESS = 0; // flight is ongoing
public const PENDING = 1; // waiting admin approval
public const ACCEPTED = 2;
public const CANCELLED = 3;
public const DELETED = 4;
class PirepState extends Enum
{
public const REJECTED = -1;
public const IN_PROGRESS = 0; // flight is ongoing
public const PENDING = 1; // waiting admin approval
public const ACCEPTED = 2;
public const CANCELLED = 3;
public const DELETED = 4;
protected static $labels = [
PirepState::REJECTED => 'system.pireps.state.rejected',
PirepState::IN_PROGRESS => 'system.pireps.state.in_progress',
PirepState::PENDING => 'system.pireps.state.pending',
PirepState::ACCEPTED => 'system.pireps.state.accepted',
PirepState::CANCELLED => 'system.pireps.state.cancelled',
PirepState::DELETED => 'system.pireps.state.deleted',
PirepState::REJECTED => 'system.pireps.state.rejected',
PirepState::IN_PROGRESS => 'system.pireps.state.in_progress',
PirepState::PENDING => 'system.pireps.state.pending',
PirepState::ACCEPTED => 'system.pireps.state.accepted',
PirepState::CANCELLED => 'system.pireps.state.cancelled',
PirepState::DELETED => 'system.pireps.state.deleted',
];
}

View File

@@ -11,15 +11,15 @@ use App\Interfaces\Enum;
*/
class PirepStatus extends Enum
{
public const PREFILE = 0;
public const SCHEDULED = 0;
public const ENROUTE = 1;
public const ARRIVED = 2;
public const PREFILE = 0;
public const SCHEDULED = 0;
public const ENROUTE = 1;
public const ARRIVED = 2;
protected static $labels = [
PirepStatus::PREFILE => 'Prefiled',
PirepStatus::SCHEDULED => 'Scheduled',
PirepStatus::ENROUTE => 'Enroute',
PirepStatus::ARRIVED => 'Arrived',
PirepStatus::PREFILE => 'Prefiled',
PirepStatus::SCHEDULED => 'Scheduled',
PirepStatus::ENROUTE => 'Enroute',
PirepStatus::ARRIVED => 'Arrived',
];
}

View File

@@ -17,10 +17,10 @@ class UserState extends Enum
public const SUSPENDED = 4;
protected static $labels = [
UserState::PENDING => 'Pending',
UserState::ACTIVE => 'Active',
UserState::REJECTED => 'Rejected',
UserState::ON_LEAVE => 'On Leave',
UserState::SUSPENDED => 'Suspended',
UserState::PENDING => 'Pending',
UserState::ACTIVE => 'Active',
UserState::REJECTED => 'Rejected',
UserState::ON_LEAVE => 'On Leave',
UserState::SUSPENDED => 'Suspended',
];
}

View File

@@ -1,17 +1,18 @@
<?php
namespace App\Models;
use App\Interfaces\Model;
/**
* Class Expense
* @property int airline_id
* @property float amount
* @property int airline_id
* @property float amount
* @property string name
* @property string ref_class
* @property string ref_class_id
* @package App\Models
*/
class Expense extends BaseModel
class Expense extends Model
{
public $table = 'expenses';
@@ -28,12 +29,12 @@ class Expense extends BaseModel
];
public static $rules = [
'active' => 'boolean',
'airline_id' => 'integer',
'amount' => 'float',
'type' => 'integer',
'multiplier' => 'bool',
'charge_to_user' => 'bool',
'active' => 'boolean',
'airline_id' => 'integer',
'amount' => 'float',
'type' => 'integer',
'multiplier' => 'bool',
'charge_to_user' => 'bool',
];
/**
@@ -45,12 +46,13 @@ class Expense extends BaseModel
return null;
}
if($this->ref_class === __CLASS__) {
if ($this->ref_class === __CLASS__) {
return $this;
}
try {
$klass = new $this->ref_class;
return $klass->find($this->ref_class_id);
} catch (\Exception $e) {
return null;

View File

@@ -1,16 +1,17 @@
<?php
namespace App\Models;
use App\Interfaces\Model;
/**
* Class Fare
* @property integer capacity
* @property float cost
* @property float price
* @property mixed code
* @property float cost
* @property float price
* @property mixed code
* @package App\Models
*/
class Fare extends BaseModel
class Fare extends Model
{
public $table = 'fares';
@@ -25,10 +26,10 @@ class Fare extends BaseModel
];
protected $casts = [
'price' => 'float',
'cost' => 'float',
'capacity' => 'integer',
'active' => 'boolean',
'price' => 'float',
'cost' => 'float',
'capacity' => 'integer',
'active' => 'boolean',
];
public static $rules = [

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use App\Interfaces\Model;
use App\Models\Traits\HashIdTrait;
use App\Support\Units\Distance;
use PhpUnitsOfMeasure\Exception\NonNumericValue;
@@ -9,16 +10,15 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName;
/**
* @property Airline airline
* @property mixed flight_number
* @property mixed route_code
* @property mixed route_leg
* @property mixed flight_number
* @property mixed route_code
* @property mixed route_leg
*/
class Flight extends BaseModel
class Flight extends Model
{
use HashIdTrait;
public const ID_MAX_LENGTH = 12;
public $table = 'flights';
public $incrementing = false;
@@ -75,11 +75,11 @@ class Flight extends BaseModel
$flight_id .= $this->flight_number;
if (filled($this->route_code)) {
$flight_id .= '/C' . $this->route_code;
$flight_id .= '/C'.$this->route_code;
}
if (filled($this->route_leg)) {
$flight_id .= '/L' . $this->route_leg;
$flight_id .= '/L'.$this->route_leg;
}
return $flight_id;
@@ -97,6 +97,7 @@ class Flight extends BaseModel
try {
$distance = (float) $this->attributes['distance'];
return new Distance($distance, config('phpvms.internal_units.distance'));
} catch (NonNumericValue $e) {
return 0;
@@ -111,7 +112,7 @@ class Flight extends BaseModel
*/
public function setDistanceAttribute($value): void
{
if($value instanceof Distance) {
if ($value instanceof Distance) {
$this->attributes['distance'] = $value->toUnit(
config('phpvms.internal_units.distance')
);
@@ -147,7 +148,7 @@ class Flight extends BaseModel
public function fares()
{
return $this->belongsToMany(Fare::class, 'flight_fare')
->withPivot('price', 'cost', 'capacity');
->withPivot('price', 'cost', 'capacity');
}
public function fields()

View File

@@ -2,11 +2,13 @@
namespace App\Models;
use App\Interfaces\Model;
/**
* Class FlightFields
* @package App\Models
*/
class FlightFields extends BaseModel
class FlightFields extends Model
{
public $table = 'flight_fields';

View File

@@ -18,21 +18,19 @@ class GeoJson
* @var int
*/
protected $counter;
/**
* @var array [lon, lat] pairs
*/
protected $line_coords = [];
/**
* @var Feature[]
*/
protected $point_coords = [];
/**
* @param $lat
* @param $lon
* @param array $attrs Attributes of the Feature
* @param $lat
* @param $lon
* @param array $attrs Attributes of the Feature
*/
public function addPoint($lat, $lon, array $attrs)
{
@@ -47,7 +45,7 @@ class GeoJson
*/
public function getLine(): FeatureCollection
{
if(empty($this->line_coords) || \count($this->line_coords) < 2) {
if (empty($this->line_coords) || \count($this->line_coords) < 2) {
return new FeatureCollection([]);
}

View File

@@ -6,22 +6,23 @@
namespace App\Models;
use App\Interfaces\Model;
use App\Support\Money;
use Carbon\Carbon;
/**
* Class Journal
* @property mixed id
* @property Money $balance
* @property string $currency
* @property Carbon $updated_at
* @property Carbon $post_date
* @property Carbon $created_at
* @property mixed id
* @property Money $balance
* @property string $currency
* @property Carbon $updated_at
* @property Carbon $post_date
* @property Carbon $created_at
* @property \App\Models\Enums\JournalType type
* @property mixed morphed_type
* @property mixed morphed_id
* @property mixed morphed_type
* @property mixed morphed_id
*/
class Journal extends BaseModel
class Journal extends Model
{
protected $table = 'journals';
@@ -81,6 +82,7 @@ class Journal extends BaseModel
public function assignToLedger(Ledger $ledger)
{
$ledger->journals()->save($this);
return $this;
}
@@ -117,7 +119,7 @@ class Journal extends BaseModel
? $value
: new Money($value);
$this->attributes['balance'] = $value ? (int)$value->getAmount() : null;
$this->attributes['balance'] = $value ? (int) $value->getAmount() : null;
}
/**
@@ -158,7 +160,7 @@ class Journal extends BaseModel
public function getBalanceOn(Carbon $date)
{
return $this->getCreditBalanceOn($date)
->subtract($this->getDebitBalanceOn($date));
->subtract($this->getDebitBalanceOn($date));
}
/**

View File

@@ -6,8 +6,10 @@
namespace App\Models;
use App\Interfaces\Model;
/**
* @property string id UUID type
* @property string id UUID type
* @property string currency
* @property string memo
* @property string transaction_group
@@ -18,9 +20,10 @@ namespace App\Models;
* @property integer ref_class_id
* @property Journal journal
*/
class JournalTransaction extends BaseModel
class JournalTransaction extends Model
{
protected $table = 'journal_transactions';
public $incrementing = false;
public $fillable = [
@@ -59,7 +62,7 @@ class JournalTransaction extends BaseModel
}
/**
* @param BaseModel $object
* @param Model $object
* @return JournalTransaction
*/
public function referencesObject($object)
@@ -67,6 +70,7 @@ class JournalTransaction extends BaseModel
$this->ref_class = \get_class($object);
$this->ref_class_id = $object->id;
$this->save();
return $this;
}
@@ -77,8 +81,10 @@ class JournalTransaction extends BaseModel
{
if ($classname = $this->ref_class) {
$klass = new $this->ref_class;
return $klass->find($this->ref_class_id);
}
return false;
}

View File

@@ -6,19 +6,20 @@
namespace App\Models;
use App\Interfaces\Model;
use App\Support\Money;
use Carbon\Carbon;
/**
* Class Journal
* @package Scottlaurent\Accounting
* @property Money $balance
* @property Money $balance
* @property string $currency
* @property Carbon $updated_at
* @property Carbon $post_date
* @property Carbon $created_at
*/
class Ledger extends BaseModel
class Ledger extends Model
{
protected $table = 'ledgers';

View File

@@ -5,33 +5,37 @@
namespace App\Models\Migrations;
use App\Interfaces\Migration as MigrationInterface;
use App\Models\Setting;
use DB;
use Illuminate\Database\Migrations\Migration as MigrationBase;
class Migration extends MigrationBase
/**
* Class Migration
* @package App\Models\Migrations
*/
class Migration extends MigrationInterface
{
private $counters = [];
private $offsets = [];
protected $counters = [];
protected $offsets = [];
/**
* Dynamically figure out the offset and the start number for a group.
* This way we don't need to mess with how to order things
* When calling getNextOrderNumber(users) 31, will be returned, then 32, and so on
* @param $name
* @param $name
* @param null $offset
* @param int $start_offset
* @param int $start_offset
*/
protected function addCounterGroup($name, $offset=null, $start_offset=0)
protected function addCounterGroup($name, $offset = null, $start_offset = 0)
{
if($offset === null) {
if ($offset === null) {
$group = DB::table('settings')
->where('group', $name)
->first();
->where('group', $name)
->first();
if($group === null) {
if ($group === null) {
$offset = (int) DB::table('settings')->max('offset');
if($offset === null) {
if ($offset === null) {
$offset = 0;
$start_offset = 1;
} else {
@@ -39,10 +43,9 @@ class Migration extends MigrationBase
$start_offset = $offset + 1;
}
} else {
# Now find the number to start from
$start_offset = (int) DB::table('settings')->where('group', $name)->max('order');
if($start_offset === null) {
if ($start_offset === null) {
$start_offset = $offset + 1;
} else {
++$start_offset;
@@ -63,7 +66,7 @@ class Migration extends MigrationBase
*/
public function getNextOrderNumber($group): int
{
if(!\in_array($group, $this->counters, true)) {
if (!\in_array($group, $this->counters, true)) {
$this->addCounterGroup($group);
}
@@ -83,16 +86,16 @@ class Migration extends MigrationBase
$order = $this->getNextOrderNumber($group);
$attrs = array_merge([
'id' => Setting::formatKey($key),
'key' => $key,
'offset' => $this->offsets[$group],
'order' => $order,
'name' => '',
'group' => $group,
'value' => '',
'default' => '',
'options' => '',
'type' => 'hidden',
'id' => Setting::formatKey($key),
'key' => $key,
'offset' => $this->offsets[$group],
'order' => $order,
'name' => '',
'group' => $group,
'value' => '',
'default' => '',
'options' => '',
'type' => 'hidden',
'description' => '',
], $attrs);
@@ -101,11 +104,11 @@ class Migration extends MigrationBase
/**
* Update a setting
* @param $key
* @param $value
* @param $key
* @param $value
* @param array $attrs
*/
public function updateSetting($key, $value, array $attrs=[])
public function updateSetting($key, $value, array $attrs = [])
{
$attrs['value'] = $value;
DB::table('settings')

View File

@@ -2,7 +2,13 @@
namespace App\Models;
class Navdata extends BaseModel
use App\Interfaces\Model;
/**
* Class Navdata
* @package App\Models
*/
class Navdata extends Model
{
public $table = 'navdata';
public $timestamps = false;
@@ -18,10 +24,10 @@ class Navdata extends BaseModel
];
public $casts = [
'type' => 'integer',
'lat' => 'float',
'lon' => 'float',
'freq' => 'float',
'type' => 'integer',
'lat' => 'float',
'lon' => 'float',
'freq' => 'float',
];
/**

View File

@@ -2,11 +2,13 @@
namespace App\Models;
use App\Interfaces\Model;
/**
* Class News
* @package App\Models
*/
class News extends BaseModel
class News extends Model
{
public $table = 'news';
@@ -18,7 +20,7 @@ class News extends BaseModel
public static $rules = [
'subject' => 'required',
'body' => 'required',
'body' => 'required',
];
/**

View File

@@ -11,6 +11,9 @@ use App\Support\ICAO;
*/
class AircraftObserver
{
/**
* @param Aircraft $aircraft
*/
public function creating(Aircraft $aircraft): void
{
if (empty($aircraft->hex_code)) {

View File

@@ -4,6 +4,10 @@ namespace App\Models\Observers;
use App\Models\JournalTransaction;
/**
* Class JournalTransactionObserver
* @package App\Models\Observers
*/
class JournalTransactionObserver
{
/**
@@ -31,7 +35,6 @@ class JournalTransactionObserver
if ($transaction['debit']) {
$balance = $journal->balance->toAmount();
#$journal->balance = $journal->balance->subtract($transaction['debit']);
$journal->balance = (int) $balance - $transaction->debit;
}

View File

@@ -4,6 +4,10 @@ namespace App\Models\Observers;
use App\Models\Setting;
/**
* Class SettingObserver
* @package App\Models\Observers
*/
class SettingObserver
{
/**

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models\Observers;
use App\Models\Subfleet;
/**
* Class SubfleetObserver
* @package App\Models\Observers
*/
class SubfleetObserver
{
/**
* @param Subfleet $model
*/
public function creating(Subfleet $model)
{
if (!filled($model->ground_handling_multiplier)) {
$model->ground_handling_multiplier = 100;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
namespace App\Models;
use Laratrust\Models\LaratrustPermission;

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use App\Interfaces\Model;
use App\Models\Enums\AcarsType;
use App\Models\Enums\PirepState;
use App\Models\Traits\HashIdTrait;
@@ -13,21 +14,21 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName;
/**
* Class Pirep
*
* @property string flight_number
* @property string route_code
* @property string route_leg
* @property integer airline_id
* @property Aircraft aircraft
* @property Airline airline
* @property Airport arr_airport
* @property Airport dep_airport
* @property integer flight_time In minutes
* @property User user
* @property string flight_number
* @property string route_code
* @property string route_leg
* @property integer airline_id
* @property integer user_id
* @property Aircraft aircraft
* @property Airline airline
* @property Airport arr_airport
* @property Airport dep_airport
* @property integer flight_time In minutes
* @property User user
* @property Flight|null flight
* @property int user_id
* @package App\Models
*/
class Pirep extends BaseModel
class Pirep extends Model
{
use HashIdTrait;
@@ -70,32 +71,32 @@ class Pirep extends BaseModel
];
protected $casts = [
'user_id' => 'integer',
'airline_id' => 'integer',
'aircraft_id' => 'integer',
'level' => 'integer',
'distance' => 'float',
'planned_distance' => 'float',
'flight_time' => 'integer',
'planned_flight_time' => 'integer',
'zfw' => 'float',
'block_fuel' => 'float',
'fuel_used' => 'float',
'landing_rate' => 'float',
'source' => 'integer',
'flight_type' => 'integer',
'state' => 'integer',
'status' => 'integer',
'user_id' => 'integer',
'airline_id' => 'integer',
'aircraft_id' => 'integer',
'level' => 'integer',
'distance' => 'float',
'planned_distance' => 'float',
'flight_time' => 'integer',
'planned_flight_time' => 'integer',
'zfw' => 'float',
'block_fuel' => 'float',
'fuel_used' => 'float',
'landing_rate' => 'float',
'source' => 'integer',
'flight_type' => 'integer',
'state' => 'integer',
'status' => 'integer',
];
public static $rules = [
'airline_id' => 'required|exists:airlines,id',
'aircraft_id' => 'required|exists:aircraft,id',
'flight_number' => 'required',
'dpt_airport_id' => 'required',
'arr_airport_id' => 'required',
'notes' => 'nullable',
'route' => 'nullable',
'airline_id' => 'required|exists:airlines,id',
'aircraft_id' => 'required|exists:aircraft,id',
'flight_number' => 'required',
'dpt_airport_id' => 'required',
'arr_airport_id' => 'required',
'notes' => 'nullable',
'route' => 'nullable',
];
/**
@@ -107,11 +108,11 @@ class Pirep extends BaseModel
$flight_id = $this->airline->code;
$flight_id .= $this->flight_number;
if(filled($this->route_code)) {
if (filled($this->route_code)) {
$flight_id .= '/C'.$this->route_code;
}
if(filled($this->route_leg)) {
if (filled($this->route_leg)) {
$flight_id .= '/L'.$this->route_leg;
}
@@ -124,12 +125,13 @@ class Pirep extends BaseModel
*/
public function getDistanceAttribute()
{
if(!array_key_exists('distance', $this->attributes)) {
if (!array_key_exists('distance', $this->attributes)) {
return null;
}
try {
$distance = (float) $this->attributes['distance'];
return new Distance($distance, config('phpvms.internal_units.distance'));
} catch (NonNumericValue $e) {
return 0;
@@ -164,6 +166,7 @@ class Pirep extends BaseModel
try {
$fuel_used = (float) $this->attributes['fuel_used'];
return new Fuel($fuel_used, config('phpvms.internal_units.fuel'));
} catch (NonNumericValue $e) {
return 0;
@@ -184,6 +187,7 @@ class Pirep extends BaseModel
try {
$distance = (float) $this->attributes['planned_distance'];
return new Distance($distance, config('phpvms.internal_units.distance'));
} catch (NonNumericValue $e) {
return 0;
@@ -199,9 +203,9 @@ class Pirep extends BaseModel
public function getFlightAttribute(): ?Flight
{
$where = [
'airline_id' => $this->airline_id,
'airline_id' => $this->airline_id,
'flight_number' => $this->flight_number,
'active' => true,
'active' => true,
];
if (filled($this->route_code)) {
@@ -261,14 +265,13 @@ class Pirep extends BaseModel
*/
public function allowedUpdates(): bool
{
if($this->state === PirepState::CANCELLED) {
if ($this->state === PirepState::CANCELLED) {
return false;
}
return true;
}
/**
* Foreign Keys
*/
@@ -276,22 +279,22 @@ class Pirep extends BaseModel
public function acars()
{
return $this->hasMany(Acars::class, 'pirep_id')
->where('type', AcarsType::FLIGHT_PATH)
->orderBy('created_at', 'desc');
->where('type', AcarsType::FLIGHT_PATH)
->orderBy('created_at', 'desc');
}
public function acars_logs()
{
return $this->hasMany(Acars::class, 'pirep_id')
->where('type', AcarsType::LOG)
->orderBy('created_at', 'asc');
->where('type', AcarsType::LOG)
->orderBy('created_at', 'asc');
}
public function acars_route()
{
return $this->hasMany(Acars::class, 'pirep_id')
->where('type', AcarsType::ROUTE)
->orderBy('order', 'asc');
->where('type', AcarsType::ROUTE)
->orderBy('order', 'asc');
}
public function aircraft()
@@ -317,7 +320,7 @@ class Pirep extends BaseModel
public function comments()
{
return $this->hasMany(PirepComment::class, 'pirep_id')
->orderBy('created_at', 'desc');
->orderBy('created_at', 'desc');
}
public function fares()
@@ -342,16 +345,16 @@ class Pirep extends BaseModel
public function position()
{
return $this->hasOne(Acars::class, 'pirep_id')
->where('type', AcarsType::FLIGHT_PATH)
->latest();
->where('type', AcarsType::FLIGHT_PATH)
->latest();
}
public function transactions()
{
return $this->hasMany(JournalTransaction::class, 'ref_class_id')
->where('ref_class', __CLASS__)
->orderBy('credit', 'desc')
->orderBy('debit', 'desc');
->where('ref_class', __CLASS__)
->orderBy('credit', 'desc')
->orderBy('debit', 'desc');
}
public function user()

View File

@@ -2,12 +2,14 @@
namespace App\Models;
use App\Interfaces\Model;
/**
* Class PirepEvent
*
* @package App\Models
*/
class PirepComment extends BaseModel
class PirepComment extends Model
{
public $table = 'pirep_comments';

View File

@@ -2,11 +2,13 @@
namespace App\Models;
use App\Interfaces\Model;
/**
* Class PirepFare
* @package App\Models
*/
class PirepFare extends BaseModel
class PirepFare extends Model
{
public $table = 'pirep_fares';
public $timestamps = false;

View File

@@ -2,13 +2,15 @@
namespace App\Models;
use App\Interfaces\Model;
/**
* Class PirepField
* @property string name
* @property string slug
* @package App\Models
*/
class PirepField extends BaseModel
class PirepField extends Model
{
public $table = 'pirep_fields';
public $timestamps = false;

View File

@@ -2,11 +2,13 @@
namespace App\Models;
use App\Interfaces\Model;
/**
* Class PirepFieldValues
* @package App\Models
*/
class PirepFieldValues extends BaseModel
class PirepFieldValues extends Model
{
public $table = 'pirep_field_values';

View File

@@ -2,14 +2,16 @@
namespace App\Models;
use App\Interfaces\Model;
/**
* Class Rank
* @property int hours
* @property int hours
* @property float manual_base_pay_rate
* @property float acars_base_pay_rate
* @package App\Models
*/
class Rank extends BaseModel
class Rank extends Model
{
public $table = 'ranks';
@@ -25,17 +27,17 @@ class Rank extends BaseModel
];
protected $casts = [
'hours' => 'integer',
'base_pay_rate' => 'float',
'auto_approve_acars' => 'bool',
'hours' => 'integer',
'base_pay_rate' => 'float',
'auto_approve_acars' => 'bool',
'auto_approve_manual' => 'bool',
'auto_promote' => 'bool',
'auto_promote' => 'bool',
];
public static $rules = [
'name' => 'required',
'hours' => 'required|integer',
'acars_base_pay_rate' => 'nullable|numeric',
'name' => 'required',
'hours' => 'required|integer',
'acars_base_pay_rate' => 'nullable|numeric',
'manual_base_pay_rate' => 'nullable|numeric',
];

View File

@@ -1,9 +1,9 @@
<?php
namespace App\Models;
use Laratrust\Models\LaratrustRole;
class Role extends LaratrustRole
{
}

View File

@@ -2,6 +2,8 @@
namespace App\Models;
use App\Interfaces\Model;
/**
* Class Setting
* @property string id
@@ -14,7 +16,7 @@ namespace App\Models;
* @property string description
* @package App\Models
*/
class Setting extends BaseModel
class Setting extends Model
{
public $table = 'settings';
public $incrementing = false;

View File

@@ -2,20 +2,23 @@
namespace App\Models;
use App\Interfaces\Model;
use App\Models\Enums\AircraftStatus;
use App\Models\Traits\ExpensableTrait;
/**
* Class Subfleet
* @property string type
* @property string ground_handling_multiplier
* @package App\Models
*/
class Subfleet extends BaseModel
class Subfleet extends Model
{
use ExpensableTrait;
public $table = 'subfleets';
public $fillable = [
protected $fillable = [
'airline_id',
'name',
'type',
@@ -26,51 +29,30 @@ class Subfleet extends BaseModel
'gross_weight',
];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
'airline_id' => 'integer',
'fuel_type' => 'integer',
'ground_handling_multiplier' => 'float',
'cargo_capacity' => 'float',
'fuel_capacity' => 'float',
'gross_weight' => 'float',
'airline_id' => 'integer',
'fuel_type' => 'integer',
'ground_handling_multiplier' => 'float',
'cargo_capacity' => 'float',
'fuel_capacity' => 'float',
'gross_weight' => 'float',
];
public static $rules = [
'name' => 'required',
'type' => 'required',
'ground_handling_multiplier' => 'nullable|numeric',
protected static $rules = [
'name' => 'required',
'type' => 'required',
'ground_handling_multiplier' => 'nullable|numeric',
];
/**
* Modify some fields on the fly. Make sure the subfleet names don't
* have spaces in them, so the csv import/export can use the types
* @param $type
*/
public static function boot()
public function setTypeAttribute($type)
{
parent::boot();
$type = str_replace(' ', '-', $type);
$type = str_replace(',', '', $type);
static::creating(function ($model) {
if (filled($model->type)) {
$model->type = str_replace(' ', '-', $model->type);
$model->type = str_replace(',', '', $model->type);
}
if(!filled($model->ground_handling_multiplier)) {
$model->ground_handling_multiplier = 100;
}
});
static::updating(function ($model) {
if (filled($model->type)) {
$model->type = str_replace(' ', '-', $model->type);
$model->type = str_replace(',', '', $model->type);
}
});
$this->attributes['type'] = $type;
}
/**
@@ -83,7 +65,7 @@ class Subfleet extends BaseModel
public function aircraft()
{
return $this->hasMany(Aircraft::class, 'subfleet_id')
->where('status', AircraftStatus::ACTIVE);
->where('status', AircraftStatus::ACTIVE);
}
public function airline()
@@ -94,7 +76,7 @@ class Subfleet extends BaseModel
public function fares()
{
return $this->belongsToMany(Fare::class, 'subfleet_fare')
->withPivot('price', 'cost', 'capacity');
->withPivot('price', 'cost', 'capacity');
}
public function flights()
@@ -105,6 +87,6 @@ class Subfleet extends BaseModel
public function ranks()
{
return $this->belongsToMany(Rank::class, 'subfleet_rank')
->withPivot('acars_pay', 'manual_pay');
->withPivot('acars_pay', 'manual_pay');
}
}

View File

@@ -8,7 +8,6 @@ trait ExpensableTrait
{
public static function bootExpensableTrait()
{
}
/**

View File

@@ -1,4 +1,5 @@
<?php
namespace App\Models\Traits;
use Hashids\Hashids;
@@ -13,6 +14,7 @@ trait HashIdTrait
{
$hashids = new Hashids('', 12);
$mt = str_replace('.', '', microtime(true));
return $hashids->encode($mt);
}

View File

@@ -6,7 +6,6 @@ use App\Models\Journal;
trait JournalTrait
{
/**
* Initialize a new journal when a new record is created
*/
@@ -44,6 +43,7 @@ trait JournalTrait
$this->journal()->save($journal);
$journal->refresh();
return $journal;
}
}

View File

@@ -10,20 +10,20 @@ use Illuminate\Notifications\Notifiable;
use Laratrust\Traits\LaratrustUserTrait;
/**
* @property integer $id
* @property string $name
* @property string $email
* @property string $password
* @property string $api_key
* @property Flight[] $flights
* @property string $flight_time
* @property string $remember_token
* @property integer $id
* @property string $name
* @property string $email
* @property string $password
* @property string $api_key
* @property Flight[] $flights
* @property string $flight_time
* @property string $remember_token
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property Rank rank
* @property Journal journal
* @property string pilot_id
* @property int state
* @property Rank rank
* @property Journal journal
* @property string pilot_id
* @property int state
* @mixin \Illuminate\Notifications\Notifiable
* @mixin \Laratrust\Traits\LaratrustUserTrait
*/
@@ -72,16 +72,16 @@ class User extends Authenticatable
];
protected $casts = [
'flights' => 'integer',
'flight_time' => 'integer',
'transferred_time' => 'integer',
'balance' => 'double',
'state' => 'integer',
'status' => 'integer',
'flights' => 'integer',
'flight_time' => 'integer',
'transferred_time' => 'integer',
'balance' => 'double',
'state' => 'integer',
'status' => 'integer',
];
public static $rules = [
'name' => 'required',
'name' => 'required',
'email' => 'required|email',
];
@@ -91,7 +91,8 @@ class User extends Authenticatable
public function getPilotIdAttribute()
{
$length = setting('pilots.id_length');
return $this->airline->icao . str_pad($this->id, $length, '0', STR_PAD_LEFT);
return $this->airline->icao.str_pad($this->id, $length, '0', STR_PAD_LEFT);
}
/**
@@ -124,14 +125,14 @@ class User extends Authenticatable
* @param mixed $size Size of the gravatar, in pixels
* @return string
*/
public function gravatar($size=null)
public function gravatar($size = null)
{
$default = config('gravatar.default');
$uri = config('gravatar.url')
. md5(strtolower(trim($this->email))).'?d='.urlencode($default);
.md5(strtolower(trim($this->email))).'?d='.urlencode($default);
if($size !== null) {
if ($size !== null) {
$uri .= '&s='.$size;
}
@@ -175,7 +176,7 @@ class User extends Authenticatable
public function pireps()
{
return $this->hasMany(Pirep::class, 'user_id')
->where('state', '!=', PirepState::CANCELLED);
->where('state', '!=', PirepState::CANCELLED);
}
public function rank()

View File

@@ -2,11 +2,13 @@
namespace App\Models;
use App\Interfaces\Model;
/**
* Class UserAward
* @package App\Models
*/
class UserAward extends BaseModel
class UserAward extends Model
{
public $table = 'user_awards';