Block aircraft with Simbrief (#1213)
* Block Aircraft with SimBrief Changes aim to have the ability to block an aircraft's usage if it is used to generate a SimBrief OFP. Unused/Expired briefings will be deleted by cron like before but will now be checked by HourlyCron, so admins can define more precise restrictions for them (and the blockage period of their aircraft) Owner of the SimBrief OFP will be able to start a flight with acars using that particular aircraft, but pilots will get an Aircraft Not Available error (similar to Aircraft State check) To prevent SimBrief OFP packs being marked as expired/unused, during pirep prefile, pirep_id will be saved to SimBrief model along with flight_id. And when a flight is finished (pirep file), flight_id will be removed from SimBrief model as before. Only pirep_id will remain and aircraft will be available for another OFP generation. * Update PirepController In case a pirep is being saved/submitted with manual entry (but the va is using simbrief effectively) same logic should be applied during save/submit button selection. Save will act like a pirep prefile , Submit will be pirep file. * Manual Pirep Checks Manual pireps, prefiled from a generated simbrief should be checked too. Also pirep.show blade's submit button should provide the same simbrief checks. * Update PirepService.php * Change settings and move sb cron to hourly * StyleFix (SimBriefService) * Another StyleFix (SimBriefService) * Update SimBriefController Removed null check of pirep_id for aircraft list generation to prevent live flights' aircraft being listed for another ofp generation. ( Active acars flights will have both flight_id and pirep_id at simbrief table) * Update PirepService.php Co-authored-by: Nabeel S <nabeelio@users.noreply.github.com>
This commit is contained in:
@@ -148,6 +148,18 @@ class PirepService extends Service
|
||||
throw new AircraftNotAvailable($pirep->aircraft);
|
||||
}
|
||||
|
||||
// See if this aircraft is being used by another user's active simbrief ofp
|
||||
if (setting('simbrief.block_aircraft', false)) {
|
||||
$sb_aircraft = SimBrief::select('aircraft_id')
|
||||
->where('aircraft_id', $pirep->aircraft_id)
|
||||
->where('user_id', '!=', $pirep->user_id)
|
||||
->whereNotNull('flight_id')
|
||||
->count();
|
||||
if ($sb_aircraft > 0) {
|
||||
throw new AircraftNotAvailable($pirep->aircraft);
|
||||
}
|
||||
}
|
||||
|
||||
// See if this aircraft is at the departure airport
|
||||
/* @noinspection NotOptimalIfConditionsInspection */
|
||||
if (setting('pireps.only_aircraft_at_dpt_airport') && $aircraft->airport_id !== $pirep->dpt_airport_id) {
|
||||
@@ -164,9 +176,20 @@ class PirepService extends Service
|
||||
}
|
||||
}
|
||||
|
||||
event(new PirepPrefiled($pirep));
|
||||
|
||||
$pirep->save();
|
||||
$pirep->refresh();
|
||||
|
||||
// Check if there is a simbrief_id, update it to have the pirep_id
|
||||
// Keep the flight_id until the end of flight (pirep file)
|
||||
if (array_key_exists('simbrief_id', $attrs)) {
|
||||
/** @var SimBrief $simbrief */
|
||||
$simbrief = SimBrief::find($attrs['simbrief_id']);
|
||||
if ($simbrief) {
|
||||
$this->simBriefSvc->attachSimbriefToPirep($pirep, $simbrief, true);
|
||||
}
|
||||
}
|
||||
|
||||
event(new PirepPrefiled($pirep));
|
||||
|
||||
return $pirep;
|
||||
}
|
||||
@@ -427,6 +450,19 @@ class PirepService extends Service
|
||||
}
|
||||
}
|
||||
|
||||
// Check if there is a simbrief_id, change it to be set to the PIREP
|
||||
// at the end of the flight when it's been submitted finally.
|
||||
// Prefile, Save (as draft) and File already have this but the Submit button
|
||||
// visible at pireps.show blade uses this function so Simbrief also needs to
|
||||
// checked here too (to remove the flight_id and release the aircraft)
|
||||
if (!empty($pirep->simbrief)) {
|
||||
/** @var SimBrief $simbrief */
|
||||
$simbrief = SimBrief::find($pirep->simbrief->id);
|
||||
if ($simbrief) {
|
||||
$this->simBriefSvc->attachSimbriefToPirep($pirep, $simbrief);
|
||||
}
|
||||
}
|
||||
|
||||
Log::info('New PIREP filed', [$pirep]);
|
||||
event(new PirepFiled($pirep));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user