DownloadController Improvements (#1091)

* DownloadController Improvements

Added multiple airline support to both Aircraft and Subfleet downloads, if the user has more than one active airline downloads will display the airline name before the object name. Also sorted the returned results to have a better look at the blade.

* Trying to pass broken UnitTest

Please do fix the UnitTest, this pr has nothing to do with units but still being tested with it and failing.
This commit is contained in:
B.Fatih KOZ 2021-03-21 16:33:04 +03:00 committed by GitHub
parent 30e88ac6bc
commit 3cc5ca2c32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Frontend;
use App\Contracts\Controller;
use App\Models\Airline;
use App\Models\File;
use Auth;
use Flash;
@ -18,6 +19,7 @@ class DownloadController extends Controller
*/
public function index()
{
$airlines = Airline::where('active', 1)->count();
$files = File::orderBy('ref_model', 'asc')->get();
/**
@ -42,10 +44,14 @@ class DownloadController extends Controller
$category = explode('\\', $class);
$category = end($category);
if ($category == 'Aircraft') {
if ($category == 'Aircraft' && $airlines > 1) {
$group_name = $category.' > '.$obj->subfleet->airline->name.' '.$obj->icao.' '.$obj->registration;
} elseif ($category == 'Aircraft') {
$group_name = $category.' > '.$obj->icao.' '.$obj->registration;
} elseif ($category == 'Airport') {
$group_name = $category.' > '.$obj->icao.' : '.$obj->name.' ('.$obj->country.')';
} elseif ($category == 'Subfleet' && $airlines > 1) {
$group_name = $category.' > '.$obj->airline->name.' '.$obj->name;
} else {
$group_name = $category.' > '.$obj->name;
}
@ -53,13 +59,15 @@ class DownloadController extends Controller
$regrouped_files[$group_name] = $files;
}
ksort($regrouped_files, SORT_STRING);
return view('downloads.index', [
'grouped_files' => $regrouped_files,
]);
}
/**
* Show the application dashboard.
* Show the application dashboard
*
* @param string $id
*