* SimBrief integration #405 * Add briefing as API response; add acars_xml field #405
This commit is contained in:
121
app/Models/SimBriefXML.php
Normal file
121
app/Models/SimBriefXML.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* Represents the SimBrief XML instance with some helper methods
|
||||
*/
|
||||
class SimBriefXML extends SimpleXMLElement
|
||||
{
|
||||
/**
|
||||
* Return a padded flight level
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFlightLevel(): string
|
||||
{
|
||||
if (empty($this->alternate->cruise_altitude)) {
|
||||
return '0'; // unknown?
|
||||
}
|
||||
|
||||
$fl = (int) ($this->alternate->cruise_altitude) / 100;
|
||||
|
||||
return str_pad($fl, 3, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all of the flightplans
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getFlightPlans(): Collection
|
||||
{
|
||||
$fps = [];
|
||||
$base_url = $this->fms_downloads->directory;
|
||||
|
||||
// TODO: Put vmsACARS on top
|
||||
if (!empty($this->fms_downloads->vma)) {
|
||||
$fps[] = [
|
||||
'name' => $this->fms_downloads->vma->name->__toString(),
|
||||
'url' => $base_url.$this->fms_downloads->vma->link,
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($this->fms_downloads->children() as $child) {
|
||||
if ($child->getName() === 'directory') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fps[] = [
|
||||
'name' => $child->name->__toString(),
|
||||
'url' => $base_url.$child->link,
|
||||
];
|
||||
}
|
||||
|
||||
return collect($fps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a generator which sends out the fix values. This can be a long list
|
||||
*
|
||||
* @return \Generator
|
||||
*/
|
||||
public function getRoute()
|
||||
{
|
||||
foreach ($this->navlog->children()->fix as $fix) {
|
||||
$type = $fix->type->__toString();
|
||||
if ($type === 'apt') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$ident = $fix->ident->__toString();
|
||||
|
||||
if ($ident === 'TOC' || $ident === 'TOD') {
|
||||
continue;
|
||||
}
|
||||
|
||||
yield $fix;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the route as a string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRouteString(): string
|
||||
{
|
||||
if (!empty($this->general->route)) {
|
||||
return $this->general->route->__toString();
|
||||
}
|
||||
|
||||
$route = [];
|
||||
foreach ($this->getRoute() as $fix) {
|
||||
$route[] = $fix->ident->__toString();
|
||||
}
|
||||
|
||||
return implode(' ', $route);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all of the image links
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getImages(): Collection
|
||||
{
|
||||
$images = [];
|
||||
$base_url = $this->images->directory;
|
||||
foreach ($this->images->map as $image) {
|
||||
$images[] = [
|
||||
'name' => $image->name->__toString(),
|
||||
'url' => $base_url.$image->link,
|
||||
];
|
||||
}
|
||||
|
||||
return collect($images);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user