58 lines
2.1 KiB
PHP
58 lines
2.1 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\Resources\Pages\ViewRecord;
|
|
|
|
class ViewBundle extends ViewRecord
|
|
{
|
|
use ReportsDomainRules;
|
|
|
|
protected static string $resource = BundleResource::class;
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('publish')
|
|
->label('Fassung veröffentlichen')
|
|
->schema([
|
|
CheckboxList::make('articles')->label('Lizenzartikel')->options(fn (): array => CatalogOptions::articles()),
|
|
CheckboxList::make('bundles')->label('Enthaltene Pakete')
|
|
->options(function (): array {
|
|
$options = CatalogOptions::bundles();
|
|
unset($options[$this->getRecord()->getKey()]);
|
|
|
|
return $options;
|
|
}),
|
|
])
|
|
->action(function (array $data): void {
|
|
$this->report(function () use ($data): void {
|
|
/** @var Bundle $bundle */
|
|
$bundle = $this->getRecord();
|
|
$items = [];
|
|
|
|
foreach ($data['articles'] ?? [] as $id) {
|
|
$items[] = LicenseArticle::query()->findOrFail($id);
|
|
}
|
|
|
|
foreach ($data['bundles'] ?? [] as $id) {
|
|
$items[] = Bundle::query()->findOrFail($id);
|
|
}
|
|
|
|
app(BundleService::class)->publish($bundle, $items);
|
|
}, 'Die Paketfassung ist veröffentlicht.');
|
|
$this->getRecord()->unsetRelations();
|
|
$this->getRecord()->refresh();
|
|
}),
|
|
];
|
|
}
|
|
}
|