2017-12-20 10:19:36 +08:00
|
|
|
<?php
|
|
|
|
|
2017-12-26 05:19:34 +08:00
|
|
|
namespace App\Models;
|
2017-12-20 10:19:36 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Model;
|
2018-03-08 22:51:36 +08:00
|
|
|
use App\Models\Traits\HashIdTrait;
|
2018-05-04 04:06:50 +08:00
|
|
|
use App\Support\Units\Distance;
|
|
|
|
use App\Support\Units\Fuel;
|
|
|
|
use PhpUnitsOfMeasure\Exception\NonNumericValue;
|
|
|
|
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
|
2017-12-20 10:19:36 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class Acars
|
|
|
|
* @param string id
|
2018-05-12 01:08:55 +08:00
|
|
|
* @property string pirep_id
|
|
|
|
* @property int type
|
|
|
|
* @property string name
|
|
|
|
* @property double lat
|
|
|
|
* @property double lon
|
|
|
|
* @property double altitude
|
|
|
|
* @property int gs
|
|
|
|
* @property int heading
|
|
|
|
* @property int order
|
|
|
|
* @property int nav_type
|
2018-03-20 09:50:40 +08:00
|
|
|
* @package App\Models
|
|
|
|
*/
|
|
|
|
class Acars extends Model
|
2017-12-20 10:19:36 +08:00
|
|
|
{
|
2018-03-08 22:51:36 +08:00
|
|
|
use HashIdTrait;
|
2017-12-26 05:19:34 +08:00
|
|
|
|
2017-12-20 10:19:36 +08:00
|
|
|
public $table = 'acars';
|
2018-01-01 04:20:52 +08:00
|
|
|
public $incrementing = false;
|
2017-12-26 05:19:34 +08:00
|
|
|
|
|
|
|
public $fillable = [
|
|
|
|
'pirep_id',
|
2018-01-02 00:30:31 +08:00
|
|
|
'type',
|
2018-01-02 03:48:02 +08:00
|
|
|
'nav_type',
|
2018-01-02 23:40:42 +08:00
|
|
|
'order',
|
2018-01-02 03:48:02 +08:00
|
|
|
'name',
|
2018-05-04 04:06:50 +08:00
|
|
|
'status',
|
2017-12-26 08:22:46 +08:00
|
|
|
'log',
|
2017-12-26 05:19:34 +08:00
|
|
|
'lat',
|
|
|
|
'lon',
|
2018-05-04 04:06:50 +08:00
|
|
|
'distance',
|
2017-12-26 08:22:46 +08:00
|
|
|
'heading',
|
2017-12-26 05:19:34 +08:00
|
|
|
'altitude',
|
|
|
|
'vs',
|
|
|
|
'gs',
|
|
|
|
'transponder',
|
|
|
|
'autopilot',
|
|
|
|
'fuel_flow',
|
|
|
|
'sim_time',
|
2018-05-09 06:30:44 +08:00
|
|
|
'created_at',
|
|
|
|
'updated_at',
|
2017-12-26 05:19:34 +08:00
|
|
|
];
|
|
|
|
|
2017-12-26 08:10:24 +08:00
|
|
|
public $casts = [
|
2018-03-20 09:50:40 +08:00
|
|
|
'type' => 'integer',
|
|
|
|
'order' => 'integer',
|
|
|
|
'nav_type' => 'integer',
|
|
|
|
'lat' => 'float',
|
|
|
|
'lon' => 'float',
|
2018-05-04 04:06:50 +08:00
|
|
|
'distance' => 'integer',
|
2018-03-20 09:50:40 +08:00
|
|
|
'heading' => 'integer',
|
|
|
|
'altitude' => 'float',
|
|
|
|
'vs' => 'float',
|
|
|
|
'gs' => 'float',
|
|
|
|
'transponder' => 'integer',
|
2018-05-04 04:06:50 +08:00
|
|
|
'fuel' => 'float',
|
2018-03-20 09:50:40 +08:00
|
|
|
'fuel_flow' => 'float',
|
2017-12-26 08:10:24 +08:00
|
|
|
];
|
2018-05-12 01:08:55 +08:00
|
|
|
/*public static $sanitize = [
|
|
|
|
'sim_time' => 'carbon',
|
|
|
|
'created_at' => '',
|
|
|
|
];*/
|
2017-12-26 08:10:24 +08:00
|
|
|
|
2018-01-01 04:20:52 +08:00
|
|
|
public static $rules = [
|
2018-03-20 09:50:40 +08:00
|
|
|
'pirep_id' => 'required',
|
2018-01-01 04:20:52 +08:00
|
|
|
];
|
|
|
|
|
2018-05-10 01:45:24 +08:00
|
|
|
|
2018-05-04 04:06:50 +08:00
|
|
|
/**
|
|
|
|
* Return a new Length unit so conversions can be made
|
|
|
|
* @return int|Distance
|
|
|
|
*/
|
|
|
|
public function getDistanceAttribute()
|
|
|
|
{
|
|
|
|
if (!array_key_exists('distance', $this->attributes)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$distance = (float) $this->attributes['distance'];
|
|
|
|
if ($this->skip_mutator) {
|
|
|
|
return $distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Distance($distance, config('phpvms.internal_units.distance'));
|
|
|
|
} catch (NonNumericValue $e) {
|
|
|
|
return 0;
|
|
|
|
} catch (NonStringUnitName $e) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the distance unit, convert to our internal default unit
|
|
|
|
* @param $value
|
|
|
|
*/
|
|
|
|
public function setDistanceAttribute($value): void
|
|
|
|
{
|
|
|
|
if ($value instanceof Distance) {
|
|
|
|
$this->attributes['distance'] = $value->toUnit(
|
|
|
|
config('phpvms.internal_units.distance'));
|
|
|
|
} else {
|
|
|
|
$this->attributes['distance'] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a new Fuel unit so conversions can be made
|
|
|
|
* @return int|Fuel
|
|
|
|
*/
|
|
|
|
public function getFuelAttribute()
|
|
|
|
{
|
|
|
|
if (!array_key_exists('fuel', $this->attributes)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$fuel = (float) $this->attributes['fuel'];
|
|
|
|
return new Fuel($fuel, config('phpvms.internal_units.fuel'));
|
|
|
|
} catch (NonNumericValue $e) {
|
|
|
|
return 0;
|
|
|
|
} catch (NonStringUnitName $e) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the amount of fuel
|
|
|
|
* @param $value
|
|
|
|
*/
|
|
|
|
public function setFuelAttribute($value)
|
|
|
|
{
|
|
|
|
if ($value instanceof Fuel) {
|
|
|
|
$this->attributes['fuel'] = $value->toUnit(
|
|
|
|
config('phpvms.internal_units.fuel')
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->attributes['fuel'] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-26 05:19:34 +08:00
|
|
|
/**
|
|
|
|
* FKs
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function pirep()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsTo(Pirep::class, 'pirep_id');
|
2017-12-26 05:19:34 +08:00
|
|
|
}
|
2017-12-20 10:19:36 +08:00
|
|
|
}
|