diff --git a/app/Database/migrations/2017_06_07_014930_create_settings_table.php b/app/Database/migrations/2017_06_07_014930_create_settings_table.php index 6801be0b..b70fe1b5 100644 --- a/app/Database/migrations/2017_06_07_014930_create_settings_table.php +++ b/app/Database/migrations/2017_06_07_014930_create_settings_table.php @@ -276,6 +276,14 @@ class CreateSettingsTable extends Migration 'type' => 'boolean', 'description' => 'Don\'t show inactive pilots in the public view', ]); + + $this->addSetting('pilots.restrict_to_company', [ + 'name' => 'Restrict the flights to company', + 'group' => 'pilots', + 'value' => false, + 'type' => 'boolean', + 'description' => 'Restrict flights to the user\'s airline', + ]); } /** diff --git a/app/Http/Controllers/Api/FlightController.php b/app/Http/Controllers/Api/FlightController.php index 947edd90..cfb8b119 100644 --- a/app/Http/Controllers/Api/FlightController.php +++ b/app/Http/Controllers/Api/FlightController.php @@ -45,6 +45,9 @@ class FlightController extends Controller $user = Auth::user(); $where = ['active' => true]; + if(setting('pilots.restrict_to_company')) { + $where['airline_id'] = Auth::user()->airline_id; + } if (setting('pilots.only_flights_from_current', false)) { $where['dpt_airport_id'] = $user->curr_airport_id; } @@ -82,6 +85,9 @@ class FlightController extends Controller try { $where = ['active' => true]; + if(setting('pilots.restrict_to_company')) { + $where['airline_id'] = Auth::user()->airline_id; + } if (setting('pilots.only_flights_from_current')) { $where['dpt_airport_id'] = Auth::user()->curr_airport_id; } diff --git a/app/Http/Controllers/Frontend/FlightController.php b/app/Http/Controllers/Frontend/FlightController.php index e06589f1..f23780cf 100644 --- a/app/Http/Controllers/Frontend/FlightController.php +++ b/app/Http/Controllers/Frontend/FlightController.php @@ -52,8 +52,11 @@ class FlightController extends Controller public function index(Request $request) { $where = [ - 'active' => true + 'active' => true, ]; + if(setting('pilots.restrict_to_company')) { + $where['airline_id'] = Auth::user()->airline_id; + } // default restrictions on the flights shown. Handle search differently if (setting('pilots.only_flights_from_current')) { @@ -68,6 +71,7 @@ class FlightController extends Controller $flights = $this->flightRepo ->orderBy('flight_number', 'asc') + ->orderBy('route_leg', 'asc') ->paginate(); $saved_flights = Bid::where('user_id', Auth::id()) @@ -94,7 +98,7 @@ class FlightController extends Controller $saved_flights = $flights->pluck('id')->toArray(); return view('flights.index', [ - 'title' => 'Bids', + 'title' => trans_choice('frontend.flights.mybid', 2), 'airlines' => $this->airlineRepo->selectBoxList(true), 'airports' => $this->airportRepo->selectBoxList(true), 'flights' => $flights, @@ -110,7 +114,16 @@ class FlightController extends Controller */ public function search(Request $request) { - $flights = $this->flightRepo->searchCriteria($request)->paginate(); + if(setting('pilots.restrict_to_company')) { + $this->flightRepo + ->pushCriteria(New WhereCriteria($request, ['airline_id' => Auth::user()->airline_id])) + ->paginate(); + } + + $flights = $this->flightRepo->searchCriteria($request) + ->orderBy('flight_number', 'asc') + ->orderBy('route_leg', 'asc') + ->paginate(); $saved_flights = Bid::where('user_id', Auth::id()) ->pluck('flight_id')->toArray(); diff --git a/resources/views/layouts/default/flights/table.blade.php b/resources/views/layouts/default/flights/table.blade.php index 881701ab..bb14795e 100644 --- a/resources/views/layouts/default/flights/table.blade.php +++ b/resources/views/layouts/default/flights/table.blade.php @@ -17,6 +17,7 @@ "x-saved-class" is the class to add/remove if the bid exists or not If you change it, remember to change it in the in-array line as well --}} + @if (!setting('pilots.only_flights_from_current') || $flight->dpt_airport->icao == Auth::user()->current_airport->icao) + @endif