Added Notifications
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\DTOs\MissingLivery;
|
||||
use App\Models\IgnoredMissingLivery;
|
||||
use App\Models\UserFlight;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class AdminService
|
||||
{
|
||||
/** @return Collection<int, MissingLivery> */
|
||||
function getMissingLiveries(): Collection
|
||||
{
|
||||
|
||||
/* $existingFiles = collect(glob(public_path('img/liveries/generated/*')))
|
||||
->map(fn ($path) => pathinfo($path, PATHINFO_FILENAME))
|
||||
->toArray();*/
|
||||
|
||||
|
||||
$existingFiles = collect(glob(Storage::disk('local')->path('images/liveries').'/*.png'))
|
||||
->map(fn ($path) => pathinfo($path, PATHINFO_FILENAME))
|
||||
->toArray();
|
||||
|
||||
$combos = UserFlight::with(['aircraft', 'airline'])
|
||||
->select('airline_id', 'aircraft_id')
|
||||
->whereNotNull('airline_id')
|
||||
->whereNotNull('aircraft_id')
|
||||
->distinct()
|
||||
->get()
|
||||
->filter(fn ($flight) => $flight->aircraft && $flight->airline)
|
||||
->map(fn ($flight) => [
|
||||
'airline_name' => $flight->airline->name,
|
||||
'aircraft_display_name' => $flight->aircraft->display_name,
|
||||
'filename' => $flight->airline->internal_name . '_' . $flight->aircraft->designator,
|
||||
'clipboard_text' => $flight->airline->name . ' ' . $flight->aircraft->display_name_short,
|
||||
])
|
||||
->filter(fn ($combo) => !in_array($combo['filename'], $existingFiles));
|
||||
|
||||
$ignoredFiles = IgnoredMissingLivery::whereIn('filename', $combos->pluck('filename'))->pluck('filename')->toArray();
|
||||
|
||||
return $combos
|
||||
->filter(fn ($combo) => !in_array($combo['filename'], $ignoredFiles))
|
||||
->sortBy('airline_name')
|
||||
->values();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user