Pdf Vorlagen Manager #11
No files matched your search
@@ -5,7 +5,6 @@
|
||||
use App\Domain\Commerce\Receipt\PdfDocument;
|
||||
use App\Domain\Media\PdfImage;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Transliterator;
|
||||
|
||||
/**
|
||||
@@ -88,9 +87,9 @@ public function render(array $guide, string $licensee, string $copyId, ?PdfImage
|
||||
private function prepareLayout(?PdfTemplate $template): void
|
||||
{
|
||||
$this->bands = [
|
||||
'header' => $this->band($template?->headerVersion, 140.0),
|
||||
'footer' => $this->band($template?->footerVersion, 140.0),
|
||||
'cover' => $template !== null && $template->show_cover ? $this->band($template->coverVersion, self::PAGE_HEIGHT * 0.4) : null,
|
||||
'header' => $this->band($template?->target('header'), 140.0),
|
||||
'footer' => $this->band($template?->target('footer'), 140.0),
|
||||
'cover' => $template !== null && $template->show_cover ? $this->band($template->target('cover'), self::PAGE_HEIGHT * 0.4) : null,
|
||||
];
|
||||
$header = (float) ($this->bands['header']['height'] ?? 0);
|
||||
$footer = (float) ($this->bands['footer']['height'] ?? 0);
|
||||
@@ -104,10 +103,10 @@ private function prepareLayout(?PdfTemplate $template): void
|
||||
*
|
||||
* @return array{jpeg: string, pixelWidth: int, pixelHeight: int, width: float, height: float, x: float}|null
|
||||
*/
|
||||
private function band(?ContentElementVersion $version, float $maxHeight): ?array
|
||||
private function band(?string $target, float $maxHeight): ?array
|
||||
{
|
||||
$file = $version === null ? null : EmbeddedImages::file($version);
|
||||
$image = $file === null ? null : PdfImage::fromBytes((string) Storage::disk('media_derived')->get($file));
|
||||
$bytes = TemplateImage::bytes($target);
|
||||
$image = $bytes === null ? null : PdfImage::fromBytes($bytes);
|
||||
|
||||
if ($image === null) {
|
||||
return null;
|
||||
|
||||
@@ -22,6 +22,9 @@ class PdfTemplate extends Model
|
||||
'header_version_id',
|
||||
'footer_version_id',
|
||||
'cover_version_id',
|
||||
'header_element_id',
|
||||
'footer_element_id',
|
||||
'cover_element_id',
|
||||
'publisher',
|
||||
'copyright',
|
||||
];
|
||||
@@ -31,6 +34,34 @@ protected function casts(): array
|
||||
return ['show_cover' => 'boolean'];
|
||||
}
|
||||
|
||||
public const SLOTS = ['header', 'footer', 'cover'];
|
||||
|
||||
/**
|
||||
* 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');
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EmbeddedImages;
|
||||
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;
|
||||
@@ -46,11 +44,12 @@ class PdfVorlagen extends Page
|
||||
|
||||
public bool $showCover = true;
|
||||
|
||||
public ?int $headerId = null;
|
||||
|
||||
public ?int $footerId = null;
|
||||
|
||||
public ?int $coverId = null;
|
||||
/**
|
||||
* 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;
|
||||
@@ -108,16 +107,14 @@ 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 !== '' || $this->headerId !== null || $this->footerId !== null || $this->coverId !== null;
|
||||
return $this->name !== '' || $this->publisher !== '' || $this->copyright !== '' || array_filter($this->bilder) !== [];
|
||||
}
|
||||
|
||||
return $this->name !== $template->name
|
||||
|| $this->publisher !== (string) $template->publisher
|
||||
|| $this->copyright !== (string) $template->copyright
|
||||
|| $this->showCover !== (bool) $template->show_cover
|
||||
|| $this->headerId !== $template->header_version_id
|
||||
|| $this->footerId !== $template->footer_version_id
|
||||
|| $this->coverId !== $template->cover_version_id;
|
||||
|| $this->bilder !== $this->templateSlots($template);
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
@@ -130,9 +127,11 @@ public function save(): void
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (['header' => $this->headerId, 'footer' => $this->footerId, 'cover' => $this->coverId] as $slot => $id) {
|
||||
if ($id !== null && $this->imageProblem($id) !== null) {
|
||||
Notification::make()->danger()->title('Das Bild für '.$this->slotLabel($slot).' lässt sich nicht verwenden.')->body((string) $this->imageProblem($id))->send();
|
||||
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;
|
||||
}
|
||||
@@ -142,9 +141,9 @@ public function save(): void
|
||||
'name' => trim($this->name),
|
||||
'kind' => PdfTemplate::KIND_DOCUMENT,
|
||||
'show_cover' => $this->showCover,
|
||||
'header_version_id' => $this->headerId,
|
||||
'footer_version_id' => $this->footerId,
|
||||
'cover_version_id' => $this->coverId,
|
||||
...PdfTemplate::columns('header', $this->bilder['header']),
|
||||
...PdfTemplate::columns('footer', $this->bilder['footer']),
|
||||
...PdfTemplate::columns('cover', $this->bilder['cover']),
|
||||
'publisher' => trim($this->publisher) === '' ? null : trim($this->publisher),
|
||||
'copyright' => trim($this->copyright) === '' ? null : trim($this->copyright),
|
||||
];
|
||||
@@ -202,12 +201,9 @@ public function openImagePicker(string $slot): void
|
||||
|
||||
public function clearImage(string $slot): void
|
||||
{
|
||||
match ($slot) {
|
||||
'header' => $this->headerId = null,
|
||||
'footer' => $this->footerId = null,
|
||||
'cover' => $this->coverId = null,
|
||||
default => null,
|
||||
};
|
||||
if (in_array($slot, PdfTemplate::SLOTS, true)) {
|
||||
$this->bilder[$slot] = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function pickerAllowsMany(): bool
|
||||
@@ -229,11 +225,11 @@ public function confirmPicker(): void
|
||||
$target = array_key_first($this->pickerMarked);
|
||||
$slot = $this->bildFeld;
|
||||
|
||||
if ($target === null || $slot === null || preg_match('/^element:(\d+)$/', (string) $target, $match) !== 1) {
|
||||
if ($target === null || $slot === null || ! in_array($slot, PdfTemplate::SLOTS, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$problem = $this->imageProblem((int) $match[1]);
|
||||
$problem = TemplateImage::problem((string) $target);
|
||||
|
||||
if ($problem !== null) {
|
||||
Notification::make()->danger()->title('Dieses Bild lässt sich nicht verwenden.')->body($problem)->send();
|
||||
@@ -241,12 +237,7 @@ public function confirmPicker(): void
|
||||
return;
|
||||
}
|
||||
|
||||
match ($slot) {
|
||||
'header' => $this->headerId = (int) $match[1],
|
||||
'footer' => $this->footerId = (int) $match[1],
|
||||
'cover' => $this->coverId = (int) $match[1],
|
||||
default => null,
|
||||
};
|
||||
$this->bilder[$slot] = (string) $target;
|
||||
$this->closePicker();
|
||||
}
|
||||
|
||||
@@ -284,16 +275,14 @@ public function pickerReplacing(): ?array
|
||||
return null;
|
||||
}
|
||||
|
||||
public function imageUrl(?int $versionId): ?string
|
||||
public function imageUrl(?string $target): ?string
|
||||
{
|
||||
return $versionId === null ? null : EmbeddedImages::staffSource($versionId);
|
||||
return TemplateImage::previewUrl($target);
|
||||
}
|
||||
|
||||
public function imageTitle(?int $versionId): string
|
||||
public function imageTitle(?string $target): string
|
||||
{
|
||||
$version = $versionId === null ? null : ContentElementVersion::query()->with('element')->find($versionId);
|
||||
|
||||
return $version?->element === null ? '' : (string) ($version->element->display_title ?: $version->element->working_title);
|
||||
return TemplateImage::title($target);
|
||||
}
|
||||
|
||||
public function slotLabel(string $slot): string
|
||||
@@ -306,21 +295,6 @@ public function slotLabel(string $slot): string
|
||||
};
|
||||
}
|
||||
|
||||
private function imageProblem(int $versionId): ?string
|
||||
{
|
||||
$version = ContentElementVersion::query()->with('element')->find($versionId);
|
||||
|
||||
if (! $version instanceof ContentElementVersion || $version->element === null || $version->element->output_class !== 'bild') {
|
||||
return 'Das ist kein Bild des Medienbestands.';
|
||||
}
|
||||
|
||||
if ($version->status !== ContentVersionStatus::Bereit) {
|
||||
return 'Die Bildfassung ist noch nicht freigegeben.';
|
||||
}
|
||||
|
||||
return EmbeddedImages::file($version) === null ? 'Die Bilddatei liegt nicht vor.' : null;
|
||||
}
|
||||
|
||||
private function loadTemplate(PdfTemplate $template): void
|
||||
{
|
||||
$this->templateId = $template->id;
|
||||
@@ -328,9 +302,15 @@ private function loadTemplate(PdfTemplate $template): void
|
||||
$this->publisher = (string) $template->publisher;
|
||||
$this->copyright = (string) $template->copyright;
|
||||
$this->showCover = (bool) $template->show_cover;
|
||||
$this->headerId = $template->header_version_id;
|
||||
$this->footerId = $template->footer_version_id;
|
||||
$this->coverId = $template->cover_version_id;
|
||||
$this->bilder = $this->templateSlots($template);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
@@ -340,9 +320,7 @@ private function clearForm(): void
|
||||
$this->publisher = '';
|
||||
$this->copyright = '';
|
||||
$this->showCover = true;
|
||||
$this->headerId = null;
|
||||
$this->footerId = null;
|
||||
$this->coverId = null;
|
||||
$this->bilder = ['header' => null, 'footer' => null, 'cover' => null];
|
||||
}
|
||||
|
||||
protected function pickerExceptId(): int
|
||||
|
||||
@@ -106,8 +106,13 @@ public function pickerResult(): array
|
||||
return ['items' => [], 'more' => false];
|
||||
}
|
||||
|
||||
if (in_array($this->pickerPurpose, ['aufbau', 'textbild', 'vorlagenbild'], true)) {
|
||||
$image = in_array($this->pickerPurpose, ['textbild', 'vorlagenbild'], true);
|
||||
// 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(
|
||||
$this->pickerQuery,
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -751,4 +751,4 @@ ## ADR-51 – Dokumente: Kapitel als Texte, Dokumentfassung als Komposition, Tab
|
||||
|
||||
**Quelle.** Auftrag „Dokumente“ von Lars vom 24.11.2026.
|
||||
|
||||
**Nachtrag (24.11.2026): PDF-Vorlagen für Dokumente.** Ein Dokument kann eine PDF-Vorlage verwenden (`pdf_templates`, Zuordnung `compositions.pdf_template_id`, Verwaltung unter Inhalte → PDF-Vorlagen). Die Vorlage ist reines Layout und legt fest: eine Titelseite, auf der der Titel allein steht (mit Untertitel, Ausgabe, Veröffentlichungsdatum, Herausgeber, Copyright-Vermerk und optional einem Titelbild), und eine Kopf- und eine Fußgrafik in voller Seitenbreite auf allen weiteren Seiten. Die Bilder wählt der gemeinsame Picker aus dem Medienbestand (freigegebene Bildfassungen). Untertitel, Ausgabe, Datum und Copyright-Vermerk sind Inhalt und gehören zur Dokumentfassung (`composition_versions.document_meta`, `DocumentMeta`); der Vermerk der Vorlage gilt nur, wenn die Fassung keinen hat. Eine Vorlage wirkt sofort auf jedes PDF der Dokumente, die sie verwenden, auch auf ältere Fassungen: Layout ist nicht Teil der Bindung. Die Angaben ändern den Änderungsnachweis (`structure_hash`) nur, wenn sie gesetzt sind; ältere Fassungen behalten ihren Nachweis. Ohne Vorlage bleibt das bisherige Layout unverändert. Die Kennzeichnung (Lizenzzeile und „Seite n von m“) steht auch auf der Titelseite. Das Muster-PDF einer Vorlage gibt es ohne Dokument. **Grenzen:** nur Helvetica (bewusst, siehe Lizenzfrage von Schriften im Druck), Grafiken als JPEG oder PNG ohne Transparenz, feste Anordnung der Titelseite. **Folgen:** eine additive Migration; der Rückfall zeigt Dokumente im vorherigen Stand nicht (SupportedKindScope) und kennt die Vorlagen nicht. Eine PDF-Bibliothek mit eigenen Schriften bleibt Option B, sobald eine Marke etabliert ist. Die gleiche Vorlagenverwaltung kann später für Übungs-PDFs und Belege genutzt werden; die Rechnung bleibt an OPEN-06 gebunden.
|
||||
**Nachtrag (24.11.2026): PDF-Vorlagen für Dokumente.** Ein Dokument kann eine PDF-Vorlage verwenden (`pdf_templates`, Zuordnung `compositions.pdf_template_id`, Verwaltung unter Inhalte → PDF-Vorlagen). Die Vorlage ist reines Layout und legt fest: eine Titelseite, auf der der Titel allein steht (mit Untertitel, Ausgabe, Veröffentlichungsdatum, Herausgeber, Copyright-Vermerk und optional einem Titelbild), und eine Kopf- und eine Fußgrafik in voller Seitenbreite auf allen weiteren Seiten. Die Bilder wählt der gemeinsame Picker aus dem Medienbestand: jedes Bild mit vorhandener Datei, auch ohne Inhaltsfassung (Präsentationsmedien, für die Website freigegebene Bilder; Spalten `*_element_id`, Klasse `TemplateImage`); gedruckt wird die Website-Datei, sonst die Präsentationsdatei. Gestaltung ist kein lizenzierter Inhalt und braucht keine Freigabe der Fassung; nur ein gesperrtes oder archiviertes Bild wird abgelehnt. Die Bindung an freigegebene Bildfassungen gilt allein für Bilder im Text eines Dokuments. Untertitel, Ausgabe, Datum und Copyright-Vermerk sind Inhalt und gehören zur Dokumentfassung (`composition_versions.document_meta`, `DocumentMeta`); der Vermerk der Vorlage gilt nur, wenn die Fassung keinen hat. Eine Vorlage wirkt sofort auf jedes PDF der Dokumente, die sie verwenden, auch auf ältere Fassungen: Layout ist nicht Teil der Bindung. Die Angaben ändern den Änderungsnachweis (`structure_hash`) nur, wenn sie gesetzt sind; ältere Fassungen behalten ihren Nachweis. Ohne Vorlage bleibt das bisherige Layout unverändert. Die Kennzeichnung (Lizenzzeile und „Seite n von m“) steht auch auf der Titelseite. Das Muster-PDF einer Vorlage gibt es ohne Dokument. **Grenzen:** nur Helvetica (bewusst, siehe Lizenzfrage von Schriften im Druck), Grafiken als JPEG oder PNG ohne Transparenz, feste Anordnung der Titelseite. **Folgen:** eine additive Migration; der Rückfall zeigt Dokumente im vorherigen Stand nicht (SupportedKindScope) und kennt die Vorlagen nicht. Eine PDF-Bibliothek mit eigenen Schriften bleibt Option B, sobald eine Marke etabliert ist. Die gleiche Vorlagenverwaltung kann später für Übungs-PDFs und Belege genutzt werden; die Rechnung bleibt an OPEN-06 gebunden.
|
||||
@@ -16,12 +16,24 @@ ## Geprüft in der Anwendung
|
||||
| Mitglied lädt das PDF (6 Seiten, 4 Lesezeichen) | Seite 1: Titelbild, Titel allein, Untertitel, Ausgabe, Veröffentlichungsdatum, Herausgeber, Vermerk unten, Lizenzzeile; Seite 2: Inhaltsverzeichnis; ab Seite 2 Kopf- und Fußgrafik | `07-pdf-titelseite.png`, `08-pdf-inhaltsverzeichnis.png`, `09-pdf-kapitelseite.png` |
|
||||
| Muster-PDF der Vorlage | PDF ohne Dokument | im Lauf geprüft (HTTP 200, PDF) |
|
||||
|
||||
## Bilder ohne Inhaltsfassung
|
||||
|
||||
Der Picker der Vorlagenseite bietet jedes Bild des Medienmanagers an, auch Bilder ohne Inhaltsfassung (Zeile „Bild · Ohne Inhaltsfassung“). Lokal geprüft: ein für die
|
||||
Website freigegebenes Bild als Kopfgrafik und ein reines Präsentationsbild als Fußgrafik gewählt, Vorlage gespeichert, Vorschau zeigt beide Bilder, im Muster-PDF
|
||||
tragen die Seiten 2 bis 4 je zwei Bilder, die Titelseite keines.
|
||||
|
||||
| Schritt | Beleg |
|
||||
|---|---|
|
||||
| Bildauswahl mit Bildern ohne Inhaltsfassung | `07-bildauswahl-ohne-fassung.png` |
|
||||
| Vorlage mit beiden Bildern ausgefüllt | `08-vorlage-mit-webbildern.png` |
|
||||
| Vorlage gespeichert | `09-webbilder-gespeichert.png` |
|
||||
|
||||
## Automatisierte Prüfungen (`DokumentVorlageTest`, `DokumentAusgabeTest`, `PdfDocumentTest`)
|
||||
|
||||
Titelseite mit allen Angaben und ohne Kapitel; Verzeichnis ab Seite 2 mit stimmenden Seitenzahlen; Titelbild nur auf Seite 1, Kopf und Fuß auf allen
|
||||
weiteren; Lizenzzeile auch auf der Titelseite; ohne Vorlage das bisherige Layout; Titelseite abschaltbar; Standard-Vermerk der Vorlage;
|
||||
Angaben je Fassung und Änderungsnachweis; Editor speichert Angaben im Entwurf und bindet sie mit der Fassung; Vorlagenseite (anlegen, ändern, Bilder
|
||||
über den Picker, nicht freigegebenes Bild abgelehnt, löschen); Löschen gibt Dokumente an das einfache Layout zurück; Redaktionsvorschau nutzt Vorlage und Entwurfsangaben.
|
||||
über den Picker auch ohne Inhaltsfassung (Präsentations- und Website-Bild), Bild im Entwurf wählbar, gesperrtes Bild, fehlende Datei und Nicht-Bild abgelehnt, löschen); Löschen gibt Dokumente an das einfache Layout zurück; Redaktionsvorschau nutzt Vorlage und Entwurfsangaben.
|
||||
|
||||
## Abweichungen und offene Punkte
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 167 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 126 KiB |
@@ -13,9 +13,9 @@
|
||||
];
|
||||
$mehr = $neu ? [] : [['label' => 'Vorlage löschen …', 'wire' => "askConfirmation('delete')", 'hinweis' => 'Dokumente mit dieser Vorlage erzeugen danach wieder das einfache PDF.', 'gefahr' => true]];
|
||||
$felder = [
|
||||
'header' => ['Kopfgrafik', 'Steht oben auf jeder Seite außer der Titelseite, in voller Seitenbreite. Empfohlen: A4-breit (2480 Pixel bei 300 dpi), JPEG oder PNG ohne Transparenz.', $this->headerId],
|
||||
'footer' => ['Fußgrafik', 'Steht unten auf jeder Seite außer der Titelseite, in voller Seitenbreite. Die Lizenzzeile und „Seite n von m“ stehen darüber.', $this->footerId],
|
||||
'cover' => ['Bild der Titelseite', 'Steht oben auf der Titelseite in voller Seitenbreite, höchstens 40 % der Seite hoch. Ohne Bild beginnt die Titelseite mit dem Titel.', $this->coverId],
|
||||
'header' => ['Kopfgrafik', 'Steht oben auf jeder Seite außer der Titelseite, in voller Seitenbreite. Empfohlen: A4-breit (2480 Pixel bei 300 dpi), JPEG oder PNG ohne Transparenz.', $this->bilder['header']],
|
||||
'footer' => ['Fußgrafik', 'Steht unten auf jeder Seite außer der Titelseite, in voller Seitenbreite. Die Lizenzzeile und „Seite n von m“ stehen darüber.', $this->bilder['footer']],
|
||||
'cover' => ['Bild der Titelseite', 'Steht oben auf der Titelseite in voller Seitenbreite, höchstens 40 % der Seite hoch. Ohne Bild beginnt die Titelseite mit dem Titel.', $this->bilder['cover']],
|
||||
];
|
||||
@endphp
|
||||
<x-filament-panels::page>
|
||||
@@ -70,20 +70,20 @@
|
||||
</label>
|
||||
</div>
|
||||
|
||||
@foreach ($felder as $slot => [$label, $hilfe, $id])
|
||||
<div class="vw-karte-box" wire:key="bild-{{ $slot }}">
|
||||
@foreach ($felder as $feld => [$label, $hilfe, $ziel])
|
||||
<div class="vw-karte-box" wire:key="bild-{{ $feld }}">
|
||||
<h3>{{ $label }}</h3>
|
||||
<p class="vw-feld-hilfe">{{ $hilfe }}</p>
|
||||
@if ($id !== null)
|
||||
<div class="vw-vorschaubild" style="height: auto; max-height: 12rem;"><img src="{{ $this->imageUrl($id) }}" alt="{{ $this->imageTitle($id) }}" style="max-height: 12rem; width: auto; max-width: 100%;"></div>
|
||||
<p class="vw-feld-hilfe">{{ $this->imageTitle($id) }}</p>
|
||||
@if ($ziel !== null)
|
||||
<div class="vw-vorschaubild" style="height: auto; max-height: 12rem;"><img src="{{ $this->imageUrl($ziel) }}" alt="{{ $this->imageTitle($ziel) }}" style="max-height: 12rem; width: auto; max-width: 100%;"></div>
|
||||
<p class="vw-feld-hilfe">{{ $this->imageTitle($ziel) }}</p>
|
||||
@else
|
||||
<p class="vw-feld-hilfe">Kein Bild gewählt.</p>
|
||||
@endif
|
||||
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem;">
|
||||
<button type="button" class="vw-btn" wire:click="openImagePicker('{{ $slot }}')">{{ $id === null ? 'Bild aus dem Bestand wählen' : 'Anderes Bild wählen' }}</button>
|
||||
@if ($id !== null)
|
||||
<button type="button" class="vw-link is-quiet" wire:click="clearImage('{{ $slot }}')">Bild entfernen</button>
|
||||
<button type="button" class="vw-btn" wire:click="openImagePicker('{{ $feld }}')">{{ $ziel === null ? 'Bild aus dem Bestand wählen' : 'Anderes Bild wählen' }}</button>
|
||||
@if ($ziel !== null)
|
||||
<button type="button" class="vw-link is-quiet" wire:click="clearImage('{{ $feld }}')">Bild entfernen</button>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DocumentMeta;
|
||||
@@ -35,6 +36,7 @@ protected function setUp(): void
|
||||
parent::setUp();
|
||||
|
||||
Storage::fake('media_derived');
|
||||
Storage::fake('media_public');
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
}
|
||||
|
||||
@@ -154,7 +156,7 @@ public function test_the_editor_saves_the_details_in_the_draft_and_binds_them_wi
|
||||
public function test_the_template_page_creates_changes_and_deletes_templates_with_images_from_the_picker(): void
|
||||
{
|
||||
$header = $this->picture('Kopf', 2480, 300, [20, 80, 60]);
|
||||
$draftImage = app(ContentService::class)->draftElementVersion(app(ContentService::class)->createElement('bild', 'bild', 'Entwurf'), null, ['file' => 'inhalte/entwurf.png']);
|
||||
$draftImage = app(ContentService::class)->draftElementVersion(app(ContentService::class)->createElement('bild', 'bild', 'Entwurf'), null, ['file' => $this->store('inhalte/entwurf.png', 1200, 200, [90, 40, 40])]);
|
||||
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')->test(PdfVorlagen::class)->assertOk();
|
||||
$this->assertSame([], $component->instance()->templates());
|
||||
@@ -164,9 +166,9 @@ public function test_the_template_page_creates_changes_and_deletes_templates_wit
|
||||
$this->assertSame(['bild' => 'Bilder'], $component->instance()->pickerKinds());
|
||||
$this->assertContains('Kopf', array_column($component->instance()->pickerResult()['items'], 'title'));
|
||||
|
||||
// Eine nicht freigegebene Fassung wird abgelehnt.
|
||||
$component->call('markPicker', 'element:'.$draftImage->id, true)->call('confirmPicker')->assertSet('headerId', null);
|
||||
$component->call('markPicker', 'element:'.$header->id, true)->call('confirmPicker')->assertSet('headerId', $header->id)->assertSet('pickerOpen', false);
|
||||
// Gestaltung braucht keine freigegebene Fassung: auch ein Bild im Entwurf lässt sich wählen.
|
||||
$component->call('markPicker', 'element:'.$draftImage->id, true)->call('confirmPicker')->assertSet('bilder.header', 'element:'.$draftImage->id);
|
||||
$component->call('openImagePicker', 'header')->call('markPicker', 'element:'.$header->id, true)->call('confirmPicker')->assertSet('bilder.header', 'element:'.$header->id)->assertSet('pickerOpen', false);
|
||||
$this->assertTrue($component->instance()->changed());
|
||||
$component->call('save');
|
||||
|
||||
@@ -184,6 +186,49 @@ public function test_the_template_page_creates_changes_and_deletes_templates_wit
|
||||
$this->assertSame(0, PdfTemplate::query()->count());
|
||||
}
|
||||
|
||||
public function test_images_without_a_content_version_work_too_presentation_media_and_images_released_for_the_website(): void
|
||||
{
|
||||
$presentation = $this->mediumWithoutVersion('Präsentationsbild', [200, 60, 60], released: false);
|
||||
$web = $this->mediumWithoutVersion('Website-Bild', [60, 60, 200], released: true);
|
||||
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')->test(PdfVorlagen::class)->set('name', 'Ohne Fassungen')->call('openImagePicker', 'header');
|
||||
$titles = array_column($component->instance()->pickerResult()['items'], 'title');
|
||||
|
||||
$this->assertContains('Präsentationsbild', $titles, 'Der Picker bietet Bilder ohne Inhaltsfassung an.');
|
||||
$this->assertContains('Website-Bild', $titles);
|
||||
|
||||
$component->call('markPicker', 'medium:'.$presentation->id, true)->call('confirmPicker')->assertSet('bilder.header', 'medium:'.$presentation->id);
|
||||
$component->call('openImagePicker', 'footer')->call('markPicker', 'medium:'.$web->id, true)->call('confirmPicker')->assertSet('bilder.footer', 'medium:'.$web->id);
|
||||
$component->call('save');
|
||||
|
||||
$template = PdfTemplate::query()->firstOrFail();
|
||||
$this->assertSame([null, $presentation->id, null, $web->id], [$template->header_version_id, $template->header_element_id, $template->footer_version_id, $template->footer_element_id]);
|
||||
$this->assertSame(['medium:'.$presentation->id, 'medium:'.$web->id], [$template->target('header'), $template->target('footer')]);
|
||||
|
||||
// Beide Bilder stehen im PDF.
|
||||
[$article, $release, $member] = $this->sold($template, null);
|
||||
$pdf = $this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->getContent();
|
||||
$this->assertSame(2, substr_count($pdf, '/Subtype /Image'));
|
||||
|
||||
$this->assertNotNull($component->instance()->imageUrl('medium:'.$presentation->id));
|
||||
$this->assertNotNull($component->instance()->imageUrl('medium:'.$web->id));
|
||||
}
|
||||
|
||||
public function test_a_blocked_image_a_missing_file_and_something_that_is_no_image_are_refused(): void
|
||||
{
|
||||
$blocked = $this->picture('Gesperrt', 800, 200);
|
||||
app(ContentService::class)->block($blocked, 'Rechte');
|
||||
$noFile = $this->mediumWithoutVersion('Ohne Datei', [1, 1, 1], released: false, file: false);
|
||||
$film = $this->film('Ein Film');
|
||||
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')->test(PdfVorlagen::class)->call('openImagePicker', 'cover');
|
||||
|
||||
foreach (['element:'.$blocked->id, 'medium:'.$noFile->id, 'element:'.$film->id] as $target) {
|
||||
$component->call('markPicker', $target, true)->call('confirmPicker')->assertSet('bilder.cover', null);
|
||||
$component->call('openImagePicker', 'cover');
|
||||
}
|
||||
}
|
||||
|
||||
public function test_deleting_a_template_returns_its_documents_to_the_simple_layout(): void
|
||||
{
|
||||
$template = $this->template();
|
||||
@@ -208,6 +253,41 @@ public function test_the_staff_preview_of_a_document_uses_its_template_and_the_d
|
||||
$this->assertStringContainsString('Entwurfsausgabe 7', $this->pdfPages($pdf)[0]);
|
||||
}
|
||||
|
||||
/** Legt eine Bilddatei im abgeleiteten Bestand ab und liefert ihren Pfad. */
|
||||
private function store(string $path, int $width, int $height, array $rgb): string
|
||||
{
|
||||
$image = imagecreatetruecolor($width, $height);
|
||||
imagefill($image, 0, 0, (int) imagecolorallocate($image, ...$rgb));
|
||||
ob_start();
|
||||
imagepng($image);
|
||||
Storage::disk('media_derived')->put($path, (string) ob_get_clean());
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein Bild ohne Inhaltsfassung: ein Präsentationsmedium (Datei unter `vorschau/`) oder ein für die Website freigegebenes Bild.
|
||||
*/
|
||||
private function mediumWithoutVersion(string $title, array $rgb, bool $released, bool $file = true): ContentElement
|
||||
{
|
||||
$element = app(ContentService::class)->createElement('bild', 'bild', $title);
|
||||
|
||||
if ($file) {
|
||||
$path = $this->store('vorschau/'.$element->id.'/datei.png', 2480, 240, $rgb);
|
||||
$element->thumbnail_path = $path;
|
||||
|
||||
if ($released) {
|
||||
Storage::disk('media_public')->put('website/'.$element->id.'/datei.png', (string) Storage::disk('media_derived')->get($path));
|
||||
$element->website_public_path = 'website/'.$element->id.'/datei.png';
|
||||
$element->website_released_at = now();
|
||||
}
|
||||
}
|
||||
|
||||
$element->save();
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Eine Vorlage mit Kopf-, Fuß- und Titelbild (drei verschiedene Grafiken).
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user