Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9041afda80 | ||
|
|
1691bd3871 | ||
|
|
1270e2e948 | ||
|
|
18ee22f37e | ||
|
|
edca8e864c | ||
|
|
580b27451c | ||
|
|
561c64fa16 | ||
|
|
3aed45a2fe | ||
|
|
e72c9ddb8d | ||
|
|
9f9370dbf8 | ||
|
|
b942b5331a | ||
|
|
58b68b768c | ||
|
|
765b8e779e | ||
|
|
81037b9868 | ||
|
|
8a44c5886b | ||
|
|
3e2fd872c2 | ||
|
|
c57a506f85 | ||
|
|
219962daff | ||
|
|
390d61feaa | ||
|
|
90c74ac03d | ||
|
|
b714dc8219 | ||
|
|
b7502ef696 | ||
|
|
45ea56b52d | ||
|
|
09889da099 | ||
|
|
3c7a71532f |
No files matched your search
@@ -66,6 +66,7 @@ ## Verwaltungsoberfläche
|
|||||||
- Maßgeblich sind `docs/ux/verwaltung/14-verwaltungsstandard.md` (Design und Interaktion) und `15-umbauauftrag.md` (Auftrag, Nachweise). Keine neue allgemeine Designabstimmung verlangen. Einstieg für alle Agenten: `AGENTS.md`, `.cursor/rules/verwaltung-ux.mdc`.
|
- Maßgeblich sind `docs/ux/verwaltung/14-verwaltungsstandard.md` (Design und Interaktion) und `15-umbauauftrag.md` (Auftrag, Nachweise). Keine neue allgemeine Designabstimmung verlangen. Einstieg für alle Agenten: `AGENTS.md`, `.cursor/rules/verwaltung-ux.mdc`.
|
||||||
- Gemeinsame Bausteine wiederverwenden statt neue Masken bauen: `resources/views/filament/verwaltung/` (`kopf`, `redaktion`, `texte`, `praesentation`, `einordnung`, `picker`, `bestaetigung`, `abgang`, `aufbau`, `bestand`) mit dem Trait `App\Filament\Support\ManagesEditorialSurface`. Listen nutzen `verwaltung/bestand` mit `ShowsBestand` (bzw. `ListsCompositions`, `ListsCatalog`) und den Eintrag `<x-vw.eintrag>`, den auch der Picker verwendet; Katalogobjekte die Seite `catalog/objekt`. CMS: Seitenkopf `cms/seite-kopf` (Register, Kontexte „Abschnitt gestalten“ und „Konfigurieren“); Seiten und Menüs in der Webpräsenz (`App\Filament\Pages\Webpraesenz`, Menüs als Arbeitsstand mit einer Speicherhandlung). Der Picker liegt im Trait `ChoosesMedia` (Redaktion über `ManagesEditorialSurface`, CMS-Bilder über `ChoosesWebsiteImages`); keine eigenen Auswahllisten für Medien bauen. Redaktionelle Auswahlwerte (Materialart, Einordnung) nur über `App\Domain\Catalog\EditorialVocabulary` anbieten und prüfen (aktiv, zulässiger Kontext, vorhandene Zuordnungen erhalten); gepflegt werden sie unter „Redaktionelle Stammdaten“. Fachliche Säulen gibt es nur in der Säulenverwaltung (`pillars`); Zuordnung über `PillarService::assign`, nie über eine Dimension. Ersetzt eine Seite die Filament-Tabelle, muss sie den Dialogbereich ausgeben (in `bestand` enthalten), sonst öffnen „… anlegen“-Dialoge nicht. Gestaltungswerte nur in `verwaltung/styles.blade.php` (Tokens `--vw-…`, dokumentiert in `docs/ux/verwaltung/tokens.md`).
|
- Gemeinsame Bausteine wiederverwenden statt neue Masken bauen: `resources/views/filament/verwaltung/` (`kopf`, `redaktion`, `texte`, `praesentation`, `einordnung`, `picker`, `bestaetigung`, `abgang`, `aufbau`, `bestand`) mit dem Trait `App\Filament\Support\ManagesEditorialSurface`. Listen nutzen `verwaltung/bestand` mit `ShowsBestand` (bzw. `ListsCompositions`, `ListsCatalog`) und den Eintrag `<x-vw.eintrag>`, den auch der Picker verwendet; Katalogobjekte die Seite `catalog/objekt`. CMS: Seitenkopf `cms/seite-kopf` (Register, Kontexte „Abschnitt gestalten“ und „Konfigurieren“); Seiten und Menüs in der Webpräsenz (`App\Filament\Pages\Webpraesenz`, Menüs als Arbeitsstand mit einer Speicherhandlung). Der Picker liegt im Trait `ChoosesMedia` (Redaktion über `ManagesEditorialSurface`, CMS-Bilder über `ChoosesWebsiteImages`); keine eigenen Auswahllisten für Medien bauen. Redaktionelle Auswahlwerte (Materialart, Einordnung) nur über `App\Domain\Catalog\EditorialVocabulary` anbieten und prüfen (aktiv, zulässiger Kontext, vorhandene Zuordnungen erhalten); gepflegt werden sie unter „Redaktionelle Stammdaten“. Fachliche Säulen gibt es nur in der Säulenverwaltung (`pillars`); Zuordnung über `PillarService::assign`, nie über eine Dimension. Ersetzt eine Seite die Filament-Tabelle, muss sie den Dialogbereich ausgeben (in `bestand` enthalten), sonst öffnen „… anlegen“-Dialoge nicht. Gestaltungswerte nur in `verwaltung/styles.blade.php` (Tokens `--vw-…`, dokumentiert in `docs/ux/verwaltung/tokens.md`).
|
||||||
- Formatierte Texte (ADR-50): gespeichert wird bereinigtes HTML aus fester Auswahl, bearbeitet mit dem einen Editor `App\Filament\Support\RichField`, in den Arbeitsplätzen über `ManagesRichFields` (`richFelder()`, `kind => 'rich'`). Ausgabe nur über `App\Domain\Catalog\FormattedText` (`html()`, `display()`, `plain()`, `blocks()` fürs PDF), nie ungeprüft; verglichen wird nur `FormattedText::same()`/`canonical()`. Klartext des Altbestands bleibt in der Datenbank, bis jemand ihn ändert. Keine eigenen Textfelder mit `textarea` für Texte, die formatiert sein sollen.
|
- Formatierte Texte (ADR-50): gespeichert wird bereinigtes HTML aus fester Auswahl, bearbeitet mit dem einen Editor `App\Filament\Support\RichField`, in den Arbeitsplätzen über `ManagesRichFields` (`richFelder()`, `kind => 'rich'`). Ausgabe nur über `App\Domain\Catalog\FormattedText` (`html()`, `display()`, `plain()`, `blocks()` fürs PDF), nie ungeprüft; verglichen wird nur `FormattedText::same()`/`canonical()`. Klartext des Altbestands bleibt in der Datenbank, bis jemand ihn ändert. Keine eigenen Textfelder mit `textarea` für Texte, die formatiert sein sollen.
|
||||||
- Mehrfachauswahl in Bestandslisten (Checkboxen, z. B. Materialarten im Medienmanager): Baustein `verwaltung/bestand-mehrfach`, die Häkchen sind mit `wire:model.live` an eine Liste gebunden (nie `wire:click` mit `@checked`: nach einer Serverantwort stimmt sonst die Anzeige nicht). Persönliche Standardfilter je Konto liegen in `user_view_defaults` (`UserViewDefault`). Texte, die für eine Übung angelegt werden, erhalten über `ExerciseSections::mark` die Materialart „Übungsabschnitt“ und den Verweis auf ihre Übung.
|
- Filter mit Mehrfachauswahl in Bestandslisten (z. B. Medienmanager): Baustein `verwaltung/bestand-filterdialog` über den Eintrag `filterdialog` in `bestand()` (Filterknopf neben der Suche, Pillen je wirksamem Feld, Dialog mit Entwurf der Auswahl: „Anwenden“ übernimmt, „Abbrechen“ verwirft). Mehrere Werte eines Felds gelten als ODER, verschiedene Felder als UND. Die Häkchen sind per `wire:model` an eine Liste im Entwurf gebunden (nie `wire:click` mit `@checked`: nach einer Serverantwort stimmt sonst die Anzeige nicht). Persönliche Standardfilter je Konto liegen in `user_view_defaults` (`UserViewDefault`). Texte, die für eine Übung angelegt werden, erhalten über `ExerciseSections::mark` die Materialart „Übungsabschnitt“ und den Verweis auf ihre Übung.
|
||||||
- Die Redaktion ist ein Arbeitsstand: nur „Redaktion speichern“ schreibt Texte, Einordnung, Präsentationsmedien und Abweichungen. Kein verdecktes Mitspeichern aus anderen Dialogen, offene Eingaben bleiben beim Wechsel erhalten.
|
- Die Redaktion ist ein Arbeitsstand: nur „Redaktion speichern“ schreibt Texte, Einordnung, Präsentationsmedien und Abweichungen. Kein verdecktes Mitspeichern aus anderen Dialogen, offene Eingaben bleiben beim Wechsel erhalten.
|
||||||
|
- Dokumente (ADR-51): Kapitel sind Texte, die Dokumentfassung ist eine Komposition (`CompositionKind::Document`); bearbeitet wird im Aufbaueditor über den Kapitelarbeitsplatz (`ManagesDocumentChapters`, `verwaltung/dokument`), ausgegeben über `DocumentGuide` (Seite) und `DocumentPdf`. Formatierte Texte mit Tabellen und Bildern laufen nur über `FormattedText`, `RichField` und `EmbeddedImages` (ein Bild ist ein Verweis auf eine Bildfassung, nie eine Adresse); PDF-Satz nur über `PdfFlow`. Änderungen an `PdfDocument` müssen die Prüfsummen in `tests/Unit/PdfDocumentTest.php` einhalten (Belege byte-gleich). Das Aussehen des Dokument-PDF (Titelseite, Kopf, Fuß) kommt aus der `PdfTemplate` (Seite `PdfVorlagen`); Inhalt wie Ausgabe, Datum und Vermerk gehört in `document_meta` der Dokumentfassung, nicht in die Vorlage.
|
||||||
- Jede UI-Änderung in der echten Anwendung prüfen (luf-test, breite und schmale Fenster, Tastatur) und mit Screenshots in `docs/ux/verwaltung/abnahme/` belegen. Stand der Abnahme: `abnahme/teil-a.md`, `abnahme/teil-b.md`, `abnahme/teil-c.md`, `abnahme/stammdaten.md`.
|
- Jede UI-Änderung in der echten Anwendung prüfen (luf-test, breite und schmale Fenster, Tastatur) und mit Screenshots in `docs/ux/verwaltung/abnahme/` belegen. Stand der Abnahme: `abnahme/teil-a.md`, `abnahme/teil-b.md`, `abnahme/teil-c.md`, `abnahme/stammdaten.md`.
|
||||||
@@ -25,6 +25,7 @@ class Composition extends Model
|
|||||||
'editorial_content_kind_id',
|
'editorial_content_kind_id',
|
||||||
'archived_at',
|
'archived_at',
|
||||||
'working_draft',
|
'working_draft',
|
||||||
|
'pdf_template_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
@@ -46,6 +47,12 @@ public function editorialContentKind(): BelongsTo
|
|||||||
return $this->belongsTo(EditorialContentKind::class);
|
return $this->belongsTo(EditorialContentKind::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Die PDF-Vorlage eines Dokuments; leer = bisheriges Layout (ADR-51). */
|
||||||
|
public function pdfTemplate(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(PdfTemplate::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function versions(): HasMany
|
public function versions(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(CompositionVersion::class);
|
return $this->hasMany(CompositionVersion::class);
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ enum CompositionKind: string
|
|||||||
case Kurs = 'kurs';
|
case Kurs = 'kurs';
|
||||||
/** Seit der Übungsverwaltung: die fachliche Übung. Der ältere Wert `uebung` bezeichnet in der Verwaltung das Modul. */
|
/** Seit der Übungsverwaltung: die fachliche Übung. Der ältere Wert `uebung` bezeichnet in der Verwaltung das Modul. */
|
||||||
case Exercise = 'exercise';
|
case Exercise = 'exercise';
|
||||||
|
/** Ein zusammenhängendes Dokument aus Kapiteln, zum Beispiel ein Trainerhandbuch (ADR-51). */
|
||||||
|
case Document = 'document';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return list<string>
|
* @return list<string>
|
||||||
@@ -25,6 +27,7 @@ public function label(): string
|
|||||||
self::Uebung => 'Modul',
|
self::Uebung => 'Modul',
|
||||||
self::Kurs => 'Kurs',
|
self::Kurs => 'Kurs',
|
||||||
self::Exercise => 'Übung',
|
self::Exercise => 'Übung',
|
||||||
|
self::Document => 'Dokument',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +38,7 @@ public function plural(): string
|
|||||||
self::Uebung => 'Module',
|
self::Uebung => 'Module',
|
||||||
self::Kurs => 'Kurse',
|
self::Kurs => 'Kurse',
|
||||||
self::Exercise => 'Übungen',
|
self::Exercise => 'Übungen',
|
||||||
|
self::Document => 'Dokumente',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +49,7 @@ public function createLabel(): string
|
|||||||
self::Uebung => 'Modul anlegen',
|
self::Uebung => 'Modul anlegen',
|
||||||
self::Kurs => 'Kurs anlegen',
|
self::Kurs => 'Kurs anlegen',
|
||||||
self::Exercise => 'Übung anlegen',
|
self::Exercise => 'Übung anlegen',
|
||||||
|
self::Document => 'Dokument anlegen',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +60,7 @@ public function explanation(): string
|
|||||||
self::Uebung => 'Eine konkrete Lernsituation, zum Beispiel aus Film und Merkblatt. Dieselben Medien können in mehreren Übungen stecken.',
|
self::Uebung => 'Eine konkrete Lernsituation, zum Beispiel aus Film und Merkblatt. Dieselben Medien können in mehreren Übungen stecken.',
|
||||||
self::Kurs => 'Ein Ablauf für den Kursbetrieb aus Übungen, Kombinationen und Medien. Ein Kurs ist keine Übung.',
|
self::Kurs => 'Ein Ablauf für den Kursbetrieb aus Übungen, Kombinationen und Medien. Ein Kurs ist keine Übung.',
|
||||||
self::Exercise => 'Eine Übung mit Lernziel, Vorbereitung, Durchführung und Varianten, mit Texten und Medien in fester Abfolge. Sie wird in Module und Programme aufgenommen.',
|
self::Exercise => 'Eine Übung mit Lernziel, Vorbereitung, Durchführung und Varianten, mit Texten und Medien in fester Abfolge. Sie wird in Module und Programme aufgenommen.',
|
||||||
|
self::Document => 'Ein zusammenhängendes Dokument, zum Beispiel ein Trainerhandbuch, aus Kapiteln und Unterkapiteln. Eine Fassung schreibt Reihenfolge und Texte fest; sie wird in Module und Programme aufgenommen und erscheint für Mitglieder mit Inhaltsverzeichnis und als PDF.',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +71,7 @@ public function deskLabel(): string
|
|||||||
self::Uebung => 'Modul',
|
self::Uebung => 'Modul',
|
||||||
self::Kurs => 'Programm',
|
self::Kurs => 'Programm',
|
||||||
self::Exercise => 'Übung',
|
self::Exercise => 'Übung',
|
||||||
|
self::Document => 'Dokument',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +81,7 @@ public function deskExplanation(): string
|
|||||||
self::Kombination => $this->explanation(),
|
self::Kombination => $this->explanation(),
|
||||||
self::Uebung => 'Ein Modul mit Lernziel, Zeit, Material und geordneten Bestandteilen. Dieselben Medien können in mehreren Modulen stecken.',
|
self::Uebung => 'Ein Modul mit Lernziel, Zeit, Material und geordneten Bestandteilen. Dieselben Medien können in mehreren Modulen stecken.',
|
||||||
self::Kurs => 'Ein Programm aus Modulen und weiteren Inhalten.',
|
self::Kurs => 'Ein Programm aus Modulen und weiteren Inhalten.',
|
||||||
self::Exercise => $this->explanation(),
|
self::Exercise, self::Document => $this->explanation(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -367,6 +367,7 @@ private function materialize(
|
|||||||
'duration_max' => $didactic['duration_max'] ?? null,
|
'duration_max' => $didactic['duration_max'] ?? null,
|
||||||
'material_note' => $didactic['material_note'] ?? null,
|
'material_note' => $didactic['material_note'] ?? null,
|
||||||
'prerequisites' => $didactic['prerequisites'] ?? null,
|
'prerequisites' => $didactic['prerequisites'] ?? null,
|
||||||
|
'document_meta' => $didactic['document_meta'] ?? null,
|
||||||
],
|
],
|
||||||
$variants,
|
$variants,
|
||||||
);
|
);
|
||||||
@@ -432,6 +433,7 @@ private function resolveTarget(string $target, ?User $actor, array $stack): Cont
|
|||||||
'duration_max' => $draft['duration_max'] ?? null,
|
'duration_max' => $draft['duration_max'] ?? null,
|
||||||
'material_note' => $draft['material_note'] ?? null,
|
'material_note' => $draft['material_note'] ?? null,
|
||||||
'prerequisites' => $draft['prerequisites'] ?? null,
|
'prerequisites' => $draft['prerequisites'] ?? null,
|
||||||
|
'document_meta' => $draft['document_meta'] ?? null,
|
||||||
],
|
],
|
||||||
$actor,
|
$actor,
|
||||||
is_string($draft['revision_note'] ?? null) ? $draft['revision_note'] : null,
|
is_string($draft['revision_note'] ?? null) ? $draft['revision_note'] : null,
|
||||||
|
|||||||
@@ -21,12 +21,14 @@ class CompositionVersion extends Model
|
|||||||
'prerequisites',
|
'prerequisites',
|
||||||
'structure_hash',
|
'structure_hash',
|
||||||
'source_snapshot_id',
|
'source_snapshot_id',
|
||||||
|
'document_meta',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'status' => ContentVersionStatus::class,
|
'status' => ContentVersionStatus::class,
|
||||||
|
'document_meta' => 'array',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public function expand(ContentElementVersion|CompositionVersion $node, string $p
|
|||||||
'path' => $path !== '' ? $path : $node->element->working_title,
|
'path' => $path !== '' ? $path : $node->element->working_title,
|
||||||
'requirement' => CompositionMember::REQUIRED,
|
'requirement' => CompositionMember::REQUIRED,
|
||||||
'variant' => null,
|
'variant' => null,
|
||||||
]];
|
], ...$this->embeddedImages($node, $path !== '' ? $path : $node->element->working_title, null)];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($node->composition_id, $stack, true)) {
|
if (in_array($node->composition_id, $stack, true)) {
|
||||||
@@ -51,6 +51,10 @@ public function expand(ContentElementVersion|CompositionVersion $node, string $p
|
|||||||
'variant' => $variantKey,
|
'variant' => $variantKey,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
foreach ($this->embeddedImages($member->contentElementVersion, $segment, $variantKey) as $image) {
|
||||||
|
$rows[] = $image;
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +83,34 @@ public function expand(ContentElementVersion|CompositionVersion $node, string $p
|
|||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bilder, auf die ein Text verweist, gehören zum Inhalt des Stands: Nur was im Stand steht, darf ein Mitglied sehen
|
||||||
|
* (`DecideAccess`), und eine Sperre des Bildes wirkt über denselben Weg. Ein fehlendes Bild macht den Text nicht
|
||||||
|
* unbrauchbar, daher „ergänzend“.
|
||||||
|
*
|
||||||
|
* @return list<array{version_id: int, role: string, path: string, requirement: string, variant: string|null}>
|
||||||
|
*/
|
||||||
|
private function embeddedImages(?ContentElementVersion $text, string $path, ?string $variantKey): array
|
||||||
|
{
|
||||||
|
if ($text === null || trim((string) $text->body) === '' || ! str_contains((string) $text->body, 'img')) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows = [];
|
||||||
|
|
||||||
|
foreach (FormattedText::imageIds($text->body) as $id) {
|
||||||
|
$rows[] = [
|
||||||
|
'version_id' => $id,
|
||||||
|
'role' => 'Bild',
|
||||||
|
'path' => $path.' / Bild',
|
||||||
|
'requirement' => CompositionMember::SUPPLEMENTARY,
|
||||||
|
'variant' => $variantKey,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
public function resolvedHash(ContentElementVersion|CompositionVersion $node): string
|
public function resolvedHash(ContentElementVersion|CompositionVersion $node): string
|
||||||
{
|
{
|
||||||
$ids = array_values(array_unique(array_column($this->expand($node), 'version_id')));
|
$ids = array_values(array_unique(array_column($this->expand($node), 'version_id')));
|
||||||
|
|||||||
@@ -164,6 +164,42 @@ public function reviseElementContent(ContentElementVersion $version, string $bod
|
|||||||
return $version->refresh();
|
return $version->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ändert den Text einer Fassung nur als Entwurf. Ist die Fassung schon festgeschrieben (in einer bereitgestellten
|
||||||
|
* Komposition oder einem Stand), entsteht eine neue Entwurfsfassung und die festgeschriebene bleibt unverändert.
|
||||||
|
* Anders als {@see self::reviseElementContent()} wird nichts bereitgestellt: Das geschieht erst mit der Fassung des
|
||||||
|
* Dokuments.
|
||||||
|
*/
|
||||||
|
public function reviseElementDraft(ContentElementVersion $version, string $body): ContentElementVersion
|
||||||
|
{
|
||||||
|
$body = trim($body);
|
||||||
|
|
||||||
|
if ($body === '') {
|
||||||
|
throw new DomainRuleException('Der Text braucht einen Inhalt.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$version->loadMissing('element');
|
||||||
|
|
||||||
|
if ($version->status === ContentVersionStatus::Gesperrt) {
|
||||||
|
throw new DomainRuleException('Eine deaktivierte Fassung lässt sich nicht ändern.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trim((string) $version->body) === $body) {
|
||||||
|
return $version;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($version->status === ContentVersionStatus::Entwurf) {
|
||||||
|
return $this->reviseElementContent($version, $body);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Eine bereitgestellte Fassung, die nirgends festgeschrieben ist, wird weiterhin an Ort und Stelle geändert.
|
||||||
|
if (! $this->isCommitted($version)) {
|
||||||
|
return $this->reviseElementContent($version, $body);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->draftElementVersion($version->element, $body);
|
||||||
|
}
|
||||||
|
|
||||||
public function elementReleaseProblem(ContentElementVersion $version): ?string
|
public function elementReleaseProblem(ContentElementVersion $version): ?string
|
||||||
{
|
{
|
||||||
$version->loadMissing('element');
|
$version->loadMissing('element');
|
||||||
@@ -190,6 +226,44 @@ public function elementReleaseProblem(ContentElementVersion $version): ?string
|
|||||||
return 'Der Text braucht einen Inhalt.';
|
return 'Der Text braucht einen Inhalt.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($version->element?->output_class === 'text') {
|
||||||
|
return $this->imageProblem((string) $version->body);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ein Text verweist auf Bildfassungen des Medienbestands. Festgeschrieben werden kann er nur, wenn jede davon
|
||||||
|
* vorhanden, ein Bild und freigegeben ist; sonst wäre die Ausgabe der Fassung nicht festgelegt.
|
||||||
|
*/
|
||||||
|
public function imageProblem(?string $body): ?string
|
||||||
|
{
|
||||||
|
$ids = FormattedText::imageIds($body);
|
||||||
|
|
||||||
|
if ($ids === []) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$versions = ContentElementVersion::query()->with('element')->whereKey($ids)->get()->keyBy('id');
|
||||||
|
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$image = $versions->get($id);
|
||||||
|
$title = $image?->element === null ? 'Bild' : (string) ($image->element->display_title ?: $image->element->working_title);
|
||||||
|
|
||||||
|
if ($image === null || $image->element === null || $image->element->output_class !== 'bild') {
|
||||||
|
return 'Der Text verweist auf ein Bild, das es nicht mehr gibt.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($image->status === ContentVersionStatus::Gesperrt) {
|
||||||
|
return 'Das Bild „'.$title.'“ ist deaktiviert und kann nicht festgeschrieben werden.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($image->status !== ContentVersionStatus::Bereit) {
|
||||||
|
return 'Das Bild „'.$title.'“ ist noch nicht freigegeben.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,6 +335,7 @@ public function publishComposition(
|
|||||||
'duration_max' => isset($didactic['duration_max']) ? (int) $didactic['duration_max'] : null,
|
'duration_max' => isset($didactic['duration_max']) ? (int) $didactic['duration_max'] : null,
|
||||||
'material_note' => $this->optionalText($didactic['material_note'] ?? null),
|
'material_note' => $this->optionalText($didactic['material_note'] ?? null),
|
||||||
'prerequisites' => $this->optionalText($didactic['prerequisites'] ?? null),
|
'prerequisites' => $this->optionalText($didactic['prerequisites'] ?? null),
|
||||||
|
'document_meta' => DocumentMeta::normalize($didactic['document_meta'] ?? null),
|
||||||
'source_snapshot_id' => isset($didactic['source_snapshot_id']) ? (int) $didactic['source_snapshot_id'] : null,
|
'source_snapshot_id' => isset($didactic['source_snapshot_id']) ? (int) $didactic['source_snapshot_id'] : null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -320,6 +395,8 @@ public function structureHash(CompositionVersion $version): string
|
|||||||
{
|
{
|
||||||
$version->loadMissing('members.variant', 'variants');
|
$version->loadMissing('members.variant', 'variants');
|
||||||
|
|
||||||
|
$meta = DocumentMeta::normalize($version->document_meta);
|
||||||
|
|
||||||
return hash('sha256', json_encode([
|
return hash('sha256', json_encode([
|
||||||
'fields' => [
|
'fields' => [
|
||||||
$version->learning_goal,
|
$version->learning_goal,
|
||||||
@@ -328,6 +405,8 @@ public function structureHash(CompositionVersion $version): string
|
|||||||
$version->material_note,
|
$version->material_note,
|
||||||
$version->prerequisites,
|
$version->prerequisites,
|
||||||
],
|
],
|
||||||
|
// Nur wenn gesetzt: Der Nachweis älterer Fassungen ohne Dokumentangaben bleibt unverändert.
|
||||||
|
...($meta === null ? [] : ['document' => $meta]),
|
||||||
'variants' => $version->variants->map(fn (CompositionVersionVariant $variant): array => [
|
'variants' => $version->variants->map(fn (CompositionVersionVariant $variant): array => [
|
||||||
$variant->key, $variant->position, $variant->name, $variant->description, $variant->origin,
|
$variant->key, $variant->position, $variant->name, $variant->description, $variant->origin,
|
||||||
])->all(),
|
])->all(),
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kapitel eines Dokuments: Textabschnitte im gemeinsamen Medienbestand mit der automatischen Materialart „Dokumentkapitel“
|
||||||
|
* und dem Verweis auf ihr Dokument (`origin_composition_id`), wie die Übungsabschnitte ({@see ExerciseSections}).
|
||||||
|
*/
|
||||||
|
final class DocumentChapters
|
||||||
|
{
|
||||||
|
public function kindId(): ?int
|
||||||
|
{
|
||||||
|
$id = EditorialContentKind::query()->where('slug', EditorialContentKind::DOCUMENT_CHAPTER_SLUG)->value('id');
|
||||||
|
|
||||||
|
return $id === null ? null : (int) $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mark(ContentElement $element, Composition $document): void
|
||||||
|
{
|
||||||
|
$element->origin_composition_id = $document->getKey();
|
||||||
|
|
||||||
|
if ($element->editorial_content_kind_id === null) {
|
||||||
|
$element->editorial_content_kind_id = $this->kindId();
|
||||||
|
}
|
||||||
|
|
||||||
|
$element->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use App\Domain\Entitlement\DecideAccess;
|
||||||
|
use App\Http\LibraryCatalog;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Das Dokument, wie ein Stand es festschreibt: die im Stand gebundene Dokumentfassung mit ihren Kapiteln und je Kapitel die
|
||||||
|
* Entscheidung der zentralen Rechteprüfung (`DecideAccess`). Ansicht und PDF lesen dieses Ergebnis; beide zeigen dieselbe
|
||||||
|
* Kapitelreihenfolge und dieselben gebundenen Textfassungen. Eine spätere Bearbeitung des Dokuments ändert einen älteren Stand
|
||||||
|
* nicht: Der Stand verweist auf die Fassung, die er festgeschrieben hat.
|
||||||
|
*/
|
||||||
|
class DocumentGuide
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly DecideAccess $access,
|
||||||
|
private readonly DocumentReader $reader,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function build(User $user, LicenseArticle $article, ArticleRelease $release, CompositionVersion $document): array
|
||||||
|
{
|
||||||
|
$document->loadMissing('composition');
|
||||||
|
$library = app(LibraryCatalog::class);
|
||||||
|
$embedded = app(EmbeddedImages::class);
|
||||||
|
$chapters = [];
|
||||||
|
|
||||||
|
foreach ($this->reader->fromVersion($document) as $chapter) {
|
||||||
|
$version = $chapter['version'];
|
||||||
|
$view = ($this->access)($user, $article, $release, $version, 'ansehen');
|
||||||
|
$download = ($this->access)($user, $article, $release, $version, 'laden');
|
||||||
|
|
||||||
|
$entry = [
|
||||||
|
'number' => $chapter['number'],
|
||||||
|
'level' => $chapter['level'],
|
||||||
|
'anchor' => $chapter['anchor'],
|
||||||
|
'title' => $chapter['title'],
|
||||||
|
'version' => $version,
|
||||||
|
'allowed' => $view->allowed,
|
||||||
|
'grant' => $view->grant,
|
||||||
|
'may_download' => $download->allowed,
|
||||||
|
'download_grant' => $download->grant,
|
||||||
|
'state' => $view->allowed ? 'ok' : ($version->status === ContentVersionStatus::Gesperrt ? 'gesperrt' : 'nicht_lizenziert'),
|
||||||
|
'html' => null,
|
||||||
|
'blocks' => $view->allowed ? FormattedText::blocks($version->body) : null,
|
||||||
|
];
|
||||||
|
$entry['html'] = $view->allowed ? self::anchoredHtml($entry, FormattedText::html($version->body, $embedded->forView($user, $article, $release, $version))) : null;
|
||||||
|
$chapters[] = self::withHeadings($entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
$text = $library->text($document->composition);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'document' => $document,
|
||||||
|
'title' => $text['title'],
|
||||||
|
'summary_html' => $text['summary_html'],
|
||||||
|
'pdf_template' => $document->composition->pdfTemplate,
|
||||||
|
'meta' => DocumentMeta::normalize($document->document_meta),
|
||||||
|
'chapters' => $chapters,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Um wie viele Stufen die Zwischenüberschriften eines Kapitels nach unten rücken: Im Kapitel (h2) bleiben h3 bis h6 wie
|
||||||
|
* geschrieben, unter einem Unterkapitel (h3) rücken sie eine Stufe tiefer (höchstens h6). So steht nie eine Überschrift
|
||||||
|
* des Texts auf der Stufe des Kapitels oder Unterkapitels, zu dem sie gehört.
|
||||||
|
*/
|
||||||
|
public static function headingShift(int $chapterLevel): int
|
||||||
|
{
|
||||||
|
return $chapterLevel >= 2 ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Das HTML eines Kapitels mit Sprungmarken an den Zwischenüberschriften und der Stufe, die zum Kapitel passt.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $chapter
|
||||||
|
*/
|
||||||
|
public static function anchoredHtml(array $chapter, string $html): string
|
||||||
|
{
|
||||||
|
return FormattedText::anchorHeadings($html, (string) $chapter['anchor'], self::headingShift((int) $chapter['level']))['html'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ergänzt ein Kapitel um seine Zwischenüberschriften (`headings`: Stufe, Text, Sprungmarke) für das Inhaltsverzeichnis und
|
||||||
|
* legt Stufe und Sprungmarke in die Überschriftenblöcke des PDF. Ansicht und PDF zählen gleich; sie lesen beide diese Liste.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $chapter
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public static function withHeadings(array $chapter): array
|
||||||
|
{
|
||||||
|
$shift = self::headingShift((int) $chapter['level']);
|
||||||
|
$headings = [];
|
||||||
|
$blocks = $chapter['blocks'] ?? null;
|
||||||
|
|
||||||
|
foreach (is_array($blocks) ? $blocks : [] as $index => $block) {
|
||||||
|
if ($block['type'] !== 'heading' || trim((string) ($block['text'] ?? '')) === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$level = min(6, (int) $block['level'] + $shift);
|
||||||
|
$anchor = $chapter['anchor'].'-u'.(count($headings) + 1);
|
||||||
|
$blocks[$index]['level'] = $level;
|
||||||
|
$blocks[$index]['anchor'] = $anchor;
|
||||||
|
$headings[] = ['level' => $level, 'text' => (string) $block['text'], 'anchor' => $anchor];
|
||||||
|
}
|
||||||
|
|
||||||
|
$chapter['blocks'] = is_array($blocks) ? $blocks : null;
|
||||||
|
$chapter['headings'] = $headings;
|
||||||
|
|
||||||
|
return $chapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Darf das PDF entstehen? Jedes Kapitel muss für `laden` zulässig sein; sonst fehlte ein Teil des Handbuchs.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $guide
|
||||||
|
*/
|
||||||
|
public function pdfAllowed(array $guide): bool
|
||||||
|
{
|
||||||
|
if ($guide['chapters'] === []) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($guide['chapters'] as $chapter) {
|
||||||
|
if (! $chapter['allowed'] || ! $chapter['may_download']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use Carbon\CarbonImmutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Angaben einer Dokumentfassung für Titelseite und Impressum des PDF: Untertitel, Ausgabe (Release), Veröffentlichungsdatum und
|
||||||
|
* Copyright-Vermerk. Sie liegen als Teil der Fassung in `composition_versions.document_meta` und ändern sich nur mit einer neuen
|
||||||
|
* Fassung. Alle Felder sind Klartext; ein leeres Feld entfällt.
|
||||||
|
*/
|
||||||
|
final class DocumentMeta
|
||||||
|
{
|
||||||
|
public const FIELDS = ['subtitle', 'edition', 'published_on', 'copyright'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bereinigte Angaben: nur die bekannten Felder, getrimmt, ohne leere Werte; ein Datum nur als `YYYY-MM-DD`. Null, wenn nichts gesetzt ist.
|
||||||
|
*
|
||||||
|
* @return array<string, string>|null
|
||||||
|
*/
|
||||||
|
public static function normalize(mixed $value): ?array
|
||||||
|
{
|
||||||
|
if (! is_array($value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$clean = [];
|
||||||
|
|
||||||
|
foreach (self::FIELDS as $field) {
|
||||||
|
$text = trim((string) ($value[$field] ?? ''));
|
||||||
|
|
||||||
|
if ($field === 'published_on') {
|
||||||
|
$text = preg_match('/^\d{4}-\d{2}-\d{2}$/', $text) === 1 ? $text : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($text !== '') {
|
||||||
|
$clean[$field] = mb_substr($text, 0, $field === 'copyright' ? 600 : 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $clean === [] ? null : $clean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Das Veröffentlichungsdatum in deutscher Schreibweise, oder leer. */
|
||||||
|
public static function publishedLabel(?array $meta): string
|
||||||
|
{
|
||||||
|
$date = $meta['published_on'] ?? '';
|
||||||
|
|
||||||
|
return $date === '' ? '' : CarbonImmutable::parse($date)->format('d.m.Y');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gliederung eines Dokuments (ADR-51). Ein Dokument ist eine flache Folge von Kapiteln; die Ebene steht in der Rolle des
|
||||||
|
* Mitglieds: „Kapitel“ (Ebene 1) oder „Unterkapitel“ (Ebene 2). Ein Unterkapitel gehört zum Kapitel davor. Die Nummern
|
||||||
|
* („3“, „3.2“) entstehen aus der Reihenfolge und werden nirgends gespeichert; Editor, Ansicht und PDF zählen gleich.
|
||||||
|
*/
|
||||||
|
final class DocumentOutline
|
||||||
|
{
|
||||||
|
public const CHAPTER = 'Kapitel';
|
||||||
|
|
||||||
|
public const SUBCHAPTER = 'Unterkapitel';
|
||||||
|
|
||||||
|
public static function level(?string $role): int
|
||||||
|
{
|
||||||
|
return trim((string) $role) === self::SUBCHAPTER ? 2 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function role(int $level): string
|
||||||
|
{
|
||||||
|
return $level >= 2 ? self::SUBCHAPTER : self::CHAPTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ebene und Nummer je Eintrag. Ein Unterkapitel ohne Kapitel davor zählt als Kapitel.
|
||||||
|
*
|
||||||
|
* @param list<string> $roles
|
||||||
|
* @return list<array{level: int, number: string, anchor: string}>
|
||||||
|
*/
|
||||||
|
public static function numbering(array $roles): array
|
||||||
|
{
|
||||||
|
$chapter = 0;
|
||||||
|
$sub = 0;
|
||||||
|
$out = [];
|
||||||
|
|
||||||
|
foreach ($roles as $role) {
|
||||||
|
$level = self::level($role);
|
||||||
|
|
||||||
|
if ($level === 2 && $chapter === 0) {
|
||||||
|
$level = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($level === 1) {
|
||||||
|
$chapter++;
|
||||||
|
$sub = 0;
|
||||||
|
$number = (string) $chapter;
|
||||||
|
} else {
|
||||||
|
$sub++;
|
||||||
|
$number = $chapter.'.'.$sub;
|
||||||
|
}
|
||||||
|
|
||||||
|
$out[] = ['level' => $level, 'number' => $number, 'anchor' => 'kapitel-'.str_replace('.', '-', $number)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Letzter Index des Blocks, den der Eintrag bei `$index` mit seinen Unterkapiteln bildet.
|
||||||
|
*
|
||||||
|
* @param list<string> $roles
|
||||||
|
*/
|
||||||
|
public static function blockEnd(array $roles, int $index): int
|
||||||
|
{
|
||||||
|
if (self::numbering($roles)[$index]['level'] === 2) {
|
||||||
|
return $index;
|
||||||
|
}
|
||||||
|
|
||||||
|
$end = $index;
|
||||||
|
|
||||||
|
for ($i = $index + 1; $i < count($roles); $i++) {
|
||||||
|
if (self::level($roles[$i]) !== 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$end = $i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $end;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,421 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use App\Domain\Commerce\Receipt\PdfDocument;
|
||||||
|
use App\Domain\Media\PdfImage;
|
||||||
|
use Closure;
|
||||||
|
use Transliterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Druckbare Ausgabe eines Dokuments (DIN A4) aus demselben Ergebnis wie die Ansicht ({@see DocumentGuide}): anklickbares
|
||||||
|
* Inhaltsverzeichnis samt Seitenzahlen, jedes Kapitel der ersten Ebene beginnt auf einer neuen Seite, Lesezeichen für die
|
||||||
|
* Gliederung des PDF-Betrachters. Fußzeile mit Lizenznehmer, Lizenzkopie und „Seite n von m“ auf jeder Seite (K2), die Kennung
|
||||||
|
* in den Metadaten (K1). Die Datei wird bei jedem Abruf neu erzeugt und nie abgelegt.
|
||||||
|
*
|
||||||
|
* Vorlage (ADR-51, Nachtrag): Ist dem Dokument eine {@see PdfTemplate} zugeordnet, steht der Titel allein auf einer eigenen
|
||||||
|
* Titelseite (mit Untertitel, Ausgabe, Veröffentlichungsdatum, Herausgeber und Copyright-Vermerk), und Kopf und Fuß aller
|
||||||
|
* weiteren Seiten tragen die gewählten Grafiken. Die Angaben kommen aus der Dokumentfassung ({@see DocumentMeta}). Ohne Vorlage
|
||||||
|
* beginnt das Inhaltsverzeichnis wie bisher unter dem Titel auf der ersten Seite.
|
||||||
|
*
|
||||||
|
* Seitenzahlen stehen erst nach dem Satz fest. Der Satz läuft deshalb so oft, bis Inhaltsverzeichnis, Kapitelanfänge und
|
||||||
|
* Seitenzahl sich nicht mehr ändern (in der Regel zweimal).
|
||||||
|
*/
|
||||||
|
class DocumentPdf
|
||||||
|
{
|
||||||
|
private const LEFT = 56.0;
|
||||||
|
|
||||||
|
private const RIGHT = 539.0;
|
||||||
|
|
||||||
|
private const PAGE_HEIGHT = 842.0;
|
||||||
|
|
||||||
|
private PdfDocument $pdf;
|
||||||
|
|
||||||
|
private PdfFlow $flow;
|
||||||
|
|
||||||
|
private int $page = 0;
|
||||||
|
|
||||||
|
private string $footer = '';
|
||||||
|
|
||||||
|
private int $total = 0;
|
||||||
|
|
||||||
|
private bool $onCover = false;
|
||||||
|
|
||||||
|
/** Das erste Kapitel setzt die Seite fort, statt eine neue zu beginnen (ohne Inhaltsverzeichnis). */
|
||||||
|
private bool $continueFirst = false;
|
||||||
|
|
||||||
|
/** Obere und untere Grenze des Textes, abhängig von den Grafiken der Vorlage. */
|
||||||
|
private float $top = 790.0;
|
||||||
|
|
||||||
|
private float $bottom = 72.0;
|
||||||
|
|
||||||
|
/** Höhe der Fußlinie über dem Seitenrand. */
|
||||||
|
private float $footerLine = 54.0;
|
||||||
|
|
||||||
|
/** @var array{header: ?array<string, mixed>, footer: ?array<string, mixed>, cover: ?array<string, mixed>} Grafiken samt Maßen, siehe {@see self::band()} */
|
||||||
|
private array $bands = ['header' => null, 'footer' => null, 'cover' => null];
|
||||||
|
|
||||||
|
/** @var array<string, array{page: int, top: float}> */
|
||||||
|
private array $starts = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $guide Ergebnis von {@see DocumentGuide::build}; `pdf_template` und `meta` sind optional
|
||||||
|
*/
|
||||||
|
public function render(array $guide, string $licensee, string $copyId, ?PdfImages $images = null): string
|
||||||
|
{
|
||||||
|
$template = ($guide['pdf_template'] ?? null) instanceof PdfTemplate ? $guide['pdf_template'] : null;
|
||||||
|
$this->prepareLayout($template);
|
||||||
|
$starts = [];
|
||||||
|
$total = 0;
|
||||||
|
$bytes = '';
|
||||||
|
|
||||||
|
for ($pass = 0; $pass < 5; $pass++) {
|
||||||
|
$bytes = $this->pass($guide, $template, $licensee, $copyId, $images, $starts, $total);
|
||||||
|
|
||||||
|
if ($this->starts === $starts && $this->total === $total) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$starts = $this->starts;
|
||||||
|
$total = $this->total;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bereitet die Grafiken der Vorlage auf und legt Ränder fest: Kopf und Fuß in voller Seitenbreite (höchstens 140 Punkt hoch),
|
||||||
|
* der Text beginnt unter dem Kopf und endet über dem Fuß.
|
||||||
|
*/
|
||||||
|
private function prepareLayout(?PdfTemplate $template): void
|
||||||
|
{
|
||||||
|
$this->bands = [
|
||||||
|
'header' => $this->band($template?->target('header'), 140.0, 'header', $template?->layout('header')),
|
||||||
|
'footer' => $this->band($template?->target('footer'), 140.0, 'footer', $template?->layout('footer')),
|
||||||
|
'cover' => $template !== null && $template->show_cover ? $this->band($template->target('cover'), self::PAGE_HEIGHT * 0.4, 'cover') : null,
|
||||||
|
];
|
||||||
|
$header = (float) ($this->bands['header']['occupied'] ?? 0);
|
||||||
|
$footer = (float) ($this->bands['footer']['occupied'] ?? 0);
|
||||||
|
$this->top = $header > 0 ? min(790.0, self::PAGE_HEIGHT - $header - 26.0) : 790.0;
|
||||||
|
$this->footerLine = max(54.0, $footer + 24.0);
|
||||||
|
$this->bottom = $this->footerLine + 18.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eine Grafik für Kopf, Fuß oder Titelseite. Als Band steht sie in Seitenbreite (bei zu großer Höhe verkleinert und zentriert),
|
||||||
|
* als Logo hat sie die gewählte Höhe und steht am linken oder rechten Textrand, höchstens halb so breit wie der Text.
|
||||||
|
* `occupied` ist die Höhe, die sie am Seitenrand belegt; `y` die Unterkante.
|
||||||
|
*
|
||||||
|
* @param array{align: string, height: int}|null $layout nur für Kopf und Fuß
|
||||||
|
* @return array{jpeg: string, pixelWidth: int, pixelHeight: int, width: float, height: float, x: float, y: float, occupied: float}|null
|
||||||
|
*/
|
||||||
|
private function band(?string $target, float $maxHeight, string $edge, ?array $layout = null): ?array
|
||||||
|
{
|
||||||
|
$bytes = TemplateImage::bytes($target);
|
||||||
|
$image = $bytes === null ? null : PdfImage::fromBytes($bytes);
|
||||||
|
|
||||||
|
if ($image === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ratio = $image['width'] / max(1, $image['height']);
|
||||||
|
$align = $layout['align'] ?? 'full';
|
||||||
|
$common = ['jpeg' => $image['jpeg'], 'pixelWidth' => $image['width'], 'pixelHeight' => $image['height']];
|
||||||
|
|
||||||
|
if ($edge !== 'cover' && $align !== 'full') {
|
||||||
|
$height = (float) ($layout['height'] ?? PdfTemplate::LOGO_DEFAULT);
|
||||||
|
$width = $height * $ratio;
|
||||||
|
|
||||||
|
if ($width > (self::RIGHT - self::LEFT) / 2) {
|
||||||
|
$width = (self::RIGHT - self::LEFT) / 2;
|
||||||
|
$height = $width / $ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
$padding = $edge === 'header' ? 24.0 : 14.0;
|
||||||
|
|
||||||
|
return $common + [
|
||||||
|
'width' => $width,
|
||||||
|
'height' => $height,
|
||||||
|
'x' => $align === 'left' ? self::LEFT : self::RIGHT - $width,
|
||||||
|
'y' => $edge === 'header' ? self::PAGE_HEIGHT - $padding - $height : $padding,
|
||||||
|
'occupied' => $height + $padding,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$width = (float) PdfDocument::WIDTH;
|
||||||
|
$height = $width / $ratio;
|
||||||
|
|
||||||
|
if ($height > $maxHeight) {
|
||||||
|
$height = $maxHeight;
|
||||||
|
$width = $height * $ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $common + [
|
||||||
|
'width' => $width,
|
||||||
|
'height' => $height,
|
||||||
|
'x' => (PdfDocument::WIDTH - $width) / 2,
|
||||||
|
'y' => $edge === 'header' ? self::PAGE_HEIGHT - $height : 0.0,
|
||||||
|
'occupied' => $height,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $guide
|
||||||
|
* @param array<string, array{page: int, top: float}> $known Kapitelanfänge aus dem vorigen Durchgang
|
||||||
|
*/
|
||||||
|
private function pass(array $guide, ?PdfTemplate $template, string $licensee, string $copyId, ?PdfImages $images, array $known, int $total): string
|
||||||
|
{
|
||||||
|
$this->pdf = new PdfDocument;
|
||||||
|
$this->page = 0;
|
||||||
|
$this->starts = [];
|
||||||
|
$this->onCover = false;
|
||||||
|
$this->footer = PdfFlow::printable('Lizenziert für '.$licensee.' · Lizenzkopie '.$copyId);
|
||||||
|
$this->flow = new PdfFlow($this->pdf, self::LEFT, self::RIGHT, $this->top, $this->bottom, function (): void {
|
||||||
|
$this->closePage();
|
||||||
|
$this->newPage();
|
||||||
|
}, $images === null ? null : Closure::fromCallable($images));
|
||||||
|
$this->flow->onHeading = function (array $block, float $top): void {
|
||||||
|
$this->starts[$block['anchor']] = ['page' => $this->page, 'top' => $top];
|
||||||
|
$this->pdf->bookmark((string) $block['text'], $this->page - 1, $top, (int) $block['level'] - 1);
|
||||||
|
};
|
||||||
|
$this->total = $total;
|
||||||
|
$withCover = $template !== null && $template->show_cover;
|
||||||
|
|
||||||
|
if ($withCover) {
|
||||||
|
$this->onCover = true;
|
||||||
|
$this->newPage();
|
||||||
|
$this->cover($guide, $template);
|
||||||
|
$this->closePage();
|
||||||
|
$this->onCover = false;
|
||||||
|
$this->newPage();
|
||||||
|
} else {
|
||||||
|
$this->newPage();
|
||||||
|
$this->flow->write(PdfFlow::printable((string) $guide['title']), 24, true, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
$setting = PdfTemplate::normalizeToc($template?->toc_mode, $template?->toc_depth);
|
||||||
|
$entries = $this->contents($guide, $setting['depth']);
|
||||||
|
$withContents = match ($setting['mode']) {
|
||||||
|
'never' => false,
|
||||||
|
'always' => true,
|
||||||
|
default => count($entries) > 1,
|
||||||
|
};
|
||||||
|
$this->continueFirst = ! $withContents;
|
||||||
|
|
||||||
|
if ($withContents) {
|
||||||
|
$this->flow->write('Inhaltsverzeichnis', 14, true, 8, keep: 40);
|
||||||
|
|
||||||
|
foreach ($entries as $entry) {
|
||||||
|
$this->contentsLine($entry, $known[$entry['anchor']] ?? ['page' => 1, 'top' => $this->top]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($guide['chapters'] as $chapter) {
|
||||||
|
$this->chapter($chapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->closePage();
|
||||||
|
$total = $this->page;
|
||||||
|
$starts = $this->starts;
|
||||||
|
$bytes = $this->pdf->output($this->asciiTitle((string) $guide['title']), 'Lizenzkopie '.$copyId);
|
||||||
|
$this->total = $total;
|
||||||
|
$this->starts = $starts;
|
||||||
|
|
||||||
|
return $bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Titelseite: Bild (falls gewählt), Titel allein, Untertitel, dann Ausgabe, Veröffentlichung und Herausgeber, unten der
|
||||||
|
* Copyright-Vermerk. Die Vermerke der Fassung gehen dem Standard der Vorlage vor.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $guide
|
||||||
|
*/
|
||||||
|
private function cover(array $guide, PdfTemplate $template): void
|
||||||
|
{
|
||||||
|
$meta = is_array($guide['meta'] ?? null) ? $guide['meta'] : [];
|
||||||
|
$y = self::PAGE_HEIGHT - 150.0;
|
||||||
|
|
||||||
|
if ($this->bands['cover'] !== null) {
|
||||||
|
$cover = $this->bands['cover'];
|
||||||
|
$this->pdf->image($cover['x'], self::PAGE_HEIGHT - $cover['height'], $cover['width'], $cover['height'], $cover['jpeg'], $cover['pixelWidth'], $cover['pixelHeight']);
|
||||||
|
$y = self::PAGE_HEIGHT - $cover['height'] - 90.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->coverText(PdfFlow::printable((string) $guide['title']), 30.0, true, $y, 12.0);
|
||||||
|
|
||||||
|
if (filled($meta['subtitle'] ?? null)) {
|
||||||
|
$this->coverText(PdfFlow::printable((string) $meta['subtitle']), 15.0, false, $y, 8.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$y -= 26.0;
|
||||||
|
$facts = array_filter([
|
||||||
|
filled($meta['edition'] ?? null) ? $meta['edition'] : null,
|
||||||
|
DocumentMeta::publishedLabel($meta) !== '' ? 'Veröffentlicht am '.DocumentMeta::publishedLabel($meta) : null,
|
||||||
|
filled($template->publisher) ? 'Herausgeber: '.$template->publisher : null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach ($facts as $fact) {
|
||||||
|
$this->coverText(PdfFlow::printable((string) $fact), 11.0, false, $y, 4.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$copyright = trim((string) ($meta['copyright'] ?? '')) !== '' ? (string) $meta['copyright'] : (string) $template->copyright;
|
||||||
|
|
||||||
|
if (trim($copyright) !== '') {
|
||||||
|
$lines = PdfDocument::wrap(PdfFlow::printable($copyright), self::RIGHT - self::LEFT, 8.5, false);
|
||||||
|
$at = $this->footerLine + 24.0 + (count($lines) - 1) * 12.0;
|
||||||
|
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
$this->pdf->text(self::LEFT, $at, $line, 8.5);
|
||||||
|
$at -= 12.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function coverText(string $text, float $size, bool $bold, float &$y, float $after): void
|
||||||
|
{
|
||||||
|
foreach (PdfDocument::wrap($text, self::RIGHT - self::LEFT, $size, $bold) as $line) {
|
||||||
|
$this->pdf->text(self::LEFT, $y, $line, $size, $bold);
|
||||||
|
$y -= $size + 6.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$y -= $after;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Einträge des Inhaltsverzeichnisses in der Reihenfolge des Dokuments: Kapitel und Unterkapitel mit Nummer, darunter
|
||||||
|
* ihre Zwischenüberschriften (h3 bis h6) bis zur gewählten Tiefe, eingerückt nach Stufe. Die Lesezeichen im PDF zeigen
|
||||||
|
* unabhängig davon alle Ebenen.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $guide
|
||||||
|
* @param int $depth höchste Überschriftenstufe im Verzeichnis (2 = nur Kapitel)
|
||||||
|
* @return list<array{anchor: string, label: string, size: float, indent: float, bold: bool}>
|
||||||
|
*/
|
||||||
|
private function contents(array $guide, int $depth = 6): array
|
||||||
|
{
|
||||||
|
$entries = [];
|
||||||
|
|
||||||
|
foreach ($guide['chapters'] as $chapter) {
|
||||||
|
$entries[] = [
|
||||||
|
'anchor' => $chapter['anchor'],
|
||||||
|
'label' => $chapter['number'].' '.$chapter['title'],
|
||||||
|
'size' => $chapter['level'] === 1 ? 11.0 : 10.0,
|
||||||
|
'indent' => $chapter['level'] === 1 ? 0.0 : 18.0,
|
||||||
|
'bold' => $chapter['level'] === 1,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($chapter['headings'] ?? [] as $heading) {
|
||||||
|
if ($heading['level'] > $depth) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$entries[] = ['anchor' => $heading['anchor'], 'label' => $heading['text'], 'size' => 9.5, 'indent' => 18.0 + ($heading['level'] - 3) * 12.0, 'bold' => false];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eine Zeile des Inhaltsverzeichnisses: Titel, Punktlinie, Seitenzahl; die ganze Zeile springt zum Eintrag.
|
||||||
|
*
|
||||||
|
* @param array{anchor: string, label: string, size: float, indent: float, bold: bool} $entry
|
||||||
|
* @param array{page: int, top: float} $target
|
||||||
|
*/
|
||||||
|
private function contentsLine(array $entry, array $target): void
|
||||||
|
{
|
||||||
|
$size = $entry['size'];
|
||||||
|
$indent = $entry['indent'];
|
||||||
|
$bold = $entry['bold'];
|
||||||
|
$label = PdfFlow::printable($entry['label']);
|
||||||
|
$pageText = (string) $target['page'];
|
||||||
|
$numberWidth = PdfDocument::exactWidth($pageText, $size, false);
|
||||||
|
$lines = PdfDocument::wrap($label, self::RIGHT - self::LEFT - $indent - $numberWidth - 14, $size, $bold);
|
||||||
|
$x = self::LEFT + $indent;
|
||||||
|
$this->flow->room(count($lines) * ($size + 4) + 2);
|
||||||
|
$top = $this->flow->y;
|
||||||
|
|
||||||
|
foreach ($lines as $index => $line) {
|
||||||
|
$this->pdf->text($x, $this->flow->y, $line, $size, $bold);
|
||||||
|
|
||||||
|
if ($index === count($lines) - 1) {
|
||||||
|
$used = PdfDocument::exactWidth($line, $size, $bold) + 4;
|
||||||
|
$room = self::RIGHT - $numberWidth - 4 - ($x + $used);
|
||||||
|
$dots = (int) floor($room / PdfDocument::exactWidth('.', 8, false));
|
||||||
|
|
||||||
|
if ($dots > 2) {
|
||||||
|
$this->pdf->text($x + $used, $this->flow->y, str_repeat('.', $dots), 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pdf->textRight(self::RIGHT, $this->flow->y, $pageText, $size);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->flow->y -= $size + 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pdf->link(self::LEFT, $this->flow->y + 2, self::RIGHT - self::LEFT, $top - $this->flow->y, max(0, $target['page'] - 1), $target['top']);
|
||||||
|
$this->flow->y -= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $chapter
|
||||||
|
*/
|
||||||
|
private function chapter(array $chapter): void
|
||||||
|
{
|
||||||
|
$level = $chapter['level'];
|
||||||
|
|
||||||
|
if ($level === 1 && ! $this->continueFirst) {
|
||||||
|
$this->closePage();
|
||||||
|
$this->newPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->continueFirst = false;
|
||||||
|
$size = $level === 1 ? 18.0 : 13.5;
|
||||||
|
$title = PdfFlow::printable($chapter['number'].' '.$chapter['title']);
|
||||||
|
$this->flow->room(($size + 4) + 60);
|
||||||
|
$top = $this->flow->y + $size;
|
||||||
|
$this->starts[$chapter['anchor']] = ['page' => $this->page, 'top' => $top];
|
||||||
|
$this->pdf->bookmark($chapter['number'].' '.$chapter['title'], $this->page - 1, $top, $level);
|
||||||
|
$this->flow->y -= $level === 1 ? 0 : 6;
|
||||||
|
$this->flow->write($title, $size, true, $level === 1 ? 10 : 5, keep: 40);
|
||||||
|
|
||||||
|
if (! $chapter['allowed']) {
|
||||||
|
$this->flow->write('Dieses Kapitel ist derzeit nicht verfügbar.', 10.5, false, 6);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->flow->formatted($chapter['blocks'] ?? []);
|
||||||
|
$this->flow->y -= 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function newPage(): void
|
||||||
|
{
|
||||||
|
$this->pdf->addPage();
|
||||||
|
$this->page++;
|
||||||
|
$this->flow->restart();
|
||||||
|
|
||||||
|
if (! $this->onCover && $this->bands['header'] !== null) {
|
||||||
|
$band = $this->bands['header'];
|
||||||
|
$this->pdf->image($band['x'], $band['y'], $band['width'], $band['height'], $band['jpeg'], $band['pixelWidth'], $band['pixelHeight']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function closePage(): void
|
||||||
|
{
|
||||||
|
if (! $this->onCover && $this->bands['footer'] !== null) {
|
||||||
|
$band = $this->bands['footer'];
|
||||||
|
$this->pdf->image($band['x'], $band['y'], $band['width'], $band['height'], $band['jpeg'], $band['pixelWidth'], $band['pixelHeight']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pdf->line(self::LEFT, $this->footerLine, self::RIGHT, $this->footerLine, 0.4);
|
||||||
|
$this->pdf->text(self::LEFT, $this->footerLine - 14.0, $this->footer, 8);
|
||||||
|
$this->pdf->textRight(self::RIGHT, $this->footerLine - 14.0, 'Seite '.$this->page.($this->total > 0 ? ' von '.$this->total : ''), 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function asciiTitle(string $title): string
|
||||||
|
{
|
||||||
|
$ascii = Transliterator::create('Any-Latin; Latin-ASCII');
|
||||||
|
|
||||||
|
return $ascii?->transliterate($title) ?: 'Dokument';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liest die Kapitel eines Dokuments in ihrer Reihenfolge: aus einer Fassung (gebundene Textfassungen) oder aus dem
|
||||||
|
* gespeicherten Entwurf (jeweils verwiesene Fassung). Ansicht, PDF und Vorschau zählen dadurch dieselben Kapitel und
|
||||||
|
* Nummern ({@see DocumentOutline}).
|
||||||
|
*/
|
||||||
|
final class DocumentReader
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return list<array{number: string, level: int, anchor: string, role: string, title: string, version: ContentElementVersion}>
|
||||||
|
*/
|
||||||
|
public function fromVersion(CompositionVersion $document): array
|
||||||
|
{
|
||||||
|
$document->loadMissing('members.contentElementVersion.element');
|
||||||
|
$items = [];
|
||||||
|
|
||||||
|
foreach ($document->members as $member) {
|
||||||
|
if ($member->contentElementVersion !== null) {
|
||||||
|
$items[] = ['role' => (string) $member->role, 'version' => $member->contentElementVersion];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->number($items);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Der gespeicherte Entwurf; ohne Entwurf die letzte bereitgestellte Fassung. Null, wenn beides fehlt.
|
||||||
|
*
|
||||||
|
* @return list<array{number: string, level: int, anchor: string, role: string, title: string, version: ContentElementVersion}>|null
|
||||||
|
*/
|
||||||
|
public function forStaff(Composition $document): ?array
|
||||||
|
{
|
||||||
|
$draft = app(EditorialWorkingDraft::class)->read($document);
|
||||||
|
|
||||||
|
if ($draft === null) {
|
||||||
|
$ready = $document->versions()->where('status', ContentVersionStatus::Bereit)->orderByDesc('number')->first();
|
||||||
|
|
||||||
|
return $ready instanceof CompositionVersion ? $this->fromVersion($ready) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$items = [];
|
||||||
|
|
||||||
|
foreach (is_array($draft['members'] ?? null) ? $draft['members'] : [] as $member) {
|
||||||
|
if (! is_array($member) || preg_match('/^element:(\d+)$/', (string) ($member['target'] ?? ''), $match) !== 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = ContentElementVersion::query()->with('element')->find($match[1]);
|
||||||
|
|
||||||
|
if ($version instanceof ContentElementVersion && $version->element !== null) {
|
||||||
|
$items[] = ['role' => (string) ($member['role'] ?? ''), 'version' => $version];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->number($items);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function title(ContentElementVersion $version): string
|
||||||
|
{
|
||||||
|
$element = $version->element;
|
||||||
|
|
||||||
|
return $element === null ? 'Kapitel' : (filled($element->display_title) ? (string) $element->display_title : (string) $element->working_title);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<array{role: string, version: ContentElementVersion}> $items
|
||||||
|
* @return list<array{number: string, level: int, anchor: string, role: string, title: string, version: ContentElementVersion}>
|
||||||
|
*/
|
||||||
|
private function number(array $items): array
|
||||||
|
{
|
||||||
|
$numbering = DocumentOutline::numbering(array_column($items, 'role'));
|
||||||
|
|
||||||
|
return array_map(fn (array $item, array $number): array => $number + [
|
||||||
|
'role' => DocumentOutline::role($number['level']),
|
||||||
|
'title' => self::title($item['version']),
|
||||||
|
'version' => $item['version'],
|
||||||
|
], $items, $numbering);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ class EditorialContentKind extends Model
|
|||||||
'medium' => 'Medium',
|
'medium' => 'Medium',
|
||||||
'modul' => 'Modul',
|
'modul' => 'Modul',
|
||||||
'uebung' => 'Übung',
|
'uebung' => 'Übung',
|
||||||
|
'dokument' => 'Dokument',
|
||||||
'programm' => 'Programm',
|
'programm' => 'Programm',
|
||||||
'lizenzartikel' => 'Lizenzartikel',
|
'lizenzartikel' => 'Lizenzartikel',
|
||||||
];
|
];
|
||||||
@@ -27,7 +28,7 @@ class EditorialContentKind extends Model
|
|||||||
* Modulen (programm, modul), Vertraulichkeit von Traineranleitungen (traineranleitung). Ihre Bezeichnung bleibt
|
* Modulen (programm, modul), Vertraulichkeit von Traineranleitungen (traineranleitung). Ihre Bezeichnung bleibt
|
||||||
* pflegbar; deaktivieren, Kontexte ändern und löschen sind gesperrt.
|
* pflegbar; deaktivieren, Kontexte ändern und löschen sind gesperrt.
|
||||||
*/
|
*/
|
||||||
public const SYSTEM_SLUGS = ['programm', 'modul', 'uebung', 'traineranleitung', self::EXERCISE_SECTION_SLUG];
|
public const SYSTEM_SLUGS = ['programm', 'modul', 'uebung', 'dokument', 'traineranleitung', self::EXERCISE_SECTION_SLUG, self::DOCUMENT_CHAPTER_SLUG];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Textabschnitte einer Übung. Die Materialart wird nur automatisch gesetzt (ExerciseSections) und hat deshalb
|
* Textabschnitte einer Übung. Die Materialart wird nur automatisch gesetzt (ExerciseSections) und hat deshalb
|
||||||
@@ -35,6 +36,9 @@ class EditorialContentKind extends Model
|
|||||||
*/
|
*/
|
||||||
public const EXERCISE_SECTION_SLUG = 'uebungsabschnitt';
|
public const EXERCISE_SECTION_SLUG = 'uebungsabschnitt';
|
||||||
|
|
||||||
|
/** Kapitel eines Dokuments: wie Übungsabschnitte nur automatisch gesetzt, nie öffentlich (ADR-51). */
|
||||||
|
public const DOCUMENT_CHAPTER_SLUG = 'dokumentkapitel';
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'slug',
|
'slug',
|
||||||
'label',
|
'label',
|
||||||
@@ -83,7 +87,7 @@ public function allows(string $context): bool
|
|||||||
/** Wird nie von Hand gewählt, sondern von der Übungsverwaltung gesetzt. */
|
/** Wird nie von Hand gewählt, sondern von der Übungsverwaltung gesetzt. */
|
||||||
public function isAutomatic(): bool
|
public function isAutomatic(): bool
|
||||||
{
|
{
|
||||||
return $this->slug === self::EXERCISE_SECTION_SLUG;
|
return in_array($this->slug, [self::EXERCISE_SECTION_SLUG, self::DOCUMENT_CHAPTER_SLUG], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isSystem(): bool
|
public function isSystem(): bool
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public static function compositionContext(?CompositionKind $kind): ?string
|
|||||||
CompositionKind::Kurs => 'programm',
|
CompositionKind::Kurs => 'programm',
|
||||||
CompositionKind::Uebung => 'modul',
|
CompositionKind::Uebung => 'modul',
|
||||||
CompositionKind::Exercise => 'uebung',
|
CompositionKind::Exercise => 'uebung',
|
||||||
|
CompositionKind::Document => 'dokument',
|
||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -181,6 +182,7 @@ private function usedKindIds(string $context): array
|
|||||||
'programm' => DB::table('compositions')->where('kind', CompositionKind::Kurs->value),
|
'programm' => DB::table('compositions')->where('kind', CompositionKind::Kurs->value),
|
||||||
'modul' => DB::table('compositions')->where('kind', CompositionKind::Uebung->value),
|
'modul' => DB::table('compositions')->where('kind', CompositionKind::Uebung->value),
|
||||||
'uebung' => DB::table('compositions')->where('kind', CompositionKind::Exercise->value),
|
'uebung' => DB::table('compositions')->where('kind', CompositionKind::Exercise->value),
|
||||||
|
'dokument' => DB::table('compositions')->where('kind', CompositionKind::Document->value),
|
||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,191 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use App\Domain\Entitlement\DecideAccess;
|
||||||
|
use App\Domain\Entitlement\Grant;
|
||||||
|
use App\Domain\Media\PdfImage;
|
||||||
|
use App\Models\User;
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bilder in formatierten Texten (ADR-51). Ein Text verweist auf eine Bildfassung; ob und wie sie erscheint, entscheidet
|
||||||
|
* hier für den Stand des Mitglieds:
|
||||||
|
*
|
||||||
|
* - Ein Bild im Text gehört zum Text. Wer den Text ansehen (PDF: laden) darf, darf die Bilder darin sehen. Es braucht kein
|
||||||
|
* eigenes Recht für Bilder; bestehende Berechtigungen, die nur Texte nennen, zeigen die Bilder der Texte mit. Die Rechte
|
||||||
|
* des Texts entscheidet wie überall `DecideAccess`.
|
||||||
|
* - Das Bild muss zum festgeschriebenen Inhalt des Stands gehören ({@see ContentResolver}: ein Bild im Text steht als
|
||||||
|
* ergänzende Zeile im Stand) und im Text tatsächlich vorkommen. So gibt die Adresse kein anderes Bild frei.
|
||||||
|
* - Eine Sperre der Bildfassung wirkt: Das Bild entfällt, der Text bleibt lesbar.
|
||||||
|
*
|
||||||
|
* Ansicht: eine Adresse ohne Ablauf, die bei jedem Abruf neu entscheidet und die Datei ausliefert (`member.stand.image`);
|
||||||
|
* eine lange Lektüre darf nicht an einer kurzlebigen Signatur scheitern. PDF: das Bild wird aus dem abgeleiteten Bestand
|
||||||
|
* gelesen und für das PDF aufbereitet.
|
||||||
|
*/
|
||||||
|
final class EmbeddedImages
|
||||||
|
{
|
||||||
|
public function __construct(private readonly DecideAccess $access) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auflösung für die Vorschau der Redaktion: Bilder zeigt die Verwaltung über ihre eigene Dateiausgabe.
|
||||||
|
*
|
||||||
|
* @return Closure(int): ?array{src: string}
|
||||||
|
*/
|
||||||
|
public static function staff(): Closure
|
||||||
|
{
|
||||||
|
return fn (int $id): array => ['src' => self::staffSource($id)];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Adresse einer Bildfassung für den Editor und die Vorschau der Verwaltung. */
|
||||||
|
public static function staffSource(int $id): string
|
||||||
|
{
|
||||||
|
return route('content.file', ['version' => $id], false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Text für einen Editor der Verwaltung: Bilder tragen ihre Adresse, damit der Editor sie zeigt. */
|
||||||
|
public static function forEditor(?string $value): string
|
||||||
|
{
|
||||||
|
return FormattedText::forEditor(FormattedText::canonical($value), fn (int $id): string => self::staffSource($id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auflösung für {@see FormattedText::html()} eines Textes im Stand.
|
||||||
|
*
|
||||||
|
* @return Closure(int): ?array{src?: string, alt?: string, note?: string}
|
||||||
|
*/
|
||||||
|
public function forView(User $user, LicenseArticle $article, ArticleRelease $release, ContentElementVersion $text): Closure
|
||||||
|
{
|
||||||
|
return function (int $id) use ($user, $article, $release, $text): ?array {
|
||||||
|
$found = $this->decide($user, $article, $release, $text, $id, 'ansehen');
|
||||||
|
|
||||||
|
if ($found === null) {
|
||||||
|
return ['note' => 'Dieses Bild gibt es nicht mehr.'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $found['allowed']) {
|
||||||
|
return ['note' => 'Dieses Bild ist derzeit nicht verfügbar.'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['src' => route('member.stand.image', ['article' => $article->id, 'release' => $release->id, 'text' => $text->id, 'version' => $id])];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Bildfassung für die Auslieferung: nur wenn sie im Text vorkommt, zum Stand gehört, nicht gesperrt ist und der Text
|
||||||
|
* für `ansehen` zulässig ist.
|
||||||
|
*
|
||||||
|
* @return array{version: ContentElementVersion, grant: Grant}|null
|
||||||
|
*/
|
||||||
|
public function serve(User $user, LicenseArticle $article, ArticleRelease $release, ContentElementVersion $text, int $id): ?array
|
||||||
|
{
|
||||||
|
$found = $this->decide($user, $article, $release, $text, $id, 'ansehen');
|
||||||
|
|
||||||
|
return $found !== null && $found['allowed'] && $found['grant'] instanceof Grant ? ['version' => $found['version'], 'grant' => $found['grant']] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auflösung für das PDF. Ein Bild darf ins PDF, wenn ein Text, der es enthält, für `laden` zulässig ist. Die Bilder, die
|
||||||
|
* tatsächlich im PDF stehen, sammelt {@see PdfImages::used()} für den Ausgabenachweis.
|
||||||
|
*
|
||||||
|
* @param list<ContentElementVersion> $texts die Texte des PDF
|
||||||
|
*/
|
||||||
|
public function forPdf(User $user, LicenseArticle $article, ArticleRelease $release, array $texts): PdfImages
|
||||||
|
{
|
||||||
|
return new PdfImages(function (int $id) use ($user, $article, $release, $texts): ?array {
|
||||||
|
$decision = null;
|
||||||
|
$exists = false;
|
||||||
|
|
||||||
|
foreach ($texts as $text) {
|
||||||
|
if (! in_array($id, FormattedText::imageIds($text->body), true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$found = $this->decide($user, $article, $release, $text, $id, 'laden');
|
||||||
|
$exists = $exists || $found !== null;
|
||||||
|
|
||||||
|
if ($found !== null && $found['allowed']) {
|
||||||
|
$decision = $found;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($decision === null) {
|
||||||
|
return ['note' => $exists ? 'Bild nicht verfügbar' : 'Bild nicht mehr vorhanden', 'grant' => null, 'version' => null];
|
||||||
|
}
|
||||||
|
|
||||||
|
$prepared = self::prepared($decision['version']);
|
||||||
|
|
||||||
|
if ($prepared === null) {
|
||||||
|
return ['note' => 'Bild kann nicht gedruckt werden', 'grant' => null, 'version' => null];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $prepared + ['grant' => $decision['grant'], 'version' => $decision['version']];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auflösung für die PDF-Vorschau der Redaktion: ohne Rechteprüfung, ohne Ausgabenachweis.
|
||||||
|
*/
|
||||||
|
public static function forStaffPdf(): PdfImages
|
||||||
|
{
|
||||||
|
return new PdfImages(function (int $id): ?array {
|
||||||
|
$version = ContentElementVersion::query()->with('element')->find($id);
|
||||||
|
|
||||||
|
if (! $version instanceof ContentElementVersion || $version->element === null || $version->element->output_class !== 'bild') {
|
||||||
|
return ['note' => 'Bild nicht mehr vorhanden', 'grant' => null, 'version' => null];
|
||||||
|
}
|
||||||
|
|
||||||
|
$prepared = self::prepared($version);
|
||||||
|
|
||||||
|
return $prepared === null ? ['note' => 'Bild kann nicht gedruckt werden', 'grant' => null, 'version' => null] : $prepared + ['grant' => null, 'version' => null];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Pfad der Bilddatei im abgeleiteten Bestand, wenn sie vorliegt. */
|
||||||
|
public static function file(ContentElementVersion $version): ?string
|
||||||
|
{
|
||||||
|
$file = $version->metadata['file'] ?? null;
|
||||||
|
|
||||||
|
return is_string($file) && $file !== '' && ! str_contains($file, '..') && Storage::disk('media_derived')->exists($file) ? $file : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Bilddatei aus dem abgeleiteten Bestand (der Web-Prozess liest nur dort), für das PDF aufbereitet.
|
||||||
|
*
|
||||||
|
* @return array{jpeg: string, width: int, height: int}|null
|
||||||
|
*/
|
||||||
|
private static function prepared(ContentElementVersion $version): ?array
|
||||||
|
{
|
||||||
|
$file = self::file($version);
|
||||||
|
|
||||||
|
return $file === null ? null : PdfImage::fromBytes((string) Storage::disk('media_derived')->get($file));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{allowed: bool, version: ContentElementVersion, grant: ?Grant}|null null = es gibt kein solches Bild im Text
|
||||||
|
*/
|
||||||
|
private function decide(User $user, LicenseArticle $article, ArticleRelease $release, ContentElementVersion $text, int $id, string $action): ?array
|
||||||
|
{
|
||||||
|
if (! in_array($id, FormattedText::imageIds($text->body), true)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = ContentElementVersion::query()->with('element')->find($id);
|
||||||
|
|
||||||
|
if (! $version instanceof ContentElementVersion || $version->element === null || $version->element->output_class !== 'bild') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$inStand = $release->contents()->where('content_element_version_id', $id)->exists();
|
||||||
|
$decision = ($this->access)($user, $article, $release, $text, $action);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'allowed' => $inStand && $decision->allowed && $version->status === ContentVersionStatus::Bereit,
|
||||||
|
'version' => $version,
|
||||||
|
'grant' => $decision->grant,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,7 +45,7 @@ public function mayOpen(User $user, LicenseArticle $article, ArticleRelease $rel
|
|||||||
*
|
*
|
||||||
* @return array{version: CompositionVersion, selection: list<string>|null}|null
|
* @return array{version: CompositionVersion, selection: list<string>|null}|null
|
||||||
*/
|
*/
|
||||||
public function locate(ArticleRelease $release, string $path): ?array
|
public function locate(ArticleRelease $release, string $path, CompositionKind $kind = CompositionKind::Exercise): ?array
|
||||||
{
|
{
|
||||||
if (preg_match('/^\d+(-\d+)*$/', $path) !== 1) {
|
if (preg_match('/^\d+(-\d+)*$/', $path) !== 1) {
|
||||||
return null;
|
return null;
|
||||||
@@ -71,7 +71,7 @@ public function locate(ArticleRelease $release, string $path): ?array
|
|||||||
|
|
||||||
$version?->loadMissing('composition');
|
$version?->loadMissing('composition');
|
||||||
|
|
||||||
if ($version === null || $version->composition === null || $version->composition->kind !== CompositionKind::Exercise) {
|
if ($version === null || $version->composition === null || $version->composition->kind !== $kind) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,6 +114,7 @@ public function build(User $user, LicenseArticle $article, ArticleRelease $relea
|
|||||||
{
|
{
|
||||||
$exercise->loadMissing(['composition', 'variants', 'members.variant', 'members.contentElementVersion.element']);
|
$exercise->loadMissing(['composition', 'variants', 'members.variant', 'members.contentElementVersion.element']);
|
||||||
$library = app(LibraryCatalog::class);
|
$library = app(LibraryCatalog::class);
|
||||||
|
$embedded = app(EmbeddedImages::class);
|
||||||
$offered = $exercise->variants->filter(fn (CompositionVersionVariant $variant): bool => $selection === null || in_array($variant->key, $selection, true))->values();
|
$offered = $exercise->variants->filter(fn (CompositionVersionVariant $variant): bool => $selection === null || in_array($variant->key, $selection, true))->values();
|
||||||
$chosen = $offered->firstWhere('key', $variantKey) ?? $offered->first();
|
$chosen = $offered->firstWhere('key', $variantKey) ?? $offered->first();
|
||||||
$entries = [];
|
$entries = [];
|
||||||
@@ -146,7 +147,7 @@ public function build(User $user, LicenseArticle $article, ArticleRelease $relea
|
|||||||
'download_grant' => $download?->grant,
|
'download_grant' => $download?->grant,
|
||||||
'state' => $decision->allowed ? 'ok' : ($version->status === ContentVersionStatus::Gesperrt ? 'gesperrt' : 'nicht_lizenziert'),
|
'state' => $decision->allowed ? 'ok' : ($version->status === ContentVersionStatus::Gesperrt ? 'gesperrt' : 'nicht_lizenziert'),
|
||||||
'blocks' => $decision->allowed && $class === 'text' ? FormattedText::blocks($version->body) : null,
|
'blocks' => $decision->allowed && $class === 'text' ? FormattedText::blocks($version->body) : null,
|
||||||
'html' => $decision->allowed && $class === 'text' ? FormattedText::html($version->body) : null,
|
'html' => $decision->allowed && $class === 'text' ? FormattedText::html($version->body, $embedded->forView($user, $article, $release, $version)) : null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Domain\Catalog;
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
use App\Domain\Commerce\Receipt\PdfDocument;
|
use App\Domain\Commerce\Receipt\PdfDocument;
|
||||||
|
use Closure;
|
||||||
use Transliterator;
|
use Transliterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,7 +24,7 @@ class ExercisePdf
|
|||||||
|
|
||||||
private PdfDocument $pdf;
|
private PdfDocument $pdf;
|
||||||
|
|
||||||
private float $y = self::TOP;
|
private PdfFlow $flow;
|
||||||
|
|
||||||
private int $page = 0;
|
private int $page = 0;
|
||||||
|
|
||||||
@@ -64,32 +65,36 @@ public function sections(array $guide): ?array
|
|||||||
* @param array<string, mixed> $guide
|
* @param array<string, mixed> $guide
|
||||||
* @param list<array<string, mixed>> $sections
|
* @param list<array<string, mixed>> $sections
|
||||||
*/
|
*/
|
||||||
public function render(array $guide, array $sections, string $licensee, string $copyId, string $variantName, string $guideUrl): string
|
public function render(array $guide, array $sections, string $licensee, string $copyId, string $variantName, string $guideUrl, ?PdfImages $images = null): string
|
||||||
{
|
{
|
||||||
$this->pdf = new PdfDocument;
|
$this->pdf = new PdfDocument;
|
||||||
$this->page = 0;
|
$this->page = 0;
|
||||||
$this->footer = self::printable('Lizenziert für '.$licensee.' · Lizenzkopie '.$copyId);
|
$this->footer = self::printable('Lizenziert für '.$licensee.' · Lizenzkopie '.$copyId);
|
||||||
|
$this->flow = new PdfFlow($this->pdf, self::LEFT, self::RIGHT, self::TOP, self::BOTTOM, function (): void {
|
||||||
|
$this->closePage();
|
||||||
|
$this->newPage();
|
||||||
|
}, $images === null ? null : Closure::fromCallable($images));
|
||||||
$this->newPage();
|
$this->newPage();
|
||||||
|
|
||||||
$this->write(self::printable((string) $guide['title']), 18, true, 8);
|
$this->flow->write(self::printable((string) $guide['title']), 18, true, 8);
|
||||||
|
|
||||||
if ($variantName !== '') {
|
if ($variantName !== '') {
|
||||||
$this->write(self::printable('Variante: '.$variantName), 11, true, 6);
|
$this->flow->write(self::printable('Variante: '.$variantName), 11, true, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->fact('Lernziel', $guide['learning_goal']);
|
$this->fact('Lernziel', $guide['learning_goal']);
|
||||||
|
|
||||||
if ($guide['duration_minutes'] !== null) {
|
if ($guide['duration_minutes'] !== null) {
|
||||||
$this->write(self::printable('Dauer: '.$guide['duration_minutes'].($guide['duration_max'] !== null ? ' bis '.$guide['duration_max'] : '').' Minuten'), 10.5, false, 4);
|
$this->flow->write(self::printable('Dauer: '.$guide['duration_minutes'].($guide['duration_max'] !== null ? ' bis '.$guide['duration_max'] : '').' Minuten'), 10.5, false, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filled($guide['prerequisites'])) {
|
if (filled($guide['prerequisites'])) {
|
||||||
$this->write(self::printable('Voraussetzungen: '.$guide['prerequisites']), 10.5, false, 4);
|
$this->flow->write(self::printable('Voraussetzungen: '.$guide['prerequisites']), 10.5, false, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->fact('Ausstattung', $guide['material_note']);
|
$this->fact('Ausstattung', $guide['material_note']);
|
||||||
|
|
||||||
$this->y -= 6;
|
$this->flow->y -= 6;
|
||||||
|
|
||||||
foreach ($sections as $section) {
|
foreach ($sections as $section) {
|
||||||
$this->section($section, $guideUrl);
|
$this->section($section, $guideUrl);
|
||||||
@@ -108,16 +113,7 @@ public function render(array $guide, array $sections, string $licensee, string $
|
|||||||
*/
|
*/
|
||||||
public static function printable(string $text): string
|
public static function printable(string $text): string
|
||||||
{
|
{
|
||||||
$text = strtr($text, ['→' => '->', '←' => '<-', '≥' => '>=', '≤' => '<=', '✓' => '+', '✗' => 'x', '≠' => '!=', '≈' => '~']);
|
return PdfFlow::printable($text);
|
||||||
$latin = Transliterator::create('Any-Latin; Latin-ASCII');
|
|
||||||
$out = '';
|
|
||||||
|
|
||||||
foreach (mb_str_split($text) as $char) {
|
|
||||||
$encoded = mb_convert_encoding($char, 'Windows-1252', 'UTF-8');
|
|
||||||
$out .= $encoded === '?' && $char !== '?' ? ($latin?->transliterate($char) ?: '?') : $char;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,16 +127,16 @@ private function section(array $section, string $guideUrl): void
|
|||||||
$label = in_array($section['class'], ['film', 'audio'], true)
|
$label = in_array($section['class'], ['film', 'audio'], true)
|
||||||
? 'Film: '.$title.' - online abrufbar im Mitgliederbereich (geschützte Wiedergabe): '.$guideUrl
|
? 'Film: '.$title.' - online abrufbar im Mitgliederbereich (geschützte Wiedergabe): '.$guideUrl
|
||||||
: 'Material: '.$title.' - im Mitgliederbereich abrufbar: '.$guideUrl;
|
: 'Material: '.$title.' - im Mitgliederbereich abrufbar: '.$guideUrl;
|
||||||
$this->write(self::printable($label), 10, false, 6);
|
$this->flow->write(self::printable($label), 10, false, 6);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->write($title, 12.5, true, 5);
|
$this->flow->write($title, 12.5, true, 5, keep: 40);
|
||||||
|
|
||||||
$this->formatted($section['blocks'] ?? []);
|
$this->flow->formatted($section['blocks'] ?? []);
|
||||||
|
|
||||||
$this->y -= 4;
|
$this->flow->y -= 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Angabe mit Bezeichnung; formatierte Angaben stehen unter der Bezeichnung, einfache dahinter. */
|
/** Angabe mit Bezeichnung; formatierte Angaben stehen unter der Bezeichnung, einfache dahinter. */
|
||||||
@@ -153,177 +149,20 @@ private function fact(string $label, ?string $value): void
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count($blocks) === 1 && $blocks[0]['type'] === 'paragraph') {
|
if (count($blocks) === 1 && $blocks[0]['type'] === 'paragraph') {
|
||||||
$this->runs([['text' => $label.': ', 'bold' => true, 'italic' => false, 'href' => null], ...$blocks[0]['runs']], self::LEFT, 10.5, after: 4);
|
$this->flow->runs([['text' => $label.': ', 'bold' => true, 'italic' => false, 'href' => null], ...$blocks[0]['runs']], self::LEFT, 10.5, after: 4);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->write(self::printable($label.':'), 10.5, true, 2);
|
$this->flow->write(self::printable($label.':'), 10.5, true, 2);
|
||||||
$this->formatted($blocks);
|
$this->flow->formatted($blocks);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Blöcke aus {@see FormattedText::blocks()}: Absatz, Zwischenüberschrift, Zitat und Listen mit fett und kursiv.
|
|
||||||
*
|
|
||||||
* @param list<array<string, mixed>> $blocks
|
|
||||||
*/
|
|
||||||
private function formatted(array $blocks): void
|
|
||||||
{
|
|
||||||
foreach ($blocks as $block) {
|
|
||||||
match ($block['type']) {
|
|
||||||
'heading' => $this->runs($block['runs'], self::LEFT, 11, bold: true, after: 4),
|
|
||||||
'quote' => $this->runs($block['runs'], self::LEFT + 14, 10.5, italic: true, after: 5),
|
|
||||||
'bullets' => $this->listItems($block['items'], fn (int $n): string => '•'),
|
|
||||||
'numbered' => $this->listItems($block['items'], fn (int $n): string => $n.'.'),
|
|
||||||
default => $this->runs($block['runs'] ?? [], self::LEFT, 10.5, after: 5),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param list<list<array{text: string, bold: bool, italic: bool, href: ?string}>> $items
|
|
||||||
*/
|
|
||||||
private function listItems(array $items, callable $marker): void
|
|
||||||
{
|
|
||||||
foreach ($items as $index => $item) {
|
|
||||||
$this->room(14);
|
|
||||||
$this->pdf->text(self::LEFT + 4, $this->y, $marker($index + 1), 10.5);
|
|
||||||
$this->runs($item, self::LEFT + 18, 10.5, after: 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->y -= 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setzt Textabschnitte mit fett und kursiv in Zeilen um. Die Breite kommt aus den Schriftbreiten der Helvetica
|
|
||||||
* ({@see PdfDocument::exactWidth()}), damit verschiedene Schnitte in einer Zeile ohne Lücken aneinanderstoßen.
|
|
||||||
* Links erscheinen mit ausgeschriebener Adresse, weil sie auf Papier sonst verloren gehen.
|
|
||||||
*
|
|
||||||
* @param list<array{text: string, bold: bool, italic: bool, href: ?string}> $runs
|
|
||||||
*/
|
|
||||||
private function runs(array $runs, float $x, float $size, bool $bold = false, bool $italic = false, float $after = 0): void
|
|
||||||
{
|
|
||||||
$maxWidth = self::RIGHT - $x;
|
|
||||||
$lines = [];
|
|
||||||
$line = [];
|
|
||||||
$width = 0.0;
|
|
||||||
$pendingSpace = false;
|
|
||||||
$count = count($runs);
|
|
||||||
|
|
||||||
$flush = function () use (&$lines, &$line, &$width, &$pendingSpace): void {
|
|
||||||
if ($line !== []) {
|
|
||||||
$lines[] = $line;
|
|
||||||
}
|
|
||||||
|
|
||||||
$line = [];
|
|
||||||
$width = 0.0;
|
|
||||||
$pendingSpace = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
$place = function (string $word, bool $isBold, bool $isItalic) use (&$line, &$width, &$pendingSpace, $maxWidth, $size, $flush): void {
|
|
||||||
$space = $pendingSpace && $line !== [] ? ' ' : '';
|
|
||||||
$need = PdfDocument::exactWidth($space.$word, $size, $isBold);
|
|
||||||
|
|
||||||
if ($line !== [] && $width + $need > $maxWidth) {
|
|
||||||
$flush();
|
|
||||||
$space = '';
|
|
||||||
$need = PdfDocument::exactWidth($word, $size, $isBold);
|
|
||||||
}
|
|
||||||
|
|
||||||
while ($need > $maxWidth && mb_strlen($word) > 1) {
|
|
||||||
$cut = mb_strlen($word) - 1;
|
|
||||||
|
|
||||||
while ($cut > 1 && PdfDocument::exactWidth(mb_substr($word, 0, $cut), $size, $isBold) > $maxWidth) {
|
|
||||||
$cut--;
|
|
||||||
}
|
|
||||||
|
|
||||||
$line[] = [mb_substr($word, 0, $cut), $isBold, $isItalic];
|
|
||||||
$flush();
|
|
||||||
$word = mb_substr($word, $cut);
|
|
||||||
$need = PdfDocument::exactWidth($word, $size, $isBold);
|
|
||||||
}
|
|
||||||
|
|
||||||
$last = $line === [] ? null : $line[array_key_last($line)];
|
|
||||||
|
|
||||||
if ($last !== null && $last[1] === $isBold && $last[2] === $isItalic) {
|
|
||||||
$line[array_key_last($line)][0] .= $space.$word;
|
|
||||||
} else {
|
|
||||||
$line[] = [$space.$word, $isBold, $isItalic];
|
|
||||||
}
|
|
||||||
|
|
||||||
$width += $need;
|
|
||||||
$pendingSpace = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach ($runs as $index => $run) {
|
|
||||||
$isBold = $bold || $run['bold'];
|
|
||||||
$isItalic = $italic || $run['italic'];
|
|
||||||
|
|
||||||
foreach (preg_split('/(\s+)/u', self::printable($run['text']), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) ?: [] as $token) {
|
|
||||||
if (trim($token) !== '') {
|
|
||||||
$place($token, $isBold, $isItalic);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str_contains($token, "\n")) {
|
|
||||||
$flush();
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pendingSpace = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$nextHref = $index + 1 < $count ? $runs[$index + 1]['href'] : null;
|
|
||||||
|
|
||||||
if ($run['href'] !== null && $nextHref !== $run['href'] && ! str_contains($run['text'], $run['href'])) {
|
|
||||||
$pendingSpace = true;
|
|
||||||
$place('('.self::printable($run['href']).')', false, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$flush();
|
|
||||||
|
|
||||||
foreach ($lines as $row) {
|
|
||||||
$this->room($size + 4);
|
|
||||||
$cursor = $x;
|
|
||||||
|
|
||||||
foreach ($row as [$text, $isBold, $isItalic]) {
|
|
||||||
$this->pdf->text($cursor, $this->y, $text, $size, $isBold, $isItalic);
|
|
||||||
$cursor += PdfDocument::exactWidth($text, $size, $isBold);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->y -= $size + 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->y -= $after;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function write(string $text, float $size, bool $bold, float $after): void
|
|
||||||
{
|
|
||||||
foreach (PdfDocument::wrap($text, self::RIGHT - self::LEFT, $size, $bold) as $line) {
|
|
||||||
$this->room($size + 4);
|
|
||||||
$this->pdf->text(self::LEFT, $this->y, $line, $size, $bold);
|
|
||||||
$this->y -= $size + 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->y -= $after;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function room(float $needed): void
|
|
||||||
{
|
|
||||||
if ($this->y - $needed < self::BOTTOM) {
|
|
||||||
$this->closePage();
|
|
||||||
$this->newPage();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function newPage(): void
|
private function newPage(): void
|
||||||
{
|
{
|
||||||
$this->pdf->addPage();
|
$this->pdf->addPage();
|
||||||
$this->page++;
|
$this->page++;
|
||||||
$this->y = self::TOP;
|
$this->flow->restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function closePage(): void
|
private function closePage(): void
|
||||||
|
|||||||
@@ -8,11 +8,15 @@
|
|||||||
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
|
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formatierter Text in der Verwaltung und im Mitgliederbereich (ADR-50).
|
* Formatierter Text in der Verwaltung und im Mitgliederbereich (ADR-50, ADR-51).
|
||||||
*
|
*
|
||||||
* Gespeichert wird bereinigtes HTML aus einer festen Auswahl: Absatz, Zwischenüberschrift (h3), fett, kursiv, Aufzählung,
|
* Gespeichert wird bereinigtes HTML aus einer festen Auswahl: Absatz, Zwischenüberschriften (h3 bis h6), fett, kursiv, Aufzählung,
|
||||||
* nummerierte Liste, Zitat, Link und Zeilenumbruch. Alles andere fällt beim Speichern weg, auch Skripte, Ereignisattribute
|
* nummerierte Liste, Zitat, Link, Zeilenumbruch, Tabelle und Bild. Alles andere fällt beim Speichern weg, auch Skripte,
|
||||||
* und Links auf andere Schemata als http, https und mailto.
|
* Ereignisattribute und Links auf andere Schemata als http, https und mailto.
|
||||||
|
*
|
||||||
|
* Ein Bild ist nie eine Adresse, sondern ein Verweis auf eine Bildfassung des Medienbestands (`<img data-id="…" alt="…">`).
|
||||||
|
* Die Adresse entsteht erst bei der Ausgabe, je nach Leser (Verwaltung, Mitglied mit Berechtigung, PDF). Ohne Auflösung
|
||||||
|
* zeigt die Ausgabe kein Bild.
|
||||||
*
|
*
|
||||||
* Klartext aus dem Altbestand bleibt unverändert in der Datenbank. Er wird erst beim Anzeigen oder Bearbeiten in dieselbe
|
* Klartext aus dem Altbestand bleibt unverändert in der Datenbank. Er wird erst beim Anzeigen oder Bearbeiten in dieselbe
|
||||||
* Form gebracht ({@see self::html()}) und erst beim Speichern als HTML abgelegt. Erkannt wird HTML an einer Regel: Der
|
* Form gebracht ({@see self::html()}) und erst beim Speichern als HTML abgelegt. Erkannt wird HTML an einer Regel: Der
|
||||||
@@ -25,7 +29,7 @@
|
|||||||
final class FormattedText
|
final class FormattedText
|
||||||
{
|
{
|
||||||
/** Blockelemente, mit denen gespeichertes HTML beginnt. */
|
/** Blockelemente, mit denen gespeichertes HTML beginnt. */
|
||||||
private const BLOCKS = ['p', 'h3', 'ul', 'ol', 'blockquote'];
|
private const BLOCKS = ['p', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol', 'blockquote', 'table', 'img'];
|
||||||
|
|
||||||
/** Angaben der Redaktion, die formatiert gespeichert werden. Suchbegriffe, Titel und Teaser bleiben Klartext. */
|
/** Angaben der Redaktion, die formatiert gespeichert werden. Suchbegriffe, Titel und Teaser bleiben Klartext. */
|
||||||
public const FIELDS = ['summary', 'description'];
|
public const FIELDS = ['summary', 'description'];
|
||||||
@@ -33,7 +37,13 @@ final class FormattedText
|
|||||||
private static ?HtmlSanitizer $sanitizer = null;
|
private static ?HtmlSanitizer $sanitizer = null;
|
||||||
|
|
||||||
/** Symbolleiste der Editoren; muss zur Auswahl oben passen. */
|
/** Symbolleiste der Editoren; muss zur Auswahl oben passen. */
|
||||||
public const TOOLBAR = [['bold', 'italic', 'link'], ['h3'], ['bulletList', 'orderedList', 'blockquote'], ['undo', 'redo']];
|
public const TOOLBAR = [
|
||||||
|
['bold', 'italic', 'link'],
|
||||||
|
['h3', 'h4', 'h5', 'h6'],
|
||||||
|
['bulletList', 'orderedList', 'blockquote'],
|
||||||
|
['table', 'tableAddRowAfter', 'tableAddColumnAfter', 'tableDeleteRow', 'tableDeleteColumn', 'tableToggleHeaderRow', 'tableDelete'],
|
||||||
|
['undo', 'redo'],
|
||||||
|
];
|
||||||
|
|
||||||
/** Wird der Wert als HTML gelesen (sonst als Klartext des Altbestands)? */
|
/** Wird der Wert als HTML gelesen (sonst als Klartext des Altbestands)? */
|
||||||
public static function isHtml(?string $value): bool
|
public static function isHtml(?string $value): bool
|
||||||
@@ -66,21 +76,164 @@ public static function canonicalHtml(?string $html): string
|
|||||||
return $html === '' ? '' : self::normalize($html);
|
return $html === '' ? '' : self::normalize($html);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sicheres HTML zur Ausgabe (für `{!! !!}`); Klartext des Altbestands wird dabei umgewandelt. */
|
/**
|
||||||
public static function html(?string $value): string
|
* Sicheres HTML zur Ausgabe (für `{!! !!}`); Klartext des Altbestands wird dabei umgewandelt.
|
||||||
|
*
|
||||||
|
* Bilder erscheinen nur, wenn `$images` sie auflöst: Die Funktion bekommt die Kennung der Bildfassung und liefert
|
||||||
|
* `['src' => Adresse, 'alt' => Text]` (Bild), `['note' => Text]` (Hinweis an der Stelle des Bilds) oder null (Bild
|
||||||
|
* entfällt). Ohne Funktion entfallen alle Bilder; so zeigt keine Ausgabe versehentlich ein Bild ohne Rechteprüfung.
|
||||||
|
*
|
||||||
|
* @param (callable(int): ?array{src?: string, alt?: string, note?: string})|null $images
|
||||||
|
*/
|
||||||
|
public static function html(?string $value, ?callable $images = null): string
|
||||||
{
|
{
|
||||||
return self::canonical($value);
|
return self::renderImages(self::canonical($value), $images);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sicheres HTML zur Ausgabe an Stellen, die Klartext des Altbestands bisher mit Zeilenumbrüchen zeigten: HTML wird
|
* Sicheres HTML zur Ausgabe an Stellen, die Klartext des Altbestands bisher mit Zeilenumbrüchen zeigten: HTML wird
|
||||||
* bereinigt ausgegeben, Klartext bleibt, wie er war (maskiert, Zeilenumbrüche erhalten).
|
* bereinigt ausgegeben, Klartext bleibt, wie er war (maskiert, Zeilenumbrüche erhalten).
|
||||||
|
*
|
||||||
|
* @param (callable(int): ?array{src?: string, alt?: string, note?: string})|null $images
|
||||||
*/
|
*/
|
||||||
public static function display(?string $value): string
|
public static function display(?string $value, ?callable $images = null): string
|
||||||
{
|
{
|
||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
|
|
||||||
return self::isHtml($value) ? self::canonical($value) : nl2br(e($value));
|
return self::isHtml($value) ? self::renderImages(self::canonical($value), $images) : nl2br(e($value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Bildfassungen, auf die ein Text verweist, in der Reihenfolge ihres Auftretens (ohne Wiederholung).
|
||||||
|
*
|
||||||
|
* @return list<int>
|
||||||
|
*/
|
||||||
|
public static function imageIds(?string $value): array
|
||||||
|
{
|
||||||
|
$html = self::canonical($value);
|
||||||
|
|
||||||
|
if ($html === '' || ! str_contains($html, '<img')) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$ids = [];
|
||||||
|
$document = HTMLDocument::createFromString('<body>'.$html.'</body>', LIBXML_NOERROR);
|
||||||
|
|
||||||
|
foreach ($document->querySelectorAll('img[data-id]') as $image) {
|
||||||
|
$id = (int) $image->getAttribute('data-id');
|
||||||
|
|
||||||
|
if ($id > 0 && ! in_array($id, $ids, true)) {
|
||||||
|
$ids[] = $id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Versieht die Zwischenüberschriften (h3 bis h6, auf oberster Ebene des Texts) mit Sprungmarken `<Präfix>-u<n>` und
|
||||||
|
* verschiebt ihre Stufe um `$shift` (höchstens h6). Die Marken zählen die nicht leeren Überschriften in ihrer Reihenfolge;
|
||||||
|
* {@see self::blocks()} zählt dieselben.
|
||||||
|
*
|
||||||
|
* @return array{html: string, headings: list<array{level: int, text: string, anchor: string}>}
|
||||||
|
*/
|
||||||
|
public static function anchorHeadings(string $html, string $prefix, int $shift = 0): array
|
||||||
|
{
|
||||||
|
if (preg_match('/<h[3-6][\s>]/i', $html) !== 1) {
|
||||||
|
return ['html' => $html, 'headings' => []];
|
||||||
|
}
|
||||||
|
|
||||||
|
$document = HTMLDocument::createFromString('<body>'.$html.'</body>', LIBXML_NOERROR);
|
||||||
|
$headings = [];
|
||||||
|
|
||||||
|
foreach (iterator_to_array($document->body->childNodes) as $node) {
|
||||||
|
if ($node->nodeType !== XML_ELEMENT_NODE || preg_match('/^h([3-6])$/', strtolower($node->nodeName), $match) !== 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$text = trim((string) preg_replace('/\s+/u', ' ', (string) $node->textContent));
|
||||||
|
|
||||||
|
if ($text === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$level = min(6, (int) $match[1] + $shift);
|
||||||
|
$anchor = $prefix.'-u'.(count($headings) + 1);
|
||||||
|
$replacement = $document->createElement('h'.$level);
|
||||||
|
$replacement->setAttribute('id', $anchor);
|
||||||
|
|
||||||
|
while ($node->firstChild !== null) {
|
||||||
|
$replacement->appendChild($node->firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
$node->replaceWith($replacement);
|
||||||
|
$headings[] = ['level' => $level, 'text' => $text, 'anchor' => $anchor];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['html' => trim($document->body->innerHTML), 'headings' => $headings];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fügt die Adresse an jedes Bild, damit der Editor es zeigt. Die Adresse gehört nicht zum gespeicherten Wert: Die
|
||||||
|
* Bereinigung entfernt sie beim Übernehmen aus dem Editor wieder.
|
||||||
|
*
|
||||||
|
* @param callable(int): ?string $source
|
||||||
|
*/
|
||||||
|
public static function forEditor(string $html, callable $source): string
|
||||||
|
{
|
||||||
|
if (! str_contains($html, '<img')) {
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
$document = HTMLDocument::createFromString('<body>'.$html.'</body>', LIBXML_NOERROR);
|
||||||
|
|
||||||
|
foreach ($document->querySelectorAll('img[data-id]') as $image) {
|
||||||
|
$src = $source((int) $image->getAttribute('data-id'));
|
||||||
|
|
||||||
|
if ($src !== null) {
|
||||||
|
$image->setAttribute('src', $src);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return trim($document->body->innerHTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param (callable(int): ?array{src?: string, alt?: string, note?: string})|null $images
|
||||||
|
*/
|
||||||
|
private static function renderImages(string $html, ?callable $images): string
|
||||||
|
{
|
||||||
|
if ($html === '' || ! str_contains($html, '<img')) {
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
$document = HTMLDocument::createFromString('<body>'.$html.'</body>', LIBXML_NOERROR);
|
||||||
|
|
||||||
|
foreach (iterator_to_array($document->querySelectorAll('img')) as $image) {
|
||||||
|
$found = $images === null ? null : $images((int) $image->getAttribute('data-id'));
|
||||||
|
|
||||||
|
if (isset($found['src'])) {
|
||||||
|
$image->removeAttribute('data-id');
|
||||||
|
$image->setAttribute('src', (string) $found['src']);
|
||||||
|
$image->setAttribute('alt', (string) ($found['alt'] ?? $image->getAttribute('alt')));
|
||||||
|
$image->setAttribute('loading', 'lazy');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($found['note'])) {
|
||||||
|
$note = $document->createElement('p');
|
||||||
|
$note->setAttribute('class', 'mb-bildhinweis');
|
||||||
|
$note->textContent = (string) $found['note'];
|
||||||
|
$image->replaceWith($note);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$image->remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
return trim($document->body->innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isBlank(?string $value): bool
|
public static function isBlank(?string $value): bool
|
||||||
@@ -103,16 +256,37 @@ public static function plain(?string $value): string
|
|||||||
$out = [];
|
$out = [];
|
||||||
|
|
||||||
foreach (self::blocks($value) as $block) {
|
foreach (self::blocks($value) as $block) {
|
||||||
$out[] = match ($block['type']) {
|
$text = self::plainBlock($block);
|
||||||
'bullets' => implode("\n", array_map(fn (array $item): string => '- '.self::runsText($item), $block['items'])),
|
|
||||||
'numbered' => implode("\n", array_map(fn (array $item, int $n): string => ($n + 1).'. '.self::runsText($item), $block['items'], array_keys($block['items']))),
|
if ($text !== '') {
|
||||||
default => self::runsText($block['runs']),
|
$out[] = $text;
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return trim(implode("\n\n", $out));
|
return trim(implode("\n\n", $out));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $block
|
||||||
|
*/
|
||||||
|
private static function plainBlock(array $block): string
|
||||||
|
{
|
||||||
|
return match ($block['type']) {
|
||||||
|
'bullets' => implode("\n", array_map(fn (array $item): string => '- '.self::runsText($item), $block['items'])),
|
||||||
|
'numbered' => implode("\n", array_map(fn (array $item, int $n): string => ($n + 1).'. '.self::runsText($item), $block['items'], array_keys($block['items']))),
|
||||||
|
'table' => implode("\n", array_map(
|
||||||
|
fn (array $row): string => implode(' | ', array_map(
|
||||||
|
fn (array $cell): string => trim((string) preg_replace('/\s+/u', ' ', implode(' ', array_filter(array_map(fn (array $inner): string => self::plainBlock($inner), $cell['blocks']))))),
|
||||||
|
$row,
|
||||||
|
)),
|
||||||
|
$block['rows'],
|
||||||
|
)),
|
||||||
|
// Ein Bild hat im Klartext keinen Platz (Listen, Auszüge, Meta-Beschreibung).
|
||||||
|
'image' => '',
|
||||||
|
default => self::runsText($block['runs']),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/** Kurzer Text für Listen und Karten. */
|
/** Kurzer Text für Listen und Karten. */
|
||||||
public static function excerpt(?string $value, int $length = 120): string
|
public static function excerpt(?string $value, int $length = 120): string
|
||||||
{
|
{
|
||||||
@@ -123,9 +297,10 @@ public static function excerpt(?string $value, int $length = 120): string
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Zerlegung in Blöcke mit Textabschnitten für das PDF. Ein Textabschnitt (Run) trägt `text`, `bold`, `italic` und
|
* Zerlegung in Blöcke mit Textabschnitten für das PDF. Ein Textabschnitt (Run) trägt `text`, `bold`, `italic` und
|
||||||
* `href`.
|
* `href`. Eine Tabelle besteht aus Zeilen mit Zellen (`header`, `colspan`, `rowspan`, `blocks`); ein Bild trägt die
|
||||||
|
* Kennung seiner Bildfassung (`id`) und den Alternativtext.
|
||||||
*
|
*
|
||||||
* @return list<array{type: 'paragraph'|'heading'|'quote'|'bullets'|'numbered', runs?: list<array{text: string, bold: bool, italic: bool, href: ?string}>, items?: list<list<array{text: string, bold: bool, italic: bool, href: ?string}>>}>
|
* @return list<array<string, mixed>>
|
||||||
*/
|
*/
|
||||||
public static function blocks(?string $value): array
|
public static function blocks(?string $value): array
|
||||||
{
|
{
|
||||||
@@ -136,9 +311,18 @@ public static function blocks(?string $value): array
|
|||||||
}
|
}
|
||||||
|
|
||||||
$document = HTMLDocument::createFromString('<body>'.$html.'</body>', LIBXML_NOERROR);
|
$document = HTMLDocument::createFromString('<body>'.$html.'</body>', LIBXML_NOERROR);
|
||||||
|
|
||||||
|
return self::extractBlocks($document->body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array<string, mixed>>
|
||||||
|
*/
|
||||||
|
private static function extractBlocks(Node $parent): array
|
||||||
|
{
|
||||||
$blocks = [];
|
$blocks = [];
|
||||||
|
|
||||||
foreach ($document->body->childNodes as $node) {
|
foreach ($parent->childNodes as $node) {
|
||||||
if ($node->nodeType !== XML_ELEMENT_NODE) {
|
if ($node->nodeType !== XML_ELEMENT_NODE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -159,19 +343,97 @@ public static function blocks(?string $value): array
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$blocks[] = [
|
if ($name === 'img') {
|
||||||
'type' => match ($name) {
|
$blocks[] = ['type' => 'image', 'id' => (int) $node->getAttribute('data-id'), 'alt' => (string) $node->getAttribute('alt')];
|
||||||
'h3' => 'heading',
|
|
||||||
'blockquote' => 'quote',
|
continue;
|
||||||
default => 'paragraph',
|
}
|
||||||
},
|
|
||||||
'runs' => self::runs($node),
|
if ($name === 'table') {
|
||||||
|
$rows = [];
|
||||||
|
|
||||||
|
foreach ($node->querySelectorAll('tr') as $row) {
|
||||||
|
$cells = [];
|
||||||
|
|
||||||
|
foreach ($row->childNodes as $cell) {
|
||||||
|
if ($cell->nodeType !== XML_ELEMENT_NODE || ! in_array(strtolower($cell->nodeName), ['th', 'td'], true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cells[] = [
|
||||||
|
'header' => strtolower($cell->nodeName) === 'th',
|
||||||
|
'colspan' => max(1, (int) $cell->getAttribute('colspan')),
|
||||||
|
'rowspan' => max(1, (int) $cell->getAttribute('rowspan')),
|
||||||
|
'blocks' => self::extractBlocks($cell),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($cells !== []) {
|
||||||
|
$rows[] = $cells;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$blocks[] = ['type' => 'table', 'rows' => $rows];
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$level = preg_match('/^h([3-6])$/', $name, $heading) === 1 ? (int) $heading[1] : 0;
|
||||||
|
$type = match (true) {
|
||||||
|
$level > 0 => 'heading',
|
||||||
|
$name === 'blockquote' => 'quote',
|
||||||
|
default => 'paragraph',
|
||||||
|
};
|
||||||
|
|
||||||
|
// Ein Bild mitten im Absatz (so setzt der Editor es) teilt den Absatz: Text davor, Bild, Text danach.
|
||||||
|
$images = $node->querySelectorAll('img');
|
||||||
|
|
||||||
|
if (count($images) === 0) {
|
||||||
|
$blocks[] = self::textBlock($type, $level, self::runs($node));
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pending = [];
|
||||||
|
|
||||||
|
foreach ($node->childNodes as $child) {
|
||||||
|
if ($child->nodeType === XML_ELEMENT_NODE && strtolower($child->nodeName) === 'img') {
|
||||||
|
if (trim(self::runsText($pending)) !== '') {
|
||||||
|
$blocks[] = self::textBlock($type, $level, $pending);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pending = [];
|
||||||
|
$blocks[] = ['type' => 'image', 'id' => (int) $child->getAttribute('data-id'), 'alt' => (string) $child->getAttribute('alt')];
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$holder = $node->ownerDocument->createElement('span');
|
||||||
|
$holder->appendChild($child->cloneNode(true));
|
||||||
|
$pending = [...$pending, ...self::runs($holder)];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trim(self::runsText($pending)) !== '') {
|
||||||
|
$blocks[] = self::textBlock($type, $level, $pending);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $blocks;
|
return $blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ein Textblock; eine Überschrift trägt zusätzlich ihre Stufe (3 bis 6) und ihren Text ohne Auszeichnung.
|
||||||
|
*
|
||||||
|
* @param list<array{text: string, bold: bool, italic: bool, href: ?string}> $runs
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
private static function textBlock(string $type, int $level, array $runs): array
|
||||||
|
{
|
||||||
|
return $type === 'heading'
|
||||||
|
? ['type' => $type, 'level' => $level, 'text' => self::runsText($runs), 'runs' => $runs]
|
||||||
|
: ['type' => $type, 'runs' => $runs];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Klartext des Altbestands als HTML: Absätze an Leerzeilen, Listen mit „- “, „• “ oder „1. “, Zwischenüberschriften
|
* Klartext des Altbestands als HTML: Absätze an Leerzeilen, Listen mit „- “, „• “ oder „1. “, Zwischenüberschriften
|
||||||
* mit „## “. Dieselben Konventionen wie {@see GuideText}.
|
* mit „## “. Dieselben Konventionen wie {@see GuideText}.
|
||||||
@@ -203,6 +465,15 @@ private static function normalize(string $html): string
|
|||||||
|
|
||||||
$document = HTMLDocument::createFromString('<body>'.$html.'</body>', LIBXML_NOERROR);
|
$document = HTMLDocument::createFromString('<body>'.$html.'</body>', LIBXML_NOERROR);
|
||||||
$body = $document->body;
|
$body = $document->body;
|
||||||
|
|
||||||
|
// Ein Bild steht zwischen den Absätzen, in einem Absatz (so setzt der Editor es) oder in einer Tabellenzelle und braucht
|
||||||
|
// seine Bildfassung. Anderswo (Liste, Zitat, Überschrift) entfällt es.
|
||||||
|
foreach (iterator_to_array($document->querySelectorAll('img')) as $image) {
|
||||||
|
if (! self::mayHoldImage($image->parentNode, $body) || (int) $image->getAttribute('data-id') < 1) {
|
||||||
|
$image->remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$out = '';
|
$out = '';
|
||||||
$loose = '';
|
$loose = '';
|
||||||
|
|
||||||
@@ -229,7 +500,7 @@ private static function normalize(string $html): string
|
|||||||
|
|
||||||
$flush();
|
$flush();
|
||||||
|
|
||||||
return self::hasText($out) ? $out : '';
|
return self::hasText($out) || str_contains($out, '<img') ? $out : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Ein Blockelement ohne Leerraum zwischen den Kindern; Listenpunkte tragen ihren Text immer in einem Absatz. */
|
/** Ein Blockelement ohne Leerraum zwischen den Kindern; Listenpunkte tragen ihren Text immer in einem Absatz. */
|
||||||
@@ -237,6 +508,16 @@ private static function block(Node $node): string
|
|||||||
{
|
{
|
||||||
$name = strtolower($node->nodeName);
|
$name = strtolower($node->nodeName);
|
||||||
|
|
||||||
|
if ($name === 'img') {
|
||||||
|
$id = (int) $node->getAttribute('data-id');
|
||||||
|
|
||||||
|
return $id > 0 ? '<img data-id="'.$id.'" alt="'.e(trim((string) $node->getAttribute('alt'))).'">' : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($name === 'table') {
|
||||||
|
return self::table($node);
|
||||||
|
}
|
||||||
|
|
||||||
if (in_array($name, ['ul', 'ol'], true)) {
|
if (in_array($name, ['ul', 'ol'], true)) {
|
||||||
$items = '';
|
$items = '';
|
||||||
|
|
||||||
@@ -265,7 +546,46 @@ private static function block(Node $node): string
|
|||||||
$inner = '<p>'.$inner.'</p>';
|
$inner = '<p>'.$inner.'</p>';
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::hasText($inner) ? '<'.$name.'>'.$inner.'</'.$name.'>' : '';
|
return self::hasContent($inner) ? '<'.$name.'>'.$inner.'</'.$name.'>' : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eine Tabelle in der festen Form des Editors: Zeilen mit Kopf- (`th`) und Datenzellen (`td`), Zellen mit Absätzen,
|
||||||
|
* Verbindungen nur als `colspan` und `rowspan` über 1. Breiten, Gestaltung und Zwischenebenen entfallen.
|
||||||
|
*/
|
||||||
|
private static function table(Node $table): string
|
||||||
|
{
|
||||||
|
$rows = '';
|
||||||
|
|
||||||
|
foreach ($table->querySelectorAll('tr') as $row) {
|
||||||
|
$cells = '';
|
||||||
|
|
||||||
|
foreach ($row->childNodes as $cell) {
|
||||||
|
if ($cell->nodeType !== XML_ELEMENT_NODE || ! in_array(strtolower($cell->nodeName), ['th', 'td'], true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$name = strtolower($cell->nodeName);
|
||||||
|
$attributes = '';
|
||||||
|
|
||||||
|
foreach (['colspan', 'rowspan'] as $span) {
|
||||||
|
$value = (int) $cell->getAttribute($span);
|
||||||
|
|
||||||
|
if ($value > 1) {
|
||||||
|
$attributes .= ' '.$span.'="'.min($value, 50).'"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$inner = self::inner($cell);
|
||||||
|
$cells .= '<'.$name.$attributes.'>'.($inner === '' ? '<p></p>' : (preg_match('/^<(?:p|ul|ol|blockquote|h[3-6]|img)[\s>]/', $inner) === 1 ? $inner : '<p>'.$inner.'</p>')).'</'.$name.'>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($cells !== '') {
|
||||||
|
$rows .= '<tr>'.$cells.'</tr>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rows !== '' && (self::hasText($rows) || str_contains($rows, '<img')) ? '<table><tbody>'.$rows.'</tbody></table>' : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function inner(Node $node): string
|
private static function inner(Node $node): string
|
||||||
@@ -273,7 +593,7 @@ private static function inner(Node $node): string
|
|||||||
$html = '';
|
$html = '';
|
||||||
|
|
||||||
foreach ($node->childNodes as $child) {
|
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);
|
$html .= self::block($child);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -285,17 +605,39 @@ private static function inner(Node $node): string
|
|||||||
return trim($html);
|
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, '<img');
|
||||||
|
}
|
||||||
|
|
||||||
private static function hasText(string $html): bool
|
private static function hasText(string $html): bool
|
||||||
{
|
{
|
||||||
return trim(html_entity_decode(strip_tags($html), ENT_QUOTES | ENT_HTML5, 'UTF-8')) !== '';
|
return trim(html_entity_decode(strip_tags($html), ENT_QUOTES | ENT_HTML5, 'UTF-8')) !== '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** b, i und andere Überschriftsstufen der Quelle werden auf die feste Auswahl abgebildet; der Rest fällt in der Bereinigung weg. */
|
/** b, i und die Überschriftsstufen 1 und 2 der Quelle werden auf die feste Auswahl abgebildet (h1 und h2 gehören dem Dokument und dem Kapitel); der Rest fällt in der Bereinigung weg. */
|
||||||
private static function mapLegacyTags(string $html): string
|
private static function mapLegacyTags(string $html): string
|
||||||
{
|
{
|
||||||
$html = (string) preg_replace('/<(\/?)b(?=[\s>\/])/i', '<$1strong', $html);
|
$html = (string) preg_replace('/<(\/?)b(?=[\s>\/])/i', '<$1strong', $html);
|
||||||
$html = (string) preg_replace('/<(\/?)i(?=[\s>\/])/i', '<$1em', $html);
|
$html = (string) preg_replace('/<(\/?)i(?=[\s>\/])/i', '<$1em', $html);
|
||||||
$html = (string) preg_replace('/<(\/?)h[1-6](?=[\s>\/])/i', '<$1h3', $html);
|
$html = (string) preg_replace('/<(\/?)h[12](?=[\s>\/])/i', '<$1h3', $html);
|
||||||
|
|
||||||
return (string) preg_replace('/<(\/?)div(?=[\s>\/])/i', '<$1p', $html);
|
return (string) preg_replace('/<(\/?)div(?=[\s>\/])/i', '<$1p', $html);
|
||||||
}
|
}
|
||||||
@@ -359,12 +701,23 @@ private static function sanitizer(): HtmlSanitizer
|
|||||||
->allowElement('p')
|
->allowElement('p')
|
||||||
->allowElement('br')
|
->allowElement('br')
|
||||||
->allowElement('h3')
|
->allowElement('h3')
|
||||||
|
->allowElement('h4')
|
||||||
|
->allowElement('h5')
|
||||||
|
->allowElement('h6')
|
||||||
->allowElement('strong')
|
->allowElement('strong')
|
||||||
->allowElement('em')
|
->allowElement('em')
|
||||||
->allowElement('ul')
|
->allowElement('ul')
|
||||||
->allowElement('ol')
|
->allowElement('ol')
|
||||||
->allowElement('li')
|
->allowElement('li')
|
||||||
->allowElement('blockquote')
|
->allowElement('blockquote')
|
||||||
|
->allowElement('table')
|
||||||
|
->allowElement('thead')
|
||||||
|
->allowElement('tbody')
|
||||||
|
->allowElement('tfoot')
|
||||||
|
->allowElement('tr')
|
||||||
|
->allowElement('th', ['colspan', 'rowspan'])
|
||||||
|
->allowElement('td', ['colspan', 'rowspan'])
|
||||||
|
->allowElement('img', ['data-id', 'alt'])
|
||||||
->allowElement('a', ['href'])
|
->allowElement('a', ['href'])
|
||||||
->allowLinkSchemes(['http', 'https', 'mailto'])
|
->allowLinkSchemes(['http', 'https', 'mailto'])
|
||||||
->allowRelativeLinks(false)
|
->allowRelativeLinks(false)
|
||||||
|
|||||||
@@ -0,0 +1,692 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use App\Domain\Commerce\Receipt\PdfDocument;
|
||||||
|
use Closure;
|
||||||
|
use Transliterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Satz für gedruckte Ausgaben (Übung, Dokument): Überschriften, Absätze mit fett und kursiv, Listen, Tabellen und Bilder
|
||||||
|
* aus den Blöcken von {@see FormattedText::blocks()}. Übung und Dokument setzen mit demselben Baustein; so sehen
|
||||||
|
* Tabellen und Bilder in beiden gleich aus.
|
||||||
|
*
|
||||||
|
* Der Satz kennt weder Seitenkopf noch Fußzeile: Passt etwas nicht mehr auf die Seite, ruft er `$breakPage` auf. Diese
|
||||||
|
* Funktion schließt die Seite und öffnet die nächste; danach beginnt der Satz wieder am oberen Rand.
|
||||||
|
*/
|
||||||
|
final class PdfFlow
|
||||||
|
{
|
||||||
|
public float $y;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wird für jede Zwischenüberschrift mit Sprungmarke aufgerufen, bevor sie gesetzt wird: Block und obere Kante.
|
||||||
|
*
|
||||||
|
* @var (Closure(array<string, mixed>, float): void)|null
|
||||||
|
*/
|
||||||
|
public ?Closure $onHeading = null;
|
||||||
|
|
||||||
|
/** Schachtelungstiefe beim Setzen einer Tabelle (Zelleninhalt setzt nie wieder eine Tabelle). */
|
||||||
|
private int $depth = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Closure(): void $breakPage
|
||||||
|
* @param (Closure(int): ?array{jpeg?: string, width?: int, height?: int, note?: string})|null $images Löst ein Bild auf: JPEG mit Maßen,
|
||||||
|
* ein Hinweistext oder null (entfällt)
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
private readonly PdfDocument $pdf,
|
||||||
|
private readonly float $left,
|
||||||
|
private readonly float $right,
|
||||||
|
private readonly float $top,
|
||||||
|
private readonly float $bottom,
|
||||||
|
private readonly Closure $breakPage,
|
||||||
|
private readonly ?Closure $images = null,
|
||||||
|
) {
|
||||||
|
$this->y = $top;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsichtbare Zeichen, die im Browser nichts zeigen, im PDF aber stören: der weiche Trennstrich (erscheint dort als
|
||||||
|
* Bindestrich), Nullbreiten- und Steuerzeichen für die Schreibrichtung sowie die Byte-Reihenfolge-Marke (erscheinen als „?“).
|
||||||
|
* Mitten in einem Link machen sie die Adresse unbrauchbar. Das PDF trennt keine Wörter und braucht sie nicht.
|
||||||
|
*/
|
||||||
|
private const INVISIBLE = '/[\x{00AD}\x{034F}\x{061C}\x{180E}\x{200B}-\x{200F}\x{202A}-\x{202E}\x{2060}-\x{2064}\x{FEFF}]/u';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zeichen außerhalb von Windows-1252 werden, wo möglich, lesbar ersetzt (Pfeil, Ungleichheitszeichen, andere
|
||||||
|
* lateinische Buchstaben); sonst bleibt „?“. Unsichtbare Zeichen entfallen.
|
||||||
|
*/
|
||||||
|
public static function printable(string $text): string
|
||||||
|
{
|
||||||
|
$text = (string) preg_replace(self::INVISIBLE, '', $text);
|
||||||
|
$text = strtr($text, ['→' => '->', '←' => '<-', '≥' => '>=', '≤' => '<=', '✓' => '+', '✗' => 'x', '≠' => '!=', '≈' => '~']);
|
||||||
|
$latin = Transliterator::create('Any-Latin; Latin-ASCII');
|
||||||
|
$out = '';
|
||||||
|
|
||||||
|
foreach (mb_str_split($text) as $char) {
|
||||||
|
$encoded = mb_convert_encoding($char, 'Windows-1252', 'UTF-8');
|
||||||
|
$out .= $encoded === '?' && $char !== '?' ? ($latin?->transliterate($char) ?: '?') : $char;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Beginn einer neuen Seite: der Satz steht wieder am oberen Rand. */
|
||||||
|
public function restart(): void
|
||||||
|
{
|
||||||
|
$this->y = $this->top;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function room(float $needed): void
|
||||||
|
{
|
||||||
|
if ($this->y - $needed < $this->bottom) {
|
||||||
|
($this->breakPage)();
|
||||||
|
$this->y = $this->top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Eine Überschrift oder ein kurzer Text in Zeilen nach {@see PdfDocument::wrap()}. `$keep` hält Platz für folgenden Text frei. */
|
||||||
|
public function write(string $text, float $size, bool $bold, float $after, float $keep = 0, ?float $x = null): void
|
||||||
|
{
|
||||||
|
$x ??= $this->left;
|
||||||
|
$lines = PdfDocument::wrap($text, $this->right - $x, $size, $bold);
|
||||||
|
|
||||||
|
if ($keep > 0 && $lines !== []) {
|
||||||
|
$this->room(count($lines) * ($size + 4) + $keep);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
$this->room($size + 4);
|
||||||
|
$this->pdf->text($x, $this->y, $line, $size, $bold);
|
||||||
|
$this->y -= $size + 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->y -= $after;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blöcke aus {@see FormattedText::blocks()}: Absatz, Zwischenüberschrift, Zitat, Listen, Tabelle und Bild.
|
||||||
|
*
|
||||||
|
* @param list<array<string, mixed>> $blocks
|
||||||
|
*/
|
||||||
|
public function formatted(array $blocks, ?float $x = null, float $size = 10.5): void
|
||||||
|
{
|
||||||
|
$x ??= $this->left;
|
||||||
|
|
||||||
|
foreach ($blocks as $block) {
|
||||||
|
match ($block['type']) {
|
||||||
|
'heading' => $this->headingBlock($block, $x, $size),
|
||||||
|
'quote' => $this->runs($block['runs'], $x + 14, $size, italic: true, after: 5),
|
||||||
|
'bullets' => $this->listItems($block['items'], fn (int $n): string => '•', $x, $size),
|
||||||
|
'numbered' => $this->listItems($block['items'], fn (int $n): string => $n.'.', $x, $size),
|
||||||
|
'table' => $this->table($block['rows'], $x),
|
||||||
|
'image' => $this->image($block, $x),
|
||||||
|
default => $this->runs($block['runs'] ?? [], $x, $size, after: 5),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $block
|
||||||
|
*/
|
||||||
|
private function headingBlock(array $block, float $x, float $size): void
|
||||||
|
{
|
||||||
|
// Stufe 3 ist die größte Zwischenüberschrift, Stufe 6 hat Textgröße (und steht kursiv).
|
||||||
|
$level = max(3, min(6, (int) ($block['level'] ?? 3)));
|
||||||
|
$heading = $size + [3 => 2.0, 4 => 1.0, 5 => 0.5, 6 => 0.0][$level];
|
||||||
|
$gap = [3 => 6.0, 4 => 4.0, 5 => 3.0, 6 => 2.0][$level];
|
||||||
|
|
||||||
|
// Eine Zwischenüberschrift bleibt bei ihrem Text: mindestens zwei Zeilen müssen mit auf die Seite.
|
||||||
|
$this->room($gap + $heading + 4 + 2 * ($size + 4));
|
||||||
|
$this->y -= $gap;
|
||||||
|
|
||||||
|
if ($this->onHeading !== null && isset($block['anchor'])) {
|
||||||
|
($this->onHeading)($block, $this->y + $heading);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->runs($block['runs'], $x, $heading, bold: true, italic: $level === 6, after: 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<list<array{text: string, bold: bool, italic: bool, href: ?string}>> $items
|
||||||
|
* @param callable(int): string $marker
|
||||||
|
*/
|
||||||
|
public function listItems(array $items, callable $marker, ?float $x = null, float $size = 10.5): void
|
||||||
|
{
|
||||||
|
$x ??= $this->left;
|
||||||
|
|
||||||
|
foreach ($items as $index => $item) {
|
||||||
|
$this->room(14);
|
||||||
|
$this->pdf->text($x + 4, $this->y, $marker($index + 1), $size);
|
||||||
|
$this->runs($item, $x + 18, $size, after: 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->y -= 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt Textabschnitte mit fett und kursiv in Zeilen um und zeichnet sie. Ein Link ist unterstrichen und anklickbar; die
|
||||||
|
* vollständige Adresse hängt am Link und bleibt auch über Zeilenumbrüche zusammen. Gedruckt steht die Adresse nur in
|
||||||
|
* Kurzform ({@see self::shortAddress()}), damit der PDF-Betrachter keine umgebrochene Adresse im Text erraten muss.
|
||||||
|
*
|
||||||
|
* @param list<array{text: string, bold: bool, italic: bool, href: ?string}> $runs
|
||||||
|
*/
|
||||||
|
public function runs(array $runs, float $x, float $size, bool $bold = false, bool $italic = false, float $after = 0): void
|
||||||
|
{
|
||||||
|
foreach ($this->lines($runs, $this->right - $x, $size, $bold, $italic) as $row) {
|
||||||
|
$this->room($size + 4);
|
||||||
|
$this->drawSegments($row, $x, $this->y, $size);
|
||||||
|
$this->y -= $size + 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->y -= $after;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zeichnet die Abschnitte einer Zeile; ein Abschnitt mit Adresse wird unterstrichen und anklickbar.
|
||||||
|
*
|
||||||
|
* @param list<array{0: string, 1: bool, 2: bool, 3?: ?string}> $segments
|
||||||
|
*/
|
||||||
|
private function drawSegments(array $segments, float $x, float $y, float $size, bool $forceBold = false): void
|
||||||
|
{
|
||||||
|
foreach ($segments as $segment) {
|
||||||
|
[$text, $isBold, $isItalic] = $segment;
|
||||||
|
$href = $segment[3] ?? null;
|
||||||
|
$isBold = $isBold || $forceBold;
|
||||||
|
$this->pdf->text($x, $y, $text, $size, $isBold, $isItalic);
|
||||||
|
|
||||||
|
if ($href !== null && trim($text) !== '') {
|
||||||
|
$start = $x + PdfDocument::exactWidth(substr($text, 0, strlen($text) - strlen(ltrim($text))), $size, $isBold);
|
||||||
|
$width = PdfDocument::exactWidth(trim($text), $size, $isBold);
|
||||||
|
$this->pdf->uriLink($start, $y - 2, $width, $size + 3, $href);
|
||||||
|
$this->pdf->line($start, $y - 1.5, $start + $width, $y - 1.5, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
$x += PdfDocument::exactWidth($text, $size, $isBold);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kurzform einer Adresse für den Druck: ohne Schema und „www.“, ohne abschließenden Schrägstrich, höchstens
|
||||||
|
* `$max` Zeichen (sonst mit „…“). Ohne „https://“ erkennt kein PDF-Betrachter sie selbst als Link.
|
||||||
|
*/
|
||||||
|
public static function shortAddress(string $address, int $max = 42): string
|
||||||
|
{
|
||||||
|
$short = (string) preg_replace('#^(?:https?://|mailto:)(?:www\.)?#i', '', trim(self::printable($address)));
|
||||||
|
$short = rtrim($short, '/');
|
||||||
|
|
||||||
|
return mb_strlen($short) > $max ? rtrim(mb_substr($short, 0, $max - 1), '/.-?&=#').'…' : $short;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ist der Linktext selbst eine Adresse (mit Schema oder „www.“)? */
|
||||||
|
private static function isAddress(string $text): bool
|
||||||
|
{
|
||||||
|
return preg_match('#^(?:https?://|mailto:|www\.)#i', trim($text)) === 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zeilen aus Textabschnitten für eine Breite. Die Breite kommt aus den Schriftbreiten der Helvetica
|
||||||
|
* ({@see PdfDocument::exactWidth()}), damit verschiedene Schnitte in einer Zeile ohne Lücken aneinanderstoßen.
|
||||||
|
*
|
||||||
|
* @param list<array{text: string, bold: bool, italic: bool, href: ?string}> $runs
|
||||||
|
* @return list<list<array{0: string, 1: bool, 2: bool, 3: ?string}>>
|
||||||
|
*/
|
||||||
|
public function lines(array $runs, float $maxWidth, float $size, bool $bold = false, bool $italic = false): array
|
||||||
|
{
|
||||||
|
$lines = [];
|
||||||
|
$line = [];
|
||||||
|
$width = 0.0;
|
||||||
|
$pendingSpace = false;
|
||||||
|
$count = count($runs);
|
||||||
|
|
||||||
|
$flush = function () use (&$lines, &$line, &$width, &$pendingSpace): void {
|
||||||
|
if ($line !== []) {
|
||||||
|
$lines[] = $line;
|
||||||
|
}
|
||||||
|
|
||||||
|
$line = [];
|
||||||
|
$width = 0.0;
|
||||||
|
$pendingSpace = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
$place = function (string $word, bool $isBold, bool $isItalic, ?string $href = null) use (&$line, &$width, &$pendingSpace, $maxWidth, $size, $flush): void {
|
||||||
|
$space = $pendingSpace && $line !== [] ? ' ' : '';
|
||||||
|
$need = PdfDocument::exactWidth($space.$word, $size, $isBold);
|
||||||
|
|
||||||
|
if ($line !== [] && $width + $need > $maxWidth) {
|
||||||
|
$flush();
|
||||||
|
$space = '';
|
||||||
|
$need = PdfDocument::exactWidth($word, $size, $isBold);
|
||||||
|
}
|
||||||
|
|
||||||
|
while ($need > $maxWidth && mb_strlen($word) > 1) {
|
||||||
|
$cut = mb_strlen($word) - 1;
|
||||||
|
|
||||||
|
while ($cut > 1 && PdfDocument::exactWidth(mb_substr($word, 0, $cut), $size, $isBold) > $maxWidth) {
|
||||||
|
$cut--;
|
||||||
|
}
|
||||||
|
|
||||||
|
$line[] = [mb_substr($word, 0, $cut), $isBold, $isItalic, $href];
|
||||||
|
$flush();
|
||||||
|
$word = mb_substr($word, $cut);
|
||||||
|
$need = PdfDocument::exactWidth($word, $size, $isBold);
|
||||||
|
}
|
||||||
|
|
||||||
|
$last = $line === [] ? null : $line[array_key_last($line)];
|
||||||
|
|
||||||
|
if ($last !== null && $last[1] === $isBold && $last[2] === $isItalic && $last[3] === $href) {
|
||||||
|
$line[array_key_last($line)][0] .= $space.$word;
|
||||||
|
} else {
|
||||||
|
$line[] = [$space.$word, $isBold, $isItalic, $href];
|
||||||
|
}
|
||||||
|
|
||||||
|
$width += $need;
|
||||||
|
$pendingSpace = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach ($runs as $index => $run) {
|
||||||
|
$isBold = $bold || $run['bold'];
|
||||||
|
$isItalic = $italic || $run['italic'];
|
||||||
|
|
||||||
|
$href = $run['href'] !== null && trim($run['href']) !== '' ? self::printable($run['href']) : null;
|
||||||
|
$text = self::printable($run['text']);
|
||||||
|
$isAddress = $href !== null && self::isAddress($text);
|
||||||
|
|
||||||
|
// Ein Linktext, der selbst eine Adresse ist, steht in Kurzform; die ganze Adresse hängt am Link.
|
||||||
|
if ($isAddress) {
|
||||||
|
$text = (preg_match('#^\s#u', $text) === 1 ? ' ' : '').self::shortAddress($text).(preg_match('#\s$#u', $text) === 1 ? ' ' : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (preg_split('/(\s+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) ?: [] as $token) {
|
||||||
|
if (trim($token) !== '') {
|
||||||
|
$place($token, $isBold, $isItalic, $href);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str_contains($token, "\n")) {
|
||||||
|
$flush();
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pendingSpace = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$nextHref = $index + 1 < $count ? $runs[$index + 1]['href'] : null;
|
||||||
|
|
||||||
|
// Zeigt der Linktext die Adresse schon, steht sie nicht noch einmal in Klammern (verglichen, wie sie gedruckt wird).
|
||||||
|
if ($href !== null && $nextHref !== $run['href'] && ! $isAddress && ! str_contains(mb_strtolower($text), mb_strtolower(self::shortAddress($href)))) {
|
||||||
|
$pendingSpace = true;
|
||||||
|
$place('('.self::shortAddress($href).')', false, false, $href);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$flush();
|
||||||
|
|
||||||
|
return $lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ein Bild in Breite der Spalte, höchstens 320 Punkt hoch. Ein Bild lässt sich nicht teilen: Es steht ganz auf einer
|
||||||
|
* Seite. Kann das Bild nicht gezeigt werden, steht an seiner Stelle der Hinweis.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $block
|
||||||
|
*/
|
||||||
|
private function image(array $block, float $x): void
|
||||||
|
{
|
||||||
|
$found = $this->images === null ? null : ($this->images)((int) $block['id']);
|
||||||
|
|
||||||
|
if ($found === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! isset($found['jpeg'])) {
|
||||||
|
$this->runs([['text' => '['.($found['note'] ?? 'Bild nicht verfügbar').']', 'bold' => false, 'italic' => true, 'href' => null]], $x, 9.5, after: 5);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$available = $this->right - $x;
|
||||||
|
$scale = min(1.0, $available / max(1, $found['width']), 320.0 / max(1, $found['height']));
|
||||||
|
$width = max(1.0, $found['width'] * $scale);
|
||||||
|
$height = max(1.0, $found['height'] * $scale);
|
||||||
|
|
||||||
|
$this->room($height + 16);
|
||||||
|
$this->pdf->image($x, $this->y + 4 - $height, $width, $height, $found['jpeg'], $found['width'], $found['height']);
|
||||||
|
$this->y -= $height + 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eine Tabelle mit Rahmen. Die Spaltenbreiten folgen dem Inhalt (Spalten mit kurzem Text bleiben schmal), Verbindungen
|
||||||
|
* über Spalten und Zeilen werden gesetzt. Eine Zeile bleibt zusammen; auf jeder Folgeseite stehen die Kopfzeilen
|
||||||
|
* erneut. Ist eine einzelne Zeile höher als eine Seite, erscheint ihr Inhalt als Fließtext.
|
||||||
|
*
|
||||||
|
* @param list<list<array<string, mixed>>> $rows
|
||||||
|
*/
|
||||||
|
private function table(array $rows, float $x): void
|
||||||
|
{
|
||||||
|
if ($this->depth > 0 || $rows === []) {
|
||||||
|
// Tabellen in Tabellen kennt der Editor nicht; sicherheitshalber als Fließtext.
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
foreach ($row as $cell) {
|
||||||
|
$this->formatted($cell['blocks'], $x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$size = 9.5;
|
||||||
|
$pad = 3.5;
|
||||||
|
$lineHeight = $size + 3;
|
||||||
|
$grid = $this->grid($rows);
|
||||||
|
$columns = $grid['columns'];
|
||||||
|
$widths = $this->columnWidths($grid['cells'], $columns, $this->right - $x, $size, $pad);
|
||||||
|
$headRows = 0;
|
||||||
|
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
if ($row !== [] && count(array_filter($row, fn (array $cell): bool => $cell['header'])) === count($row)) {
|
||||||
|
$headRows++;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$headRows = $headRows === count($rows) ? 0 : $headRows;
|
||||||
|
$prepared = [];
|
||||||
|
|
||||||
|
foreach ($grid['cells'] as $cell) {
|
||||||
|
$inner = array_sum(array_slice($widths, $cell['column'], $cell['colspan'])) - 2 * $pad;
|
||||||
|
$this->depth++;
|
||||||
|
$cell['lines'] = $this->cellLines($cell['blocks'], max(10.0, $inner), $size, $cell['header']);
|
||||||
|
$this->depth--;
|
||||||
|
$cell['height'] = max($lineHeight, array_sum(array_column($cell['lines'], 'height'))) + 2 * $pad;
|
||||||
|
$prepared[] = $cell;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rowCount = count($rows);
|
||||||
|
$heights = array_fill(0, $rowCount, $lineHeight + 2 * $pad);
|
||||||
|
|
||||||
|
foreach ($prepared as $cell) {
|
||||||
|
if ($cell['rowspan'] === 1) {
|
||||||
|
$heights[$cell['row']] = max($heights[$cell['row']], $cell['height']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($prepared as $cell) {
|
||||||
|
if ($cell['rowspan'] > 1) {
|
||||||
|
$last = min($rowCount - 1, $cell['row'] + $cell['rowspan'] - 1);
|
||||||
|
$have = array_sum(array_slice($heights, $cell['row'], $last - $cell['row'] + 1));
|
||||||
|
$heights[$last] += max(0.0, $cell['height'] - $have);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$pageHeight = $this->top - $this->bottom;
|
||||||
|
|
||||||
|
if (max($heights) > $pageHeight - 8) {
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
foreach ($row as $cell) {
|
||||||
|
$this->formatted($cell['blocks'], $x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$drawRows = function (int $from, int $to) use ($prepared, $widths, $heights, $x, $size, $pad): void {
|
||||||
|
$y = $this->y;
|
||||||
|
|
||||||
|
for ($r = $from; $r <= $to; $r++) {
|
||||||
|
foreach ($prepared as $cell) {
|
||||||
|
if ($cell['row'] !== $r) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cellLeft = $x + array_sum(array_slice($widths, 0, $cell['column']));
|
||||||
|
$cellWidth = array_sum(array_slice($widths, $cell['column'], $cell['colspan']));
|
||||||
|
$cellHeight = array_sum(array_slice($heights, $r, $cell['rowspan']));
|
||||||
|
$this->frame($cellLeft, $y - $cellHeight, $cellWidth, $cellHeight, $cell['header']);
|
||||||
|
$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']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cursor = $cellLeft + $pad + $line['indent'];
|
||||||
|
|
||||||
|
$this->drawSegments($line['segments'], $cursor, $textY, $size, $cell['header']);
|
||||||
|
|
||||||
|
$textY -= $line['height'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$y -= $heights[$r];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->y = $y;
|
||||||
|
};
|
||||||
|
|
||||||
|
$this->room($heights[0] + ($rowCount > 1 ? min($heights[1], 40.0) : 0));
|
||||||
|
|
||||||
|
for ($r = 0; $r < $rowCount; $r++) {
|
||||||
|
// Zeilen, die eine Verbindung über Zeilen zusammenhält, werden gemeinsam gesetzt.
|
||||||
|
$end = $r;
|
||||||
|
|
||||||
|
do {
|
||||||
|
$before = $end;
|
||||||
|
|
||||||
|
foreach ($prepared as $cell) {
|
||||||
|
if ($cell['row'] <= $end && $end < $cell['row'] + $cell['rowspan'] - 1) {
|
||||||
|
$end = min($rowCount - 1, $cell['row'] + $cell['rowspan'] - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while ($end !== $before);
|
||||||
|
|
||||||
|
$span = $end - $r + 1;
|
||||||
|
$need = array_sum(array_slice($heights, $r, $span));
|
||||||
|
|
||||||
|
if ($this->y - $need < $this->bottom) {
|
||||||
|
($this->breakPage)();
|
||||||
|
$this->y = $this->top;
|
||||||
|
|
||||||
|
if ($headRows > 0 && $r >= $headRows) {
|
||||||
|
$drawRows(0, $headRows - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$drawRows($r, $r + $span - 1);
|
||||||
|
$r += $span - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->y -= 18;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function frame(float $x, float $y, float $w, float $h, bool $header): void
|
||||||
|
{
|
||||||
|
if ($header) {
|
||||||
|
$this->pdf->fillRect($x, $y, $w, $h, 0.92);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pdf->line($x, $y, $x + $w, $y, 0.4);
|
||||||
|
$this->pdf->line($x, $y + $h, $x + $w, $y + $h, 0.4);
|
||||||
|
$this->pdf->line($x, $y, $x, $y + $h, 0.4);
|
||||||
|
$this->pdf->line($x + $w, $y, $x + $w, $y + $h, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Weist jeder Zelle ihre Spalte zu; Verbindungen über Zeilen belegen die Spalte in den Folgezeilen mit.
|
||||||
|
*
|
||||||
|
* @param list<list<array<string, mixed>>> $rows
|
||||||
|
* @return array{columns: int, cells: list<array<string, mixed>>}
|
||||||
|
*/
|
||||||
|
private function grid(array $rows): array
|
||||||
|
{
|
||||||
|
$occupied = [];
|
||||||
|
$cells = [];
|
||||||
|
$columns = 0;
|
||||||
|
|
||||||
|
foreach ($rows as $r => $row) {
|
||||||
|
$column = 0;
|
||||||
|
|
||||||
|
foreach ($row as $cell) {
|
||||||
|
while (isset($occupied[$r][$column])) {
|
||||||
|
$column++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$colspan = max(1, (int) $cell['colspan']);
|
||||||
|
$rowspan = max(1, (int) $cell['rowspan']);
|
||||||
|
|
||||||
|
for ($dr = 0; $dr < $rowspan; $dr++) {
|
||||||
|
for ($dc = 0; $dc < $colspan; $dc++) {
|
||||||
|
$occupied[$r + $dr][$column + $dc] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$cells[] = $cell + ['row' => $r, 'column' => $column] + ['colspan' => $colspan, 'rowspan' => $rowspan];
|
||||||
|
$column += $colspan;
|
||||||
|
$columns = max($columns, $column);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['columns' => max(1, $columns), 'cells' => $cells];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spaltenbreiten nach Inhalt: Jede Spalte braucht mindestens ihr längstes Wort und wünscht sich die Breite ihres
|
||||||
|
* längsten Zelltexts. Reicht der Platz, wird der Rest gleichmäßig verteilt; sonst teilt sich der Mangel nach Wunsch auf.
|
||||||
|
*
|
||||||
|
* @param list<array<string, mixed>> $cells
|
||||||
|
* @return list<float>
|
||||||
|
*/
|
||||||
|
private function columnWidths(array $cells, int $columns, float $available, float $size, float $pad): array
|
||||||
|
{
|
||||||
|
$min = array_fill(0, $columns, 24.0);
|
||||||
|
$want = array_fill(0, $columns, 24.0);
|
||||||
|
|
||||||
|
foreach ($cells as $cell) {
|
||||||
|
if ($cell['colspan'] !== 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$text = self::printable($this->cellText($cell['blocks']));
|
||||||
|
$widest = 0.0;
|
||||||
|
|
||||||
|
foreach (preg_split('/\s+/u', $text) ?: [] as $word) {
|
||||||
|
$widest = max($widest, PdfDocument::exactWidth($word, $size, (bool) $cell['header']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$c = $cell['column'];
|
||||||
|
$min[$c] = max($min[$c], $widest + 2 * $pad + 1);
|
||||||
|
$want[$c] = max($want[$c], PdfDocument::exactWidth($text, $size, (bool) $cell['header']) + 2 * $pad + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$want = array_map(fn (float $w, float $m): float => max($w, $m), $want, $min);
|
||||||
|
|
||||||
|
if (array_sum($min) >= $available) {
|
||||||
|
$scale = $available / array_sum($min);
|
||||||
|
|
||||||
|
return array_map(fn (float $w): float => $w * $scale, $min);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_sum($want) <= $available) {
|
||||||
|
$extra = ($available - array_sum($want)) / $columns;
|
||||||
|
|
||||||
|
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);
|
||||||
|
$open = array_keys($min);
|
||||||
|
usort($open, fn (int $a, int $b): int => ($want[$a] - $min[$a]) <=> ($want[$b] - $min[$b]));
|
||||||
|
|
||||||
|
foreach ($open as $position => $c) {
|
||||||
|
$share = $room / (count($open) - $position);
|
||||||
|
$give = min($want[$c] - $min[$c], $share);
|
||||||
|
$widths[$c] += $give;
|
||||||
|
$room -= $give;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $widths;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<array<string, mixed>> $blocks
|
||||||
|
*/
|
||||||
|
private function cellText(array $blocks): string
|
||||||
|
{
|
||||||
|
$out = [];
|
||||||
|
|
||||||
|
foreach ($blocks as $block) {
|
||||||
|
$out[] = match ($block['type']) {
|
||||||
|
'bullets', 'numbered' => implode(' ', array_map(fn (array $item): string => implode('', array_column($item, 'text')), $block['items'])),
|
||||||
|
'table', 'image' => '',
|
||||||
|
default => implode('', array_column($block['runs'] ?? [], 'text')),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return trim((string) preg_replace('/\s+/u', ' ', implode(' ', $out)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<array<string, mixed>> $blocks
|
||||||
|
* @return list<array<string, mixed>>
|
||||||
|
*/
|
||||||
|
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, '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, 'height' => $lineHeight];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use App\Domain\Entitlement\Grant;
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Bilder eines PDF: löst jedes Bild einmal auf und merkt sich, welche Bildfassungen tatsächlich gedruckt wurden,
|
||||||
|
* damit der Ausgabenachweis sie wie jede andere Fassung des PDF führt.
|
||||||
|
*/
|
||||||
|
final class PdfImages
|
||||||
|
{
|
||||||
|
/** @var array<int, array{jpeg?: string, width?: int, height?: int, note?: string, grant: ?Grant, version: ?ContentElementVersion}|null> */
|
||||||
|
private array $resolved = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Closure(int): ?array{jpeg?: string, width?: int, height?: int, note?: string, grant: ?Grant, version: ?ContentElementVersion} $resolve
|
||||||
|
*/
|
||||||
|
public function __construct(private readonly Closure $resolve) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{jpeg?: string, width?: int, height?: int, note?: string}|null
|
||||||
|
*/
|
||||||
|
public function __invoke(int $id): ?array
|
||||||
|
{
|
||||||
|
if (! array_key_exists($id, $this->resolved)) {
|
||||||
|
$this->resolved[$id] = ($this->resolve)($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->resolved[$id];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{version: ContentElementVersion, grant: Grant}>
|
||||||
|
*/
|
||||||
|
public function used(): array
|
||||||
|
{
|
||||||
|
$used = [];
|
||||||
|
|
||||||
|
foreach ($this->resolved as $found) {
|
||||||
|
if ($found !== null && isset($found['jpeg']) && $found['version'] instanceof ContentElementVersion && $found['grant'] instanceof Grant) {
|
||||||
|
$used[] = ['version' => $found['version'], 'grant' => $found['grant']];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $used;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vorlage für das PDF eines Dokuments (ADR-51, Nachtrag): Titelseite, grafische Kopf- und Fußzeile und Standardvermerke.
|
||||||
|
* Die Vorlage bestimmt nur das Aussehen. Der Inhalt, auch Ausgabe, Datum und Copyright-Vermerk der Dokumentfassung, gehört
|
||||||
|
* zur Fassung ({@see DocumentMeta}); die Vorlage liefert nur den Standard-Vermerk, wenn die Fassung keinen eigenen hat.
|
||||||
|
*/
|
||||||
|
class PdfTemplate extends Model
|
||||||
|
{
|
||||||
|
public const KIND_DOCUMENT = 'dokument';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
'kind',
|
||||||
|
'show_cover',
|
||||||
|
'header_version_id',
|
||||||
|
'footer_version_id',
|
||||||
|
'cover_version_id',
|
||||||
|
'header_element_id',
|
||||||
|
'footer_element_id',
|
||||||
|
'cover_element_id',
|
||||||
|
'header_align',
|
||||||
|
'footer_align',
|
||||||
|
'header_logo_height',
|
||||||
|
'footer_logo_height',
|
||||||
|
'toc_mode',
|
||||||
|
'toc_depth',
|
||||||
|
'publisher',
|
||||||
|
'copyright',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return ['show_cover' => 'boolean'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public const SLOTS = ['header', 'footer', 'cover'];
|
||||||
|
|
||||||
|
/** Anordnung von Kopf- und Fußgrafik: Band in voller Seitenbreite oder Logo links oder rechts. */
|
||||||
|
public const ALIGNMENTS = ['full', 'left', 'right'];
|
||||||
|
|
||||||
|
public const LOGO_MIN = 16;
|
||||||
|
|
||||||
|
public const LOGO_MAX = 100;
|
||||||
|
|
||||||
|
public const LOGO_DEFAULT = 40;
|
||||||
|
|
||||||
|
/** Inhaltsverzeichnis: nur bei mehr als einem Eintrag, immer oder nie. */
|
||||||
|
public const TOC_MODES = ['auto', 'always', 'never'];
|
||||||
|
|
||||||
|
/** Tiefe des Verzeichnisses: 2 = nur Kapitel und Unterkapitel, 3 bis 6 = zusätzlich die Überschriften bis zu dieser Stufe. */
|
||||||
|
public const TOC_DEPTH_MIN = 2;
|
||||||
|
|
||||||
|
public const TOC_DEPTH_MAX = 6;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Darstellung des gedruckten Inhaltsverzeichnisses.
|
||||||
|
*
|
||||||
|
* @return array{mode: string, depth: int}
|
||||||
|
*/
|
||||||
|
public function toc(): array
|
||||||
|
{
|
||||||
|
return self::normalizeToc((string) $this->getAttribute('toc_mode'), (int) $this->getAttribute('toc_depth'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{mode: string, depth: int}
|
||||||
|
*/
|
||||||
|
public static function normalizeToc(?string $mode, int|string|null $depth): array
|
||||||
|
{
|
||||||
|
$depth = (int) $depth;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'mode' => in_array($mode, self::TOC_MODES, true) ? (string) $mode : 'auto',
|
||||||
|
'depth' => $depth < 1 ? self::TOC_DEPTH_MAX : max(self::TOC_DEPTH_MIN, min(self::TOC_DEPTH_MAX, $depth)),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anordnung und Logohöhe (Punkt) von Kopf oder Fuß; ungültige Werte fallen auf die Vorgabe zurück.
|
||||||
|
*
|
||||||
|
* @return array{align: string, height: int}
|
||||||
|
*/
|
||||||
|
public function layout(string $slot): array
|
||||||
|
{
|
||||||
|
return self::normalizeLayout((string) $this->getAttribute($slot.'_align'), (int) $this->getAttribute($slot.'_logo_height'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{align: string, height: int}
|
||||||
|
*/
|
||||||
|
public static function normalizeLayout(?string $align, int|string|null $height): array
|
||||||
|
{
|
||||||
|
$height = (int) $height;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'align' => in_array($align, self::ALIGNMENTS, true) ? (string) $align : 'full',
|
||||||
|
'height' => $height < 1 ? self::LOGO_DEFAULT : max(self::LOGO_MIN, min(self::LOGO_MAX, $height)),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Das Bild eines Bildfelds als Ziel des Pickers: `element:<Fassung>`, `medium:<Medium>` oder null.
|
||||||
|
*/
|
||||||
|
public function target(string $slot): ?string
|
||||||
|
{
|
||||||
|
$version = $this->getAttribute($slot.'_version_id');
|
||||||
|
$element = $this->getAttribute($slot.'_element_id');
|
||||||
|
|
||||||
|
return $version !== null ? 'element:'.$version : ($element !== null ? 'medium:'.$element : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Spaltenwerte eines Bildfelds für ein Ziel des Pickers.
|
||||||
|
*
|
||||||
|
* @return array<string, int|null>
|
||||||
|
*/
|
||||||
|
public static function columns(string $slot, ?string $target): array
|
||||||
|
{
|
||||||
|
$ref = TemplateImage::parse($target);
|
||||||
|
|
||||||
|
return [
|
||||||
|
$slot.'_version_id' => ($ref['type'] ?? null) === 'version' ? $ref['id'] : null,
|
||||||
|
$slot.'_element_id' => ($ref['type'] ?? null) === 'medium' ? $ref['id'] : null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function headerVersion(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ContentElementVersion::class, 'header_version_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function footerVersion(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ContentElementVersion::class, 'footer_version_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function coverVersion(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ContentElementVersion::class, 'cover_version_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function compositions(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Composition::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use App\Filament\Support\EditorialCatalog;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ein Bild einer PDF-Vorlage (ADR-51, Nachtrag). Es kommt aus dem Medienmanager in einer von zwei Formen, die der gemeinsame
|
||||||
|
* Picker als Ziel liefert:
|
||||||
|
*
|
||||||
|
* - `element:<Fassung>`: ein Bild mit Inhaltsfassung (Datei im abgeleiteten Bestand), gleich in welchem Stand; nur ein gesperrtes Bild nicht,
|
||||||
|
* - `medium:<Medium>`: ein Bild ohne Inhaltsfassung, also ein Präsentationsmedium oder ein für die Website freigegebenes Bild. Gedruckt wird
|
||||||
|
* die für die Website freigegebene Datei, sonst die Präsentationsdatei.
|
||||||
|
*
|
||||||
|
* Jedes Bild mit vorhandener Datei lässt sich verwenden. Das Bild ist Gestaltung der Vorlage und kein lizenzierter Inhalt; es geht nicht über
|
||||||
|
* die Rechteprüfung der Mitglieder und braucht keine Inhaltsfassung.
|
||||||
|
*/
|
||||||
|
final class TemplateImage
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array{type: 'version'|'medium', id: int}|null
|
||||||
|
*/
|
||||||
|
public static function parse(?string $target): ?array
|
||||||
|
{
|
||||||
|
if ($target !== null && preg_match('/^(element|medium):(\d+)$/', $target, $match) === 1) {
|
||||||
|
return ['type' => $match[1] === 'element' ? 'version' : 'medium', 'id' => (int) $match[2]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Die Bilddatei als Bytes, oder null, wenn sie nicht vorliegt. */
|
||||||
|
public static function bytes(?string $target): ?string
|
||||||
|
{
|
||||||
|
$source = self::source($target);
|
||||||
|
|
||||||
|
return $source === null ? null : (string) Storage::disk($source['disk'])->get($source['path']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Warum sich das Bild nicht verwenden lässt; null, wenn es geht. */
|
||||||
|
public static function problem(?string $target): ?string
|
||||||
|
{
|
||||||
|
$ref = self::parse($target);
|
||||||
|
|
||||||
|
if ($ref === null) {
|
||||||
|
return 'Das ist kein Bild des Medienmanagers.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ref['type'] === 'version') {
|
||||||
|
$version = ContentElementVersion::query()->with('element')->find($ref['id']);
|
||||||
|
|
||||||
|
if (! $version instanceof ContentElementVersion || $version->element === null || $version->element->output_class !== 'bild') {
|
||||||
|
return 'Das ist kein Bild des Medienmanagers.';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestaltung braucht keine Freigabe der Fassung; nur ein bewusst gesperrtes Bild bleibt außen vor.
|
||||||
|
if ($version->status === ContentVersionStatus::Gesperrt) {
|
||||||
|
return 'Dieses Bild ist deaktiviert.';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$element = ContentElement::query()->find($ref['id']);
|
||||||
|
|
||||||
|
if (! $element instanceof ContentElement || $element->output_class !== 'bild' || $element->archived_at !== null) {
|
||||||
|
return 'Das ist kein Bild des Medienmanagers.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::source($target) === null ? 'Die Bilddatei liegt nicht vor.' : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function title(?string $target): string
|
||||||
|
{
|
||||||
|
$ref = self::parse($target);
|
||||||
|
$element = match ($ref['type'] ?? null) {
|
||||||
|
'version' => ContentElementVersion::query()->with('element')->find($ref['id'])?->element,
|
||||||
|
'medium' => ContentElement::query()->find($ref['id']),
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
|
||||||
|
return $element === null ? '' : (string) ($element->display_title ?: $element->working_title);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Adresse zur Ansicht in der Verwaltung (Vorschau im Formular). */
|
||||||
|
public static function previewUrl(?string $target): ?string
|
||||||
|
{
|
||||||
|
$ref = self::parse($target);
|
||||||
|
|
||||||
|
if ($ref === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ref['type'] === 'version') {
|
||||||
|
return EmbeddedImages::staffSource($ref['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$element = ContentElement::query()->find($ref['id']);
|
||||||
|
|
||||||
|
if (! $element instanceof ContentElement) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($element->website_released_at !== null && $element->website_public_path !== null) {
|
||||||
|
return route('website.media', $element);
|
||||||
|
}
|
||||||
|
|
||||||
|
return app(EditorialCatalog::class)->cardUrl('element', $element->id, $element->thumbnail_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{disk: string, path: string}|null
|
||||||
|
*/
|
||||||
|
private static function source(?string $target): ?array
|
||||||
|
{
|
||||||
|
$ref = self::parse($target);
|
||||||
|
|
||||||
|
if ($ref === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ref['type'] === 'version') {
|
||||||
|
$version = ContentElementVersion::query()->find($ref['id']);
|
||||||
|
$file = $version instanceof ContentElementVersion ? EmbeddedImages::file($version) : null;
|
||||||
|
|
||||||
|
return $file === null ? null : ['disk' => 'media_derived', 'path' => $file];
|
||||||
|
}
|
||||||
|
|
||||||
|
$element = ContentElement::query()->find($ref['id']);
|
||||||
|
|
||||||
|
if (! $element instanceof ContentElement) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$public = (string) $element->website_public_path;
|
||||||
|
|
||||||
|
if ($element->website_released_at !== null && preg_match('#^website/'.$element->id.'/datei\.[a-z0-9]+$#', $public) === 1 && Storage::disk('media_public')->exists($public)) {
|
||||||
|
return ['disk' => 'media_public', 'path' => $public];
|
||||||
|
}
|
||||||
|
|
||||||
|
$preview = (string) $element->thumbnail_path;
|
||||||
|
|
||||||
|
if (str_starts_with($preview, 'vorschau/') && ! str_contains($preview, '..') && Storage::disk('media_derived')->exists($preview)) {
|
||||||
|
return ['disk' => 'media_derived', 'path' => $preview];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
class PublicMaterialReader
|
class PublicMaterialReader
|
||||||
{
|
{
|
||||||
/** Inhaltsarten, die nie öffentlich auf einer Karte erscheinen: Anleitungen für Trainer und die Textabschnitte der Übungen. */
|
/** 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<int, array{id: int, title: string}>|null Element-ID => erstes öffentliches Programm */
|
/** @var array<int, array{id: int, title: string}>|null Element-ID => erstes öffentliches Programm */
|
||||||
private ?array $publicIndex = null;
|
private ?array $publicIndex = null;
|
||||||
|
|||||||
@@ -2,32 +2,27 @@
|
|||||||
|
|
||||||
namespace App\Domain\Cms\Widgets\Support;
|
namespace App\Domain\Cms\Widgets\Support;
|
||||||
|
|
||||||
|
use App\Support\Brand\SymbolCatalog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zulässige Kleingrafiken des Brand-Kits als Auswahl im CMS (ADR-30: nur feste Werte, nie freie Dateinamen).
|
* Zulässige Kleingrafiken des Brand-Kits als Auswahl im CMS (ADR-30: nur feste Werte, nie freie Dateinamen).
|
||||||
*
|
*
|
||||||
* Die Schlüssel sind Dateinamen aus resources/svg/brand/symbole/. Nicht angeboten werden die gelbe Unterstreichung
|
* Die Schlüssel sind Dateinamen aus resources/svg/brand/symbole/, Titel und Gruppen stehen im Katalog
|
||||||
* (eigene Einstellung „Pinselstrich“) und die Signalstrahlen (Markenakzent des Einstiegs). Eine Prüfung im Test stellt
|
* (App\Support\Brand\SymbolCatalog, Datei _katalog.json). Nicht angeboten werden die gelbe Unterstreichung (eigene
|
||||||
* sicher, dass jeder Schlüssel eine vorhandene Datei hat.
|
* Einstellung „Pinselstrich“) und die Signalstrahlen (Markenakzent des Einstiegs). Eine Prüfung im Test stellt sicher,
|
||||||
|
* dass jeder Schlüssel eine vorhandene Datei und einen Katalogeintrag hat.
|
||||||
*/
|
*/
|
||||||
final class HeadingAccent
|
final class HeadingAccent
|
||||||
{
|
{
|
||||||
/** @var array<string, string> */
|
/**
|
||||||
public const SYMBOLS = [
|
* Angebotene Symbole: Schlüssel => Titel, geordnet nach Gruppe. Einzige Quelle für Prüfung und Auswahl.
|
||||||
'bildung' => 'Bildung',
|
*
|
||||||
'buch' => 'Buch',
|
* @return array<string, string>
|
||||||
'download' => 'Download',
|
*/
|
||||||
'filmklappe' => 'Filmklappe',
|
public static function symbols(): array
|
||||||
'filmstreifen' => 'Filmstreifen',
|
{
|
||||||
'gruppe' => 'Gruppe',
|
return SymbolCatalog::options();
|
||||||
'merkblatt' => 'Merkblatt',
|
}
|
||||||
'muskelarm' => 'Starker Arm',
|
|
||||||
'paket' => 'Paket',
|
|
||||||
'pause-hand' => 'Pause (Hand)',
|
|
||||||
'play' => 'Abspielen',
|
|
||||||
'schutzschild' => 'Schutzschild',
|
|
||||||
'sprechblase-fragezeichen' => 'Frage (Sprechblase)',
|
|
||||||
'uebungsblatt' => 'Übungsblatt',
|
|
||||||
];
|
|
||||||
|
|
||||||
/** @var array<string, string> */
|
/** @var array<string, string> */
|
||||||
public const BRUSH = ['brush' => 'Gelber Pinselstrich unter der Überschrift'];
|
public const BRUSH = ['brush' => 'Gelber Pinselstrich unter der Überschrift'];
|
||||||
@@ -36,6 +31,117 @@ final class HeadingAccent
|
|||||||
|
|
||||||
public const BRUSH_LABEL = ['Pinselstrich', 'Gelbe Unterstreichung unter der Überschrift (freigegebenes Motiv aus dem Brand-Kit). Vorgabe: ohne.'];
|
public const BRUSH_LABEL = ['Pinselstrich', 'Gelbe Unterstreichung unter der Überschrift (freigegebenes Motiv aus dem Brand-Kit). Vorgabe: ohne.'];
|
||||||
|
|
||||||
|
/** @var array<string, string> */
|
||||||
|
public const SIZE = [
|
||||||
|
'small' => 'Klein (2,5 rem), links neben dem ganzen Absatz',
|
||||||
|
'medium' => 'Mittel (3,5 rem), links neben dem ganzen Absatz',
|
||||||
|
'large' => 'Groß (5 rem), links neben dem ganzen Absatz',
|
||||||
|
'xlarge' => 'Sehr groß (7 rem), links neben dem ganzen Absatz',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gemeinsame Größenstufen aller Widgets (Kantenlänge des Symbolquadrats): klein 2,5 rem, mittel 3,5 rem, groß 5 rem,
|
||||||
|
* sehr groß 7 rem. Die Werte stehen als --lf-symbol-… in tokens.css; Merkmalszeile, Karten und alle Überschriften-
|
||||||
|
* Widgets verwenden dieselben Schlüssel.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public const STEPS = ['small' => 'Klein', 'medium' => 'Mittel', 'large' => 'Groß', 'xlarge' => 'Sehr groß'];
|
||||||
|
|
||||||
|
public const SIZE_LABEL = ['Größe des Symbols', 'Vorgabe: klein, vor der Überschrift in der Zeile. Klein bis Sehr groß stellen das Symbol links neben Überschrift und Text; bei wenig Platz steht es darüber. Wirkt nur, wenn ein Symbol gewählt ist.'];
|
||||||
|
|
||||||
|
/** @var array<string, string> */
|
||||||
|
public const ALIGN = ['top' => 'Oben', 'center' => 'Mitte', 'bottom' => 'Unten'];
|
||||||
|
|
||||||
|
public const ALIGN_LABEL = ['Ausrichtung des Symbols', 'Senkrechte Lage des Symbols neben dem Absatz. Vorgabe: oben. Wirkt nur bei Symbolen neben dem Absatz (Klein bis Sehr groß).'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Waagerechte Ausrichtung von Inhalten mit Symbol (Merkmalszeile, Karten): links ist die Vorgabe.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public const TEXT_ALIGN = ['left' => 'Linksbündig', 'center' => 'Zentriert', 'right' => 'Rechtsbündig'];
|
||||||
|
|
||||||
|
/** @var array<string, string> */
|
||||||
|
public const LINK_STYLE = ['text' => 'Kleiner Textlink', 'pill' => 'Pille (Schaltfläche)'];
|
||||||
|
|
||||||
|
public const LINK_STYLE_LABEL = ['Darstellung der Links', 'Wie die Links der Merkmale aussehen. Vorgabe: kleiner Textlink. Merkmale ohne Link zeigen nichts.'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Größenstufe eines Symbols links neben dem ganzen Absatz (small, medium, large, xlarge) oder null, wenn das Symbol
|
||||||
|
* klein vor der Überschrift steht. Nur mit gültigem Symbol. Ohne gültige Stufe gilt $default (null = in der Zeile).
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $settings
|
||||||
|
*/
|
||||||
|
public static function sideSize(array $settings, ?string $default = null): ?string
|
||||||
|
{
|
||||||
|
if (self::symbol($settings) === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$size = $settings['symbol_size'] ?? null;
|
||||||
|
|
||||||
|
return is_string($size) && array_key_exists($size, self::SIZE) ? $size : $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alles, was eine Ansicht für Symbol und Absatz braucht: das Symbol, die Stufe neben dem Absatz (oder null), die
|
||||||
|
* senkrechte Lage und die Einstellungen für das kleine Symbol in der Überschrift (leer, wenn das Symbol daneben steht,
|
||||||
|
* damit es nicht doppelt erscheint).
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $settings
|
||||||
|
* @return array{symbol: ?string, side: ?string, align: string, inline: array<string, mixed>}
|
||||||
|
*/
|
||||||
|
public static function lead(array $settings, ?string $defaultSide = null): array
|
||||||
|
{
|
||||||
|
$side = self::sideSize($settings, $defaultSide);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'symbol' => self::symbol($settings),
|
||||||
|
'side' => $side,
|
||||||
|
'align' => self::align($settings),
|
||||||
|
'inline' => $side !== null ? [] : $settings,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Senkrechte Ausrichtung des Symbols neben dem Absatz; ungültig oder leer ergibt oben.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $settings
|
||||||
|
*/
|
||||||
|
public static function align(array $settings): string
|
||||||
|
{
|
||||||
|
$align = $settings['symbol_align'] ?? null;
|
||||||
|
|
||||||
|
return is_string($align) && array_key_exists($align, self::ALIGN) ? $align : 'top';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ausrichtung und Symbolgröße für Inhalte mit Symbol über dem Text (Merkmalszeile, Karten). Ungültige oder fehlende
|
||||||
|
* Werte fallen auf die Vorgaben zurück: linksbündig und mittlere Symbole.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $settings
|
||||||
|
* @return array{align: string, size: string}
|
||||||
|
*/
|
||||||
|
public static function block(array $settings): array
|
||||||
|
{
|
||||||
|
$align = $settings['align'] ?? null;
|
||||||
|
$size = $settings['symbol_size'] ?? null;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'align' => is_string($align) && array_key_exists($align, self::TEXT_ALIGN) ? $align : 'left',
|
||||||
|
'size' => is_string($size) && array_key_exists($size, self::STEPS) ? $size : 'medium',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $settings
|
||||||
|
*/
|
||||||
|
public static function linkStyle(array $settings): string
|
||||||
|
{
|
||||||
|
return ($settings['link_style'] ?? null) === 'pill' ? 'pill' : 'text';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gültiger Symbolname aus den Einstellungen eines Widgets oder null.
|
* Gültiger Symbolname aus den Einstellungen eines Widgets oder null.
|
||||||
*
|
*
|
||||||
@@ -45,7 +151,7 @@ public static function symbol(array $settings): ?string
|
|||||||
{
|
{
|
||||||
$name = $settings['symbol'] ?? null;
|
$name = $settings['symbol'] ?? null;
|
||||||
|
|
||||||
return is_string($name) && array_key_exists($name, self::SYMBOLS) ? $name : null;
|
return is_string($name) && array_key_exists($name, self::symbols()) ? $name : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -93,17 +93,27 @@ public function dataFields(): array
|
|||||||
|
|
||||||
public function settings(): array
|
public function settings(): array
|
||||||
{
|
{
|
||||||
return ['symbol' => HeadingAccent::SYMBOLS];
|
return [
|
||||||
|
'symbol' => HeadingAccent::symbols(),
|
||||||
|
'symbol_size' => HeadingAccent::SIZE,
|
||||||
|
'symbol_align' => HeadingAccent::ALIGN,
|
||||||
|
'accent' => HeadingAccent::BRUSH,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function settingGroups(): array
|
public function settingGroups(): array
|
||||||
{
|
{
|
||||||
return ['Aussehen' => ['symbol']];
|
return ['Aussehen' => ['symbol', 'symbol_size', 'symbol_align', 'accent']];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function settingLabels(): array
|
public function settingLabels(): array
|
||||||
{
|
{
|
||||||
return ['symbol' => HeadingAccent::SYMBOL_LABEL];
|
return [
|
||||||
|
'symbol' => HeadingAccent::SYMBOL_LABEL,
|
||||||
|
'symbol_size' => HeadingAccent::SIZE_LABEL,
|
||||||
|
'symbol_align' => HeadingAccent::ALIGN_LABEL,
|
||||||
|
'accent' => HeadingAccent::BRUSH_LABEL,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clean(array $data, array $refs, WidgetErrors $errors): array
|
public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||||
|
|||||||
@@ -3,15 +3,18 @@
|
|||||||
namespace App\Domain\Cms\Widgets\Types;
|
namespace App\Domain\Cms\Widgets\Types;
|
||||||
|
|
||||||
use App\Domain\Cms\Widgets\RenderContext;
|
use App\Domain\Cms\Widgets\RenderContext;
|
||||||
|
use App\Domain\Cms\Widgets\Support\HeadingAccent;
|
||||||
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
||||||
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
||||||
use App\Domain\Cms\Widgets\Support\SafeUrl;
|
use App\Domain\Cms\Widgets\Support\SafeUrl;
|
||||||
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||||
use App\Domain\Cms\Widgets\WidgetType;
|
use App\Domain\Cms\Widgets\WidgetType;
|
||||||
|
use App\Filament\Support\SymbolField;
|
||||||
use Filament\Forms\Components\Repeater;
|
use Filament\Forms\Components\Repeater;
|
||||||
use Filament\Forms\Components\Textarea;
|
use Filament\Forms\Components\Textarea;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redaktionelle Karten. Die Einträge sind freie redaktionelle Verweise, keine Produkte oder Lizenzartikel.
|
* Redaktionelle Karten. Die Einträge sind freie redaktionelle Verweise, keine Produkte oder Lizenzartikel.
|
||||||
@@ -85,11 +88,33 @@ public function dataRules(): array
|
|||||||
'items.*.title' => ['required', 'string', 'max:120'],
|
'items.*.title' => ['required', 'string', 'max:120'],
|
||||||
'items.*.text' => ['nullable', 'string', 'max:500'],
|
'items.*.text' => ['nullable', 'string', 'max:500'],
|
||||||
'items.*.url' => ['nullable', 'string', 'max:500'],
|
'items.*.url' => ['nullable', 'string', 'max:500'],
|
||||||
|
'items.*.symbol' => ['nullable', 'string', Rule::in(array_keys(HeadingAccent::symbols()))],
|
||||||
'items.*.image' => ['nullable'],
|
'items.*.image' => ['nullable'],
|
||||||
'items.*._upload' => ['nullable'],
|
'items.*._upload' => ['nullable'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function settings(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'symbol_size' => HeadingAccent::STEPS,
|
||||||
|
'align' => HeadingAccent::TEXT_ALIGN,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settingGroups(): array
|
||||||
|
{
|
||||||
|
return ['Aussehen' => ['symbol_size', 'align']];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settingLabels(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'symbol_size' => ['Größe der Symbole', 'Kantenlänge der Symbole auf den Karten, die eins haben: Klein 2,5 rem, Mittel 3,5 rem, Groß 5 rem, Sehr groß 7 rem. Vorgabe: Mittel.'],
|
||||||
|
'align' => ['Ausrichtung', 'Richtet Symbol, Titel und Text jeder Karte aus. Vorgabe: linksbündig.'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function dataFields(): array
|
public function dataFields(): array
|
||||||
{
|
{
|
||||||
[$image, $upload, $status] = ImageRefFields::fields('Bild (optional)');
|
[$image, $upload, $status] = ImageRefFields::fields('Bild (optional)');
|
||||||
@@ -99,6 +124,8 @@ public function dataFields(): array
|
|||||||
->label('Karten')
|
->label('Karten')
|
||||||
->schema([
|
->schema([
|
||||||
TextInput::make('title')->label('Titel')->required()->maxLength(120),
|
TextInput::make('title')->label('Titel')->required()->maxLength(120),
|
||||||
|
SymbolField::make('symbol', 'Symbol (optional)')
|
||||||
|
->helperText('Kleine Grafik aus dem Brand-Kit über dem Titel. Größe und Ausrichtung im Reiter „Darstellung“.'),
|
||||||
Textarea::make('text')->label('Beschreibung')->rows(2)->maxLength(500),
|
Textarea::make('text')->label('Beschreibung')->rows(2)->maxLength(500),
|
||||||
TextInput::make('url')
|
TextInput::make('url')
|
||||||
->label('Linkziel')
|
->label('Linkziel')
|
||||||
@@ -128,10 +155,12 @@ public function clean(array $data, array $refs, WidgetErrors $errors): array
|
|||||||
|
|
||||||
$itemRefs = ImageRefFields::clean(['image' => $item['image'] ?? null, '_upload' => $item['_upload'] ?? null], $errors, errorKey: "data.items.$index.image");
|
$itemRefs = ImageRefFields::clean(['image' => $item['image'] ?? null, '_upload' => $item['_upload'] ?? null], $errors, errorKey: "data.items.$index.image");
|
||||||
|
|
||||||
|
// Der Schlüssel symbol wird nur gespeichert, wenn ein Symbol gewählt ist: Karten ohne Symbol bleiben byteweise wie zuvor.
|
||||||
$data['items'][$index] = [
|
$data['items'][$index] = [
|
||||||
'title' => $item['title'],
|
'title' => $item['title'],
|
||||||
'text' => filled($item['text'] ?? null) ? $item['text'] : null,
|
'text' => filled($item['text'] ?? null) ? $item['text'] : null,
|
||||||
'url' => filled($item['url'] ?? null) ? $item['url'] : null,
|
'url' => filled($item['url'] ?? null) ? $item['url'] : null,
|
||||||
|
...(filled($item['symbol'] ?? null) ? ['symbol' => $item['symbol']] : []),
|
||||||
'image' => $itemRefs['image'],
|
'image' => $itemRefs['image'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -154,6 +183,7 @@ public function resolve(array $widget, RenderContext $context): array
|
|||||||
'title' => $item['title'],
|
'title' => $item['title'],
|
||||||
'text' => $item['text'] ?? null,
|
'text' => $item['text'] ?? null,
|
||||||
'url' => SafeUrl::isSafe($item['url'] ?? null) ? $item['url'] : null,
|
'url' => SafeUrl::isSafe($item['url'] ?? null) ? $item['url'] : null,
|
||||||
|
'symbol' => HeadingAccent::symbol(['symbol' => $item['symbol'] ?? null]),
|
||||||
'imageUrl' => $images->url($item['image'] ?? null, $context->preview),
|
'imageUrl' => $images->url($item['image'] ?? null, $context->preview),
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -162,7 +192,11 @@ public function resolve(array $widget, RenderContext $context): array
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['items' => $items, 'imageNotice' => $notices === [] ? null : implode(' ', $notices)];
|
return [
|
||||||
|
'items' => $items,
|
||||||
|
'layout' => HeadingAccent::block($widget['settings'] ?? []),
|
||||||
|
'imageNotice' => $notices === [] ? null : implode(' ', $notices),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function mediaPaths(array $widget): array
|
public function mediaPaths(array $widget): array
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Domain\Cms\Widgets\Types;
|
namespace App\Domain\Cms\Widgets\Types;
|
||||||
|
|
||||||
|
use App\Domain\Cms\Widgets\Support\HeadingAccent;
|
||||||
use App\Domain\Cms\Widgets\WidgetType;
|
use App\Domain\Cms\Widgets\WidgetType;
|
||||||
use Filament\Forms\Components\Repeater;
|
use Filament\Forms\Components\Repeater;
|
||||||
use Filament\Forms\Components\Textarea;
|
use Filament\Forms\Components\Textarea;
|
||||||
@@ -83,6 +84,29 @@ public function dataFields(): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function settings(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'symbol' => HeadingAccent::symbols(),
|
||||||
|
'symbol_size' => HeadingAccent::SIZE,
|
||||||
|
'symbol_align' => HeadingAccent::ALIGN,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settingGroups(): array
|
||||||
|
{
|
||||||
|
return ['Aussehen' => ['symbol', 'symbol_size', 'symbol_align']];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settingLabels(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'symbol' => ['Symbol neben den Fragen', 'Kleine Grafik aus dem Brand-Kit links neben allen Fragen. Sie ist reine Zierde und wird von Hilfstechnik nicht vorgelesen. Vorgabe: kein Symbol.'],
|
||||||
|
'symbol_size' => ['Größe des Symbols', 'Vorgabe: Mittel. Bei wenig Platz steht das Symbol über den Fragen. Wirkt nur, wenn ein Symbol gewählt ist.'],
|
||||||
|
'symbol_align' => HeadingAccent::ALIGN_LABEL,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function summary(array $widget): string
|
public function summary(array $widget): string
|
||||||
{
|
{
|
||||||
$count = count($widget['data']['items'] ?? []);
|
$count = count($widget['data']['items'] ?? []);
|
||||||
|
|||||||
@@ -4,22 +4,50 @@
|
|||||||
|
|
||||||
use App\Domain\Cms\Widgets\RenderContext;
|
use App\Domain\Cms\Widgets\RenderContext;
|
||||||
use App\Domain\Cms\Widgets\Support\HeadingAccent;
|
use App\Domain\Cms\Widgets\Support\HeadingAccent;
|
||||||
|
use App\Domain\Cms\Widgets\Support\SafeUrl;
|
||||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||||
use App\Domain\Cms\Widgets\WidgetType;
|
use App\Domain\Cms\Widgets\WidgetType;
|
||||||
|
use App\Filament\Support\SymbolField;
|
||||||
use Filament\Forms\Components\Repeater;
|
use Filament\Forms\Components\Repeater;
|
||||||
use Filament\Forms\Components\Select;
|
|
||||||
use Filament\Forms\Components\Textarea;
|
use Filament\Forms\Components\Textarea;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merkmalszeile nach den Entwürfen des Brand-Kits (04_visuelle_entwuerfe): zwei bis vier Merkmale nebeneinander,
|
* Merkmalszeile nach den Entwürfen des Brand-Kits (04_visuelle_entwuerfe): ein bis zwölf Merkmale nebeneinander,
|
||||||
* je mit Symbol, Kurztitel und einem Satz. Die Anzahl der Einträge bestimmt die Spaltenzahl; es gibt keine
|
* je mit Symbol, Kurztitel und einem Satz. Die Spaltenzahl folgt der Anzahl der Einträge und der Breite; es gibt keine
|
||||||
* zweite Einstellung dafür. Das Symbol stammt aus der festen Auswahl (HeadingAccent::SYMBOLS), nie aus einem
|
* zweite Einstellung dafür. Das Symbol stammt aus der festen Auswahl (HeadingAccent::symbols()), nie aus einem
|
||||||
* freien Dateinamen.
|
* freien Dateinamen.
|
||||||
*/
|
*/
|
||||||
class FeaturesWidget extends WidgetType
|
class FeaturesWidget extends WidgetType
|
||||||
{
|
{
|
||||||
|
private const DEFAULT_LINK_LABEL = 'Mehr erfahren';
|
||||||
|
|
||||||
|
/** @var array<string, string> */
|
||||||
|
public const ALIGN = HeadingAccent::TEXT_ALIGN;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Größenstufen der Symbole, überall dieselben (HeadingAccent::STEPS): klein 2,5 rem, mittel 3,5 rem (Vorgabe), groß
|
||||||
|
* 5 rem, sehr groß 7 rem.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public const SYMBOL_SIZE = HeadingAccent::STEPS;
|
||||||
|
|
||||||
|
/** @var array<string, string> */
|
||||||
|
public const DIVIDER = ['line' => 'Feiner Strich zwischen den Merkmalen'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gültige Layout-Einstellungen mit Vorgaben (links, mittel, ohne Strich); alles andere fällt auf die Vorgabe zurück.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $settings
|
||||||
|
* @return array{align: string, size: string, divider: bool}
|
||||||
|
*/
|
||||||
|
public static function layout(array $settings): array
|
||||||
|
{
|
||||||
|
return HeadingAccent::block($settings) + ['divider' => ($settings['divider'] ?? null) === 'line'];
|
||||||
|
}
|
||||||
|
|
||||||
public function key(): string
|
public function key(): string
|
||||||
{
|
{
|
||||||
return 'features';
|
return 'features';
|
||||||
@@ -32,12 +60,12 @@ public function label(): string
|
|||||||
|
|
||||||
public function description(): string
|
public function description(): string
|
||||||
{
|
{
|
||||||
return 'Zwei bis vier Merkmale nebeneinander, je mit Symbol, Kurztitel und einem Satz.';
|
return 'Ein bis zwölf Merkmale nebeneinander (bei wenig Platz untereinander), je mit Symbol, Kurztitel, einem Satz und optionalem Link.';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportedUnits(): array
|
public function supportedUnits(): array
|
||||||
{
|
{
|
||||||
return [2, 3, 4];
|
return [1, 2, 3, 4];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function narrowBehavior(): string
|
public function narrowBehavior(): string
|
||||||
@@ -71,10 +99,37 @@ public function schematic(): array
|
|||||||
public function dataRules(): array
|
public function dataRules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'items' => ['required', 'array', 'min:2', 'max:4'],
|
'items' => ['required', 'array', 'min:1', 'max:12'],
|
||||||
'items.*.symbol' => ['required', 'string', Rule::in(array_keys(HeadingAccent::SYMBOLS))],
|
'items.*.symbol' => ['required', 'string', Rule::in(array_keys(HeadingAccent::symbols()))],
|
||||||
'items.*.title' => ['required', 'string', 'max:60'],
|
'items.*.title' => ['required', 'string', 'max:60'],
|
||||||
'items.*.text' => ['nullable', 'string', 'max:200'],
|
'items.*.text' => ['nullable', 'string', 'max:200'],
|
||||||
|
'items.*.url' => ['nullable', 'string', 'max:500'],
|
||||||
|
'items.*.link_label' => ['nullable', 'string', 'max:60'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settings(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'align' => self::ALIGN,
|
||||||
|
'symbol_size' => self::SYMBOL_SIZE,
|
||||||
|
'divider' => self::DIVIDER,
|
||||||
|
'link_style' => HeadingAccent::LINK_STYLE,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settingGroups(): array
|
||||||
|
{
|
||||||
|
return ['Aussehen' => ['align', 'symbol_size', 'divider', 'link_style']];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settingLabels(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'align' => ['Ausrichtung', 'Richtet Symbol, Titel, Satz und Link jedes Merkmals aus. Vorgabe: linksbündig.'],
|
||||||
|
'symbol_size' => ['Größe der Symbole', 'Kantenlänge der Symbole: Klein 2,5 rem, Mittel 3,5 rem, Groß 5 rem, Sehr groß 7 rem. Vorgabe: Mittel.'],
|
||||||
|
'divider' => ['Trennstrich', 'Ein feiner Strich zwischen den Merkmalen: senkrecht zwischen Spalten, waagerecht zwischen Zeilen und bei untereinander stehenden Merkmalen. Vorgabe: ohne.'],
|
||||||
|
'link_style' => HeadingAccent::LINK_STYLE_LABEL,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,27 +139,46 @@ public function dataFields(): array
|
|||||||
Repeater::make('items')
|
Repeater::make('items')
|
||||||
->label('Merkmale')
|
->label('Merkmale')
|
||||||
->schema([
|
->schema([
|
||||||
Select::make('symbol')->label('Symbol')->options(HeadingAccent::SYMBOLS)->required(),
|
SymbolField::make('symbol', 'Symbol', required: true),
|
||||||
TextInput::make('title')->label('Kurztitel')->required()->maxLength(60),
|
TextInput::make('title')->label('Kurztitel')->required()->maxLength(60),
|
||||||
Textarea::make('text')->label('Satz')->rows(2)->maxLength(200),
|
Textarea::make('text')->label('Satz')->rows(2)->maxLength(200),
|
||||||
|
TextInput::make('url')
|
||||||
|
->label('Linkziel (optional)')
|
||||||
|
->maxLength(500)
|
||||||
|
->rule(SafeUrl::rule())
|
||||||
|
->helperText('Seitenpfad wie /materialien oder eine http(s)-Adresse. Leer lassen für ein Merkmal ohne Link.'),
|
||||||
|
TextInput::make('link_label')
|
||||||
|
->label('Linktext')
|
||||||
|
->maxLength(60)
|
||||||
|
->placeholder(self::DEFAULT_LINK_LABEL)
|
||||||
|
->helperText('Nur mit Linkziel. Leer: „'.self::DEFAULT_LINK_LABEL.'“.'),
|
||||||
])
|
])
|
||||||
->minItems(2)
|
->minItems(1)
|
||||||
->maxItems(4)
|
->maxItems(12)
|
||||||
->reorderableWithButtons()
|
->reorderableWithButtons()
|
||||||
->collapsible()
|
->collapsible()
|
||||||
->itemLabel(fn (array $state): ?string => $state['title'] ?? null)
|
->itemLabel(fn (array $state): ?string => $state['title'] ?? null)
|
||||||
->addActionLabel('Merkmal hinzufügen')
|
->addActionLabel('Merkmal hinzufügen')
|
||||||
->helperText('Die Anzahl der Merkmale bestimmt die Spalten: zwei, drei oder vier.'),
|
->helperText('Ein bis zwölf Merkmale. Sie stehen nebeneinander, solange jedes mindestens 12 rem breit bleibt, und brechen sonst um.'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clean(array $data, array $refs, WidgetErrors $errors): array
|
public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||||
{
|
{
|
||||||
foreach ($data['items'] as $index => $item) {
|
foreach ($data['items'] as $index => $item) {
|
||||||
|
$hasUrl = filled($item['url'] ?? null);
|
||||||
|
|
||||||
|
if ($hasUrl && ! SafeUrl::isSafe($item['url'])) {
|
||||||
|
$errors->add("data.items.$index.url", SafeUrl::message());
|
||||||
|
}
|
||||||
|
|
||||||
$data['items'][$index] = [
|
$data['items'][$index] = [
|
||||||
'symbol' => $item['symbol'],
|
'symbol' => $item['symbol'],
|
||||||
'title' => $item['title'],
|
'title' => $item['title'],
|
||||||
'text' => filled($item['text'] ?? null) ? $item['text'] : null,
|
'text' => filled($item['text'] ?? null) ? $item['text'] : null,
|
||||||
|
'url' => $hasUrl ? $item['url'] : null,
|
||||||
|
// Ein Linktext ohne Linkziel wird verworfen, damit nichts Verstecktes gespeichert bleibt.
|
||||||
|
'link_label' => $hasUrl && filled($item['link_label'] ?? null) ? $item['link_label'] : null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,10 +198,14 @@ public function resolve(array $widget, RenderContext $context): array
|
|||||||
'symbol' => HeadingAccent::symbol(['symbol' => $item['symbol'] ?? null]),
|
'symbol' => HeadingAccent::symbol(['symbol' => $item['symbol'] ?? null]),
|
||||||
'title' => $item['title'],
|
'title' => $item['title'],
|
||||||
'text' => $item['text'] ?? null,
|
'text' => $item['text'] ?? null,
|
||||||
|
'url' => SafeUrl::isSafe($item['url'] ?? null) ? $item['url'] : null,
|
||||||
|
'linkLabel' => filled($item['link_label'] ?? null) ? $item['link_label'] : self::DEFAULT_LINK_LABEL,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['items' => $items];
|
$settings = $widget['settings'] ?? [];
|
||||||
|
|
||||||
|
return ['items' => $items, 'linkStyle' => HeadingAccent::linkStyle($settings), 'layout' => self::layout($settings)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function summary(array $widget): string
|
public function summary(array $widget): string
|
||||||
|
|||||||
@@ -75,20 +75,24 @@ public function dataFields(): array
|
|||||||
public function settings(): array
|
public function settings(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'symbol' => HeadingAccent::SYMBOLS,
|
'symbol' => HeadingAccent::symbols(),
|
||||||
|
'symbol_size' => HeadingAccent::SIZE,
|
||||||
|
'symbol_align' => HeadingAccent::ALIGN,
|
||||||
'accent' => HeadingAccent::BRUSH,
|
'accent' => HeadingAccent::BRUSH,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function settingGroups(): array
|
public function settingGroups(): array
|
||||||
{
|
{
|
||||||
return ['Aussehen' => ['symbol', 'accent']];
|
return ['Aussehen' => ['symbol', 'symbol_size', 'symbol_align', 'accent']];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function settingLabels(): array
|
public function settingLabels(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'symbol' => HeadingAccent::SYMBOL_LABEL,
|
'symbol' => HeadingAccent::SYMBOL_LABEL,
|
||||||
|
'symbol_size' => HeadingAccent::SIZE_LABEL,
|
||||||
|
'symbol_align' => HeadingAccent::ALIGN_LABEL,
|
||||||
'accent' => HeadingAccent::BRUSH_LABEL,
|
'accent' => HeadingAccent::BRUSH_LABEL,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,14 +113,16 @@ public function settings(): array
|
|||||||
return [
|
return [
|
||||||
'heading_level' => PremiumFields::HEADING_LEVELS,
|
'heading_level' => PremiumFields::HEADING_LEVELS,
|
||||||
'accent' => ['underline' => 'Gelbe Unterstreichung', 'rays' => 'Unterstreichung und Signalstrahlen', 'none' => 'Ohne Akzent'],
|
'accent' => ['underline' => 'Gelbe Unterstreichung', 'rays' => 'Unterstreichung und Signalstrahlen', 'none' => 'Ohne Akzent'],
|
||||||
'symbol' => HeadingAccent::SYMBOLS,
|
'symbol' => HeadingAccent::symbols(),
|
||||||
|
'symbol_size' => HeadingAccent::SIZE,
|
||||||
|
'symbol_align' => HeadingAccent::ALIGN,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function settingGroups(): array
|
public function settingGroups(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'Aussehen' => ['accent', 'symbol'],
|
'Aussehen' => ['accent', 'symbol', 'symbol_size', 'symbol_align'],
|
||||||
'Seitenstruktur' => ['heading_level'],
|
'Seitenstruktur' => ['heading_level'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -131,6 +133,8 @@ public function settingLabels(): array
|
|||||||
'heading_level' => ['Überschriftenebene', 'Betrifft nur die Gliederung für Suchmaschinen und Hilfstechnik, nicht das Aussehen. Der erste Einstieg einer Seite ist immer die Hauptüberschrift (H1).'],
|
'heading_level' => ['Überschriftenebene', 'Betrifft nur die Gliederung für Suchmaschinen und Hilfstechnik, nicht das Aussehen. Der erste Einstieg einer Seite ist immer die Hauptüberschrift (H1).'],
|
||||||
'accent' => ['Markenakzent', 'Freigegebene Akzente aus dem Brand-UI-Kit. Vorgabe: gelbe Unterstreichung.'],
|
'accent' => ['Markenakzent', 'Freigegebene Akzente aus dem Brand-UI-Kit. Vorgabe: gelbe Unterstreichung.'],
|
||||||
'symbol' => HeadingAccent::SYMBOL_LABEL,
|
'symbol' => HeadingAccent::SYMBOL_LABEL,
|
||||||
|
'symbol_size' => HeadingAccent::SIZE_LABEL,
|
||||||
|
'symbol_align' => HeadingAccent::ALIGN_LABEL,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,14 +115,16 @@ public function settings(): array
|
|||||||
return [
|
return [
|
||||||
'surface' => ['cream' => 'Creme (Markenfläche)', 'clear' => 'Ohne eigene Fläche', 'navy' => 'Navy (dunkel)'],
|
'surface' => ['cream' => 'Creme (Markenfläche)', 'clear' => 'Ohne eigene Fläche', 'navy' => 'Navy (dunkel)'],
|
||||||
'heading_level' => PremiumFields::HEADING_LEVELS,
|
'heading_level' => PremiumFields::HEADING_LEVELS,
|
||||||
'symbol' => HeadingAccent::SYMBOLS,
|
'symbol' => HeadingAccent::symbols(),
|
||||||
|
'symbol_size' => HeadingAccent::SIZE,
|
||||||
|
'symbol_align' => HeadingAccent::ALIGN,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function settingGroups(): array
|
public function settingGroups(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'Aussehen' => ['surface', 'symbol'],
|
'Aussehen' => ['surface', 'symbol', 'symbol_size', 'symbol_align'],
|
||||||
'Seitenstruktur' => ['heading_level'],
|
'Seitenstruktur' => ['heading_level'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -132,6 +134,8 @@ public function settingLabels(): array
|
|||||||
return [
|
return [
|
||||||
'surface' => ['Hintergrund des Widgets', 'Unabhängig vom Abschnittshintergrund. „Ohne eigene Fläche“ übernimmt den Abschnitt.'],
|
'surface' => ['Hintergrund des Widgets', 'Unabhängig vom Abschnittshintergrund. „Ohne eigene Fläche“ übernimmt den Abschnitt.'],
|
||||||
'symbol' => HeadingAccent::SYMBOL_LABEL,
|
'symbol' => HeadingAccent::SYMBOL_LABEL,
|
||||||
|
'symbol_size' => HeadingAccent::SIZE_LABEL,
|
||||||
|
'symbol_align' => HeadingAccent::ALIGN_LABEL,
|
||||||
'heading_level' => ['Überschriftenebene', 'Betrifft nur die Gliederung für Suchmaschinen und Hilfstechnik, nicht das Aussehen. Steht das Widget als erstes auf der Seite, ist die Überschrift immer H1.'],
|
'heading_level' => ['Überschriftenebene', 'Betrifft nur die Gliederung für Suchmaschinen und Hilfstechnik, nicht das Aussehen. Steht das Widget als erstes auf der Seite, ist die Überschrift immer H1.'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Domain\Cms\Widgets\Types;
|
namespace App\Domain\Cms\Widgets\Types;
|
||||||
|
|
||||||
|
use App\Domain\Cms\Widgets\Support\HeadingAccent;
|
||||||
use App\Domain\Cms\Widgets\Support\RichText;
|
use App\Domain\Cms\Widgets\Support\RichText;
|
||||||
use App\Domain\Cms\Widgets\WidgetType;
|
use App\Domain\Cms\Widgets\WidgetType;
|
||||||
use Filament\Forms\Components\Textarea;
|
use Filament\Forms\Components\Textarea;
|
||||||
@@ -69,6 +70,29 @@ public function dataFields(): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function settings(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'symbol' => HeadingAccent::symbols(),
|
||||||
|
'symbol_size' => HeadingAccent::SIZE,
|
||||||
|
'symbol_align' => HeadingAccent::ALIGN,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settingGroups(): array
|
||||||
|
{
|
||||||
|
return ['Aussehen' => ['symbol', 'symbol_size', 'symbol_align']];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settingLabels(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'symbol' => ['Symbol neben dem Text', 'Kleine Grafik aus dem Brand-Kit links neben dem ganzen Text. Sie ist reine Zierde und wird von Hilfstechnik nicht vorgelesen. Vorgabe: kein Symbol.'],
|
||||||
|
'symbol_size' => ['Größe des Symbols', 'Vorgabe: Mittel. Bei wenig Platz steht das Symbol über dem Text. Wirkt nur, wenn ein Symbol gewählt ist.'],
|
||||||
|
'symbol_align' => HeadingAccent::ALIGN_LABEL,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function summary(array $widget): string
|
public function summary(array $widget): string
|
||||||
{
|
{
|
||||||
return RichText::excerpt(e((string) ($widget['data']['body'] ?? '')));
|
return RichText::excerpt(e((string) ($widget['data']['body'] ?? '')));
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
* WinAnsi). Absichtlich ohne Abhängigkeit: Ein Zahlungsbeleg ist ein Text mit Linien. Der Inhalt ist unkomprimiert und
|
* WinAnsi). Absichtlich ohne Abhängigkeit: Ein Zahlungsbeleg ist ein Text mit Linien. Der Inhalt ist unkomprimiert und
|
||||||
* enthält keinen Zeitstempel, damit dasselbe Dokument bei jedem Abruf byte-gleich ist und Tests den Text prüfen können.
|
* enthält keinen Zeitstempel, damit dasselbe Dokument bei jedem Abruf byte-gleich ist und Tests den Text prüfen können.
|
||||||
* Zeichen außerhalb von Windows-1252 werden durch „?“ ersetzt (das Minuszeichen U+2212 durch „-“).
|
* Zeichen außerhalb von Windows-1252 werden durch „?“ ersetzt (das Minuszeichen U+2212 durch „-“).
|
||||||
|
*
|
||||||
|
* Für längere Dokumente (Handbuch) kann der Schreiber zusätzlich Flächen, JPEG-Bilder, Verweise innerhalb des Dokuments
|
||||||
|
* (Inhaltsverzeichnis) und Lesezeichen setzen. Wer sie nicht nutzt, erhält dieselben Bytes wie zuvor: Die zusätzlichen
|
||||||
|
* Objekte entstehen nur bei Bedarf und nach allen bisherigen.
|
||||||
*/
|
*/
|
||||||
final class PdfDocument
|
final class PdfDocument
|
||||||
{
|
{
|
||||||
@@ -20,6 +24,21 @@ final class PdfDocument
|
|||||||
/** Schräge Schnitte werden nur eingebunden, wenn das Dokument sie braucht (Belege bleiben unverändert). */
|
/** Schräge Schnitte werden nur eingebunden, wenn das Dokument sie braucht (Belege bleiben unverändert). */
|
||||||
private bool $usesItalic = false;
|
private bool $usesItalic = false;
|
||||||
|
|
||||||
|
/** @var list<array{bytes: string, width: int, height: int}> */
|
||||||
|
private array $images = [];
|
||||||
|
|
||||||
|
/** @var array<string, int> Prüfsumme der Bilddatei => Index in {@see self::$images} */
|
||||||
|
private array $imageIndex = [];
|
||||||
|
|
||||||
|
/** @var array<int, array<int, true>> Seite => Bilder, die sie zeigt */
|
||||||
|
private array $pageImages = [];
|
||||||
|
|
||||||
|
/** @var array<int, list<array{x: float, y: float, w: float, h: float, page?: int, top?: float, uri?: string}>> */
|
||||||
|
private array $links = [];
|
||||||
|
|
||||||
|
/** @var list<array{title: string, page: int, top: float, level: int}> */
|
||||||
|
private array $outline = [];
|
||||||
|
|
||||||
/** Breiten der Helvetica (Tausendstel der Schrifthöhe) für Zeichen 32 bis 126; schräg wie aufrecht. */
|
/** Breiten der Helvetica (Tausendstel der Schrifthöhe) für Zeichen 32 bis 126; schräg wie aufrecht. */
|
||||||
private const REGULAR = [278, 278, 355, 556, 556, 889, 667, 191, 333, 333, 389, 584, 278, 333, 278, 278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 278, 278, 584, 584, 584, 556, 1015, 667, 667, 722, 722, 667, 611, 778, 722, 278, 500, 667, 556, 833, 722, 778, 667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 278, 278, 278, 469, 556, 333, 556, 556, 500, 556, 556, 278, 556, 556, 222, 222, 500, 222, 833, 556, 556, 556, 556, 333, 500, 278, 556, 500, 722, 500, 500, 500, 334, 260, 334, 584];
|
private const REGULAR = [278, 278, 355, 556, 556, 889, 667, 191, 333, 333, 389, 584, 278, 333, 278, 278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 278, 278, 584, 584, 584, 556, 1015, 667, 667, 722, 722, 667, 611, 778, 722, 278, 500, 667, 556, 833, 722, 778, 667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 278, 278, 278, 469, 556, 333, 556, 556, 500, 556, 556, 278, 556, 556, 222, 222, 500, 222, 833, 556, 556, 556, 556, 333, 500, 278, 556, 500, 722, 500, 500, 500, 334, 260, 334, 584];
|
||||||
|
|
||||||
@@ -31,6 +50,86 @@ public function addPage(): void
|
|||||||
$this->pages[] = '';
|
$this->pages[] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Anzahl der bisher angelegten Seiten. */
|
||||||
|
public function pageCount(): int
|
||||||
|
{
|
||||||
|
return count($this->pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gefüllte Fläche in einem Grauwert (0 schwarz, 1 weiß), zum Beispiel für Tabellenköpfe. */
|
||||||
|
public function fillRect(float $x, float $y, float $w, float $h, float $gray): void
|
||||||
|
{
|
||||||
|
$this->append(sprintf("q %s g %s %s %s %s re f Q\n", $this->n($gray), $this->n($x), $this->n($y), $this->n($w), $this->n($h)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt ein JPEG (RGB, aus `imagejpeg`) mit seiner linken unteren Ecke bei `$x`/`$y`. Dasselbe Bild wird nur einmal
|
||||||
|
* im Dokument abgelegt.
|
||||||
|
*/
|
||||||
|
public function image(float $x, float $y, float $w, float $h, string $jpeg, int $pixelWidth, int $pixelHeight): void
|
||||||
|
{
|
||||||
|
$key = md5($jpeg);
|
||||||
|
|
||||||
|
if (! isset($this->imageIndex[$key])) {
|
||||||
|
$this->imageIndex[$key] = count($this->images);
|
||||||
|
$this->images[] = ['bytes' => $jpeg, 'width' => $pixelWidth, 'height' => $pixelHeight];
|
||||||
|
}
|
||||||
|
|
||||||
|
$index = $this->imageIndex[$key];
|
||||||
|
|
||||||
|
if ($this->pages === []) {
|
||||||
|
$this->addPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pageImages[array_key_last($this->pages)][$index] = true;
|
||||||
|
$this->append(sprintf("q %s 0 0 %s %s %s cm /Im%d Do Q\n", $this->n($w), $this->n($h), $this->n($x), $this->n($y), $index + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anklickbarer Bereich auf der aktuellen Seite, der zu einer Stelle im Dokument springt (Seitenindex ab 0, `$top` ist
|
||||||
|
* die Höhe des Ziels auf der Zielseite).
|
||||||
|
*/
|
||||||
|
public function link(float $x, float $y, float $w, float $h, int $page, float $top): void
|
||||||
|
{
|
||||||
|
if ($this->pages === []) {
|
||||||
|
$this->addPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->links[array_key_last($this->pages)][] = ['x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'page' => $page, 'top' => $top];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anklickbarer Bereich auf der aktuellen Seite, der eine Internetadresse öffnet. Eine Adresse, die am Zeilenende umbricht,
|
||||||
|
* bekommt für jede Zeile einen Bereich mit derselben vollständigen Adresse: Sie bleibt als Ganzes zusammen, gleich wie
|
||||||
|
* der sichtbare Text umbricht.
|
||||||
|
*/
|
||||||
|
public function uriLink(float $x, float $y, float $w, float $h, string $uri): void
|
||||||
|
{
|
||||||
|
if ($this->pages === []) {
|
||||||
|
$this->addPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->links[array_key_last($this->pages)][] = ['x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'uri' => $uri];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Adresse als 7-Bit-Zeichenkette für das PDF: Zeichen außerhalb von ASCII und Leerzeichen werden prozentkodiert,
|
||||||
|
* unsichtbare Zeichen entfallen.
|
||||||
|
*/
|
||||||
|
private static function uriString(string $uri): string
|
||||||
|
{
|
||||||
|
$uri = (string) preg_replace('/[\x{00AD}\x{034F}\x{061C}\x{180E}\x{200B}-\x{200F}\x{202A}-\x{202E}\x{2060}-\x{2064}\x{FEFF}]/u', '', $uri);
|
||||||
|
$uri = (string) preg_replace_callback('/[^\x21-\x7E]/', fn (array $m): string => rawurlencode($m[0]), $uri);
|
||||||
|
|
||||||
|
return str_replace(['\\', '(', ')'], ['\\\\', '\\(', '\\)'], $uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Lesezeichen (Ebene 1 bis 6) für die Gliederung in PDF-Betrachtern. */
|
||||||
|
public function bookmark(string $title, int $page, float $top, int $level = 1): void
|
||||||
|
{
|
||||||
|
$this->outline[] = ['title' => $title, 'page' => $page, 'top' => $top, 'level' => max(1, min(6, $level))];
|
||||||
|
}
|
||||||
|
|
||||||
public function text(float $x, float $y, string $text, float $size = 10, bool $bold = false, bool $italic = false): void
|
public function text(float $x, float $y, string $text, float $size = 10, bool $bold = false, bool $italic = false): void
|
||||||
{
|
{
|
||||||
$font = $italic ? ($bold ? 'F4' : 'F3') : ($bold ? 'F2' : 'F1');
|
$font = $italic ? ($bold ? 'F4' : 'F3') : ($bold ? 'F2' : 'F1');
|
||||||
@@ -145,9 +244,39 @@ public function output(string $title, ?string $keywords = null): string
|
|||||||
$kids = [];
|
$kids = [];
|
||||||
$next = 6;
|
$next = 6;
|
||||||
|
|
||||||
foreach ($pages as $stream) {
|
// Nummern der zusätzlichen Objekte: nach den Seiten und Schriften, in fester Reihenfolge (Verweise, Bilder, Gliederung).
|
||||||
|
$cursor = 6 + 2 * count($pages) + ($this->usesItalic ? 2 : 0);
|
||||||
|
$annotations = [];
|
||||||
|
|
||||||
|
foreach ($this->links as $pageIndex => $links) {
|
||||||
|
foreach ($links as $link) {
|
||||||
|
$annotations[$pageIndex][] = ['number' => $cursor++] + $link;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$imageNumbers = [];
|
||||||
|
|
||||||
|
foreach (array_keys($this->images) as $index) {
|
||||||
|
$imageNumbers[$index] = $cursor++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$outlineRoot = $this->outline === [] ? null : $cursor++;
|
||||||
|
$outlineNumbers = [];
|
||||||
|
|
||||||
|
foreach (array_keys($this->outline) as $index) {
|
||||||
|
$outlineNumbers[$index] = $cursor++;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($pages as $pageIndex => $stream) {
|
||||||
$kids[] = $next.' 0 R';
|
$kids[] = $next.' 0 R';
|
||||||
$objects[$next] = '<< /Type /Page /Parent 2 0 R /MediaBox [0 0 '.self::WIDTH.' '.self::HEIGHT.'] /Resources << /Font << /F1 3 0 R /F2 4 0 R'.($this->usesItalic ? ' /F3 %ITALIC% 0 R /F4 %BOLDITALIC% 0 R' : '').' >> >> /Contents '.($next + 1).' 0 R >>';
|
$xobjects = '';
|
||||||
|
|
||||||
|
foreach (array_keys($this->pageImages[$pageIndex] ?? []) as $index) {
|
||||||
|
$xobjects .= ' /Im'.($index + 1).' '.$imageNumbers[$index].' 0 R';
|
||||||
|
}
|
||||||
|
|
||||||
|
$annots = isset($annotations[$pageIndex]) ? ' /Annots ['.implode(' ', array_map(fn (array $link): string => $link['number'].' 0 R', $annotations[$pageIndex])).']' : '';
|
||||||
|
$objects[$next] = '<< /Type /Page /Parent 2 0 R /MediaBox [0 0 '.self::WIDTH.' '.self::HEIGHT.'] /Resources << /Font << /F1 3 0 R /F2 4 0 R'.($this->usesItalic ? ' /F3 %ITALIC% 0 R /F4 %BOLDITALIC% 0 R' : '').' >>'.($xobjects === '' ? '' : ' /XObject <<'.$xobjects.' >>').' >> /Contents '.($next + 1).' 0 R'.$annots.' >>';
|
||||||
$objects[$next + 1] = '<< /Length '.strlen($stream)." >>\nstream\n".$stream.'endstream';
|
$objects[$next + 1] = '<< /Length '.strlen($stream)." >>\nstream\n".$stream.'endstream';
|
||||||
$next += 2;
|
$next += 2;
|
||||||
}
|
}
|
||||||
@@ -161,6 +290,32 @@ public function output(string $title, ?string $keywords = null): string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($annotations as $links) {
|
||||||
|
foreach ($links as $link) {
|
||||||
|
$rect = sprintf('[%s %s %s %s]', $this->n($link['x']), $this->n($link['y']), $this->n($link['x'] + $link['w']), $this->n($link['y'] + $link['h']));
|
||||||
|
$objects[$link['number']] = isset($link['uri'])
|
||||||
|
? '<< /Type /Annot /Subtype /Link /Rect '.$rect.' /Border [0 0 0] /A << /S /URI /URI ('.self::uriString($link['uri']).') >> >>'
|
||||||
|
: sprintf(
|
||||||
|
'<< /Type /Annot /Subtype /Link /Rect %s /Border [0 0 0] /Dest [%d 0 R /XYZ 0 %s null] >>',
|
||||||
|
$rect,
|
||||||
|
6 + 2 * min($link['page'], count($pages) - 1),
|
||||||
|
$this->n($link['top']),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->images as $index => $image) {
|
||||||
|
$objects[$imageNumbers[$index]] = '<< /Type /XObject /Subtype /Image /Width '.$image['width'].' /Height '.$image['height'].' /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length '.strlen($image['bytes'])." >>\nstream\n".$image['bytes']."\nendstream";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($outlineRoot !== null) {
|
||||||
|
$objects[1] = '<< /Type /Catalog /Pages 2 0 R /Outlines '.$outlineRoot.' 0 R /PageMode /UseOutlines >>';
|
||||||
|
|
||||||
|
foreach ($this->outlineObjects($outlineRoot, $outlineNumbers, count($pages)) as $number => $body) {
|
||||||
|
$objects[$number] = $body;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$objects[2] = '<< /Type /Pages /Kids ['.implode(' ', $kids).'] /Count '.count($pages).' >>';
|
$objects[2] = '<< /Type /Pages /Kids ['.implode(' ', $kids).'] /Count '.count($pages).' >>';
|
||||||
$objects[3] = '<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >>';
|
$objects[3] = '<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >>';
|
||||||
$objects[4] = '<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding >>';
|
$objects[4] = '<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding >>';
|
||||||
@@ -186,6 +341,52 @@ public function output(string $title, ?string $keywords = null): string
|
|||||||
return $pdf.'trailer'."\n<< /Size ".(count($objects) + 1).' /Root 1 0 R /Info 5 0 R >>'."\nstartxref\n".$xref."\n%%EOF\n";
|
return $pdf.'trailer'."\n<< /Size ".(count($objects) + 1).' /Root 1 0 R /Info 5 0 R >>'."\nstartxref\n".$xref."\n%%EOF\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gliederung (Lesezeichen): Ebene 1 unter der Wurzel, Ebene 2 unter dem vorangehenden Eintrag der Ebene 1.
|
||||||
|
*
|
||||||
|
* @param array<int, int> $numbers Objektnummer je Eintrag
|
||||||
|
* @return array<int, string>
|
||||||
|
*/
|
||||||
|
private function outlineObjects(int $root, array $numbers, int $pageCount): array
|
||||||
|
{
|
||||||
|
$parentOf = [];
|
||||||
|
$childrenOf = [];
|
||||||
|
$descendants = [];
|
||||||
|
$path = [];
|
||||||
|
|
||||||
|
// Ein Eintrag gehört zum nächsten davor mit kleinerer Ebene; ohne einen solchen steht er oben.
|
||||||
|
foreach ($this->outline as $index => $item) {
|
||||||
|
while ($path !== [] && $this->outline[$path[array_key_last($path)]]['level'] >= $item['level']) {
|
||||||
|
array_pop($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$parentOf[$index] = $path === [] ? null : $path[array_key_last($path)];
|
||||||
|
$childrenOf[$parentOf[$index] ?? -1][] = $index;
|
||||||
|
|
||||||
|
foreach ($path as $ancestor) {
|
||||||
|
$descendants[$ancestor] = ($descendants[$ancestor] ?? 0) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$path[] = $index;
|
||||||
|
}
|
||||||
|
|
||||||
|
$top = $childrenOf[-1];
|
||||||
|
$objects = [$root => '<< /Type /Outlines /First '.$numbers[$top[0]].' 0 R /Last '.$numbers[$top[array_key_last($top)]].' 0 R /Count '.count($this->outline).' >>'];
|
||||||
|
|
||||||
|
foreach ($this->outline as $index => $item) {
|
||||||
|
$siblings = $childrenOf[$parentOf[$index] ?? -1];
|
||||||
|
$position = (int) array_search($index, $siblings, true);
|
||||||
|
$kids = $childrenOf[$index] ?? [];
|
||||||
|
$objects[$numbers[$index]] = '<< /Title ('.self::escape($item['title']).') /Parent '.($parentOf[$index] === null ? $root : $numbers[$parentOf[$index]]).' 0 R'
|
||||||
|
.($position > 0 ? ' /Prev '.$numbers[$siblings[$position - 1]].' 0 R' : '')
|
||||||
|
.($position < count($siblings) - 1 ? ' /Next '.$numbers[$siblings[$position + 1]].' 0 R' : '')
|
||||||
|
.($kids === [] ? '' : ' /First '.$numbers[$kids[0]].' 0 R /Last '.$numbers[$kids[array_key_last($kids)]].' 0 R /Count '.($descendants[$index] ?? 0))
|
||||||
|
.' /Dest ['.(6 + 2 * min($item['page'], $pageCount - 1)).' 0 R /XYZ 0 '.$this->n($item['top']).' null] >>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $objects;
|
||||||
|
}
|
||||||
|
|
||||||
private function append(string $operators): void
|
private function append(string $operators): void
|
||||||
{
|
{
|
||||||
if ($this->pages === []) {
|
if ($this->pages === []) {
|
||||||
@@ -204,7 +405,7 @@ private function n(float $value): string
|
|||||||
private static function escape(string $text): string
|
private static function escape(string $text): string
|
||||||
{
|
{
|
||||||
$text = strtr($text, ["\u{2212}" => '-', "\u{2019}" => "'", "\u{2026}" => '...', "\u{00A0}" => ' ', "\u{202F}" => ' ']);
|
$text = strtr($text, ["\u{2212}" => '-', "\u{2019}" => "'", "\u{2026}" => '...', "\u{00A0}" => ' ', "\u{202F}" => ' ']);
|
||||||
$text = (string) preg_replace('/[\x00-\x08\x0B-\x1F\x7F]/u', '', $text);
|
$text = (string) preg_replace('/[\x00-\x08\x0B-\x1F\x7F\x{00AD}\x{034F}\x{061C}\x{180E}\x{200B}-\x{200F}\x{202A}-\x{202E}\x{2060}-\x{2064}\x{FEFF}]/u', '', $text);
|
||||||
$encoded = mb_convert_encoding($text, 'Windows-1252', 'UTF-8');
|
$encoded = mb_convert_encoding($text, 'Windows-1252', 'UTF-8');
|
||||||
|
|
||||||
return str_replace(['\\', '(', ')'], ['\\\\', '\\(', '\\)'], $encoded);
|
return str_replace(['\\', '(', ')'], ['\\\\', '\\(', '\\)'], $encoded);
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Media;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bereitet ein Bild für das PDF auf: Es wird mit GD gelesen, auf eine druckbare Größe verkleinert, auf Weiß gesetzt
|
||||||
|
* (Transparenz gibt es im PDF-Schreiber nicht) und als JPEG neu kodiert. So braucht das PDF keine Bildbibliothek und
|
||||||
|
* keine Rücksicht auf das Ausgangsformat. Was GD nicht lesen kann (zum Beispiel WebP in einem Image ohne WebP-Unterstützung),
|
||||||
|
* liefert null; die Ausgabe zeigt dann einen Hinweis statt des Bildes.
|
||||||
|
*/
|
||||||
|
final class PdfImage
|
||||||
|
{
|
||||||
|
/** Längste Kante in Pixel; 1400 Pixel genügen für die Spaltenbreite einer A4-Seite bei guter Druckqualität. */
|
||||||
|
public const MAX_EDGE = 1400;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{jpeg: string, width: int, height: int}|null
|
||||||
|
*/
|
||||||
|
public static function fromBytes(string $raw): ?array
|
||||||
|
{
|
||||||
|
if ($raw === '' || ! function_exists('imagecreatefromstring')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$source = @imagecreatefromstring($raw);
|
||||||
|
|
||||||
|
if ($source === false) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$width = imagesx($source);
|
||||||
|
$height = imagesy($source);
|
||||||
|
|
||||||
|
if ($width < 1 || $height < 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$scale = min(1.0, self::MAX_EDGE / max($width, $height));
|
||||||
|
$targetWidth = max(1, (int) round($width * $scale));
|
||||||
|
$targetHeight = max(1, (int) round($height * $scale));
|
||||||
|
$canvas = imagecreatetruecolor($targetWidth, $targetHeight);
|
||||||
|
|
||||||
|
if ($canvas === false) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
imagefill($canvas, 0, 0, (int) imagecolorallocate($canvas, 255, 255, 255));
|
||||||
|
imagecopyresampled($canvas, $source, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
$written = imagejpeg($canvas, null, 82);
|
||||||
|
$jpeg = (string) ob_get_clean();
|
||||||
|
|
||||||
|
return $written && $jpeg !== '' ? ['jpeg' => $jpeg, 'width' => $targetWidth, 'height' => $targetHeight] : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
use Illuminate\Contracts\Support\Htmlable;
|
use Illuminate\Contracts\Support\Htmlable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arbeitsplatz: Programme und Module in der gemeinsamen Bestandsliste. Die Listen „Module“ und „Programme“ zeigen
|
* Gemeinsame Übersicht „Programme und Module“ (kein Menüpunkt; Einstieg über die Stammdaten). Die Listen „Module“ und „Programme“ zeigen
|
||||||
* dieselben Zeilen mit festem Typ (ListsCompositions).
|
* dieselben Zeilen mit festem Typ (ListsCompositions).
|
||||||
*/
|
*/
|
||||||
class EditorialDesk extends Page
|
class EditorialDesk extends Page
|
||||||
@@ -23,6 +23,9 @@ class EditorialDesk extends Page
|
|||||||
|
|
||||||
protected static ?int $navigationSort = 0;
|
protected static ?int $navigationSort = 0;
|
||||||
|
|
||||||
|
/** Kein Menüpunkt mehr; die gemeinsame Übersicht bleibt über den Filterlink der Stammdaten erreichbar. */
|
||||||
|
protected static bool $shouldRegisterNavigation = false;
|
||||||
|
|
||||||
protected static ?string $slug = 'arbeitsplatz';
|
protected static ?string $slug = 'arbeitsplatz';
|
||||||
|
|
||||||
protected static ?string $title = 'Arbeitsplatz';
|
protected static ?string $title = 'Arbeitsplatz';
|
||||||
|
|||||||
@@ -0,0 +1,387 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\PdfTemplate;
|
||||||
|
use App\Domain\Catalog\TemplateImage;
|
||||||
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
|
use App\Filament\Support\ChoosesMedia;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Pages\Page;
|
||||||
|
use Filament\Support\Enums\Width;
|
||||||
|
use Illuminate\Contracts\Support\Htmlable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PDF-Vorlagen für Dokumente (ADR-51, Nachtrag): Titelseite, grafische Kopf- und Fußzeile und Standardvermerke. Die Bilder
|
||||||
|
* wählt der gemeinsame Picker aus dem Medienbestand (freigegebene Bildfassungen); eine Vorlage ist reines Layout und ändert
|
||||||
|
* keinen Inhalt. Gespeichert wird erst mit „Vorlage speichern“; offene Eingaben bleiben beim Wechsel der Vorlage nicht stehen,
|
||||||
|
* der Wechsel fragt bei offenen Änderungen nach.
|
||||||
|
*/
|
||||||
|
class PdfVorlagen extends Page
|
||||||
|
{
|
||||||
|
use ChoosesMedia;
|
||||||
|
|
||||||
|
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'PDF-Vorlagen';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 60;
|
||||||
|
|
||||||
|
protected static ?string $slug = 'pdf-vorlagen';
|
||||||
|
|
||||||
|
protected static ?string $title = 'PDF-Vorlagen';
|
||||||
|
|
||||||
|
protected string $view = 'filament.pdf.vorlagen';
|
||||||
|
|
||||||
|
/** Gewählte Vorlage; 0 = neue, noch nicht gespeicherte. */
|
||||||
|
public int $templateId = 0;
|
||||||
|
|
||||||
|
public string $name = '';
|
||||||
|
|
||||||
|
public string $publisher = '';
|
||||||
|
|
||||||
|
public string $copyright = '';
|
||||||
|
|
||||||
|
public bool $showCover = true;
|
||||||
|
|
||||||
|
/** Inhaltsverzeichnis im PDF: `auto` (nur bei mehr als einem Eintrag), `always`, `never`. */
|
||||||
|
public string $tocModus = 'auto';
|
||||||
|
|
||||||
|
/** Tiefe des Verzeichnisses: 2 = nur Kapitel, 3 bis 6 = bis zu dieser Überschriftenstufe. */
|
||||||
|
public int $tocTiefe = PdfTemplate::TOC_DEPTH_MAX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anordnung von Kopf und Fuß: `full` (Band in voller Seitenbreite), `left` oder `right` (Logo).
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $anordnung = ['header' => 'full', 'footer' => 'full'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Höhe des Logos in Punkt, wenn Kopf oder Fuß ein Logo tragen.
|
||||||
|
*
|
||||||
|
* @var array<string, int|string>
|
||||||
|
*/
|
||||||
|
public array $logohoehe = ['header' => PdfTemplate::LOGO_DEFAULT, 'footer' => PdfTemplate::LOGO_DEFAULT];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Bilder je Bildfeld (header, footer, cover) als Ziel des Pickers: `element:<Fassung>` oder `medium:<Medium>`.
|
||||||
|
*
|
||||||
|
* @var array<string, string|null>
|
||||||
|
*/
|
||||||
|
public array $bilder = ['header' => null, 'footer' => null, 'cover' => null];
|
||||||
|
|
||||||
|
/** Das Bildfeld, in das die Auswahl übernommen wird: header, footer oder cover. */
|
||||||
|
public ?string $bildFeld = null;
|
||||||
|
|
||||||
|
/** @var array{aktion: string, argument: int|string|null, titel: string, text: string, label: string, gefahr: bool}|null */
|
||||||
|
public ?array $bestaetigung = null;
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return ContentElementResource::editor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mount(): void
|
||||||
|
{
|
||||||
|
$first = PdfTemplate::query()->where('kind', PdfTemplate::KIND_DOCUMENT)->orderBy('name')->first();
|
||||||
|
$first instanceof PdfTemplate ? $this->loadTemplate($first) : $this->clearForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHeading(): string|Htmlable|null
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMaxContentWidth(): Width|string|null
|
||||||
|
{
|
||||||
|
return Width::Full;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{id: int, name: string, documents: int}>
|
||||||
|
*/
|
||||||
|
public function templates(): array
|
||||||
|
{
|
||||||
|
return PdfTemplate::query()->where('kind', PdfTemplate::KIND_DOCUMENT)->withCount('compositions')->orderBy('name')->get()
|
||||||
|
->map(fn (PdfTemplate $template): array => ['id' => $template->id, 'name' => $template->name, 'documents' => (int) $template->compositions_count])->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function select(int $id): void
|
||||||
|
{
|
||||||
|
$template = PdfTemplate::query()->where('kind', PdfTemplate::KIND_DOCUMENT)->find($id);
|
||||||
|
|
||||||
|
if ($template instanceof PdfTemplate) {
|
||||||
|
$this->loadTemplate($template);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function newTemplate(): void
|
||||||
|
{
|
||||||
|
$this->clearForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ob die Eingaben vom gespeicherten Stand abweichen. */
|
||||||
|
public function changed(): bool
|
||||||
|
{
|
||||||
|
$template = $this->templateId > 0 ? PdfTemplate::query()->find($this->templateId) : null;
|
||||||
|
|
||||||
|
if (! $template instanceof PdfTemplate) {
|
||||||
|
return $this->name !== '' || $this->publisher !== '' || $this->copyright !== '' || array_filter($this->bilder) !== [] || $this->layouts() !== [PdfTemplate::normalizeLayout(null, null), PdfTemplate::normalizeLayout(null, null)] || $this->tocSetting() !== PdfTemplate::normalizeToc(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->name !== $template->name
|
||||||
|
|| $this->publisher !== (string) $template->publisher
|
||||||
|
|| $this->copyright !== (string) $template->copyright
|
||||||
|
|| $this->showCover !== (bool) $template->show_cover
|
||||||
|
|| $this->bilder !== $this->templateSlots($template)
|
||||||
|
|| $this->layouts() !== [$template->layout('header'), $template->layout('footer')]
|
||||||
|
|| $this->tocSetting() !== $template->toc();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(): void
|
||||||
|
{
|
||||||
|
abort_unless(ContentElementResource::editor(), 403);
|
||||||
|
|
||||||
|
if (trim($this->name) === '') {
|
||||||
|
Notification::make()->danger()->title('Der Name fehlt.')->body('Er bezeichnet die Vorlage bei der Auswahl am Dokument.')->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (PdfTemplate::SLOTS as $slot) {
|
||||||
|
$problem = $this->bilder[$slot] === null ? null : TemplateImage::problem($this->bilder[$slot]);
|
||||||
|
|
||||||
|
if ($problem !== null) {
|
||||||
|
Notification::make()->danger()->title('Das Bild für '.$this->slotLabel($slot).' lässt sich nicht verwenden.')->body($problem)->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$values = [
|
||||||
|
'name' => trim($this->name),
|
||||||
|
'kind' => PdfTemplate::KIND_DOCUMENT,
|
||||||
|
'show_cover' => $this->showCover,
|
||||||
|
...PdfTemplate::columns('header', $this->bilder['header']),
|
||||||
|
...PdfTemplate::columns('footer', $this->bilder['footer']),
|
||||||
|
...PdfTemplate::columns('cover', $this->bilder['cover']),
|
||||||
|
'header_align' => $this->layouts()[0]['align'],
|
||||||
|
'header_logo_height' => $this->layouts()[0]['height'],
|
||||||
|
'footer_align' => $this->layouts()[1]['align'],
|
||||||
|
'footer_logo_height' => $this->layouts()[1]['height'],
|
||||||
|
'toc_mode' => $this->tocSetting()['mode'],
|
||||||
|
'toc_depth' => $this->tocSetting()['depth'],
|
||||||
|
'publisher' => trim($this->publisher) === '' ? null : trim($this->publisher),
|
||||||
|
'copyright' => trim($this->copyright) === '' ? null : trim($this->copyright),
|
||||||
|
];
|
||||||
|
$template = $this->templateId > 0 ? PdfTemplate::query()->find($this->templateId) : null;
|
||||||
|
$template instanceof PdfTemplate ? $template->update($values) : $template = PdfTemplate::query()->create($values);
|
||||||
|
$this->loadTemplate($template);
|
||||||
|
Notification::make()->success()->title('Vorlage gespeichert')->body('Sie gilt sofort für jedes Dokument, das sie verwendet, auch für ältere Fassungen.')->send();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function askConfirmation(string $aktion): void
|
||||||
|
{
|
||||||
|
if ($aktion === 'delete' && $this->templateId > 0) {
|
||||||
|
$uses = PdfTemplate::query()->withCount('compositions')->find($this->templateId)?->compositions_count ?? 0;
|
||||||
|
$this->bestaetigung = [
|
||||||
|
'aktion' => 'delete',
|
||||||
|
'argument' => null,
|
||||||
|
'titel' => '„'.$this->name.'“ löschen?',
|
||||||
|
'text' => $uses > 0
|
||||||
|
? $uses.' '.($uses === 1 ? 'Dokument verwendet' : 'Dokumente verwenden').' diese Vorlage und '.($uses === 1 ? 'erzeugt' : 'erzeugen').' danach wieder das einfache PDF ohne Titelseite. Die Bilder bleiben im Medienbestand.'
|
||||||
|
: 'Die Vorlage wird entfernt. Die Bilder bleiben im Medienbestand.',
|
||||||
|
'label' => 'Vorlage löschen',
|
||||||
|
'gefahr' => true,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function confirmConfirmation(): void
|
||||||
|
{
|
||||||
|
$frage = $this->bestaetigung;
|
||||||
|
$this->bestaetigung = null;
|
||||||
|
|
||||||
|
if (($frage['aktion'] ?? null) === 'delete' && $this->templateId > 0) {
|
||||||
|
abort_unless(ContentElementResource::editor(), 403);
|
||||||
|
PdfTemplate::query()->whereKey($this->templateId)->delete();
|
||||||
|
$this->mount();
|
||||||
|
Notification::make()->success()->title('Vorlage gelöscht')->send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cancelConfirmation(): void
|
||||||
|
{
|
||||||
|
$this->bestaetigung = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function openImagePicker(string $slot): void
|
||||||
|
{
|
||||||
|
if (! in_array($slot, ['header', 'footer', 'cover'], true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->bildFeld = $slot;
|
||||||
|
$this->resetPicker('vorlagenbild');
|
||||||
|
$this->pickerKind = 'bild';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clearImage(string $slot): void
|
||||||
|
{
|
||||||
|
if (in_array($slot, PdfTemplate::SLOTS, true)) {
|
||||||
|
$this->bilder[$slot] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pickerAllowsMany(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function closePicker(): void
|
||||||
|
{
|
||||||
|
$this->pickerOpen = false;
|
||||||
|
$this->pickerSelected = '';
|
||||||
|
$this->pickerInspected = '';
|
||||||
|
$this->pickerMarked = [];
|
||||||
|
$this->bildFeld = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function confirmPicker(): void
|
||||||
|
{
|
||||||
|
$target = array_key_first($this->pickerMarked);
|
||||||
|
$slot = $this->bildFeld;
|
||||||
|
|
||||||
|
if ($target === null || $slot === null || ! in_array($slot, PdfTemplate::SLOTS, true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$problem = TemplateImage::problem((string) $target);
|
||||||
|
|
||||||
|
if ($problem !== null) {
|
||||||
|
Notification::make()->danger()->title('Dieses Bild lässt sich nicht verwenden.')->body($problem)->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->bilder[$slot] = (string) $target;
|
||||||
|
$this->closePicker();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array<string, string> */
|
||||||
|
public function pickerKinds(): array
|
||||||
|
{
|
||||||
|
return ['bild' => 'Bilder'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pickerTitle(): string
|
||||||
|
{
|
||||||
|
return 'Bild für '.$this->slotLabel((string) $this->bildFeld);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pickerConfirmLabel(): string
|
||||||
|
{
|
||||||
|
return 'Bild übernehmen';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array{art: string, titel: string} */
|
||||||
|
public function pickerKontext(): array
|
||||||
|
{
|
||||||
|
return ['art' => 'die PDF-Vorlage', 'titel' => trim($this->name) !== '' ? $this->name : 'neue Vorlage'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array<string, string> */
|
||||||
|
public function presentationRoleOptions(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array<string, mixed>|null */
|
||||||
|
public function pickerReplacing(): ?array
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function imageUrl(?string $target): ?string
|
||||||
|
{
|
||||||
|
return TemplateImage::previewUrl($target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function imageTitle(?string $target): string
|
||||||
|
{
|
||||||
|
return TemplateImage::title($target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function slotLabel(string $slot): string
|
||||||
|
{
|
||||||
|
return match ($slot) {
|
||||||
|
'header' => 'den Kopf der Seiten',
|
||||||
|
'footer' => 'den Fuß der Seiten',
|
||||||
|
'cover' => 'die Titelseite',
|
||||||
|
default => 'die Vorlage',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private function loadTemplate(PdfTemplate $template): void
|
||||||
|
{
|
||||||
|
$this->templateId = $template->id;
|
||||||
|
$this->name = $template->name;
|
||||||
|
$this->publisher = (string) $template->publisher;
|
||||||
|
$this->copyright = (string) $template->copyright;
|
||||||
|
$this->showCover = (bool) $template->show_cover;
|
||||||
|
$this->bilder = $this->templateSlots($template);
|
||||||
|
$this->anordnung = ['header' => $template->layout('header')['align'], 'footer' => $template->layout('footer')['align']];
|
||||||
|
$this->logohoehe = ['header' => $template->layout('header')['height'], 'footer' => $template->layout('footer')['height']];
|
||||||
|
$this->tocModus = $template->toc()['mode'];
|
||||||
|
$this->tocTiefe = $template->toc()['depth'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{mode: string, depth: int}
|
||||||
|
*/
|
||||||
|
private function tocSetting(): array
|
||||||
|
{
|
||||||
|
return PdfTemplate::normalizeToc($this->tocModus, $this->tocTiefe);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anordnung und Logohöhe von Kopf und Fuß, ungültige Eingaben auf gültige Werte gebracht.
|
||||||
|
*
|
||||||
|
* @return list<array{align: string, height: int}>
|
||||||
|
*/
|
||||||
|
private function layouts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
PdfTemplate::normalizeLayout($this->anordnung['header'] ?? null, $this->logohoehe['header'] ?? null),
|
||||||
|
PdfTemplate::normalizeLayout($this->anordnung['footer'] ?? null, $this->logohoehe['footer'] ?? null),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string|null>
|
||||||
|
*/
|
||||||
|
private function templateSlots(PdfTemplate $template): array
|
||||||
|
{
|
||||||
|
return ['header' => $template->target('header'), 'footer' => $template->target('footer'), 'cover' => $template->target('cover')];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function clearForm(): void
|
||||||
|
{
|
||||||
|
$this->templateId = 0;
|
||||||
|
$this->name = '';
|
||||||
|
$this->publisher = '';
|
||||||
|
$this->copyright = '';
|
||||||
|
$this->showCover = true;
|
||||||
|
$this->bilder = ['header' => null, 'footer' => null, 'cover' => null];
|
||||||
|
$this->anordnung = ['header' => 'full', 'footer' => 'full'];
|
||||||
|
$this->logohoehe = ['header' => PdfTemplate::LOGO_DEFAULT, 'footer' => PdfTemplate::LOGO_DEFAULT];
|
||||||
|
$this->tocModus = 'auto';
|
||||||
|
$this->tocTiefe = PdfTemplate::TOC_DEPTH_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function pickerExceptId(): int
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@ class CombinationResource extends CompositionKindResource
|
|||||||
|
|
||||||
protected static ?string $pluralModelLabel = 'Fachliche Kombinationen';
|
protected static ?string $pluralModelLabel = 'Fachliche Kombinationen';
|
||||||
|
|
||||||
protected static ?int $navigationSort = 5;
|
protected static ?int $navigationSort = 6;
|
||||||
|
|
||||||
public static function kind(): CompositionKind
|
public static function kind(): CompositionKind
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
use App\Domain\Catalog\ContentElementVersion;
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
use App\Domain\Catalog\ContentService;
|
use App\Domain\Catalog\ContentService;
|
||||||
use App\Domain\Catalog\ContentVersionStatus;
|
use App\Domain\Catalog\ContentVersionStatus;
|
||||||
|
use App\Domain\Catalog\DocumentMeta;
|
||||||
use App\Domain\Catalog\DomainRuleException;
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
use App\Domain\Catalog\EditorialVocabulary;
|
use App\Domain\Catalog\EditorialVocabulary;
|
||||||
use App\Domain\Catalog\EditorialWorkingDraft;
|
use App\Domain\Catalog\EditorialWorkingDraft;
|
||||||
@@ -21,12 +22,14 @@
|
|||||||
use App\Domain\Catalog\IdentityDimension;
|
use App\Domain\Catalog\IdentityDimension;
|
||||||
use App\Domain\Catalog\IdentityDimensionValue;
|
use App\Domain\Catalog\IdentityDimensionValue;
|
||||||
use App\Domain\Catalog\IdentityProfile;
|
use App\Domain\Catalog\IdentityProfile;
|
||||||
|
use App\Domain\Catalog\PdfTemplate;
|
||||||
use App\Domain\Catalog\StructureNode;
|
use App\Domain\Catalog\StructureNode;
|
||||||
use App\Domain\Cms\Catalog\PublicCatalogReader;
|
use App\Domain\Cms\Catalog\PublicCatalogReader;
|
||||||
use App\Domain\Cms\Widgets\RenderContext;
|
use App\Domain\Cms\Widgets\RenderContext;
|
||||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
use App\Filament\Support\AssignsPillars;
|
use App\Filament\Support\AssignsPillars;
|
||||||
use App\Filament\Support\EditorialCatalog;
|
use App\Filament\Support\EditorialCatalog;
|
||||||
|
use App\Filament\Support\ManagesDocumentChapters;
|
||||||
use App\Filament\Support\ManagesEditorialSurface;
|
use App\Filament\Support\ManagesEditorialSurface;
|
||||||
use App\Filament\Support\ManagesRichFields;
|
use App\Filament\Support\ManagesRichFields;
|
||||||
use App\Filament\Support\MediumForm;
|
use App\Filament\Support\MediumForm;
|
||||||
@@ -50,6 +53,7 @@
|
|||||||
abstract class EditComposition extends EditRecord
|
abstract class EditComposition extends EditRecord
|
||||||
{
|
{
|
||||||
use AssignsPillars;
|
use AssignsPillars;
|
||||||
|
use ManagesDocumentChapters;
|
||||||
use ManagesEditorialSurface;
|
use ManagesEditorialSurface;
|
||||||
use ManagesRichFields;
|
use ManagesRichFields;
|
||||||
use WithFileUploads;
|
use WithFileUploads;
|
||||||
@@ -79,6 +83,18 @@ abstract class EditComposition extends EditRecord
|
|||||||
|
|
||||||
public string $durationMax = '';
|
public string $durationMax = '';
|
||||||
|
|
||||||
|
/** Dokumentfassung (ADR-51): Angaben für Titelseite und Impressum des PDF. Sie gehören zur Fassung. */
|
||||||
|
public string $docSubtitle = '';
|
||||||
|
|
||||||
|
public string $docEdition = '';
|
||||||
|
|
||||||
|
public string $docPublished = '';
|
||||||
|
|
||||||
|
public string $docCopyright = '';
|
||||||
|
|
||||||
|
/** Die PDF-Vorlage des Dokuments („“ = bisheriges Layout). Wirkt sofort, ohne Fassung. */
|
||||||
|
public string $pdfTemplateId = '';
|
||||||
|
|
||||||
public string $prerequisites = '';
|
public string $prerequisites = '';
|
||||||
|
|
||||||
public string $newVariantName = '';
|
public string $newVariantName = '';
|
||||||
@@ -278,6 +294,10 @@ public function previewUrl(): ?string
|
|||||||
/** @var Composition $composition */
|
/** @var Composition $composition */
|
||||||
$composition = $this->getRecord();
|
$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 !== []) {
|
if (is_array($composition->working_draft) && $composition->working_draft !== []) {
|
||||||
return route('editorial.draft-preview', ['composition' => $composition]);
|
return route('editorial.draft-preview', ['composition' => $composition]);
|
||||||
}
|
}
|
||||||
@@ -371,8 +391,18 @@ public function redaktionKopf(): array
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'art' => $this->hostLabel(),
|
'art' => $this->hostLabel(),
|
||||||
'fuer' => $program ? 'das Programm' : 'das Modul',
|
'fuer' => match (true) {
|
||||||
'liste' => $program ? 'Programme' : 'Module',
|
$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',
|
'zurueck' => 'Zurück zum Aufbau',
|
||||||
'typ' => null,
|
'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.',
|
'umfang' => '„Redaktion speichern“ sichert Name, Texte, Präsentationsmedien und Einordnung. Aufbau, Lernziel, Zeit und Fassungen bleiben unverändert; offene Änderungen am Aufbau bleiben offen.',
|
||||||
@@ -401,6 +431,16 @@ protected function richFelder(): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texte dürfen Bilder aus dem Medienbestand enthalten (gemeinsamer Picker); Kurzangaben nicht.
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
protected function richBilder(): array
|
||||||
|
{
|
||||||
|
return ['partBody', 'newTextBody'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return list<array<string, mixed>>
|
* @return list<array<string, mixed>>
|
||||||
*/
|
*/
|
||||||
@@ -695,10 +735,16 @@ public function saveDraft(): void
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! $this->persistChapterEdits()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/** @var Composition $record */
|
/** @var Composition $record */
|
||||||
$record = $this->getRecord();
|
$record = $this->getRecord();
|
||||||
app(EditorialWorkingDraft::class)->write($record, $this->payload());
|
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
|
public function armRelease(): void
|
||||||
@@ -712,6 +758,12 @@ public function armRelease(): void
|
|||||||
|
|
||||||
$this->commitRoleDraft();
|
$this->commitRoleDraft();
|
||||||
|
|
||||||
|
if (! $this->persistChapterEdits()) {
|
||||||
|
$this->releaseArmed = false;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->members === []) {
|
if ($this->members === []) {
|
||||||
$this->releaseArmed = false;
|
$this->releaseArmed = false;
|
||||||
$this->feedback = 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Entwurf kannst du schon speichern.';
|
$this->feedback = 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Entwurf kannst du schon speichern.';
|
||||||
@@ -761,6 +813,11 @@ public function releaseFollowUp(): string
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->isDocument()) {
|
||||||
|
return 'Module und Programme binden eine Dokumentfassung über „Hinzufügen“ ein; ein Stand schreibt sie dann fest. Frühere Fassungen bleiben dort, wo sie eingebunden sind, unverändert.'
|
||||||
|
.(is_array($this->getRecord()->working_draft) && $this->getRecord()->working_draft !== [] ? ' Es gibt einen gespeicherten Entwurf neben der bereitgestellten Fassung.' : ' Es gibt keinen offenen Entwurf.');
|
||||||
|
}
|
||||||
|
|
||||||
/** @var Composition $composition */
|
/** @var Composition $composition */
|
||||||
$composition = $this->getRecord();
|
$composition = $this->getRecord();
|
||||||
$releases = app(CompositionDisplayRelease::class);
|
$releases = app(CompositionDisplayRelease::class);
|
||||||
@@ -797,6 +854,7 @@ public function discardDraft(): void
|
|||||||
$record = $this->getRecord();
|
$record = $this->getRecord();
|
||||||
app(EditorialWorkingDraft::class)->clear($record);
|
app(EditorialWorkingDraft::class)->clear($record);
|
||||||
$this->releaseArmed = false;
|
$this->releaseArmed = false;
|
||||||
|
$this->chapterEdits = [];
|
||||||
$this->loadAufbau();
|
$this->loadAufbau();
|
||||||
$this->selected = null;
|
$this->selected = null;
|
||||||
$this->selectFirstPart();
|
$this->selectFirstPart();
|
||||||
@@ -842,6 +900,12 @@ public function includeNeedsRelease(): bool
|
|||||||
|
|
||||||
public function moveTo(int $from, int $to): void
|
public function moveTo(int $from, int $to): void
|
||||||
{
|
{
|
||||||
|
if ($this->isDocument()) {
|
||||||
|
$this->moveChapterTo($from, $to);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->commitRoleDraft();
|
$this->commitRoleDraft();
|
||||||
$count = count($this->members);
|
$count = count($this->members);
|
||||||
|
|
||||||
@@ -1174,6 +1238,11 @@ public function removePart(int $index): void
|
|||||||
}
|
}
|
||||||
|
|
||||||
$title = (string) ($this->members[$index]['title'] ?? 'Der Bestandteil');
|
$title = (string) ($this->members[$index]['title'] ?? 'Der Bestandteil');
|
||||||
|
|
||||||
|
if ($this->isDocument()) {
|
||||||
|
$this->forgetChapter($index);
|
||||||
|
}
|
||||||
|
|
||||||
unset($this->members[$index]);
|
unset($this->members[$index]);
|
||||||
$this->members = array_values($this->members);
|
$this->members = array_values($this->members);
|
||||||
$this->selected = $this->members === [] ? null : min($index, count($this->members) - 1);
|
$this->selected = $this->members === [] ? null : min($index, count($this->members) - 1);
|
||||||
@@ -1196,7 +1265,9 @@ protected function extraConfirmation(string $aktion, int|string|null $argument):
|
|||||||
'aktion' => $aktion,
|
'aktion' => $aktion,
|
||||||
'argument' => (int) $argument,
|
'argument' => (int) $argument,
|
||||||
'titel' => '„'.$title.'“ aus diesem Aufbau entfernen?',
|
'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',
|
'label' => 'Aus dem Aufbau entfernen',
|
||||||
'gefahr' => true,
|
'gefahr' => true,
|
||||||
];
|
];
|
||||||
@@ -1211,6 +1282,12 @@ protected function runExtraConfirmation(string $aktion, int|string|null $argumen
|
|||||||
|
|
||||||
public function movePart(int $index, int $direction): void
|
public function movePart(int $index, int $direction): void
|
||||||
{
|
{
|
||||||
|
if ($this->isDocument()) {
|
||||||
|
$this->moveChapter($index, $direction);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->commitRoleDraft();
|
$this->commitRoleDraft();
|
||||||
$target = $index + $direction;
|
$target = $index + $direction;
|
||||||
|
|
||||||
@@ -1729,6 +1806,11 @@ public function presentationChips(): array
|
|||||||
{
|
{
|
||||||
/** @var Composition $composition */
|
/** @var Composition $composition */
|
||||||
$composition = $this->getRecord();
|
$composition = $this->getRecord();
|
||||||
|
|
||||||
|
// Ein Dokument erscheint nie als eigene Karte in der Bibliothek; es wird in Module und Programme eingebunden.
|
||||||
|
if ($this->isDocument()) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
$offered = in_array($composition->id, app(EditorialCatalog::class)->offeredCompositionIds(), true);
|
$offered = in_array($composition->id, app(EditorialCatalog::class)->offeredCompositionIds(), true);
|
||||||
|
|
||||||
return app(EditorialCatalog::class)->statusChips($composition, $offered);
|
return app(EditorialCatalog::class)->statusChips($composition, $offered);
|
||||||
@@ -1744,6 +1826,10 @@ public function publishRevision(): bool
|
|||||||
|
|
||||||
$this->commitRoleDraft();
|
$this->commitRoleDraft();
|
||||||
|
|
||||||
|
if (! $this->persistChapterEdits()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->members === []) {
|
if ($this->members === []) {
|
||||||
$this->feedback = 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Kurzbeschreibung kannst du schon speichern.';
|
$this->feedback = 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Kurzbeschreibung kannst du schon speichern.';
|
||||||
|
|
||||||
@@ -1784,6 +1870,7 @@ public function publishRevision(): bool
|
|||||||
'duration_max' => $this->blank($this->durationMax),
|
'duration_max' => $this->blank($this->durationMax),
|
||||||
'material_note' => $this->richBlank('materialNote'),
|
'material_note' => $this->richBlank('materialNote'),
|
||||||
'prerequisites' => $this->blank($this->prerequisites),
|
'prerequisites' => $this->blank($this->prerequisites),
|
||||||
|
'document_meta' => $this->documentMetaNow(),
|
||||||
],
|
],
|
||||||
$this->releaseConsent,
|
$this->releaseConsent,
|
||||||
$this->normalizeVariants($this->variants),
|
$this->normalizeVariants($this->variants),
|
||||||
@@ -1803,7 +1890,9 @@ public function publishRevision(): bool
|
|||||||
$this->loadEditor();
|
$this->loadEditor();
|
||||||
$released = $this->currentReadyVersion();
|
$released = $this->currentReadyVersion();
|
||||||
$number = $released instanceof CompositionVersion ? $released->number : '';
|
$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) {
|
if ($this->returnAfterRelease) {
|
||||||
$this->returnAfterRelease = false;
|
$this->returnAfterRelease = false;
|
||||||
@@ -1901,6 +1990,7 @@ protected function loadAufbau(): void
|
|||||||
$this->thumbnailError = $composition->thumbnail_error;
|
$this->thumbnailError = $composition->thumbnail_error;
|
||||||
$this->thumbnailSource = $composition->thumbnail_source;
|
$this->thumbnailSource = $composition->thumbnail_source;
|
||||||
$this->imageCaptionText = $this->captionFor($composition->thumbnail_source);
|
$this->imageCaptionText = $this->captionFor($composition->thumbnail_source);
|
||||||
|
$this->pdfTemplateId = $composition->pdf_template_id === null ? '' : (string) $composition->pdf_template_id;
|
||||||
$this->catalogScope = match ($this->hostKind()) {
|
$this->catalogScope = match ($this->hostKind()) {
|
||||||
CompositionKind::Kurs => 'module',
|
CompositionKind::Kurs => 'module',
|
||||||
CompositionKind::Uebung => 'uebungen',
|
CompositionKind::Uebung => 'uebungen',
|
||||||
@@ -1924,6 +2014,7 @@ protected function loadAufbau(): void
|
|||||||
$this->learningGoal = '';
|
$this->learningGoal = '';
|
||||||
$this->durationMinutes = '';
|
$this->durationMinutes = '';
|
||||||
$this->materialNote = '';
|
$this->materialNote = '';
|
||||||
|
$this->fillDocumentMeta(null);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1959,12 +2050,14 @@ protected function applyDraft(array $draft): void
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->members = $rows;
|
$this->members = $rows;
|
||||||
|
$this->slimChapterMembers();
|
||||||
$this->variants = $this->normalizeVariants($draft['variants'] ?? []);
|
$this->variants = $this->normalizeVariants($draft['variants'] ?? []);
|
||||||
$this->durationMax = ($draft['duration_max'] ?? null) === null ? '' : (string) $draft['duration_max'];
|
$this->durationMax = ($draft['duration_max'] ?? null) === null ? '' : (string) $draft['duration_max'];
|
||||||
$this->prerequisites = (string) ($draft['prerequisites'] ?? '');
|
$this->prerequisites = (string) ($draft['prerequisites'] ?? '');
|
||||||
$this->learningGoal = (string) ($draft['learning_goal'] ?? '');
|
$this->learningGoal = (string) ($draft['learning_goal'] ?? '');
|
||||||
$this->durationMinutes = ($draft['duration_minutes'] ?? null) === null ? '' : (string) $draft['duration_minutes'];
|
$this->durationMinutes = ($draft['duration_minutes'] ?? null) === null ? '' : (string) $draft['duration_minutes'];
|
||||||
$this->materialNote = (string) ($draft['material_note'] ?? '');
|
$this->materialNote = (string) ($draft['material_note'] ?? '');
|
||||||
|
$this->fillDocumentMeta($draft['document_meta'] ?? null);
|
||||||
$this->revisionNote = (string) ($draft['revision_note'] ?? '');
|
$this->revisionNote = (string) ($draft['revision_note'] ?? '');
|
||||||
$this->selected = null;
|
$this->selected = null;
|
||||||
$this->roleDraft = '';
|
$this->roleDraft = '';
|
||||||
@@ -1979,6 +2072,7 @@ protected function applyDraft(array $draft): void
|
|||||||
protected function applyVersion(CompositionVersion $version): void
|
protected function applyVersion(CompositionVersion $version): void
|
||||||
{
|
{
|
||||||
$this->members = app(EditorialCatalog::class)->rows($version, (int) $this->getRecord()->getKey());
|
$this->members = app(EditorialCatalog::class)->rows($version, (int) $this->getRecord()->getKey());
|
||||||
|
$this->slimChapterMembers();
|
||||||
$this->variants = $this->normalizeVariants($version->variants->map(fn ($variant): array => [
|
$this->variants = $this->normalizeVariants($version->variants->map(fn ($variant): array => [
|
||||||
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description, 'origin' => $variant->origin,
|
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description, 'origin' => $variant->origin,
|
||||||
])->all());
|
])->all());
|
||||||
@@ -1987,6 +2081,7 @@ protected function applyVersion(CompositionVersion $version): void
|
|||||||
$this->learningGoal = (string) ($version->learning_goal ?? '');
|
$this->learningGoal = (string) ($version->learning_goal ?? '');
|
||||||
$this->durationMinutes = $version->duration_minutes === null ? '' : (string) $version->duration_minutes;
|
$this->durationMinutes = $version->duration_minutes === null ? '' : (string) $version->duration_minutes;
|
||||||
$this->materialNote = (string) ($version->material_note ?? '');
|
$this->materialNote = (string) ($version->material_note ?? '');
|
||||||
|
$this->fillDocumentMeta($version->document_meta);
|
||||||
$this->selected = null;
|
$this->selected = null;
|
||||||
$this->roleDraft = '';
|
$this->roleDraft = '';
|
||||||
$this->noteDraft = '';
|
$this->noteDraft = '';
|
||||||
@@ -2004,6 +2099,13 @@ protected function commitRoleDraft(?string $value = null): void
|
|||||||
return;
|
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]['role'] = trim($value ?? $this->roleDraft);
|
||||||
$this->members[$this->selected]['note'] = trim($this->noteDraft);
|
$this->members[$this->selected]['note'] = trim($this->noteDraft);
|
||||||
}
|
}
|
||||||
@@ -2013,6 +2115,13 @@ protected function syncRoleDraft(): void
|
|||||||
$member = $this->selected !== null ? ($this->members[$this->selected] ?? null) : null;
|
$member = $this->selected !== null ? ($this->members[$this->selected] ?? null) : null;
|
||||||
$this->roleDraft = is_array($member) ? (string) ($member['role'] ?? '') : '';
|
$this->roleDraft = is_array($member) ? (string) ($member['role'] ?? '') : '';
|
||||||
$this->noteDraft = is_array($member) ? (string) ($member['note'] ?? '') : '';
|
$this->noteDraft = is_array($member) ? (string) ($member['note'] ?? '') : '';
|
||||||
|
|
||||||
|
if ($this->isDocument()) {
|
||||||
|
$this->loadChapterFields();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->partTitle = is_array($member) ? (string) ($member['title'] ?? '') : '';
|
$this->partTitle = is_array($member) ? (string) ($member['title'] ?? '') : '';
|
||||||
$this->partBody = is_array($member) ? (string) ($member['body'] ?? '') : '';
|
$this->partBody = is_array($member) ? (string) ($member['body'] ?? '') : '';
|
||||||
}
|
}
|
||||||
@@ -2089,6 +2198,66 @@ protected function sameMembers(CompositionVersion $version): bool
|
|||||||
return $current === $next;
|
return $current === $next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Angaben der Dokumentfassung im Arbeitsstand; nur bei einem Dokument, sonst null.
|
||||||
|
*
|
||||||
|
* @return array<string, string>|null
|
||||||
|
*/
|
||||||
|
protected function documentMetaNow(): ?array
|
||||||
|
{
|
||||||
|
if (! $this->isDocument()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DocumentMeta::normalize([
|
||||||
|
'subtitle' => $this->docSubtitle,
|
||||||
|
'edition' => $this->docEdition,
|
||||||
|
'published_on' => $this->docPublished,
|
||||||
|
'copyright' => $this->docCopyright,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function fillDocumentMeta(mixed $meta): void
|
||||||
|
{
|
||||||
|
$meta = DocumentMeta::normalize($meta) ?? [];
|
||||||
|
$this->docSubtitle = $meta['subtitle'] ?? '';
|
||||||
|
$this->docEdition = $meta['edition'] ?? '';
|
||||||
|
$this->docPublished = $meta['published_on'] ?? '';
|
||||||
|
$this->docCopyright = $meta['copyright'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die wählbaren PDF-Vorlagen für Dokumente.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function pdfTemplateOptions(): array
|
||||||
|
{
|
||||||
|
return PdfTemplate::query()->where('kind', PdfTemplate::KIND_DOCUMENT)->orderBy('name')->pluck('name', 'id')
|
||||||
|
->mapWithKeys(fn (string $name, int|string $id): array => [(string) $id => $name])->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ordnet dem Dokument eine PDF-Vorlage zu. Das gilt sofort für jedes PDF dieses Dokuments, auch für ältere Fassungen. */
|
||||||
|
public function savePdfTemplate(): void
|
||||||
|
{
|
||||||
|
$this->guardEditorial();
|
||||||
|
$id = ctype_digit($this->pdfTemplateId) ? (int) $this->pdfTemplateId : null;
|
||||||
|
|
||||||
|
if ($id !== null && ! PdfTemplate::query()->where('kind', PdfTemplate::KIND_DOCUMENT)->whereKey($id)->exists()) {
|
||||||
|
$this->feedback = 'Diese PDF-Vorlage gibt es nicht mehr.';
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Composition $composition */
|
||||||
|
$composition = $this->getRecord();
|
||||||
|
$composition->pdf_template_id = $id;
|
||||||
|
$composition->save();
|
||||||
|
$this->feedback = $id === null
|
||||||
|
? 'Das Dokument verwendet wieder das einfache PDF-Layout ohne Titelseite.'
|
||||||
|
: 'Die PDF-Vorlage ist zugeordnet. Sie gilt sofort für jedes PDF dieses Dokuments, auch für ältere Fassungen; Ausgabe, Datum und Vermerk bleiben je Fassung.';
|
||||||
|
}
|
||||||
|
|
||||||
protected function didacticChanged(CompositionVersion $version): bool
|
protected function didacticChanged(CompositionVersion $version): bool
|
||||||
{
|
{
|
||||||
$minutes = $this->minutes($this->durationMinutes);
|
$minutes = $this->minutes($this->durationMinutes);
|
||||||
@@ -2108,6 +2277,7 @@ protected function didacticChanged(CompositionVersion $version): bool
|
|||||||
|| $version->prerequisites !== $this->blank($this->prerequisites)
|
|| $version->prerequisites !== $this->blank($this->prerequisites)
|
||||||
|| ($version->duration_max === null ? null : (string) $version->duration_max) !== $this->blank($this->durationMax)
|
|| ($version->duration_max === null ? null : (string) $version->duration_max) !== $this->blank($this->durationMax)
|
||||||
|| $storedVariants !== $this->normalizeVariants($this->variants)
|
|| $storedVariants !== $this->normalizeVariants($this->variants)
|
||||||
|
|| DocumentMeta::normalize($version->document_meta) !== $this->documentMetaNow()
|
||||||
|| $storedMinutes !== $minutes;
|
|| $storedMinutes !== $minutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2330,6 +2500,9 @@ protected function payload(): array
|
|||||||
'prerequisites' => $this->blank($this->prerequisites),
|
'prerequisites' => $this->blank($this->prerequisites),
|
||||||
'variants' => $this->normalizeVariants($this->variants),
|
'variants' => $this->normalizeVariants($this->variants),
|
||||||
'revision_note' => $this->blank($this->revisionNote),
|
'revision_note' => $this->blank($this->revisionNote),
|
||||||
|
'document_meta' => $this->documentMetaNow(),
|
||||||
|
// Ungespeicherte Texte der Kapitel gelten als Änderung des Entwurfs; nach dem Speichern sind sie leer.
|
||||||
|
'chapters' => $this->chapterEditsNow(),
|
||||||
'members' => array_values(array_map(
|
'members' => array_values(array_map(
|
||||||
fn (array $member): array => [
|
fn (array $member): array => [
|
||||||
'role' => trim((string) ($member['role'] ?? '')),
|
'role' => trim((string) ($member['role'] ?? '')),
|
||||||
@@ -2374,6 +2547,7 @@ protected function readyPayload(): array
|
|||||||
'prerequisites' => null,
|
'prerequisites' => null,
|
||||||
'variants' => [],
|
'variants' => [],
|
||||||
'revision_note' => null,
|
'revision_note' => null,
|
||||||
|
'document_meta' => null,
|
||||||
'members' => [],
|
'members' => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -2390,6 +2564,7 @@ protected function readyPayload(): array
|
|||||||
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description, 'origin' => $variant->origin,
|
'key' => $variant->key, 'name' => $variant->name, 'description' => (string) $variant->description, 'origin' => $variant->origin,
|
||||||
])->all()),
|
])->all()),
|
||||||
'revision_note' => null,
|
'revision_note' => null,
|
||||||
|
'document_meta' => DocumentMeta::normalize($version->document_meta),
|
||||||
'members' => array_values(array_map(
|
'members' => array_values(array_map(
|
||||||
fn (array $row): array => [
|
fn (array $row): array => [
|
||||||
'role' => trim((string) ($row['role'] ?? '')),
|
'role' => trim((string) ($row['role'] ?? '')),
|
||||||
@@ -2432,6 +2607,8 @@ protected function normalizePayload(array $payload): array
|
|||||||
'prerequisites' => $payload['prerequisites'] ?? null,
|
'prerequisites' => $payload['prerequisites'] ?? null,
|
||||||
'variants' => $this->normalizeVariants($payload['variants'] ?? []),
|
'variants' => $this->normalizeVariants($payload['variants'] ?? []),
|
||||||
'revision_note' => $payload['revision_note'] ?? null,
|
'revision_note' => $payload['revision_note'] ?? null,
|
||||||
|
'document_meta' => DocumentMeta::normalize($payload['document_meta'] ?? null),
|
||||||
|
'chapters' => is_array($payload['chapters'] ?? null) ? $payload['chapters'] : [],
|
||||||
'members' => $members,
|
'members' => $members,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,14 +34,12 @@ protected function fixedKind(): ?CompositionKind
|
|||||||
|
|
||||||
private function onDesk(): bool
|
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
|
public function getSubheading(): string|Htmlable|null
|
||||||
{
|
{
|
||||||
$desk = $this->onDesk() && $this->kind() !== CompositionKind::Exercise ? ' Programme und Module stehen gemeinsam auch auf dem Arbeitsplatz.' : '';
|
return $this->kind()->deskExplanation();
|
||||||
|
|
||||||
return $this->kind()->deskExplanation().$desk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMaxContentWidth(): Width|string|null
|
public function getMaxContentWidth(): Width|string|null
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ class ContentElementResource extends Resource
|
|||||||
|
|
||||||
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||||
|
|
||||||
protected static ?string $navigationLabel = 'Medien';
|
protected static ?string $navigationLabel = 'Contentmanager';
|
||||||
|
|
||||||
|
protected static ?string $slug = 'contentmanager';
|
||||||
|
|
||||||
protected static ?string $modelLabel = 'Medium';
|
protected static ?string $modelLabel = 'Medium';
|
||||||
|
|
||||||
@@ -32,7 +34,7 @@ class ContentElementResource extends Resource
|
|||||||
|
|
||||||
protected static ?string $recordTitleAttribute = 'working_title';
|
protected static ?string $recordTitleAttribute = 'working_title';
|
||||||
|
|
||||||
protected static ?int $navigationSort = 1;
|
protected static ?int $navigationSort = 4;
|
||||||
|
|
||||||
public static function canViewAny(): bool
|
public static function canViewAny(): bool
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
use App\Domain\Catalog\ContentService;
|
use App\Domain\Catalog\ContentService;
|
||||||
use App\Domain\Catalog\DomainRuleException;
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
use App\Domain\Catalog\EditorialVocabulary;
|
use App\Domain\Catalog\EditorialVocabulary;
|
||||||
|
use App\Domain\Catalog\EmbeddedImages;
|
||||||
use App\Domain\Catalog\FormattedText;
|
use App\Domain\Catalog\FormattedText;
|
||||||
use App\Domain\Catalog\IdentityDimension;
|
use App\Domain\Catalog\IdentityDimension;
|
||||||
use App\Domain\Catalog\IdentityDimensionValue;
|
use App\Domain\Catalog\IdentityDimensionValue;
|
||||||
@@ -195,7 +196,7 @@ protected function mutateFormDataBeforeFill(array $data): array
|
|||||||
return [
|
return [
|
||||||
'working_title' => $this->getRecord()->working_title,
|
'working_title' => $this->getRecord()->working_title,
|
||||||
'thumbnail_alt' => $this->getRecord()->thumbnail_alt,
|
'thumbnail_alt' => $this->getRecord()->thumbnail_alt,
|
||||||
'body' => FormattedText::html($this->getRecord()->versions()->orderByDesc('number')->first()?->body),
|
'body' => EmbeddedImages::forEditor($this->getRecord()->versions()->orderByDesc('number')->first()?->body),
|
||||||
'display_title' => $this->getRecord()->display_title,
|
'display_title' => $this->getRecord()->display_title,
|
||||||
'description' => FormattedText::html($this->getRecord()->description),
|
'description' => FormattedText::html($this->getRecord()->description),
|
||||||
'usage_note' => $this->getRecord()->usage_note,
|
'usage_note' => $this->getRecord()->usage_note,
|
||||||
|
|||||||
@@ -70,13 +70,22 @@ class ListContentElements extends ListRecords
|
|||||||
#[Url(as: 'arten', except: '')]
|
#[Url(as: 'arten', except: '')]
|
||||||
public string $arten = '';
|
public string $arten = '';
|
||||||
|
|
||||||
|
/** Der Filterdialog ist offen. */
|
||||||
|
public bool $filterOffen = false;
|
||||||
|
|
||||||
|
/** Das Filterfeld, bei dem der Dialog beginnt (leer: beim ersten Feld). */
|
||||||
|
public string $filterFokus = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Die gewählten Schlüssel für die Checkboxen (wire:model). `arten` bleibt die maßgebliche Angabe in der Adresse
|
* Arbeitsstand des Dialogs: die Auswahl seit dem Öffnen. Erst „Anwenden“ übernimmt sie in die Filter der Liste,
|
||||||
* und im persönlichen Standard; diese Liste folgt ihr und ändert sie beim Ankreuzen.
|
* „Abbrechen“ verwirft sie.
|
||||||
*
|
*
|
||||||
* @var list<string>
|
* @var array<string, mixed>
|
||||||
*/
|
*/
|
||||||
public array $artenAuswahl = [];
|
public array $filterDraft = [];
|
||||||
|
|
||||||
|
/** Filterfelder mit mehreren Werten (ODER); verschiedene Felder gelten zusammen (UND). */
|
||||||
|
private const MULTI_FIELDS = ['art', 'freigabe', 'nutzung'];
|
||||||
|
|
||||||
#[Url(as: 'einordnung', except: '')]
|
#[Url(as: 'einordnung', except: '')]
|
||||||
public string $einordnung = '';
|
public string $einordnung = '';
|
||||||
@@ -106,25 +115,6 @@ public function mount(): void
|
|||||||
if ($given === [] && ($saved = $this->savedDefault()) !== null) {
|
if ($given === [] && ($saved = $this->savedDefault()) !== null) {
|
||||||
$this->applyFilters($saved);
|
$this->applyFilters($saved);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->syncArtenAuswahl();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updatedArten(): void
|
|
||||||
{
|
|
||||||
$this->syncArtenAuswahl();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Ein Häkchen wurde gesetzt oder entfernt. */
|
|
||||||
public function updatedArtenAuswahl(): void
|
|
||||||
{
|
|
||||||
$known = array_keys($this->artChoices());
|
|
||||||
$this->storeArten(array_values(array_intersect($known, array_map('strval', $this->artenAuswahl))));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function syncArtenAuswahl(): void
|
|
||||||
{
|
|
||||||
$this->artenAuswahl = $this->selectedArten();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSubheading(): string|Htmlable|null
|
public function getSubheading(): string|Htmlable|null
|
||||||
@@ -217,7 +207,6 @@ public function resetFilters(): void
|
|||||||
$this->einordnung = '';
|
$this->einordnung = '';
|
||||||
$this->inhaltsart = '';
|
$this->inhaltsart = '';
|
||||||
$this->arten = '';
|
$this->arten = '';
|
||||||
$this->syncArtenAuswahl();
|
|
||||||
$this->verarbeitung = '';
|
$this->verarbeitung = '';
|
||||||
$this->archiv = 'aktiv';
|
$this->archiv = 'aktiv';
|
||||||
$this->bestandGrenze = Bestand::SCHRITT;
|
$this->bestandGrenze = Bestand::SCHRITT;
|
||||||
@@ -266,11 +255,6 @@ public function selectedArten(): array
|
|||||||
return MaterialKindSelection::decode($this->arten) ?? $this->defaultArten();
|
return MaterialKindSelection::decode($this->arten) ?? $this->defaultArten();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function selectAllArten(): void
|
|
||||||
{
|
|
||||||
$this->storeArten(array_keys($this->artChoices()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param list<string> $keys
|
* @param list<string> $keys
|
||||||
*/
|
*/
|
||||||
@@ -282,7 +266,6 @@ private function storeArten(array $keys): void
|
|||||||
|
|
||||||
// Die allgemeine Startansicht bleibt ohne Eintrag in der Adresse.
|
// Die allgemeine Startansicht bleibt ohne Eintrag in der Adresse.
|
||||||
$this->arten = $keys === $default ? '' : MaterialKindSelection::encode($keys);
|
$this->arten = $keys === $default ? '' : MaterialKindSelection::encode($keys);
|
||||||
$this->syncArtenAuswahl();
|
|
||||||
$this->bestandGrenze = Bestand::SCHRITT;
|
$this->bestandGrenze = Bestand::SCHRITT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,6 +307,7 @@ public function saveDefault(): void
|
|||||||
}
|
}
|
||||||
|
|
||||||
UserViewDefault::remember($userId, UserViewDefault::MEDIA, $filters);
|
UserViewDefault::remember($userId, UserViewDefault::MEDIA, $filters);
|
||||||
|
$this->filterOffen = false;
|
||||||
Notification::make()->title('Standard gespeichert')->body('Der Medienmanager startet für dich mit diesen Filtern.')->success()->send();
|
Notification::make()->title('Standard gespeichert')->body('Der Medienmanager startet für dich mit diesen Filtern.')->success()->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,6 +323,7 @@ public function restoreDefault(): void
|
|||||||
|
|
||||||
$this->suche = '';
|
$this->suche = '';
|
||||||
$this->applyFilters($saved);
|
$this->applyFilters($saved);
|
||||||
|
$this->filterOffen = false;
|
||||||
Notification::make()->title('Dein Standard ist geladen')->success()->send();
|
Notification::make()->title('Dein Standard ist geladen')->success()->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,6 +337,7 @@ public function deleteDefault(): void
|
|||||||
|
|
||||||
$this->resetFilters();
|
$this->resetFilters();
|
||||||
$this->ansicht = 'liste';
|
$this->ansicht = 'liste';
|
||||||
|
$this->filterOffen = false;
|
||||||
Notification::make()->title('Persönlicher Standard gelöscht')->body('Der Medienmanager startet wieder mit der allgemeinen Auswahl.')->success()->send();
|
Notification::make()->title('Persönlicher Standard gelöscht')->body('Der Medienmanager startet wieder mit der allgemeinen Auswahl.')->success()->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,12 +354,198 @@ private function applyFilters(array $filters): void
|
|||||||
|
|
||||||
$this->ansicht = $this->ansicht === 'kacheln' ? 'kacheln' : 'liste';
|
$this->ansicht = $this->ansicht === 'kacheln' ? 'kacheln' : 'liste';
|
||||||
$this->archiv = in_array($this->archiv, ['aktiv', 'archiviert', 'alle'], true) ? $this->archiv : 'aktiv';
|
$this->archiv = in_array($this->archiv, ['aktiv', 'archiviert', 'alle'], true) ? $this->archiv : 'aktiv';
|
||||||
$this->syncArtenAuswahl();
|
$this->bestandGrenze = Bestand::SCHRITT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- Filterdialog
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filterfelder mit Checkboxen (Mehrfachauswahl). Mehrere Werte eines Felds gelten als ODER.
|
||||||
|
*
|
||||||
|
* @return array<string, array{label: string, kurz: string, optionen: array<string, string>}>
|
||||||
|
*/
|
||||||
|
private function multiFields(): array
|
||||||
|
{
|
||||||
|
$arten = array_map(fn (array $choice): string => $choice['label'], $this->artChoices());
|
||||||
|
|
||||||
|
return [
|
||||||
|
'arten' => ['label' => 'Fachliche Materialart', 'kurz' => 'Materialart', 'optionen' => $arten],
|
||||||
|
'art' => ['label' => 'Technische Art', 'kurz' => 'Technische Art', 'optionen' => collect($this->typeOptions())->mapWithKeys(fn (array $type): array => [$type['value'] => $type['label']])->all()],
|
||||||
|
'freigabe' => ['label' => 'Freigabe', 'kurz' => 'Freigabe', 'optionen' => ['freigegeben' => 'Freigegebene Fassung', 'entwurf' => 'Nur offener Entwurf', 'ohne' => 'Keine freigegebene Fassung']],
|
||||||
|
'nutzung' => ['label' => 'Verwendung', 'kurz' => 'Verwendung', 'optionen' => ['verwendet' => 'Verwendet', 'unbenutzt' => 'Nicht verwendet']],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Weitere Kriterien mit einem Wert je Feld, unter „Weitere Filter“ im Dialog.
|
||||||
|
*
|
||||||
|
* @return array<string, array{label: string, vorgabe: string, alle: string|null, optionen: array<string, string>}>
|
||||||
|
*/
|
||||||
|
private function singleFields(): array
|
||||||
|
{
|
||||||
|
$optionen = fn (array $liste, string $wert, string $label): array => collect($liste)
|
||||||
|
->mapWithKeys(fn (array $eintrag): array => [(string) $eintrag[$wert] => $eintrag[$label]])
|
||||||
|
->all();
|
||||||
|
$fields = [
|
||||||
|
'schutz' => ['label' => 'Schutz', 'vorgabe' => '', 'alle' => 'Alle Medien', 'optionen' => ['geschuetzt' => 'Geschützte Medien', 'oeffentlich' => 'Öffentliche Medien', 'website' => 'Auf der Website frei']],
|
||||||
|
'entwurf' => ['label' => 'Entwurf', 'vorgabe' => '', 'alle' => 'Entwurf egal', 'optionen' => ['offen' => 'Offener Entwurf', 'keiner' => 'Kein offener Entwurf']],
|
||||||
|
'fassung' => ['label' => 'Deaktivierte Fassungen', 'vorgabe' => '', 'alle' => 'Regulärer Bestand', 'optionen' => ['mit' => 'Mit deaktivierter Fassung', 'nur' => 'Nur deaktivierte Fassungen']],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (($pillars = $this->pillarOptions()) !== []) {
|
||||||
|
$fields['saeule'] = ['label' => 'Fachliche Säule', 'vorgabe' => '', 'alle' => 'Alle Säulen', 'optionen' => $optionen($pillars, 'id', 'name')];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($classes = $this->classificationOptions()) !== []) {
|
||||||
|
$fields['einordnung'] = ['label' => 'Einordnung', 'vorgabe' => '', 'alle' => 'Alle Einordnungen', 'optionen' => $optionen($classes, 'id', 'label')];
|
||||||
|
}
|
||||||
|
|
||||||
|
$fields['verarbeitung'] = ['label' => 'Verarbeitung', 'vorgabe' => '', 'alle' => 'Verarbeitung egal', 'optionen' => ['fehler' => 'Verarbeitungsfehler', 'uebernahme' => 'Datei wird übernommen']];
|
||||||
|
$fields['archiv'] = ['label' => 'Archiv', 'vorgabe' => 'aktiv', 'alle' => null, 'optionen' => ['aktiv' => 'Aktive Medien', 'archiviert' => 'Archivierte Medien', 'alle' => 'Auch archivierte']];
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function appliedList(string $field): array
|
||||||
|
{
|
||||||
|
$value = trim((string) $this->{$field});
|
||||||
|
|
||||||
|
return $value === '' ? [] : array_values(array_filter(array_map('trim', explode(',', $value)), fn (string $part): bool => $part !== ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Auswahl der Liste als Arbeitsstand des Dialogs.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
private function draftFromApplied(): array
|
||||||
|
{
|
||||||
|
$draft = ['arten' => $this->selectedArten()];
|
||||||
|
|
||||||
|
foreach (self::MULTI_FIELDS as $field) {
|
||||||
|
$draft[$field] = $this->appliedList($field);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (array_keys($this->singleFields()) as $field) {
|
||||||
|
$draft[$field] = (string) $this->{$field};
|
||||||
|
}
|
||||||
|
|
||||||
|
return $draft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function openFilter(string $field = ''): void
|
||||||
|
{
|
||||||
|
$this->filterDraft = $this->draftFromApplied();
|
||||||
|
$this->filterFokus = $field;
|
||||||
|
$this->filterOffen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Verwirft die Auswahl seit dem Öffnen. */
|
||||||
|
public function cancelFilter(): void
|
||||||
|
{
|
||||||
|
$this->filterOffen = false;
|
||||||
|
$this->filterDraft = [];
|
||||||
|
$this->filterFokus = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Alle Materialarten im Dialog ankreuzen, auch Übungsabschnitte und „Ohne Materialart“. */
|
||||||
|
public function draftAlleArten(): void
|
||||||
|
{
|
||||||
|
$this->filterDraft['arten'] = array_keys($this->artChoices());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Übernimmt die Auswahl des Dialogs in die Liste. */
|
||||||
|
public function applyFilter(): void
|
||||||
|
{
|
||||||
|
$this->applyDraft();
|
||||||
|
$this->filterOffen = false;
|
||||||
|
$this->filterDraft = [];
|
||||||
|
$this->filterFokus = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Übernimmt die Auswahl des Dialogs und merkt sie als persönlichen Standard. */
|
||||||
|
public function saveDefaultFromDialog(): void
|
||||||
|
{
|
||||||
|
$this->applyDraft();
|
||||||
|
$this->filterDraft = [];
|
||||||
|
$this->filterFokus = '';
|
||||||
|
$this->saveDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function applyDraft(): void
|
||||||
|
{
|
||||||
|
$draft = $this->filterDraft;
|
||||||
|
$known = array_keys($this->artChoices());
|
||||||
|
$this->storeArten(array_values(array_intersect($known, array_map('strval', (array) ($draft['arten'] ?? [])))));
|
||||||
|
$options = $this->multiFields();
|
||||||
|
|
||||||
|
foreach (self::MULTI_FIELDS as $field) {
|
||||||
|
$allowed = array_keys($options[$field]['optionen']);
|
||||||
|
$chosen = array_values(array_intersect($allowed, array_map('strval', (array) ($draft[$field] ?? []))));
|
||||||
|
// Alle Werte angekreuzt heißt: keine Einschränkung.
|
||||||
|
$this->{$field} = count($chosen) === count($allowed) ? '' : implode(',', $chosen);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->singleFields() as $field => $definition) {
|
||||||
|
$value = (string) ($draft[$field] ?? $definition['vorgabe']);
|
||||||
|
$this->{$field} = array_key_exists($value, $definition['optionen']) ? $value : $definition['vorgabe'];
|
||||||
|
}
|
||||||
|
|
||||||
$this->bestandGrenze = Bestand::SCHRITT;
|
$this->bestandGrenze = Bestand::SCHRITT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gemeinsame Bestandsliste: Suche und häufige Filter sichtbar, die übrigen unter „Weitere Filter“.
|
* Die wirksamen Filter als Pillen unter der Suche. Ein Klick öffnet den Dialog beim Filterfeld. In der allgemeinen
|
||||||
|
* Startansicht erklärt eine Pille, warum Übungsabschnitte fehlen.
|
||||||
|
*
|
||||||
|
* @return list<array{feld: string, label: string, info: bool}>
|
||||||
|
*/
|
||||||
|
private function filterPills(): array
|
||||||
|
{
|
||||||
|
$pills = [];
|
||||||
|
$short = function (array $labels): string {
|
||||||
|
$joined = implode(', ', $labels);
|
||||||
|
|
||||||
|
return count($labels) <= 3 && mb_strlen($joined) <= 40 ? $joined : count($labels).' gewählt';
|
||||||
|
};
|
||||||
|
$multi = $this->multiFields();
|
||||||
|
|
||||||
|
if ($this->arten === '') {
|
||||||
|
$pills[] = ['feld' => 'arten', 'label' => 'Übungsabschnitte und Dokumentkapitel ausgeblendet', 'info' => true];
|
||||||
|
} else {
|
||||||
|
$selected = $this->selectedArten();
|
||||||
|
|
||||||
|
if ($selected === []) {
|
||||||
|
$pills[] = ['feld' => 'arten', 'label' => 'Materialart · keine gewählt', 'info' => false];
|
||||||
|
} elseif (count($selected) < count($multi['arten']['optionen'])) {
|
||||||
|
$pills[] = ['feld' => 'arten', 'label' => 'Materialart · '.$short(array_map(fn (string $key): string => $multi['arten']['optionen'][$key] ?? $key, $selected)), 'info' => false];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (self::MULTI_FIELDS as $field) {
|
||||||
|
$values = $this->appliedList($field);
|
||||||
|
|
||||||
|
if ($values !== []) {
|
||||||
|
$pills[] = ['feld' => $field, 'label' => $multi[$field]['kurz'].' · '.$short(array_map(fn (string $value): string => $multi[$field]['optionen'][$value] ?? $value, $values)), 'info' => false];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->singleFields() as $field => $definition) {
|
||||||
|
$value = (string) $this->{$field};
|
||||||
|
|
||||||
|
if ($value !== $definition['vorgabe']) {
|
||||||
|
$pills[] = ['feld' => $field, 'label' => $definition['label'].' · '.($definition['optionen'][$value] ?? $value), 'info' => false];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $pills;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gemeinsame Bestandsliste: Suche mit Filterknopf, wirksame Filter als Pillen, alle Kriterien im Filterdialog.
|
||||||
*
|
*
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
@@ -384,65 +556,27 @@ public function bestand(): array
|
|||||||
[$this->saeule, $this->einordnung] = [(string) $pillar, ''];
|
[$this->saeule, $this->einordnung] = [(string) $pillar, ''];
|
||||||
}
|
}
|
||||||
|
|
||||||
$optionen = fn (array $liste, string $wert, string $label): array => collect($liste)
|
$pills = $this->filterPills();
|
||||||
->mapWithKeys(fn (array $eintrag): array => [(string) $eintrag[$wert] => $eintrag[$label]])
|
$keine = $this->selectedArten() === [];
|
||||||
->all();
|
|
||||||
$weitere = [
|
|
||||||
['eigenschaft' => 'entwurf', 'label' => 'Entwurf', 'vorgabe' => '', 'alle' => 'Entwurf egal', 'optionen' => ['offen' => 'Offener Entwurf', 'keiner' => 'Kein offener Entwurf']],
|
|
||||||
['eigenschaft' => 'fassung', 'label' => 'Deaktivierte Fassungen', 'vorgabe' => '', 'alle' => 'Regulärer Bestand', 'optionen' => ['mit' => 'Mit deaktivierter Fassung', 'nur' => 'Nur deaktivierte Fassungen']],
|
|
||||||
];
|
|
||||||
|
|
||||||
if (($pillars = $this->pillarOptions()) !== []) {
|
|
||||||
$weitere[] = ['eigenschaft' => 'saeule', 'label' => 'Fachliche Säule', 'vorgabe' => '', 'alle' => 'Alle Säulen', 'optionen' => $optionen($pillars, 'id', 'name')];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (($classes = $this->classificationOptions()) !== []) {
|
|
||||||
$weitere[] = ['eigenschaft' => 'einordnung', 'label' => 'Einordnung', 'vorgabe' => '', 'alle' => 'Alle Einordnungen', 'optionen' => $optionen($classes, 'id', 'label')];
|
|
||||||
}
|
|
||||||
|
|
||||||
$weitere[] = ['eigenschaft' => 'verarbeitung', 'label' => 'Verarbeitung', 'vorgabe' => '', 'alle' => 'Verarbeitung egal', 'optionen' => ['fehler' => 'Verarbeitungsfehler', 'uebernahme' => 'Datei wird übernommen']];
|
|
||||||
$weitere[] = ['eigenschaft' => 'archiv', 'label' => 'Archiv', 'vorgabe' => 'aktiv', 'optionen' => ['aktiv' => 'Aktive Medien', 'archiviert' => 'Archivierte Medien', 'alle' => 'Auch archivierte']];
|
|
||||||
|
|
||||||
$arten = $this->artChoices();
|
|
||||||
$gewaehlt = $this->selectedArten();
|
|
||||||
$keine = $gewaehlt === [];
|
|
||||||
$gespeichert = $this->hasSavedDefault();
|
$gespeichert = $this->hasSavedDefault();
|
||||||
$materialart = [
|
$dialog = [
|
||||||
'typ' => 'mehrfach',
|
'offen' => $this->filterOffen,
|
||||||
'eigenschaft' => 'arten',
|
'fokus' => $this->filterFokus,
|
||||||
'label' => 'Fachliche Materialart',
|
'pillen' => $pills,
|
||||||
'vorgabe' => '',
|
'anzahl' => count(array_filter($pills, fn (array $pill): bool => ! $pill['info'])),
|
||||||
'optionen' => array_map(fn (array $choice): string => $choice['label'], $arten),
|
'felder' => $this->multiFields(),
|
||||||
'gewaehlt' => $gewaehlt,
|
'weitere' => $this->singleFields(),
|
||||||
'modell' => 'artenAuswahl',
|
'entwurf' => 'filterDraft',
|
||||||
'chip' => 'Materialarten: '.match (true) {
|
'gespeichert' => $gespeichert,
|
||||||
$keine => 'keine',
|
'hinweis' => 'Mehrere Werte eines Felds zeigen Medien, auf die einer davon zutrifft. Verschiedene Felder gelten zusammen. Freigabe meint die Fassung des Mediums, nicht die Website und keinen Zugriff. Geschützte Medien haben eine Inhaltsfassung und laufen über Lizenzen. Öffentliche Medien sind eigenständige Präsentationsmedien ohne Fassung für die Website. Materialart und Einordnung sind die redaktionelle Klassifikation; Verwendung zeigt, wo das Medium tatsächlich eingebunden ist. Übungsabschnitte und Dokumentkapitel, die Texte der Übungen und Dokumente, erscheinen erst, wenn du sie unter Materialart ankreuzt. „Als Standard speichern“ merkt die Filter für dein Konto, ohne die Suche.',
|
||||||
count($gewaehlt) <= 4 => implode(', ', array_map(fn (string $key): string => $arten[$key]['label'] ?? $key, $gewaehlt)),
|
|
||||||
default => count($gewaehlt).' von '.count($arten).' ausgewählt',
|
|
||||||
},
|
|
||||||
'aktionen' => [
|
|
||||||
['label' => 'Alle auswählen', 'wire' => 'selectAllArten', 'aktiv' => true],
|
|
||||||
['label' => 'Als Standard speichern', 'wire' => 'saveDefault', 'aktiv' => true],
|
|
||||||
['label' => 'Standard wiederherstellen', 'wire' => 'restoreDefault', 'aktiv' => $gespeichert],
|
|
||||||
['label' => 'Persönlichen Standard löschen', 'wire' => 'deleteDefault', 'aktiv' => $gespeichert],
|
|
||||||
],
|
|
||||||
'hilfe' => 'Zu Beginn sind alle Materialarten und Medien ohne Materialart gewählt. Übungsabschnitte, die Texte der Übungen, erscheinen erst, wenn du sie ankreuzt. „Als Standard speichern“ merkt die gesetzten Filter für dein Konto, ohne die Suche.',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'suche' => ['eigenschaft' => 'suche', 'label' => 'Suche', 'platzhalter' => 'Titel, Beschreibung oder Suchbegriff'],
|
'suche' => ['eigenschaft' => 'suche', 'label' => 'Suche', 'platzhalter' => 'Titel, Beschreibung oder Suchbegriff'],
|
||||||
'filter' => [
|
'filterdialog' => $dialog,
|
||||||
$materialart,
|
|
||||||
['eigenschaft' => 'art', 'label' => 'Technische Art', 'vorgabe' => '', 'alle' => 'Alle Arten', 'optionen' => $optionen($this->typeOptions(), 'value', 'label')],
|
|
||||||
['eigenschaft' => 'schutz', 'label' => 'Schutz', 'vorgabe' => '', 'alle' => 'Alle Medien', 'optionen' => ['geschuetzt' => 'Geschützte Medien', 'oeffentlich' => 'Öffentliche Medien', 'website' => 'Auf der Website frei']],
|
|
||||||
['eigenschaft' => 'freigabe', 'label' => 'Freigabe', 'vorgabe' => '', 'alle' => 'Alle Freigaben', 'optionen' => ['freigegeben' => 'Freigegebene Fassung', 'entwurf' => 'Nur offener Entwurf', 'ohne' => 'Keine freigegebene Fassung']],
|
|
||||||
['eigenschaft' => 'nutzung', 'label' => 'Verwendung', 'vorgabe' => '', 'alle' => 'Verwendung egal', 'optionen' => ['verwendet' => 'Verwendet', 'unbenutzt' => 'Nicht verwendet']],
|
|
||||||
],
|
|
||||||
'weitere' => $weitere,
|
|
||||||
'hinweis' => 'Freigabe meint die Fassung des Mediums, nicht die Website und keinen Zugriff. Geschützte Medien haben eine Inhaltsfassung und laufen über Lizenzen. Öffentliche Medien sind eigenständige Präsentationsmedien ohne Fassung für die Website; ob sie freigegeben sind, zeigt die Kennzeichnung an der Zeile. Materialart und Einordnung sind die redaktionelle Klassifikation; Verwendung zeigt, wo das Medium tatsächlich eingebunden ist. Deaktivierte und archivierte Medien bleiben über „Weitere Filter“ auffindbar.',
|
|
||||||
'zeilen' => array_map($this->zeile(...), $this->cards()),
|
'zeilen' => array_map($this->zeile(...), $this->cards()),
|
||||||
'einheit' => ['Medium', 'Medien'],
|
'einheit' => ['Medium', 'Medien'],
|
||||||
'leerHinweis' => $keine ? 'Wähle oben mindestens eine Materialart aus, um Medien zu sehen. „Alle auswählen“ zeigt alles, auch die Übungsabschnitte.' : null,
|
'leerHinweis' => $keine ? 'Öffne den Filter und wähle mindestens eine Materialart aus, um Medien zu sehen. „Alle auswählen“ zeigt alles, auch Übungsabschnitte und Dokumentkapitel.' : null,
|
||||||
'leer' => ['titel' => 'Noch keine Medien', 'text' => 'Mit „Medium anlegen“ oben lädst du eine Datei hoch oder schreibst einen Text.'],
|
'leer' => ['titel' => 'Noch keine Medien', 'text' => 'Mit „Medium anlegen“ oben lädst du eine Datei hoch oder schreibst einen Text.'],
|
||||||
'ansicht' => 'ansicht',
|
'ansicht' => 'ansicht',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -791,6 +791,14 @@ protected function richFelder(): array
|
|||||||
return ['summary' => 'Kurzbeschreibung', 'descriptionText' => 'Ausführliche Beschreibung', 'bodyDraft' => 'Text der Fassung'];
|
return ['summary' => 'Kurzbeschreibung', 'descriptionText' => 'Ausführliche Beschreibung', 'bodyDraft' => 'Text der Fassung'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
protected function richBilder(): array
|
||||||
|
{
|
||||||
|
return ['bodyDraft'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return list<array<string, mixed>>
|
* @return list<array<string, mixed>>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
class CourseResource extends CompositionKindResource
|
class CourseResource extends CompositionKindResource
|
||||||
{
|
{
|
||||||
protected static ?string $slug = 'kurse';
|
protected static ?string $slug = 'programme';
|
||||||
|
|
||||||
protected static ?string $navigationLabel = 'Programme';
|
protected static ?string $navigationLabel = 'Programme';
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ class CourseResource extends CompositionKindResource
|
|||||||
|
|
||||||
protected static ?string $pluralModelLabel = 'Programme';
|
protected static ?string $pluralModelLabel = 'Programme';
|
||||||
|
|
||||||
protected static ?int $navigationSort = 4;
|
protected static ?int $navigationSort = 1;
|
||||||
|
|
||||||
public static function kind(): CompositionKind
|
public static function kind(): CompositionKind
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Documents;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\CompositionKind;
|
||||||
|
use App\Filament\Resources\Compositions\CompositionKindResource;
|
||||||
|
use App\Filament\Resources\Documents\Pages\EditDocument;
|
||||||
|
use App\Filament\Resources\Documents\Pages\ListDocuments;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dokumente unter „Inhalte“: zusammenhängende Texte aus Kapiteln, der erste Fall ist das Trainerhandbuch (ADR-51).
|
||||||
|
* Wie Übungen sind es Kompositionen mit eigener Art; Fassung, Einbindung und Stand arbeiten mit denselben Bausteinen.
|
||||||
|
*/
|
||||||
|
class DocumentResource extends CompositionKindResource
|
||||||
|
{
|
||||||
|
protected static ?string $slug = 'dokumente';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'Dokumente';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'Dokument';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'Dokumente';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 5;
|
||||||
|
|
||||||
|
public static function kind(): CompositionKind
|
||||||
|
{
|
||||||
|
return CompositionKind::Document;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ListDocuments::route('/'),
|
||||||
|
'edit' => EditDocument::route('/{record}'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Documents\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Compositions\Pages\EditComposition;
|
||||||
|
use App\Filament\Resources\Documents\DocumentResource;
|
||||||
|
|
||||||
|
class EditDocument extends EditComposition
|
||||||
|
{
|
||||||
|
protected static string $resource = DocumentResource::class;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Documents\Pages;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\CompositionKind;
|
||||||
|
use App\Filament\Resources\Compositions\Pages\ListCompositionKind;
|
||||||
|
use App\Filament\Resources\Documents\DocumentResource;
|
||||||
|
|
||||||
|
class ListDocuments extends ListCompositionKind
|
||||||
|
{
|
||||||
|
protected static string $resource = DocumentResource::class;
|
||||||
|
|
||||||
|
protected function kind(): CompositionKind
|
||||||
|
{
|
||||||
|
return CompositionKind::Document;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
class ExerciseResource extends CompositionKindResource
|
class ExerciseResource extends CompositionKindResource
|
||||||
{
|
{
|
||||||
protected static ?string $slug = 'uebungen';
|
protected static ?string $slug = 'module';
|
||||||
|
|
||||||
protected static ?string $navigationLabel = 'Module';
|
protected static ?string $navigationLabel = 'Module';
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ class ExerciseResource extends CompositionKindResource
|
|||||||
|
|
||||||
protected static ?string $pluralModelLabel = 'Module';
|
protected static ?string $pluralModelLabel = 'Module';
|
||||||
|
|
||||||
protected static ?int $navigationSort = 3;
|
protected static ?int $navigationSort = 2;
|
||||||
|
|
||||||
public static function kind(): CompositionKind
|
public static function kind(): CompositionKind
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
use App\Filament\Resources\Practices\Pages\ListPractices;
|
use App\Filament\Resources\Practices\Pages\ListPractices;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Die fachliche Übung. Der ältere Eintrag „Module“ (`ExerciseResource`, Adresse `uebungen`) bleibt unverändert und
|
* Die fachliche Übung. Der Eintrag „Module“ (`ExerciseResource`, Adresse `module`) zeigt die Zusammenstellungen der Art `uebung`;
|
||||||
* zeigt die Zusammenstellungen der Art `uebung`; hier stehen die Übungen mit Varianten.
|
* hier stehen die Übungen mit Varianten.
|
||||||
*/
|
*/
|
||||||
class PracticeResource extends CompositionKindResource
|
class PracticeResource extends CompositionKindResource
|
||||||
{
|
{
|
||||||
@@ -21,7 +21,7 @@ class PracticeResource extends CompositionKindResource
|
|||||||
|
|
||||||
protected static ?string $pluralModelLabel = 'Übungen';
|
protected static ?string $pluralModelLabel = 'Übungen';
|
||||||
|
|
||||||
protected static ?int $navigationSort = 2;
|
protected static ?int $navigationSort = 3;
|
||||||
|
|
||||||
public static function kind(): CompositionKind
|
public static function kind(): CompositionKind
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ final class CatalogLabels
|
|||||||
'pdf:ansehen' => 'PDF ansehen',
|
'pdf:ansehen' => 'PDF ansehen',
|
||||||
'pdf:laden' => 'PDF herunterladen',
|
'pdf:laden' => 'PDF herunterladen',
|
||||||
'text:ansehen' => 'Text ansehen',
|
'text:ansehen' => 'Text ansehen',
|
||||||
|
'text:laden' => 'Text als PDF herunterladen (Übung, Dokument)',
|
||||||
'bild:ansehen' => 'Bild ansehen',
|
'bild:ansehen' => 'Bild ansehen',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -106,13 +106,20 @@ public function pickerResult(): array
|
|||||||
return ['items' => [], 'more' => false];
|
return ['items' => [], 'more' => false];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->pickerPurpose === 'aufbau') {
|
// Eine PDF-Vorlage nimmt auch Bilder ohne Inhaltsfassung (Präsentationsmedien, Website-Bilder) auf.
|
||||||
|
if ($this->pickerPurpose === 'vorlagenbild') {
|
||||||
|
return $this->filterByMaterialart(app(EditorialCatalog::class)->presentationBrowse($this->pickerQuery, 'bild'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($this->pickerPurpose, ['aufbau', 'textbild'], true)) {
|
||||||
|
$image = $this->pickerPurpose === 'textbild';
|
||||||
|
|
||||||
return $this->filterByMaterialart(app(EditorialCatalog::class)->browse(
|
return $this->filterByMaterialart(app(EditorialCatalog::class)->browse(
|
||||||
$this->pickerQuery,
|
$this->pickerQuery,
|
||||||
$this->pickerKind,
|
$image ? 'bild' : $this->pickerKind,
|
||||||
$this->pickerDimension,
|
$this->pickerDimension,
|
||||||
$this->pickerExceptId(),
|
$this->pickerExceptId(),
|
||||||
false,
|
$image,
|
||||||
ctype_digit($this->pickerSaeule) ? (int) $this->pickerSaeule : 0,
|
ctype_digit($this->pickerSaeule) ? (int) $this->pickerSaeule : 0,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
use App\Filament\Resources\Combinations\CombinationResource;
|
use App\Filament\Resources\Combinations\CombinationResource;
|
||||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
use App\Filament\Resources\Courses\CourseResource;
|
use App\Filament\Resources\Courses\CourseResource;
|
||||||
|
use App\Filament\Resources\Documents\DocumentResource;
|
||||||
use App\Filament\Resources\Exercises\ExerciseResource;
|
use App\Filament\Resources\Exercises\ExerciseResource;
|
||||||
use App\Filament\Resources\Practices\PracticeResource;
|
use App\Filament\Resources\Practices\PracticeResource;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
@@ -297,7 +298,7 @@ public function browse(string $query, string $kind, string $dimension, int $exce
|
|||||||
$rows = [];
|
$rows = [];
|
||||||
$dimensionId = ctype_digit($dimension) ? (int) $dimension : 0;
|
$dimensionId = ctype_digit($dimension) ? (int) $dimension : 0;
|
||||||
|
|
||||||
if ($kind !== 'modul') {
|
if (! in_array($kind, ['modul', 'dokumentfassung'], true)) {
|
||||||
$latestElements = ContentElementVersion::query()
|
$latestElements = ContentElementVersion::query()
|
||||||
->selectRaw('MAX(id)')
|
->selectRaw('MAX(id)')
|
||||||
->whereIn('status', [ContentVersionStatus::Bereit, ContentVersionStatus::Entwurf])
|
->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()
|
$latestCompositions = CompositionVersion::query()
|
||||||
->selectRaw('MAX(id)')
|
->selectRaw('MAX(id)')
|
||||||
->where('status', ContentVersionStatus::Bereit)
|
->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]);
|
$builder->whereIn('kind', [CompositionKind::Uebung, CompositionKind::Exercise]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($kind === 'dokumentfassung') {
|
||||||
|
$builder->where('kind', CompositionKind::Document);
|
||||||
|
}
|
||||||
|
|
||||||
if ($dimensionId > 0) {
|
if ($dimensionId > 0) {
|
||||||
$builder->whereIn('id', $this->dimensionSubjectIds(Composition::class, $dimensionId));
|
$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()
|
$unreleased = Composition::query()
|
||||||
->where('id', '!=', $exceptCompositionId)
|
->where('id', '!=', $exceptCompositionId)
|
||||||
->whereNotNull('working_draft')
|
->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 {
|
->whereDoesntHave('versions', function ($builder): void {
|
||||||
$builder->where('status', ContentVersionStatus::Bereit);
|
$builder->where('status', ContentVersionStatus::Bereit);
|
||||||
})
|
})
|
||||||
@@ -1085,6 +1092,7 @@ public function create(string $designation, CompositionKind $kind): Composition
|
|||||||
CompositionKind::Kurs => 'programm',
|
CompositionKind::Kurs => 'programm',
|
||||||
CompositionKind::Uebung => 'modul',
|
CompositionKind::Uebung => 'modul',
|
||||||
CompositionKind::Exercise => 'uebung',
|
CompositionKind::Exercise => 'uebung',
|
||||||
|
CompositionKind::Document => 'dokument',
|
||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
$editorial = $slug === null ? null : EditorialContentKind::query()->where('slug', $slug)->first();
|
$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::Kombination => CombinationResource::class,
|
||||||
CompositionKind::Uebung => ExerciseResource::class,
|
CompositionKind::Uebung => ExerciseResource::class,
|
||||||
CompositionKind::Exercise => PracticeResource::class,
|
CompositionKind::Exercise => PracticeResource::class,
|
||||||
|
CompositionKind::Document => DocumentResource::class,
|
||||||
};
|
};
|
||||||
|
|
||||||
return $resource::getUrl('edit', ['record' => $composition]);
|
return $resource::getUrl('edit', ['record' => $composition]);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
use App\Domain\Catalog\ContentElementVersion;
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
use App\Domain\Catalog\ContentService;
|
use App\Domain\Catalog\ContentService;
|
||||||
use App\Domain\Catalog\DomainRuleException;
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
use App\Domain\Catalog\EmbeddedImages;
|
||||||
use App\Domain\Catalog\FormattedText;
|
use App\Domain\Catalog\FormattedText;
|
||||||
use App\Filament\Resources\ContentElements\Pages\EditContentElement;
|
use App\Filament\Resources\ContentElements\Pages\EditContentElement;
|
||||||
use Filament\Forms\Components\Component;
|
use Filament\Forms\Components\Component;
|
||||||
@@ -71,7 +72,7 @@ public static function fields(ContentElement $element): array
|
|||||||
$latest = $element->versions()->orderByDesc('number')->first();
|
$latest = $element->versions()->orderByDesc('number')->first();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
RichField::make('body', 'Text', live: false)->default(FormattedText::html($latest?->body)),
|
RichField::make('body', 'Text', live: false)->default(EmbeddedImages::forEditor($latest?->body)),
|
||||||
EditContentElement::uploadField(),
|
EditContentElement::uploadField(),
|
||||||
Toggle::make('drop_file')
|
Toggle::make('drop_file')
|
||||||
->label('Datei in der neuen Fassung nicht mehr verwenden')
|
->label('Datei in der neuen Fassung nicht mehr verwenden')
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Support;
|
||||||
|
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frühere Adressen der Verwaltung. Die Bestände heißen seit der Neuordnung „Inhalte“ anders: Programme
|
||||||
|
* (früher `kurse`), Module (früher `uebungen`) und Contentmanager (früher `content-elements`). Gespeicherte Links
|
||||||
|
* führen mit Objektnummer, Unterseite und Filtern zum neuen Ziel.
|
||||||
|
*
|
||||||
|
* Die Weiterleitung steht hinter der Anmeldung des Panels und trägt selbst keine Daten. Die Rechte prüft erst das
|
||||||
|
* Ziel; wer die Seite nicht sehen darf, bekommt über eine alte Adresse dieselbe Absage wie über die neue. Die
|
||||||
|
* Antwort ist bewusst keine dauerhafte (302): Ein Rückfall des Codes setzt die neuen Adressen zurück, ein im Browser
|
||||||
|
* gemerktes 301 würde dann ins Leere führen.
|
||||||
|
*/
|
||||||
|
final class LegacyAddresses
|
||||||
|
{
|
||||||
|
/** @var array<string, string> alte Adresse => neue Adresse (jeweils unter dem Panelpfad) */
|
||||||
|
public const MOVED = [
|
||||||
|
'kurse' => 'programme',
|
||||||
|
'uebungen' => 'module',
|
||||||
|
'content-elements' => 'contentmanager',
|
||||||
|
];
|
||||||
|
|
||||||
|
public static function routes(): void
|
||||||
|
{
|
||||||
|
foreach (self::MOVED as $old => $new) {
|
||||||
|
Route::get($old.'/{rest?}', fn (Request $request, ?string $rest = null): RedirectResponse => self::redirect($request, $new, $rest))
|
||||||
|
->where('rest', '.*')
|
||||||
|
->name('legacy.'.$old);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function redirect(Request $request, string $new, ?string $rest): RedirectResponse
|
||||||
|
{
|
||||||
|
$path = '/'.trim(Filament::getPanel('verwaltung')->getPath(), '/').'/'.$new;
|
||||||
|
$rest = trim((string) $rest, '/');
|
||||||
|
|
||||||
|
if ($rest !== '') {
|
||||||
|
$path .= '/'.$rest;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = (string) $request->server->get('QUERY_STRING', '');
|
||||||
|
|
||||||
|
return redirect()->to(url($path).($query !== '' ? '?'.$query : ''));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -78,6 +78,7 @@ public function bestand(): array
|
|||||||
CompositionKind::Kurs => ['Programm', 'Programme'],
|
CompositionKind::Kurs => ['Programm', 'Programme'],
|
||||||
CompositionKind::Uebung => ['Modul', 'Module'],
|
CompositionKind::Uebung => ['Modul', 'Module'],
|
||||||
CompositionKind::Exercise => ['Übung', 'Übungen'],
|
CompositionKind::Exercise => ['Übung', 'Übungen'],
|
||||||
|
CompositionKind::Document => ['Dokument', 'Dokumente'],
|
||||||
CompositionKind::Kombination => ['Fachliche Kombination', 'Fachliche Kombinationen'],
|
CompositionKind::Kombination => ['Fachliche Kombination', 'Fachliche Kombinationen'],
|
||||||
default => ['Programm oder Modul', 'Programme und Module'],
|
default => ['Programm oder Modul', 'Programme und Module'],
|
||||||
};
|
};
|
||||||
@@ -118,6 +119,8 @@ public function bestand(): array
|
|||||||
'text' => 'Mit „'.match ($fixed) {
|
'text' => 'Mit „'.match ($fixed) {
|
||||||
CompositionKind::Kurs => 'Programm anlegen',
|
CompositionKind::Kurs => 'Programm anlegen',
|
||||||
CompositionKind::Kombination => CompositionKind::Kombination->createLabel(),
|
CompositionKind::Kombination => CompositionKind::Kombination->createLabel(),
|
||||||
|
CompositionKind::Exercise => 'Übung anlegen',
|
||||||
|
CompositionKind::Document => 'Dokument anlegen',
|
||||||
default => 'Modul anlegen',
|
default => 'Modul anlegen',
|
||||||
}.'“ oben entsteht der erste Eintrag. Der Name genügt.',
|
}.'“ oben entsteht der erste Eintrag. Der Name genügt.',
|
||||||
],
|
],
|
||||||
@@ -247,12 +250,14 @@ protected function createCompositionAction(CompositionKind $kind): Action
|
|||||||
$label = match ($kind) {
|
$label = match ($kind) {
|
||||||
CompositionKind::Kurs => 'Programm',
|
CompositionKind::Kurs => 'Programm',
|
||||||
CompositionKind::Exercise => 'Übung',
|
CompositionKind::Exercise => 'Übung',
|
||||||
|
CompositionKind::Document => 'Dokument',
|
||||||
default => 'Modul',
|
default => 'Modul',
|
||||||
};
|
};
|
||||||
|
|
||||||
return Action::make(match ($kind) {
|
return Action::make(match ($kind) {
|
||||||
CompositionKind::Kurs => 'createProgram',
|
CompositionKind::Kurs => 'createProgram',
|
||||||
CompositionKind::Exercise => 'createExercise',
|
CompositionKind::Exercise => 'createExercise',
|
||||||
|
CompositionKind::Document => 'createDocument',
|
||||||
default => 'createModule',
|
default => 'createModule',
|
||||||
})
|
})
|
||||||
->label($label.' anlegen')
|
->label($label.' anlegen')
|
||||||
|
|||||||
@@ -0,0 +1,506 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Support;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\Composition;
|
||||||
|
use App\Domain\Catalog\CompositionKind;
|
||||||
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
|
use App\Domain\Catalog\ContentService;
|
||||||
|
use App\Domain\Catalog\DocumentChapters;
|
||||||
|
use App\Domain\Catalog\DocumentOutline;
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
use App\Domain\Catalog\FormattedText;
|
||||||
|
use App\Filament\Resources\Compositions\Pages\EditComposition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kapitelarbeitsplatz eines Dokuments im Aufbaueditor (ADR-51). Der Arbeitsplatz hält die Kapitel wie jeden Aufbau als
|
||||||
|
* Mitglieder in `$members`; die Ebene steht in der Rolle („Kapitel“, „Unterkapitel“). Das Kapitel, das gerade offen ist,
|
||||||
|
* liegt in `$partTitle` und `$partBody` (derselbe Editor wie bei jedem Text).
|
||||||
|
*
|
||||||
|
* Offene Eingaben bleiben beim Wechsel des Kapitels erhalten: Der Wechsel legt Titel und Text des verlassenen Kapitels in
|
||||||
|
* `$chapterEdits` ab, und das Öffnen eines Kapitels liest zuerst dort. Geschrieben wird erst mit „Entwurf speichern“
|
||||||
|
* ({@see self::persistChapterEdits()}), und zwar als Entwurfsfassung des Kapitels; bereitgestellt wird erst mit der
|
||||||
|
* Dokumentfassung. Die Reihenfolge ändert immer den ganzen Block aus Kapitel und seinen Unterkapiteln.
|
||||||
|
*
|
||||||
|
* Die Seite stellt `members`, `selected`, `partTitle`, `partBody`, `feedback` und `memberExtras()` bereit
|
||||||
|
* ({@see EditComposition}).
|
||||||
|
*/
|
||||||
|
trait ManagesDocumentChapters
|
||||||
|
{
|
||||||
|
/** @var array<string, array{title: string, body: string}> Ungespeicherte Änderungen je Kapitel (Ziel => Titel und Text) */
|
||||||
|
public array $chapterEdits = [];
|
||||||
|
|
||||||
|
/** @var array<string, string> 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<array{index: int, number: string, level: int, anchor: string, title: string, changed: bool, draft: bool, selected: bool, first: bool, last: bool}>
|
||||||
|
*/
|
||||||
|
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<string, array{title: string, body: string}>
|
||||||
|
*/
|
||||||
|
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'] === '' ? '<p></p>' : $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, '<p></p>');
|
||||||
|
/** @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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
use App\Domain\Media\WebsiteRelease;
|
use App\Domain\Media\WebsiteRelease;
|
||||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Filament\Forms\Components\RichEditor\EditorCommand;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Livewire\Attributes\Url;
|
use Livewire\Attributes\Url;
|
||||||
|
|
||||||
@@ -66,6 +67,12 @@ trait ManagesEditorialSurface
|
|||||||
|
|
||||||
public bool $ausgabeOpen = false;
|
public bool $ausgabeOpen = false;
|
||||||
|
|
||||||
|
/** Der Editor, in den das gewählte Bild eingefügt wird (Eigenschaft der Seite), und seine Cursorstelle. */
|
||||||
|
public string $textImageField = '';
|
||||||
|
|
||||||
|
/** @var array<string, mixed> */
|
||||||
|
public array $textImageSelection = [];
|
||||||
|
|
||||||
/** @var array{aktion: string, argument: int|string|null, titel: string, text: string, label: string, gefahr: bool}|null */
|
/** @var array{aktion: string, argument: int|string|null, titel: string, text: string, label: string, gefahr: bool}|null */
|
||||||
public ?array $bestaetigung = null;
|
public ?array $bestaetigung = null;
|
||||||
|
|
||||||
@@ -596,6 +603,57 @@ public function closePicker(): void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Öffnet den gemeinsamen Picker für ein Bild im Text. Der Editor ruft das mit seinem Namen und der Cursorstelle auf
|
||||||
|
* ({@see RichField}). Gewählt wird eine freigegebene Bildfassung des Medienbestands; eine Adresse speichert der Text nie.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $selection
|
||||||
|
*/
|
||||||
|
public function openTextImagePicker(string $field, array $selection = []): void
|
||||||
|
{
|
||||||
|
if (! method_exists($this, 'richKomponente') || $this->richKomponente($field) === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->textImageField = $field;
|
||||||
|
$this->textImageSelection = $selection;
|
||||||
|
$this->resetPicker('textbild');
|
||||||
|
$this->pickerKind = 'bild';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fügt die gewählte Bildfassung an der Cursorstelle ein. Nur freigegebene Fassungen: Der Text verweist auf genau
|
||||||
|
* diese Fassung, und eine Dokumentfassung kann später nur freigegebene Bilder festschreiben.
|
||||||
|
*/
|
||||||
|
protected function insertTextImage(string $target): void
|
||||||
|
{
|
||||||
|
$component = method_exists($this, 'richKomponente') ? $this->richKomponente($this->textImageField) : null;
|
||||||
|
$version = preg_match('/^element:(\d+)$/', $target, $match) === 1
|
||||||
|
? ContentElementVersion::query()->with('element')->find($match[1])
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if ($component === null || ! $version instanceof ContentElementVersion || $version->element === null || $version->element->output_class !== 'bild') {
|
||||||
|
$this->feedback('Dieses Bild lässt sich nicht einfügen.', true);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($version->status !== ContentVersionStatus::Bereit) {
|
||||||
|
$this->feedback('„'.($version->element->display_title ?: $version->element->working_title).'“ ist noch nicht freigegeben. Gib das Bild im Medienbestand frei, dann lässt es sich einfügen.', true);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$alt = trim((string) ($version->element->website_alt ?: $version->element->display_title ?: $version->element->working_title));
|
||||||
|
$component->runCommands([
|
||||||
|
EditorCommand::make('insertContent', arguments: [[
|
||||||
|
'type' => 'image',
|
||||||
|
'attrs' => ['alt' => $alt, 'id' => (string) $version->id, 'src' => route('content.file', ['version' => $version->id], false)],
|
||||||
|
]]),
|
||||||
|
], editorSelection: $this->textImageSelection === [] ? null : $this->textImageSelection);
|
||||||
|
$this->feedback('„'.($version->element->display_title ?: $version->element->working_title).'“ ist im Text eingefügt. Gespeichert wird mit dem Text.');
|
||||||
|
}
|
||||||
|
|
||||||
public function pickerAllowsMany(): bool
|
public function pickerAllowsMany(): bool
|
||||||
{
|
{
|
||||||
return $this->pickerPurpose === 'praesentation' && $this->roleAllowsMany($this->presentationRole);
|
return $this->pickerPurpose === 'praesentation' && $this->roleAllowsMany($this->presentationRole);
|
||||||
@@ -625,6 +683,14 @@ public function confirmPicker(): void
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->pickerPurpose === 'textbild') {
|
||||||
|
$target = $marked[0];
|
||||||
|
$this->closePicker();
|
||||||
|
$this->insertTextImage($target);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->guardEditorial();
|
$this->guardEditorial();
|
||||||
|
|
||||||
if ($this->pickerPurpose === 'austausch' || ($this->pickerPurpose === 'praesentation' && $this->replacingKey !== null)) {
|
if ($this->pickerPurpose === 'austausch' || ($this->pickerPurpose === 'praesentation' && $this->replacingKey !== null)) {
|
||||||
@@ -684,12 +750,12 @@ public function assignFromPicker(string $target): void
|
|||||||
*/
|
*/
|
||||||
public function pickerKinds(): array
|
public function pickerKinds(): array
|
||||||
{
|
{
|
||||||
if ($this->pickerPurpose === 'vorschaubild') {
|
if (in_array($this->pickerPurpose, ['vorschaubild', 'textbild'], true)) {
|
||||||
return ['bild' => 'Bilder'];
|
return ['bild' => 'Bilder'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->pickerPurpose === 'aufbau') {
|
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'];
|
return ['alle' => 'Alle Medien', 'bild' => 'Bilder', 'film' => 'Filme', 'audio' => 'Hörstücke', 'dokument' => 'Dokumente'];
|
||||||
@@ -709,6 +775,7 @@ public function pickerTitle(): string
|
|||||||
'aufbau' => 'Bestandteil auswählen',
|
'aufbau' => 'Bestandteil auswählen',
|
||||||
'austausch' => 'Medium austauschen',
|
'austausch' => 'Medium austauschen',
|
||||||
'vorschaubild' => 'Vorschaubild aus dem Bestand',
|
'vorschaubild' => 'Vorschaubild aus dem Bestand',
|
||||||
|
'textbild' => 'Bild in den Text einfügen',
|
||||||
default => 'Medien auswählen',
|
default => 'Medien auswählen',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -725,6 +792,7 @@ public function pickerConfirmLabel(): string
|
|||||||
'aufbau' => 'In den Aufbau übernehmen',
|
'aufbau' => 'In den Aufbau übernehmen',
|
||||||
'austausch' => 'Austauschen',
|
'austausch' => 'Austauschen',
|
||||||
'vorschaubild' => 'Als Vorschaubild übernehmen',
|
'vorschaubild' => 'Als Vorschaubild übernehmen',
|
||||||
|
'textbild' => 'Bild einfügen',
|
||||||
default => $count === 1 ? '1 Medium übernehmen' : ($count === 0 ? 'Medien übernehmen' : $count.' Medien übernehmen'),
|
default => $count === 1 ? '1 Medium übernehmen' : ($count === 0 ? 'Medien übernehmen' : $count.' Medien übernehmen'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Filament\Support;
|
namespace App\Filament\Support;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\EmbeddedImages;
|
||||||
use App\Domain\Catalog\FormattedText;
|
use App\Domain\Catalog\FormattedText;
|
||||||
use Filament\Forms\Components\RichEditor;
|
use Filament\Forms\Components\RichEditor;
|
||||||
use Filament\Schemas\Components\Component;
|
use Filament\Schemas\Components\Component;
|
||||||
@@ -41,6 +42,16 @@ protected function richFelder(): array
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eigenschaften, deren Editor Bilder aus dem Medienbestand einfügen darf (Textinhalte, nicht Kurzangaben).
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
protected function richBilder(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
/** @return list<string> */
|
/** @return list<string> */
|
||||||
protected function richNamen(): array
|
protected function richNamen(): array
|
||||||
{
|
{
|
||||||
@@ -51,7 +62,7 @@ public function richTextSchema(Schema $schema): Schema
|
|||||||
{
|
{
|
||||||
return $schema
|
return $schema
|
||||||
->statePath('rich')
|
->statePath('rich')
|
||||||
->components(array_map(fn (string $name, string $label): RichEditor => RichField::make($name, $label, hideLabel: true), $this->richNamen(), $this->richFelder()));
|
->components(array_map(fn (string $name, string $label): RichEditor => RichField::make($name, $label, hideLabel: true, images: in_array($name, $this->richBilder(), true) && method_exists($this, 'openTextImagePicker')), $this->richNamen(), $this->richFelder()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function richKomponente(string $name): ?Component
|
public function richKomponente(string $name): ?Component
|
||||||
@@ -93,7 +104,7 @@ protected function richPush(string $name): void
|
|||||||
}
|
}
|
||||||
|
|
||||||
$canonical = FormattedText::canonical((string) $this->{$name});
|
$canonical = FormattedText::canonical((string) $this->{$name});
|
||||||
$component->state($canonical === '' ? null : $canonical);
|
$component->state($canonical === '' ? null : FormattedText::forEditor($canonical, fn (int $id): string => EmbeddedImages::staffSource($id)));
|
||||||
$this->richSeen[$name] = md5($canonical);
|
$this->richSeen[$name] = md5($canonical);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
use App\Domain\Catalog\ReleaseContent;
|
use App\Domain\Catalog\ReleaseContent;
|
||||||
use App\Domain\Media\ThumbnailRef;
|
use App\Domain\Media\ThumbnailRef;
|
||||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
use App\Filament\Resources\Practices\PracticeResource;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
@@ -144,12 +143,12 @@ private function normalize(array $filters): array
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'suche' => trim($filters['suche'] ?? ''),
|
'suche' => trim($filters['suche'] ?? ''),
|
||||||
'art' => $this->choice($filters['art'] ?? '', ['film', 'text', 'document', 'bild', 'audio']),
|
'art' => $this->choices($filters['art'] ?? '', ['film', 'text', 'document', 'bild', 'audio']),
|
||||||
'freigabe' => $this->choice($filters['freigabe'] ?? '', ['freigegeben', 'entwurf', 'ohne']),
|
'freigabe' => $this->choices($filters['freigabe'] ?? '', ['freigegeben', 'entwurf', 'ohne']),
|
||||||
'schutz' => $this->choice($filters['schutz'] ?? '', ['geschuetzt', 'oeffentlich', 'website']),
|
'schutz' => $this->choice($filters['schutz'] ?? '', ['geschuetzt', 'oeffentlich', 'website']),
|
||||||
'entwurf' => $this->choice($filters['entwurf'] ?? '', ['offen', 'keiner']),
|
'entwurf' => $this->choice($filters['entwurf'] ?? '', ['offen', 'keiner']),
|
||||||
'fassung' => $this->choice($filters['fassung'] ?? '', ['mit', 'nur']),
|
'fassung' => $this->choice($filters['fassung'] ?? '', ['mit', 'nur']),
|
||||||
'nutzung' => $this->choice($filters['nutzung'] ?? '', ['verwendet', 'unbenutzt']),
|
'nutzung' => $this->choices($filters['nutzung'] ?? '', ['verwendet', 'unbenutzt']),
|
||||||
'saeule' => $saeule,
|
'saeule' => $saeule,
|
||||||
'einordnung' => $einordnung,
|
'einordnung' => $einordnung,
|
||||||
'inhaltsart' => ctype_digit($filters['inhaltsart'] ?? '') ? $filters['inhaltsart'] : '',
|
'inhaltsart' => ctype_digit($filters['inhaltsart'] ?? '') ? $filters['inhaltsart'] : '',
|
||||||
@@ -160,6 +159,18 @@ private function normalize(array $filters): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mehrere Werte eines Filterfelds, durch Komma getrennt. Sie gelten als ODER; leer heißt keine Einschränkung.
|
||||||
|
* Ein einzelner Wert, wie ihn ältere Adressen und gespeicherte Standards enthalten, ist ein gültiger Sonderfall.
|
||||||
|
*
|
||||||
|
* @param list<string> $allowed
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function choices(string $value, array $allowed): array
|
||||||
|
{
|
||||||
|
return array_values(array_intersect($allowed, array_map('trim', explode(',', $value))));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param list<string> $allowed
|
* @param list<string> $allowed
|
||||||
*/
|
*/
|
||||||
@@ -361,7 +372,7 @@ private function processing(Collection $versions): ?string
|
|||||||
/**
|
/**
|
||||||
* @param array<string, mixed> $portrait
|
* @param array<string, mixed> $portrait
|
||||||
* @param list<array<string, mixed>> $uses
|
* @param list<array<string, mixed>> $uses
|
||||||
* @param array<string, string> $filters
|
* @param array<string, mixed> $filters
|
||||||
* @param array<int, list<int>> $classified
|
* @param array<int, list<int>> $classified
|
||||||
*/
|
*/
|
||||||
private function matches(ContentElement $element, array $portrait, array $uses, array $filters, string $needle, array $classified): bool
|
private function matches(ContentElement $element, array $portrait, array $uses, array $filters, string $needle, array $classified): bool
|
||||||
@@ -370,7 +381,7 @@ private function matches(ContentElement $element, array $portrait, array $uses,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->matchesArt($element, $filters['art'])) {
|
if ($filters['art'] !== [] && ! $this->matchesAnyArt($element, $filters['art'])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,16 +413,16 @@ private function matches(ContentElement $element, array $portrait, array $uses,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($filters['freigabe'] === 'freigegeben' && $portrait['ready'] === null) {
|
if ($filters['freigabe'] !== []) {
|
||||||
|
$passes = [
|
||||||
|
'freigegeben' => $portrait['ready'] !== null,
|
||||||
|
'entwurf' => $portrait['draft'] !== null && $portrait['ready'] === null,
|
||||||
|
'ohne' => $portrait['ready'] === null,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (! in_array(true, array_intersect_key($passes, array_flip($filters['freigabe'])), true)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($filters['freigabe'] === 'entwurf' && ($portrait['draft'] === null || $portrait['ready'] !== null)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($filters['freigabe'] === 'ohne' && $portrait['ready'] !== null) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($filters['entwurf'] === 'offen' && $portrait['draft'] === null) {
|
if ($filters['entwurf'] === 'offen' && $portrait['draft'] === null) {
|
||||||
@@ -432,11 +443,7 @@ private function matches(ContentElement $element, array $portrait, array $uses,
|
|||||||
|
|
||||||
$used = $this->usageCount($uses) > 0;
|
$used = $this->usageCount($uses) > 0;
|
||||||
|
|
||||||
if ($filters['nutzung'] === 'verwendet' && ! $used) {
|
if ($filters['nutzung'] !== [] && ! in_array($used ? 'verwendet' : 'unbenutzt', $filters['nutzung'], true)) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($filters['nutzung'] === 'unbenutzt' && $used) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,6 +487,20 @@ private function isPresentationMedium(ContentElement $element, int $versionCount
|
|||||||
return $versionCount === 0 && in_array($element->output_class, ['bild', 'film', 'audio'], true);
|
return $versionCount === 0 && in_array($element->output_class, ['bild', 'film', 'audio'], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<string> $arts
|
||||||
|
*/
|
||||||
|
private function matchesAnyArt(ContentElement $element, array $arts): bool
|
||||||
|
{
|
||||||
|
foreach ($arts as $art) {
|
||||||
|
if ($this->matchesArt($element, $art)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private function matchesArt(ContentElement $element, string $art): bool
|
private function matchesArt(ContentElement $element, string $art): bool
|
||||||
{
|
{
|
||||||
if ($art === '') {
|
if ($art === '') {
|
||||||
@@ -571,7 +592,8 @@ private function exerciseOf(ContentElement $element, bool $canEdit): ?array
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'title' => (string) ($exercise->display_title ?: $exercise->designation),
|
'title' => (string) ($exercise->display_title ?: $exercise->designation),
|
||||||
'url' => $canEdit ? PracticeResource::getUrl('edit', ['record' => $exercise]) : null,
|
'url' => $canEdit ? EditorialCatalog::editUrl($exercise) : null,
|
||||||
|
'kind' => $exercise->kind instanceof CompositionKind ? $exercise->kind->deskLabel() : 'Übung',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
use App\Domain\Catalog\ContentService;
|
use App\Domain\Catalog\ContentService;
|
||||||
use App\Domain\Catalog\DomainRuleException;
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
use App\Domain\Catalog\EditorialVocabulary;
|
use App\Domain\Catalog\EditorialVocabulary;
|
||||||
|
use App\Domain\Catalog\EmbeddedImages;
|
||||||
use App\Domain\Catalog\FormattedText;
|
use App\Domain\Catalog\FormattedText;
|
||||||
use App\Domain\Catalog\IdentityProfile;
|
use App\Domain\Catalog\IdentityProfile;
|
||||||
use App\Domain\Media\PresentationFile;
|
use App\Domain\Media\PresentationFile;
|
||||||
@@ -221,7 +222,7 @@ public static function fill(ContentElement $element): array
|
|||||||
'usage_note' => $element->usage_note,
|
'usage_note' => $element->usage_note,
|
||||||
'license_note' => $element->license_note,
|
'license_note' => $element->license_note,
|
||||||
'thumbnail_alt' => $element->thumbnail_alt,
|
'thumbnail_alt' => $element->thumbnail_alt,
|
||||||
'body' => FormattedText::html($latest?->body),
|
'body' => EmbeddedImages::forEditor($latest?->body),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
use App\Domain\Catalog\FormattedText;
|
use App\Domain\Catalog\FormattedText;
|
||||||
use Filament\Forms\Components\RichEditor;
|
use Filament\Forms\Components\RichEditor;
|
||||||
|
use Filament\Forms\Components\RichEditor\RichEditorTool;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Illuminate\Support\Js;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Der eine Editor für formatierte Texte (ADR-50): immer dieselbe Symbolleiste, dasselbe Ergebnis (bereinigtes HTML).
|
* Der eine Editor für formatierte Texte (ADR-50): immer dieselbe Symbolleiste, dasselbe Ergebnis (bereinigtes HTML).
|
||||||
@@ -15,10 +18,27 @@ final class RichField
|
|||||||
* @param ?string $label Bezeichnung des Felds; sie ist auch der Name für Hilfstechnik
|
* @param ?string $label Bezeichnung des Felds; sie ist auch der Name für Hilfstechnik
|
||||||
* @param bool $live Arbeitsplätze gleichen beim Verlassen des Felds ab ({@see ManagesRichFields}); Dialoge nicht
|
* @param bool $live Arbeitsplätze gleichen beim Verlassen des Felds ab ({@see ManagesRichFields}); Dialoge nicht
|
||||||
* @param bool $hideLabel Die Bezeichnung zeigt der Arbeitsplatz selbst
|
* @param bool $hideLabel Die Bezeichnung zeigt der Arbeitsplatz selbst
|
||||||
|
* @param bool $images Bilder aus dem Medienbestand einfügen; nur auf Seiten mit dem gemeinsamen Picker
|
||||||
|
* ({@see ManagesEditorialSurface::openTextImagePicker()})
|
||||||
*/
|
*/
|
||||||
public static function make(string $name, ?string $label = null, bool $live = true, bool $hideLabel = false): RichEditor
|
public static function make(string $name, ?string $label = null, bool $live = true, bool $hideLabel = false, bool $images = false): RichEditor
|
||||||
{
|
{
|
||||||
$field = RichEditor::make($name)->toolbarButtons(FormattedText::TOOLBAR);
|
$toolbar = FormattedText::TOOLBAR;
|
||||||
|
|
||||||
|
if ($images) {
|
||||||
|
array_splice($toolbar, count($toolbar) - 1, 0, [['bild']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$field = RichEditor::make($name)->toolbarButtons($toolbar);
|
||||||
|
|
||||||
|
if ($images) {
|
||||||
|
$field->tools([
|
||||||
|
RichEditorTool::make('bild')
|
||||||
|
->label('Bild aus dem Medienbestand einfügen')
|
||||||
|
->icon(Heroicon::Photo)
|
||||||
|
->jsHandler('$wire.openTextImagePicker('.Js::from($name).', editorSelection)'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($live) {
|
if ($live) {
|
||||||
$field->live(onBlur: true);
|
$field->live(onBlur: true);
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Support;
|
||||||
|
|
||||||
|
use App\Support\Brand\SymbolCatalog;
|
||||||
|
use Filament\Forms\Components\ViewField;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auswahlfeld für ein Symbol der Symbolbibliothek: Vorschau des gewählten Symbols und ein Raster zum Wählen (Gruppen,
|
||||||
|
* Suche, Tastatur) statt einer Auswahlliste. Katalog und Bilder lädt das Feld erst beim Öffnen (SymbolPickerController).
|
||||||
|
*
|
||||||
|
* Gespeichert wird nur der Schlüssel. Die Prüfung gegen den Katalog bleibt Sache des Widgets (ADR-30); das Feld prüft
|
||||||
|
* zusätzlich, damit ein manipulierter Wert gar nicht erst ankommt.
|
||||||
|
*/
|
||||||
|
final class SymbolField
|
||||||
|
{
|
||||||
|
public static function make(string $name = 'symbol', string $label = 'Symbol', bool $required = false): ViewField
|
||||||
|
{
|
||||||
|
return ViewField::make($name)
|
||||||
|
->label($label)
|
||||||
|
->view('filament.cms.symbol-feld')
|
||||||
|
->required($required)
|
||||||
|
->rule(Rule::in(array_keys(SymbolCatalog::options())));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
use Filament\Forms\Components\RichEditor\RichContentRenderer;
|
use Filament\Forms\Components\RichEditor\RichContentRenderer;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\ToggleButtons;
|
use Filament\Forms\Components\ToggleButtons;
|
||||||
|
use Filament\Forms\Components\ViewField;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Schemas\Components\Grid;
|
use Filament\Schemas\Components\Grid;
|
||||||
use Filament\Schemas\Components\Group;
|
use Filament\Schemas\Components\Group;
|
||||||
@@ -125,7 +126,7 @@ public static function slotBuilder(string $name = 'widget'): Builder
|
|||||||
/**
|
/**
|
||||||
* Erklärung als kleines (i) neben der Bezeichnung: erscheint beim Überfahren und beim Fokussieren.
|
* Erklärung als kleines (i) neben der Bezeichnung: erscheint beim Überfahren und beim Fokussieren.
|
||||||
*/
|
*/
|
||||||
private static function withInfo(ToggleButtons|Select $component, ?string $help): ToggleButtons|Select
|
private static function withInfo(ToggleButtons|Select|ViewField $component, ?string $help): ToggleButtons|Select|ViewField
|
||||||
{
|
{
|
||||||
return filled($help)
|
return filled($help)
|
||||||
? $component->hintIcon('heroicon-m-information-circle', tooltip: $help)->hintColor('gray')
|
? $component->hintIcon('heroicon-m-information-circle', tooltip: $help)->hintColor('gray')
|
||||||
@@ -154,7 +155,7 @@ public static function block(WidgetType $type): Block
|
|||||||
$labels = $type->settingLabels();
|
$labels = $type->settingLabels();
|
||||||
$hiddenWhen = $type->settingHiddenWhen();
|
$hiddenWhen = $type->settingHiddenWhen();
|
||||||
|
|
||||||
$field = function (string $key) use ($options, $labels, $type, $icons, $hiddenWhen): Select|ToggleButtons {
|
$field = function (string $key) use ($options, $labels, $type, $icons, $hiddenWhen): Select|ToggleButtons|ViewField {
|
||||||
$help = $labels[$key][1] ?? null;
|
$help = $labels[$key][1] ?? null;
|
||||||
// Gemeinsame Höhe (ADR-38): immer als sichtbare Auswahl mit Vorgabe, nie als freie Eingabe.
|
// Gemeinsame Höhe (ADR-38): immer als sichtbare Auswahl mit Vorgabe, nie als freie Eingabe.
|
||||||
$component = $key === 'height'
|
$component = $key === 'height'
|
||||||
@@ -165,11 +166,14 @@ public static function block(WidgetType $type): Block
|
|||||||
->default($type->defaultHeight())
|
->default($type->defaultHeight())
|
||||||
->inline()
|
->inline()
|
||||||
->live()
|
->live()
|
||||||
|
: ($key === 'symbol'
|
||||||
|
// Symbole stehen in einem durchsuchbaren Raster (Symbolbibliothek), nicht in einer Auswahlliste.
|
||||||
|
? SymbolField::make('symbol', $labels[$key][0] ?? 'Symbol')->live()->columnSpanFull()
|
||||||
: Select::make($key)
|
: Select::make($key)
|
||||||
->label($labels[$key][0] ?? Str::headline($key))
|
->label($labels[$key][0] ?? Str::headline($key))
|
||||||
->placeholder('Vorgabe der Darstellung')
|
->placeholder('Vorgabe der Darstellung')
|
||||||
->options($options[$key])
|
->options($options[$key])
|
||||||
->live();
|
->live());
|
||||||
|
|
||||||
if ($key === 'height') {
|
if ($key === 'height') {
|
||||||
$help = 'Gestaltungsparameter, keine Begrenzung: Längere Inhalte erhalten immer den nötigen Platz.';
|
$help = 'Gestaltungsparameter, keine Begrenzung: Längere Inhalte erhalten immer den nötigen Platz.';
|
||||||
|
|||||||
@@ -0,0 +1,136 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\Composition;
|
||||||
|
use App\Domain\Catalog\CompositionKind;
|
||||||
|
use App\Domain\Catalog\ContentVersionStatus;
|
||||||
|
use App\Domain\Catalog\DocumentGuide;
|
||||||
|
use App\Domain\Catalog\DocumentMeta;
|
||||||
|
use App\Domain\Catalog\DocumentPdf;
|
||||||
|
use App\Domain\Catalog\DocumentReader;
|
||||||
|
use App\Domain\Catalog\EditorialWorkingDraft;
|
||||||
|
use App\Domain\Catalog\EmbeddedImages;
|
||||||
|
use App\Domain\Catalog\FormattedText;
|
||||||
|
use App\Domain\Catalog\PdfTemplate;
|
||||||
|
use App\Domain\Identity\StaffRole;
|
||||||
|
use App\Filament\Support\EditorialCatalog;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vorschau eines Dokuments für die Redaktion: der gespeicherte Entwurf, sonst die letzte bereitgestellte Fassung, so wie ein
|
||||||
|
* Mitglied sie als Seite und als PDF sieht (ohne Rechteprüfung und ohne Ausgabenachweis). Ungespeicherte Eingaben im Editor
|
||||||
|
* erscheinen hier erst nach „Entwurf speichern“.
|
||||||
|
*/
|
||||||
|
class DocumentPreviewController extends Controller
|
||||||
|
{
|
||||||
|
public function show(Composition $composition): View
|
||||||
|
{
|
||||||
|
$this->authorizeStaff($composition);
|
||||||
|
$guide = $this->guide($composition);
|
||||||
|
$images = EmbeddedImages::staff();
|
||||||
|
|
||||||
|
foreach ($guide['chapters'] as $index => $chapter) {
|
||||||
|
$guide['chapters'][$index]['html'] = DocumentGuide::anchoredHtml($chapter, 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<string, mixed>
|
||||||
|
*/
|
||||||
|
private function guide(Composition $composition): array
|
||||||
|
{
|
||||||
|
$chapters = app(DocumentReader::class)->forStaff($composition);
|
||||||
|
abort_if($chapters === null, 404);
|
||||||
|
|
||||||
|
foreach ($chapters as $index => $chapter) {
|
||||||
|
$chapters[$index] = DocumentGuide::withHeadings($chapters[$index] + [
|
||||||
|
'allowed' => true,
|
||||||
|
'grant' => null,
|
||||||
|
'may_download' => true,
|
||||||
|
'download_grant' => null,
|
||||||
|
'state' => 'ok',
|
||||||
|
'html' => null,
|
||||||
|
'blocks' => FormattedText::blocks($chapter['version']->body),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$draft = app(EditorialWorkingDraft::class)->read($composition);
|
||||||
|
$ready = $composition->versions()->where('status', ContentVersionStatus::Bereit)->orderByDesc('number')->first();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'title' => app(EditorialCatalog::class)->compositionTitle($composition),
|
||||||
|
'summary_html' => FormattedText::html($composition->summary),
|
||||||
|
'pdf_template' => $composition->pdfTemplate,
|
||||||
|
'meta' => DocumentMeta::normalize($draft !== null ? ($draft['document_meta'] ?? null) : $ready?->document_meta),
|
||||||
|
'chapters' => $chapters,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Muster-PDF einer Vorlage: ein kurzes Handbuch mit Beispielangaben, damit Titelseite, Kopf, Fuß und Seitenzahlen zu sehen
|
||||||
|
* sind, ohne ein Dokument zu brauchen.
|
||||||
|
*/
|
||||||
|
public function template(PdfTemplate $template): Response
|
||||||
|
{
|
||||||
|
$this->authorizeUser();
|
||||||
|
$table = '<table><tbody><tr><th><p>Zeit</p></th><th><p>Inhalt</p></th></tr><tr><td><p>10 Min.</p></td><td><p>Begrüßung</p></td></tr></tbody></table>';
|
||||||
|
$chapters = [];
|
||||||
|
|
||||||
|
foreach (['Grundlagen' => 1, 'Haltung und Abstand' => 1, 'Vertiefung' => 2] as $title => $level) {
|
||||||
|
$number = count($chapters) + 1;
|
||||||
|
$chapters[] = DocumentGuide::withHeadings([
|
||||||
|
'number' => (string) ($level === 1 ? count(array_filter($chapters, fn (array $c): bool => $c['level'] === 1)) + 1 : '2.1'),
|
||||||
|
'level' => $level,
|
||||||
|
'anchor' => 'muster-'.$number,
|
||||||
|
'title' => $title,
|
||||||
|
'allowed' => true,
|
||||||
|
'blocks' => FormattedText::blocks('<p>'.str_repeat('Mustertext für die Vorschau der Vorlage. ', 30).'</p><h3>Zwischenüberschrift</h3>'.$table),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$guide = [
|
||||||
|
'title' => 'Musterhandbuch',
|
||||||
|
'pdf_template' => $template,
|
||||||
|
'meta' => ['subtitle' => 'Beispiel für eine Titelseite', 'edition' => 'Ausgabe 1.0 · Muster', 'published_on' => now()->format('Y-m-d')],
|
||||||
|
'chapters' => $chapters,
|
||||||
|
];
|
||||||
|
|
||||||
|
return response(app(DocumentPdf::class)->render($guide, 'Vorschau der Redaktion', 'vorschau'), 200, [
|
||||||
|
'Content-Type' => 'application/pdf',
|
||||||
|
'Content-Disposition' => 'inline; filename="muster.pdf"',
|
||||||
|
'Cache-Control' => 'private, no-store',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function authorizeUser(): void
|
||||||
|
{
|
||||||
|
$user = auth('staff')->user();
|
||||||
|
abort_unless(
|
||||||
|
$user instanceof User && ($user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter)),
|
||||||
|
403,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function authorizeStaff(Composition $composition): void
|
||||||
|
{
|
||||||
|
$this->authorizeUser();
|
||||||
|
abort_unless($composition->kind === CompositionKind::Document, 404);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Member;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ArticleRelease;
|
||||||
|
use App\Domain\Catalog\CompositionKind;
|
||||||
|
use App\Domain\Catalog\CompositionVersion;
|
||||||
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
|
use App\Domain\Catalog\DocumentGuide;
|
||||||
|
use App\Domain\Catalog\DocumentPdf;
|
||||||
|
use App\Domain\Catalog\EmbeddedImages;
|
||||||
|
use App\Domain\Catalog\ExerciseGuide;
|
||||||
|
use App\Domain\Catalog\LicenseArticle;
|
||||||
|
use App\Domain\Media\DeliveryLog;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Contracts\View\View;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Das Dokument innerhalb des erworbenen Moduls oder Programms: als zusammenhängende Seite mit anklickbarem
|
||||||
|
* Inhaltsverzeichnis und als PDF. Beide zeigen die im Artikel-Stand gebundene Dokumentfassung (ADR-51); über jedes Kapitel
|
||||||
|
* und jedes Bild entscheidet `DecideAccess`, auch die direkte PDF-Adresse wird bei jedem Abruf neu entschieden.
|
||||||
|
*/
|
||||||
|
class DocumentController extends Controller
|
||||||
|
{
|
||||||
|
public function show(Request $request, LicenseArticle $article, ArticleRelease $release, string $path): View
|
||||||
|
{
|
||||||
|
[$guide, $located] = $this->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,
|
||||||
|
// Ohne Ablauf der Adresse: Die Seite bleibt lange offen; bei jedem Abruf entscheidet `DecideAccess` neu.
|
||||||
|
'pdfUrl' => app(DocumentGuide::class)->pdfAllowed($guide) ? route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => $path]) : null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pdf(Request $request, LicenseArticle $article, ArticleRelease $release, string $path): Response
|
||||||
|
{
|
||||||
|
[$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, array_map(fn (array $chapter): ContentElementVersion => $chapter['version'], $guide['chapters']));
|
||||||
|
$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<string, mixed>, 1: array{version: CompositionVersion, selection: list<string>|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];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
use App\Domain\Catalog\ArticleRelease;
|
use App\Domain\Catalog\ArticleRelease;
|
||||||
use App\Domain\Catalog\CompositionVersion;
|
use App\Domain\Catalog\CompositionVersion;
|
||||||
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
|
use App\Domain\Catalog\EmbeddedImages;
|
||||||
use App\Domain\Catalog\ExerciseGuide;
|
use App\Domain\Catalog\ExerciseGuide;
|
||||||
use App\Domain\Catalog\ExercisePdf;
|
use App\Domain\Catalog\ExercisePdf;
|
||||||
use App\Domain\Catalog\LicenseArticle;
|
use App\Domain\Catalog\LicenseArticle;
|
||||||
@@ -76,6 +78,7 @@ public function pdf(Request $request, LicenseArticle $article, ArticleRelease $r
|
|||||||
|
|
||||||
$copy = DeliveryLog::newCopyId();
|
$copy = DeliveryLog::newCopyId();
|
||||||
$variant = collect($guide['variants'])->firstWhere('key', $guide['chosen']);
|
$variant = collect($guide['variants'])->firstWhere('key', $guide['chosen']);
|
||||||
|
$images = app(EmbeddedImages::class)->forPdf($request->user(), $article, $release, array_values(array_map(fn (array $section): ContentElementVersion => $section['version'], array_filter($sections, fn (array $section): bool => $section['class'] === 'text'))));
|
||||||
$content = $pdf->render(
|
$content = $pdf->render(
|
||||||
$guide,
|
$guide,
|
||||||
$sections,
|
$sections,
|
||||||
@@ -83,6 +86,7 @@ public function pdf(Request $request, LicenseArticle $article, ArticleRelease $r
|
|||||||
$copy,
|
$copy,
|
||||||
(string) ($variant['name'] ?? ''),
|
(string) ($variant['name'] ?? ''),
|
||||||
route('member.exercise', ['article' => $article, 'release' => $release, 'path' => $path, 'variante' => $guide['chosen']]),
|
route('member.exercise', ['article' => $article, 'release' => $release, 'path' => $path, 'variante' => $guide['chosen']]),
|
||||||
|
$images,
|
||||||
);
|
);
|
||||||
$checksum = hash('sha256', $content);
|
$checksum = hash('sha256', $content);
|
||||||
|
|
||||||
@@ -94,6 +98,11 @@ public function pdf(Request $request, LicenseArticle $article, ArticleRelease $r
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bilder im Text sind eigene Fassungen: Auch sie stehen im Ausgabenachweis dieses PDF.
|
||||||
|
foreach ($images->used() as $image) {
|
||||||
|
app(DeliveryLog::class)->write($image['grant'], $article, $release, $image['version'], 'laden', 'pdf', $checksum, 'k2', $copy, $located['version']->id);
|
||||||
|
}
|
||||||
|
|
||||||
$name = str($guide['title'])->slug()->value() ?: 'uebung';
|
$name = str($guide['title'])->slug()->value() ?: 'uebung';
|
||||||
|
|
||||||
return response($content, 200, [
|
return response($content, 200, [
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
use App\Domain\Catalog\ContentElementVersion;
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
use App\Domain\Catalog\ContentVersionStatus;
|
use App\Domain\Catalog\ContentVersionStatus;
|
||||||
use App\Domain\Catalog\EditorialVocabulary;
|
use App\Domain\Catalog\EditorialVocabulary;
|
||||||
|
use App\Domain\Catalog\EmbeddedImages;
|
||||||
use App\Domain\Catalog\IdentityDimension;
|
use App\Domain\Catalog\IdentityDimension;
|
||||||
use App\Domain\Catalog\LicenseArticle;
|
use App\Domain\Catalog\LicenseArticle;
|
||||||
use App\Domain\Catalog\Pillar;
|
use App\Domain\Catalog\Pillar;
|
||||||
@@ -240,6 +241,7 @@ public function show(Request $request, LicenseArticle $article): View
|
|||||||
'class' => $class,
|
'class' => $class,
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
|
'images' => $class === 'text' ? app(EmbeddedImages::class)->forView($request->user(), $article, $release, $version) : null,
|
||||||
'role' => $content->role,
|
'role' => $content->role,
|
||||||
'action' => $action,
|
'action' => $action,
|
||||||
'allowed' => $decision->allowed,
|
'allowed' => $decision->allowed,
|
||||||
@@ -319,6 +321,7 @@ public function media(
|
|||||||
'article' => $article,
|
'article' => $article,
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
'license' => $decision->grant->rights_snapshot['purpose'] ?? null,
|
'license' => $decision->grant->rights_snapshot['purpose'] ?? null,
|
||||||
|
'images' => app(EmbeddedImages::class)->forView($request->user(), $article, $release, $version),
|
||||||
'reader' => $request->user()->name,
|
'reader' => $request->user()->name,
|
||||||
'copy' => $delivery->copy_id,
|
'copy' => $delivery->copy_id,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Member;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ArticleRelease;
|
||||||
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
|
use App\Domain\Catalog\EmbeddedImages;
|
||||||
|
use App\Domain\Catalog\ExerciseGuide;
|
||||||
|
use App\Domain\Catalog\LicenseArticle;
|
||||||
|
use App\Domain\Media\DeliveryLog;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\LibraryCatalog;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ein Bild im Text eines erworbenen Stands (ADR-51). Die Adresse läuft nicht ab, weil eine Seite lange offen bleibt; dafür
|
||||||
|
* entscheidet jeder Abruf neu: Konto, Stand, Text, Recht am Text, Zugehörigkeit des Bildes zum Text und zum Stand und die
|
||||||
|
* Sperre der Bildfassung. Eine Datei liegt nie unter einem öffentlichen Pfad.
|
||||||
|
*/
|
||||||
|
class StandImageController extends Controller
|
||||||
|
{
|
||||||
|
public function __invoke(Request $request, LicenseArticle $article, ArticleRelease $release, ContentElementVersion $text, ContentElementVersion $version): StreamedResponse
|
||||||
|
{
|
||||||
|
abort_unless(app(ExerciseGuide::class)->mayOpen($request->user(), $article, $release), 403);
|
||||||
|
|
||||||
|
$served = app(EmbeddedImages::class)->serve($request->user(), $article, $release, $text, $version->id);
|
||||||
|
abort_if($served === null, 403);
|
||||||
|
|
||||||
|
$file = EmbeddedImages::file($served['version']);
|
||||||
|
abort_if($file === null, 404);
|
||||||
|
|
||||||
|
$disk = Storage::disk('media_derived');
|
||||||
|
$delivery = app(DeliveryLog::class)->write($served['grant'], $article, $release, $served['version'], 'ansehen', 'bestand', hash_file('sha256', $disk->path($file)) ?: null, 'k0');
|
||||||
|
$title = app(LibraryCatalog::class)->text($served['version']->element)['title'];
|
||||||
|
$name = ($title !== '' ? preg_replace('/[\x00-\x1F\x7F\/\\\\:*?"<>|]+/u', ' ', $title) : 'bild').'.'.strtolower(pathinfo($file, PATHINFO_EXTENSION));
|
||||||
|
|
||||||
|
return $disk->response($file, trim((string) $name), ['X-License-Copy' => $delivery->copy_id, 'Cache-Control' => 'private, max-age=300'], 'inline');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Domain\Identity\StaffRole;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Support\Brand\SymbolCatalog;
|
||||||
|
use App\Support\Brand\Symbols;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daten für den Symbolwähler im CMS (nur Redaktion und Katalogverwaltung): der Katalog als JSON, je Symbol mit seiner
|
||||||
|
* Zeichnung.
|
||||||
|
*
|
||||||
|
* Der Wähler lädt das erst beim Öffnen und einmal je Seitenaufruf. So stecken nicht 70 Zeichnungen in jeder Antwort
|
||||||
|
* des Formulars, und es braucht keine 70 einzelnen Bildabrufe.
|
||||||
|
*/
|
||||||
|
class SymbolPickerController extends Controller
|
||||||
|
{
|
||||||
|
public function catalog(): JsonResponse
|
||||||
|
{
|
||||||
|
$this->authorizeStaff();
|
||||||
|
|
||||||
|
// Eine Antwort mit allen Zeichnungen statt eines Bildes je Symbol: ein Aufruf, keine siebzig.
|
||||||
|
$groups = array_map(function (array $group): array {
|
||||||
|
$group['items'] = array_map(fn (array $item): array => $item + ['svg' => (string) Symbols::symbol($item['key'])], $group['items']);
|
||||||
|
|
||||||
|
return $group;
|
||||||
|
}, SymbolCatalog::groups());
|
||||||
|
|
||||||
|
return response()->json(['groups' => $groups])->header('Cache-Control', 'private, max-age=300');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function authorizeStaff(): void
|
||||||
|
{
|
||||||
|
$user = auth('staff')->user();
|
||||||
|
|
||||||
|
abort_unless(
|
||||||
|
$user instanceof User && ($user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter)),
|
||||||
|
403,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
$title = $node->title;
|
||||||
|
|
||||||
if ($element !== null) {
|
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,
|
'kind' => $node->editorialKindLabel ?? $this->outputLabel($node->technicalKindLabel) ?? $node->technicalKindLabel,
|
||||||
'output_class' => $node->outputClass,
|
'output_class' => $node->outputClass,
|
||||||
'playback' => $playback,
|
'playback' => $playback,
|
||||||
'view_url' => $view,
|
'view_url' => $view ?? $documentUrl,
|
||||||
'poster_url' => $poster,
|
'poster_url' => $poster,
|
||||||
'download_url' => $download,
|
'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,
|
'composition_id' => $node->compositionId,
|
||||||
'element_id' => $node->contentElementId,
|
'element_id' => $node->contentElementId,
|
||||||
'version_id' => $node->contentElementVersionId,
|
'version_id' => $node->contentElementVersionId,
|
||||||
@@ -407,13 +410,20 @@ private function present(User $user, StructureNode $node, bool $full, int $rootI
|
|||||||
'composition' => $rootId,
|
'composition' => $rootId,
|
||||||
'version' => $node->contentElementVersionId,
|
'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),
|
fn (StructureNode $child): array => $this->present($user, $child, $full, $rootId),
|
||||||
$node->children,
|
$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<array<string, mixed>> $nodes
|
* @param list<array<string, mixed>> $nodes
|
||||||
* @param list<array<string, mixed>> $parents
|
* @param list<array<string, mixed>> $parents
|
||||||
@@ -467,7 +477,7 @@ private function countCompositions(array $nodes): int
|
|||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
foreach ($nodes as $node) {
|
foreach ($nodes as $node) {
|
||||||
if ($node['composition_id'] !== null) {
|
if ($node['composition_id'] !== null && empty($node['document'])) {
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,8 +523,9 @@ private function exerciseUrl(User $user, int $rootId, StructureNode $node): ?str
|
|||||||
}
|
}
|
||||||
|
|
||||||
$nested = CompositionVersion::query()->with('composition')->find($node->compositionVersionId);
|
$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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,7 +544,7 @@ private function exerciseUrl(User $user, int $rootId, StructureNode $node): ?str
|
|||||||
$path = $guide->pathTo($release->rootCompositionVersion, $nested->id);
|
$path = $guide->pathTo($release->rootCompositionVersion, $nested->id);
|
||||||
|
|
||||||
if ($path !== null) {
|
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use App\Auth\StaffAuthenticatorName;
|
use App\Auth\StaffAuthenticatorName;
|
||||||
use App\Filament\Auth\StaffLogin;
|
use App\Filament\Auth\StaffLogin;
|
||||||
|
use App\Filament\Support\LegacyAddresses;
|
||||||
use App\Http\Middleware\SanitizeIntendedUrl;
|
use App\Http\Middleware\SanitizeIntendedUrl;
|
||||||
use Filament\Auth\MultiFactor\App\AppAuthentication;
|
use Filament\Auth\MultiFactor\App\AppAuthentication;
|
||||||
use Filament\Http\Middleware\Authenticate;
|
use Filament\Http\Middleware\Authenticate;
|
||||||
@@ -67,6 +68,7 @@ public function panel(Panel $panel): Panel
|
|||||||
->authMiddleware([
|
->authMiddleware([
|
||||||
Authenticate::class,
|
Authenticate::class,
|
||||||
])
|
])
|
||||||
|
->authenticatedRoutes(LegacyAddresses::routes(...))
|
||||||
// Favicon zur Anfragezeit: ->favicon(asset(...)) würde beim Start der Anwendung berechnet, vor der
|
// Favicon zur Anfragezeit: ->favicon(asset(...)) würde beim Start der Anwendung berechnet, vor der
|
||||||
// Auswertung von Proxy-Kopfzeilen und geöffneter Adresse, und könnte auf einen falschen Host zeigen.
|
// Auswertung von Proxy-Kopfzeilen und geöffneter Adresse, und könnte auf einen falschen Host zeigen.
|
||||||
->renderHook(
|
->renderHook(
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Support\Brand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Katalog der Kleingrafiken: deutscher Titel, Gruppe und Suchwörter je Symbol.
|
||||||
|
*
|
||||||
|
* Quelle ist resources/svg/brand/symbole/_katalog.json. Der Schlüssel ist der Dateiname ohne Endung und wird dauerhaft in
|
||||||
|
* Seitendaten gespeichert (nie umbenennen). Ein Symbol mit "angeboten": false (gelbe Unterstreichung, Signalstrahlen) hat
|
||||||
|
* eine eigene Einstellung und erscheint nicht in der Auswahl. Ein Test stellt sicher, dass jede Datei einen Eintrag hat.
|
||||||
|
*/
|
||||||
|
final class SymbolCatalog
|
||||||
|
{
|
||||||
|
/** @var array{gruppen: list<string>, symbole: array<string, array<string, mixed>>}|null */
|
||||||
|
private static ?array $data = null;
|
||||||
|
|
||||||
|
/** @var array<string, string>|null */
|
||||||
|
private static ?array $options = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auswahl für Prüfung und Auswahlfelder: Schlüssel => Titel, geordnet nach Gruppe und Titel.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public static function options(): array
|
||||||
|
{
|
||||||
|
return self::$options ??= (function (): array {
|
||||||
|
$options = [];
|
||||||
|
|
||||||
|
foreach (self::groups() as $group) {
|
||||||
|
foreach ($group['items'] as $item) {
|
||||||
|
$options[$item['key']] = $item['title'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{name: string, items: list<array{key: string, title: string, search: string}>}>
|
||||||
|
*/
|
||||||
|
public static function groups(): array
|
||||||
|
{
|
||||||
|
$data = self::data();
|
||||||
|
$groups = array_map(fn (string $name): array => ['name' => $name, 'items' => []], $data['gruppen']);
|
||||||
|
|
||||||
|
foreach ($data['symbole'] as $key => $entry) {
|
||||||
|
$index = $entry['gruppe'] ?? null;
|
||||||
|
|
||||||
|
if (($entry['angeboten'] ?? true) === false || ! is_int($index) || ! isset($groups[$index])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$groups[$index]['items'][] = [
|
||||||
|
'key' => $key,
|
||||||
|
'title' => (string) $entry['titel'],
|
||||||
|
'search' => mb_strtolower($entry['titel'].' '.($entry['suche'] ?? '')),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($groups as &$group) {
|
||||||
|
usort($group['items'], fn (array $a, array $b): int => strcmp(self::sortKey($a['title']), self::sortKey($b['title'])));
|
||||||
|
}
|
||||||
|
unset($group);
|
||||||
|
|
||||||
|
return array_values(array_filter($groups, fn (array $group): bool => $group['items'] !== []));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function title(string $key): ?string
|
||||||
|
{
|
||||||
|
$title = self::data()['symbole'][$key]['titel'] ?? null;
|
||||||
|
|
||||||
|
return is_string($title) ? $title : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schlüssel, zu denen der Katalog einen Eintrag hat (auch nicht angebotene).
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
public static function keys(): array
|
||||||
|
{
|
||||||
|
return array_keys(self::data()['symbole']);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function sortKey(string $title): string
|
||||||
|
{
|
||||||
|
return strtr(mb_strtolower($title), ['ä' => 'a', 'ö' => 'o', 'ü' => 'u', 'ß' => 'ss']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{gruppen: list<string>, symbole: array<string, array<string, mixed>>}
|
||||||
|
*/
|
||||||
|
private static function data(): array
|
||||||
|
{
|
||||||
|
return self::$data ??= (function (): array {
|
||||||
|
$file = resource_path('svg/brand/symbole/_katalog.json');
|
||||||
|
$data = is_file($file) ? json_decode((string) file_get_contents($file), true) : null;
|
||||||
|
|
||||||
|
return is_array($data) && is_array($data['gruppen'] ?? null) && is_array($data['symbole'] ?? null)
|
||||||
|
? $data
|
||||||
|
: ['gruppen' => [], 'symbole' => []];
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,9 @@ final class Symbols
|
|||||||
/** @var array<string, string> */
|
/** @var array<string, string> */
|
||||||
private static array $cache = [];
|
private static array $cache = [];
|
||||||
|
|
||||||
|
/** @var array<string, array<string, float>>|null */
|
||||||
|
private static ?array $bounds = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return list<string>
|
* @return list<string>
|
||||||
*/
|
*/
|
||||||
@@ -56,20 +59,51 @@ private static function render(string $set, string $name, string $attributes): H
|
|||||||
throw new InvalidArgumentException("Unbekanntes Markensymbol „{$name}“ im Satz „{$set}“.");
|
throw new InvalidArgumentException("Unbekanntes Markensymbol „{$name}“ im Satz „{$set}“.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$svg = self::$cache["$set/$name"] ??= self::clean((string) file_get_contents(self::directory($set)."/$name.svg"));
|
$svg = self::$cache["$set/$name"] ??= self::clean((string) file_get_contents(self::directory($set)."/$name.svg"), $set === self::SET_SYMBOLS ? self::bounds($name) : null);
|
||||||
$extra = trim($attributes) === '' ? '' : ' '.trim($attributes);
|
$extra = trim($attributes) === '' ? '' : ' '.trim($attributes);
|
||||||
|
|
||||||
return new HtmlString(preg_replace('/^<svg\b/', '<svg aria-hidden="true" focusable="false"'.$extra, $svg, 1) ?? $svg);
|
return new HtmlString(preg_replace('/^<svg\b/', '<svg aria-hidden="true" focusable="false"'.$extra, $svg, 1) ?? $svg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function clean(string $svg): string
|
/**
|
||||||
|
* Sichtbare Zeichnung eines Symbols in Einheiten seiner ursprünglichen Zeichenfläche: x, y, w (Breite), h (Höhe).
|
||||||
|
* Die Kit-Dateien haben einen unsichtbaren Rand um die Zeichnung (je nach Symbol 5 bis 20 % der Fläche). Beim
|
||||||
|
* Einbetten wird die Zeichenfläche auf diese Grenzen zugeschnitten, damit die Oberkante der Zeichnung bündig mit der
|
||||||
|
* Oberkante von Text oder Rahmen abschließt. Gemessen mit scripts/brand-symbol-bounds.py (Datei _grenzen.json).
|
||||||
|
*
|
||||||
|
* @return array{x: float, y: float, w: float, h: float}|null
|
||||||
|
*/
|
||||||
|
public static function bounds(string $name): ?array
|
||||||
|
{
|
||||||
|
self::$bounds ??= (function (): array {
|
||||||
|
$file = self::directory(self::SET_SYMBOLS).'/_grenzen.json';
|
||||||
|
$data = is_file($file) ? json_decode((string) file_get_contents($file), true) : null;
|
||||||
|
|
||||||
|
return is_array($data) ? $data : [];
|
||||||
|
})();
|
||||||
|
|
||||||
|
$box = self::$bounds[$name] ?? null;
|
||||||
|
|
||||||
|
return is_array($box) && isset($box['x'], $box['y'], $box['w'], $box['h']) && $box['w'] > 0 && $box['h'] > 0 ? $box : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array{x: float, y: float, w: float, h: float}|null $bounds
|
||||||
|
*/
|
||||||
|
private static function clean(string $svg, ?array $bounds = null): string
|
||||||
{
|
{
|
||||||
$svg = trim($svg);
|
$svg = trim($svg);
|
||||||
$svg = preg_replace('#<title\b[^>]*>.*?</title>#s', '', $svg) ?? $svg;
|
$svg = preg_replace('#<title\b[^>]*>.*?</title>#s', '', $svg) ?? $svg;
|
||||||
$svg = preg_replace('/\r?\n\s*/', '', $svg) ?? $svg;
|
$svg = preg_replace('/\r?\n\s*/', '', $svg) ?? $svg;
|
||||||
|
|
||||||
return (string) preg_replace_callback('/^<svg\b[^>]*>/', function (array $root): string {
|
return (string) preg_replace_callback('/^<svg\b[^>]*>/', function (array $root) use ($bounds): string {
|
||||||
return (string) preg_replace('/\s(?:id|role|aria-labelledby|width|height)="[^"]*"/', '', $root[0]);
|
$tag = (string) preg_replace('/\s(?:id|role|aria-labelledby|width|height)="[^"]*"/', '', $root[0]);
|
||||||
|
|
||||||
|
if ($bounds !== null) {
|
||||||
|
$tag = (string) preg_replace('/\sviewBox="[^"]*"/', ' viewBox="'.implode(' ', [$bounds['x'], $bounds['y'], $bounds['w'], $bounds['h']]).'"', $tag, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tag;
|
||||||
}, $svg);
|
}, $svg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dokumente (ADR-51), rein additiv: zwei redaktionelle Materialarten ohne neue Spalte und ohne neue Tabelle.
|
||||||
|
*
|
||||||
|
* - `dokument`: Art des Dokuments selbst, wählbar im Kontext „Dokument“.
|
||||||
|
* - `dokumentkapitel`: Art der Kapiteltexte, nur automatisch gesetzt (kein wählbarer Kontext), im Medienbestand wie die
|
||||||
|
* Übungsabschnitte standardmäßig ausgeblendet.
|
||||||
|
*
|
||||||
|
* Der Rückfall auf den vorherigen Programmstand setzt nur den Code zurück. Dieser kennt die Kompositionsart `document`
|
||||||
|
* nicht und blendet Dokumente über den Bereichsfilter (SupportedKindScope) aus; die Kapiteltexte bleiben als Texte
|
||||||
|
* erhalten. Ein Stand, der ein Dokument bindet, bleibt in der Datenbank unverändert.
|
||||||
|
*/
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$now = now();
|
||||||
|
DB::table('editorial_content_kinds')->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();
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PDF-Vorlagen für Dokumente (ADR-51, Nachtrag), rein additiv:
|
||||||
|
*
|
||||||
|
* - `pdf_templates`: Titelseite, Kopf- und Fußgrafik und Standardvermerke. Die Bilder verweisen auf freigegebene Bildfassungen
|
||||||
|
* des Medienbestands.
|
||||||
|
* - `compositions.pdf_template_id`: welche Vorlage ein Dokument verwendet (leer = bisheriges Layout).
|
||||||
|
* - `composition_versions.document_meta`: Untertitel, Ausgabe (Release), Veröffentlichungsdatum und Copyright-Vermerk einer
|
||||||
|
* Dokumentfassung. Sie sind Teil der Fassung und damit versioniert.
|
||||||
|
*
|
||||||
|
* Der Rückfall auf den vorherigen Programmstand setzt nur den Code zurück. Dieser kennt die Spalten und die Tabelle nicht;
|
||||||
|
* ohne Vorlage und ohne Angaben erzeugt er dasselbe PDF wie bisher.
|
||||||
|
*/
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('pdf_templates', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
|
$table->string('kind')->default('dokument');
|
||||||
|
$table->boolean('show_cover')->default(true);
|
||||||
|
$table->foreignId('header_version_id')->nullable()->constrained('content_element_versions')->nullOnDelete();
|
||||||
|
$table->foreignId('footer_version_id')->nullable()->constrained('content_element_versions')->nullOnDelete();
|
||||||
|
$table->foreignId('cover_version_id')->nullable()->constrained('content_element_versions')->nullOnDelete();
|
||||||
|
$table->string('publisher')->nullable();
|
||||||
|
$table->text('copyright')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('compositions', function (Blueprint $table) {
|
||||||
|
$table->foreignId('pdf_template_id')->nullable()->constrained('pdf_templates')->nullOnDelete();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('composition_versions', function (Blueprint $table) {
|
||||||
|
$table->json('document_meta')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('composition_versions', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('document_meta');
|
||||||
|
});
|
||||||
|
Schema::table('compositions', function (Blueprint $table) {
|
||||||
|
$table->dropConstrainedForeignId('pdf_template_id');
|
||||||
|
});
|
||||||
|
Schema::dropIfExists('pdf_templates');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PDF-Vorlagen können auch Bilder ohne Inhaltsfassung verwenden, also Präsentationsmedien und für die Website freigegebene
|
||||||
|
* Bilder des Medienmanagers. Je Bildfeld steht dafür neben der Bildfassung (`*_version_id`) der Verweis auf das Medium selbst
|
||||||
|
* (`*_element_id`). Rein additiv; ein Feld nutzt immer genau eine der beiden Angaben.
|
||||||
|
*/
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('pdf_templates', function (Blueprint $table) {
|
||||||
|
$table->foreignId('header_element_id')->nullable()->constrained('content_elements')->nullOnDelete();
|
||||||
|
$table->foreignId('footer_element_id')->nullable()->constrained('content_elements')->nullOnDelete();
|
||||||
|
$table->foreignId('cover_element_id')->nullable()->constrained('content_elements')->nullOnDelete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('pdf_templates', function (Blueprint $table) {
|
||||||
|
$table->dropConstrainedForeignId('header_element_id');
|
||||||
|
$table->dropConstrainedForeignId('footer_element_id');
|
||||||
|
$table->dropConstrainedForeignId('cover_element_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kopf und Fuß einer PDF-Vorlage können statt eines Bands in voller Seitenbreite ein Logo links oder rechts tragen.
|
||||||
|
* Je Zeile steht dafür die Anordnung (`full`, `left`, `right`) und die Höhe des Logos in Punkt. Rein additiv; ohne die
|
||||||
|
* Spalten, also im vorherigen Programmstand, bleibt jede Grafik ein Band in voller Seitenbreite.
|
||||||
|
*/
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('pdf_templates', function (Blueprint $table) {
|
||||||
|
$table->string('header_align', 10)->default('full');
|
||||||
|
$table->string('footer_align', 10)->default('full');
|
||||||
|
$table->unsignedSmallInteger('header_logo_height')->default(40);
|
||||||
|
$table->unsignedSmallInteger('footer_logo_height')->default(40);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('pdf_templates', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['header_align', 'footer_align', 'header_logo_height', 'footer_logo_height']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Das gedruckte Inhaltsverzeichnis einer PDF-Vorlage ist einstellbar: ob es erscheint (`auto` = nur bei mehr als einem
|
||||||
|
* Eintrag, `always`, `never`) und bis zu welcher Überschriftenstufe es reicht (2 = nur Kapitel, 3 bis 6 = bis zu dieser
|
||||||
|
* Überschrift). Rein additiv; ohne die Spalten, also im vorherigen Programmstand, steht das vollständige Verzeichnis.
|
||||||
|
*/
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('pdf_templates', function (Blueprint $table) {
|
||||||
|
$table->string('toc_mode', 10)->default('auto');
|
||||||
|
$table->unsignedTinyInteger('toc_depth')->default(6);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('pdf_templates', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['toc_mode', 'toc_depth']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
After Width: | Height: | Size: 137 KiB |
|
After Width: | Height: | Size: 123 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 135 KiB |
|
After Width: | Height: | Size: 194 KiB |
|
After Width: | Height: | Size: 160 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 113 KiB |
|
After Width: | Height: | Size: 233 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 186 KiB |
|
After Width: | Height: | Size: 154 KiB |
@@ -0,0 +1,9 @@
|
|||||||
|
# Lara & Felix – Symbolbibliothek v0.1
|
||||||
|
|
||||||
|
50 Symbole, echte Vektorpfade, transparente Hintergründe. 64 × 64 viewBox, Grundkontur 3,2 Einheiten, runde Linien.
|
||||||
|
|
||||||
|
Quellen: Vorschau(1).png, brand_ui_uebersicht_entwurf(1).png, homepage_entwurf(3).png; design-prinzipien.md §§3–5; trainingskonzept-und-produktstruktur.md §§2–3.
|
||||||
|
|
||||||
|
Original-SVGs und PowerPoint-Trainerkarte nicht verfügbar. Rekonstruktionen sind keine Originale. Farben sind Entwurfswerte. Wortmarke bleibt unverändert und ist nicht Teil der Bibliothek. Text-Badges und dekorative Pinselstriche sind keine eigenständigen Funktionssymbole.
|
||||||
|
|
||||||
|
Freigabe offen: Originalabgleich, tatsächlicher A5-Probedruck, Verständlichkeitstest ohne Labels, fünf separate Themen-Signaturen (nicht mit Funktionssymbolen gleichsetzen). Übergreifender ADR-36-Ergänzungsvorschlag nach Freigabe: stabile Dateinamen, eindeutige Semantik und gemeinsame Assets für Druck/Web; keine Änderung am zentralen ADR vor Freigabe.
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
# Symbolmatrix v0.1
|
||||||
|
|
||||||
|
Entwurf – keine Freigabe. R = Rekonstruktion nach PNG, kein Original-SVG; N = Neuentwicklung.
|
||||||
|
|
||||||
|
| Symbol | Datei | Bedeutung | Anwendungsfall | Herkunft | Farben |
|
||||||
|
|---|---|---|---|---|---|
|
||||||
|
| Film | `film.svg` | Vollständiger Film | Film auswählen | Rekonstruktion nach PNG | Dunkelblau, Gelb; monochrom zulässig mit Textlabel |
|
||||||
|
| Filmsequenz | `filmsequenz.svg` | Ausschnitt eines Films | Pausenstelle / Clip | Rekonstruktion nach PNG | Dunkelblau; monochrom zulässig mit Textlabel |
|
||||||
|
| Wiedergabe | `wiedergabe.svg` | Film starten | Player-Aktion | Rekonstruktion nach PNG | Dunkelblau, Gelb; monochrom zulässig mit Textlabel |
|
||||||
|
| Denkpause | `denkpause.svg` | Bewusstes Unterbrechen zum Nachdenken | Film anhalten und offene Frage stellen | Rekonstruktion nach PNG | Dunkelblau, Gelb; monochrom zulässig mit Textlabel |
|
||||||
|
| Bildkarten | `bildkarten.svg` | Visuelle Szenenkarten | Karten auslegen | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Arbeitsblatt | `arbeitsblatt.svg` | Aufgaben zum Bearbeiten | Kinderaufgabe | Rekonstruktion nach PNG | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Merkblatt | `merkblatt.svg` | Zusammenfassung zum Nachlesen | Merkzettel verteilen | Rekonstruktion nach PNG | Dunkelblau; monochrom zulässig mit Textlabel |
|
||||||
|
| Handbuch | `handbuch.svg` | Umfangreiche Anleitung | Trainerhandbuch | Rekonstruktion nach PNG | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Download | `download.svg` | Datei herunterladen | PDF speichern | Rekonstruktion nach PNG | Dunkelblau; monochrom zulässig mit Textlabel |
|
||||||
|
| Materialpaket | `materialpaket.svg` | Gebündelte Materialien | Materialsammlung | Rekonstruktion nach PNG | Dunkelblau; monochrom zulässig mit Textlabel |
|
||||||
|
| Rollenspiel | `rollenspiel.svg` | Eine Situation in Rollen spielen | Szenen nachstellen | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Partnerübung | `partneruebung.svg` | Üben zu zweit | Zweiergruppen | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Gruppenübung | `gruppenuebung.svg` | Gemeinsam in einer Gruppe üben | Gruppenaufgabe | Rekonstruktion nach PNG | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Bewegung | `bewegung.svg` | Körperlich aktiv werden | Bewegungsübung | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Visualisierung | `visualisierung.svg` | Inhalte bildlich darstellen | Tafelbild / Skizze | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Gespräch | `gespraech.svg` | Miteinander sprechen | Austausch anleiten | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Beobachtung | `beobachtung.svg` | Gezielt wahrnehmen | Körpersprache beobachten | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Reflexion | `reflexion.svg` | Erfahrung nachträglich betrachten | Nachbesprechung | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Fragebogen | `fragebogen.svg` | Fragen strukturiert beantworten | Rückmeldung erfassen | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Lernziele | `lernziele.svg` | Angestrebte Fähigkeit | Lernziel angeben | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Material | `material.svg` | Benötigte Gegenstände | Materialliste | Neuentwicklung | Dunkelblau; monochrom zulässig mit Textlabel |
|
||||||
|
| Raumaufbau | `raumaufbau.svg` | Räumliche Anordnung | Trainingsfläche vorbereiten | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Rollenverteilung | `rollenverteilung.svg` | Aufgaben Personen zuweisen | Rollen vergeben | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Vorbereitung | `vorbereitung.svg` | Vor Kursbeginn prüfen | Vorbereitungscheck | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Zeitbedarf | `zeitbedarf.svg` | Benötigte Dauer | Minutenangabe | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Ablauf | `ablauf.svg` | Geordnete Schritte | Trainingsreihenfolge | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Wiederholung | `wiederholung.svg` | Erneut durchführen | Übung wiederholen | Neuentwicklung | Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Varianten | `varianten.svg` | Abwandlungen einer Übung | Alternative Übungsform | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Persönlicher Abstand | `persoenlicher-abstand.svg` | Distanz zwischen Personen | Abstandsübung | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Grenzen erkennen | `grenzen-erkennen.svg` | Persönlichen Bereich wahrnehmen | Nähe und Distanz reflektieren | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Stopp | `stopp.svg` | Eindeutiges Anhaltesignal | Annäherung sofort beenden | Rekonstruktion nach PNG | Dunkelblau; monochrom zulässig mit Textlabel |
|
||||||
|
| Nein sagen | `nein-sagen.svg` | Ablehnung aussprechen | Nein üben | Neuentwicklung | Dunkelblau; keine negative Statusfarbe |
|
||||||
|
| Körpersprache | `koerpersprache.svg` | Haltung und Gestik | Sicheren Stand üben | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Stimme | `stimme.svg` | Bewusst hörbar sprechen | Stimmübung | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Selbstvertrauen | `selbstvertrauen.svg` | Eigene Stärke erfahren | Mut und Selbstwirksamkeit | Rekonstruktion nach PNG | Dunkelblau, Gelb; monochrom zulässig mit Textlabel |
|
||||||
|
| Hilfe holen | `hilfe-holen.svg` | Unterstützung ansprechen | Vertrauensperson kontaktieren | Neuentwicklung | Dunkelblau, Grün, Gelb; monochrom zulässig mit Textlabel |
|
||||||
|
| Trainerhinweis | `trainerhinweis.svg` | Hinweis für die Kursleitung | Durchführungshinweis | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Unerwartete Kinderreaktion | `kinderreaktion.svg` | Reaktion, die Aufmerksamkeit braucht | Übung unterbrechen und begleiten | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Perspektivwechsel | `perspektivwechsel.svg` | Andere Sichtweise einnehmen | Sicht der Beteiligten wechseln | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Handlungsalternativen | `handlungsalternativen.svg` | Mehrere mögliche Entscheidungen | Optionen sammeln | Neuentwicklung | Dunkelblau; monochrom zulässig mit Textlabel |
|
||||||
|
| Deeskalation | `deeskalation.svg` | Spannung abbauen | Konflikt beruhigen | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Freiwilligkeit | `freiwilligkeit.svg` | Teilnahme selbst wählen | Einverständnis vor Übung | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Kindeswohl | `kindeswohl.svg` | Schutz und Wohlergehen des Kindes | Kinderschutz beachten | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Merksatz | `merksatz.svg` | Zentrale Botschaft behalten | Abschlussregel | Neuentwicklung | Dunkelblau, Grün, Gelb; monochrom zulässig mit Textlabel |
|
||||||
|
| Aufmerksamkeit | `aufmerksamkeit.svg` | Wichtigen Impuls beachten | Hervorhebung | Neuentwicklung | Dunkelblau, Gelb; monochrom zulässig mit Textlabel |
|
||||||
|
| Sicherheitshinweis | `sicherheitshinweis.svg` | Sicherheitsrelevante Anweisung | Gefahr vermeiden | Neuentwicklung | Dunkelblau, Grün; monochrom zulässig mit Textlabel |
|
||||||
|
| Geeignet | `geeignet.svg` | Methode oder Verhalten geeignet | Positive Kennzeichnung | Rekonstruktion nach PNG | Grün; alternativ monochrom |
|
||||||
|
| Nicht geeignet | `nicht-geeignet.svg` | Methode oder Verhalten nicht geeignet | Negative Kennzeichnung | Rekonstruktion nach PNG | Rot; alternativ monochrom |
|
||||||
|
| Mitdenken | `mitdenken.svg` | Offene Frage zum Nachdenken | Gesprächsimpuls | Rekonstruktion nach PNG | Grün; alternativ monochrom |
|
||||||
|
| Bildung | `bildung.svg` | Pädagogischer Einsatz | Schule und Weiterbildung | Rekonstruktion nach PNG | Dunkelblau, Grün, Gelb; monochrom zulässig mit Textlabel |
|
||||||
|
After Width: | Height: | Size: 6.5 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 8.1 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 6.2 KiB |