2018-04-03 11:35:25 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Widgets;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Widget;
|
2018-04-07 22:05:06 +08:00
|
|
|
use App\Support\Metar;
|
2018-04-03 11:35:25 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a widget for the 3rd party CheckWX service
|
|
|
|
*/
|
|
|
|
class Weather extends Widget
|
|
|
|
{
|
|
|
|
protected $config = [
|
|
|
|
'icao' => null,
|
|
|
|
];
|
|
|
|
|
|
|
|
public const URL = 'https://avwx.rest/api/metar/';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to get the data from the CheckWX API
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
2018-04-03 11:44:31 +08:00
|
|
|
/**
|
2019-07-16 03:44:31 +08:00
|
|
|
* @var \App\Contracts\Metar
|
2018-04-03 11:44:31 +08:00
|
|
|
*/
|
|
|
|
$klass = config('phpvms.metar');
|
2018-08-27 00:40:04 +08:00
|
|
|
$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-08 09:52:12 +08:00
|
|
|
$metar = new Metar($raw_metar);
|
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,
|
|
|
|
'unit_alt' => setting('units.altitude'),
|
|
|
|
'unit_dist' => setting('units.distance'),
|
|
|
|
'unit_temp' => setting('units.temperature'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|