From 993513c22b5a1ff3ba5ae05f833b3c444cdf4dd2 Mon Sep 17 00:00:00 2001 From: lordwilbur Date: Sat, 19 May 2018 00:28:34 +0200 Subject: [PATCH 1/5] flights filtered per va --- .../Controllers/Frontend/FlightController.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Frontend/FlightController.php b/app/Http/Controllers/Frontend/FlightController.php index e06589f1..fa91b85a 100644 --- a/app/Http/Controllers/Frontend/FlightController.php +++ b/app/Http/Controllers/Frontend/FlightController.php @@ -52,7 +52,8 @@ class FlightController extends Controller public function index(Request $request) { $where = [ - 'active' => true + 'active' => true, + 'airline_id' => Auth::user()->airline_id, ]; // default restrictions on the flights shown. Handle search differently @@ -68,6 +69,8 @@ class FlightController extends Controller $flights = $this->flightRepo ->orderBy('flight_number', 'asc') + ->orderBy('route_leg', 'asc') + ->orderBy('route_code', 'asc') ->paginate(); $saved_flights = Bid::where('user_id', Auth::id()) @@ -94,7 +97,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,8 +113,14 @@ class FlightController extends Controller */ public function search(Request $request) { - $flights = $this->flightRepo->searchCriteria($request)->paginate(); - + $request['airline_id'] = Auth::user()->airline_id; + + $flights = $this->flightRepo->searchCriteria($request) + ->orderBy('flight_number', 'asc') + ->orderBy('route_leg', 'asc') + ->orderBy('route_code', 'asc') + ->paginate(); + $saved_flights = Bid::where('user_id', Auth::id()) ->pluck('flight_id')->toArray(); From 0d53c5487d153e75d0208babcdeefcbc5abed6b6 Mon Sep 17 00:00:00 2001 From: lordwilbur Date: Sat, 19 May 2018 00:55:08 +0200 Subject: [PATCH 2/5] pilot unable to place bids on flight if pilots.only_flights_from_current = true and departure airport is not the same pilot's current airport. --- .../views/layouts/default/flights/table.blade.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/resources/views/layouts/default/flights/table.blade.php b/resources/views/layouts/default/flights/table.blade.php index 881701ab..57c41c24 100644 --- a/resources/views/layouts/default/flights/table.blade.php +++ b/resources/views/layouts/default/flights/table.blade.php @@ -17,29 +17,31 @@ "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
{{--
--}} - DEP  + {{ strtoupper(trans('frontend.flights.dep')) }}  {{ $flight->dpt_airport->name }} ({{$flight->dpt_airport->icao}}) @if($flight->dpt_time), {{ $flight->dpt_time }}@endif
- ARR  + {{ strtoupper(trans('frontend.flights.arr')) }}  {{ $flight->arr_airport->name }} (DISTANCE  + {{ strtoupper(trans('frontend.global.distance')) }}  {{ $flight->distance }} {{ setting('units.distance') }} @endif
@if($flight->level) - LEVEL  + {{ strtoupper(trans('frontend.flights.level')) }}  {{ $flight->level }} {{ setting('units.altitude') }} @endif
- ROUTE  + {{ strtoupper(trans('frontend.global.route')) }}  {{ $flight->route }}
From 650d9884b0d19f76d8e0e503fc0de4722850bd75 Mon Sep 17 00:00:00 2001 From: lordwilbur Date: Sat, 19 May 2018 02:03:06 +0200 Subject: [PATCH 3/5] removed tabs added setting corrected code --- ...017_06_07_014930_create_settings_table.php | 8 +++++++ .../Controllers/Frontend/FlightController.php | 22 +++++++++++-------- .../layouts/default/flights/table.blade.php | 12 +++++----- 3 files changed, 27 insertions(+), 15 deletions(-) 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/Frontend/FlightController.php b/app/Http/Controllers/Frontend/FlightController.php index fa91b85a..5d14d219 100644 --- a/app/Http/Controllers/Frontend/FlightController.php +++ b/app/Http/Controllers/Frontend/FlightController.php @@ -53,8 +53,10 @@ class FlightController extends Controller { $where = [ 'active' => true, - 'airline_id' => Auth::user()->airline_id, ]; + 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')) { @@ -70,7 +72,6 @@ class FlightController extends Controller $flights = $this->flightRepo ->orderBy('flight_number', 'asc') ->orderBy('route_leg', 'asc') - ->orderBy('route_code', 'asc') ->paginate(); $saved_flights = Bid::where('user_id', Auth::id()) @@ -113,14 +114,17 @@ class FlightController extends Controller */ public function search(Request $request) { - $request['airline_id'] = Auth::user()->airline_id; - $flights = $this->flightRepo->searchCriteria($request) - ->orderBy('flight_number', 'asc') - ->orderBy('route_leg', 'asc') - ->orderBy('route_code', 'asc') - ->paginate(); - + ->orderBy('flight_number', 'asc') + ->orderBy('route_leg', 'asc') + ->paginate(); + + if(setting('pilots.restrict_to_company')) { + $flights = $this->flightRepo + ->pushCriteria(New WhereCriteria($request, ['airline_id' => Auth::user()->airline_id])) + ->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 57c41c24..bb14795e 100644 --- a/resources/views/layouts/default/flights/table.blade.php +++ b/resources/views/layouts/default/flights/table.blade.php @@ -24,7 +24,7 @@ x-id="{{ $flight->id }}" x-saved-class="btn-info" type="button" - title="@lang('frontend.flights.addremovebid')" + title="Add/Remove Bid" > @@ -34,14 +34,14 @@
- {{ strtoupper(trans('frontend.global.route')) }}  + ROUTE  {{ $flight->route }}
From e026a8d333f72775b64421e02905bdc9507ab399 Mon Sep 17 00:00:00 2001 From: lordwilbur Date: Sat, 19 May 2018 02:37:11 +0200 Subject: [PATCH 4/5] corrected code and replicated in Api/FlightController.php --- app/Http/Controllers/Api/FlightController.php | 6 ++++++ app/Http/Controllers/Frontend/FlightController.php | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) 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 5d14d219..e6ef8aaa 100644 --- a/app/Http/Controllers/Frontend/FlightController.php +++ b/app/Http/Controllers/Frontend/FlightController.php @@ -114,17 +114,17 @@ class FlightController extends Controller */ public function search(Request $request) { + if(setting('pilots.restrict_to_company')) { + $flights = $this->flightRepo + ->pushCriteria(New WhereCriteria($request, ['airline_id' => Auth::user()->airline_id])); + } + $flights = $this->flightRepo->paginate(); + $flights = $this->flightRepo->searchCriteria($request) ->orderBy('flight_number', 'asc') ->orderBy('route_leg', 'asc') ->paginate(); - if(setting('pilots.restrict_to_company')) { - $flights = $this->flightRepo - ->pushCriteria(New WhereCriteria($request, ['airline_id' => Auth::user()->airline_id])) - ->paginate(); - } - $saved_flights = Bid::where('user_id', Auth::id()) ->pluck('flight_id')->toArray(); From 1c0c7e00124ff24f337fa74ce2146d8e5f5d1fcf Mon Sep 17 00:00:00 2001 From: lordwilbur Date: Sat, 19 May 2018 09:05:24 +0200 Subject: [PATCH 5/5] removed $flights variable --- app/Http/Controllers/Frontend/FlightController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Frontend/FlightController.php b/app/Http/Controllers/Frontend/FlightController.php index e6ef8aaa..f23780cf 100644 --- a/app/Http/Controllers/Frontend/FlightController.php +++ b/app/Http/Controllers/Frontend/FlightController.php @@ -115,10 +115,10 @@ class FlightController extends Controller public function search(Request $request) { if(setting('pilots.restrict_to_company')) { - $flights = $this->flightRepo - ->pushCriteria(New WhereCriteria($request, ['airline_id' => Auth::user()->airline_id])); + $this->flightRepo + ->pushCriteria(New WhereCriteria($request, ['airline_id' => Auth::user()->airline_id])) + ->paginate(); } - $flights = $this->flightRepo->paginate(); $flights = $this->flightRepo->searchCriteria($request) ->orderBy('flight_number', 'asc')