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
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\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;
|
2017-12-20 10:19:36 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class Acars
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param string id
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-05-12 01:08:55 +08:00
|
|
|
* @property string pirep_id
|
|
|
|
* @property int type
|
|
|
|
* @property string name
|
2018-08-27 00:40:04 +08:00
|
|
|
* @property float lat
|
|
|
|
* @property float lon
|
|
|
|
* @property float altitude
|
2018-05-12 01:08:55 +08:00
|
|
|
* @property int gs
|
|
|
|
* @property int heading
|
|
|
|
* @property int order
|
|
|
|
* @property int nav_type
|
2018-03-20 09:50:40 +08:00
|
|
|
*/
|
|
|
|
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';
|
2019-09-13 20:05:02 +08:00
|
|
|
|
|
|
|
protected $keyType = 'string';
|
2018-01-01 04:20:52 +08:00
|
|
|
public $incrementing = false;
|
2017-12-26 05:19:34 +08:00
|
|
|
|
|
|
|
public $fillable = [
|
2018-12-27 23:35:40 +08:00
|
|
|
'id',
|
2017-12-26 05:19:34 +08:00
|
|
|
'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-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-04 04:06:50 +08:00
|
|
|
/**
|
|
|
|
* Set the distance unit, convert to our internal default unit
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-05-04 04:06:50 +08:00
|
|
|
* @param $value
|
|
|
|
*/
|
|
|
|
public function setDistanceAttribute($value): void
|
|
|
|
{
|
|
|
|
if ($value instanceof Distance) {
|
|
|
|
$this->attributes['distance'] = $value->toUnit(
|
2019-05-13 02:26:44 +08:00
|
|
|
config('phpvms.internal_units.distance')
|
|
|
|
);
|
2018-05-04 04:06:50 +08:00
|
|
|
} else {
|
|
|
|
$this->attributes['distance'] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the amount of fuel
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-05-04 04:06:50 +08:00
|
|
|
* @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
|
|
|
}
|