2020-03-23 21:31:35 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use App\Contracts\Model;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
/**
|
2020-08-12 05:48:51 +08:00
|
|
|
* @property string $id The Simbrief OFP ID
|
|
|
|
* @property int $user_id The user that generated this
|
|
|
|
* @property string $flight_id Optional, if attached to a flight, removed if attached to PIREP
|
|
|
|
* @property string $pirep_id Optional, if attached to a PIREP, removed if attached to flight
|
2021-03-10 00:36:56 +08:00
|
|
|
* @property string $aircraft_id The aircraft this is for
|
2020-03-23 21:31:35 +08:00
|
|
|
* @property string $acars_xml
|
|
|
|
* @property string $ofp_xml
|
|
|
|
* @property string $ofp_html
|
2021-03-03 01:29:04 +08:00
|
|
|
* @property string $fare_data JSON string of the fare data that was generated
|
2020-03-23 21:31:35 +08:00
|
|
|
* @property Collection $images
|
|
|
|
* @property Collection $files
|
|
|
|
* @property Flight $flight
|
|
|
|
* @property User $user
|
|
|
|
* @property SimBriefXML $xml
|
2021-03-03 01:29:04 +08:00
|
|
|
* @property Aircraft $aircraft
|
2020-03-23 21:31:35 +08:00
|
|
|
* @property string $acars_flightplan_url
|
|
|
|
*/
|
|
|
|
class SimBrief extends Model
|
|
|
|
{
|
|
|
|
public $table = 'simbrief';
|
|
|
|
public $incrementing = false;
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
'id',
|
|
|
|
'user_id',
|
|
|
|
'flight_id',
|
2021-03-03 01:29:04 +08:00
|
|
|
'aircraft_id',
|
2020-03-23 21:31:35 +08:00
|
|
|
'pirep_id',
|
|
|
|
'acars_xml',
|
|
|
|
'ofp_xml',
|
2021-03-03 01:29:04 +08:00
|
|
|
'fare_data',
|
2020-03-23 21:31:35 +08:00
|
|
|
'created_at',
|
|
|
|
'updated_at',
|
|
|
|
];
|
|
|
|
|
|
|
|
/** @var \App\Models\SimBriefXML Store a cached version of the XML object */
|
|
|
|
private $xml_instance;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a SimpleXML object of the $ofp_xml
|
|
|
|
*
|
|
|
|
* @return \App\Models\SimBriefXML|null
|
|
|
|
*/
|
|
|
|
public function getXmlAttribute(): SimBriefXML
|
|
|
|
{
|
|
|
|
if (empty($this->attributes['ofp_xml'])) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->xml_instance) {
|
|
|
|
$this->xml_instance = simplexml_load_string(
|
|
|
|
$this->attributes['ofp_xml'],
|
|
|
|
SimBriefXML::class
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->xml_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of images
|
|
|
|
*/
|
|
|
|
public function getImagesAttribute(): Collection
|
|
|
|
{
|
|
|
|
return $this->xml->getImages();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all of the flight plans
|
|
|
|
*/
|
|
|
|
public function getFilesAttribute(): Collection
|
|
|
|
{
|
|
|
|
return $this->xml->getFlightPlans();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Relationships
|
|
|
|
*/
|
|
|
|
|
2021-03-03 01:29:04 +08:00
|
|
|
public function aircraft()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Aircraft::class, 'aircraft_id');
|
|
|
|
}
|
|
|
|
|
2020-03-23 21:31:35 +08:00
|
|
|
public function flight()
|
|
|
|
{
|
|
|
|
if (!empty($this->attributes['flight_id'])) {
|
|
|
|
return $this->belongsTo(Flight::class, 'flight_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($this->attributes['pirep_id'])) {
|
|
|
|
return $this->belongsTo(Pirep::class, 'pirep_id');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
|
|
}
|
|
|
|
}
|