Files
laraundfelix/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php
LarsandCursor a7feef2cd2
Deploy Test / test (push) Successful in 26s
Deploy Test / deploy (push) Successful in 22s
Mache den Aufbau von Modulen und Programmen im Arbeitsplatz bedienbar.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-16 14:03:22 +01:00

66 lines
2.6 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
{
$desk = in_array($this->kind(), [CompositionKind::Kurs, CompositionKind::Uebung], true)
? ' Programme und Module liegen gemeinsam auf dem Arbeitsplatz.'
: '';
return $this->kind()->deskExplanation().$desk;
}
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]));
}
}),
];
}
}