Merge pull request #270 from nkevins/fix_search_flight_restriction
Fix flight search restriction
This commit is contained in:
@@ -123,13 +123,28 @@ class FlightController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function search(Request $request)
|
public function search(Request $request)
|
||||||
{
|
{
|
||||||
|
$where = [
|
||||||
|
'active' => true,
|
||||||
|
'visible' => true,
|
||||||
|
];
|
||||||
|
|
||||||
if (setting('pilots.restrict_to_company')) {
|
if (setting('pilots.restrict_to_company')) {
|
||||||
$this->flightRepo
|
$where['airline_id'] = Auth::user()->airline_id;
|
||||||
->pushCriteria(new WhereCriteria($request, ['airline_id' => Auth::user()->airline_id]))
|
}
|
||||||
->paginate();
|
|
||||||
|
// default restrictions on the flights shown. Handle search differently
|
||||||
|
if (setting('pilots.only_flights_from_current')) {
|
||||||
|
$where['dpt_airport_id'] = Auth::user()->curr_airport_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where));
|
||||||
|
} catch (RepositoryException $e) {
|
||||||
|
Log::emergency($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
$flights = $this->flightRepo->searchCriteria($request)
|
$flights = $this->flightRepo->searchCriteria($request)
|
||||||
|
->with(['dpt_airport', 'arr_airport', 'airline'])
|
||||||
->orderBy('flight_number', 'asc')
|
->orderBy('flight_number', 'asc')
|
||||||
->orderBy('route_leg', 'asc')
|
->orderBy('route_leg', 'asc')
|
||||||
->paginate();
|
->paginate();
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class SettingRepository extends Repository implements CacheableInterface
|
|||||||
case 'bool':
|
case 'bool':
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
$value = $setting->value;
|
$value = $setting->value;
|
||||||
return $value === 'true' || $value === '1' || $value === 1;
|
return $value === 'true' || $value === '1' || $value === 1 || $value === 'on';
|
||||||
case 'date':
|
case 'date':
|
||||||
return Carbon::parse($setting->value);
|
return Carbon::parse($setting->value);
|
||||||
case 'int':
|
case 'int':
|
||||||
|
|||||||
Reference in New Issue
Block a user