59 lines
2.3 KiB
PHP
59 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Bundles\Pages;
|
|
|
|
use App\Domain\Catalog\Bundle;
|
|
use App\Domain\Catalog\BundleService;
|
|
use App\Domain\Catalog\LicenseArticle;
|
|
use App\Filament\Resources\Bundles\BundleResource;
|
|
use App\Filament\Support\CatalogOptions;
|
|
use App\Filament\Support\ReportsDomainRules;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\CheckboxList;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\Pages\ListRecords;
|
|
|
|
class ListBundles extends ListRecords
|
|
{
|
|
use ReportsDomainRules;
|
|
|
|
protected static string $resource = BundleResource::class;
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('create')->label('Paket anlegen')->schema([
|
|
TextInput::make('name')->label('Name')->required(),
|
|
])->action(function (array $data): void {
|
|
$this->report(function () use ($data): void {
|
|
app(BundleService::class)->create($data['name']);
|
|
}, 'Das Paket ist angelegt.');
|
|
}),
|
|
Action::make('publish')->label('Fassung veröffentlichen')->schema([
|
|
Select::make('bundle_id')->label('Paket')->options(fn (): array => CatalogOptions::bundles())->required(),
|
|
CheckboxList::make('articles')->label('Lizenzartikel')->options(fn (): array => CatalogOptions::articles()),
|
|
CheckboxList::make('bundles')->label('Enthaltene Pakete')->options(fn (): array => CatalogOptions::bundles()),
|
|
])->action(function (array $data): void {
|
|
$this->report(function () use ($data): void {
|
|
$items = [];
|
|
|
|
foreach ($data['articles'] ?? [] as $id) {
|
|
$items[] = LicenseArticle::query()->findOrFail($id);
|
|
}
|
|
|
|
foreach ($data['bundles'] ?? [] as $id) {
|
|
if ((int) $id === (int) $data['bundle_id']) {
|
|
continue;
|
|
}
|
|
|
|
$items[] = Bundle::query()->findOrFail($id);
|
|
}
|
|
|
|
app(BundleService::class)->publish(Bundle::query()->findOrFail($data['bundle_id']), $items);
|
|
}, 'Die Paketfassung ist veröffentlicht.');
|
|
}),
|
|
];
|
|
}
|
|
}
|