diff --git a/app/Database/seeds/dev.yml b/app/Database/seeds/dev.yml index 0803be30..72ea728c 100644 --- a/app/Database/seeds/dev.yml +++ b/app/Database/seeds/dev.yml @@ -18,9 +18,10 @@ users: rank_id: 1 home_airport_id: KAUS curr_airport_id: KJFK + last_pirep_id: pirepid_3 flights: 3 flight_time: 43200 - last_pirep_id: pirepid_3 + timezone: America/Chicago state: 1 created_at: now updated_at: now @@ -197,6 +198,8 @@ flights: route: KAUS SID TNV J87 IAH J2 LCH J22 MEI J239 ATL J52 AJFEB J14 BYJAC Q60 JAXSN J14 COLIN J61 HUBBS J55 SIE STAR KJFK dpt_time: 6PM CST arr_time: 11PM EST + created_at: NOW + updated_at: NOW - id: flightid_2 airline_id: 1 flight_number: 101 @@ -205,6 +208,8 @@ flights: dpt_time: 9AM EST arr_time: 12PM CST route: KJFK KAUS + created_at: NOW + updated_at: NOW - id: flightid_3 airline_id: 1 flight_number: 200 @@ -213,6 +218,8 @@ flights: dpt_time: 9AM EST arr_time: 12PM CST route: KJFK KAUS + created_at: NOW + updated_at: NOW - id: flightid_4 airline_id: 1 flight_number: 201 @@ -221,6 +228,8 @@ flights: dpt_time: 10AM EST arr_time: 1PM CST route: KJFK KAUS + created_at: NOW + updated_at: NOW - id: flightid_5 airline_id: 1 flight_number: 202 @@ -340,6 +349,8 @@ pireps: state: 0 route: PLMMR2 SPA Q22 BEARI FAK PHLBO3 notes: just a pilot report + created_at: NOW + updated_at: NOW - id: pirepid_2 user_id: 1 airline_id: 1 @@ -351,6 +362,8 @@ pireps: state: 0 route: PLMMR2 SPA Q22 BEARI FAK PHLBO3 notes: just a pilot report + created_at: NOW + updated_at: NOW - id: pirepid_3 user_id: 1 airline_id: 1 @@ -362,6 +375,8 @@ pireps: state: 0 route: PLMMR2 SPA Q22 BEARI FAK PHLBO3 notes: just a pilot report + created_at: NOW + updated_at: NOW pirep_fields: - id: 1 diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 2040b4da..8c931225 100755 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -4,9 +4,10 @@ namespace App\Http\Controllers\Auth; use Log; use Validator; +use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; use Illuminate\Foundation\Auth\RegistersUsers; -use Illuminate\Http\Request; +use Jackiedo\Timezonelist\Facades\Timezonelist; use App\Models\User; use App\Facades\Utils; @@ -53,6 +54,7 @@ class RegisterController extends Controller return $this->view('auth.register', [ 'airports' => $airports, 'airlines' => $airlines, + 'timezones' => Timezonelist::toArray(), ]); } diff --git a/app/Services/DatabaseService.php b/app/Services/DatabaseService.php index a9c9416f..d485579b 100644 --- a/app/Services/DatabaseService.php +++ b/app/Services/DatabaseService.php @@ -55,7 +55,7 @@ class DatabaseService extends BaseService # if any time fields are == to "now", then insert the right time foreach($this->time_fields as $tf) { - if(array_key_exists($tf, $row) && $row[$tf] === 'now') { + if(array_key_exists($tf, $row) && strtolower($row[$tf]) === 'now') { $row[$tf] = $this->time(); } } diff --git a/app/Services/GeoService.php b/app/Services/GeoService.php index f6ee9b01..6267d589 100644 --- a/app/Services/GeoService.php +++ b/app/Services/GeoService.php @@ -178,13 +178,26 @@ class GeoService extends BaseService * @param Pirep $pirep * @return array */ - public function pirepGeoJson(Pirep $pirep) + public function pirepGeoJson($pirep) { $coords = []; $coords[] = [$pirep->dpt_airport->lon, $pirep->dpt_airport->lat]; // TODO: Add markers for the start/end airports - // TODO: Read from the ACARS data table + + // TODO: Check if there's data in the ACARS table + if (!empty($pirep->route)) { + $route_coords = $this->getCoordsFromRoute( + $pirep->dpt_airport->icao, + $pirep->arr_airport->icao, + [$pirep->dpt_airport->lat, $pirep->dpt_airport->lon], + $pirep->route); + + // lat, lon needs to be reversed for GeoJSON + foreach ($route_coords as $rc) { + $coords[] = [$rc[1], $rc[0]]; + } + } $coords[] = [$pirep->arr_airport->lon, $pirep->arr_airport->lat]; diff --git a/app/helpers.php b/app/helpers.php index 192e83c3..5c202967 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -3,7 +3,8 @@ /** * Shortcut for retrieving a setting value */ -if (!function_exists('setting')) { +if (!function_exists('setting')) +{ function setting($key, $value = null) { $settingRepo = app('setting'); // defined in AppServiceProvider @@ -19,7 +20,8 @@ if (!function_exists('setting')) { * Wrap the asset URL in the publicBaseUrl that's been * set */ -if (!function_exists('public_asset')) { +if (!function_exists('public_asset')) +{ function public_asset($path, $parameters = [], $secure = null) { $publicBaseUrl = app()->publicUrlPath(); @@ -32,3 +34,46 @@ if (!function_exists('public_asset')) { return url($path, $parameters, $secure); } } + +/** + * Show a date/time in the proper timezone for a user + */ +if(!function_exists('show_datetime')) +{ + /** + * Format the a Carbon date into the datetime string + * but convert it into the user's timezone + * @param \Carbon\Carbon $date + * @return string + */ + function show_datetime(\Carbon\Carbon $date) + { + $timezone = 'UTC'; + if (Auth::check()) { + $timezone = Auth::user()->timezone ?: $timezone; + } + + return $date->timezone($timezone)->toDayDateTimeString(); + } +} + +/** + * Show a date/time in the proper timezone for a user + */ +if (!function_exists('show_date')) { + /** + * Format the a Carbon date into the datetime string + * but convert it into the user's timezone + * @param \Carbon\Carbon $date + * @return string + */ + function show_date(\Carbon\Carbon $date) + { + $timezone = 'UTC'; + if (Auth::check()) { + $timezone = Auth::user()->timezone ?: $timezone; + } + + return $date->timezone($timezone)->toFormattedDateString(); + } +} diff --git a/config/app.php b/config/app.php index c8c66bf5..ba527c04 100755 --- a/config/app.php +++ b/config/app.php @@ -8,7 +8,9 @@ return [ 'url' => env('APP_URL', 'http://localhost'), 'version' => '7.0', + # DON'T CHANGE THIS OR ELSE YOUR TIMES WILL BE MESSED UP! 'timezone' => 'UTC', + 'locale' => env('APP_LOCALE', 'en'), 'fallback_locale' => 'en', diff --git a/resources/views/admin/pireps/pirep_card.blade.php b/resources/views/admin/pireps/pirep_card.blade.php index 04acee7e..d15362d7 100644 --- a/resources/views/admin/pireps/pirep_card.blade.php +++ b/resources/views/admin/pireps/pirep_card.blade.php @@ -21,7 +21,7 @@
{{ $errors->first('home_airport_id') }}
@endif + +{{ $errors->first('timezone') }}
+ @endif +