' : '';
+ return $rows !== '' && (self::hasText($rows) || str_contains($rows, ''.$rows.'' : '';
}
private static function inner(Node $node): string
@@ -506,7 +536,7 @@ private static function inner(Node $node): string
$html = '';
foreach ($node->childNodes as $child) {
- if ($child->nodeType === XML_ELEMENT_NODE && in_array(strtolower($child->nodeName), ['ul', 'ol', 'p', 'blockquote'], true)) {
+ if ($child->nodeType === XML_ELEMENT_NODE && in_array(strtolower($child->nodeName), ['ul', 'ol', 'p', 'blockquote', 'img'], true)) {
$html .= self::block($child);
continue;
@@ -518,6 +548,28 @@ private static function inner(Node $node): string
return trim($html);
}
+ /** Wo darf ein Bild stehen: im Text, in einer Tabellenzelle oder in einem Absatz dort. */
+ private static function mayHoldImage(?Node $parent, Node $body): bool
+ {
+ if ($parent === null) {
+ return false;
+ }
+
+ $name = strtolower($parent->nodeName);
+
+ if ($parent === $body || in_array($name, ['td', 'th'], true)) {
+ return true;
+ }
+
+ return $name === 'p' && $parent->parentNode !== null && ($parent->parentNode === $body || in_array(strtolower($parent->parentNode->nodeName), ['td', 'th'], true));
+ }
+
+ /** Hat der Ausschnitt einen Inhalt: Text oder ein Bild? */
+ private static function hasContent(string $html): bool
+ {
+ return self::hasText($html) || str_contains($html, 'room($height + 8);
- $this->pdf->image($x, $this->y - $height, $width, $height, $found['jpeg'], $found['width'], $found['height']);
- $this->y -= $height + 8;
+ $this->room($height + 16);
+ $this->pdf->image($x, $this->y + 4 - $height, $width, $height, $found['jpeg'], $found['width'], $found['height']);
+ $this->y -= $height + 16;
}
/**
@@ -330,7 +330,7 @@ private function table(array $rows, float $x): void
$this->depth++;
$cell['lines'] = $this->cellLines($cell['blocks'], max(10.0, $inner), $size, $cell['header']);
$this->depth--;
- $cell['height'] = max(1, count($cell['lines'])) * $lineHeight + 2 * $pad;
+ $cell['height'] = max($lineHeight, array_sum(array_column($cell['lines'], 'height'))) + 2 * $pad;
$prepared[] = $cell;
}
@@ -363,7 +363,7 @@ private function table(array $rows, float $x): void
return;
}
- $drawRows = function (int $from, int $to) use ($prepared, $widths, $heights, $x, $size, $pad, $lineHeight): void {
+ $drawRows = function (int $from, int $to) use ($prepared, $widths, $heights, $x, $size, $pad): void {
$y = $this->y;
for ($r = $from; $r <= $to; $r++) {
@@ -379,6 +379,13 @@ private function table(array $rows, float $x): void
$textY = $y - $pad - $size;
foreach ($cell['lines'] as $line) {
+ if (isset($line['image'])) {
+ $this->pdf->image($cellLeft + $pad, $textY + $size - $line['image']['height'], $line['image']['width'], $line['image']['height'], $line['image']['jpeg'], $line['image']['pixelWidth'], $line['image']['pixelHeight']);
+ $textY -= $line['height'];
+
+ continue;
+ }
+
if ($line['marker'] !== null) {
$this->pdf->text($cellLeft + $pad + $line['indent'] - 12, $textY, $line['marker'], $size, $cell['header']);
}
@@ -390,7 +397,7 @@ private function table(array $rows, float $x): void
$cursor += PdfDocument::exactWidth($text, $size, $isBold || $cell['header']);
}
- $textY -= $lineHeight;
+ $textY -= $line['height'];
}
}
@@ -528,10 +535,21 @@ private function columnWidths(array $cells, int $columns, float $available, floa
return array_map(fn (float $w): float => $w + $extra, $want);
}
+ // Der Platz über dem Mindestmaß wird gleichmäßig verteilt, aber keine Spalte bekommt mehr, als sie sich wünscht:
+ // Schmale Spalten behalten ihren Text in einer Zeile, die breite nimmt den Rest.
+ $widths = $min;
$room = $available - array_sum($min);
- $wishes = array_sum($want) - array_sum($min);
+ $open = array_keys($min);
+ usort($open, fn (int $a, int $b): int => ($want[$a] - $min[$a]) <=> ($want[$b] - $min[$b]));
- return array_map(fn (float $m, float $w): float => $m + $room * (($w - $m) / max(1.0, $wishes)), $min, $want);
+ foreach ($open as $position => $c) {
+ $share = $room / (count($open) - $position);
+ $give = min($want[$c] - $min[$c], $share);
+ $widths[$c] += $give;
+ $room -= $give;
+ }
+
+ return $widths;
}
/**
@@ -553,32 +571,49 @@ private function cellText(array $blocks): string
}
/**
- * Zeilen einer Tabellenzelle: Absätze, Aufzählungen und Zwischenüberschriften; ein Bild in der Zelle entfällt.
+ * Zeilen einer Tabellenzelle: Absätze, Aufzählungen, Zwischenüberschriften und Bilder (höchstens 110 Punkt hoch, in
+ * Breite der Zelle). Jeder Eintrag trägt seine Höhe.
*
* @param list> $blocks
- * @return list, indent: float, marker: ?string}>
+ * @return list>
*/
private function cellLines(array $blocks, float $width, float $size, bool $header): array
{
$out = [];
+ $lineHeight = $size + 3;
foreach ($blocks as $block) {
if (in_array($block['type'], ['bullets', 'numbered'], true)) {
foreach ($block['items'] as $index => $item) {
foreach ($this->lines($item, $width - 12, $size, $header) as $i => $segments) {
- $out[] = ['segments' => $segments, 'indent' => 12.0, 'marker' => $i === 0 ? ($block['type'] === 'bullets' ? '•' : ($index + 1).'.') : null];
+ $out[] = ['segments' => $segments, 'indent' => 12.0, 'marker' => $i === 0 ? ($block['type'] === 'bullets' ? '•' : ($index + 1).'.') : null, 'height' => $lineHeight];
}
}
continue;
}
+ if ($block['type'] === 'image') {
+ $found = $this->images === null ? null : ($this->images)((int) $block['id']);
+
+ if ($found !== null && isset($found['jpeg'])) {
+ $scale = min(1.0, $width / max(1, $found['width']), 110.0 / max(1, $found['height']));
+ $w = max(1.0, $found['width'] * $scale);
+ $h = max(1.0, $found['height'] * $scale);
+ $out[] = ['image' => ['jpeg' => $found['jpeg'], 'width' => $w, 'height' => $h, 'pixelWidth' => $found['width'], 'pixelHeight' => $found['height']], 'height' => $h + 4];
+ } elseif ($found !== null) {
+ $out[] = ['segments' => [['['.($found['note'] ?? 'Bild nicht verfügbar').']', false, true]], 'indent' => 0.0, 'marker' => null, 'height' => $lineHeight];
+ }
+
+ continue;
+ }
+
if (! isset($block['runs'])) {
continue;
}
foreach ($this->lines($block['runs'], $width, $size, $header || $block['type'] === 'heading', $block['type'] === 'quote') as $segments) {
- $out[] = ['segments' => $segments, 'indent' => 0.0, 'marker' => null];
+ $out[] = ['segments' => $segments, 'indent' => 0.0, 'marker' => null, 'height' => $lineHeight];
}
}
diff --git a/app/Domain/Cms/Catalog/PublicMaterialReader.php b/app/Domain/Cms/Catalog/PublicMaterialReader.php
index 66fa673..0fc5e96 100644
--- a/app/Domain/Cms/Catalog/PublicMaterialReader.php
+++ b/app/Domain/Cms/Catalog/PublicMaterialReader.php
@@ -39,7 +39,7 @@
class PublicMaterialReader
{
/** Inhaltsarten, die nie öffentlich auf einer Karte erscheinen: Anleitungen für Trainer und die Textabschnitte der Übungen. */
- public const CONFIDENTIAL_KINDS = ['traineranleitung', 'uebungsabschnitt'];
+ public const CONFIDENTIAL_KINDS = ['traineranleitung', 'uebungsabschnitt', 'dokumentkapitel'];
/** @var array|null Element-ID => erstes öffentliches Programm */
private ?array $publicIndex = null;
diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php
index 6268d48..467ba9e 100644
--- a/app/Filament/Resources/Compositions/Pages/EditComposition.php
+++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php
@@ -27,6 +27,7 @@
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Support\AssignsPillars;
use App\Filament\Support\EditorialCatalog;
+use App\Filament\Support\ManagesDocumentChapters;
use App\Filament\Support\ManagesEditorialSurface;
use App\Filament\Support\ManagesRichFields;
use App\Filament\Support\MediumForm;
@@ -50,6 +51,7 @@
abstract class EditComposition extends EditRecord
{
use AssignsPillars;
+ use ManagesDocumentChapters;
use ManagesEditorialSurface;
use ManagesRichFields;
use WithFileUploads;
@@ -278,6 +280,10 @@ public function previewUrl(): ?string
/** @var Composition $composition */
$composition = $this->getRecord();
+ if ($this->isDocument()) {
+ return $this->currentReadyVersion() === null && ! is_array($composition->working_draft) ? null : route('editorial.document-preview', ['composition' => $composition]);
+ }
+
if (is_array($composition->working_draft) && $composition->working_draft !== []) {
return route('editorial.draft-preview', ['composition' => $composition]);
}
@@ -371,8 +377,18 @@ public function redaktionKopf(): array
return [
'art' => $this->hostLabel(),
- 'fuer' => $program ? 'das Programm' : 'das Modul',
- 'liste' => $program ? 'Programme' : 'Module',
+ 'fuer' => match (true) {
+ $program => 'das Programm',
+ $this->isDocument() => 'das Dokument',
+ $this->isExercise() => 'die Übung',
+ default => 'das Modul',
+ },
+ 'liste' => match (true) {
+ $program => 'Programme',
+ $this->isDocument() => 'Dokumente',
+ $this->isExercise() => 'Übungen',
+ default => 'Module',
+ },
'zurueck' => 'Zurück zum Aufbau',
'typ' => null,
'umfang' => '„Redaktion speichern“ sichert Name, Texte, Präsentationsmedien und Einordnung. Aufbau, Lernziel, Zeit und Fassungen bleiben unverändert; offene Änderungen am Aufbau bleiben offen.',
@@ -705,10 +721,16 @@ public function saveDraft(): void
return;
}
+ if (! $this->persistChapterEdits()) {
+ return;
+ }
+
/** @var Composition $record */
$record = $this->getRecord();
app(EditorialWorkingDraft::class)->write($record, $this->payload());
- $this->feedback = 'Der Entwurf ist gespeichert. Es entsteht keine neue Fassung.';
+ $this->feedback = $this->isDocument()
+ ? 'Der Entwurf ist gespeichert, auch die Texte der Kapitel. Es entsteht keine neue Dokumentfassung.'
+ : 'Der Entwurf ist gespeichert. Es entsteht keine neue Fassung.';
}
public function armRelease(): void
@@ -722,6 +744,12 @@ public function armRelease(): void
$this->commitRoleDraft();
+ if (! $this->persistChapterEdits()) {
+ $this->releaseArmed = false;
+
+ return;
+ }
+
if ($this->members === []) {
$this->releaseArmed = false;
$this->feedback = 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Entwurf kannst du schon speichern.';
@@ -807,6 +835,7 @@ public function discardDraft(): void
$record = $this->getRecord();
app(EditorialWorkingDraft::class)->clear($record);
$this->releaseArmed = false;
+ $this->chapterEdits = [];
$this->loadAufbau();
$this->selected = null;
$this->selectFirstPart();
@@ -852,6 +881,12 @@ public function includeNeedsRelease(): bool
public function moveTo(int $from, int $to): void
{
+ if ($this->isDocument()) {
+ $this->moveChapterTo($from, $to);
+
+ return;
+ }
+
$this->commitRoleDraft();
$count = count($this->members);
@@ -1184,6 +1219,11 @@ public function removePart(int $index): void
}
$title = (string) ($this->members[$index]['title'] ?? 'Der Bestandteil');
+
+ if ($this->isDocument()) {
+ $this->forgetChapter($index);
+ }
+
unset($this->members[$index]);
$this->members = array_values($this->members);
$this->selected = $this->members === [] ? null : min($index, count($this->members) - 1);
@@ -1206,7 +1246,9 @@ protected function extraConfirmation(string $aktion, int|string|null $argument):
'aktion' => $aktion,
'argument' => (int) $argument,
'titel' => '„'.$title.'“ aus diesem Aufbau entfernen?',
- 'text' => 'Nur diese Verwendung wird entfernt. Das Medium oder Modul bleibt im Bestand und in anderen Aufbauten. Gespeichert wird das mit „Entwurf speichern“.',
+ 'text' => $this->isDocument()
+ ? 'Nur dieses Kapitel wird aus dem Dokument genommen; seine Unterkapitel bleiben und gehören dann zum Kapitel davor. Der Text bleibt im Medienbestand, ungespeicherte Eingaben zu diesem Kapitel entfallen. Gespeichert wird das mit „Entwurf speichern“.'
+ : 'Nur diese Verwendung wird entfernt. Das Medium oder Modul bleibt im Bestand und in anderen Aufbauten. Gespeichert wird das mit „Entwurf speichern“.',
'label' => 'Aus dem Aufbau entfernen',
'gefahr' => true,
];
@@ -1221,6 +1263,12 @@ protected function runExtraConfirmation(string $aktion, int|string|null $argumen
public function movePart(int $index, int $direction): void
{
+ if ($this->isDocument()) {
+ $this->moveChapter($index, $direction);
+
+ return;
+ }
+
$this->commitRoleDraft();
$target = $index + $direction;
@@ -1754,6 +1802,10 @@ public function publishRevision(): bool
$this->commitRoleDraft();
+ if (! $this->persistChapterEdits()) {
+ return false;
+ }
+
if ($this->members === []) {
$this->feedback = 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Kurzbeschreibung kannst du schon speichern.';
@@ -1813,7 +1865,9 @@ public function publishRevision(): bool
$this->loadEditor();
$released = $this->currentReadyVersion();
$number = $released instanceof CompositionVersion ? $released->number : '';
- $this->feedback = 'Fassung '.$number.' ist freigegeben. Der Entwurf ist geschlossen und die bisherige Fassung bleibt erhalten. Die Mitgliederbibliothek ändert sich dadurch nicht.';
+ $this->feedback = $this->isDocument()
+ ? 'Dokumentfassung '.$number.' ist bereitgestellt. Der Entwurf ist geschlossen, frühere Fassungen bleiben erhalten. Ein Modul oder Programm bindet sie über „Hinzufügen“ ein; bestehende Stände ändern sich dadurch nicht.'
+ : 'Fassung '.$number.' ist freigegeben. Der Entwurf ist geschlossen und die bisherige Fassung bleibt erhalten. Die Mitgliederbibliothek ändert sich dadurch nicht.';
if ($this->returnAfterRelease) {
$this->returnAfterRelease = false;
@@ -1969,6 +2023,7 @@ protected function applyDraft(array $draft): void
}
$this->members = $rows;
+ $this->slimChapterMembers();
$this->variants = $this->normalizeVariants($draft['variants'] ?? []);
$this->durationMax = ($draft['duration_max'] ?? null) === null ? '' : (string) $draft['duration_max'];
$this->prerequisites = (string) ($draft['prerequisites'] ?? '');
@@ -1989,6 +2044,7 @@ protected function applyDraft(array $draft): void
protected function applyVersion(CompositionVersion $version): void
{
$this->members = app(EditorialCatalog::class)->rows($version, (int) $this->getRecord()->getKey());
+ $this->slimChapterMembers();
$this->variants = $this->normalizeVariants($version->variants->map(fn ($variant): array => [
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description, 'origin' => $variant->origin,
])->all());
@@ -2014,6 +2070,13 @@ protected function commitRoleDraft(?string $value = null): void
return;
}
+ if ($this->isDocument()) {
+ // Ein Kapitel hat keine freie Rolle: Die Ebene steht fest; offene Eingaben des Kapitels bleiben erhalten.
+ $this->stashChapter();
+
+ return;
+ }
+
$this->members[$this->selected]['role'] = trim($value ?? $this->roleDraft);
$this->members[$this->selected]['note'] = trim($this->noteDraft);
}
@@ -2023,6 +2086,13 @@ protected function syncRoleDraft(): void
$member = $this->selected !== null ? ($this->members[$this->selected] ?? null) : null;
$this->roleDraft = is_array($member) ? (string) ($member['role'] ?? '') : '';
$this->noteDraft = is_array($member) ? (string) ($member['note'] ?? '') : '';
+
+ if ($this->isDocument()) {
+ $this->loadChapterFields();
+
+ return;
+ }
+
$this->partTitle = is_array($member) ? (string) ($member['title'] ?? '') : '';
$this->partBody = is_array($member) ? (string) ($member['body'] ?? '') : '';
}
@@ -2340,6 +2410,8 @@ protected function payload(): array
'prerequisites' => $this->blank($this->prerequisites),
'variants' => $this->normalizeVariants($this->variants),
'revision_note' => $this->blank($this->revisionNote),
+ // Ungespeicherte Texte der Kapitel gelten als Änderung des Entwurfs; nach dem Speichern sind sie leer.
+ 'chapters' => $this->chapterEditsNow(),
'members' => array_values(array_map(
fn (array $member): array => [
'role' => trim((string) ($member['role'] ?? '')),
@@ -2442,6 +2514,7 @@ protected function normalizePayload(array $payload): array
'prerequisites' => $payload['prerequisites'] ?? null,
'variants' => $this->normalizeVariants($payload['variants'] ?? []),
'revision_note' => $payload['revision_note'] ?? null,
+ 'chapters' => is_array($payload['chapters'] ?? null) ? $payload['chapters'] : [],
'members' => $members,
];
}
diff --git a/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php b/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php
index bb89d40..3f96d74 100644
--- a/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php
+++ b/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php
@@ -34,12 +34,12 @@ protected function fixedKind(): ?CompositionKind
private function onDesk(): bool
{
- return in_array($this->kind(), [CompositionKind::Kurs, CompositionKind::Uebung, CompositionKind::Exercise], true);
+ return in_array($this->kind(), [CompositionKind::Kurs, CompositionKind::Uebung, CompositionKind::Exercise, CompositionKind::Document], true);
}
public function getSubheading(): string|Htmlable|null
{
- $desk = $this->onDesk() && $this->kind() !== CompositionKind::Exercise ? ' Programme und Module stehen gemeinsam auch auf dem Arbeitsplatz.' : '';
+ $desk = $this->onDesk() && ! in_array($this->kind(), [CompositionKind::Exercise, CompositionKind::Document], true) ? ' Programme und Module stehen gemeinsam auch auf dem Arbeitsplatz.' : '';
return $this->kind()->deskExplanation().$desk;
}
diff --git a/app/Filament/Resources/Documents/DocumentResource.php b/app/Filament/Resources/Documents/DocumentResource.php
new file mode 100644
index 0000000..9e9b3f9
--- /dev/null
+++ b/app/Filament/Resources/Documents/DocumentResource.php
@@ -0,0 +1,38 @@
+ ListDocuments::route('/'),
+ 'edit' => EditDocument::route('/{record}'),
+ ];
+ }
+}
diff --git a/app/Filament/Resources/Documents/Pages/EditDocument.php b/app/Filament/Resources/Documents/Pages/EditDocument.php
new file mode 100644
index 0000000..091ef43
--- /dev/null
+++ b/app/Filament/Resources/Documents/Pages/EditDocument.php
@@ -0,0 +1,11 @@
+selectRaw('MAX(id)')
->whereIn('status', [ContentVersionStatus::Bereit, ContentVersionStatus::Entwurf])
@@ -321,7 +322,7 @@ public function browse(string $query, string $kind, string $dimension, int $exce
}
}
- if (! $elementsOnly && in_array($kind, ['alle', 'modul'], true)) {
+ if (! $elementsOnly && in_array($kind, ['alle', 'modul', 'dokumentfassung'], true)) {
$latestCompositions = CompositionVersion::query()
->selectRaw('MAX(id)')
->where('status', ContentVersionStatus::Bereit)
@@ -331,6 +332,10 @@ public function browse(string $query, string $kind, string $dimension, int $exce
$builder->whereIn('kind', [CompositionKind::Uebung, CompositionKind::Exercise]);
}
+ if ($kind === 'dokumentfassung') {
+ $builder->where('kind', CompositionKind::Document);
+ }
+
if ($dimensionId > 0) {
$builder->whereIn('id', $this->dimensionSubjectIds(Composition::class, $dimensionId));
}
@@ -370,6 +375,8 @@ public function browse(string $query, string $kind, string $dimension, int $exce
$unreleased = Composition::query()
->where('id', '!=', $exceptCompositionId)
->whereNotNull('working_draft')
+ // Ein Dokument bindet man nur als bereitgestellte Fassung ein, nie als Entwurf.
+ ->where('kind', '!=', CompositionKind::Document->value)
->whereDoesntHave('versions', function ($builder): void {
$builder->where('status', ContentVersionStatus::Bereit);
})
@@ -1085,6 +1092,7 @@ public function create(string $designation, CompositionKind $kind): Composition
CompositionKind::Kurs => 'programm',
CompositionKind::Uebung => 'modul',
CompositionKind::Exercise => 'uebung',
+ CompositionKind::Document => 'dokument',
default => null,
};
$editorial = $slug === null ? null : EditorialContentKind::query()->where('slug', $slug)->first();
@@ -1107,6 +1115,7 @@ public static function editUrl(Composition $composition): string
CompositionKind::Kombination => CombinationResource::class,
CompositionKind::Uebung => ExerciseResource::class,
CompositionKind::Exercise => PracticeResource::class,
+ CompositionKind::Document => DocumentResource::class,
};
return $resource::getUrl('edit', ['record' => $composition]);
diff --git a/app/Filament/Support/ListsCompositions.php b/app/Filament/Support/ListsCompositions.php
index c22dc83..8820a76 100644
--- a/app/Filament/Support/ListsCompositions.php
+++ b/app/Filament/Support/ListsCompositions.php
@@ -78,6 +78,7 @@ public function bestand(): array
CompositionKind::Kurs => ['Programm', 'Programme'],
CompositionKind::Uebung => ['Modul', 'Module'],
CompositionKind::Exercise => ['Übung', 'Übungen'],
+ CompositionKind::Document => ['Dokument', 'Dokumente'],
CompositionKind::Kombination => ['Fachliche Kombination', 'Fachliche Kombinationen'],
default => ['Programm oder Modul', 'Programme und Module'],
};
@@ -118,6 +119,8 @@ public function bestand(): array
'text' => 'Mit „'.match ($fixed) {
CompositionKind::Kurs => 'Programm anlegen',
CompositionKind::Kombination => CompositionKind::Kombination->createLabel(),
+ CompositionKind::Exercise => 'Übung anlegen',
+ CompositionKind::Document => 'Dokument anlegen',
default => 'Modul anlegen',
}.'“ oben entsteht der erste Eintrag. Der Name genügt.',
],
@@ -247,12 +250,14 @@ protected function createCompositionAction(CompositionKind $kind): Action
$label = match ($kind) {
CompositionKind::Kurs => 'Programm',
CompositionKind::Exercise => 'Übung',
+ CompositionKind::Document => 'Dokument',
default => 'Modul',
};
return Action::make(match ($kind) {
CompositionKind::Kurs => 'createProgram',
CompositionKind::Exercise => 'createExercise',
+ CompositionKind::Document => 'createDocument',
default => 'createModule',
})
->label($label.' anlegen')
diff --git a/app/Filament/Support/ManagesDocumentChapters.php b/app/Filament/Support/ManagesDocumentChapters.php
new file mode 100644
index 0000000..2d2975d
--- /dev/null
+++ b/app/Filament/Support/ManagesDocumentChapters.php
@@ -0,0 +1,506 @@
+ Ungespeicherte Änderungen je Kapitel (Ziel => Titel und Text) */
+ public array $chapterEdits = [];
+
+ /** @var array Gespeicherter Text je Ziel, nur für den Vergleich innerhalb einer Anfrage */
+ private array $chapterBase = [];
+
+ public function isDocument(): bool
+ {
+ return $this->hostKind() === CompositionKind::Document;
+ }
+
+ /**
+ * Die Kapitelübersicht: Nummer, Ebene, Titel (auch ein noch nicht gespeicherter) und Stand je Kapitel.
+ *
+ * @return list
+ */
+ public function chapterRows(): array
+ {
+ $numbering = DocumentOutline::numbering(array_map(fn (array $member): string => (string) ($member['role'] ?? ''), $this->members));
+ $open = $this->openChapterEdit();
+ $rows = [];
+
+ foreach ($this->members as $index => $member) {
+ $target = (string) ($member['target'] ?? '');
+ $edit = $this->chapterEdits[$target] ?? null;
+ $title = $this->selected === $index && $open !== null ? $open['title'] : ($edit['title'] ?? (string) ($member['title'] ?? ''));
+ $rows[] = $numbering[$index] + [
+ 'index' => $index,
+ 'title' => trim($title) === '' ? 'Ohne Titel' : $title,
+ 'changed' => $edit !== null || ($this->selected === $index && $open !== null),
+ 'draft' => ($member['version_label'] ?? '') === 'Entwurf',
+ 'selected' => $this->selected === $index,
+ 'first' => $index === 0,
+ 'last' => $index === count($this->members) - 1,
+ ];
+ }
+
+ return $rows;
+ }
+
+ public function chapterCount(): int
+ {
+ return count($this->members);
+ }
+
+ /** Anzahl der Kapitel mit offenen Änderungen (gespeichert wird mit „Entwurf speichern“). */
+ public function chapterEditCount(): int
+ {
+ return count($this->chapterEditsNow());
+ }
+
+ /**
+ * Wechselt das Kapitel. Das verlassene bleibt mit seinen offenen Eingaben erhalten.
+ */
+ public function selectChapter(int $index): void
+ {
+ if (! isset($this->members[$index])) {
+ return;
+ }
+
+ $this->commitRoleDraft();
+ $this->selected = $index;
+ $this->panel = 'bestandteil';
+ $this->aufbauTab = 'aufbau';
+ $this->syncRoleDraft();
+ }
+
+ /** Legt das offene Kapitel in den Arbeitsstand, wenn es vom gespeicherten abweicht. */
+ protected function stashChapter(): void
+ {
+ $open = $this->openChapterEdit();
+ $target = $this->selectedChapterTarget();
+
+ if ($target === null) {
+ return;
+ }
+
+ if ($open === null) {
+ unset($this->chapterEdits[$target]);
+
+ return;
+ }
+
+ $this->chapterEdits[$target] = $open;
+ }
+
+ /**
+ * Das offene Kapitel, falls Titel oder Text vom gespeicherten Stand abweichen.
+ *
+ * @return array{title: string, body: string}|null
+ */
+ protected function openChapterEdit(): ?array
+ {
+ $target = $this->selectedChapterTarget();
+
+ if ($target === null) {
+ return null;
+ }
+
+ $title = trim($this->partTitle);
+ $body = FormattedText::canonical($this->partBody);
+ $storedTitle = trim((string) ($this->members[$this->selected]['title'] ?? ''));
+
+ if ($title === $storedTitle && FormattedText::same($body, $this->storedChapterBody($target))) {
+ return null;
+ }
+
+ return ['title' => $title, 'body' => $body];
+ }
+
+ /**
+ * Alle Änderungen, auch die des gerade offenen Kapitels.
+ *
+ * @return array
+ */
+ public function chapterEditsNow(): array
+ {
+ $edits = $this->chapterEdits;
+ $target = $this->selectedChapterTarget();
+
+ if ($target !== null) {
+ $open = $this->openChapterEdit();
+
+ if ($open === null) {
+ unset($edits[$target]);
+ } else {
+ $edits[$target] = $open;
+ }
+ }
+
+ ksort($edits);
+
+ return $edits;
+ }
+
+ private function selectedChapterTarget(): ?string
+ {
+ if (! $this->isDocument() || $this->selected === null || ! isset($this->members[$this->selected])) {
+ return null;
+ }
+
+ $target = (string) ($this->members[$this->selected]['target'] ?? '');
+
+ return preg_match('/^element:\d+$/', $target) === 1 ? $target : null;
+ }
+
+ private function storedChapterBody(string $target): string
+ {
+ if (! array_key_exists($target, $this->chapterBase)) {
+ $version = ContentElementVersion::query()->find((int) substr($target, 8));
+ $this->chapterBase[$target] = $version instanceof ContentElementVersion ? (string) $version->body : '';
+ }
+
+ return $this->chapterBase[$target];
+ }
+
+ /**
+ * Titel und Text des gewählten Kapitels in die Eingabefelder laden: zuerst die offenen Eingaben, sonst den gespeicherten Stand.
+ */
+ protected function loadChapterFields(): void
+ {
+ $target = $this->selectedChapterTarget();
+
+ if ($target === null) {
+ $this->partTitle = '';
+ $this->partBody = '';
+
+ return;
+ }
+
+ $edit = $this->chapterEdits[$target] ?? null;
+ $this->partTitle = $edit['title'] ?? (string) ($this->members[$this->selected]['title'] ?? '');
+ $this->partBody = $edit['body'] ?? FormattedText::canonical($this->storedChapterBody($target));
+ }
+
+ /**
+ * Schreibt die offenen Kapitel als Entwurfsfassungen und übernimmt sie in den Aufbau. Eine festgeschriebene Fassung
+ * bleibt unverändert; es entsteht eine neue Entwurfsfassung, die erst mit der Dokumentfassung bereitgestellt wird.
+ */
+ protected function persistChapterEdits(): bool
+ {
+ if (! $this->isDocument()) {
+ return true;
+ }
+
+ $this->stashChapter();
+
+ foreach ($this->chapterEdits as $target => $edit) {
+ if (trim($edit['title']) === '') {
+ $this->feedback = 'Jedes Kapitel braucht einen Titel.';
+ $this->selectTarget($target);
+
+ return false;
+ }
+ }
+
+ $service = app(ContentService::class);
+
+ foreach ($this->chapterEdits as $target => $edit) {
+ $index = $this->memberIndex($target);
+ $version = $index === null ? null : ContentElementVersion::query()->with('element')->find((int) substr($target, 8));
+
+ if ($index === null || ! $version instanceof ContentElementVersion || $version->element === null) {
+ continue;
+ }
+
+ try {
+ $service->describe($version->element, trim($edit['title']), $version->element->description);
+ $updated = $service->reviseElementDraft($version, $edit['body'] === '' ? '' : $edit['body']);
+ } catch (DomainRuleException $exception) {
+ $this->feedback = $exception->getMessage();
+
+ return false;
+ }
+
+ if ($updated->id !== $version->id) {
+ $row = app(EditorialCatalog::class)->rowForTarget('element:'.$updated->id, (int) $this->getRecord()->getKey(), allowSelf: true, allowDraft: true);
+
+ if ($row === null) {
+ $this->feedback = 'Die neue Fassung des Kapitels ließ sich nicht übernehmen.';
+
+ return false;
+ }
+
+ $this->members[$index] = [...$row, 'role' => (string) $this->members[$index]['role'], 'note' => (string) ($this->members[$index]['note'] ?? ''), ...$this->memberExtras($this->members[$index])];
+ } else {
+ $this->members[$index]['title'] = trim($edit['title']);
+ }
+ }
+
+ $this->chapterEdits = [];
+ $this->chapterBase = [];
+ $this->slimChapterMembers();
+ $this->syncRoleDraft();
+
+ return true;
+ }
+
+ /**
+ * Ein Kapitelmitglied trägt nur, was die Übersicht braucht. Der Text eines Kapitels liegt in der Datenbank und wird beim
+ * Öffnen gelesen; so bleibt der Zustand der Seite klein, auch bei einem Handbuch mit vielen Kapiteln (jede Anfrage sendet ihn).
+ */
+ protected function slimChapterMembers(): void
+ {
+ if (! $this->isDocument()) {
+ return;
+ }
+
+ foreach ($this->members as $index => $member) {
+ unset($this->members[$index]['body'], $this->members[$index]['summary'], $this->members[$index]['medium_description'], $this->members[$index]['usage_note'], $this->members[$index]['license_note']);
+ }
+ }
+
+ private function memberIndex(string $target): ?int
+ {
+ foreach ($this->members as $index => $member) {
+ if (($member['target'] ?? '') === $target) {
+ return $index;
+ }
+ }
+
+ return null;
+ }
+
+ private function selectTarget(string $target): void
+ {
+ $index = $this->memberIndex($target);
+
+ if ($index !== null) {
+ $this->selected = $index;
+ $this->syncRoleDraft();
+ }
+ }
+
+ /**
+ * Legt ein neues Kapitel (Ebene 1) oder Unterkapitel (Ebene 2) an. Es steht hinter dem gewählten Kapitel samt dessen
+ * Unterkapiteln beziehungsweise hinter dem gewählten Unterkapitel und ist sofort zum Schreiben geöffnet.
+ */
+ public function addChapter(int $level = 1): void
+ {
+ abort_unless($this->canEditEditorial(), 403);
+
+ if (($reason = $this->schreibschutz()) !== null) {
+ $this->feedback = $reason;
+
+ return;
+ }
+
+ $this->commitRoleDraft();
+ $level = $level >= 2 && $this->members !== [] ? 2 : 1;
+ $title = $level === 2 ? 'Neues Unterkapitel' : 'Neues Kapitel';
+
+ try {
+ $service = app(ContentService::class);
+ $element = $service->createElement('text', 'text', $title);
+ $version = $service->draftElementVersion($element, '');
+ /** @var Composition $document */
+ $document = $this->getRecord();
+ app(DocumentChapters::class)->mark($element, $document);
+ } catch (DomainRuleException $exception) {
+ $this->feedback = $exception->getMessage();
+
+ return;
+ }
+
+ $row = app(EditorialCatalog::class)->rowForTarget('element:'.$version->id, (int) $this->getRecord()->getKey(), allowSelf: true, allowDraft: true);
+
+ if ($row === null) {
+ $this->feedback = 'Das Kapitel ließ sich nicht anlegen.';
+
+ return;
+ }
+
+ $row['role'] = DocumentOutline::role($level);
+ $row['note'] = '';
+ $row = [...$row, ...$this->memberExtras([])];
+ unset($row['body'], $row['summary'], $row['medium_description'], $row['usage_note'], $row['license_note']);
+ $roles = array_map(fn (array $member): string => (string) ($member['role'] ?? ''), $this->members);
+ $at = count($this->members);
+
+ if ($this->selected !== null && isset($this->members[$this->selected])) {
+ $base = $this->selected;
+ $levels = array_column(DocumentOutline::numbering($roles), 'level');
+
+ // Ein neues Kapitel steht hinter dem ganzen gewählten Kapitel, ein Unterkapitel hinter dem gewählten Eintrag.
+ while ($level === 1 && $levels[$base] === 2 && $base > 0) {
+ $base--;
+ }
+
+ $at = DocumentOutline::blockEnd($roles, $base) + 1;
+ }
+
+ array_splice($this->members, $at, 0, [$row]);
+ $this->members = array_values($this->members);
+ $this->selected = $at;
+ $this->panel = 'bestandteil';
+ $this->syncRoleDraft();
+ $this->feedback = '„'.$title.'“ steht jetzt an Stelle '.($at + 1).'. Gib dem Kapitel einen Titel und schreibe den Text; gespeichert wird mit „Entwurf speichern“.';
+ }
+
+ /** Ändert die Ebene: Kapitel oder Unterkapitel. Das erste Kapitel bleibt immer ein Kapitel. */
+ public function setChapterLevel(int $index, int $level): void
+ {
+ if (! isset($this->members[$index])) {
+ return;
+ }
+
+ $this->commitRoleDraft();
+
+ if ($index === 0 && $level >= 2) {
+ $this->feedback = 'Das erste Kapitel bleibt ein Kapitel: Ein Unterkapitel braucht ein Kapitel davor.';
+
+ return;
+ }
+
+ $this->members[$index]['role'] = DocumentOutline::role($level);
+ $this->syncRoleDraft();
+ $this->feedback = '„'.$this->members[$index]['title'].'“ ist jetzt ein '.DocumentOutline::role($level).'. Die Nummern folgen der Reihenfolge. Gespeichert ist das erst mit „Entwurf speichern“.';
+ }
+
+ /** Verschiebt ein Kapitel mit seinen Unterkapiteln um eine Stelle; ein Unterkapitel wandert auch in das Nachbarkapitel. */
+ public function moveChapter(int $index, int $direction): void
+ {
+ $this->commitRoleDraft();
+
+ if (! isset($this->members[$index]) || ! in_array($direction, [-1, 1], true)) {
+ return;
+ }
+
+ $roles = array_map(fn (array $member): string => (string) ($member['role'] ?? ''), $this->members);
+ $levels = array_column(DocumentOutline::numbering($roles), 'level');
+ $end = DocumentOutline::blockEnd($roles, $index);
+ $after = null;
+
+ if ($levels[$index] === 1) {
+ if ($direction < 0) {
+ $previous = null;
+
+ for ($i = $index - 1; $i >= 0; $i--) {
+ if ($levels[$i] === 1) {
+ $previous = $i;
+ break;
+ }
+ }
+
+ $after = $previous === null ? null : $previous - 1;
+ } elseif (isset($this->members[$end + 1])) {
+ $after = DocumentOutline::blockEnd($roles, $end + 1);
+ }
+ } elseif ($direction < 0) {
+ if ($index > 0 && $levels[$index - 1] === 2) {
+ $after = $index - 2;
+ } elseif ($index - 1 > 0) {
+ // Das erste Unterkapitel wandert ans Ende des vorigen Kapitels.
+ $after = $index - 2;
+ }
+ } elseif (isset($levels[$index + 1])) {
+ // Hinter das nächste Unterkapitel, beziehungsweise als erstes Unterkapitel in das nächste Kapitel.
+ $after = $index + 1;
+ }
+
+ if ($after === null) {
+ $this->feedback = 'Weiter lässt sich dieses Kapitel nicht verschieben.';
+
+ return;
+ }
+
+ $this->relocate($index, $end, $after);
+ }
+
+ /** Ablegen per Ziehen: Der Block des gezogenen Kapitels wandert an die Stelle des Ziels. */
+ protected function moveChapterTo(int $from, int $to): void
+ {
+ $this->commitRoleDraft();
+
+ if (! isset($this->members[$from], $this->members[$to]) || $from === $to) {
+ return;
+ }
+
+ $roles = array_map(fn (array $member): string => (string) ($member['role'] ?? ''), $this->members);
+ $levels = array_column(DocumentOutline::numbering($roles), 'level');
+ $end = DocumentOutline::blockEnd($roles, $from);
+
+ if ($to >= $from && $to <= $end) {
+ return;
+ }
+
+ if ($levels[$from] === 1) {
+ // Ein Kapitel zieht man auf ein Kapitel; ein Unterkapitel als Ziel zählt als sein Kapitel.
+ while ($levels[$to] === 2 && $to > 0) {
+ $to--;
+ }
+
+ $after = $to < $from ? $to - 1 : DocumentOutline::blockEnd($roles, $to);
+ } else {
+ $after = $to < $from ? $to - 1 : $to;
+ }
+
+ $this->relocate($from, $end, $after);
+ }
+
+ /**
+ * Setzt den Block `$start..$end` hinter den Eintrag mit dem ursprünglichen Index `$after` (−1 = an den Anfang).
+ */
+ private function relocate(int $start, int $end, int $after): void
+ {
+ $selectedTarget = $this->selected !== null ? ($this->members[$this->selected]['target'] ?? null) : null;
+ $block = array_slice($this->members, $start, $end - $start + 1);
+ $position = 0;
+
+ foreach (array_keys($this->members) as $i) {
+ if ($i <= $after && ($i < $start || $i > $end)) {
+ $position++;
+ }
+ }
+
+ $rest = array_values(array_filter($this->members, fn (int $i): bool => $i < $start || $i > $end, ARRAY_FILTER_USE_KEY));
+ array_splice($rest, $position, 0, $block);
+ $this->members = $rest;
+
+ // Ein Unterkapitel am Anfang hätte kein Kapitel davor.
+ if (DocumentOutline::level((string) ($this->members[0]['role'] ?? '')) === 2) {
+ $this->members[0]['role'] = DocumentOutline::CHAPTER;
+ }
+
+ $this->selected = $this->memberIndex((string) $selectedTarget) ?? $this->selected;
+ $this->syncRoleDraft();
+ $this->feedback = 'Die Reihenfolge ist geändert. Die Nummern folgen ihr. Gespeichert ist das erst mit „Entwurf speichern“.';
+ }
+
+ /** Entfernt ein Kapitel aus dem Dokument; seine offenen Eingaben entfallen, der Text bleibt im Medienbestand. */
+ protected function forgetChapter(int $index): void
+ {
+ $target = (string) ($this->members[$index]['target'] ?? '');
+ unset($this->chapterEdits[$target]);
+ }
+}
diff --git a/app/Filament/Support/ManagesEditorialSurface.php b/app/Filament/Support/ManagesEditorialSurface.php
index af94bdd..9b11d77 100644
--- a/app/Filament/Support/ManagesEditorialSurface.php
+++ b/app/Filament/Support/ManagesEditorialSurface.php
@@ -755,7 +755,7 @@ public function pickerKinds(): array
}
if ($this->pickerPurpose === 'aufbau') {
- return ['alle' => 'Alle Inhalte', 'film' => 'Filme', 'bild' => 'Bilder', 'audio' => 'Hörstücke', 'dokument' => 'Dokumente', 'text' => 'Texte', 'modul' => 'Module'];
+ return ['alle' => 'Alle Inhalte', 'film' => 'Filme', 'bild' => 'Bilder', 'audio' => 'Hörstücke', 'dokument' => 'Dokumente', 'text' => 'Texte', 'modul' => 'Module', 'dokumentfassung' => 'Dokumente (Fassungen)'];
}
return ['alle' => 'Alle Medien', 'bild' => 'Bilder', 'film' => 'Filme', 'audio' => 'Hörstücke', 'dokument' => 'Dokumente'];
diff --git a/app/Http/Controllers/DocumentPreviewController.php b/app/Http/Controllers/DocumentPreviewController.php
new file mode 100644
index 0000000..fc8fbdb
--- /dev/null
+++ b/app/Http/Controllers/DocumentPreviewController.php
@@ -0,0 +1,86 @@
+authorizeStaff($composition);
+ $guide = $this->guide($composition);
+ $images = EmbeddedImages::staff();
+
+ foreach ($guide['chapters'] as $index => $chapter) {
+ $guide['chapters'][$index]['html'] = DocumentGuide::shiftHeadings(FormattedText::html($chapter['version']->body, $images));
+ }
+
+ return view('document.preview', ['guide' => $guide, 'composition' => $composition, 'pdfUrl' => route('editorial.document-preview.pdf', $composition)]);
+ }
+
+ public function pdf(Composition $composition): Response
+ {
+ $this->authorizeStaff($composition);
+ $content = app(DocumentPdf::class)->render($this->guide($composition), 'Vorschau der Redaktion', 'vorschau', EmbeddedImages::forStaffPdf());
+
+ return response($content, 200, [
+ 'Content-Type' => 'application/pdf',
+ 'Content-Disposition' => 'inline; filename="vorschau.pdf"',
+ 'Cache-Control' => 'private, no-store',
+ ]);
+ }
+
+ /**
+ * @return array
+ */
+ private function guide(Composition $composition): array
+ {
+ $chapters = app(DocumentReader::class)->forStaff($composition);
+ abort_if($chapters === null, 404);
+
+ foreach ($chapters as $index => $chapter) {
+ $chapters[$index] += [
+ 'allowed' => true,
+ 'grant' => null,
+ 'may_download' => true,
+ 'download_grant' => null,
+ 'state' => 'ok',
+ 'html' => null,
+ 'blocks' => FormattedText::blocks($chapter['version']->body),
+ ];
+ }
+
+ return [
+ 'title' => app(EditorialCatalog::class)->compositionTitle($composition),
+ 'summary_html' => FormattedText::html($composition->summary),
+ 'chapters' => $chapters,
+ ];
+ }
+
+ private function authorizeStaff(Composition $composition): void
+ {
+ $user = auth('staff')->user();
+ abort_unless(
+ $user instanceof User && ($user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter)),
+ 403,
+ );
+ abort_unless($composition->kind === CompositionKind::Document, 404);
+ }
+}
diff --git a/app/Http/Controllers/Member/DocumentController.php b/app/Http/Controllers/Member/DocumentController.php
new file mode 100644
index 0000000..108db8e
--- /dev/null
+++ b/app/Http/Controllers/Member/DocumentController.php
@@ -0,0 +1,97 @@
+load($request, $article, $release, $path);
+ $copy = DeliveryLog::newCopyId();
+ $shown = false;
+
+ foreach ($guide['chapters'] as $chapter) {
+ if ($chapter['allowed'] && $chapter['grant'] !== null) {
+ app(DeliveryLog::class)->write($chapter['grant'], $article, $release, $chapter['version'], 'ansehen', 'text', hash('sha256', (string) $chapter['version']->body), 'k2', $copy, $located['version']->id);
+ $shown = true;
+ }
+ }
+
+ return view('member.document', [
+ 'guide' => $guide,
+ 'reader' => $request->user()->name,
+ 'copy' => $shown ? $copy : null,
+ 'pdfUrl' => app(DocumentGuide::class)->pdfAllowed($guide) ? SignedLink::temporary('member.document.pdf', now()->addMinutes(10), [
+ 'article' => $article->id,
+ 'release' => $release->id,
+ 'path' => $path,
+ 'reader' => $request->user()->id,
+ ]) : null,
+ ]);
+ }
+
+ public function pdf(Request $request, LicenseArticle $article, ArticleRelease $release, string $path): Response
+ {
+ abort_unless((int) $request->query('reader') === $request->user()->id, 403);
+
+ [$guide, $located] = $this->load($request, $article, $release, $path);
+ abort_unless(app(DocumentGuide::class)->pdfAllowed($guide), 403, 'Für dieses PDF fehlt die Berechtigung für ein Kapitel.');
+
+ $copy = DeliveryLog::newCopyId();
+ $images = app(EmbeddedImages::class)->forPdf($request->user(), $article, $release);
+ $content = app(DocumentPdf::class)->render($guide, $request->user()->name, $copy, $images);
+ $checksum = hash('sha256', $content);
+
+ foreach ($guide['chapters'] as $chapter) {
+ $grant = $chapter['download_grant'] ?? $chapter['grant'];
+
+ if ($grant !== null) {
+ app(DeliveryLog::class)->write($grant, $article, $release, $chapter['version'], 'laden', 'pdf', $checksum, 'k2', $copy, $located['version']->id);
+ }
+ }
+
+ foreach ($images->used() as $image) {
+ app(DeliveryLog::class)->write($image['grant'], $article, $release, $image['version'], 'laden', 'pdf', $checksum, 'k2', $copy, $located['version']->id);
+ }
+
+ return response($content, 200, [
+ 'Content-Type' => 'application/pdf',
+ 'Content-Disposition' => 'attachment; filename="'.(str($guide['title'])->slug()->value() ?: 'dokument').'.pdf"',
+ 'X-License-Copy' => $copy,
+ 'Cache-Control' => 'private, no-store',
+ ]);
+ }
+
+ /**
+ * @return array{0: array, 1: array{version: CompositionVersion, selection: list|null}}
+ */
+ private function load(Request $request, LicenseArticle $article, ArticleRelease $release, string $path): array
+ {
+ $guides = app(ExerciseGuide::class);
+ abort_unless($guides->mayOpen($request->user(), $article, $release), 403);
+ $located = $guides->locate($release, $path, CompositionKind::Document);
+ abort_if($located === null, 404);
+
+ return [app(DocumentGuide::class)->build($request->user(), $article, $release, $located['version']), $located];
+ }
+}
diff --git a/app/Http/LibraryCatalog.php b/app/Http/LibraryCatalog.php
index 2e40ed6..ed380b9 100644
--- a/app/Http/LibraryCatalog.php
+++ b/app/Http/LibraryCatalog.php
@@ -380,6 +380,8 @@ private function present(User $user, StructureNode $node, bool $full, int $rootI
}
}
+ $document = $this->isDocument($node);
+ $documentUrl = $document ? $this->exerciseUrl($user, $rootId, $node) : null;
$title = $node->title;
if ($element !== null) {
@@ -396,10 +398,11 @@ private function present(User $user, StructureNode $node, bool $full, int $rootI
'kind' => $node->editorialKindLabel ?? $this->outputLabel($node->technicalKindLabel) ?? $node->technicalKindLabel,
'output_class' => $node->outputClass,
'playback' => $playback,
- 'view_url' => $view,
+ 'view_url' => $view ?? $documentUrl,
'poster_url' => $poster,
'download_url' => $download,
- 'program_url' => $this->exerciseUrl($user, $rootId, $node) ?? $this->programUrl($node),
+ 'program_url' => $documentUrl ?? $this->exerciseUrl($user, $rootId, $node) ?? $this->programUrl($node),
+ 'document' => $document,
'composition_id' => $node->compositionId,
'element_id' => $node->contentElementId,
'version_id' => $node->contentElementVersionId,
@@ -407,13 +410,20 @@ private function present(User $user, StructureNode $node, bool $full, int $rootI
'composition' => $rootId,
'version' => $node->contentElementVersionId,
]),
- 'children' => array_map(
+ // Ein Dokument steht als ein Eintrag da; seine Kapitel lesen Mitglieder im Dokument selbst.
+ 'children' => $document ? [] : array_map(
fn (StructureNode $child): array => $this->present($user, $child, $full, $rootId),
$node->children,
),
];
}
+ private function isDocument(StructureNode $node): bool
+ {
+ return $node->compositionId !== null
+ && Composition::query()->whereKey($node->compositionId)->where('kind', CompositionKind::Document->value)->exists();
+ }
+
/**
* @param list> $nodes
* @param list> $parents
@@ -513,8 +523,9 @@ private function exerciseUrl(User $user, int $rootId, StructureNode $node): ?str
}
$nested = CompositionVersion::query()->with('composition')->find($node->compositionVersionId);
+ $kind = $nested?->composition?->kind;
- if ($nested?->composition?->kind !== CompositionKind::Exercise) {
+ if (! in_array($kind, [CompositionKind::Exercise, CompositionKind::Document], true)) {
return null;
}
@@ -533,7 +544,7 @@ private function exerciseUrl(User $user, int $rootId, StructureNode $node): ?str
$path = $guide->pathTo($release->rootCompositionVersion, $nested->id);
if ($path !== null) {
- return route('member.exercise', ['article' => $grant->license_article_id, 'release' => $release->id, 'path' => $path]);
+ return route($kind === CompositionKind::Document ? 'member.document' : 'member.exercise', ['article' => $grant->license_article_id, 'release' => $release->id, 'path' => $path]);
}
}
}
diff --git a/database/migrations/2026_11_28_100000_add_documents.php b/database/migrations/2026_11_28_100000_add_documents.php
new file mode 100644
index 0000000..b1de4d7
--- /dev/null
+++ b/database/migrations/2026_11_28_100000_add_documents.php
@@ -0,0 +1,38 @@
+insertOrIgnore([
+ ['slug' => 'dokument', 'label' => 'Dokument', 'sort_order' => 27, 'is_active' => true, 'contexts' => json_encode(['dokument']), 'created_at' => $now, 'updated_at' => $now],
+ ['slug' => 'dokumentkapitel', 'label' => 'Dokumentkapitel', 'sort_order' => 28, 'is_active' => true, 'contexts' => json_encode([]), 'created_at' => $now, 'updated_at' => $now],
+ ]);
+ }
+
+ public function down(): void
+ {
+ DB::table('content_elements')
+ ->whereIn('editorial_content_kind_id', DB::table('editorial_content_kinds')->where('slug', 'dokumentkapitel')->select('id'))
+ ->update(['editorial_content_kind_id' => null]);
+ DB::table('compositions')
+ ->whereIn('editorial_content_kind_id', DB::table('editorial_content_kinds')->where('slug', 'dokument')->select('id'))
+ ->update(['editorial_content_kind_id' => null]);
+ DB::table('editorial_content_kinds')->whereIn('slug', ['dokument', 'dokumentkapitel'])->delete();
+ }
+};
diff --git a/resources/css/components/lf-member.css b/resources/css/components/lf-member.css
index b5884fc..745ec51 100644
--- a/resources/css/components/lf-member.css
+++ b/resources/css/components/lf-member.css
@@ -1830,3 +1830,102 @@ @media (max-width: 40rem) {
grid-column: 1 / -1;
}
}
+
+/* Dokument mit Inhaltsverzeichnis (ADR-51) */
+.mb-document {
+ max-width: 62rem;
+}
+
+.mb-doc {
+ display: grid;
+ gap: var(--space-5);
+}
+
+@media (min-width: 62rem) {
+ .mb-doc {
+ grid-template-columns: 17rem minmax(0, 1fr);
+ align-items: start;
+ }
+
+ .mb-doc-toc {
+ position: sticky;
+ top: var(--space-4);
+ max-height: calc(100vh - 2 * var(--space-4));
+ overflow-y: auto;
+ }
+}
+
+.mb-doc-toc {
+ padding: var(--pad-card);
+ border: 1px solid var(--color-border);
+ border-radius: var(--radius-card);
+ background: var(--color-surface-subtle);
+}
+
+.mb-doc-toc summary {
+ font-weight: 700;
+ cursor: pointer;
+}
+
+.mb-doc-toc ol {
+ display: grid;
+ gap: var(--space-1);
+ margin: var(--space-3) 0 0;
+ padding: 0;
+ list-style: none;
+}
+
+.mb-doc-toc a {
+ display: block;
+ padding: var(--space-1) 0;
+ color: var(--color-text);
+ text-decoration: none;
+}
+
+.mb-doc-toc a:hover,
+.mb-doc-toc a:focus-visible {
+ text-decoration: underline;
+}
+
+.mb-doc-toc-2 {
+ padding-left: var(--space-4);
+ font-size: 0.95em;
+}
+
+.mb-doc-nr {
+ display: inline-block;
+ min-width: 2.2ch;
+ color: var(--lf-green-deep);
+ font-variant-numeric: tabular-nums;
+ font-weight: 700;
+}
+
+.mb-doc-body {
+ display: grid;
+ gap: var(--space-5);
+ min-width: 0;
+}
+
+.mb-doc-chapter {
+ scroll-margin-top: var(--space-5);
+}
+
+.mb-doc-level-1 > h2 {
+ margin: 0 0 var(--space-3);
+ padding-bottom: var(--space-2);
+ border-bottom: 2px solid var(--color-accent);
+}
+
+.mb-doc-level-2 > h3 {
+ margin: 0 0 var(--space-2);
+}
+
+.mb-doc-chapter .mb-prose h4 {
+ margin: var(--space-4) 0 var(--space-2);
+ font-size: var(--text-body);
+}
+
+.mb-doc-up {
+ margin: var(--space-3) 0 0;
+ font-size: 0.9em;
+}
diff --git a/resources/views/document/preview.blade.php b/resources/views/document/preview.blade.php
new file mode 100644
index 0000000..1f1d6e3
--- /dev/null
+++ b/resources/views/document/preview.blade.php
@@ -0,0 +1,24 @@
+@extends('layouts.site')
+
+@section('title', 'Vorschau: '.$guide['title'])
+
+{{-- Vorschau eines Dokuments für die Redaktion: so sehen Mitglieder die Seite; das PDF liegt daneben. Nur für die Verwaltung. --}}
+@section('content')
+
+
Vorschau für die Redaktion. Gezeigt wird der gespeicherte Entwurf, sonst die letzte bereitgestellte Fassung. Ungespeicherte Änderungen im Editor erscheinen hier erst nach „Entwurf speichern“.
@include('filament.verwaltung.icon', ['name' => 'info'])„Entwurf speichern“ sichert Aufbau, Rollen, Hinweise und Didaktik. Freigegebene Fassungen bleiben unverändert, bis du eine neue Fassung freigibst. Texte und Präsentation bearbeitest du in der Redaktion.
+ @if ($dokument)
+
@include('filament.verwaltung.icon', ['name' => 'info'])„Entwurf speichern“ sichert Gliederung und Texte aller Kapitel. Bereitgestellte Dokumentfassungen bleiben unverändert, bis du eine neue Dokumentfassung bereitstellst. Titel, Beschreibung und Einordnung des Dokuments bearbeitest du in der Redaktion.
+ @else
+
@include('filament.verwaltung.icon', ['name' => 'info'])„Entwurf speichern“ sichert Aufbau, Rollen, Hinweise und Didaktik. Freigegebene Fassungen bleiben unverändert, bis du eine neue Fassung freigibst. Texte und Präsentation bearbeitest du in der Redaktion.
+ @endif
@foreach (array_unique(array_filter([$this->feedback, $this->deskFeedback])) as $meldung)
{{ $meldung }}
@@ -60,7 +65,7 @@
- @foreach (['aufbau' => 'Aufbau', 'angaben' => 'Didaktik und Katalogbild', 'verlauf' => 'Fassungen und Verwendung'] as $wert => $label)
+ @foreach (['aufbau' => $dokument ? 'Kapitel' : 'Aufbau', 'angaben' => $dokument ? 'Katalogbild' : 'Didaktik und Katalogbild', 'verlauf' => 'Fassungen und Verwendung'] as $wert => $label)