Simbrief Edit & Download Latest OFP (#1228)

* SimBrief OFP Edit

Changes aim to have ability of editing generated SimBrief Flight Plans and re-downloading.

* Move url to config

* Blade update and $uri change

* Update simbrief_form.blade.php

Used `$flight->id` along with `$user->ident` to have a more unique static id value. No details given for that fields uniqueness requirements, this will be ok I think though. 
Also we are passing user's simbrief userid with api to find the flight plan, both combined, no chance to get another users plan and/or any other plan of same user.

* Update SimBriefController.php

Move `static_id` to controller

* Update simbrief_form.blade.php

Read `static_id` from controller

* StyleFix

* Update phpvms.php

* Update SimBriefService.php

Co-authored-by: Nabeel S <nabeelio@users.noreply.github.com>
This commit is contained in:
B.Fatih KOZ
2021-06-09 18:38:14 +03:00
committed by GitHub
parent 7481dab012
commit 90344fb6e6
6 changed files with 87 additions and 8 deletions

View File

@@ -70,6 +70,9 @@ class SimBriefController
return redirect(route('frontend.flights.index'));
}
// Generate SimBrief Static ID
$static_id = $user->ident.'_'.$flight->id;
// No aircraft selected, show selection form
if (!$aircraft_id) {
// If no subfleets defined for flight get them from user
@@ -237,6 +240,7 @@ class SimBriefController
'tpayload' => $tpayload,
'tcargoload' => $tcargoload,
'loaddist' => implode(' ', $loaddist),
'static_id' => $static_id,
]);
}
@@ -367,6 +371,31 @@ class SimBriefController
]);
}
/**
* Get the latest generated OFP. Pass in two additional items, the Simbrief userid and static_id
* This will get the latest edited/regenerated of from Simbrief and update our records
* We do not need to send the fares again, so used an empty array
*/
public function update_ofp(Request $request)
{
/** @var User $user */
$user = Auth::user();
$ofp_id = $request->input('ofp_id');
$flight_id = $request->input('flight_id');
$aircraft_id = $request->input('aircraft_id');
$sb_userid = $request->input('sb_userid');
$sb_static_id = $request->input('sb_static_id');
$fares = [];
$simbrief = $this->simBriefSvc->downloadOfp($user->id, $ofp_id, $flight_id, $aircraft_id, $fares, $sb_userid, $sb_static_id);
if ($simbrief === null) {
$error = new AssetNotFound(new Exception('Simbrief OFP not found'));
return $error->getResponse();
}
return redirect(route('frontend.simbrief.briefing', [$ofp_id]));
}
/**
* Generate the API code
*

View File

@@ -140,6 +140,7 @@ class RouteServiceProvider extends ServiceProvider
Route::get('simbrief/generate', 'SimBriefController@generate')->name('simbrief.generate');
Route::post('simbrief/apicode', 'SimBriefController@api_code')->name('simbrief.api_code');
Route::get('simbrief/check_ofp', 'SimBriefController@check_ofp')->name('simbrief.check_ofp');
Route::get('simbrief/update_ofp', 'SimBriefController@update_ofp')->name('simbrief.update_ofp');
Route::get('simbrief/{id}', 'SimBriefController@briefing')->name('simbrief.briefing');
Route::get('simbrief/{id}/prefile', 'SimBriefController@prefile')->name('simbrief.prefile');
Route::get('simbrief/{id}/cancel', 'SimBriefController@cancel')->name('simbrief.cancel');

View File

@@ -26,11 +26,13 @@ class SimBriefService extends Service
* Check to see if the OFP exists server-side. If it does, download it and
* cache it immediately
*
* @param string $user_id User who generated this
* @param string $ofp_id The SimBrief OFP ID
* @param string $flight_id The flight ID
* @param string $ac_id The aircraft ID
* @param array $fares Full list of fares for the flightß
* @param string $user_id User who generated this
* @param string $ofp_id The SimBrief OFP ID
* @param string $flight_id The flight ID
* @param string $ac_id The aircraft ID
* @param array $fares Full list of fares for the flight
* @param string $sb_userid User's Simbrief ID (Used for Update)
* @param string $sb_static_id Static ID for the generated OFP (Used for Update)
*
* @return SimBrief|null
*/
@@ -39,10 +41,18 @@ class SimBriefService extends Service
string $ofp_id,
string $flight_id,
string $ac_id,
array $fares = []
array $fares = [],
string $sb_user_id = null,
string $sb_static_id = null
) {
$uri = str_replace('{id}', $ofp_id, config('phpvms.simbrief_url'));
if ($sb_user_id && $sb_static_id) {
// $uri = str_replace('{sb_user_id}', $sb_user_id, config('phpvms.simbrief_update_url'));
// $uri = str_replace('{sb_static_id}', $sb_static_id, $uri);
$uri = 'https://www.simbrief.com/api/xml.fetcher.php?userid='.$sb_user_id.'&static_id='.$sb_static_id;
}
$opts = [
'connect_timeout' => 2, // wait two seconds by default
'allow_redirects' => false,