SimBrief Planning System Update (#991)

* SimBrief Planning System Update

Replaces outdated old pr.

Same improvements apply to both controller and simbrief_form.blade.

* Style Fix for SimBrief.Controller

* strict equals fix and some comments

changed equals to strict equals and put in some comments about the loadarray and manualrmk generation.

* Formatting/separate out secstohhmm

* Formatting

* Removed duplicates

We have the $wakecat, $equipment and $transponder in the controller, removed them from the blade.

Fixed a harmless typo in the IVAO Prefile DEPTIME line

Co-authored-by: Nabeel S <nabeelio@users.noreply.github.com>
Co-authored-by: Nabeel Shahzad <nabeel@nabeel.sh>
This commit is contained in:
B.Fatih KOZ
2021-01-17 23:59:32 +03:00
committed by GitHub
parent 3a99fe9e0e
commit 617cea5df7
5 changed files with 565 additions and 320 deletions

View File

@@ -3,22 +3,34 @@
namespace App\Http\Controllers\Frontend;
use App\Exceptions\AssetNotFound;
use App\Models\Aircraft;
use App\Models\Enums\FlightType;
use App\Models\SimBrief;
use App\Repositories\FlightRepository;
use App\Services\FareService;
use App\Services\SimBriefService;
use App\Services\UserService;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class SimBriefController
{
private $fareSvc;
private $flightRepo;
private $simBriefSvc;
private $userSvc;
public function __construct(FlightRepository $flightRepo, SimBriefService $simBriefSvc)
{
public function __construct(
FareService $fareSvc,
FlightRepository $flightRepo,
SimBriefService $simBriefSvc,
UserService $userSvc
) {
$this->fareSvc = $fareSvc;
$this->flightRepo = $flightRepo;
$this->simBriefSvc = $simBriefSvc;
$this->userSvc = $userSvc;
}
/**
@@ -32,20 +44,29 @@ class SimBriefController
*/
public function generate(Request $request)
{
/** @var \App\Models\User $user */
$user = Auth::user();
$flight_id = $request->input('flight_id');
$flight = $this->flightRepo->find($flight_id);
$aircraft_id = $request->input('aircraft_id');
$flight = $this->flightRepo->with(['subfleets'])->find($flight_id);
$flight = $this->fareSvc->getReconciledFaresForFlight($flight);
if (!$flight) {
flash()->error('Unknown flight');
return redirect(route('frontend.flights.index'));
}
if (!$aircraft_id) {
flash()->error('Aircraft not selected ! Please select an Aircraft to Proceed ...');
}
$apiKey = setting('simbrief.api_key');
if (empty($apiKey)) {
flash()->error('Invalid SimBrief API key!');
return redirect(route('frontend.flights.index'));
}
$user = Auth::user();
$simbrief = SimBrief::select('id')->where([
'flight_id' => $flight_id,
'user_id' => $user->id,
@@ -55,8 +76,27 @@ class SimBriefController
return redirect(route('frontend.simbrief.briefing', [$simbrief->id]));
}
$aircraft = Aircraft::select('registration', 'name', 'icao', 'iata', 'subfleet_id')
->where('id', $aircraft_id)
->get();
if ($flight->subfleets->count() > 0) {
$subfleets = $flight->subfleets;
} else {
$subfleets = $this->userSvc->getAllowableSubfleets($user);
}
if ($flight->flight_type === FlightType::CHARTER_PAX_ONLY) {
$pax_weight = 197;
} else {
$pax_weight = 208;
}
return view('flights.simbrief_form', [
'flight' => $flight,
'flight' => $flight,
'aircraft' => $aircraft,
'subfleets' => $subfleets,
'pax_weight' => $pax_weight, // TODO: Replace with a setting
]);
}
@@ -75,8 +115,18 @@ class SimBriefController
return redirect(route('frontend.flights.index'));
}
$str = $simbrief->xml->aircraft->equip;
$wc = stripos($str, '-');
$tr = stripos($str, '/');
$wakecat = substr($str, 0, $wc);
$equipment = substr($str, $wc + 1, $tr - 2);
$transponder = substr($str, $tr + 1);
return view('flights.simbrief_briefing', [
'simbrief' => $simbrief,
'simbrief' => $simbrief,
'wakecat' => $wakecat,
'equipment' => $equipment,
'transponder' => $transponder,
]);
}