96 lines
3.8 KiB
PHP
96 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ContentElements\Pages;
|
|
|
|
use App\Domain\Catalog\ContentElement;
|
|
use App\Domain\Catalog\ContentElementVersion;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
|
use App\Filament\Support\ReportsDomainRules;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\FileUpload;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\Pages\ViewRecord;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
|
|
class ViewContentElement extends ViewRecord
|
|
{
|
|
use ReportsDomainRules;
|
|
|
|
protected static string $resource = ContentElementResource::class;
|
|
|
|
public function getSubheading(): string|Htmlable|null
|
|
{
|
|
return 'Text und Datei gehören zur Fassung. Eine Filmfassung kann eine Entscheidungsmarke in Sekunden tragen. Zum Kurs wird das Element in einer Komposition, zum Paket über den Lizenzartikel.';
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('preview')
|
|
->label('Ansehen')
|
|
->url(function (): ?string {
|
|
$version = $this->latestVersion();
|
|
|
|
return $version === null ? null : route('content.preview', $version);
|
|
})
|
|
->visible(fn (): bool => $this->latestVersion() !== null)
|
|
->openUrlInNewTab(),
|
|
Action::make('version')
|
|
->label('Fassung veröffentlichen')
|
|
->schema([
|
|
Textarea::make('body')->label('Text'),
|
|
FileUpload::make('incoming')
|
|
->label('Datei')
|
|
->disk('cms_incoming')
|
|
->directory('inhalte')
|
|
->helperText('Film, Audio oder PDF. Die Datei wird übernommen und ist danach unter Ansehen sichtbar.'),
|
|
TextInput::make('decision_seconds')
|
|
->label('Entscheidungsmarke in Sekunden')
|
|
->numeric()
|
|
->minValue(0)
|
|
->helperText('Nur für Filme: der Kursplayer pausiert an dieser Stelle.'),
|
|
TextInput::make('change_note')->label('Änderungsnotiz'),
|
|
])
|
|
->action(function (array $data): void {
|
|
$this->report(function () use ($data): void {
|
|
/** @var ContentElement $element */
|
|
$element = $this->getRecord();
|
|
$metadata = [];
|
|
$incoming = $data['incoming'] ?? null;
|
|
|
|
if (is_array($incoming)) {
|
|
$incoming = array_values(array_filter($incoming, 'is_string'))[0] ?? null;
|
|
}
|
|
|
|
if (is_string($incoming) && $incoming !== '') {
|
|
$metadata['incoming'] = $incoming;
|
|
}
|
|
|
|
if (is_numeric($data['decision_seconds'] ?? null)) {
|
|
$metadata['decision_seconds'] = (int) $data['decision_seconds'];
|
|
}
|
|
|
|
app(ContentService::class)->publishElementVersion(
|
|
$element,
|
|
$data['body'] ?? null,
|
|
$metadata,
|
|
$data['change_note'] ?? null,
|
|
);
|
|
}, 'Die Fassung ist gespeichert.');
|
|
$this->getRecord()->unsetRelations();
|
|
$this->getRecord()->refresh();
|
|
}),
|
|
];
|
|
}
|
|
|
|
private function latestVersion(): ?ContentElementVersion
|
|
{
|
|
/** @var ContentElement $element */
|
|
$element = $this->getRecord();
|
|
|
|
return $element->versions()->orderByDesc('number')->first();
|
|
}
|
|
}
|