From 4e66add1f03112e2978c3507c13b9b28c7dda603 Mon Sep 17 00:00:00 2001 From: Lars Stommer Date: Mon, 26 Oct 2026 07:35:17 +0100 Subject: [PATCH] Phase 6, Anwendungsseite: Bildwelten und die Marke je Website MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Die Theme-Sitzung wartete darauf: Seebad ruft schon ortsneutrale Plätze über `partials/motif` auf und behilft sich mit einem eigenen `motifs/`- Ordner. Der Kommentar dort sagt es selbst – „so a later picture-world system can replace the mapping below". Das System gibt es jetzt. **Bildwelten** (A18–A20) sind Pakete wie Themes: `resources/image-worlds/ /` mit `world.json` und `svg/`. Eine Website wählt eine Bildwelt, eine Wohnung darf eine andere tragen – das ist der Platz für die Bergwohnung auf einer Küsten-Website. Vorlagen fragen über `$theme->motif($slot)` nach einem Platz, nie nach einer Datei. Die Render-Logik ist aus Seebads Partial in die Anwendung gewandert, damit jedes Theme sie bekommt: Inline-SVG (nimmt die Textfarbe an, kein zweiter Request), Titel und ARIA entfernt, und die internen Ids je Aufruf eindeutig gemacht – zwei Kopien derselben Grafik auf einer Seite würden sonst auf denselben Verlauf zeigen und eine davon verlöre ihre Farben. Ein leerer Platz ist kein Fehler: die Vorlage bekommt schlicht keine Dekoration. Weil das leicht zu übersehen ist, meldet `php artisan image-worlds:check`, welcher Platz ohne Datei dasteht. **Marke je Website** (A14/A22): Logo, Favicon und ein Logo für E-Mail und Vertrag als Medien der Website. Der Mietvertrag bettet die Datei ein statt eine URL zu holen – er wird auf dem Server gerendert und darf nicht davon abhängen, dass dieser sich selbst erreicht. Ohne Logo bleibt der Vertrag wie bisher. `resources/themes/**` ist unberührt: die Ostsee-Grafiken sind kopiert, nicht verschoben. Was die Theme-Sitzung nun tun kann, steht in ZUSAMMENARBEIT.md §6; ihr Wunsch aus §5 ist als erledigt vermerkt. 272 Feature-Tests grün. Co-Authored-By: Claude Opus 5 --- app/Console/Commands/CheckImageWorlds.php | 71 +++++++++ app/Documents/RentalContract.php | 11 +- .../Properties/Schemas/PropertyForm.php | 6 + .../Resources/Sites/Schemas/SiteForm.php | 29 ++++ app/ImageWorlds/ImageWorldManifest.php | 77 ++++++++++ app/ImageWorlds/ImageWorldRegistry.php | 52 +++++++ app/ImageWorlds/MotifRenderer.php | 65 +++++++++ app/Models/Property.php | 1 + app/Models/Site.php | 59 +++++++- app/Themes/Theme.php | 36 +++++ config/image-worlds.php | 26 ++++ ...dd_image_world_to_sites_and_properties.php | 34 +++++ docs/ZUSAMMENARBEIT.md | 4 +- .../ostsee/svg/band-seebruecke.svg | 20 +++ .../image-worlds/ostsee/svg/band-sonne.svg | 21 +++ resources/image-worlds/ostsee/svg/gaube.svg | 9 ++ .../image-worlds/ostsee/svg/gelaender.svg | 16 +++ .../image-worlds/ostsee/svg/kopfband.svg | 6 + resources/image-worlds/ostsee/svg/moewen.svg | 3 + .../ostsee/svg/vignette-molli.svg | 27 ++++ .../image-worlds/ostsee/svg/vignette-rad.svg | 21 +++ .../ostsee/svg/vignette-seebruecke.svg | 22 +++ .../ostsee/svg/vignette-strand.svg | 15 ++ .../image-worlds/ostsee/svg/vignette-wald.svg | 24 ++++ resources/image-worlds/ostsee/world.json | 17 +++ resources/views/pdf/contract.blade.php | 4 + tests/Feature/ImageWorldTest.php | 136 ++++++++++++++++++ tests/Feature/SiteBrandTest.php | 99 +++++++++++++ 28 files changed, 906 insertions(+), 5 deletions(-) create mode 100644 app/Console/Commands/CheckImageWorlds.php create mode 100644 app/ImageWorlds/ImageWorldManifest.php create mode 100644 app/ImageWorlds/ImageWorldRegistry.php create mode 100644 app/ImageWorlds/MotifRenderer.php create mode 100644 config/image-worlds.php create mode 100644 database/migrations/2026_10_24_175021_add_image_world_to_sites_and_properties.php create mode 100644 resources/image-worlds/ostsee/svg/band-seebruecke.svg create mode 100644 resources/image-worlds/ostsee/svg/band-sonne.svg create mode 100644 resources/image-worlds/ostsee/svg/gaube.svg create mode 100644 resources/image-worlds/ostsee/svg/gelaender.svg create mode 100644 resources/image-worlds/ostsee/svg/kopfband.svg create mode 100644 resources/image-worlds/ostsee/svg/moewen.svg create mode 100644 resources/image-worlds/ostsee/svg/vignette-molli.svg create mode 100644 resources/image-worlds/ostsee/svg/vignette-rad.svg create mode 100644 resources/image-worlds/ostsee/svg/vignette-seebruecke.svg create mode 100644 resources/image-worlds/ostsee/svg/vignette-strand.svg create mode 100644 resources/image-worlds/ostsee/svg/vignette-wald.svg create mode 100644 resources/image-worlds/ostsee/world.json create mode 100644 tests/Feature/ImageWorldTest.php create mode 100644 tests/Feature/SiteBrandTest.php diff --git a/app/Console/Commands/CheckImageWorlds.php b/app/Console/Commands/CheckImageWorlds.php new file mode 100644 index 0000000..d55e949 --- /dev/null +++ b/app/Console/Commands/CheckImageWorlds.php @@ -0,0 +1,71 @@ +all(); + + if ($worlds === []) { + $this->warn('Keine Bildwelt gefunden.'); + + return self::SUCCESS; + } + + $incomplete = 0; + + foreach ($worlds as $world) { + $missing = $world->missingFiles(); + + if ($missing === []) { + $this->info(sprintf('✓ %s (%s): %d Plätze', $world->name, $world->key, count($world->slots))); + + continue; + } + + $incomplete++; + $this->error(sprintf('✗ %s (%s): ohne Datei – %s', $world->name, $world->key, implode(', ', $missing))); + } + + $this->newLine(); + $this->line($this->slotOverview($worlds)); + + return $incomplete === 0 ? self::SUCCESS : self::FAILURE; + } + + /** + * Which slot is filled by which world – so a template author sees what they may rely on. + * + * @param array $worlds + */ + private function slotOverview(array $worlds): string + { + $slots = []; + + foreach ($worlds as $world) { + foreach (array_keys($world->slots) as $slot) { + $slots[$slot][] = $world->key; + } + } + + ksort($slots); + + return collect($slots) + ->map(fn (array $keys, string $slot): string => sprintf(' %-18s %s', $slot, implode(', ', $keys))) + ->implode(PHP_EOL); + } +} diff --git a/app/Documents/RentalContract.php b/app/Documents/RentalContract.php index f4b8d3f..7514f43 100644 --- a/app/Documents/RentalContract.php +++ b/app/Documents/RentalContract.php @@ -3,6 +3,7 @@ namespace App\Documents; use App\Models\Booking; +use App\Models\Site; use Barryvdh\DomPDF\Facade\Pdf; use Illuminate\Support\Facades\Storage; @@ -22,7 +23,15 @@ public function generate(Booking $booking, bool $draft = false): string ? "contracts/Angebot-{$booking->reference}-v{$booking->offer_version}.pdf" : "contracts/Mietvertrag-{$booking->reference}.pdf"; - Storage::disk(self::DISK)->put($path, Pdf::loadView('pdf.contract', ['booking' => $booking, 'draft' => $draft])->setPaper('a4')->output()); + // The logo is embedded as a file: the PDF is rendered on the server and must not depend on + // fetching anything over the network. Each website has its own (A14). + $logo = $booking->website()?->brandPath(Site::BRAND_DOCUMENT_LOGO); + + Storage::disk(self::DISK)->put($path, Pdf::loadView('pdf.contract', [ + 'booking' => $booking, + 'draft' => $draft, + 'logo' => $logo, + ])->setPaper('a4')->output()); $booking->update([$draft ? 'offer_path' : 'contract_path' => $path]); return $path; diff --git a/app/Filament/Resources/Properties/Schemas/PropertyForm.php b/app/Filament/Resources/Properties/Schemas/PropertyForm.php index d1d0ed5..c800395 100644 --- a/app/Filament/Resources/Properties/Schemas/PropertyForm.php +++ b/app/Filament/Resources/Properties/Schemas/PropertyForm.php @@ -3,6 +3,7 @@ namespace App\Filament\Resources\Properties\Schemas; use App\Filament\Forms\Components\EuroInput; +use App\ImageWorlds\ImageWorldRegistry; use App\Models\Site; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; @@ -52,6 +53,11 @@ public static function configure(Schema $schema): Schema ->label('Website') ->options(fn (): array => Site::query()->pluck('name', 'id')->all()) ->placeholder('keine'), + Select::make('image_world') + ->label('Bildwelt') + ->options(fn (): array => app(ImageWorldRegistry::class)->options()) + ->placeholder('wie die Website') + ->helperText('Nur setzen, wenn diese Wohnung anders aussehen soll als die Website – etwa eine Bergwohnung auf einer Küsten-Website.'), Toggle::make('is_active') ->label('Aktiv (auf der Webseite buchbar)') ->default(true), diff --git a/app/Filament/Resources/Sites/Schemas/SiteForm.php b/app/Filament/Resources/Sites/Schemas/SiteForm.php index b56c7e1..3159e7d 100644 --- a/app/Filament/Resources/Sites/Schemas/SiteForm.php +++ b/app/Filament/Resources/Sites/Schemas/SiteForm.php @@ -3,10 +3,12 @@ namespace App\Filament\Resources\Sites\Schemas; use App\Filament\Resources\Appearances\Schemas\AppearanceForm; +use App\ImageWorlds\ImageWorldRegistry; use App\Models\Site; use App\Themes\ThemeRegistry; use Filament\Actions\Action; use Filament\Forms\Components\Select; +use Filament\Forms\Components\SpatieMediaLibraryFileUpload; use Filament\Forms\Components\TagsInput; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; @@ -50,8 +52,35 @@ public static function configure(Schema $schema): Schema ->icon('heroicon-o-eye') ->url(fn (Get $get): string => URL::temporarySignedRoute('home', now()->addDay(), ['theme' => $get('theme') ?: config('themes.base')]), shouldOpenInNewTab: true), ), + Select::make('image_world') + ->label('Bildwelt') + ->options(fn (): array => app(ImageWorldRegistry::class)->options()) + ->placeholder('Vorgabe der Installation') + ->helperText(fn (Get $get): ?string => app(ImageWorldRegistry::class)->get($get('image_world'))?->description + ?: 'Bänder, Vignetten und Ornamente dieser Website. Eine Wohnung kann eine andere Bildwelt tragen.'), Toggle::make('is_default')->label('Standard-Website')->inline(false), ]), + Section::make('Marke') + ->description('Logo, Favicon und das Logo für E-Mails und den Mietvertrag. Gehört dem Vermieter, nicht dem Theme – jede Website hat ihre eigene.') + ->columns(3) + ->collapsible() + ->schema([ + SpatieMediaLibraryFileUpload::make('logo') + ->label('Logo') + ->collection(Site::BRAND_LOGO) + ->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/webp']) + ->helperText('SVG bevorzugt – bleibt in jeder Größe scharf.'), + SpatieMediaLibraryFileUpload::make('favicon') + ->label('Favicon') + ->collection(Site::BRAND_FAVICON) + ->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/x-icon']) + ->helperText('Das kleine Zeichen im Browser-Tab.'), + SpatieMediaLibraryFileUpload::make('document_logo') + ->label('Logo für E-Mail und Vertrag') + ->collection(Site::BRAND_DOCUMENT_LOGO) + ->acceptedFileTypes(['image/png', 'image/jpeg']) + ->helperText('Als PNG oder JPG – E-Mail-Programme und der PDF-Druck zeichnen kein SVG.'), + ]), Section::make('Farben des Themes') ->description('Grundfarben dieser Website; saisonale Erscheinungsbilder können einzelne Farben zusätzlich ändern.') ->columns(3) diff --git a/app/ImageWorlds/ImageWorldManifest.php b/app/ImageWorlds/ImageWorldManifest.php new file mode 100644 index 0000000..e7e08ca --- /dev/null +++ b/app/ImageWorlds/ImageWorldManifest.php @@ -0,0 +1,77 @@ + $slots slot => file name without .svg + */ + public function __construct( + public readonly string $key, + public readonly string $name, + public readonly ?string $description, + public readonly string $path, + public readonly array $slots, + ) {} + + public static function fromFile(string $file): self + { + try { + $data = json_decode((string) file_get_contents($file), true, 512, JSON_THROW_ON_ERROR); + } catch (JsonException $exception) { + throw new RuntimeException('Bildwelt '.$file.' ist kein gültiges JSON: '.$exception->getMessage()); + } + + $path = dirname($file); + $key = basename($path); + + return new self( + key: $key, + name: is_string($data['name'] ?? null) ? $data['name'] : $key, + description: is_string($data['description'] ?? null) ? $data['description'] : null, + path: $path, + slots: array_filter( + is_array($data['slots'] ?? null) ? $data['slots'] : [], + fn (mixed $file, mixed $slot): bool => is_string($slot) && is_string($file), + ARRAY_FILTER_USE_BOTH, + ), + ); + } + + /** + * The file behind a slot, or null when this world does not fill it. A missing slot is not an error: + * a template asks for decoration and simply gets none. + */ + public function fileFor(string $slot): ?string + { + $name = $this->slots[$slot] ?? null; + + if ($name === null) { + return null; + } + + $file = $this->path.DIRECTORY_SEPARATOR.'svg'.DIRECTORY_SEPARATOR.$name.'.svg'; + + return is_file($file) ? $file : null; + } + + /** + * @return list + */ + public function missingFiles(): array + { + return array_values(array_filter( + array_keys($this->slots), + fn (string $slot): bool => $this->fileFor($slot) === null, + )); + } +} diff --git a/app/ImageWorlds/ImageWorldRegistry.php b/app/ImageWorlds/ImageWorldRegistry.php new file mode 100644 index 0000000..42b88f7 --- /dev/null +++ b/app/ImageWorlds/ImageWorldRegistry.php @@ -0,0 +1,52 @@ +|null */ + private ?array $worlds = null; + + /** + * @return array + */ + public function all(): array + { + if ($this->worlds === null) { + $this->worlds = []; + + foreach (config('image-worlds.paths') as $path) { + foreach (glob(rtrim($path, '/\\').'/*/world.json') ?: [] as $file) { + $manifest = ImageWorldManifest::fromFile($file); + $this->worlds[$manifest->key] = $manifest; + } + } + + ksort($this->worlds); + } + + return $this->worlds; + } + + public function get(?string $key): ?ImageWorldManifest + { + if ($key === null || $key === '') { + return null; + } + + return $this->all()[$key] ?? null; + } + + /** + * Key => name, for a select in the admin. + * + * @return array + */ + public function options(): array + { + return array_map(fn (ImageWorldManifest $world): string => $world->name, $this->all()); + } +} diff --git a/app/ImageWorlds/MotifRenderer.php b/app/ImageWorlds/MotifRenderer.php new file mode 100644 index 0000000..77c38f1 --- /dev/null +++ b/app/ImageWorlds/MotifRenderer.php @@ -0,0 +1,65 @@ + */ + private array $cache = []; + + public function render(string $slot, ?string $class = null, ?string $label = null): HtmlString + { + $world = $this->world(); + $file = $world?->fileFor($slot); + + if ($file === null) { + return new HtmlString(''); // a template asks for decoration and gets none + } + + $svg = $this->cache[$file] ??= (string) file_get_contents($file); + + if ($svg === '') { + return new HtmlString(''); + } + + $unique = 'm'.Str::lower(Str::random(6)); + + $svg = (string) preg_replace(['/\s(role|aria-label|aria-hidden)="[^"]*"/', '/.*?<\/title>/s'], '', $svg); + $svg = (string) preg_replace(['/id="([^"]+)"/', '/url\(#([^)]+)\)/'], ['id="$1-'.$unique.'"', 'url(#$1-'.$unique.')'], $svg); + + $attributes = 'class="'.e((string) $class).'" '.($label !== null + ? 'role="img" aria-label="'.e($label).'"' + : 'aria-hidden="true" focusable="false"'); + + return new HtmlString((string) preg_replace('/<svg\s/', '<svg '.$attributes.' ', $svg, 1)); + } + + public function has(string $slot): bool + { + return $this->world()?->fileFor($slot) !== null; + } + + /** + * The picture world in force for what is being rendered right now. + */ + public function world(): ?ImageWorldManifest + { + $registry = app(ImageWorldRegistry::class); + $theme = app()->bound(Theme::class) ? app(Theme::class) : null; + + return $registry->get($theme?->property()?->image_world) + ?? $registry->get($theme?->site->image_world) + ?? $registry->get(config('image-worlds.default')); + } +} diff --git a/app/Models/Property.php b/app/Models/Property.php index 0b66ca8..b349622 100644 --- a/app/Models/Property.php +++ b/app/Models/Property.php @@ -19,6 +19,7 @@ 'site_id', 'name', 'slug', + 'image_world', 'address', 'size_sqm', 'max_guests', diff --git a/app/Models/Site.php b/app/Models/Site.php index 64eb558..a31390a 100644 --- a/app/Models/Site.php +++ b/app/Models/Site.php @@ -12,16 +12,18 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Facades\URL; +use Spatie\MediaLibrary\HasMedia; +use Spatie\MediaLibrary\InteractsWithMedia; /** * A website: domain, theme with its settings, pages and appearances, and the properties it shows. * Today there is one site; more sites allow other landlords to use the system under their own domain. */ -#[Fillable(['name', 'domain', 'is_default', 'theme', 'theme_settings', 'locale'])] -class Site extends Model +#[Fillable(['name', 'domain', 'is_default', 'theme', 'image_world', 'theme_settings', 'locale'])] +class Site extends Model implements HasMedia { /** @use HasFactory<SiteFactory> */ - use BelongsToTenant, HasFactory; + use BelongsToTenant, HasFactory, InteractsWithMedia; protected static function booted(): void { @@ -83,6 +85,57 @@ public function signedRoute(string $name, mixed $parameters = []): string /** * Keep the single domain field and the host table on the same hostname. */ + /** + * The brand of this website: the graphics that identify the landlord, not the decoration of the theme. + * Kept per website so a second landlord never inherits the first one's logo in their contract (A14/A22). + */ + public const BRAND_LOGO = 'logo'; + + public const BRAND_FAVICON = 'favicon'; + + public const BRAND_DOCUMENT_LOGO = 'document_logo'; + + public function registerMediaCollections(): void + { + // The brand is shown on the public website and in mails, so it lives on the public disk. + $this->addMediaCollection(self::BRAND_LOGO) + ->useDisk('public') + ->singleFile() + ->acceptsMimeTypes(['image/svg+xml', 'image/png', 'image/webp']); + + $this->addMediaCollection(self::BRAND_FAVICON) + ->useDisk('public') + ->singleFile() + ->acceptsMimeTypes(['image/svg+xml', 'image/png', 'image/x-icon']); + + // Mail clients and the PDF renderer do not draw SVG, so this one is a pixel image. + $this->addMediaCollection(self::BRAND_DOCUMENT_LOGO) + ->useDisk('public') + ->singleFile() + ->acceptsMimeTypes(['image/png', 'image/jpeg']); + } + + /** + * The URL of a brand graphic, or null when this website has none. + */ + public function brandUrl(string $collection): ?string + { + $media = $this->getFirstMedia($collection); + + return $media?->getUrl() ?: null; + } + + /** + * The absolute path of a brand graphic – mails and the contract PDF embed the file, they cannot fetch + * a URL from a server that may not be reachable from where the PDF is rendered. + */ + public function brandPath(string $collection): ?string + { + $path = $this->getFirstMedia($collection)?->getPath(); + + return is_string($path) && is_file($path) ? $path : null; + } + public function syncDomainHost(): void { if (! $this->wasRecentlyCreated && ! $this->wasChanged('domain')) { diff --git a/app/Themes/Theme.php b/app/Themes/Theme.php index 74ce1f6..1d1cabd 100644 --- a/app/Themes/Theme.php +++ b/app/Themes/Theme.php @@ -2,6 +2,8 @@ namespace App\Themes; +use App\ImageWorlds\ImageWorldManifest; +use App\ImageWorlds\MotifRenderer; use App\Models\Appearance; use App\Models\Page; use App\Models\Photo; @@ -9,6 +11,7 @@ use App\Models\Site; use Illuminate\Support\Collection; use Illuminate\Support\Facades\View; +use Illuminate\Support\HtmlString; /** * The theme context of the current request: site, theme chain and appearance. Activating it registers the @@ -128,6 +131,39 @@ public function appearanceKey(): string return $this->appearance ? str($this->appearance->name)->slug()->toString() : 'standard'; } + /** + * A brand graphic of this website (logo, favicon, document logo), or null when none was uploaded. + * The brand belongs to the landlord; the picture world belongs to the look. Templates that fall back + * to their own graphic should ask for this first (A14/A22). + */ + public function brand(string $collection): ?string + { + return $this->site->exists ? $this->site->brandUrl($collection) : null; + } + + /** + * The graphic behind a picture-world slot (divider, closing, vignette.beach …). Templates ask for a + * slot, never for a file, so the same template works in every picture world (A18/A19). + */ + public function motif(string $slot, ?string $class = null, ?string $label = null): HtmlString + { + return app(MotifRenderer::class)->render($slot, $class, $label); + } + + /** + * Whether the current picture world fills this slot – for templates that want to leave out a whole + * decorative block instead of rendering an empty one. + */ + public function hasMotif(string $slot): bool + { + return app(MotifRenderer::class)->has($slot); + } + + public function imageWorld(): ?ImageWorldManifest + { + return app(MotifRenderer::class)->world(); + } + public function property(): ?Property { if (! $this->propertyResolved) { diff --git a/config/image-worlds.php b/config/image-worlds.php new file mode 100644 index 0000000..0a5732a --- /dev/null +++ b/config/image-worlds.php @@ -0,0 +1,26 @@ +<?php + +return [ + + /* + |-------------------------------------------------------------------------- + | Picture worlds ("Bildwelten") + |-------------------------------------------------------------------------- + | + | Every folder below one of these paths that contains a world.json is a + | picture world: the bands, vignettes and ornaments a website is dressed + | in. Themes ask for a slot, never for a file (MANDANTEN-ANFORDERUNGEN + | A18/A19), so the same theme can wear "Ostsee" or later "Berge". + | + */ + + 'paths' => [ + resource_path('image-worlds'), + ], + + /* + | Applies while a website has chosen none. Empty = no decoration at all. + */ + 'default' => env('FEWO_IMAGE_WORLD', 'ostsee'), + +]; diff --git a/database/migrations/2026_10_24_175021_add_image_world_to_sites_and_properties.php b/database/migrations/2026_10_24_175021_add_image_world_to_sites_and_properties.php new file mode 100644 index 0000000..b80b91b --- /dev/null +++ b/database/migrations/2026_10_24_175021_add_image_world_to_sites_and_properties.php @@ -0,0 +1,34 @@ +<?php + +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +return new class extends Migration +{ + /** + * A website is dressed in a picture world; an apartment may wear a different one (A18/A20) – that is + * the place for a mountain apartment on a coastal website. Empty means: the one above decides. + */ + public function up(): void + { + Schema::table('sites', function (Blueprint $table) { + $table->string('image_world')->nullable()->after('theme'); + }); + + Schema::table('properties', function (Blueprint $table) { + $table->string('image_world')->nullable(); + }); + } + + public function down(): void + { + Schema::table('properties', function (Blueprint $table) { + $table->dropColumn('image_world'); + }); + + Schema::table('sites', function (Blueprint $table) { + $table->dropColumn('image_world'); + }); + } +}; diff --git a/docs/ZUSAMMENARBEIT.md b/docs/ZUSAMMENARBEIT.md index 6ef645b..5c1d922 100644 --- a/docs/ZUSAMMENARBEIT.md +++ b/docs/ZUSAMMENARBEIT.md @@ -74,7 +74,7 @@ ## 5. Wünsche der Design-Session an die Anwendung | 23.10.2026 | **Darstellungsvarianten je Baustein** (`theme.json › variants`), Feld „Darstellung“ im Seiten-Baukasten (DESIGN-KONZEPT §7 Nr. 2) | offen | | 23.10.2026 | **Baustein „Tipps der Gastgeberin“**: Orte mit Kategorie (Strand, Seebrücke, Bahn, Rad, Wald …), Weg/Gehzeit, Text, Foto, Karten-Link; saisonal filterbar. Seebad zeigt je Kategorie eine Vignette der Bildwelt (DESIGN-KONZEPT §7 Nr. 4) | offen | | 23.10.2026 | **Baustein „Gut zu wissen“**: strukturierte Angaben (Zugang/Stufen, Dusche, Rollstuhl, Haustiere, An-/Abreisezeiten, Parken) an der Wohnung; Seebad stellt ihn in der Kartusche dar (DESIGN-KONZEPT §7 Nr. 5) | offen | -| 23.10.2026 | **Bildwelt-System** (MANDANTEN-ANFORDERUNGEN A18–A20): Seebad nutzt schon Plätze über `partials/motif` (`mark`, `divider`, `closing`, `crest`, `gulls`, `vignette.*`) | offen | +| 23.10.2026 | **Bildwelt-System** (MANDANTEN-ANFORDERUNGEN A18–A20): Seebad nutzt schon Plätze über `partials/motif` (`mark`, `divider`, `closing`, `crest`, `gulls`, `vignette.*`) | **erledigt in `6a1d0`** – Anwendungsseite steht, siehe §6 | | 23.10.2026 | Hilfetext „*Wort* wird hervorgehoben“ im Titelbereich ist theme-abhängig (Seebad hebt nicht hervor) – Hinweis neutral formulieren | offen | | 23.10.2026 | **Menübild je Seite** (Feld an der Seite, Auswahl aus den Fotos, `PhotoSelect`) und optional ein kurzer **Menütext** – Seebad zeigt beides in den Menü-Tafeln; heute nur SEO-Beschreibung und Sprunglinks | offen | @@ -89,4 +89,6 @@ ## 6. Änderungsprotokoll Vorlagen-Vertrag | 22.10.2026 | `hero`: `$featuredOffer` (wichtigstes hervorgehobenes Angebot oder null) | sections/hero | | 22.10.2026 | `offers`: `$display` (grid/list/rotating), `$offers` = `AdvertisedOffer` (Termin, Preis, `bookingUrl()`); rollierend über `data-rotator*` | sections/offers | | 23.10.2026 | **Neuer Baustein `floor_plan`** (Grundriss interaktiv): Vertrag in THEMES.md §5; Basis-Vorlage `ostsee-licht/views/sections/floor_plan.blade.php` (ohne JS: Flächen springen zur Raumliste), Seebad interaktiv (`theme.js` `initFloorPlans`). Neue Themes brauchen keine eigene Vorlage (Vererbung) | sections/floor_plan | +| 24.10.2026 | **Bildwelt-System steht (Anwendungsseite).** `$theme->motif($slot, $class, $label)` liefert das Inline-SVG des Platzes, `$theme->hasMotif($slot)` sagt, ob der Platz gefüllt ist, `$theme->imageWorld()` nennt die aktive Bildwelt. Bildwelten liegen in `resources/image-worlds/<key>/` (`world.json` + `svg/`), Auswahl an der Website, Überschreibung an der Wohnung. Die Ostsee-Grafiken sind als Bildwelt `ostsee` **kopiert** – `resources/themes/seebad/motifs/` ist unverändert. **Seebad kann jetzt** sein `partials/motif.blade.php` auf `{!! $theme->motif($slot, $class ?? null, $label ?? null) !!}` verkürzen und seinen `motifs/`-Ordner löschen. `php artisan image-worlds:check` zeigt, welcher Platz von welcher Bildwelt gefüllt wird. | sections/*, partials/motif | +| 24.10.2026 | **Marke je Website** (A14/A22): `$theme->brand('logo'|'favicon'|'document_logo')` liefert die URL oder null. Gepflegt unter Webseite › Website › Marke. **Noch offen und ein Fall für euch:** `ostsee-licht/views/layouts/app.blade.php` holt das Favicon aus `public/brand/`, Seebad aus seinen eigenen Assets – beide sollten zuerst `$theme->brand('favicon')` fragen und nur sonst auf ihre eigene Datei zurückfallen. Dasselbe gilt für `ostsee-licht/views/partials/brand.blade.php`, das noch fest verdrahtete Ostsee-Grafiken zeigt (A19). | layouts/app, partials/brand | | 22.10.2026 | Seiten außerhalb der Bausteine, die das Theme-Layout nutzen: Angebotsseite `resources/views/offer.blade.php`, Bewertung `resources/views/review.blade.php` – beim Theme-Test mitprüfen | layouts/app | diff --git a/resources/image-worlds/ostsee/svg/band-seebruecke.svg b/resources/image-worlds/ostsee/svg/band-seebruecke.svg new file mode 100644 index 0000000..8877ba9 --- /dev/null +++ b/resources/image-worlds/ostsee/svg/band-seebruecke.svg @@ -0,0 +1,20 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1600 150" preserveAspectRatio="xMidYMid meet" role="presentation" aria-hidden="true"> + <defs><clipPath id="band-pier-horizon"><rect x="1160" y="20" width="140" height="78"/></clipPath></defs> + <circle cx="1230" cy="98" r="50" fill="var(--brand-sun, #F2C27A)" clip-path="url(#band-pier-horizon)"/> + <g fill="var(--brand-navy, #0B2E55)"> + <rect x="1100" y="92" width="380" height="6" rx="1"/> + <rect x="1100" y="80" width="300" height="2.5"/> + <path d="M1108 80 V92 M1126 80 V92 M1144 80 V92 M1162 80 V92 M1180 80 V92 M1198 80 V92 M1216 80 V92 M1234 80 V92 M1252 80 V92 M1270 80 V92 M1288 80 V92 M1306 80 V92 M1324 80 V92 M1342 80 V92 M1360 80 V92 M1378 80 V92" stroke="var(--brand-navy, #0B2E55)" stroke-width="2"/> + <path d="M1112 98 H1117 V112 H1112 Z M1150 98 H1155 V112 H1150 Z M1188 98 H1193 V112 H1188 Z M1226 98 H1231 V112 H1226 Z M1264 98 H1269 V112 H1264 Z M1302 98 H1307 V112 H1302 Z M1340 98 H1345 V112 H1340 Z M1378 98 H1383 V112 H1378 Z M1416 98 H1421 V112 H1416 Z M1454 98 H1459 V112 H1454 Z"/> + <rect x="1410" y="72" width="44" height="20"/> + <path d="M1404 74 L1432 50 L1460 74 Z"/> + <path d="M1430 50 L1432 34 L1434 50 Z"/> + <rect x="1160" y="56" width="2" height="24"/> + <path d="M1162 56 L1174 60 L1162 64 Z"/> + <rect x="1380" y="60" width="2" height="20"/> + <path d="M1382 60 L1392 64 L1382 68 Z"/> + </g> + <path fill="none" stroke="var(--brand-navy, #0B2E55)" stroke-width="3" stroke-linecap="round" d="M1060 44 Q1068 36 1076 44 Q1084 34 1094 40 M1020 64 Q1025 59 1030 64 Q1035 58 1041 61"/> + <path fill="var(--brand-teal, #0286A2)" d="M10 104 C200 70 400 68 600 90 C800 112 1000 112 1200 106 C1350 102 1480 96 1590 80 C1440 130 1260 126 1100 120 C900 114 760 120 600 108 C400 88 200 92 10 104 Z"/> + <path fill="var(--brand-wave, #6DBFC2)" d="M60 122 C240 102 420 104 600 120 C800 136 1000 130 1200 124 C1340 120 1460 116 1540 110 C1400 142 1220 142 1060 136 C900 132 760 136 600 130 C420 118 240 116 60 122 Z"/> +</svg> diff --git a/resources/image-worlds/ostsee/svg/band-sonne.svg b/resources/image-worlds/ostsee/svg/band-sonne.svg new file mode 100644 index 0000000..0d404ba --- /dev/null +++ b/resources/image-worlds/ostsee/svg/band-sonne.svg @@ -0,0 +1,21 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1600 150" preserveAspectRatio="xMidYMid meet" role="presentation" aria-hidden="true"> + <defs><clipPath id="band-sonne-horizon"><rect x="740" y="20" width="120" height="78"/></clipPath></defs> + <circle cx="800" cy="98" r="44" fill="var(--brand-sun, #F2C27A)" clip-path="url(#band-sonne-horizon)"/> + <path fill="var(--brand-sun, #F2C27A)" d="M760 104 H840 A3 3 0 0 1 840 110 H760 A3 3 0 0 1 760 104 Z M776 118 H824 A3 3 0 0 1 824 124 H776 A3 3 0 0 1 776 118 Z"/> + <g fill="var(--brand-reed, #C9A15E)" transform="translate(744 100) scale(-1 1)"> + <path d="M0 0 C-4 -20 -14 -38 -30 -50 C-18 -34 -10 -18 -4 0 Z"/> + <path d="M2 0 C2 -22 -2 -42 -12 -62 C-4 -40 -2 -20 -2 0 Z"/> + <path d="M4 0 C8 -18 16 -34 28 -46 C18 -30 10 -16 8 0 Z"/> + <path d="M6 0 C14 -12 24 -22 36 -26 C26 -18 16 -8 10 0 Z"/> + <path d="M-2 0 C-10 -10 -22 -18 -36 -20 C-22 -14 -12 -6 -6 0 Z"/> + </g> + <g fill="var(--brand-reed, #C9A15E)" transform="translate(856 100)"> + <path d="M0 0 C-4 -20 -14 -38 -30 -50 C-18 -34 -10 -18 -4 0 Z"/> + <path d="M2 0 C2 -22 -2 -42 -12 -62 C-4 -40 -2 -20 -2 0 Z"/> + <path d="M4 0 C8 -18 16 -34 28 -46 C18 -30 10 -16 8 0 Z"/> + <path d="M6 0 C14 -12 24 -22 36 -26 C26 -18 16 -8 10 0 Z"/> + <path d="M-2 0 C-10 -10 -22 -18 -36 -20 C-22 -14 -12 -6 -6 0 Z"/> + </g> + <path fill="var(--brand-teal, #0286A2)" d="M10 104 C200 66 400 64 600 88 C690 98 750 104 800 100 C850 96 910 88 1000 88 C1200 88 1400 112 1590 74 C1420 128 1220 120 1000 108 C910 104 850 112 800 114 C750 116 690 114 600 106 C400 84 200 88 10 104 Z"/> + <path fill="var(--brand-wave, #6DBFC2)" d="M60 122 C240 100 420 102 600 118 C690 126 750 128 800 126 C850 124 910 116 1000 116 C1180 116 1360 134 1540 110 C1380 142 1200 140 1000 130 C910 126 850 134 800 136 C750 138 690 136 600 130 C420 116 240 114 60 122 Z"/> +</svg> diff --git a/resources/image-worlds/ostsee/svg/gaube.svg b/resources/image-worlds/ostsee/svg/gaube.svg new file mode 100644 index 0000000..db2bcc6 --- /dev/null +++ b/resources/image-worlds/ostsee/svg/gaube.svg @@ -0,0 +1,9 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 66" role="img" aria-label="Rundbogengaube"> + <title>Rundbogengaube + + + + + + + diff --git a/resources/image-worlds/ostsee/svg/gelaender.svg b/resources/image-worlds/ostsee/svg/gelaender.svg new file mode 100644 index 0000000..6fae450 --- /dev/null +++ b/resources/image-worlds/ostsee/svg/gelaender.svg @@ -0,0 +1,16 @@ + diff --git a/resources/image-worlds/ostsee/svg/kopfband.svg b/resources/image-worlds/ostsee/svg/kopfband.svg new file mode 100644 index 0000000..af3ea85 --- /dev/null +++ b/resources/image-worlds/ostsee/svg/kopfband.svg @@ -0,0 +1,6 @@ + diff --git a/resources/image-worlds/ostsee/svg/moewen.svg b/resources/image-worlds/ostsee/svg/moewen.svg new file mode 100644 index 0000000..36df78a --- /dev/null +++ b/resources/image-worlds/ostsee/svg/moewen.svg @@ -0,0 +1,3 @@ + diff --git a/resources/image-worlds/ostsee/svg/vignette-molli.svg b/resources/image-worlds/ostsee/svg/vignette-molli.svg new file mode 100644 index 0000000..620d432 --- /dev/null +++ b/resources/image-worlds/ostsee/svg/vignette-molli.svg @@ -0,0 +1,27 @@ + + Bäderbahn Molli + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/image-worlds/ostsee/svg/vignette-rad.svg b/resources/image-worlds/ostsee/svg/vignette-rad.svg new file mode 100644 index 0000000..549122a --- /dev/null +++ b/resources/image-worlds/ostsee/svg/vignette-rad.svg @@ -0,0 +1,21 @@ + + Mit dem Rad an der Küste + + + + + + + + + + + + + + + + + + + diff --git a/resources/image-worlds/ostsee/svg/vignette-seebruecke.svg b/resources/image-worlds/ostsee/svg/vignette-seebruecke.svg new file mode 100644 index 0000000..bb47307 --- /dev/null +++ b/resources/image-worlds/ostsee/svg/vignette-seebruecke.svg @@ -0,0 +1,22 @@ + + Seebrücke + + + + + + + + + + + + + + + + + + + + diff --git a/resources/image-worlds/ostsee/svg/vignette-strand.svg b/resources/image-worlds/ostsee/svg/vignette-strand.svg new file mode 100644 index 0000000..bf25fca --- /dev/null +++ b/resources/image-worlds/ostsee/svg/vignette-strand.svg @@ -0,0 +1,15 @@ + + Strand mit Sonne + + + + + + + + + + + + + diff --git a/resources/image-worlds/ostsee/svg/vignette-wald.svg b/resources/image-worlds/ostsee/svg/vignette-wald.svg new file mode 100644 index 0000000..5618f3c --- /dev/null +++ b/resources/image-worlds/ostsee/svg/vignette-wald.svg @@ -0,0 +1,24 @@ + + Küstenwald + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/image-worlds/ostsee/world.json b/resources/image-worlds/ostsee/world.json new file mode 100644 index 0000000..6729300 --- /dev/null +++ b/resources/image-worlds/ostsee/world.json @@ -0,0 +1,17 @@ +{ + "name": "Ostsee", + "description": "Bänder, Vignetten und Ornamente der Ostseeküste: Sonne, Seebrücke, Möwen, Molli.", + "slots": { + "divider": "band-sonne", + "closing": "band-seebruecke", + "crest": "gaube", + "railing": "gelaender", + "bracket": "kopfband", + "gulls": "moewen", + "vignette.beach": "vignette-strand", + "vignette.pier": "vignette-seebruecke", + "vignette.train": "vignette-molli", + "vignette.bike": "vignette-rad", + "vignette.forest": "vignette-wald" + } +} diff --git a/resources/views/pdf/contract.blade.php b/resources/views/pdf/contract.blade.php index 6be8106..66c9404 100644 --- a/resources/views/pdf/contract.blade.php +++ b/resources/views/pdf/contract.blade.php @@ -25,6 +25,10 @@ + @if ($logo ?? null) + + @endif + @if ($draft ?? false)

Angebot und Mietvertrag (Entwurf)

Angebot {{ $booking->reference }} · Version {{ $booking->offer_version }} · erstellt am {{ ($booking->offer_sent_at ?? now())->format('d.m.Y') }} · gültig bis {{ $booking->hold_expires_at?->format('d.m.Y, H:i') }} Uhr

diff --git a/tests/Feature/ImageWorldTest.php b/tests/Feature/ImageWorldTest.php new file mode 100644 index 0000000..c00fa12 --- /dev/null +++ b/tests/Feature/ImageWorldTest.php @@ -0,0 +1,136 @@ +extra = resource_path('image-worlds/berge'); + File::ensureDirectoryExists($this->extra.'/svg'); + File::put($this->extra.'/world.json', json_encode([ + 'name' => 'Berge', + 'description' => 'Gipfel statt Wellen.', + 'slots' => ['divider' => 'grat', 'crest' => 'gipfel'], + ])); + File::put($this->extra.'/svg/grat.svg', 'Grat'); + + app()->forgetInstance(ImageWorldRegistry::class); + } + + protected function tearDown(): void + { + File::deleteDirectory($this->extra); + + parent::tearDown(); + } + + public function test_the_registry_finds_every_world_and_reports_slots_without_a_file(): void + { + $registry = app(ImageWorldRegistry::class); + + $this->assertArrayHasKey('ostsee', $registry->all()); + $this->assertArrayHasKey('berge', $registry->all()); + $this->assertSame('Berge', $registry->options()['berge']); + + $this->assertSame([], $registry->get('ostsee')->missingFiles()); + $this->assertSame(['crest'], $registry->get('berge')->missingFiles(), 'gipfel.svg fehlt und muss auffallen.'); + $this->assertNull($registry->get('gibtsnicht')); + } + + public function test_a_slot_without_a_file_renders_nothing_instead_of_breaking(): void + { + $this->useWorld('berge'); + + $this->assertSame('', (string) app(MotifRenderer::class)->render('crest')); + $this->assertFalse(app(MotifRenderer::class)->has('crest')); + $this->assertTrue(app(MotifRenderer::class)->has('divider')); + } + + public function test_the_apartment_overrules_the_website(): void + { + $this->useWorld('ostsee'); + $this->assertSame('ostsee', app(MotifRenderer::class)->world()?->key); + + $this->useWorld('ostsee', apartmentWorld: 'berge'); + $this->assertSame('berge', app(MotifRenderer::class)->world()?->key, 'Die Bergwohnung trägt ihre eigene Bildwelt.'); + } + + public function test_without_any_choice_the_installation_decides(): void + { + config(['image-worlds.default' => 'berge']); + $this->useWorld(null); + + $this->assertSame('berge', app(MotifRenderer::class)->world()?->key); + } + + public function test_the_rendered_graphic_is_decorative_unless_it_is_given_a_label(): void + { + $this->useWorld('berge'); + + $plain = (string) app(MotifRenderer::class)->render('divider', 'h-8 text-accent'); + + $this->assertStringContainsString('aria-hidden="true"', $plain); + $this->assertStringContainsString('class="h-8 text-accent"', $plain); + $this->assertStringNotContainsString('', $plain, 'Der Titel würde sonst doppelt vorgelesen.'); + + $labelled = (string) app(MotifRenderer::class)->render('divider', null, 'Bergkamm'); + + $this->assertStringContainsString('role="img"', $labelled); + $this->assertStringContainsString('aria-label="Bergkamm"', $labelled); + } + + /** + * Two copies of one graphic on a page must not share their internal ids – the second would otherwise + * point at the first one's gradient and lose its colours. + */ + public function test_the_internal_ids_are_unique_per_rendering(): void + { + $this->useWorld('berge'); + + $first = (string) app(MotifRenderer::class)->render('divider'); + $second = (string) app(MotifRenderer::class)->render('divider'); + + $this->assertNotSame($first, $second); + $this->assertMatchesRegularExpression('/id="line-m\w{6}"/', $first); + $this->assertStringContainsString('url(#verlauf-m', $first); + } + + private function useWorld(?string $key, ?string $apartmentWorld = null): Theme + { + $tenant = Tenant::factory()->create(); + + return app(TenantContext::class)->run($tenant, function () use ($key, $apartmentWorld): Theme { + $site = Site::factory()->create(['image_world' => $key, 'is_default' => true]); + Property::factory()->create(['site_id' => $site->id, 'image_world' => $apartmentWorld]); + + $theme = app(ThemeFactory::class)->forSite($site); + app()->instance(Theme::class, $theme); + + return $theme; + }); + } +} diff --git a/tests/Feature/SiteBrandTest.php b/tests/Feature/SiteBrandTest.php new file mode 100644 index 0000000..e4a5c02 --- /dev/null +++ b/tests/Feature/SiteBrandTest.php @@ -0,0 +1,99 @@ +<?php + +namespace Tests\Feature; + +use App\Documents\RentalContract; +use App\Models\Booking; +use App\Models\Property; +use App\Models\Site; +use App\Models\Tenant; +use App\Tenancy\TenantContext; +use App\Themes\Theme; +use App\Themes\ThemeFactory; +use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Http\UploadedFile; +use Illuminate\Support\Facades\Storage; +use Tests\TestCase; + +/** + * The brand (A14/A22): logo, favicon and the logo for mail and contract belong to the website, not to the + * installation. Without this, a second landlord would carry the first one's logo in their rental contract. + */ +class SiteBrandTest extends TestCase +{ + use RefreshDatabase; + + public function test_each_website_carries_its_own_brand(): void + { + Storage::fake('public'); + + $first = $this->website('Nordhaus'); + $second = $this->website('Südheim'); + + $first->addMedia(UploadedFile::fake()->image('nord.png'))->toMediaCollection(Site::BRAND_LOGO); + + $this->assertNotNull($first->fresh()->brandUrl(Site::BRAND_LOGO)); + $this->assertNull($second->fresh()->brandUrl(Site::BRAND_LOGO), 'Ohne eigenes Logo erbt niemand ein fremdes.'); + $this->assertNull($first->fresh()->brandUrl(Site::BRAND_FAVICON)); + } + + public function test_the_contract_shows_the_logo_of_its_own_website(): void + { + Storage::fake('public'); + Storage::fake('local'); + + $site = $this->website('Nordhaus'); + $site->addMedia(UploadedFile::fake()->image('vertrag.png', 300, 100))->toMediaCollection(Site::BRAND_DOCUMENT_LOGO); + + $booking = app(TenantContext::class)->run($site->tenant, fn (): Booking => Booking::factory() + ->for(Property::factory()->create(['site_id' => $site->id])) + ->create()); + + $path = app(TenantContext::class)->run($site->tenant, fn (): string => app(RentalContract::class)->generate($booking, draft: true)); + + Storage::disk('local')->assertExists($path); + $this->assertGreaterThan(1000, strlen(Storage::disk('local')->get($path))); + } + + public function test_a_website_without_a_document_logo_still_renders_its_contract(): void + { + Storage::fake('public'); + Storage::fake('local'); + + $site = $this->website('Ohne Marke'); + + $booking = app(TenantContext::class)->run($site->tenant, fn (): Booking => Booking::factory() + ->for(Property::factory()->create(['site_id' => $site->id])) + ->create()); + + $path = app(TenantContext::class)->run($site->tenant, fn (): string => app(RentalContract::class)->generate($booking, draft: false)); + + Storage::disk('local')->assertExists($path); + } + + public function test_the_theme_hands_the_brand_to_the_templates(): void + { + Storage::fake('public'); + + $site = $this->website('Nordhaus'); + $site->addMedia(UploadedFile::fake()->image('logo.png'))->toMediaCollection(Site::BRAND_LOGO); + + $theme = app(TenantContext::class)->run( + $site->tenant, + fn (): Theme => app(ThemeFactory::class)->forSite($site->fresh()), + ); + + $this->assertStringContainsString('logo', (string) $theme->brand(Site::BRAND_LOGO)); + $this->assertNull($theme->brand(Site::BRAND_FAVICON)); + } + + private function website(string $name): Site + { + $tenant = Tenant::factory()->create(['name' => $name]); + + return app(TenantContext::class)->run($tenant, fn (): Site => Site::factory()->create([ + 'name' => $name, + 'is_default' => false, + ])); + } +}