Restrict the aircraft to only show the user's #138
This commit is contained in:
2
Makefile
2
Makefile
@@ -62,7 +62,7 @@ reload-db:
|
|||||||
@php artisan database:create --reset
|
@php artisan database:create --reset
|
||||||
@php artisan migrate:refresh --seed
|
@php artisan migrate:refresh --seed
|
||||||
@php artisan phpvms:import app/Database/seeds/sample.yml
|
@php artisan phpvms:import app/Database/seeds/sample.yml
|
||||||
@php artisan phpvms:navdata
|
#php artisan phpvms:navdata
|
||||||
|
|
||||||
.PHONY: tests
|
.PHONY: tests
|
||||||
tests: test
|
tests: test
|
||||||
|
|||||||
@@ -190,14 +190,11 @@ aircraft:
|
|||||||
name: Boeing 777-200
|
name: Boeing 777-200
|
||||||
registration: NC20
|
registration: NC20
|
||||||
tail_number: 20
|
tail_number: 20
|
||||||
|
- id: 3
|
||||||
#aircraft_rank:
|
subfleet_id: 1
|
||||||
# - aircraft_id: 1
|
name: Boeing 747-412
|
||||||
# rank_id: 1
|
registration: NS233
|
||||||
# - aircraft_id: 1
|
tail_number: 1233
|
||||||
# rank_id: 2
|
|
||||||
# acars_pay: 100
|
|
||||||
# manual_pay: 50
|
|
||||||
|
|
||||||
fares:
|
fares:
|
||||||
- id: 1
|
- id: 1
|
||||||
@@ -253,6 +250,10 @@ subfleet_flight:
|
|||||||
- subfleet_id: 1
|
- subfleet_id: 1
|
||||||
flight_id: flightid_1
|
flight_id: flightid_1
|
||||||
|
|
||||||
|
subfleet_rank:
|
||||||
|
- rank_id: 1
|
||||||
|
subfleet_id: 1
|
||||||
|
|
||||||
flights:
|
flights:
|
||||||
- id: flightid_1
|
- id: flightid_1
|
||||||
airline_id: 1
|
airline_id: 1
|
||||||
|
|||||||
@@ -16,10 +16,13 @@ use App\Models\Enums\PirepState;
|
|||||||
|
|
||||||
use App\Http\Requests\CreatePirepRequest;
|
use App\Http\Requests\CreatePirepRequest;
|
||||||
use App\Http\Requests\UpdatePirepRequest;
|
use App\Http\Requests\UpdatePirepRequest;
|
||||||
|
|
||||||
use App\Repositories\AircraftRepository;
|
use App\Repositories\AircraftRepository;
|
||||||
use App\Repositories\AirlineRepository;
|
use App\Repositories\AirlineRepository;
|
||||||
use App\Repositories\AirportRepository;
|
use App\Repositories\AirportRepository;
|
||||||
use App\Repositories\PirepRepository;
|
use App\Repositories\PirepRepository;
|
||||||
|
use App\Repositories\SubfleetRepository;
|
||||||
|
|
||||||
use App\Facades\Utils;
|
use App\Facades\Utils;
|
||||||
|
|
||||||
|
|
||||||
@@ -27,34 +30,50 @@ class PirepController extends BaseController
|
|||||||
{
|
{
|
||||||
private $airportRepo,
|
private $airportRepo,
|
||||||
$airlineRepo,
|
$airlineRepo,
|
||||||
$pirepRepo,
|
|
||||||
$aircraftRepo,
|
$aircraftRepo,
|
||||||
$pirepSvc;
|
$pirepSvc,
|
||||||
|
$pirepRepo,
|
||||||
|
$subfleetRepo;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AirportRepository $airportRepo,
|
AirportRepository $airportRepo,
|
||||||
AirlineRepository $airlineRepo,
|
AirlineRepository $airlineRepo,
|
||||||
AircraftRepository $aircraftRepo,
|
AircraftRepository $aircraftRepo,
|
||||||
PirepRepository $pirepRepo,
|
PirepRepository $pirepRepo,
|
||||||
PIREPService $pirepSvc
|
PIREPService $pirepSvc,
|
||||||
|
SubfleetRepository $subfleetRepo
|
||||||
) {
|
) {
|
||||||
$this->airportRepo = $airportRepo;
|
$this->airportRepo = $airportRepo;
|
||||||
$this->airlineRepo = $airlineRepo;
|
$this->airlineRepo = $airlineRepo;
|
||||||
$this->aircraftRepo = $aircraftRepo;
|
$this->aircraftRepo = $aircraftRepo;
|
||||||
$this->pirepRepo = $pirepRepo;
|
$this->pirepRepo = $pirepRepo;
|
||||||
$this->pirepSvc = $pirepSvc;
|
$this->pirepSvc = $pirepSvc;
|
||||||
|
$this->subfleetRepo = $subfleetRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function aircraftList()
|
/**
|
||||||
|
* Dropdown with aircraft grouped by subfleet
|
||||||
|
*/
|
||||||
|
public function aircraftList($user=null)
|
||||||
{
|
{
|
||||||
$retval = [];
|
$aircraft = [];
|
||||||
$all_aircraft = $this->aircraftRepo->all();
|
|
||||||
|
|
||||||
foreach ($all_aircraft as $ac) {
|
if($user === null) {
|
||||||
$retval[$ac->id] = $ac->subfleet->name.' - '.$ac->name.' ('.$ac->registration.')';
|
$subfleets = $this->subfleetRepo->all();
|
||||||
|
} else {
|
||||||
|
$subfleets = $this->userSvc->getAllowableSubfleets($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $retval;
|
foreach ($subfleets as $subfleet) {
|
||||||
|
$tmp = [];
|
||||||
|
foreach ($subfleet->aircraft as $ac) {
|
||||||
|
$tmp[$ac->id] = $ac['name'] . ' - ' . $ac['registration'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$aircraft[$subfleet->name] = $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $aircraft;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,7 +121,11 @@ class PirepController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
return view('admin.pireps.create');
|
return view('admin.pireps.create', [
|
||||||
|
'aircraft' => $this->aircraftList(),
|
||||||
|
'airports' => $this->airportRepo->selectBoxList(),
|
||||||
|
'airlines' => $this->airlineRepo->selectBoxList(),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -160,9 +183,9 @@ class PirepController extends BaseController
|
|||||||
|
|
||||||
return view('admin.pireps.edit', [
|
return view('admin.pireps.edit', [
|
||||||
'pirep' => $pirep,
|
'pirep' => $pirep,
|
||||||
|
'aircraft' => $this->aircraftList(),
|
||||||
'airports' => $this->airportRepo->selectBoxList(),
|
'airports' => $this->airportRepo->selectBoxList(),
|
||||||
'airlines' => $this->airlineRepo->selectBoxList(),
|
'airlines' => $this->airlineRepo->selectBoxList(),
|
||||||
'aircraft' => $this->aircraftRepo->selectBoxList(),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,54 +3,89 @@
|
|||||||
namespace App\Http\Controllers\Frontend;
|
namespace App\Http\Controllers\Frontend;
|
||||||
|
|
||||||
use App\Facades\Utils;
|
use App\Facades\Utils;
|
||||||
use App\Models\Enums\PirepSource;
|
|
||||||
use App\Models\Enums\PirepState;
|
|
||||||
use App\Repositories\Criteria\WhereCriteria;
|
|
||||||
use App\Services\GeoService;
|
|
||||||
use App\Services\PIREPService;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
use App\Models\Enums\PirepSource;
|
||||||
|
use App\Models\Enums\PirepState;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
use App\Models\PirepField;
|
use App\Models\PirepField;
|
||||||
|
|
||||||
|
use App\Services\GeoService;
|
||||||
|
use App\Services\PIREPService;
|
||||||
|
use App\Services\UserService;
|
||||||
|
|
||||||
|
use App\Repositories\Criteria\WhereCriteria;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Repositories\AirlineRepository;
|
use App\Repositories\AirlineRepository;
|
||||||
use App\Repositories\AircraftRepository;
|
|
||||||
use App\Repositories\AirportRepository;
|
use App\Repositories\AirportRepository;
|
||||||
use App\Repositories\PirepRepository;
|
use App\Repositories\PirepRepository;
|
||||||
use App\Repositories\PirepFieldRepository;
|
use App\Repositories\PirepFieldRepository;
|
||||||
|
use App\Repositories\SubfleetRepository;
|
||||||
|
|
||||||
|
|
||||||
class PirepController extends Controller
|
class PirepController extends Controller
|
||||||
{
|
{
|
||||||
private $airlineRepo,
|
private $airlineRepo,
|
||||||
$aircraftRepo,
|
|
||||||
$pirepRepo,
|
$pirepRepo,
|
||||||
$airportRepo,
|
$airportRepo,
|
||||||
$pirepFieldRepo,
|
$pirepFieldRepo,
|
||||||
$geoSvc,
|
$geoSvc,
|
||||||
$pirepSvc;
|
$pirepSvc,
|
||||||
|
$subfleetRepo,
|
||||||
|
$userSvc;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AirlineRepository $airlineRepo,
|
AirlineRepository $airlineRepo,
|
||||||
PirepRepository $pirepRepo,
|
PirepRepository $pirepRepo,
|
||||||
AircraftRepository $aircraftRepo,
|
|
||||||
AirportRepository $airportRepo,
|
AirportRepository $airportRepo,
|
||||||
PirepFieldRepository $pirepFieldRepo,
|
PirepFieldRepository $pirepFieldRepo,
|
||||||
GeoService $geoSvc,
|
GeoService $geoSvc,
|
||||||
PIREPService $pirepSvc
|
SubfleetRepository $subfleetRepo,
|
||||||
|
PIREPService $pirepSvc,
|
||||||
|
UserService $userSvc
|
||||||
) {
|
) {
|
||||||
$this->airlineRepo = $airlineRepo;
|
$this->airlineRepo = $airlineRepo;
|
||||||
$this->aircraftRepo = $aircraftRepo;
|
|
||||||
$this->pirepRepo = $pirepRepo;
|
$this->pirepRepo = $pirepRepo;
|
||||||
$this->airportRepo = $airportRepo;
|
$this->airportRepo = $airportRepo;
|
||||||
|
$this->subfleetRepo = $subfleetRepo;
|
||||||
$this->pirepFieldRepo = $pirepFieldRepo;
|
$this->pirepFieldRepo = $pirepFieldRepo;
|
||||||
|
|
||||||
$this->geoSvc = $geoSvc;
|
$this->geoSvc = $geoSvc;
|
||||||
$this->pirepSvc = $pirepSvc;
|
$this->pirepSvc = $pirepSvc;
|
||||||
|
$this->userSvc = $userSvc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dropdown with aircraft grouped by subfleet
|
||||||
|
*/
|
||||||
|
public function aircraftList($user=null)
|
||||||
|
{
|
||||||
|
$aircraft = [];
|
||||||
|
|
||||||
|
if ($user === null) {
|
||||||
|
$subfleets = $this->subfleetRepo->all();
|
||||||
|
} else {
|
||||||
|
$subfleets = $this->userSvc->getAllowableSubfleets($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($subfleets as $subfleet) {
|
||||||
|
$tmp = [];
|
||||||
|
foreach ($subfleet->aircraft as $ac) {
|
||||||
|
$tmp[$ac->id] = $ac['name'] . ' - ' . $ac['registration'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$aircraft[$subfleet->name] = $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $aircraft;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
||||||
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
@@ -72,10 +107,12 @@ class PirepController extends Controller
|
|||||||
|
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
|
$user = Auth::user();
|
||||||
|
|
||||||
return $this->view('pireps.create', [
|
return $this->view('pireps.create', [
|
||||||
|
'aircraft' => $this->aircraftList($user),
|
||||||
'airports' => $this->airportRepo->selectBoxList(),
|
'airports' => $this->airportRepo->selectBoxList(),
|
||||||
'airlines' => $this->airlineRepo->selectBoxList(),
|
'airlines' => $this->airlineRepo->selectBoxList(),
|
||||||
'aircraft' => $this->aircraftRepo->selectBoxList(),
|
|
||||||
'pirepfields' => $this->pirepFieldRepo->all(),
|
'pirepfields' => $this->pirepFieldRepo->all(),
|
||||||
'fieldvalues' => [],
|
'fieldvalues' => [],
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user