62 lines
2.4 KiB
PHP
62 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Compositions\Pages;
|
|
|
|
use App\Domain\Catalog\CompositionKind;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Domain\Catalog\EditorialContentKind;
|
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
|
use App\Filament\Support\ReportsDomainRules;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\Pages\ListRecords;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
|
|
abstract class ListCompositionKind extends ListRecords
|
|
{
|
|
use ReportsDomainRules;
|
|
|
|
abstract protected function kind(): CompositionKind;
|
|
|
|
public function getSubheading(): string|Htmlable|null
|
|
{
|
|
return $this->kind()->deskExplanation();
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('create')
|
|
->label(match ($this->kind()) {
|
|
CompositionKind::Kurs => 'Programm anlegen',
|
|
CompositionKind::Uebung => 'Modul anlegen',
|
|
default => $this->kind()->createLabel(),
|
|
})
|
|
->visible(fn (): bool => ContentElementResource::editor())
|
|
->schema([
|
|
TextInput::make('designation')->label('Bezeichnung')->required(),
|
|
])
|
|
->action(function (array $data): void {
|
|
$composition = null;
|
|
$this->report(function () use ($data, &$composition): void {
|
|
$composition = app(ContentService::class)->createComposition($data['designation'], $this->kind());
|
|
$slug = match ($this->kind()) {
|
|
CompositionKind::Kurs => 'programm',
|
|
CompositionKind::Uebung => 'modul',
|
|
default => null,
|
|
};
|
|
$editorial = $slug === null ? null : EditorialContentKind::query()->where('slug', $slug)->first();
|
|
if ($editorial !== null) {
|
|
$composition->editorial_content_kind_id = $editorial->id;
|
|
$composition->save();
|
|
}
|
|
}, $this->kind()->label().' ist angelegt.');
|
|
|
|
if ($composition !== null) {
|
|
$this->redirect(static::getResource()::getUrl('edit', ['record' => $composition]));
|
|
}
|
|
}),
|
|
];
|
|
}
|
|
}
|