Skip to content

Commit

Permalink
Update FlightController.php (#1663)
Browse files Browse the repository at this point in the history
Adjust controller to show open (non-restricted by rank/type rating) flights too when restrictions are in place.

This will allow VA's to have both open to all and limited/restricted flights. And those flights should be able to be selected, operated by pilots.
  • Loading branch information
FatihKoz authored Nov 1, 2023
1 parent 47cf80f commit 342a353
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/Http/Controllers/Frontend/FlightController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,16 @@ public function search(Request $request): View
// Get allowed subfleets for the user
$user_subfleets = $this->userSvc->getAllowableSubfleets($user)->pluck('id')->toArray();
// Get flight_id's from relationships (group by flight id to reduce the array size)
$allowed_flights = DB::table('flight_subfleet')
->select('flight_id')
->whereIn('subfleet_id', $user_subfleets)
$user_flights = DB::table('flight_subfleet')
->select('flight_id')
->whereIn('subfleet_id', $user_subfleets)
->groupBy('flight_id')
->pluck('flight_id')
->toArray();
// Get flight_id's of open (non restricted) flights
$open_flights = Flight::withCount('subfleets')->whereNull('user_id')->having('subfleets_count', 0)->pluck('id')->toArray();
// Merge results
$allowed_flights = array_merge($user_flights, $open_flights);
} else {
$allowed_flights = [];
}
Expand Down

0 comments on commit 342a353

Please sign in to comment.