Mache die Inhaltsverwaltung fuer die Redaktion bedienbar
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
9b52181be1
commit
d6ff881e4e
10 files changed
+371
-49
No files matched your search
@@ -2,17 +2,24 @@
|
||||
|
||||
namespace App\Filament\Resources\Compositions\Pages;
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\CompositionMember;
|
||||
use App\Domain\Catalog\CompositionStructureReader;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\EditorialDimensionValue;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
use App\Domain\Catalog\StructureNode;
|
||||
use App\Filament\Resources\Combinations\CombinationResource;
|
||||
use App\Filament\Resources\Courses\CourseResource;
|
||||
use App\Filament\Resources\Exercises\ExerciseResource;
|
||||
@@ -21,6 +28,8 @@
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
@@ -50,6 +59,12 @@ public function form(Schema $schema): Schema
|
||||
TextInput::make('display_title')->label('Anzeigetitel')
|
||||
->helperText('Erscheint in der Bibliothek. Leer lässt die Bezeichnung stehen.'),
|
||||
Textarea::make('summary')->label('Kurzbeschreibung')->rows(3),
|
||||
Textarea::make('learning_goal')->label('Lernziel')->rows(2)
|
||||
->helperText('Gehört zur Fassung. Eine Änderung legt eine neue Fassung an.'),
|
||||
TextInput::make('duration_minutes')->label('Zeitbedarf in Minuten')->numeric()->minValue(1),
|
||||
Textarea::make('material_note')->label('Materialbedarf')->rows(2),
|
||||
Placeholder::make('status')->label('Stand')->content(fn (): HtmlString => new HtmlString(e($this->statusText()))),
|
||||
Placeholder::make('outline')->label('Gliederung der aktuellen Fassung')->content(fn (): HtmlString => new HtmlString($this->outlineHtml())),
|
||||
Select::make('kind')->label('Art')->options(CompositionKind::options())->required()
|
||||
->helperText('Übung, Kurs und fachliche Kombination sind verschiedene Zusammenstellungen. Die Art lässt sich hier ändern.'),
|
||||
Select::make('editorial_content_kind_id')
|
||||
@@ -66,11 +81,25 @@ public function form(Schema $schema): Schema
|
||||
->where('nested_composition_version_id', $version->id)
|
||||
->with('compositionVersion.composition')
|
||||
->get()
|
||||
->map(fn (CompositionMember $member): string => ($member->compositionVersion->composition->designation ?? 'Programm').' · '.$member->role)
|
||||
->map(fn (CompositionMember $member): string => ($member->compositionVersion->composition->designation ?? 'Programm').', Rolle '.$member->role)
|
||||
->all();
|
||||
$articles = ArticleRelease::query()
|
||||
->where('root_composition_version_id', $version->id)
|
||||
->with('article')
|
||||
->get()
|
||||
->map(fn (ArticleRelease $release): string => 'Lizenzartikel '.$release->article->code.', Stand '.$release->number)
|
||||
->all();
|
||||
$lines = [...$lines, ...$articles];
|
||||
|
||||
return new HtmlString($lines === [] ? 'In keiner anderen Fassung enthalten.' : e(implode(' · ', $lines)));
|
||||
return new HtmlString($lines === [] ? 'In keinem anderen Programm und in keinem Lizenzartikel.' : implode('<br>', array_map(e(...), $lines)));
|
||||
}),
|
||||
CheckboxList::make('dimension_ids')->label('Fachliche Einordnung')
|
||||
->options(fn (): array => self::dimensionOptions())
|
||||
->columns(1)
|
||||
->helperText('Wirkt auf die Suche in der Bibliothek und legt keine neue Fassung an.'),
|
||||
FileUpload::make('thumbnail_upload')->label('Vorschaubild')
|
||||
->disk('cms_incoming')->directory('vorschau')->visibility('private')->image()
|
||||
->helperText('Ersetzt nur das Bild der Karte. Die Fassung und die Dateien bleiben unverändert.'),
|
||||
Placeholder::make('history')->label('Aktuelle Fassung')->content(function (): HtmlString {
|
||||
/** @var Composition $composition */
|
||||
$composition = $this->getRecord();
|
||||
@@ -89,8 +118,9 @@ public function form(Schema $schema): Schema
|
||||
->label('Bausteine der neuen Fassung')
|
||||
->schema([
|
||||
TextInput::make('role')->label('Rolle')->placeholder('Film, Merkblatt, Übung')->required(),
|
||||
Select::make('target')->label('Fassung')->required()->searchable()
|
||||
->options(fn (): array => CatalogOptions::assignmentTargets($this->getRecord()->getKey())),
|
||||
Select::make('target')->label('Vorhandener Inhalt')->required()->searchable()
|
||||
->options(fn (): array => CatalogOptions::assignmentTargets($this->getRecord()->getKey()))
|
||||
->helperText('Titel, Inhaltsart und Fassungsnummer. Es wird genau diese Fassung verwendet.'),
|
||||
])
|
||||
->minItems(1)
|
||||
->reorderable()
|
||||
@@ -177,6 +207,15 @@ protected function mutateFormDataBeforeFill(array $data): array
|
||||
'summary' => $composition->summary,
|
||||
'kind' => $kind instanceof CompositionKind ? $kind->value : $kind,
|
||||
'editorial_content_kind_id' => $composition->editorial_content_kind_id,
|
||||
'learning_goal' => $version?->learning_goal,
|
||||
'duration_minutes' => $version?->duration_minutes,
|
||||
'material_note' => $version?->material_note,
|
||||
'dimension_ids' => IdentityDimensionValue::query()
|
||||
->where('subject_type', $composition->getMorphClass())
|
||||
->where('subject_id', $composition->id)
|
||||
->where('origin', 'direkt')
|
||||
->pluck('editorial_dimension_value_id')
|
||||
->all(),
|
||||
'members' => $members,
|
||||
'note' => null,
|
||||
];
|
||||
@@ -196,10 +235,20 @@ protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
'summary' => $data['summary'] ?? null,
|
||||
], auth()->user());
|
||||
$record->kind = $kind;
|
||||
$record->editorial_content_kind_id = filled($data['editorial_content_kind_id'] ?? null)
|
||||
? (int) $data['editorial_content_kind_id']
|
||||
: null;
|
||||
if (array_key_exists('editorial_content_kind_id', $data)) {
|
||||
$record->editorial_content_kind_id = filled($data['editorial_content_kind_id'] ?? null)
|
||||
? (int) $data['editorial_content_kind_id']
|
||||
: null;
|
||||
}
|
||||
if (is_string($data['thumbnail_upload'] ?? null) && $data['thumbnail_upload'] !== '') {
|
||||
$record->thumbnail_path = $data['thumbnail_upload'];
|
||||
$record->thumbnail_error = null;
|
||||
$record->thumbnail_alt = $record->designation;
|
||||
}
|
||||
$record->save();
|
||||
if (array_key_exists('dimension_ids', $data)) {
|
||||
$this->syncDimensions($record, array_map(intval(...), $data['dimension_ids'] ?? []));
|
||||
}
|
||||
|
||||
$members = [];
|
||||
|
||||
@@ -216,14 +265,21 @@ protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
}
|
||||
|
||||
$note = is_string($data['note'] ?? null) ? trim($data['note']) : '';
|
||||
$current = $this->currentReadyVersion();
|
||||
$didactic = [
|
||||
'learning_goal' => $this->blankToNull(array_key_exists('learning_goal', $data) ? $data['learning_goal'] : $current?->learning_goal),
|
||||
'duration_minutes' => $this->minutes(array_key_exists('duration_minutes', $data) ? $data['duration_minutes'] : $current?->duration_minutes),
|
||||
'material_note' => $this->blankToNull(array_key_exists('material_note', $data) ? $data['material_note'] : $current?->material_note),
|
||||
];
|
||||
|
||||
if ($note !== '' || ! $this->sameMembers($record, $members)) {
|
||||
if ($note !== '' || ! $this->sameMembers($record, $members) || $this->didacticChanged($current, $didactic)) {
|
||||
$actor = Filament::auth()->user();
|
||||
app(ContentService::class)->publishComposition(
|
||||
$record,
|
||||
$members,
|
||||
$actor instanceof User ? $actor : null,
|
||||
$note !== '' ? $note : null,
|
||||
$didactic,
|
||||
);
|
||||
$this->savedTitle = 'Die neue Fassung ist veröffentlicht. Die bisherige Fassung bleibt erhalten.';
|
||||
} else {
|
||||
@@ -303,4 +359,118 @@ private function sameMembers(Composition $composition, array $members): bool
|
||||
|
||||
return $current === $next;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{learning_goal: mixed, duration_minutes: mixed, material_note: mixed} $didactic
|
||||
*/
|
||||
private function didacticChanged(?CompositionVersion $version, array $didactic): bool
|
||||
{
|
||||
if ($version === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$storedMinutes = $version->duration_minutes === null ? null : (int) $version->duration_minutes;
|
||||
|
||||
return $version->learning_goal !== $didactic['learning_goal']
|
||||
|| $version->material_note !== $didactic['material_note']
|
||||
|| $storedMinutes !== $didactic['duration_minutes'];
|
||||
}
|
||||
|
||||
private function minutes(mixed $value): ?int
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
private function blankToNull(mixed $value): ?string
|
||||
{
|
||||
if (! is_string($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = trim($value);
|
||||
|
||||
return $value === '' ? null : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $ids
|
||||
*/
|
||||
private function syncDimensions(Composition $composition, array $ids): void
|
||||
{
|
||||
IdentityDimensionValue::query()
|
||||
->where('subject_type', $composition->getMorphClass())
|
||||
->where('subject_id', $composition->id)
|
||||
->where('origin', 'direkt')
|
||||
->whereNotIn('editorial_dimension_value_id', $ids === [] ? [0] : $ids)
|
||||
->delete();
|
||||
|
||||
foreach (EditorialDimensionValue::query()->whereIn('id', $ids)->get() as $value) {
|
||||
app(IdentityDimension::class)->assign($composition, $value, 'direkt');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private static function dimensionOptions(): array
|
||||
{
|
||||
$options = [];
|
||||
|
||||
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
|
||||
foreach ($dimension->values as $value) {
|
||||
$options[$value->id] = $dimension->label.': '.$value->label;
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
private function statusText(): string
|
||||
{
|
||||
/** @var Composition $composition */
|
||||
$composition = $this->getRecord();
|
||||
$version = $this->currentReadyVersion();
|
||||
|
||||
if ($version === null) {
|
||||
return 'Noch keine technisch bereite Fassung. Speichern legt die erste Fassung an.';
|
||||
}
|
||||
|
||||
$released = app(CompositionDisplayRelease::class)->isReleased($version);
|
||||
$older = $composition->versions()->where('number', '<', $version->number)->orderBy('number')->pluck('number')->all();
|
||||
$history = $older === [] ? 'Es gibt keine ältere Fassung.' : 'Ältere Fassungen: '.implode(', ', $older).'.';
|
||||
|
||||
return 'Fassung '.$version->number.' ist technisch bereit. '
|
||||
.($released ? 'Sie ist zur Anzeige freigegeben. ' : 'Sie ist noch nicht zur Anzeige freigegeben. ')
|
||||
.$history;
|
||||
}
|
||||
|
||||
private function outlineHtml(): string
|
||||
{
|
||||
$version = $this->currentReadyVersion();
|
||||
|
||||
if ($version === null) {
|
||||
return 'Die Gliederung erscheint, sobald eine Fassung bereit ist.';
|
||||
}
|
||||
|
||||
$lines = [];
|
||||
$this->outlineLines(app(CompositionStructureReader::class)->tree($version), 0, $lines);
|
||||
|
||||
return $lines === [] ? 'Diese Fassung hat noch keine Bestandteile.' : implode('<br>', array_map(e(...), $lines));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<StructureNode> $nodes
|
||||
* @param list<string> $lines
|
||||
*/
|
||||
private function outlineLines(array $nodes, int $depth, array &$lines): void
|
||||
{
|
||||
foreach ($nodes as $node) {
|
||||
$lines[] = str_repeat('– ', $depth).$node->role.': '.$node->title;
|
||||
$this->outlineLines($node->children, $depth + 1, $lines);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
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;
|
||||
@@ -26,7 +27,11 @@ protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('create')
|
||||
->label($this->kind()->createLabel())
|
||||
->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(),
|
||||
@@ -35,6 +40,16 @@ protected function getHeaderActions(): array
|
||||
$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) {
|
||||
|
||||
Reference in new issue
Block a user