2017-06-29 08:54:05 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
use App\Facades\Utils;
|
2017-06-29 08:54:05 +08:00
|
|
|
use App\Http\Requests\CreatePirepRequest;
|
|
|
|
use App\Http\Requests\UpdatePirepRequest;
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Controller;
|
2018-02-25 05:38:25 +08:00
|
|
|
use App\Models\Enums\PirepSource;
|
2018-02-21 12:33:09 +08:00
|
|
|
use App\Models\Enums\PirepState;
|
2018-02-25 05:38:25 +08:00
|
|
|
use App\Models\Pirep;
|
2018-02-21 12:33:09 +08:00
|
|
|
use App\Models\PirepComment;
|
2017-07-14 11:09:38 +08:00
|
|
|
use App\Repositories\AircraftRepository;
|
2017-12-04 05:29:34 +08:00
|
|
|
use App\Repositories\AirlineRepository;
|
|
|
|
use App\Repositories\AirportRepository;
|
2018-03-03 06:09:48 +08:00
|
|
|
use App\Repositories\JournalRepository;
|
2018-02-25 05:38:25 +08:00
|
|
|
use App\Repositories\PirepFieldRepository;
|
2017-06-29 08:54:05 +08:00
|
|
|
use App\Repositories\PirepRepository;
|
2018-01-11 09:40:20 +08:00
|
|
|
use App\Repositories\SubfleetRepository;
|
2018-03-02 06:20:13 +08:00
|
|
|
use App\Services\FareService;
|
2018-03-07 07:36:06 +08:00
|
|
|
use App\Services\PirepService;
|
2018-02-21 12:33:09 +08:00
|
|
|
use App\Services\UserService;
|
|
|
|
use App\Support\Units\Time;
|
|
|
|
use Flash;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Log;
|
|
|
|
use Prettus\Repository\Criteria\RequestCriteria;
|
|
|
|
use Response;
|
2017-12-04 05:29:34 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class PirepController
|
|
|
|
*/
|
|
|
|
class PirepController extends Controller
|
2017-06-29 08:54:05 +08:00
|
|
|
{
|
2018-08-27 00:40:04 +08:00
|
|
|
private $airportRepo;
|
|
|
|
private $airlineRepo;
|
|
|
|
private $aircraftRepo;
|
|
|
|
private $fareSvc;
|
|
|
|
private $journalRepo;
|
|
|
|
private $pirepSvc;
|
|
|
|
private $pirepRepo;
|
|
|
|
private $pirepFieldRepo;
|
|
|
|
private $subfleetRepo;
|
|
|
|
private $userSvc;
|
2017-06-29 08:54:05 +08:00
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
/**
|
|
|
|
* PirepController constructor.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param AirportRepository $airportRepo
|
|
|
|
* @param AirlineRepository $airlineRepo
|
|
|
|
* @param AircraftRepository $aircraftRepo
|
|
|
|
* @param FareService $fareSvc
|
|
|
|
* @param JournalRepository $journalRepo
|
|
|
|
* @param PirepRepository $pirepRepo
|
2018-03-03 06:09:48 +08:00
|
|
|
* @param PirepFieldRepository $pirepFieldRepo
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param PirepService $pirepSvc
|
|
|
|
* @param SubfleetRepository $subfleetRepo
|
|
|
|
* @param UserService $userSvc
|
2018-02-21 12:33:09 +08:00
|
|
|
*/
|
2017-12-03 14:48:33 +08:00
|
|
|
public function __construct(
|
2017-12-04 05:29:34 +08:00
|
|
|
AirportRepository $airportRepo,
|
|
|
|
AirlineRepository $airlineRepo,
|
2017-12-03 14:48:33 +08:00
|
|
|
AircraftRepository $aircraftRepo,
|
2018-03-02 06:20:13 +08:00
|
|
|
FareService $fareSvc,
|
2018-03-03 06:09:48 +08:00
|
|
|
JournalRepository $journalRepo,
|
2017-12-03 14:48:33 +08:00
|
|
|
PirepRepository $pirepRepo,
|
2018-02-25 05:38:25 +08:00
|
|
|
PirepFieldRepository $pirepFieldRepo,
|
2018-03-07 07:36:06 +08:00
|
|
|
PirepService $pirepSvc,
|
2018-01-20 01:46:30 +08:00
|
|
|
SubfleetRepository $subfleetRepo,
|
|
|
|
UserService $userSvc
|
2017-12-03 14:48:33 +08:00
|
|
|
) {
|
2017-12-04 05:29:34 +08:00
|
|
|
$this->airportRepo = $airportRepo;
|
|
|
|
$this->airlineRepo = $airlineRepo;
|
2017-07-14 11:09:38 +08:00
|
|
|
$this->aircraftRepo = $aircraftRepo;
|
2018-03-02 06:20:13 +08:00
|
|
|
$this->fareSvc = $fareSvc;
|
2018-03-03 06:09:48 +08:00
|
|
|
$this->journalRepo = $journalRepo;
|
2017-07-14 11:09:38 +08:00
|
|
|
$this->pirepRepo = $pirepRepo;
|
2018-02-25 05:38:25 +08:00
|
|
|
$this->pirepFieldRepo = $pirepFieldRepo;
|
2017-12-03 14:48:33 +08:00
|
|
|
$this->pirepSvc = $pirepSvc;
|
2018-01-11 09:40:20 +08:00
|
|
|
$this->subfleetRepo = $subfleetRepo;
|
2018-01-20 01:46:30 +08:00
|
|
|
$this->userSvc = $userSvc;
|
2017-07-14 11:09:38 +08:00
|
|
|
}
|
|
|
|
|
2018-01-11 09:40:20 +08:00
|
|
|
/**
|
|
|
|
* Dropdown with aircraft grouped by subfleet
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-01-20 01:46:30 +08:00
|
|
|
* @param null $user
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-01-20 01:46:30 +08:00
|
|
|
* @return array
|
2018-01-11 09:40:20 +08:00
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
public function aircraftList($user = null)
|
2017-07-14 11:09:38 +08:00
|
|
|
{
|
2018-01-11 09:40:20 +08:00
|
|
|
$aircraft = [];
|
2017-07-14 11:09:38 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
if ($user === null) {
|
2018-01-11 09:40:20 +08:00
|
|
|
$subfleets = $this->subfleetRepo->all();
|
|
|
|
} else {
|
|
|
|
$subfleets = $this->userSvc->getAllowableSubfleets($user);
|
2017-07-14 11:09:38 +08:00
|
|
|
}
|
|
|
|
|
2018-01-11 09:40:20 +08:00
|
|
|
foreach ($subfleets as $subfleet) {
|
|
|
|
$tmp = [];
|
|
|
|
foreach ($subfleet->aircraft as $ac) {
|
2018-03-20 09:50:40 +08:00
|
|
|
$tmp[$ac->id] = $ac['name'].' - '.$ac['registration'];
|
2018-01-11 09:40:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$aircraft[$subfleet->name] = $tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $aircraft;
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
|
2018-02-25 05:38:25 +08:00
|
|
|
/**
|
|
|
|
* Save any custom fields found
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param Pirep $pirep
|
2018-02-25 05:38:25 +08:00
|
|
|
* @param Request $request
|
|
|
|
*/
|
2018-03-21 02:06:06 +08:00
|
|
|
protected function saveCustomFields(Pirep $pirep, Request $request): void
|
2018-02-25 05:38:25 +08:00
|
|
|
{
|
|
|
|
$custom_fields = [];
|
|
|
|
$pirep_fields = $this->pirepFieldRepo->all();
|
|
|
|
foreach ($pirep_fields as $field) {
|
|
|
|
if (!$request->filled($field->slug)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$custom_fields[] = [
|
2018-03-20 09:50:40 +08:00
|
|
|
'name' => $field->name,
|
|
|
|
'value' => $request->input($field->slug),
|
2018-08-27 00:40:04 +08:00
|
|
|
'source' => PirepSource::MANUAL,
|
2018-02-25 05:38:25 +08:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
Log::info('PIREP Custom Fields', $custom_fields);
|
|
|
|
$this->pirepSvc->updateCustomFields($pirep->id, $custom_fields);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the fares that have been specified/saved
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param Pirep $pirep
|
2018-02-25 05:38:25 +08:00
|
|
|
* @param Request $request
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-02-25 05:38:25 +08:00
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
protected function saveFares(Pirep $pirep, Request $request)
|
|
|
|
{
|
|
|
|
$fares = [];
|
|
|
|
foreach ($pirep->aircraft->subfleet->fares as $fare) {
|
2018-03-20 09:50:40 +08:00
|
|
|
$field_name = 'fare_'.$fare->id;
|
2018-02-25 05:38:25 +08:00
|
|
|
if (!$request->filled($field_name)) {
|
|
|
|
$count = 0;
|
|
|
|
} else {
|
|
|
|
$count = $request->input($field_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
$fares[] = [
|
|
|
|
'fare_id' => $fare->id,
|
2018-03-20 09:50:40 +08:00
|
|
|
'count' => $count,
|
2018-02-25 05:38:25 +08:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-03-02 06:20:13 +08:00
|
|
|
$this->fareSvc->saveForPirep($pirep, $fares);
|
2018-02-25 05:38:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the fares form for a given aircraft
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-02-25 05:38:25 +08:00
|
|
|
* @param Request $request
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-02-25 05:38:25 +08:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function fares(Request $request)
|
|
|
|
{
|
|
|
|
$aircraft_id = $request->input('aircraft_id');
|
|
|
|
Log::info($aircraft_id);
|
|
|
|
|
|
|
|
$aircraft = $this->aircraftRepo->find($aircraft_id);
|
|
|
|
Log::info('aircraft', $aircraft->toArray());
|
|
|
|
|
|
|
|
return view('admin.pireps.fares', [
|
2018-03-20 09:50:40 +08:00
|
|
|
'aircraft' => $aircraft,
|
2018-02-25 05:38:25 +08:00
|
|
|
'read_only' => false,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-06-29 08:54:05 +08:00
|
|
|
/**
|
|
|
|
* @param Request $request
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2017-12-02 00:53:33 +08:00
|
|
|
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
2017-06-29 08:54:05 +08:00
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
2017-08-25 02:37:54 +08:00
|
|
|
$criterea = new RequestCriteria($request);
|
|
|
|
$this->pirepRepo->pushCriteria($criterea);
|
|
|
|
|
2017-12-03 14:48:33 +08:00
|
|
|
$pireps = $this->pirepRepo
|
2018-05-12 02:43:33 +08:00
|
|
|
->whereNotInOrder('state', [
|
2018-05-10 06:58:51 +08:00
|
|
|
PirepState::CANCELLED,
|
|
|
|
PirepState::DRAFT,
|
2018-08-27 00:40:04 +08:00
|
|
|
PirepState::IN_PROGRESS,
|
2018-05-10 06:58:51 +08:00
|
|
|
], 'created_at', 'desc')
|
2018-03-20 09:50:40 +08:00
|
|
|
->paginate();
|
2017-06-29 08:54:05 +08:00
|
|
|
|
|
|
|
return view('admin.pireps.index', [
|
2018-08-27 00:40:04 +08:00
|
|
|
'pireps' => $pireps,
|
2017-06-29 08:54:05 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-12-04 00:55:01 +08:00
|
|
|
/**
|
|
|
|
* @param Request $request
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2017-12-04 00:55:01 +08:00
|
|
|
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
2017-12-04 00:55:01 +08:00
|
|
|
*/
|
|
|
|
public function pending(Request $request)
|
|
|
|
{
|
|
|
|
$criterea = new RequestCriteria($request);
|
|
|
|
$this->pirepRepo->pushCriteria($criterea);
|
|
|
|
|
|
|
|
$pireps = $this->pirepRepo
|
2017-12-20 10:19:36 +08:00
|
|
|
->findWhere(['status' => PirepState::PENDING])
|
2017-12-04 00:55:01 +08:00
|
|
|
->orderBy('created_at', 'desc')
|
|
|
|
->paginate();
|
|
|
|
|
|
|
|
return view('admin.pireps.index', [
|
2018-08-27 00:40:04 +08:00
|
|
|
'pireps' => $pireps,
|
2017-12-04 00:55:01 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-06-29 08:54:05 +08:00
|
|
|
/**
|
|
|
|
* Show the form for creating a new Pirep.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2017-06-29 08:54:05 +08:00
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2018-01-11 09:40:20 +08:00
|
|
|
return view('admin.pireps.create', [
|
|
|
|
'aircraft' => $this->aircraftList(),
|
|
|
|
'airports' => $this->airportRepo->selectBoxList(),
|
|
|
|
'airlines' => $this->airlineRepo->selectBoxList(),
|
|
|
|
]);
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param CreatePirepRequest $request
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2017-12-02 00:53:33 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2018-02-25 05:38:25 +08:00
|
|
|
* @throws \Exception
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
2017-06-29 08:54:05 +08:00
|
|
|
*/
|
|
|
|
public function store(CreatePirepRequest $request)
|
|
|
|
{
|
2018-02-07 02:58:48 +08:00
|
|
|
$attrs = $request->all();
|
|
|
|
$pirep = $this->pirepRepo->create($attrs);
|
2017-06-29 08:54:05 +08:00
|
|
|
|
2018-02-07 02:58:48 +08:00
|
|
|
$hours = (int) $attrs['hours'];
|
|
|
|
$minutes = (int) $attrs['minutes'];
|
|
|
|
$pirep->flight_time = Utils::hoursToMinutes($hours) + $minutes;
|
2017-12-14 00:56:26 +08:00
|
|
|
|
2018-02-25 05:38:25 +08:00
|
|
|
$this->saveCustomFields($pirep, $request);
|
|
|
|
$this->saveFares($pirep, $request);
|
|
|
|
|
2017-06-29 08:54:05 +08:00
|
|
|
Flash::success('Pirep saved successfully.');
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2017-06-29 08:54:05 +08:00
|
|
|
return redirect(route('admin.pireps.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified Pirep.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
*
|
2017-06-29 08:54:05 +08:00
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
2017-08-25 02:37:54 +08:00
|
|
|
$pirep = $this->pirepRepo->find($id);
|
2017-06-29 08:54:05 +08:00
|
|
|
|
|
|
|
if (empty($pirep)) {
|
|
|
|
Flash::error('Pirep not found');
|
|
|
|
return redirect(route('admin.pireps.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('admin.pireps.show', [
|
|
|
|
'pirep' => $pirep,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified Pirep.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
*
|
2018-03-03 06:09:48 +08:00
|
|
|
* @throws \InvalidArgumentException
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @return Response
|
2017-06-29 08:54:05 +08:00
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
2017-07-14 11:09:38 +08:00
|
|
|
$pirep = $this->pirepRepo->findWithoutFail($id);
|
2017-06-29 08:54:05 +08:00
|
|
|
if (empty($pirep)) {
|
|
|
|
Flash::error('Pirep not found');
|
|
|
|
return redirect(route('admin.pireps.index'));
|
|
|
|
}
|
|
|
|
|
2018-02-20 03:33:26 +08:00
|
|
|
$time = new Time($pirep->flight_time);
|
|
|
|
$pirep->hours = $time->hours;
|
|
|
|
$pirep->minutes = $time->minutes;
|
2017-12-04 05:29:34 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// set the custom fields
|
2018-02-25 05:38:25 +08:00
|
|
|
foreach ($pirep->fields as $field) {
|
2018-07-13 10:20:10 +08:00
|
|
|
$field_name = 'field_'.$field->slug;
|
|
|
|
$pirep->{$field_name} = $field->value;
|
2018-02-25 05:38:25 +08:00
|
|
|
}
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// set the fares
|
2018-02-25 05:38:25 +08:00
|
|
|
foreach ($pirep->fares as $fare) {
|
2018-03-20 09:50:40 +08:00
|
|
|
$field_name = 'fare_'.$fare->fare_id;
|
2018-02-25 05:38:25 +08:00
|
|
|
$pirep->{$field_name} = $fare->count;
|
2018-02-07 02:58:48 +08:00
|
|
|
}
|
|
|
|
|
2018-03-03 06:09:48 +08:00
|
|
|
$journal = $this->journalRepo->getAllForObject($pirep, $pirep->airline->journal);
|
|
|
|
|
2017-06-29 08:54:05 +08:00
|
|
|
return view('admin.pireps.edit', [
|
2018-03-20 09:50:40 +08:00
|
|
|
'pirep' => $pirep,
|
|
|
|
'aircraft' => $pirep->aircraft,
|
2018-02-25 05:38:25 +08:00
|
|
|
'aircraft_list' => $this->aircraftList(),
|
|
|
|
'airports_list' => $this->airportRepo->selectBoxList(),
|
|
|
|
'airlines_list' => $this->airlineRepo->selectBoxList(),
|
2018-03-20 09:50:40 +08:00
|
|
|
'journal' => $journal,
|
2017-06-29 08:54:05 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param $id
|
2017-06-29 08:54:05 +08:00
|
|
|
* @param UpdatePirepRequest $request
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2017-12-02 00:53:33 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2018-02-20 03:33:26 +08:00
|
|
|
* @throws \Exception
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
2017-06-29 08:54:05 +08:00
|
|
|
*/
|
|
|
|
public function update($id, UpdatePirepRequest $request)
|
|
|
|
{
|
2017-07-14 11:09:38 +08:00
|
|
|
$pirep = $this->pirepRepo->findWithoutFail($id);
|
2017-06-29 08:54:05 +08:00
|
|
|
|
|
|
|
if (empty($pirep)) {
|
|
|
|
Flash::error('Pirep not found');
|
|
|
|
return redirect(route('admin.pireps.index'));
|
|
|
|
}
|
|
|
|
|
2018-01-02 03:48:02 +08:00
|
|
|
$orig_route = $pirep->route;
|
2018-02-07 02:58:48 +08:00
|
|
|
$orig_flight_time = $pirep->flight_time;
|
|
|
|
|
|
|
|
$attrs = $request->all();
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
// Fix the time
|
2018-02-20 03:33:26 +08:00
|
|
|
$attrs['flight_time'] = Time::init(
|
|
|
|
$attrs['minutes'],
|
|
|
|
$attrs['hours'])->getMinutes();
|
2018-02-07 02:58:48 +08:00
|
|
|
|
2018-01-02 03:48:02 +08:00
|
|
|
$pirep = $this->pirepRepo->update($attrs, $id);
|
|
|
|
|
2018-01-02 05:04:32 +08:00
|
|
|
// A route change in the PIREP, so update the saved points in the ACARS table
|
2018-03-20 09:50:40 +08:00
|
|
|
if ($pirep->route !== $orig_route) {
|
2018-01-02 03:48:02 +08:00
|
|
|
$this->pirepSvc->saveRoute($pirep);
|
|
|
|
}
|
2017-06-29 08:54:05 +08:00
|
|
|
|
2018-02-25 05:38:25 +08:00
|
|
|
$this->saveCustomFields($pirep, $request);
|
|
|
|
$this->saveFares($pirep, $request);
|
|
|
|
|
2017-06-29 08:54:05 +08:00
|
|
|
Flash::success('Pirep updated successfully.');
|
|
|
|
return redirect(route('admin.pireps.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified Pirep from storage.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
*
|
2017-06-29 08:54:05 +08:00
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
2017-07-14 11:09:38 +08:00
|
|
|
$pirep = $this->pirepRepo->findWithoutFail($id);
|
2017-06-29 08:54:05 +08:00
|
|
|
|
|
|
|
if (empty($pirep)) {
|
|
|
|
Flash::error('Pirep not found');
|
|
|
|
return redirect(route('admin.pireps.index'));
|
|
|
|
}
|
|
|
|
|
2017-07-14 11:09:38 +08:00
|
|
|
$this->pirepRepo->delete($id);
|
2017-06-29 08:54:05 +08:00
|
|
|
|
|
|
|
Flash::success('Pirep deleted successfully.');
|
|
|
|
return redirect(route('admin.pireps.index'));
|
|
|
|
}
|
2017-12-03 14:48:33 +08:00
|
|
|
|
|
|
|
/**
|
2018-01-04 10:39:24 +08:00
|
|
|
* Change or update the PIREP status. Just return the new actionbar
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2017-12-03 14:48:33 +08:00
|
|
|
* @param Request $request
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2017-12-03 14:48:33 +08:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function status(Request $request)
|
|
|
|
{
|
2017-12-20 10:19:36 +08:00
|
|
|
Log::info('PIREP state update call', [$request->toArray()]);
|
2017-12-03 14:48:33 +08:00
|
|
|
|
|
|
|
$pirep = $this->pirepRepo->findWithoutFail($request->id);
|
2018-03-20 09:50:40 +08:00
|
|
|
if ($request->isMethod('post')) {
|
2018-02-07 02:58:48 +08:00
|
|
|
$new_status = (int) $request->post('new_status');
|
2017-12-20 10:19:36 +08:00
|
|
|
$pirep = $this->pirepSvc->changeState($pirep, $new_status);
|
2017-12-03 14:48:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$pirep->refresh();
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-02-07 02:58:48 +08:00
|
|
|
return view('admin.pireps.actions', ['pirep' => $pirep, 'on_edit_page' => false]);
|
2017-12-03 14:48:33 +08:00
|
|
|
}
|
2018-01-04 05:27:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a comment to the Pirep
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param $id
|
2018-01-04 05:27:56 +08:00
|
|
|
* @param Request $request
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-02-21 12:33:09 +08:00
|
|
|
* @throws \Exception
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @return mixed
|
2018-01-04 05:27:56 +08:00
|
|
|
*/
|
|
|
|
public function comments($id, Request $request)
|
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
$pirep = $this->pirepRepo->findWithoutFail($request->id);
|
|
|
|
if ($request->isMethod('post')) {
|
|
|
|
$comment = new PirepComment([
|
2018-03-20 09:50:40 +08:00
|
|
|
'user_id' => $user->id,
|
2018-01-04 05:27:56 +08:00
|
|
|
'pirep_id' => $pirep->id,
|
2018-03-20 09:50:40 +08:00
|
|
|
'comment' => $request->get('comment'),
|
2018-01-04 05:27:56 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$comment->save();
|
|
|
|
$pirep->refresh();
|
|
|
|
}
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
if ($request->isMethod('delete')) {
|
2018-01-04 05:27:56 +08:00
|
|
|
$comment = PirepComment::find($request->get('comment_id'));
|
|
|
|
$comment->delete();
|
|
|
|
$pirep->refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('admin.pireps.comments', [
|
|
|
|
'pirep' => $pirep,
|
|
|
|
]);
|
|
|
|
}
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|