diff --git a/app/Enums/PhotoCategory.php b/app/Enums/PhotoCategory.php index aaf0f17..3cf8df2 100644 --- a/app/Enums/PhotoCategory.php +++ b/app/Enums/PhotoCategory.php @@ -9,6 +9,8 @@ enum PhotoCategory: string implements HasLabel case Apartment = 'apartment'; case Outdoor = 'outdoor'; case Area = 'area'; + /** Floor plans and drawings: chosen explicitly (e.g. for the interactive floor plan), never shown in galleries. */ + case Plan = 'plan'; public function getLabel(): string { @@ -16,6 +18,17 @@ public function getLabel(): string self::Apartment => 'Wohnung', self::Outdoor => 'Terrasse & Garten', self::Area => 'Kühlungsborn & Umgebung', + self::Plan => 'Grundriss & Pläne', }; } + + /** + * Categories a gallery or an automatic photo may show. + * + * @return list + */ + public static function forGalleries(): array + { + return array_values(array_filter(self::cases(), fn (self $category): bool => $category !== self::Plan)); + } } diff --git a/app/Filament/Resources/FloorPlans/Schemas/FloorPlanForm.php b/app/Filament/Resources/FloorPlans/Schemas/FloorPlanForm.php index 5420a12..213c588 100644 --- a/app/Filament/Resources/FloorPlans/Schemas/FloorPlanForm.php +++ b/app/Filament/Resources/FloorPlans/Schemas/FloorPlanForm.php @@ -36,7 +36,7 @@ public static function configure(Schema $schema): Schema ->live(), PhotoSelect::make('photo_id') ->label('Grundriss-Bild') - ->helperText('Rendering oder Plan aus Webseite › Fotos. Ein neues Bild im gleichen Ausschnitt behält die Räume.') + ->helperText('Rendering oder Plan aus Webseite › Fotos – am besten in der Kategorie „Grundriss & Pläne“: Sie erscheint in keiner Galerie, ausblenden ist nicht nötig. Ein neues Bild im gleichen Ausschnitt behält die Räume.') ->required() ->live(), Repeater::make('rooms') diff --git a/app/Models/Photo.php b/app/Models/Photo.php index 801dfd2..8f75e2f 100644 --- a/app/Models/Photo.php +++ b/app/Models/Photo.php @@ -81,6 +81,18 @@ protected function published(Builder $query): Builder return $query->where('is_published', true)->orderBy('sort_order'); } + /** + * Photos a gallery or an automatic choice may show – floor plans and drawings only appear where chosen. + * + * @param Builder $query + * @return Builder + */ + #[Scope] + protected function forGalleries(Builder $query): Builder + { + return $query->whereIn('category', PhotoCategory::forGalleries()); + } + /** * Photos of the apartment and those without an apartment (e.g. the area); without an apartment all photos. * diff --git a/app/Themes/Sections/GallerySection.php b/app/Themes/Sections/GallerySection.php index fb69e41..b7d7b41 100644 --- a/app/Themes/Sections/GallerySection.php +++ b/app/Themes/Sections/GallerySection.php @@ -32,7 +32,7 @@ public static function schema(): array { return [ TextInput::make('heading')->label('Überschrift')->maxLength(120), - Select::make('category')->label('Bilder')->options(['all' => 'Alle', ...collect(PhotoCategory::cases())->mapWithKeys(fn (PhotoCategory $category): array => [$category->value => $category->getLabel()])->all()])->default('all'), + Select::make('category')->label('Bilder')->options(['all' => 'Alle', ...collect(PhotoCategory::forGalleries())->mapWithKeys(fn (PhotoCategory $category): array => [$category->value => $category->getLabel()])->all()])->default('all'), TextInput::make('limit')->label('Anzahl (leer = alle)')->integer()->minValue(1), ]; } @@ -48,7 +48,7 @@ public function data(Theme $theme, array $data): array return [ 'heading' => $data['heading'] ?? null, - 'photos' => $this->withSeasonalPhotos($theme, $data, 'photo_ids', Photo::query()->published()->forProperty($theme->property())->with('media') + 'photos' => $this->withSeasonalPhotos($theme, $data, 'photo_ids', Photo::query()->published()->forGalleries()->forProperty($theme->property())->with('media') ->when($category, fn ($query) => $query->where('category', $category)) ->when(filled($data['limit'] ?? null), fn ($query) => $query->limit((int) $data['limit'])) ->get()), diff --git a/app/Themes/Sections/HeroSection.php b/app/Themes/Sections/HeroSection.php index 9dd4df0..7d9e597 100644 --- a/app/Themes/Sections/HeroSection.php +++ b/app/Themes/Sections/HeroSection.php @@ -53,7 +53,7 @@ public function data(Theme $theme, array $data): array { $fallback = isset($data['photo_id']) ? Photo::find($data['photo_id']) - : Photo::query()->published()->when($theme->property(), fn ($query, $property) => $query->whereBelongsTo($property))->first() ?? Photo::query()->published()->first(); + : Photo::query()->published()->forGalleries()->when($theme->property(), fn ($query, $property) => $query->whereBelongsTo($property))->first() ?? Photo::query()->published()->forGalleries()->first(); $featuredOffer = ($data['show_offer'] ?? true) && $theme->property() ? app(OfferShowcase::class)->current($theme->property(), limit: 1, featuredOnly: true)->first() : null; diff --git a/database/migrations/2026_10_29_184027_move_floor_plan_pictures_to_the_plan_category.php b/database/migrations/2026_10_29_184027_move_floor_plan_pictures_to_the_plan_category.php new file mode 100644 index 0000000..807ddda --- /dev/null +++ b/database/migrations/2026_10_29_184027_move_floor_plan_pictures_to_the_plan_category.php @@ -0,0 +1,22 @@ +whereIn('id', DB::table('floor_plans')->whereNotNull('photo_id')->select('photo_id')) + ->update(['category' => 'plan']); + } + + public function down(): void + { + DB::table('photos')->where('category', 'plan')->update(['category' => 'apartment']); + } +}; diff --git a/tests/Feature/FloorPlanTest.php b/tests/Feature/FloorPlanTest.php index 8336022..aa7def8 100644 --- a/tests/Feature/FloorPlanTest.php +++ b/tests/Feature/FloorPlanTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature; +use App\Enums\PhotoCategory; use App\Enums\UserRole; use App\Filament\Resources\FloorPlans\FloorPlanResource; use App\Filament\Resources\FloorPlans\Pages\CreateFloorPlan; @@ -77,6 +78,39 @@ public function test_section_shows_visible_rooms_with_area_photo_equipment_and_h ->assertDontSee('Ohne Fläche'); } + public function test_plan_pictures_serve_the_floor_plan_even_when_hidden_but_never_appear_in_galleries(): void + { + $plan = Photo::factory()->create(['category' => PhotoCategory::Plan, 'is_published' => false]); + Photo::factory()->create(['alt_text' => 'Lageplan des Hauses', 'category' => PhotoCategory::Plan]); + Photo::factory()->create(['alt_text' => 'Wohnzimmer mit Erker', 'category' => PhotoCategory::Apartment]); + FloorPlan::factory()->for($this->property)->create([ + 'photo_id' => $plan->id, + 'rooms' => [['id' => 'a', 'name' => 'Bad', 'points' => '50,40 66,40 66,65', 'is_visible' => true]], + ]); + $this->placeSectionOnApartmentPage(); + $page = Site::sole()->pages()->where('slug', 'wohnung')->sole(); + $page->update(['sections' => [...$page->sections, ['type' => 'gallery', 'data' => ['heading' => 'Alle Bilder', 'category' => 'all']]]]); + + $this->get('/wohnung') + ->assertOk() + ->assertSee('points="50,40 66,40 66,65"', false) + ->assertSee('Wohnzimmer mit Erker') + ->assertDontSee('Lageplan des Hauses'); + } + + public function test_floor_plan_pictures_move_to_the_plan_category(): void + { + $plan = Photo::factory()->create(['category' => PhotoCategory::Apartment, 'is_published' => false]); + $other = Photo::factory()->create(['category' => PhotoCategory::Apartment]); + FloorPlan::factory()->for($this->property)->create(['photo_id' => $plan->id]); + + (require database_path('migrations/2026_10_29_184027_move_floor_plan_pictures_to_the_plan_category.php'))->up(); + + $this->assertSame(PhotoCategory::Plan, $plan->fresh()->category); + $this->assertFalse($plan->fresh()->is_published); + $this->assertSame(PhotoCategory::Apartment, $other->fresh()->category); + } + public function test_section_shows_nothing_without_a_floor_plan(): void { $this->placeSectionOnApartmentPage();