Restrict the aircraft to only show the user's #138

This commit is contained in:
Nabeel Shahzad 2018-01-10 19:40:20 -06:00
parent 54a458d522
commit 186bbca428
4 changed files with 93 additions and 32 deletions

View File

@ -62,7 +62,7 @@ reload-db:
@php artisan database:create --reset
@php artisan migrate:refresh --seed
@php artisan phpvms:import app/Database/seeds/sample.yml
@php artisan phpvms:navdata
#php artisan phpvms:navdata
.PHONY: tests
tests: test

View File

@ -190,14 +190,11 @@ aircraft:
name: Boeing 777-200
registration: NC20
tail_number: 20
#aircraft_rank:
# - aircraft_id: 1
# rank_id: 1
# - aircraft_id: 1
# rank_id: 2
# acars_pay: 100
# manual_pay: 50
- id: 3
subfleet_id: 1
name: Boeing 747-412
registration: NS233
tail_number: 1233
fares:
- id: 1
@ -253,6 +250,10 @@ subfleet_flight:
- subfleet_id: 1
flight_id: flightid_1
subfleet_rank:
- rank_id: 1
subfleet_id: 1
flights:
- id: flightid_1
airline_id: 1

View File

@ -16,10 +16,13 @@ use App\Models\Enums\PirepState;
use App\Http\Requests\CreatePirepRequest;
use App\Http\Requests\UpdatePirepRequest;
use App\Repositories\AircraftRepository;
use App\Repositories\AirlineRepository;
use App\Repositories\AirportRepository;
use App\Repositories\PirepRepository;
use App\Repositories\SubfleetRepository;
use App\Facades\Utils;
@ -27,34 +30,50 @@ class PirepController extends BaseController
{
private $airportRepo,
$airlineRepo,
$pirepRepo,
$aircraftRepo,
$pirepSvc;
$pirepSvc,
$pirepRepo,
$subfleetRepo;
public function __construct(
AirportRepository $airportRepo,
AirlineRepository $airlineRepo,
AircraftRepository $aircraftRepo,
PirepRepository $pirepRepo,
PIREPService $pirepSvc
PIREPService $pirepSvc,
SubfleetRepository $subfleetRepo
) {
$this->airportRepo = $airportRepo;
$this->airlineRepo = $airlineRepo;
$this->aircraftRepo = $aircraftRepo;
$this->pirepRepo = $pirepRepo;
$this->pirepSvc = $pirepSvc;
$this->subfleetRepo = $subfleetRepo;
}
public function aircraftList()
/**
* Dropdown with aircraft grouped by subfleet
*/
public function aircraftList($user=null)
{
$retval = [];
$all_aircraft = $this->aircraftRepo->all();
$aircraft = [];
foreach ($all_aircraft as $ac) {
$retval[$ac->id] = $ac->subfleet->name.' - '.$ac->name.' ('.$ac->registration.')';
if($user === null) {
$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()
{
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', [
'pirep' => $pirep,
'aircraft' => $this->aircraftList(),
'airports' => $this->airportRepo->selectBoxList(),
'airlines' => $this->airlineRepo->selectBoxList(),
'aircraft' => $this->aircraftRepo->selectBoxList(),
]);
}

View File

@ -3,54 +3,89 @@
namespace App\Http\Controllers\Frontend;
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\Http\Request;
use App\Models\Enums\PirepSource;
use App\Models\Enums\PirepState;
use App\Models\Pirep;
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\Repositories\AirlineRepository;
use App\Repositories\AircraftRepository;
use App\Repositories\AirportRepository;
use App\Repositories\PirepRepository;
use App\Repositories\PirepFieldRepository;
use App\Repositories\SubfleetRepository;
class PirepController extends Controller
{
private $airlineRepo,
$aircraftRepo,
$pirepRepo,
$airportRepo,
$pirepFieldRepo,
$geoSvc,
$pirepSvc;
$pirepSvc,
$subfleetRepo,
$userSvc;
public function __construct(
AirlineRepository $airlineRepo,
PirepRepository $pirepRepo,
AircraftRepository $aircraftRepo,
AirportRepository $airportRepo,
PirepFieldRepository $pirepFieldRepo,
GeoService $geoSvc,
PIREPService $pirepSvc
SubfleetRepository $subfleetRepo,
PIREPService $pirepSvc,
UserService $userSvc
) {
$this->airlineRepo = $airlineRepo;
$this->aircraftRepo = $aircraftRepo;
$this->pirepRepo = $pirepRepo;
$this->airportRepo = $airportRepo;
$this->subfleetRepo = $subfleetRepo;
$this->pirepFieldRepo = $pirepFieldRepo;
$this->geoSvc = $geoSvc;
$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)
{
$user = Auth::user();
@ -72,10 +107,12 @@ class PirepController extends Controller
public function create()
{
$user = Auth::user();
return $this->view('pireps.create', [
'aircraft' => $this->aircraftList($user),
'airports' => $this->airportRepo->selectBoxList(),
'airlines' => $this->airlineRepo->selectBoxList(),
'aircraft' => $this->aircraftRepo->selectBoxList(),
'pirepfields' => $this->pirepFieldRepo->all(),
'fieldvalues' => [],
]);