From 0af85a3fff9221fba9c2fe1e7ae06ca33770e113 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Thu, 12 Jul 2018 22:29:50 -0500 Subject: [PATCH] Only show flights if they're also marked as visible --- app/Cron/Nightly/SetActiveFlights.php | 9 +++++++-- app/Http/Controllers/Api/FlightController.php | 12 ++++++++++-- app/Http/Controllers/Frontend/FlightController.php | 4 +++- app/Repositories/FlightRepository.php | 3 ++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/Cron/Nightly/SetActiveFlights.php b/app/Cron/Nightly/SetActiveFlights.php index c3387844..897a5c70 100644 --- a/app/Cron/Nightly/SetActiveFlights.php +++ b/app/Cron/Nightly/SetActiveFlights.php @@ -40,7 +40,6 @@ class SetActiveFlights extends Listener * @var Flight $flight */ foreach($flights as $flight) { - if (!$flight->active) { continue; } @@ -54,6 +53,9 @@ class SetActiveFlights extends Listener Log::info('Marking flight '.$flight->ident.' to '.($visible ? 'visible' : 'invisible')); $flight->visible = $visible; } + } else { + Log::info('Toggling flight '.$flight->ident.' to visible'); + $flight->visible = true; } $flight->save(); @@ -72,7 +74,10 @@ class SetActiveFlights extends Listener $flight->visible = true; } } else { - $flight->visible = true; + if ($flight->visible !== true) { + Log::info('Toggling flight '.$flight->ident.' to visible'); + $flight->visible = true; + } } } else { $flight->visible = false; diff --git a/app/Http/Controllers/Api/FlightController.php b/app/Http/Controllers/Api/FlightController.php index cfb8b119..4d156200 100644 --- a/app/Http/Controllers/Api/FlightController.php +++ b/app/Http/Controllers/Api/FlightController.php @@ -44,7 +44,11 @@ class FlightController extends Controller { $user = Auth::user(); - $where = ['active' => true]; + $where = [ + 'active' => true, + 'visible' => true, + ]; + if(setting('pilots.restrict_to_company')) { $where['airline_id'] = Auth::user()->airline_id; } @@ -84,7 +88,11 @@ class FlightController extends Controller $user = Auth::user(); try { - $where = ['active' => true]; + $where = [ + 'active' => true, + 'visible' => true, + ]; + if(setting('pilots.restrict_to_company')) { $where['airline_id'] = Auth::user()->airline_id; } diff --git a/app/Http/Controllers/Frontend/FlightController.php b/app/Http/Controllers/Frontend/FlightController.php index a974f3d7..04625446 100644 --- a/app/Http/Controllers/Frontend/FlightController.php +++ b/app/Http/Controllers/Frontend/FlightController.php @@ -52,8 +52,10 @@ class FlightController extends Controller public function index(Request $request) { $where = [ - 'active' => true, + 'active' => true, + 'visible' => true, ]; + if(setting('pilots.restrict_to_company')) { $where['airline_id'] = Auth::user()->airline_id; } diff --git a/app/Repositories/FlightRepository.php b/app/Repositories/FlightRepository.php index 350772c5..c9762514 100644 --- a/app/Repositories/FlightRepository.php +++ b/app/Repositories/FlightRepository.php @@ -71,7 +71,8 @@ class FlightRepository extends Repository implements CacheableInterface $where = []; if ($only_active === true) { - $where['active'] = $only_active; + $where['active'] = $only_active; + $where['visible'] = $only_active; } if ($request->filled('flight_id')) {