Add airport overview page and links to it #225
This commit is contained in:
@@ -113,6 +113,15 @@ class CreateSettingsTable extends Migration
|
||||
'description' => 'The units for fuel for display',
|
||||
]);
|
||||
|
||||
$this->addSetting('units.temperature', [
|
||||
'name' => 'Temperature Units',
|
||||
'group' => 'units',
|
||||
'value' => 'f',
|
||||
'type' => 'select',
|
||||
'options' => 'f=Fahrenheit,c=Celsius',
|
||||
'description' => 'The units for temperature',
|
||||
]);
|
||||
|
||||
/**
|
||||
* BIDS
|
||||
*/
|
||||
|
||||
32
app/Support/Http.php
Normal file
32
app/Support/Http.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
/**
|
||||
* Helper for HTTP stuff
|
||||
* @package App\Support
|
||||
*/
|
||||
class Http
|
||||
{
|
||||
/**
|
||||
* Download a URI. If a file is given, it will save the downloaded
|
||||
* content into that file
|
||||
* @param $uri
|
||||
* @param array $opts
|
||||
* @return string
|
||||
*/
|
||||
public static function get($uri, array $opts)
|
||||
{
|
||||
$client = new Client();
|
||||
$response = $client->request('GET', $uri, $opts);
|
||||
|
||||
$body = $response->getBody()->getContents();
|
||||
if ($response->getHeader('content-type') === 'application/json') {
|
||||
$body = \GuzzleHttp\json_decode($body);
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
52
app/Widgets/CheckWx.php
Normal file
52
app/Widgets/CheckWx.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Widgets;
|
||||
|
||||
use App\Interfaces\Widget;
|
||||
use App\Support\Http;
|
||||
|
||||
/**
|
||||
* This is a widget for the 3rd party CheckWX service
|
||||
* @package App\Widgets
|
||||
*/
|
||||
class CheckWx extends Widget
|
||||
{
|
||||
protected $config = [
|
||||
'icao' => null,
|
||||
];
|
||||
|
||||
/**
|
||||
* Attempt to get the data from the CheckWX API
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if (!config('checkwx.api_key')) {
|
||||
$data = null;
|
||||
} else {
|
||||
$url = config('checkwx.url').'/metar/'.$this->config['icao'].'/decoded';
|
||||
$data = Http::get($url, [
|
||||
'headers' => [
|
||||
'X-API-Key' => config('checkwx.api_key'),
|
||||
'content-type' => 'application/json',
|
||||
]
|
||||
]);
|
||||
|
||||
$data = json_decode($data);
|
||||
#dd($data);
|
||||
|
||||
if($data->results === 1) {
|
||||
$data = $data->data[0];
|
||||
} else {
|
||||
$data = null;
|
||||
}
|
||||
}
|
||||
|
||||
return view('widgets.check_wx', [
|
||||
'config' => $this->config,
|
||||
'data' => $data,
|
||||
'unit_alt' => setting('units.altitude'),
|
||||
'unit_dist' => setting('units.distance'),
|
||||
'unit_temp' => setting('units.temperature'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -195,3 +195,29 @@ if (!function_exists('show_date')) {
|
||||
return $date->timezone($timezone)->toFormattedDateString();
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('_fmt')) {
|
||||
/**
|
||||
* Replace strings
|
||||
* @param $line "Hi, my name is :name"
|
||||
* @param array $replace ['name' => 'Nabeel']
|
||||
* @return mixed
|
||||
*/
|
||||
function _fmt($line, array $replace)
|
||||
{
|
||||
if (empty($replace)) {
|
||||
return $line;
|
||||
}
|
||||
|
||||
foreach ($replace as $key => $value) {
|
||||
$key = strtolower($key);
|
||||
$line = str_replace(
|
||||
[':'.$key],
|
||||
[$value],
|
||||
$line
|
||||
);
|
||||
}
|
||||
|
||||
return $line;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user