2018-04-03 11:35:25 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Widgets;
|
|
|
|
|
|
|
|
use App\Interfaces\Widget;
|
|
|
|
use App\Support\Http;
|
2018-04-05 09:59:52 +08:00
|
|
|
use App\Support\MetarWrapper;
|
2018-04-03 11:35:25 +08:00
|
|
|
use App\Support\Units\Distance;
|
|
|
|
use App\Support\Units\Temperature;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use MetarDecoder\MetarDecoder;
|
|
|
|
use SimpleXMLElement;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a widget for the 3rd party CheckWX service
|
|
|
|
* @package App\Widgets
|
|
|
|
*/
|
|
|
|
class Weather extends Widget
|
|
|
|
{
|
|
|
|
protected $config = [
|
|
|
|
'icao' => null,
|
|
|
|
];
|
|
|
|
|
|
|
|
public const URL = 'https://avwx.rest/api/metar/';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine the category depending on the rules for visibility/ceiling
|
|
|
|
* https://www.aviationweather.gov/cva/help
|
|
|
|
* @param $metar
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function determineCategory($metar): string
|
|
|
|
{
|
2018-04-04 22:04:14 +08:00
|
|
|
|
2018-04-03 11:35:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to get the data from the CheckWX API
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
2018-04-03 11:44:31 +08:00
|
|
|
/**
|
|
|
|
* @var \App\Interfaces\Metar
|
|
|
|
*/
|
|
|
|
$klass = config('phpvms.metar');
|
|
|
|
$metar_class = new $klass;
|
2018-04-04 22:04:14 +08:00
|
|
|
|
2018-04-05 06:14:46 +08:00
|
|
|
$metar = null;
|
|
|
|
$wind = null;
|
|
|
|
$raw_metar = $metar_class->get_metar($this->config['icao']);
|
2018-04-03 11:35:25 +08:00
|
|
|
|
2018-04-05 06:14:46 +08:00
|
|
|
if ($raw_metar && $raw_metar !== '') {
|
2018-04-05 09:59:52 +08:00
|
|
|
$metar = new MetarWrapper($raw_metar);
|
2018-04-05 06:14:46 +08:00
|
|
|
$wind = $metar->getWinds();
|
2018-04-04 22:04:14 +08:00
|
|
|
}
|
2018-04-03 11:35:25 +08:00
|
|
|
|
|
|
|
return view('widgets.weather', [
|
|
|
|
'config' => $this->config,
|
|
|
|
'metar' => $metar,
|
2018-04-05 06:14:46 +08:00
|
|
|
'wind' => $wind,
|
2018-04-03 11:35:25 +08:00
|
|
|
'unit_alt' => setting('units.altitude'),
|
|
|
|
'unit_dist' => setting('units.distance'),
|
|
|
|
'unit_temp' => setting('units.temperature'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|