Eigene Fotokategorie fuer Grundrisse und Plaene, nie in Galerien

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-10-29 18:43:02 +01:00
1 parent 8bcda9a4bc
commit d02f3e05c7
7 files changed
+85 -4

No files matched your search

+13
View File
@@ -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<self>
*/
public static function forGalleries(): array
{
return array_values(array_filter(self::cases(), fn (self $category): bool => $category !== self::Plan));
}
}
@@ -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')
+12
View File
@@ -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<Photo> $query
* @return Builder<Photo>
*/
#[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.
*
+2 -2
View File
@@ -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()),
+1 -1
View File
@@ -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;
@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* Pictures used by a floor plan move to the new category "Grundriss & Pläne", which galleries never show.
*/
public function up(): void
{
DB::table('photos')
->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']);
}
};
+34
View File
@@ -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();