Eine Fassung bleibt nummeriert und kann deaktiviert werden. Beschreibung und fachliche Säulen gehören zum Medium und legen keine neue Fassung an. Co-authored-by: Cursor <cursoragent@cursor.com>
85 lines
3.6 KiB
PHP
85 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ContentElements\Pages;
|
|
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
|
use App\Filament\Support\IncomingFile;
|
|
use App\Filament\Support\ReportsDomainRules;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\Pages\ListRecords;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
|
|
class ListContentElements extends ListRecords
|
|
{
|
|
use ReportsDomainRules;
|
|
|
|
protected static string $resource = ContentElementResource::class;
|
|
|
|
public function getSubheading(): string|Htmlable|null
|
|
{
|
|
return 'Die Dateien und Texte. Eine Übung, ein Kurs oder eine fachliche Kombination verweist darauf; die Datei wird nicht für jede Verwendung neu hochgeladen.';
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('create')
|
|
->label('Medium anlegen')
|
|
->visible(fn (): bool => ContentElementResource::editor())
|
|
->schema([
|
|
TextInput::make('working_title')->label('Arbeitstitel')->required(),
|
|
Select::make('kind')->label('Art')->options([
|
|
'film' => 'Film',
|
|
'audio' => 'Audio',
|
|
'bild' => 'Bild',
|
|
'pdf' => 'PDF',
|
|
'text' => 'Text',
|
|
'aufgabe' => 'Aufgabe',
|
|
])->required(),
|
|
Select::make('output_class')->label('Ausgabeklasse')->options([
|
|
'film' => 'Film',
|
|
'audio' => 'Audio',
|
|
'bild' => 'Bild',
|
|
'pdf' => 'PDF',
|
|
'text' => 'Text',
|
|
])->required(),
|
|
Textarea::make('body')->label('Text'),
|
|
EditContentElement::uploadField(),
|
|
TextInput::make('decision_seconds')->label('Entscheidungsmarke in Sekunden')->numeric()->minValue(0),
|
|
TextInput::make('change_note')->label('Änderungsnotiz'),
|
|
])
|
|
->action(function (array $data): void {
|
|
$element = null;
|
|
$this->report(function () use ($data, &$element): void {
|
|
$service = app(ContentService::class);
|
|
$element = $service->createElement($data['kind'], $data['output_class'], $data['working_title']);
|
|
$metadata = [];
|
|
$incoming = IncomingFile::store($data['incoming'] ?? null);
|
|
|
|
if (is_string($incoming) && $incoming !== '') {
|
|
$metadata['incoming'] = $incoming;
|
|
}
|
|
|
|
if (is_numeric($data['decision_seconds'] ?? null)) {
|
|
$metadata['decision_seconds'] = (int) $data['decision_seconds'];
|
|
}
|
|
|
|
$body = $data['body'] ?? null;
|
|
|
|
if ((is_string($body) && $body !== '') || $metadata !== []) {
|
|
$service->publishElementVersion($element, is_string($body) ? $body : null, $metadata, $data['change_note'] ?? null);
|
|
}
|
|
}, 'Das Medium ist angelegt.');
|
|
|
|
if ($element !== null) {
|
|
$this->redirect(ContentElementResource::getUrl('view', ['record' => $element]));
|
|
}
|
|
}),
|
|
];
|
|
}
|
|
}
|