Merge pull request #242 from LordWilbur/vaflights

flights filtered per va
This commit is contained in:
Nabeel Shahzad 2018-05-19 14:04:39 -05:00 committed by GitHub
commit 77a2fd70c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 3 deletions

View File

@ -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',
]);
}
/**

View File

@ -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;
}

View File

@ -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();

View File

@ -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)
<button class="btn btn-round btn-icon btn-icon-mini
{{ in_array($flight->id, $saved, true) ? 'btn-info':'' }}
save_flight"
@ -27,6 +28,7 @@
>
<i class="fas fa-map-marker"></i>
</button>
@endif
</div>
</div>
<div class="row">