From 8bcda9a4bc3595dd00a9a349b25adc905cfd785a Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 29 Oct 2026 18:40:13 +0100 Subject: [PATCH 1/5] Wohnungsumschalter im Verwaltungsmenue und wohnungsbezogene Listen Oben im Seitenmenue waehlt man die Wohnung; Listen, neue Eintraege, Belegungsplan und Preise & Angebote folgen ihr. Ein geoeffneter Eintrag einer anderen Wohnung schaltet auf diese um. Galerie und Ersatz-Titelbild der Website zeigen nur Fotos der Wohnung des Bausteins und Fotos ohne Wohnung. Co-Authored-By: Claude Opus 5.5 --- .../Concerns/ListsCurrentProperty.php | 33 ++++ .../Concerns/SelectsRecordProperty.php | 34 ++++ app/Filament/Pages/OccupancyCalendar.php | 8 +- app/Filament/Pages/PricesAndOffers.php | 15 +- .../Resources/Amenities/AmenityResource.php | 3 +- .../Amenities/Pages/ListAmenities.php | 3 + .../Amenities/Schemas/AmenityForm.php | 3 +- .../BlockedPeriods/BlockedPeriodResource.php | 6 +- .../Pages/ManageBlockedPeriods.php | 3 + .../Resources/Bookings/BookingResource.php | 3 +- .../Bookings/Schemas/BookingForm.php | 3 +- .../Bookings/Tables/BookingsTable.php | 5 +- .../ChannelTasks/Pages/ListChannelTasks.php | 10 ++ .../Resources/Channels/ChannelResource.php | 3 +- .../Resources/Channels/Pages/ListChannels.php | 3 + .../Channels/Schemas/ChannelForm.php | 3 +- .../FloorPlans/FloorPlanResource.php | 3 +- .../FloorPlans/Pages/ListFloorPlans.php | 3 + .../FloorPlans/Schemas/FloorPlanForm.php | 3 +- .../Resources/Photos/Pages/ListPhotos.php | 15 +- .../Resources/Photos/PhotoResource.php | 3 +- .../Resources/Photos/Schemas/PhotoForm.php | 3 +- .../PortalEmails/Pages/ListPortalEmails.php | 10 ++ .../Pages/ManagePortalOccupations.php | 3 + .../PortalOccupationResource.php | 3 +- .../Resources/Reviews/Pages/ListReviews.php | 3 + .../Resources/Reviews/ReviewResource.php | 3 +- .../Resources/Reviews/Schemas/ReviewForm.php | 3 +- .../Controllers/SwitchPropertyController.php | 60 +++++++ app/Models/Photo.php | 14 ++ app/Providers/Filament/AdminPanelProvider.php | 7 + app/Support/CurrentProperty.php | 86 ++++++++++ app/Themes/Sections/GallerySection.php | 2 +- app/Themes/Sections/HeroSection.php | 4 +- .../pages/occupancy-calendar.blade.php | 7 - .../filament/property-switcher.blade.php | 32 ++++ tests/Feature/CurrentPropertyTest.php | 150 ++++++++++++++++++ 37 files changed, 520 insertions(+), 35 deletions(-) create mode 100644 app/Filament/Concerns/ListsCurrentProperty.php create mode 100644 app/Filament/Concerns/SelectsRecordProperty.php create mode 100644 app/Http/Controllers/SwitchPropertyController.php create mode 100644 app/Support/CurrentProperty.php create mode 100644 resources/views/filament/property-switcher.blade.php create mode 100644 tests/Feature/CurrentPropertyTest.php diff --git a/app/Filament/Concerns/ListsCurrentProperty.php b/app/Filament/Concerns/ListsCurrentProperty.php new file mode 100644 index 0000000..27388bf --- /dev/null +++ b/app/Filament/Concerns/ListsCurrentProperty.php @@ -0,0 +1,33 @@ +get(); + + return $query instanceof Builder && $property !== null ? $this->scopeToProperty($query, $property) : $query; + } + + /** + * @param Builder $query + * @return Builder + */ + protected function scopeToProperty(Builder $query, Property $property): Builder + { + return $query->where($query->qualifyColumn('property_id'), $property->id); + } +} diff --git a/app/Filament/Concerns/SelectsRecordProperty.php b/app/Filament/Concerns/SelectsRecordProperty.php new file mode 100644 index 0000000..a8d1169 --- /dev/null +++ b/app/Filament/Concerns/SelectsRecordProperty.php @@ -0,0 +1,34 @@ +id() && ($property = Property::query()->find($propertyId))) { + app(CurrentProperty::class)->select($property); + } + + return $record; + } + + public static function recordPropertyId(Model $record): ?int + { + $id = $record->getAttribute('property_id'); + + return $id !== null ? (int) $id : null; + } +} diff --git a/app/Filament/Pages/OccupancyCalendar.php b/app/Filament/Pages/OccupancyCalendar.php index a637f71..36a5a3d 100644 --- a/app/Filament/Pages/OccupancyCalendar.php +++ b/app/Filament/Pages/OccupancyCalendar.php @@ -6,6 +6,7 @@ use App\Filament\Concerns\FollowsAdminMode; use App\Models\Booking; use App\Models\Property; +use App\Support\CurrentProperty; use BackedEnum; use Carbon\CarbonImmutable; use Filament\Pages\Page; @@ -45,10 +46,15 @@ public static function canAccess(): bool return Gate::allows('viewAny', Booking::class); } + public function getSubheading(): ?string + { + return app(CurrentProperty::class)->hasChoice() ? Property::query()->find($this->propertyId)?->name : null; + } + public function mount(): void { $this->month = $this->month ?: now()->format('Y-m'); - $this->propertyId ??= Property::query()->where('is_active', true)->value('id') ?? Property::query()->value('id'); + $this->propertyId = app(CurrentProperty::class)->followUrl($this->propertyId); } #[Computed] diff --git a/app/Filament/Pages/PricesAndOffers.php b/app/Filament/Pages/PricesAndOffers.php index d937234..95e9625 100644 --- a/app/Filament/Pages/PricesAndOffers.php +++ b/app/Filament/Pages/PricesAndOffers.php @@ -9,8 +9,8 @@ use App\Filament\Resources\Properties\RelationManagers\SeasonsRelationManager; use App\Filament\Resources\Properties\RelationManagers\SpecialOffersRelationManager; use App\Models\Property; +use App\Support\CurrentProperty; use BackedEnum; -use Filament\Forms\Components\Select; use Filament\Pages\Page; use Filament\Schemas\Components\Livewire; use Filament\Schemas\Components\Tabs; @@ -49,9 +49,14 @@ public static function canAccess(): bool return (bool) auth()->user()?->hasRole(UserRole::Admin, UserRole::Rentals); } + public function getSubheading(): ?string + { + return app(CurrentProperty::class)->hasChoice() ? Property::query()->find($this->propertyId)?->name : null; + } + public function mount(): void { - $this->propertyId ??= Property::query()->where('is_active', true)->value('id') ?? Property::query()->value('id'); + $this->propertyId = app(CurrentProperty::class)->followUrl($this->propertyId); } public function content(Schema $schema): Schema @@ -64,12 +69,6 @@ public function content(Schema $schema): Schema $context = ['ownerRecord' => $property, 'pageClass' => EditProperty::class]; return $schema->components([ - Select::make('propertyId') - ->label('Wohnung') - ->options(fn (): array => Property::query()->orderBy('name')->pluck('name', 'id')->all()) - ->live() - ->afterStateUpdated(fn () => $this->redirect(static::getUrl(['wohnung' => $this->propertyId]))) - ->visible(fn (): bool => Property::query()->count() > 1), Tabs::make('prices') ->persistTabInQueryString() ->tabs([ diff --git a/app/Filament/Resources/Amenities/AmenityResource.php b/app/Filament/Resources/Amenities/AmenityResource.php index 341194b..8696a9a 100644 --- a/app/Filament/Resources/Amenities/AmenityResource.php +++ b/app/Filament/Resources/Amenities/AmenityResource.php @@ -3,6 +3,7 @@ namespace App\Filament\Resources\Amenities; use App\Filament\Concerns\FollowsAdminMode; +use App\Filament\Concerns\SelectsRecordProperty; use App\Filament\Resources\Amenities\Pages\CreateAmenity; use App\Filament\Resources\Amenities\Pages\EditAmenity; use App\Filament\Resources\Amenities\Pages\ListAmenities; @@ -18,7 +19,7 @@ class AmenityResource extends Resource { - use FollowsAdminMode; + use FollowsAdminMode, SelectsRecordProperty; protected static ?string $model = Amenity::class; diff --git a/app/Filament/Resources/Amenities/Pages/ListAmenities.php b/app/Filament/Resources/Amenities/Pages/ListAmenities.php index 29ad95c..96e4415 100644 --- a/app/Filament/Resources/Amenities/Pages/ListAmenities.php +++ b/app/Filament/Resources/Amenities/Pages/ListAmenities.php @@ -2,12 +2,15 @@ namespace App\Filament\Resources\Amenities\Pages; +use App\Filament\Concerns\ListsCurrentProperty; use App\Filament\Resources\Amenities\AmenityResource; use Filament\Actions\CreateAction; use Filament\Resources\Pages\ListRecords; class ListAmenities extends ListRecords { + use ListsCurrentProperty; + protected static string $resource = AmenityResource::class; protected function getHeaderActions(): array diff --git a/app/Filament/Resources/Amenities/Schemas/AmenityForm.php b/app/Filament/Resources/Amenities/Schemas/AmenityForm.php index b6ec50e..c8c201f 100644 --- a/app/Filament/Resources/Amenities/Schemas/AmenityForm.php +++ b/app/Filament/Resources/Amenities/Schemas/AmenityForm.php @@ -4,6 +4,7 @@ use App\Enums\AmenityArea; use App\Models\Property; +use App\Support\CurrentProperty; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; @@ -28,7 +29,7 @@ public static function configure(Schema $schema): Schema Select::make('property_id') ->label('Wohnung') ->options(fn (): array => Property::query()->pluck('name', 'id')->all()) - ->default(fn (): ?int => Property::query()->value('id')) + ->default(fn (): ?int => app(CurrentProperty::class)->id()) ->required(), Toggle::make('is_highlight') ->label('Highlight (auf der Startseite hervorheben)'), diff --git a/app/Filament/Resources/BlockedPeriods/BlockedPeriodResource.php b/app/Filament/Resources/BlockedPeriods/BlockedPeriodResource.php index faf277b..b4fcd89 100644 --- a/app/Filament/Resources/BlockedPeriods/BlockedPeriodResource.php +++ b/app/Filament/Resources/BlockedPeriods/BlockedPeriodResource.php @@ -6,12 +6,14 @@ use App\Channels\ICal\ICalRuleEngine; use App\Enums\BlockedPeriodPurpose; use App\Filament\Concerns\FollowsAdminMode; +use App\Filament\Concerns\SelectsRecordProperty; use App\Filament\Resources\BlockedPeriods\Pages\ManageBlockedPeriods; use App\Filament\Resources\PortalOccupations\PortalOccupationResource; use App\Models\BlockedPeriod; use App\Models\Booking; use App\Models\Channel; use App\Models\Property; +use App\Support\CurrentProperty; use BackedEnum; use Filament\Actions\Action; use Filament\Actions\DeleteAction; @@ -37,7 +39,7 @@ */ class BlockedPeriodResource extends Resource { - use FollowsAdminMode; + use FollowsAdminMode, SelectsRecordProperty; protected static ?string $model = BlockedPeriod::class; @@ -59,7 +61,7 @@ public static function form(Schema $schema): Schema Select::make('property_id') ->label('Wohnung') ->options(fn (): array => Property::query()->orderBy('name')->pluck('name', 'id')->all()) - ->default(fn (): ?int => Property::query()->where('is_active', true)->value('id')) + ->default(fn (): ?int => app(CurrentProperty::class)->id()) ->required() ->columnSpanFull() ->hidden(fn (): bool => Property::query()->count() <= 1) diff --git a/app/Filament/Resources/BlockedPeriods/Pages/ManageBlockedPeriods.php b/app/Filament/Resources/BlockedPeriods/Pages/ManageBlockedPeriods.php index 8add1c3..70b5943 100644 --- a/app/Filament/Resources/BlockedPeriods/Pages/ManageBlockedPeriods.php +++ b/app/Filament/Resources/BlockedPeriods/Pages/ManageBlockedPeriods.php @@ -2,12 +2,15 @@ namespace App\Filament\Resources\BlockedPeriods\Pages; +use App\Filament\Concerns\ListsCurrentProperty; use App\Filament\Resources\BlockedPeriods\BlockedPeriodResource; use Filament\Actions\CreateAction; use Filament\Resources\Pages\ManageRecords; class ManageBlockedPeriods extends ManageRecords { + use ListsCurrentProperty; + protected static string $resource = BlockedPeriodResource::class; protected function getHeaderActions(): array diff --git a/app/Filament/Resources/Bookings/BookingResource.php b/app/Filament/Resources/Bookings/BookingResource.php index 7918273..5ffe7ee 100644 --- a/app/Filament/Resources/Bookings/BookingResource.php +++ b/app/Filament/Resources/Bookings/BookingResource.php @@ -4,6 +4,7 @@ use App\Enums\BookingStatus; use App\Filament\Concerns\FollowsAdminMode; +use App\Filament\Concerns\SelectsRecordProperty; use App\Filament\Resources\Bookings\Pages\CreateBooking; use App\Filament\Resources\Bookings\Pages\ListBookings; use App\Filament\Resources\Bookings\Pages\ViewBooking; @@ -21,7 +22,7 @@ class BookingResource extends Resource { - use FollowsAdminMode; + use FollowsAdminMode, SelectsRecordProperty; protected static ?string $model = Booking::class; diff --git a/app/Filament/Resources/Bookings/Schemas/BookingForm.php b/app/Filament/Resources/Bookings/Schemas/BookingForm.php index ecbb9f5..02bb833 100644 --- a/app/Filament/Resources/Bookings/Schemas/BookingForm.php +++ b/app/Filament/Resources/Bookings/Schemas/BookingForm.php @@ -3,6 +3,7 @@ namespace App\Filament\Resources\Bookings\Schemas; use App\Models\Property; +use App\Support\CurrentProperty; use Filament\Forms\Components\DatePicker; use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; @@ -26,7 +27,7 @@ public static function configure(Schema $schema): Schema Select::make('property_id') ->label('Wohnung') ->options(fn (): array => Property::query()->orderBy('name')->pluck('name', 'id')->all()) - ->default(fn (): ?int => Property::query()->value('id')) + ->default(fn (): ?int => app(CurrentProperty::class)->id()) ->required(), TextInput::make('guests') ->label('Personen') diff --git a/app/Filament/Resources/Bookings/Tables/BookingsTable.php b/app/Filament/Resources/Bookings/Tables/BookingsTable.php index c63fdc1..4fb0a00 100644 --- a/app/Filament/Resources/Bookings/Tables/BookingsTable.php +++ b/app/Filament/Resources/Bookings/Tables/BookingsTable.php @@ -5,6 +5,7 @@ use App\Availability\OccupancyOverview; use App\Enums\BookingStatus; use App\Models\Property; +use App\Support\CurrentProperty; use Filament\Actions\Action; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Filters\Filter; @@ -59,7 +60,9 @@ public static function configure(Table $table, ?int $guestId = null): Table TextColumn::make('property')->label('Wohnung')->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ - SelectFilter::make('property')->label('Wohnung')->options(fn (): array => Property::query()->orderBy('name')->pluck('name', 'id')->all()), + SelectFilter::make('property')->label('Wohnung')->options(fn (): array => Property::query()->orderBy('name')->pluck('name', 'id')->all()) + // The booking list starts with the apartment chosen in the menu; a guest's bookings show all apartments. + ->default(fn (): ?int => $guestId === null ? app(CurrentProperty::class)->id() : null), SelectFilter::make('kind')->label('Buchungsweg')->options(['booking' => 'Eigene Anfragen & Buchungen', 'portal' => 'Portalreservierungen']), SelectFilter::make('status')->label('Status')->multiple()->options([ ...collect(BookingStatus::cases())->mapWithKeys(fn (BookingStatus $status): array => [$status->value => $status->getLabel()])->all(), diff --git a/app/Filament/Resources/ChannelTasks/Pages/ListChannelTasks.php b/app/Filament/Resources/ChannelTasks/Pages/ListChannelTasks.php index 886ff47..4036727 100644 --- a/app/Filament/Resources/ChannelTasks/Pages/ListChannelTasks.php +++ b/app/Filament/Resources/ChannelTasks/Pages/ListChannelTasks.php @@ -2,10 +2,20 @@ namespace App\Filament\Resources\ChannelTasks\Pages; +use App\Filament\Concerns\ListsCurrentProperty; use App\Filament\Resources\ChannelTasks\ChannelTaskResource; +use App\Models\Property; use Filament\Resources\Pages\ListRecords; +use Illuminate\Database\Eloquent\Builder; class ListChannelTasks extends ListRecords { + use ListsCurrentProperty; + protected static string $resource = ChannelTaskResource::class; + + protected function scopeToProperty(Builder $query, Property $property): Builder + { + return $query->whereHas('channel', fn (Builder $channel) => $channel->where('property_id', $property->id)); + } } diff --git a/app/Filament/Resources/Channels/ChannelResource.php b/app/Filament/Resources/Channels/ChannelResource.php index 51fc2a6..f20d7eb 100644 --- a/app/Filament/Resources/Channels/ChannelResource.php +++ b/app/Filament/Resources/Channels/ChannelResource.php @@ -3,6 +3,7 @@ namespace App\Filament\Resources\Channels; use App\Filament\Concerns\FollowsAdminMode; +use App\Filament\Concerns\SelectsRecordProperty; use App\Filament\Resources\Channels\Pages\ChannelRules; use App\Filament\Resources\Channels\Pages\CreateChannel; use App\Filament\Resources\Channels\Pages\EditChannel; @@ -20,7 +21,7 @@ class ChannelResource extends Resource { - use FollowsAdminMode; + use FollowsAdminMode, SelectsRecordProperty; protected static ?string $model = Channel::class; diff --git a/app/Filament/Resources/Channels/Pages/ListChannels.php b/app/Filament/Resources/Channels/Pages/ListChannels.php index b169aa5..c658df5 100644 --- a/app/Filament/Resources/Channels/Pages/ListChannels.php +++ b/app/Filament/Resources/Channels/Pages/ListChannels.php @@ -2,12 +2,15 @@ namespace App\Filament\Resources\Channels\Pages; +use App\Filament\Concerns\ListsCurrentProperty; use App\Filament\Resources\Channels\ChannelResource; use Filament\Actions\CreateAction; use Filament\Resources\Pages\ListRecords; class ListChannels extends ListRecords { + use ListsCurrentProperty; + protected static string $resource = ChannelResource::class; protected function getHeaderActions(): array diff --git a/app/Filament/Resources/Channels/Schemas/ChannelForm.php b/app/Filament/Resources/Channels/Schemas/ChannelForm.php index fb41fb2..3b495bb 100644 --- a/app/Filament/Resources/Channels/Schemas/ChannelForm.php +++ b/app/Filament/Resources/Channels/Schemas/ChannelForm.php @@ -9,6 +9,7 @@ use App\Enums\ChannelStatus; use App\Models\Channel; use App\Models\Property; +use App\Support\CurrentProperty; use Filament\Forms\Components\DateTimePicker; use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; @@ -30,7 +31,7 @@ public static function configure(Schema $schema, bool $selectProperty = false): ->components([ ...($selectProperty ? [Select::make('property_id')->label('Wohnung')->required() ->options(fn (): array => Property::query()->orderBy('name')->pluck('name', 'id')->all()) - ->default(fn (): ?int => Property::query()->where('is_active', true)->value('id')) + ->default(fn (): ?int => app(CurrentProperty::class)->id()) ->disabled(fn (?Channel $record): bool => $record !== null)->dehydrated()->columnSpanFull()] : []), TextEntry::make('export_url') ->label('Eigener iCal-Exportlink') diff --git a/app/Filament/Resources/FloorPlans/FloorPlanResource.php b/app/Filament/Resources/FloorPlans/FloorPlanResource.php index a79db83..ca4e409 100644 --- a/app/Filament/Resources/FloorPlans/FloorPlanResource.php +++ b/app/Filament/Resources/FloorPlans/FloorPlanResource.php @@ -3,6 +3,7 @@ namespace App\Filament\Resources\FloorPlans; use App\Filament\Concerns\FollowsAdminMode; +use App\Filament\Concerns\SelectsRecordProperty; use App\Filament\Resources\FloorPlans\Pages\CreateFloorPlan; use App\Filament\Resources\FloorPlans\Pages\EditFloorPlan; use App\Filament\Resources\FloorPlans\Pages\ListFloorPlans; @@ -21,7 +22,7 @@ */ class FloorPlanResource extends Resource { - use FollowsAdminMode; + use FollowsAdminMode, SelectsRecordProperty; protected static ?string $model = FloorPlan::class; diff --git a/app/Filament/Resources/FloorPlans/Pages/ListFloorPlans.php b/app/Filament/Resources/FloorPlans/Pages/ListFloorPlans.php index c488192..76a5659 100644 --- a/app/Filament/Resources/FloorPlans/Pages/ListFloorPlans.php +++ b/app/Filament/Resources/FloorPlans/Pages/ListFloorPlans.php @@ -2,12 +2,15 @@ namespace App\Filament\Resources\FloorPlans\Pages; +use App\Filament\Concerns\ListsCurrentProperty; use App\Filament\Resources\FloorPlans\FloorPlanResource; use Filament\Actions\CreateAction; use Filament\Resources\Pages\ListRecords; class ListFloorPlans extends ListRecords { + use ListsCurrentProperty; + protected static string $resource = FloorPlanResource::class; protected function getHeaderActions(): array diff --git a/app/Filament/Resources/FloorPlans/Schemas/FloorPlanForm.php b/app/Filament/Resources/FloorPlans/Schemas/FloorPlanForm.php index 60241e0..5420a12 100644 --- a/app/Filament/Resources/FloorPlans/Schemas/FloorPlanForm.php +++ b/app/Filament/Resources/FloorPlans/Schemas/FloorPlanForm.php @@ -6,6 +6,7 @@ use App\Models\Amenity; use App\Models\FloorPlan; use App\Models\Property; +use App\Support\CurrentProperty; use Closure; use Filament\Forms\Components\Hidden; use Filament\Forms\Components\Repeater; @@ -28,7 +29,7 @@ public static function configure(Schema $schema): Schema Select::make('property_id') ->label('Wohnung') ->options(fn (): array => Property::query()->pluck('name', 'id')->all()) - ->default(fn (): ?int => Property::query()->value('id')) + ->default(fn (): ?int => app(CurrentProperty::class)->id()) ->unique(ignoreRecord: true) ->validationMessages(['unique' => 'Für diese Wohnung gibt es schon einen Grundriss.']) ->required() diff --git a/app/Filament/Resources/Photos/Pages/ListPhotos.php b/app/Filament/Resources/Photos/Pages/ListPhotos.php index 1af3de9..152bb50 100644 --- a/app/Filament/Resources/Photos/Pages/ListPhotos.php +++ b/app/Filament/Resources/Photos/Pages/ListPhotos.php @@ -3,9 +3,11 @@ namespace App\Filament\Resources\Photos\Pages; use App\Enums\PhotoCategory; +use App\Filament\Concerns\ListsCurrentProperty; use App\Filament\Resources\Photos\PhotoResource; use App\Models\Photo; use App\Models\Property; +use App\Support\CurrentProperty; use Filament\Actions\Action; use Filament\Actions\CreateAction; use Filament\Forms\Components\FileUpload; @@ -13,12 +15,23 @@ use Filament\Notifications\Notification; use Filament\Resources\Pages\ListRecords; use Filament\Support\Icons\Heroicon; +use Illuminate\Database\Eloquent\Builder; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; class ListPhotos extends ListRecords { + use ListsCurrentProperty; + protected static string $resource = PhotoResource::class; + /** + * Photos without an apartment (e.g. the area) belong to every apartment. + */ + protected function scopeToProperty(Builder $query, Property $property): Builder + { + return $query->where(fn (Builder $query) => $query->where('property_id', $property->id)->orWhereNull('property_id')); + } + protected function getHeaderActions(): array { return [ @@ -42,7 +55,7 @@ protected function getHeaderActions(): array ->required(), ]) ->action(function (array $data): void { - $propertyId = Property::query()->value('id'); + $propertyId = app(CurrentProperty::class)->id(); $nextSort = (int) Photo::max('sort_order'); /** @var TemporaryUploadedFile $file */ diff --git a/app/Filament/Resources/Photos/PhotoResource.php b/app/Filament/Resources/Photos/PhotoResource.php index 4a372cd..64cf4cc 100644 --- a/app/Filament/Resources/Photos/PhotoResource.php +++ b/app/Filament/Resources/Photos/PhotoResource.php @@ -3,6 +3,7 @@ namespace App\Filament\Resources\Photos; use App\Filament\Concerns\FollowsAdminMode; +use App\Filament\Concerns\SelectsRecordProperty; use App\Filament\Resources\Photos\Pages\CreatePhoto; use App\Filament\Resources\Photos\Pages\EditPhoto; use App\Filament\Resources\Photos\Pages\ListPhotos; @@ -18,7 +19,7 @@ class PhotoResource extends Resource { - use FollowsAdminMode; + use FollowsAdminMode, SelectsRecordProperty; protected static ?string $model = Photo::class; diff --git a/app/Filament/Resources/Photos/Schemas/PhotoForm.php b/app/Filament/Resources/Photos/Schemas/PhotoForm.php index 3862cdc..6326622 100644 --- a/app/Filament/Resources/Photos/Schemas/PhotoForm.php +++ b/app/Filament/Resources/Photos/Schemas/PhotoForm.php @@ -5,6 +5,7 @@ use App\Enums\PhotoCategory; use App\Models\Photo; use App\Models\Property; +use App\Support\CurrentProperty; use Filament\Forms\Components\Select; use Filament\Forms\Components\SpatieMediaLibraryFileUpload; use Filament\Forms\Components\TextInput; @@ -44,7 +45,7 @@ public static function configure(Schema $schema): Schema Select::make('property_id') ->label('Wohnung') ->options(fn (): array => Property::query()->pluck('name', 'id')->all()) - ->default(fn (): ?int => Property::query()->value('id')) + ->default(fn (): ?int => app(CurrentProperty::class)->id()) ->placeholder('– keine (z. B. Umgebung) –'), Toggle::make('is_published') ->label('Auf der Webseite zeigen') diff --git a/app/Filament/Resources/PortalEmails/Pages/ListPortalEmails.php b/app/Filament/Resources/PortalEmails/Pages/ListPortalEmails.php index e50e539..f9b949c 100644 --- a/app/Filament/Resources/PortalEmails/Pages/ListPortalEmails.php +++ b/app/Filament/Resources/PortalEmails/Pages/ListPortalEmails.php @@ -2,10 +2,20 @@ namespace App\Filament\Resources\PortalEmails\Pages; +use App\Filament\Concerns\ListsCurrentProperty; use App\Filament\Resources\PortalEmails\PortalEmailResource; +use App\Models\Property; use Filament\Resources\Pages\ListRecords; +use Illuminate\Database\Eloquent\Builder; class ListPortalEmails extends ListRecords { + use ListsCurrentProperty; + protected static string $resource = PortalEmailResource::class; + + protected function scopeToProperty(Builder $query, Property $property): Builder + { + return $query->whereHas('channel', fn (Builder $channel) => $channel->where('property_id', $property->id)); + } } diff --git a/app/Filament/Resources/PortalOccupations/Pages/ManagePortalOccupations.php b/app/Filament/Resources/PortalOccupations/Pages/ManagePortalOccupations.php index 9c72830..5b02e05 100644 --- a/app/Filament/Resources/PortalOccupations/Pages/ManagePortalOccupations.php +++ b/app/Filament/Resources/PortalOccupations/Pages/ManagePortalOccupations.php @@ -2,6 +2,7 @@ namespace App\Filament\Resources\PortalOccupations\Pages; +use App\Filament\Concerns\ListsCurrentProperty; use App\Filament\Resources\PortalOccupations\PortalOccupationResource; use Filament\Resources\Pages\ManageRecords; use Filament\Schemas\Components\Tabs\Tab; @@ -9,6 +10,8 @@ class ManagePortalOccupations extends ManageRecords { + use ListsCurrentProperty; + protected static string $resource = PortalOccupationResource::class; public function getTabs(): array diff --git a/app/Filament/Resources/PortalOccupations/PortalOccupationResource.php b/app/Filament/Resources/PortalOccupations/PortalOccupationResource.php index 9f67535..e01205b 100644 --- a/app/Filament/Resources/PortalOccupations/PortalOccupationResource.php +++ b/app/Filament/Resources/PortalOccupations/PortalOccupationResource.php @@ -6,6 +6,7 @@ use App\Enums\OccupationKind; use App\Filament\Actions\AssignGuestAction; use App\Filament\Concerns\FollowsAdminMode; +use App\Filament\Concerns\SelectsRecordProperty; use App\Filament\Resources\BlockedPeriods\BlockedPeriodResource; use App\Filament\Resources\Bookings\BookingResource; use App\Filament\Resources\Guests\GuestResource; @@ -32,7 +33,7 @@ class PortalOccupationResource extends Resource { - use FollowsAdminMode; + use FollowsAdminMode, SelectsRecordProperty; protected static ?string $model = BlockedPeriod::class; diff --git a/app/Filament/Resources/Reviews/Pages/ListReviews.php b/app/Filament/Resources/Reviews/Pages/ListReviews.php index 5abcab3..9b8bd52 100644 --- a/app/Filament/Resources/Reviews/Pages/ListReviews.php +++ b/app/Filament/Resources/Reviews/Pages/ListReviews.php @@ -2,12 +2,15 @@ namespace App\Filament\Resources\Reviews\Pages; +use App\Filament\Concerns\ListsCurrentProperty; use App\Filament\Resources\Reviews\ReviewResource; use Filament\Actions\CreateAction; use Filament\Resources\Pages\ListRecords; class ListReviews extends ListRecords { + use ListsCurrentProperty; + protected static string $resource = ReviewResource::class; protected function getHeaderActions(): array diff --git a/app/Filament/Resources/Reviews/ReviewResource.php b/app/Filament/Resources/Reviews/ReviewResource.php index 28aef41..8eadef8 100644 --- a/app/Filament/Resources/Reviews/ReviewResource.php +++ b/app/Filament/Resources/Reviews/ReviewResource.php @@ -4,6 +4,7 @@ use App\Enums\ReviewStatus; use App\Filament\Concerns\FollowsAdminMode; +use App\Filament\Concerns\SelectsRecordProperty; use App\Filament\Resources\Reviews\Pages\CreateReview; use App\Filament\Resources\Reviews\Pages\EditReview; use App\Filament\Resources\Reviews\Pages\ListReviews; @@ -19,7 +20,7 @@ class ReviewResource extends Resource { - use FollowsAdminMode; + use FollowsAdminMode, SelectsRecordProperty; protected static ?string $model = Review::class; diff --git a/app/Filament/Resources/Reviews/Schemas/ReviewForm.php b/app/Filament/Resources/Reviews/Schemas/ReviewForm.php index 2346bf8..17efce3 100644 --- a/app/Filament/Resources/Reviews/Schemas/ReviewForm.php +++ b/app/Filament/Resources/Reviews/Schemas/ReviewForm.php @@ -5,6 +5,7 @@ use App\Enums\ReviewStatus; use App\Models\Property; use App\Models\Review; +use App\Support\CurrentProperty; use Filament\Forms\Components\DatePicker; use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; @@ -54,7 +55,7 @@ public static function configure(Schema $schema): Schema Select::make('property_id') ->label('Wohnung') ->options(fn (): array => Property::query()->pluck('name', 'id')->all()) - ->default(fn (): ?int => Property::query()->value('id')) + ->default(fn (): ?int => app(CurrentProperty::class)->id()) ->required(), ]), Section::make('Öffentliche Antwort der Gastgeber') diff --git a/app/Http/Controllers/SwitchPropertyController.php b/app/Http/Controllers/SwitchPropertyController.php new file mode 100644 index 0000000..8363ca1 --- /dev/null +++ b/app/Http/Controllers/SwitchPropertyController.php @@ -0,0 +1,60 @@ +findOrFail($request->integer('property')); + $current->select($property); + + return redirect()->to($this->target($request->input('return', url()->previous()), $property)); + } + + private function target(string $previous, Property $property): string + { + $fallback = route('filament.admin.pages.dashboard'); + if (! Str::startsWith($previous, url('/admin'))) { + return $fallback; + } + + try { + $route = Route::getRoutes()->match(Request::create($previous)); + } catch (HttpException) { + return $fallback; + } + + $name = (string) $route->getName(); + if (Str::startsWith($name, 'filament.admin.resources.properties.')) { + return PropertyResource::getUrl('edit', ['record' => $property]); + } + + if (Str::endsWith($name, ['.edit', '.view'])) { + $index = Str::beforeLast($name, '.').'.index'; + + return Route::has($index) ? route($index) : $fallback; + } + + // A page's own apartment parameter would undo the switch. + $query = []; + parse_str((string) parse_url($previous, PHP_URL_QUERY), $query); + unset($query['wohnung']); + + return strtok($previous, '?').($query !== [] ? '?'.http_build_query($query) : ''); + } +} diff --git a/app/Models/Photo.php b/app/Models/Photo.php index 1f1201f..801dfd2 100644 --- a/app/Models/Photo.php +++ b/app/Models/Photo.php @@ -81,6 +81,20 @@ protected function published(Builder $query): Builder return $query->where('is_published', true)->orderBy('sort_order'); } + /** + * Photos of the apartment and those without an apartment (e.g. the area); without an apartment all photos. + * + * @param Builder $query + * @return Builder + */ + #[Scope] + protected function forProperty(Builder $query, ?Property $property): Builder + { + return $property === null + ? $query + : $query->where(fn (Builder $query) => $query->where('property_id', $property->id)->orWhereNull('property_id')); + } + public function url(string $size = 'md'): string { return $this->getFirstMediaUrl(self::COLLECTION, $size); diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index 518cf21..085727e 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -3,6 +3,7 @@ namespace App\Providers\Filament; use App\Enums\AdminMode; +use App\Http\Controllers\SwitchPropertyController; use App\Http\Middleware\ResolveTheme; use App\Models\User; use Filament\Actions\Action; @@ -25,6 +26,7 @@ use Illuminate\Foundation\Http\Middleware\PreventRequestForgery; use Illuminate\Routing\Middleware\SubstituteBindings; use Illuminate\Session\Middleware\StartSession; +use Illuminate\Support\Facades\Route; use Illuminate\View\Middleware\ShareErrorsFromSession; class AdminPanelProvider extends PanelProvider @@ -68,6 +70,11 @@ public function panel(Panel $panel): Panel ->brandName('FeWo Stommer · Verwaltung') // As long as the site is not switched live, every page shows where the e-mails go. ->renderHook(PanelsRenderHook::BODY_START, fn (): View => view('filament.test-mode-banner')) + // Apartment switcher at the top of the menu; lists and new records follow the chosen apartment. + ->renderHook(PanelsRenderHook::SIDEBAR_NAV_START, fn (): View => view('filament.property-switcher')) + ->authenticatedRoutes(function (): void { + Route::post('wohnung-wechseln', SwitchPropertyController::class)->name('switch-property'); + }) ->navigationGroups(['Vermietung', 'Webseite', 'System']) ->colors([ 'primary' => Color::Sky, diff --git a/app/Support/CurrentProperty.php b/app/Support/CurrentProperty.php new file mode 100644 index 0000000..0a83a86 --- /dev/null +++ b/app/Support/CurrentProperty.php @@ -0,0 +1,86 @@ +chosenId(); + $property = $chosen !== null ? Property::query()->find($chosen) : null; + + return $property + ?? Property::query()->where('is_active', true)->orderBy('id')->first() + ?? Property::query()->orderBy('id')->first(); + } + + public function id(): ?int + { + return $this->get()?->id; + } + + public function select(Property $property): void + { + if (app()->bound('session')) { + session()->put(self::SESSION_KEY.'.'.$this->tenantKey(), $property->id); + } + } + + /** + * An apartment named in a page URL (old links, e-mails) becomes the choice; another landlord's apartment is not found. + */ + public function followUrl(?int $propertyId): ?int + { + if ($propertyId === null) { + return $this->id(); + } + + $this->select(Property::query()->findOrFail($propertyId)); + + return $propertyId; + } + + /** + * Whether the landlord has more than one apartment to choose from. + */ + public function hasChoice(): bool + { + return Property::query()->count() > 1; + } + + /** + * @return array + */ + public function options(): array + { + return Property::query()->orderBy('name')->get() + ->mapWithKeys(fn (Property $property): array => [$property->id => $property->is_active ? $property->name : $property->name.' (inaktiv)']) + ->all(); + } + + private function chosenId(): ?int + { + if (! app()->bound('session')) { + return null; + } + + $id = session()->get(self::SESSION_KEY.'.'.$this->tenantKey()); + + return is_numeric($id) ? (int) $id : null; + } + + private function tenantKey(): string + { + return (string) (app(TenantContext::class)->id() ?? 'none'); + } +} diff --git a/app/Themes/Sections/GallerySection.php b/app/Themes/Sections/GallerySection.php index 2cbe104..fb69e41 100644 --- a/app/Themes/Sections/GallerySection.php +++ b/app/Themes/Sections/GallerySection.php @@ -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()->with('media') + 'photos' => $this->withSeasonalPhotos($theme, $data, 'photo_ids', Photo::query()->published()->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 2afe8aa..9dd4df0 100644 --- a/app/Themes/Sections/HeroSection.php +++ b/app/Themes/Sections/HeroSection.php @@ -51,7 +51,9 @@ public static function photoSlots(): array public function data(Theme $theme, array $data): array { - $fallback = isset($data['photo_id']) ? Photo::find($data['photo_id']) : Photo::query()->published()->first(); + $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(); $featuredOffer = ($data['show_offer'] ?? true) && $theme->property() ? app(OfferShowcase::class)->current($theme->property(), limit: 1, featuredOnly: true)->first() : null; diff --git a/resources/views/filament/pages/occupancy-calendar.blade.php b/resources/views/filament/pages/occupancy-calendar.blade.php index 07c4093..3a81724 100644 --- a/resources/views/filament/pages/occupancy-calendar.blade.php +++ b/resources/views/filament/pages/occupancy-calendar.blade.php @@ -28,13 +28,6 @@ @php($calendar = $this->calendar)
- ← Zurück Weiter → diff --git a/resources/views/filament/property-switcher.blade.php b/resources/views/filament/property-switcher.blade.php new file mode 100644 index 0000000..81e75d1 --- /dev/null +++ b/resources/views/filament/property-switcher.blade.php @@ -0,0 +1,32 @@ +@php + /** Apartment switcher at the top of the admin menu (App\Support\CurrentProperty). */ + $current = app(\App\Support\CurrentProperty::class); + $property = $current->get(); +@endphp +@if ($property) +
+ + @if ($current->hasChoice()) +
+ @csrf + + + + @foreach ($current->options() as $id => $name) + + @endforeach + + + +
+ @else +

{{ $property->name }}

+ @endif + @can('update', $property) + + Einstellungen der Wohnung + + @endcan +
+
+@endif diff --git a/tests/Feature/CurrentPropertyTest.php b/tests/Feature/CurrentPropertyTest.php new file mode 100644 index 0000000..89c9f47 --- /dev/null +++ b/tests/Feature/CurrentPropertyTest.php @@ -0,0 +1,150 @@ +actingAs(User::factory()->create()); + $this->coast = Property::factory()->create(['name' => 'Küstenwohnung']); + $this->mountains = Property::factory()->create(['name' => 'Bergwohnung']); + } + + public function test_menu_shows_the_switcher_with_all_apartments_and_starts_with_the_first_active_one(): void + { + $this->get(OccupancyCalendar::getUrl()) + ->assertOk() + ->assertSee('Wohnung wählen') + ->assertSeeInOrder(['Bergwohnung', 'Küstenwohnung']) + ->assertSee('Einstellungen der Wohnung') + ->assertSee(PropertyResource::getUrl('edit', ['record' => $this->coast]), false); + } + + public function test_a_single_apartment_is_named_without_a_choice(): void + { + $this->mountains->delete(); + + $this->get(OccupancyCalendar::getUrl())->assertOk()->assertSee('Küstenwohnung')->assertDontSee('Wohnung wählen'); + } + + public function test_switching_returns_to_the_page_and_lists_follow_the_chosen_apartment(): void + { + Amenity::factory()->for($this->coast)->create(['name' => 'Strandkorb']); + Amenity::factory()->for($this->mountains)->create(['name' => 'Kachelofen']); + $list = AmenityResource::getUrl('index'); + + Livewire::test(ListAmenities::class)->assertSee('Strandkorb')->assertDontSee('Kachelofen'); + + $this->post(route('filament.admin.switch-property'), ['property' => $this->mountains->id, 'return' => $list])->assertRedirect($list); + + $this->assertSame($this->mountains->id, app(CurrentProperty::class)->id()); + Livewire::test(ListAmenities::class)->assertSee('Kachelofen')->assertDontSee('Strandkorb'); + } + + public function test_switching_leaves_a_record_page_for_its_list_and_the_apartment_settings_for_the_chosen_ones(): void + { + $amenity = Amenity::factory()->for($this->coast)->create(); + + $this->post(route('filament.admin.switch-property'), ['property' => $this->mountains->id, 'return' => AmenityResource::getUrl('edit', ['record' => $amenity])]) + ->assertRedirect(AmenityResource::getUrl('index')); + $this->post(route('filament.admin.switch-property'), ['property' => $this->coast->id, 'return' => PropertyResource::getUrl('edit', ['record' => $this->mountains])]) + ->assertRedirect(PropertyResource::getUrl('edit', ['record' => $this->coast])); + $this->post(route('filament.admin.switch-property'), ['property' => $this->coast->id, 'return' => OccupancyCalendar::getUrl(['monat' => '2026-11', 'wohnung' => $this->mountains->id])]) + ->assertRedirect(OccupancyCalendar::getUrl(['monat' => '2026-11'])); + $this->post(route('filament.admin.switch-property'), ['property' => $this->coast->id, 'return' => 'https://example.com/admin']) + ->assertRedirect(route('filament.admin.pages.dashboard')); + } + + public function test_another_landlords_apartment_cannot_be_chosen(): void + { + $foreign = Property::factory()->create(['tenant_id' => Tenant::factory()->create()->id]); + + $this->post(route('filament.admin.switch-property'), ['property' => $foreign->id])->assertNotFound(); + $this->assertSame($this->coast->id, app(CurrentProperty::class)->id()); + } + + public function test_opening_a_record_of_another_apartment_switches_to_it(): void + { + $amenity = Amenity::factory()->for($this->mountains)->create(); + + $this->get(AmenityResource::getUrl('edit', ['record' => $amenity]))->assertOk(); + + $this->assertSame($this->mountains->id, app(CurrentProperty::class)->id()); + } + + public function test_new_records_belong_to_the_chosen_apartment(): void + { + app(CurrentProperty::class)->select($this->mountains); + + Livewire::test(CreateAmenity::class)->assertSchemaStateSet(['property_id' => $this->mountains->id]); + } + + public function test_photo_list_shows_the_apartment_and_the_shared_area_photos(): void + { + app(CurrentProperty::class)->select($this->mountains); + $own = Photo::factory()->create(['property_id' => $this->mountains->id, 'alt_text' => 'Blick auf die Alpen']); + $area = Photo::factory()->create(['property_id' => null, 'category' => PhotoCategory::Area, 'alt_text' => 'Wanderweg']); + $other = Photo::factory()->create(['property_id' => $this->coast->id, 'alt_text' => 'Blick auf die Ostsee']); + + Livewire::test(ListPhotos::class)->assertCanSeeTableRecords([$own, $area])->assertCanNotSeeTableRecords([$other]); + } + + public function test_pages_for_one_apartment_follow_the_choice_and_name_it(): void + { + app(CurrentProperty::class)->select($this->mountains); + + Livewire::test(PricesAndOffers::class)->assertSet('propertyId', $this->mountains->id)->assertSee('Bergwohnung'); + $this->get(OccupancyCalendar::getUrl(['wohnung' => $this->coast->id]))->assertOk(); + $this->assertSame($this->coast->id, app(CurrentProperty::class)->id()); + } + + public function test_website_gallery_shows_only_the_photos_of_the_sections_apartment(): void + { + $this->withoutVite(); + $site = Site::factory()->create(['domain' => 'wohnungen.test', 'is_default' => true]); + $this->coast->update(['site_id' => $site->id]); + $this->mountains->update(['site_id' => $site->id]); + Photo::factory()->create(['property_id' => $this->coast->id, 'alt_text' => 'Blick auf die Ostsee']); + Photo::factory()->create(['property_id' => $this->mountains->id, 'alt_text' => 'Blick auf die Alpen']); + Photo::factory()->create(['property_id' => null, 'alt_text' => 'Gemeinsamer Ort']); + Page::factory()->for($site)->create([ + 'slug' => Page::HOME, + 'sections' => [['type' => 'gallery', 'data' => ['heading' => 'Bilder', 'property_id' => $this->mountains->id]]], + ]); + + $this->get('http://wohnungen.test/') + ->assertOk() + ->assertSee('Blick auf die Alpen') + ->assertSee('Gemeinsamer Ort') + ->assertDontSee('Blick auf die Ostsee'); + } +} From d02f3e05c7a00b89be9a43b59e1cba21429c233f Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 29 Oct 2026 18:43:02 +0100 Subject: [PATCH 2/5] Eigene Fotokategorie fuer Grundrisse und Plaene, nie in Galerien Co-Authored-By: Claude Opus 5.5 --- app/Enums/PhotoCategory.php | 13 +++++++ .../FloorPlans/Schemas/FloorPlanForm.php | 2 +- app/Models/Photo.php | 12 +++++++ app/Themes/Sections/GallerySection.php | 4 +-- app/Themes/Sections/HeroSection.php | 2 +- ...oor_plan_pictures_to_the_plan_category.php | 22 ++++++++++++ tests/Feature/FloorPlanTest.php | 34 +++++++++++++++++++ 7 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 database/migrations/2026_10_29_184027_move_floor_plan_pictures_to_the_plan_category.php 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(); From 791786ed3e01b10d091b9dd2a62975a2ed717e03 Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 29 Oct 2026 18:53:56 +0100 Subject: [PATCH 3/5] Saisonfotos am Foto statt am Erscheinungsbild Ein Foto gehoert zu keinem (ganzjaehrig) oder mehreren Erscheinungsbildern und erscheint nur dort, vor den ganzjaehrigen Fotos. Bausteine waehlen "automatisch" oder eine eigene Auswahl; Titelbereich und Abschluss zeigen das erste passende Foto ihrer Liste. Titelbild und "Bilder je Baustein" des Erscheinungsbilds werden in die Bausteine uebernommen und entfallen dort. Co-Authored-By: Claude Opus 5.5 --- app/Filament/Forms/Components/PhotoSelect.php | 3 +- .../Appearances/Schemas/AppearanceForm.php | 79 +++--------- .../Resources/Photos/Schemas/PhotoForm.php | 21 ++++ .../Resources/Photos/Tables/PhotosTable.php | 36 ++++++ app/Http/Controllers/PageController.php | 8 +- app/Models/Appearance.php | 50 ++++++-- app/Models/Photo.php | 58 ++++++++- app/Themes/Sections/CallToActionSection.php | 11 +- app/Themes/Sections/GallerySection.php | 15 +-- app/Themes/Sections/HeroSection.php | 14 +-- app/Themes/Sections/LocationSection.php | 13 +- app/Themes/Sections/Section.php | 112 +++++++++--------- app/Themes/Sections/TextImageSection.php | 10 +- app/Themes/Theme.php | 37 ++---- ...10_29_184538_give_photos_their_seasons.php | 101 ++++++++++++++++ docs/KONZEPT.md | 4 +- docs/STATUS.md | 2 +- docs/THEMES.md | 12 +- docs/ZUSAMMENARBEIT.md | 1 + docs/architecture/webseite.md | 2 +- tests/Feature/ThemeSystemTest.php | 95 +++++++++++---- 21 files changed, 449 insertions(+), 235 deletions(-) create mode 100644 database/migrations/2026_10_29_184538_give_photos_their_seasons.php diff --git a/app/Filament/Forms/Components/PhotoSelect.php b/app/Filament/Forms/Components/PhotoSelect.php index c1f0b52..a727a38 100644 --- a/app/Filament/Forms/Components/PhotoSelect.php +++ b/app/Filament/Forms/Components/PhotoSelect.php @@ -40,7 +40,8 @@ public static function optionLabel(Photo $photo): string ? '' : ''; $hidden = $photo->is_published ? '' : ' (ausgeblendet)'; + $seasons = $photo->appearanceNames() === [] ? '' : ' · nur '.e(implode(', ', $photo->appearanceNames())).''; - return ''.$image.''.e($photo->alt_text).$hidden.''; + return ''.$image.''.e($photo->alt_text).$seasons.$hidden.''; } } diff --git a/app/Filament/Resources/Appearances/Schemas/AppearanceForm.php b/app/Filament/Resources/Appearances/Schemas/AppearanceForm.php index 1ed71b2..defcf01 100644 --- a/app/Filament/Resources/Appearances/Schemas/AppearanceForm.php +++ b/app/Filament/Resources/Appearances/Schemas/AppearanceForm.php @@ -2,21 +2,15 @@ namespace App\Filament\Resources\Appearances\Schemas; -use App\Filament\Forms\Components\PhotoSelect; use App\Models\Appearance; -use App\Models\Page; +use App\Models\Photo; use App\Models\Site; -use App\Themes\SectionRegistry; -use App\Themes\Sections\Section as SectionBlock; use App\Themes\ThemeRegistry; use Closure; use Filament\Forms\Components\ColorPicker; -use Filament\Forms\Components\Radio; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; -use Filament\Schemas\Components\Component; -use Filament\Schemas\Components\Fieldset; use Filament\Schemas\Components\Section; use Filament\Schemas\Components\Text; use Filament\Schemas\Components\Utilities\Get; @@ -45,18 +39,11 @@ public static function configure(Schema $schema): Schema Toggle::make('is_default')->label('Standard (wenn kein Zeitraum passt)')->inline(false), Toggle::make('is_active')->label('Aktiv')->default(true)->inline(false), ]), - Section::make('Titelbild') - ->description('Gilt für alle Titelbereiche und als Vorschaubild beim Teilen in sozialen Medien – einzelne Bausteine können unten ein eigenes Bild bekommen. Sonderangebote werden unabhängig vom Erscheinungsbild beworben (Wohnung › Sonderangebote).') + Section::make('Bilder') + ->description('Welche Fotos in diesem Erscheinungsbild erscheinen, legen Sie beim Foto fest: Webseite › Fotos › „Zeigen in“. Ein Foto kann zu mehreren Erscheinungsbildern gehören; Fotos ohne Angabe erscheinen ganzjährig.') ->schema([ - PhotoSelect::make('hero_photo_id') - ->label('Titelbild') - ->placeholder('Bild der Seite verwenden'), + Text::make(fn (?Appearance $record): string => self::photoSummary($record)), ]), - Section::make('Bilder je Baustein') - ->description('Für jeden Baustein mit Bildern ein eigenes Saisonbild wählen. Leer = Bild aus der Seite. Neue Bilder laden Sie unter Webseite › Fotos hoch.') - ->collapsible() - ->columnSpanFull() - ->schema(fn (Get $get): array => self::sectionPhotoFields($get('site_id'))), Section::make('Texte') ->description('Leer lassen = Text der Seite bzw. kein Banner.') ->columns(2) @@ -75,57 +62,21 @@ public static function configure(Schema $schema): Schema } /** - * One group per page and one field set per placed section that has photo slots - * (see Section::photoSlots); stored in section_photos[
][]. - * - * @return list + * How many photos are made for this appearance. */ - public static function sectionPhotoFields(int|string|null $siteId): array + public static function photoSummary(?Appearance $appearance): string { - $registry = app(SectionRegistry::class); - $pages = Page::query()->where('site_id', $siteId)->orderBy('sort_order')->get(); - - $groups = []; - foreach ($pages as $page) { - $fieldsets = []; - foreach ($page->sections ?? [] as $stored) { - $class = $registry->all()[$stored['type'] ?? ''] ?? null; - $sectionId = $stored['data']['id'] ?? null; - if ($class === null || blank($sectionId) || $class::photoSlots() === []) { - continue; - } - - $fields = []; - foreach ($class::photoSlots() as $slot => $definition) { - $field = PhotoSelect::make("section_photos.{$sectionId}.{$slot}") - ->label($definition['label']) - ->placeholder('Standard (Bild aus der Seite)') - ->multiple($definition['type'] !== SectionBlock::SLOT_SINGLE); - if (isset($definition['max'])) { - $field->maxItems($definition['max']); - } - $fields[] = $field; - - if ($definition['type'] === SectionBlock::SLOT_COLLECTION) { - $fields[] = Radio::make("section_photos.{$sectionId}.mode") - ->label('Saisonbilder') - ->options(['replace' => 'ersetzen die Bilder des Bausteins', 'prepend' => 'kommen zuerst, danach die übrigen']) - ->default('replace') - ->inline(); - } - } - - $fieldsets[] = Fieldset::make(collect([$class::label(), $class::summary($stored['data'] ?? [])])->filter()->implode(' · ')) - ->columns(1) - ->schema($fields); - } - - if ($fieldsets !== []) { - $groups[] = Section::make($page->title)->compact()->collapsible()->schema($fieldsets); - } + if ($appearance === null) { + return 'Nach dem Speichern können Sie Fotos diesem Erscheinungsbild zuordnen.'; } - return $groups ?: [Text::make('Auf den Seiten gibt es noch keine Bausteine mit Bildern.')]; + $count = Photo::query()->get(['id', 'appearance_ids'])->filter(fn (Photo $photo): bool => $photo->isMadeFor($appearance))->count(); + + return match ($count) { + 0 => 'Noch keine Fotos zugeordnet – es erscheinen die ganzjährigen Fotos.', + 1 => '1 Foto ist diesem Erscheinungsbild zugeordnet.', + default => "{$count} Fotos sind diesem Erscheinungsbild zugeordnet.", + }; } /** diff --git a/app/Filament/Resources/Photos/Schemas/PhotoForm.php b/app/Filament/Resources/Photos/Schemas/PhotoForm.php index 6326622..196d36a 100644 --- a/app/Filament/Resources/Photos/Schemas/PhotoForm.php +++ b/app/Filament/Resources/Photos/Schemas/PhotoForm.php @@ -3,6 +3,7 @@ namespace App\Filament\Resources\Photos\Schemas; use App\Enums\PhotoCategory; +use App\Models\Appearance; use App\Models\Photo; use App\Models\Property; use App\Support\CurrentProperty; @@ -47,9 +48,29 @@ public static function configure(Schema $schema): Schema ->options(fn (): array => Property::query()->pluck('name', 'id')->all()) ->default(fn (): ?int => app(CurrentProperty::class)->id()) ->placeholder('– keine (z. B. Umgebung) –'), + Select::make('appearance_ids') + ->label('Zeigen in') + ->multiple() + ->options(fn (): array => Appearance::photoOptions()) + ->placeholder('ganzjährig') + ->helperText('Leer = ganzjährig. Mit Auswahl erscheint das Foto nur in diesen Erscheinungsbildern – dann vor den ganzjährigen Fotos.') + ->dehydrateStateUsing(fn (?array $state): ?array => self::appearanceIds($state)), Toggle::make('is_published') ->label('Auf der Webseite zeigen') ->default(true), ]); } + + /** + * Selected appearances as integers, null for "all year". + * + * @param array|null $state + * @return list|null + */ + public static function appearanceIds(?array $state): ?array + { + $ids = array_values(array_unique(array_map('intval', array_filter((array) $state)))); + + return $ids === [] ? null : $ids; + } } diff --git a/app/Filament/Resources/Photos/Tables/PhotosTable.php b/app/Filament/Resources/Photos/Tables/PhotosTable.php index c7b495c..758a189 100644 --- a/app/Filament/Resources/Photos/Tables/PhotosTable.php +++ b/app/Filament/Resources/Photos/Tables/PhotosTable.php @@ -3,17 +3,23 @@ namespace App\Filament\Resources\Photos\Tables; use App\Enums\PhotoCategory; +use App\Filament\Resources\Photos\Schemas\PhotoForm; +use App\Models\Appearance; use App\Models\Photo; +use Filament\Actions\BulkAction; use Filament\Actions\BulkActionGroup; use Filament\Actions\DeleteAction; use Filament\Actions\DeleteBulkAction; use Filament\Actions\EditAction; +use Filament\Forms\Components\Select; use Filament\Tables\Columns\IconColumn; use Filament\Tables\Columns\Layout\Stack; use Filament\Tables\Columns\SpatieMediaLibraryImageColumn; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; class PhotosTable { @@ -36,6 +42,12 @@ public static function configure(Table $table): Table ->searchable(), TextColumn::make('category') ->badge(), + TextColumn::make('appearance_ids') + ->label('Zeigen in') + ->state(fn (Photo $record): array => $record->appearanceNames()) + ->badge() + ->color('warning') + ->icon('heroicon-m-sun'), IconColumn::make('is_published') ->boolean() ->trueIcon('heroicon-o-eye') @@ -46,6 +58,14 @@ public static function configure(Table $table): Table SelectFilter::make('category') ->label('Kategorie') ->options(PhotoCategory::class), + SelectFilter::make('season') + ->label('Zeigen in') + ->options(fn (): array => ['all_year' => 'ganzjährig', ...Appearance::photoOptions()]) + ->query(fn (Builder $query, array $data): Builder => match (true) { + blank($data['value'] ?? null) => $query, + $data['value'] === 'all_year' => $query->where(fn (Builder $query) => $query->whereNull('appearance_ids')->orWhereJsonLength('appearance_ids', 0)), + default => $query->whereJsonContains('appearance_ids', (int) $data['value']), + }), ]) ->recordActions([ EditAction::make(), @@ -53,6 +73,22 @@ public static function configure(Table $table): Table ]) ->toolbarActions([ BulkActionGroup::make([ + BulkAction::make('seasons') + ->label('Zeigen in …') + ->icon('heroicon-o-sun') + ->schema([ + Select::make('appearance_ids') + ->label('Zeigen in') + ->multiple() + ->options(fn (): array => Appearance::photoOptions()) + ->placeholder('ganzjährig') + ->helperText('Leer = ganzjährig. Ersetzt die bisherige Zuordnung der ausgewählten Fotos.'), + ]) + ->action(function (Collection $records, array $data): void { + $records->each(fn (Photo $photo) => $photo->update(['appearance_ids' => PhotoForm::appearanceIds($data['appearance_ids'] ?? [])])); + }) + ->authorizeIndividualRecords('update') + ->deselectRecordsAfterCompletion(), DeleteBulkAction::make(), ]), ]); diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index dece92b..0a96d21 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -43,8 +43,8 @@ public function show(string $slug): View 'sections' => $this->sections->render($this->theme(), $page->sections), 'title' => $page->isHome() ? null : ($page->seo_title ?: $page->title), 'description' => $page->seo_description ?: ($page->isHome() ? Content::get('seo.home.description') : null), - 'ogImage' => $this->theme()->heroPhoto()?->url('lg') ?: null, - 'structuredData' => $page->isHome() ? $this->structuredData() : null, + 'ogImage' => $this->theme()->sharePhoto($page->sections ?? [])?->url('lg') ?: null, + 'structuredData' => $page->isHome() ? $this->structuredData($page) : null, ]); } @@ -77,7 +77,7 @@ public function robots(): Response * * @return array|null */ - private function structuredData(): ?array + private function structuredData(Page $page): ?array { $property = $this->theme()->property(); if ($property === null) { @@ -89,7 +89,7 @@ private function structuredData(): ?array '@type' => 'VacationRental', 'name' => $property->name, 'url' => route('home'), - 'image' => $this->theme()->heroPhoto()?->url('lg') ?: null, + 'image' => $this->theme()->sharePhoto($page->sections ?? [])?->url('lg') ?: null, 'address' => ['@type' => 'PostalAddress', 'streetAddress' => str($property->address)->before(',')->trim()->toString(), 'addressLocality' => 'Kühlungsborn', 'postalCode' => '18225', 'addressCountry' => 'DE'], 'containsPlace' => ['@type' => 'Accommodation', 'floorSize' => ['@type' => 'QuantitativeValue', 'value' => $property->size_sqm, 'unitCode' => 'MTK'], 'occupancy' => ['@type' => 'QuantitativeValue', 'maxValue' => $property->max_guests]], 'telephone' => config('fewo.owner.phone'), diff --git a/app/Models/Appearance.php b/app/Models/Appearance.php index 323d672..247313c 100644 --- a/app/Models/Appearance.php +++ b/app/Models/Appearance.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Models\Concerns\BelongsToTenant; +use App\Tenancy\TenantContext; use Carbon\CarbonInterface; use Database\Factories\AppearanceFactory; use Illuminate\Database\Eloquent\Attributes\Fillable; @@ -11,12 +12,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; /** - * A seasonal look of a site (e.g. summer, winter, Christmas, New Year's Eve): colour tokens, hero photo, - * photos per section, texts and banner change – the page structure does not (sections may be limited to + * A seasonal look of a site (e.g. summer, winter, Christmas, New Year's Eve): colour tokens, texts and banner + * change, photos made for it (Photo::appearance_ids) are shown – the page structure does not (sections may be limited to * appearances, see SectionRegistry). Offers are advertised by their own rules (OfferShowcase). The period recurs every year ("MM-DD" to "MM-DD", * inclusive; a period may run over the turn of the year). The default appearance applies when none matches. */ -#[Fillable(['site_id', 'name', 'starts_md', 'ends_md', 'priority', 'is_default', 'is_active', 'tokens', 'overrides', 'hero_photo_id', 'section_photos'])] +#[Fillable(['site_id', 'name', 'starts_md', 'ends_md', 'priority', 'is_default', 'is_active', 'tokens', 'overrides'])] class Appearance extends Model { /** @use HasFactory */ @@ -48,7 +49,6 @@ protected function casts(): array 'is_active' => 'boolean', 'tokens' => 'array', 'overrides' => 'array', - 'section_photos' => 'array', ]; } @@ -61,11 +61,47 @@ public function site(): BelongsTo } /** - * @return BelongsTo + * Names by id of the landlord's appearances, loaded once per request and landlord. + * + * @return array */ - public function heroPhoto(): BelongsTo + public static function names(): array { - return $this->belongsTo(Photo::class, 'hero_photo_id'); + // once() keys its cache by the closure's bound variables, so each landlord gets its own entry. + $tenantId = app(TenantContext::class)->id(); + + return once(function (): array { + return self::query()->pluck('name', 'id')->all(); + }); + } + + /** + * Choices for "Zeigen in" at the photos, e.g. "Winter · 01.11.–31.03."; with several websites prefixed by the website. + * + * @return array + */ + public static function photoOptions(): array + { + $appearances = self::query()->with('site')->orderByDesc('is_default')->orderBy('starts_md')->orderBy('name')->get(); + $severalSites = $appearances->pluck('site_id')->unique()->count() > 1; + + return $appearances->mapWithKeys(fn (Appearance $appearance): array => [ + $appearance->id => ($severalSites ? $appearance->site?->name.': ' : '').$appearance->periodLabel(), + ])->all(); + } + + /** + * "Winter · 01.11.–31.03.", "Standard · wenn kein Zeitraum passt". + */ + public function periodLabel(): string + { + if ($this->starts_md === null || $this->ends_md === null) { + return $this->name.($this->is_default ? ' · wenn kein Zeitraum passt' : ''); + } + + $day = fn (string $monthDay): string => substr($monthDay, 3, 2).'.'.substr($monthDay, 0, 2).'.'; + + return $this->name.' · '.$day($this->starts_md).'–'.$day($this->ends_md); } public function covers(CarbonInterface $date): bool diff --git a/app/Models/Photo.php b/app/Models/Photo.php index 8f75e2f..70cc159 100644 --- a/app/Models/Photo.php +++ b/app/Models/Photo.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Attributes\Scope; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection as EloquentCollection; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -18,8 +19,10 @@ /** * A website photo. The uploaded original is kept; web sizes are generated as WebP on upload. + * A photo may belong to appearances (seasons such as summer, winter, Christmas): then it is only shown while + * one of them is in effect, and ahead of the all-year photos. Without appearances it is shown all year. */ -#[Fillable(['property_id', 'category', 'alt_text', 'caption', 'is_published', 'sort_order'])] +#[Fillable(['property_id', 'category', 'appearance_ids', 'alt_text', 'caption', 'is_published', 'sort_order'])] class Photo extends Model implements HasMedia { /** @use HasFactory */ @@ -39,6 +42,7 @@ protected function casts(): array { return [ 'category' => PhotoCategory::class, + 'appearance_ids' => 'array', 'is_published' => 'boolean', ]; } @@ -107,6 +111,58 @@ protected function forProperty(Builder $query, ?Property $property): Builder : $query->where(fn (Builder $query) => $query->where('property_id', $property->id)->orWhereNull('property_id')); } + /** + * Photos picked automatically: published, of the apartment and those without one, never plans, fitting the + * season – photos made for the appearance in effect first, then the all-year photos in their order. + * + * @return EloquentCollection + */ + public static function automatic(?Property $property, ?Appearance $appearance, ?PhotoCategory $category = null): EloquentCollection + { + return self::query()->published()->forGalleries()->forProperty($property)->with('media') + ->when($category, fn (Builder $query) => $query->where('category', $category)) + ->get() + ->filter(fn (Photo $photo): bool => $photo->fitsSeason($appearance)) + ->sortBy(fn (Photo $photo): int => $photo->isMadeFor($appearance) ? 0 : 1) + ->values(); + } + + /** + * Appearance ids as integers (the form may deliver strings). + * + * @return list + */ + public function appearanceIds(): array + { + return array_values(array_unique(array_map('intval', array_filter((array) $this->appearance_ids)))); + } + + /** + * Whether the photo may be shown while this appearance is in effect: all-year photos always, seasonal ones in their seasons. + */ + public function fitsSeason(?Appearance $appearance): bool + { + return $this->appearanceIds() === [] || $this->isMadeFor($appearance); + } + + /** + * Whether the photo was chosen for this appearance (seasonal photos come first while it is in effect). + */ + public function isMadeFor(?Appearance $appearance): bool + { + return $appearance !== null && in_array($appearance->id, $this->appearanceIds(), true); + } + + /** + * Names of the appearances the photo is made for (empty = all year). + * + * @return list + */ + public function appearanceNames(): array + { + return array_values(array_intersect_key(Appearance::names(), array_flip($this->appearanceIds()))); + } + public function url(string $size = 'md'): string { return $this->getFirstMediaUrl(self::COLLECTION, $size); diff --git a/app/Themes/Sections/CallToActionSection.php b/app/Themes/Sections/CallToActionSection.php index 3ead6c1..2e4f7d2 100644 --- a/app/Themes/Sections/CallToActionSection.php +++ b/app/Themes/Sections/CallToActionSection.php @@ -2,7 +2,6 @@ namespace App\Themes\Sections; -use App\Models\Photo; use App\Themes\Theme; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; @@ -32,23 +31,19 @@ public static function schema(): array return [ TextInput::make('title')->label('Überschrift')->required()->maxLength(160), Textarea::make('text')->label('Text')->rows(2), - static::photoSelect('photo_id', 'Hintergrundfoto'), + static::photoSelect('photo_ids', 'Hintergrundfotos', multiple: true) + ->helperText('Gezeigt wird das erste, das zum Erscheinungsbild passt. '.self::SEASON_HINT), TextInput::make('button_label')->label('Button-Text')->default('Belegung & Preise')->maxLength(60), static::pageSelect('button_page', 'Button führt zu'), ]; } - public static function photoSlots(): array - { - return ['photo_id' => ['label' => 'Hintergrundfoto', 'type' => self::SLOT_SINGLE]]; - } - public function data(Theme $theme, array $data): array { return [ 'title' => $theme->text('cta.title', $data['title'] ?? null), 'text' => $theme->text('cta.text', $data['text'] ?? null), - 'photo' => $this->seasonalPhoto($theme, $data, 'photo_id') ?? (isset($data['photo_id']) ? Photo::find($data['photo_id']) : null), + 'photo' => $this->chosenPhotos($theme, $data['photo_ids'] ?? [])->first(), 'buttonLabel' => $data['button_label'] ?? 'Belegung & Preise', 'buttonUrl' => $this->pageUrl($data['button_page'] ?? null) ?? route('booking.create'), ]; diff --git a/app/Themes/Sections/GallerySection.php b/app/Themes/Sections/GallerySection.php index b7d7b41..20c18f9 100644 --- a/app/Themes/Sections/GallerySection.php +++ b/app/Themes/Sections/GallerySection.php @@ -3,10 +3,10 @@ namespace App\Themes\Sections; use App\Enums\PhotoCategory; -use App\Models\Photo; use App\Themes\Theme; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; +use Filament\Schemas\Components\Utilities\Get; /** * Photo gallery of one category (or all), opened in a lightbox. @@ -32,26 +32,19 @@ public static function schema(): array { return [ TextInput::make('heading')->label('Überschrift')->maxLength(120), - Select::make('category')->label('Bilder')->options(['all' => 'Alle', ...collect(PhotoCategory::forGalleries())->mapWithKeys(fn (PhotoCategory $category): array => [$category->value => $category->getLabel()])->all()])->default('all'), + ...static::photoSourceFields('Automatisch nach Kategorie'), + Select::make('category')->label('Kategorie')->visible(fn (Get $get): bool => $get('photo_source') !== 'selection')->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), ]; } - public static function photoSlots(): array - { - return ['photo_ids' => ['label' => 'Galerie', 'type' => self::SLOT_COLLECTION]]; - } - public function data(Theme $theme, array $data): array { $category = PhotoCategory::tryFrom($data['category'] ?? ''); return [ 'heading' => $data['heading'] ?? null, - '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()), + 'photos' => $this->sourcedPhotos($theme, $data, $category, filled($data['limit'] ?? null) ? (int) $data['limit'] : null), ]; } } diff --git a/app/Themes/Sections/HeroSection.php b/app/Themes/Sections/HeroSection.php index 7d9e597..80a5782 100644 --- a/app/Themes/Sections/HeroSection.php +++ b/app/Themes/Sections/HeroSection.php @@ -2,7 +2,6 @@ namespace App\Themes\Sections; -use App\Models\Photo; use App\Pricing\OfferShowcase; use App\Themes\Theme; use Filament\Forms\Components\Textarea; @@ -35,7 +34,8 @@ public static function schema(): array TextInput::make('eyebrow')->label('Kleine Überschrift')->maxLength(100), TextInput::make('title')->label('Überschrift')->helperText('*Wort* wird hervorgehoben (kursiv).')->required()->maxLength(160), Textarea::make('text')->label('Text')->rows(2)->maxLength(400), - static::photoSelect('photo_id', 'Foto (wenn das Erscheinungsbild keins vorgibt)'), + static::photoSelect('photo_ids', 'Fotos', multiple: true) + ->helperText('Gezeigt wird das erste Foto, das zum Erscheinungsbild passt; leer = automatisch ein Foto der Wohnung. '.self::SEASON_HINT), Toggle::make('show_search')->label('Verfügbarkeitssuche anzeigen')->default(true), Toggle::make('show_offer') ->label('Hervorgehobenes Sonderangebot im Titelbereich zeigen') @@ -44,16 +44,8 @@ public static function schema(): array ]; } - public static function photoSlots(): array - { - return ['photo_id' => ['label' => 'Foto', 'type' => self::SLOT_SINGLE]]; - } - public function data(Theme $theme, array $data): array { - $fallback = isset($data['photo_id']) - ? Photo::find($data['photo_id']) - : 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; @@ -62,7 +54,7 @@ public function data(Theme $theme, array $data): array 'eyebrow' => $theme->text('hero.eyebrow', $data['eyebrow'] ?? null), 'title' => $theme->text('hero.title', $data['title'] ?? $theme->site->name), 'text' => $theme->text('hero.text', $data['text'] ?? null), - 'photo' => $this->seasonalPhoto($theme, $data, 'photo_id') ?? $theme->heroPhoto($fallback), + 'photo' => $this->chosenPhotos($theme, $data['photo_ids'] ?? [])->first() ?? $this->automaticPhotos($theme, limit: 1)->first(), 'featuredOffer' => $featuredOffer, 'showSearch' => (bool) ($data['show_search'] ?? true), 'property' => $theme->property(), diff --git a/app/Themes/Sections/LocationSection.php b/app/Themes/Sections/LocationSection.php index 4b64e3f..051dab6 100644 --- a/app/Themes/Sections/LocationSection.php +++ b/app/Themes/Sections/LocationSection.php @@ -3,11 +3,12 @@ namespace App\Themes\Sections; use App\Enums\PhotoCategory; -use App\Models\Photo; use App\Themes\Theme; use Filament\Forms\Components\RichEditor; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; +use Filament\Schemas\Components\Group; +use Filament\Schemas\Components\Utilities\Get; /** * Location: text, photos of the area and a map link (no embedded third-party map, so no consent needed). @@ -35,15 +36,11 @@ public static function schema(): array TextInput::make('eyebrow')->label('Kleine Überschrift')->maxLength(100), TextInput::make('heading')->label('Überschrift')->required()->maxLength(160), RichEditor::make('text')->label('Text')->toolbarButtons([['bold', 'italic', 'link'], ['bulletList']]), - Toggle::make('show_photos')->label('Bilder der Umgebung zeigen')->default(true), + Toggle::make('show_photos')->label('Bilder zeigen')->default(true)->live(), + Group::make(static::photoSourceFields('Automatisch: Fotos der Umgebung'))->visible(fn (Get $get): bool => (bool) $get('show_photos')), ]; } - public static function photoSlots(): array - { - return ['photo_ids' => ['label' => 'Bilder der Umgebung', 'type' => self::SLOT_COLLECTION]]; - } - public function data(Theme $theme, array $data): array { $address = $theme->property()?->address; @@ -55,7 +52,7 @@ public function data(Theme $theme, array $data): array 'address' => $address, 'mapUrl' => $address ? 'https://www.openstreetmap.org/search?query='.rawurlencode($address) : null, 'photos' => ($data['show_photos'] ?? true) - ? $this->withSeasonalPhotos($theme, $data, 'photo_ids', Photo::query()->published()->with('media')->where('category', PhotoCategory::Area)->limit(6)->get()) + ? $this->sourcedPhotos($theme, $data, PhotoCategory::Area, 6) : collect(), ]; } diff --git a/app/Themes/Sections/Section.php b/app/Themes/Sections/Section.php index 11d0300..cbdd31e 100644 --- a/app/Themes/Sections/Section.php +++ b/app/Themes/Sections/Section.php @@ -2,13 +2,16 @@ namespace App\Themes\Sections; +use App\Enums\PhotoCategory; use App\Filament\Forms\Components\PhotoSelect; use App\Models\Page; use App\Models\Photo; use App\Themes\Theme; +use Filament\Forms\Components\Radio; use Filament\Forms\Components\RichEditor\RichContentRenderer; use Filament\Forms\Components\Select; use Filament\Schemas\Components\Component; +use Filament\Schemas\Components\Utilities\Get; use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\HtmlString; @@ -18,14 +21,8 @@ */ abstract class Section { - /** One photo (field holds a photo id). */ - public const SLOT_SINGLE = 'single'; - - /** Several chosen photos (field holds a list of ids). */ - public const SLOT_MULTIPLE = 'multiple'; - - /** Photos picked automatically (e.g. by category); an appearance may replace or precede them. */ - public const SLOT_COLLECTION = 'collection'; + /** How photos follow the seasons – shown below every photo choice. */ + public const SEASON_HINT = 'Fotos mit Saison (Webseite › Fotos › „Zeigen in“) erscheinen nur in ihrem Erscheinungsbild, alle anderen ganzjährig.'; abstract public static function key(): string; @@ -49,16 +46,6 @@ public static function schema(): array return []; } - /** - * Photo places an appearance can fill with seasonal photos ("Bilder je Baustein"). - * - * @return array - */ - public static function photoSlots(): array - { - return []; - } - /** * Short text identifying a placed section in admin lists, e.g. its heading. * @@ -108,52 +95,63 @@ protected function photos(?array $ids): Collection } /** - * The seasonal photo the active appearance sets for a single slot of this placed section. + * Chosen photos in the editor's order: published and fitting the season in effect. * - * @param array $data - */ - protected function seasonalPhoto(Theme $theme, array $data, string $slot): ?Photo - { - return $this->seasonalPhotos($theme, $data, $slot)?->first(); - } - - /** - * The seasonal photos the active appearance sets for a slot of this placed section, null if none. - * - * @param array $data - * @return Collection|null - */ - protected function seasonalPhotos(Theme $theme, array $data, string $slot): ?Collection - { - $ids = $theme->sectionPhotoIds($data['id'] ?? null, $slot); - if ($ids === []) { - return null; - } - - $photos = $this->photos($ids); - - return $photos->isEmpty() ? null : $photos; - } - - /** - * Photos of a collection slot: the automatic photos, replaced or preceded by the seasonal ones. - * - * @param array $data - * @param Collection $automatic + * @param list|null $ids * @return Collection */ - protected function withSeasonalPhotos(Theme $theme, array $data, string $slot, Collection $automatic): Collection + protected function chosenPhotos(Theme $theme, ?array $ids): Collection { - $seasonal = $this->seasonalPhotos($theme, $data, $slot); - if ($seasonal === null) { - return $automatic; + return $this->photos($ids)->filter(fn (Photo $photo): bool => $photo->fitsSeason($theme->appearance))->values(); + } + + /** + * Photos picked automatically for the section's apartment and the season (Photo::automatic). + * + * @return Collection + */ + protected function automaticPhotos(Theme $theme, ?PhotoCategory $category = null, ?int $limit = null): Collection + { + $photos = Photo::automatic($theme->property(), $theme->appearance, $category); + + return $limit !== null ? $photos->take($limit)->values() : $photos; + } + + /** + * Photos of a section that offers "automatisch" or "eigene Auswahl" (fields from photoSourceFields()). + * + * @param array $data + * @return Collection + */ + protected function sourcedPhotos(Theme $theme, array $data, ?PhotoCategory $category = null, ?int $limit = null): Collection + { + if (($data['photo_source'] ?? 'auto') === 'selection') { + $photos = $this->chosenPhotos($theme, $data['photo_ids'] ?? []); + + return $limit !== null ? $photos->take($limit)->values() : $photos; } - if ($theme->sectionPhotoMode($data['id'] ?? null) === 'prepend') { - return $seasonal->merge($automatic)->unique('id')->values(); - } + return $this->automaticPhotos($theme, $category, $limit); + } - return $seasonal; + /** + * "Automatisch" or "Eigene Auswahl" plus the selection field, shown only for a selection. + * + * @return list + */ + protected static function photoSourceFields(string $automaticLabel): array + { + return [ + Radio::make('photo_source') + ->label('Bilder') + ->options(['auto' => $automaticLabel, 'selection' => 'Eigene Auswahl']) + ->default('auto') + ->inline() + ->live(), + static::photoSelect('photo_ids', 'Ausgewählte Bilder', multiple: true) + ->helperText(self::SEASON_HINT) + ->visible(fn (Get $get): bool => $get('photo_source') === 'selection'), + ]; } protected function pageUrl(?string $slug): ?string diff --git a/app/Themes/Sections/TextImageSection.php b/app/Themes/Sections/TextImageSection.php index a5600ee..2fb2120 100644 --- a/app/Themes/Sections/TextImageSection.php +++ b/app/Themes/Sections/TextImageSection.php @@ -33,25 +33,21 @@ public static function schema(): array TextInput::make('eyebrow')->label('Kleine Überschrift')->maxLength(100), TextInput::make('heading')->label('Überschrift')->required()->maxLength(160), RichEditor::make('text')->label('Text')->toolbarButtons([['bold', 'italic', 'link'], ['bulletList', 'orderedList']]), - static::photoSelect('photo_ids', 'Bilder (bis zu 3)', multiple: true)->maxItems(3), + static::photoSelect('photo_ids', 'Bilder', multiple: true)->maxItems(9) + ->helperText('Gezeigt werden die ersten drei, die zum Erscheinungsbild passen. '.self::SEASON_HINT), Select::make('image_position')->label('Bilder')->options(['right' => 'rechts', 'left' => 'links'])->default('right'), TextInput::make('link_label')->label('Link-Text')->maxLength(80), static::pageSelect('link_page', 'Link zur Seite'), ]; } - public static function photoSlots(): array - { - return ['photo_ids' => ['label' => 'Bilder', 'type' => self::SLOT_MULTIPLE, 'max' => 3]]; - } - public function data(Theme $theme, array $data): array { return [ 'eyebrow' => $data['eyebrow'] ?? null, 'heading' => $data['heading'] ?? '', 'text' => $this->html($data['text'] ?? null), - 'photos' => $this->seasonalPhotos($theme, $data, 'photo_ids') ?? $this->photos($data['photo_ids'] ?? []), + 'photos' => $this->chosenPhotos($theme, $data['photo_ids'] ?? [])->take(3)->values(), 'imagePosition' => $data['image_position'] ?? 'right', 'linkLabel' => $data['link_label'] ?? null, 'linkUrl' => $this->pageUrl($data['link_page'] ?? null), diff --git a/app/Themes/Theme.php b/app/Themes/Theme.php index acc66c2..20c30b6 100644 --- a/app/Themes/Theme.php +++ b/app/Themes/Theme.php @@ -95,35 +95,24 @@ public function text(string $key, ?string $fallback = null): ?string return $this->appearance?->override($key) ?? $fallback; } - public function heroPhoto(?Photo $fallback = null): ?Photo - { - return $this->appearance?->heroPhoto ?? $fallback; - } - /** - * Photo ids the active appearance sets for a slot of a placed section ("Bilder je Baustein"). + * Picture for link previews (social media, messengers) and search engines: the first photo of the page's + * title area that fits the season, else an automatic photo of the apartment. * - * @return list + * @param list> $sections the page's placed sections */ - public function sectionPhotoIds(?string $sectionId, string $slot): array + public function sharePhoto(array $sections = []): ?Photo { - if (blank($sectionId) || $this->appearance === null) { - return []; - } + $chosen = collect($sections) + ->filter(fn (array $section): bool => ($section['type'] ?? null) === 'hero') + ->flatMap(fn (array $section): array => (array) ($section['data']['photo_ids'] ?? [])) + ->map(fn ($id): int => (int) $id) + ->all(); + $photos = Photo::query()->published()->whereKey($chosen)->with('media')->get()->keyBy('id'); + $first = collect($chosen)->map(fn (int $id): ?Photo => $photos->get($id)) + ->first(fn (?Photo $photo): bool => $photo?->fitsSeason($this->appearance) ?? false); - $ids = $this->appearance->section_photos[$sectionId][$slot] ?? null; - - return array_values(array_map('intval', array_filter((array) $ids))); - } - - /** - * Whether seasonal photos replace the automatic photos of a section ('replace') or come first ('prepend'). - */ - public function sectionPhotoMode(?string $sectionId): string - { - $mode = $sectionId ? ($this->appearance?->section_photos[$sectionId]['mode'] ?? null) : null; - - return $mode === 'prepend' ? 'prepend' : 'replace'; + return $first ?? Photo::automatic($this->property(), $this->appearance)->first(); } public function appearanceKey(): string diff --git a/database/migrations/2026_10_29_184538_give_photos_their_seasons.php b/database/migrations/2026_10_29_184538_give_photos_their_seasons.php new file mode 100644 index 0000000..238ad70 --- /dev/null +++ b/database/migrations/2026_10_29_184538_give_photos_their_seasons.php @@ -0,0 +1,101 @@ +json('appearance_ids')->nullable()->after('category'); + }); + + $pages = DB::table('pages')->get(['id', 'site_id', 'sections']) + ->map(fn (object $page): object => (object) ['id' => $page->id, 'site_id' => $page->site_id, 'sections' => json_decode((string) $page->sections, true) ?: []]); + $tags = []; + + foreach (DB::table('appearances')->get() as $appearance) { + $sitePages = $pages->where('site_id', $appearance->site_id); + $seasonal = ! $appearance->is_default; + + if ($appearance->hero_photo_id !== null) { + if ($seasonal) { + $tags[$appearance->hero_photo_id][] = $appearance->id; + } + foreach ($sitePages as $page) { + foreach ($page->sections as $index => $section) { + if (($section['type'] ?? null) === 'hero') { + $page->sections[$index]['data']['photo_ids'] = $this->prepend([$appearance->hero_photo_id], $section['data']['photo_ids'] ?? []); + } + } + } + } + + foreach (json_decode((string) $appearance->section_photos, true) ?: [] as $sectionId => $slots) { + $ids = collect($slots)->except('mode')->flatten()->filter()->map(fn ($id): int => (int) $id)->all(); + foreach ($seasonal ? $ids : [] as $id) { + $tags[$id][] = $appearance->id; + } + + foreach ($sitePages as $page) { + foreach ($page->sections as $index => $section) { + if (($section['data']['id'] ?? null) === $sectionId && in_array($section['type'] ?? null, ['hero', 'cta', 'text_image'], true)) { + $page->sections[$index]['data']['photo_ids'] = $this->prepend($ids, $section['data']['photo_ids'] ?? []); + } + } + } + } + } + + foreach ($pages as $page) { + foreach ($page->sections as $index => $section) { + if (in_array($section['type'] ?? null, ['hero', 'cta'], true) && array_key_exists('photo_id', $section['data'] ?? [])) { + $legacy = $section['data']['photo_id']; + unset($page->sections[$index]['data']['photo_id']); + $page->sections[$index]['data']['photo_ids'] = array_values(array_unique([...($page->sections[$index]['data']['photo_ids'] ?? []), ...array_filter([(int) $legacy])])); + } + } + DB::table('pages')->where('id', $page->id)->update(['sections' => json_encode($page->sections)]); + } + + foreach ($tags as $photoId => $appearanceIds) { + DB::table('photos')->where('id', $photoId)->update(['appearance_ids' => json_encode(array_values(array_unique($appearanceIds)))]); + } + + Schema::table('appearances', function (Blueprint $table) { + $table->dropConstrainedForeignId('hero_photo_id'); + $table->dropColumn('section_photos'); + }); + } + + public function down(): void + { + Schema::table('appearances', function (Blueprint $table) { + $table->foreignId('hero_photo_id')->nullable()->constrained('photos')->nullOnDelete(); + $table->json('section_photos')->nullable()->after('hero_photo_id'); + }); + + Schema::table('photos', function (Blueprint $table) { + $table->dropColumn('appearance_ids'); + }); + } + + /** + * @param list $first + * @param list $rest + * @return list + */ + private function prepend(array $first, array $rest): array + { + return array_values(array_unique(array_map('intval', [...$first, ...$rest]))); + } +}; diff --git a/docs/KONZEPT.md b/docs/KONZEPT.md index 4f5b939..891a71f 100644 --- a/docs/KONZEPT.md +++ b/docs/KONZEPT.md @@ -48,7 +48,7 @@ ## 4a. Theme- und Vorlagensystem (Entscheidungen vom 22.10.2026 – umgesetzt, D - **Themes** (Design) als Code-Pakete mit Manifest, eigenen Vorlagen und eigenem CSS; was ein Theme nicht mitbringt, kommt aus einem vollständigen **Basis-Theme** (Child-Theme-Prinzip). Erstes Theme: **„Ostsee-Licht“** (Entwurf A, orientiert an der bisherigen Webseite). Die Entwürfe B/C können später als weitere Themes folgen. - **Bausteinsystem (geführt):** Seiten werden aus einem festen Katalog von Abschnitten zusammengestellt (Reihenfolge, Sichtbarkeit); Seiten und Menüs können je Ausrichtung unterschiedlich sein. Keine freie Seitengestaltung. -- **Saisonale Erscheinungsbilder:** wechseln Fotos (Titelbild und **Bilder je Baustein**), Texte, Farben/Akzente und Banner – nicht den Aufbau. Bausteine können **nur in bestimmten Erscheinungsbildern** erscheinen (z. B. ein Weihnachts-Baustein). Sonderangebote werden seit 22.10.2026 **unabhängig** davon nach eigenen Regeln beworben (5a). Zeitplan jährlich wiederkehrend mit Priorität und Standard; Vorschau-Link vor Aktivierung. Startset: **Sommer** (Strand, Baden), **Winter** (raue See, stimmungsvoller Himmel), **Weihnachten** (gemütlich, besinnlich), **Silvester** (Party, Feuerwerk). Klickbare Vorschau: lokale HTML-Datei (Scratchpad der Sitzung). +- **Saisonale Erscheinungsbilder:** wechseln Fotos (seit 29.10.2026 am Foto festgelegt: „Zeigen in“ mehreren Erscheinungsbildern, leer = ganzjährig), Texte, Farben/Akzente und Banner – nicht den Aufbau. Bausteine können **nur in bestimmten Erscheinungsbildern** erscheinen (z. B. ein Weihnachts-Baustein). Sonderangebote werden seit 22.10.2026 **unabhängig** davon nach eigenen Regeln beworben (5a). Zeitplan jährlich wiederkehrend mit Priorität und Standard; Vorschau-Link vor Aktivierung. Startset: **Sommer** (Strand, Baden), **Winter** (raue See, stimmungsvoller Himmel), **Weihnachten** (gemütlich, besinnlich), **Silvester** (Party, Feuerwerk). Klickbare Vorschau: lokale HTML-Datei (Scratchpad der Sitzung). - **Mehrfähigkeit offen halten:** „Site“ = Domain + Theme/Erscheinungsbilder + angezeigte Wohnungen; kein Portal, aber andere Vermieter könnten die Funktionen über eine eigene Domain nutzen (Mandantenfähigkeit vorbereiten, nicht ausbauen). - **Plugins:** Theme- und Baustein-Plugins als Composer-Pakete (Registry wie bei den Portal-Connectoren); Auslieferung per Deployment – kein Upload von Vorlagen im Admin (Sicherheit). - **Strato:** CSS aller Themes wird beim Deployment gebaut; Seiten-Cache je Erscheinungsbild. @@ -181,7 +181,7 @@ ## 10. Umsetzungsphasen 1. **Fundament:** Laravel + Filament, Datenmodell, Saisons/Preise, Preisberechnung (mit Tests). ✅ 2. **Kalender & Anfrage:** Belegung, Anfrageformular, Vorreservierung mit Haltezeit, Sonderangebote (Rabattaktion, fester Termin, Lückenfüller), Mindestaufenthalt mit Ausnahmen, Sperrzeiten, Buchungsverwaltung. ✅ 3. **Buchungsworkflow:** Buchungsweg 1 Anfrage → Angebot → Annahme durch den Gast (§6a), Mietvertrag-PDF, Zahlungsfristen & Erinnerungen, Anreiseinfos. ✅ (Mietbedingungen/Storno/Angebotstexte noch als Muster) -4. **Webseite:** Theme-System, Bausteine, Erscheinungsbilder (Bilder je Baustein, saisonale Bausteine), Seiten, SEO, Markengrafiken ✅ · neues Design-Theme in eigener Session (docs/ZUSAMMENARBEIT.md, docs/THEME-ERSTELLUNG.md). +4. **Webseite:** Theme-System, Bausteine, Erscheinungsbilder (Saisonfotos, saisonale Bausteine), Seiten, SEO, Markengrafiken ✅ · neues Design-Theme in eigener Session (docs/ZUSAMMENARBEIT.md, docs/THEME-ERSTELLUNG.md). 5. **Connectoren:** iCal-Import/-Export, Sync-Log, Konfliktwarnung, Portal-E-Mails. ✅ (echte Portal-Mails zur Feinabstimmung des Parsers fehlen) 6. **Go-Live:** Strato-Deployment und Testbetrieb ✅ · offen: Cronjob, Produktion, Umleitungen, Rechtstexte, echte Testbuchungen (Stand: docs/STATUS.md). diff --git a/docs/STATUS.md b/docs/STATUS.md index d88350e..33c8786 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -89,7 +89,7 @@ ## 1. Fertig (umgesetzt, getestet, auf stommer.info) **Webseite** - **Theme-System:** Basis-Theme „Ostsee-Licht“, 15 Bausteine, Seiten-Baukasten. - **Erscheinungsbilder** für Standard, Sommer, Winter, Weihnachten und Silvester: - - Bilder je Baustein, Bausteine nur in bestimmten Erscheinungsbildern, + - Saisonfotos (am Foto: „Zeigen in“), Bausteine nur in bestimmten Erscheinungsbildern, - Vorschau-Links, Bildauswahl mit Vorschaubild. - **Markengrafiken** im Theme: Logo, Favicon, Symbole, Wellenband, Illustration. *(`public/brand`, `partials/brand`)* - **Theme-Werkzeuge:** `themes:make`, `themes:check`, `themes:preview`; Anleitung in THEME-ERSTELLUNG.md. diff --git a/docs/THEMES.md b/docs/THEMES.md index 45b4d76..3d2e428 100644 --- a/docs/THEMES.md +++ b/docs/THEMES.md @@ -28,7 +28,7 @@ ## 1. Überblick | **Theme** | `resources/themes//` | Manifest `theme.json`, Vorlagen `views/`, `theme.css`, `theme.js` | | **Seite** | `pages`, Admin › Webseite › Seiten | Adresse, Menü (Haupt/Fuß/keins), SEO, **Bausteine** (Builder) | | **Baustein** (Section) | `app/Themes/Sections/*`, Katalog in `config/themes.php` | Admin-Formular + Datenaufbereitung; Darstellung: `theme::sections.` | -| **Erscheinungsbild** (Appearance) | `appearances`, Admin › Webseite › Erscheinungsbilder | Jährlicher Zeitraum + Priorität; ersetzt Farben (Tokens), Titelbild, **Bilder je Baustein**, ausgewählte Texte, Banner – **nicht** den Aufbau. Bausteine können auf Erscheinungsbilder beschränkt werden. Sonderangebote sind **unabhängig** davon (`OfferShowcase`) | +| **Erscheinungsbild** (Appearance) | `appearances`, Admin › Webseite › Erscheinungsbilder | Jährlicher Zeitraum + Priorität; ersetzt Farben (Tokens), ausgewählte Texte, Banner; **Fotos gehören zu Erscheinungsbildern** (`photos.appearance_ids`, mehrere möglich, leer = ganzjährig) – **nicht** den Aufbau. Bausteine können auf Erscheinungsbilder beschränkt werden. Sonderangebote sind **unabhängig** davon (`OfferShowcase`) | Code: `app/Themes/` (Theme, ThemeFactory, ThemeRegistry, ThemeManifest, SectionRegistry, Sections/), `app/Http/Middleware/ResolveTheme.php`, `app/Http/Controllers/PageController.php`, `app/Providers/ThemeServiceProvider.php`. @@ -85,8 +85,7 @@ ## 4. Was Layout und Vorlagen zur Verfügung haben | `$theme->isPreview` | Vorschau-Modus (Layout setzt `noindex` und zeigt einen Hinweis) | | `$theme->appearanceKey()` | z. B. `weihnachten` – steht als `data-appearance` am ``; für saisonale CSS-Details nutzbar: `[data-appearance=silvester] .hero {…}` | | `$theme->text($key, $fallback)` | Text des Erscheinungsbilds oder Fallback (Schlüssel: `Appearance::OVERRIDABLE`) | -| `$theme->heroPhoto($fallback)` | Titelbild des Erscheinungsbilds oder Fallback | -| `$theme->sectionPhotoIds($sectionId, $slot)` / `sectionPhotoMode($sectionId)` | Saisonbilder eines platzierten Bausteins (in Bausteinen über `seasonalPhoto()`, `seasonalPhotos()`, `withSeasonalPhotos()` der Basisklasse) | +| `$theme->sharePhoto($sections)` | Vorschaubild beim Teilen und für Suchmaschinen: erstes zur Saison passendes Titelbild der Seite, sonst ein automatisches Foto der Wohnung | | `$theme->property()` | Hauptwohnung der Site | | `$theme->menu('main' \| 'footer')` | veröffentlichte Seiten des Menüs (`->url()`, `->label()`) | | `$theme->tokens()`, `cssVariables()`, `assets()` | für das Layout | @@ -120,15 +119,16 @@ ## 5. Bausteinkatalog – Vertrag der Vorlagen Rich-Text-Variablen sind bereits bereinigt (HtmlString) und werden mit `{{ $text }}` ausgegeben. -**Jeder platzierte Baustein** hat `data.id` (feste UUID, `Page::assignSectionIds` beim Speichern; Kopien bekommen eine neue) und `data.appearances` (Erscheinungsbild-IDs; leer = immer sichtbar, sonst nur in diesen – z. B. ein Weihnachts-Baustein). Bausteine mit Bildern melden ihre Bildplätze über `photoSlots()` (`single`, `multiple`, `collection` = automatisch gewählte Bilder, die ein Erscheinungsbild ersetzen oder voranstellen kann); daraus baut das Erscheinungsbild-Formular „Bilder je Baustein“ (`appearances.section_photos[][]`, bei Sammlungen zusätzlich `mode`). Alle Bildauswahlen nutzen `App\Filament\Forms\Components\PhotoSelect` (Vorschaubild + Beschreibung, nach Kategorie gruppiert). +**Jeder platzierte Baustein** hat `data.id` (feste UUID, `Page::assignSectionIds` beim Speichern; Kopien bekommen eine neue) und `data.appearances` (Erscheinungsbild-IDs; leer = immer sichtbar, sonst nur in diesen – z. B. ein Weihnachts-Baustein). **Bilder in Bausteinen** (Basisklasse): `chosenPhotos()` = ausgewählte Fotos in ihrer Reihenfolge, nur veröffentlichte und zur Saison passende; `automaticPhotos()` = `Photo::automatic()` (Fotos der Wohnung des Bausteins und solche ohne Wohnung, nie Kategorie „Grundriss & Pläne“, zur Saison passend, Saisonfotos zuerst); `photoSourceFields()`/`sourcedPhotos()` = Wahl „automatisch“ oder „eigene Auswahl“ (`data.photo_source`, `data.photo_ids`). Titelbereich und Abschluss halten eine Liste `photo_ids`, gezeigt wird das erste passende Foto. Ein Foto gehört zu keinem (= ganzjährig) oder mehreren Erscheinungsbildern; dann erscheint es nur dort und vor den ganzjährigen. Alle Bildauswahlen nutzen `App\Filament\Forms\Components\PhotoSelect` (Vorschaubild + Beschreibung, nach Kategorie gruppiert). **Neuer Baustein** (auch als Plugin): Klasse `extends App\Themes\Sections\Section` (`key()`, `label()`, `icon()`, `schema()` = Admin-Felder, `data()` = Variablen) → in `config/themes.php › sections` eintragen → Vorlage `sections/.blade.php` im Basis-Theme anlegen (Test `test_base_theme_is_discovered_and_provides_a_view_for_every_section` erzwingt das). Unbekannte Bausteine werden auf der Seite übersprungen, nie ein Fehler. ## 6. Erscheinungsbilder -- Felder: Name, Zeitraum `TT.MM.`–`TT.MM.` (jährlich, darf über Silvester laufen), Priorität, Standard, aktiv, Titelbild, **Bilder je Baustein** (alle Bausteine mit Bildern auf allen Seiten; leer = Bild aus der Seite), Texte (`banner.text`, `banner.link_label`, `banner.link_url`, `hero.eyebrow`, `hero.title`, `hero.text`, `cta.title`, `cta.text`), Farben. +- Felder: Name, Zeitraum `TT.MM.`–`TT.MM.` (jährlich, darf über Silvester laufen), Priorität, Standard, aktiv, Texte (`banner.text`, `banner.link_label`, `banner.link_url`, `hero.eyebrow`, `hero.title`, `hero.text`, `cta.title`, `cta.text`), Farben. - Startset (Seeder): Standard · Sommer 01.06.–31.08. · Winter 01.11.–31.03. · Weihnachten 01.12.–25.12. (Prio 20) · Silvester 26.12.–03.01. (Prio 20). -- **Vorschau:** Admin › Erscheinungsbilder › „Vorschau“ = signierter Link (24 h), `noindex`. +- **Fotos:** nicht mehr am Erscheinungsbild, sondern am Foto (Webseite › Fotos › „Zeigen in“, auch als Sammelaktion). Das Erscheinungsbild zeigt nur, wie viele Fotos ihm zugeordnet sind. Umstellung 29.10.2026: Titelbild und „Bilder je Baustein“ wurden in die Bausteine übernommen (Migration `give_photos_their_seasons`). +- **Vorschau:** Admin › Erscheinungsbilder › „Vorschau“ = signierter Link (24 h), `noindex` – zeigt auch die Saisonfotos. - Ohne Erscheinungsbild-Banner wird der neueste aktive Hinweis (Admin › Hinweis-Banner) gezeigt. ## 7. Assets, Schriften, Build diff --git a/docs/ZUSAMMENARBEIT.md b/docs/ZUSAMMENARBEIT.md index e305a1c..125d2bc 100644 --- a/docs/ZUSAMMENARBEIT.md +++ b/docs/ZUSAMMENARBEIT.md @@ -84,6 +84,7 @@ ## 6. Änderungsprotokoll Vorlagen-Vertrag | Datum | Änderung | Betrifft | |---|---|---| +| 29.10.2026 | **Fotos und Saisons:** Variablen der Vorlagen unverändert (`$photo`, `$photos`). Entfallen: `$theme->heroPhoto()`, `sectionPhotoIds()`, `sectionPhotoMode()`, `Section::photoSlots()` und die Saison-Helfer `seasonalPhoto(s)`/`withSeasonalPhotos`; neu `$theme->sharePhoto($sections)`, `chosenPhotos()`, `automaticPhotos()`, `sourcedPhotos()`. Titelbereich/Abschluss: `data.photo_ids` statt `photo_id`. Neue Fotokategorie `plan` erscheint nie automatisch. | nur Bausteinklassen; Vorlagen nicht betroffen | | 26.10.2026 | **Mandantenabschluss:** Beide Themes beziehen Logo und Favicon ausschließlich aus der Website-Marke; ohne Marke bleibt die Darstellung neutral. Dekoration und Bild-Platzhalter kommen aus Bildwelt-Plätzen. `partials/brand` bleibt als kompatible Platz-Zuordnung erhalten; Seebads `partials/motif` nutzt die Bildwelt-API. Bestehende Stommer-Marken werden vor Aktivierung ausdrücklich für diese Website importiert. | layouts/app, partials/brand, partials/logo, partials/motif, partials/image, header | | 22.10.2026 | `theme-base.css` (Schriften, Token-Mapping, Basis-Klassen) von `theme.css` getrennt – Child-Themes importieren `theme-base.css` | theme.css | | 22.10.2026 | Markengrafiken: `@include('theme::partials.brand', ['name' => 'mark', 'class' => '…'])` (mark, logo, wave-divider, icon-apartment/-sea/-terrace/-location); Farben über `--brand-navy/-teal/-wave/-sun` (navy = Textfarbe) | header, footer, facts, location, image | diff --git a/docs/architecture/webseite.md b/docs/architecture/webseite.md index 388712c..e9fcc3a 100644 --- a/docs/architecture/webseite.md +++ b/docs/architecture/webseite.md @@ -43,7 +43,7 @@ ### Gestaltung, Marke und Saisons Eine Website wählt ein installiertes Theme. Vorhanden sind „Ostsee-Licht“ und „Seebad“. Der Vermieter kann das Theme auswählen, aber keine ausführbaren Gestaltungspakete hochladen. Vorschau-Links ermöglichen die Sichtung einer Gestaltung vor der Aktivierung. -Erscheinungsbilder ändern saisonal Fotos, Bilder je Baustein, Texte, Farben und Banner. Der Seitenaufbau bleibt davon grundsätzlich unabhängig. Einzelne Bausteine können auf bestimmte Erscheinungsbilder begrenzt werden. Zeiträume können jährlich wiederkehren; Prioritäten und ein Standard regeln die Auswahl. Vorbereitet sind unter anderem Sommer, Winter, Weihnachten und Silvester. +Erscheinungsbilder ändern saisonal Texte, Farben und Banner. Fotos gehören zu einem, mehreren oder keinem Erscheinungsbild (dann ganzjährig); passende Saisonfotos erscheinen zuerst, fremde gar nicht. Grundrisse und Pläne haben eine eigene Kategorie, die keine Galerie zeigt. Der Seitenaufbau bleibt davon grundsätzlich unabhängig. Einzelne Bausteine können auf bestimmte Erscheinungsbilder begrenzt werden. Zeiträume können jährlich wiederkehren; Prioritäten und ein Standard regeln die Auswahl. Vorbereitet sind unter anderem Sommer, Winter, Weihnachten und Silvester. Zur Website gehören Logo, Favicon und eine eigene Grafik für E-Mails beziehungsweise Vertragsunterlagen. Eine Bildwelt liefert passende Dekoration unabhängig vom Theme; eine Wohnung kann eine andere Bildwelt als ihre Website wählen. Damit können etwa eine Ostsee- und eine Bergwohnung unter derselben Grundgestaltung erscheinen. diff --git a/tests/Feature/ThemeSystemTest.php b/tests/Feature/ThemeSystemTest.php index 2597a3d..ac6b523 100644 --- a/tests/Feature/ThemeSystemTest.php +++ b/tests/Feature/ThemeSystemTest.php @@ -6,9 +6,10 @@ use App\Enums\UserRole; use App\Filament\Resources\Appearances\AppearanceResource; use App\Filament\Resources\Appearances\Pages\CreateAppearance; -use App\Filament\Resources\Appearances\Pages\EditAppearance; use App\Filament\Resources\Pages\PageResource; use App\Filament\Resources\Pages\Pages\EditPage; +use App\Filament\Resources\Photos\Pages\EditPhoto; +use App\Filament\Resources\Photos\Pages\ListPhotos; use App\Filament\Resources\Sites\SiteResource; use App\Models\Appearance; use App\Models\Page; @@ -27,6 +28,7 @@ use Database\Seeders\WebsiteContentSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\UploadedFile; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\URL; use Livewire\Livewire; @@ -239,43 +241,92 @@ public function test_section_can_be_limited_to_an_appearance(): void $this->get('/')->assertOk()->assertSee('Adventsmarkt am Hafen'); } - public function test_appearance_sets_seasonal_photos_per_section(): void + public function test_seasonal_photos_appear_only_in_their_appearances_and_come_first(): void { Storage::fake('public'); - $summerPhoto = Photo::factory()->create(['alt_text' => 'Strand im Sommer', 'sort_order' => 1]); - $summerPhoto->addMedia(UploadedFile::fake()->image('sommer.jpg', 1600, 1000))->toMediaCollection(Photo::COLLECTION); - $winterPhoto = Photo::factory()->create(['alt_text' => 'Raue See im Winter', 'sort_order' => 99]); - $winterPhoto->addMedia(UploadedFile::fake()->image('winter.jpg', 1600, 1000))->toMediaCollection(Photo::COLLECTION); - - $page = $this->site->pages()->where('slug', 'start')->sole(); - $cta = collect($page->sections)->firstWhere('type', 'cta'); $winter = $this->site->appearances()->where('name', 'Winter')->sole(); - $winter->update(['section_photos' => [$cta['data']['id'] => ['photo_id' => $winterPhoto->id]]]); + $christmas = $this->site->appearances()->where('name', 'Weihnachten')->sole(); + $allYear = $this->photoWithFile(['alt_text' => 'Garten im Licht', 'sort_order' => 1]); + $snow = $this->photoWithFile(['alt_text' => 'Raue See im Winter', 'sort_order' => 99, 'appearance_ids' => [$winter->id, $christmas->id]]); + $page = $this->site->pages()->where('slug', 'start')->sole(); + $page->update(['sections' => collect($page->sections)->map(fn (array $section): array => $section['type'] === 'cta' + ? [...$section, 'data' => [...$section['data'], 'photo_ids' => [$snow->id, $allYear->id]]] + : $section)->all()]); + $apartmentGallery = fn () => $this->get('/wohnung')->assertOk(); - $this->get('/')->assertOk()->assertDontSee('Raue See im Winter'); + $this->get('/')->assertOk()->assertSee('Garten im Licht')->assertDontSee('Raue See im Winter'); + $apartmentGallery()->assertDontSee('Raue See im Winter'); $this->travelTo(CarbonImmutable::parse('2026-11-15 10:00')); + $this->get('/')->assertOk()->assertSee('Raue See im Winter')->assertDontSee('Garten im Licht'); + $apartmentGallery()->assertSeeInOrder(['Raue See im Winter', 'Garten im Licht']); + + $this->travelTo(CarbonImmutable::parse('2026-12-20 10:00')); $this->get('/')->assertOk()->assertSee('Raue See im Winter'); } - public function test_appearance_form_lists_the_sections_with_photos(): void + public function test_photo_belongs_to_several_appearances_and_the_appearance_counts_its_photos(): void { $this->actingAs(User::factory()->role(UserRole::Content)->create()); $winter = $this->site->appearances()->where('name', 'Winter')->sole(); - $photo = Photo::factory()->create(['alt_text' => 'Strand im Schnee']); - $cta = collect($this->site->pages()->where('slug', 'start')->sole()->sections)->firstWhere('type', 'cta'); + $christmas = $this->site->appearances()->where('name', 'Weihnachten')->sole(); + Storage::fake('public'); + $photo = $this->photoWithFile(['alt_text' => 'Strand im Schnee']); - $this->get(AppearanceResource::getUrl('edit', ['record' => $winter])) - ->assertOk() - ->assertSee('Bilder je Baustein') - ->assertSee('Abschluss'); - - Livewire::test(EditAppearance::class, ['record' => $winter->getRouteKey()]) - ->set("data.section_photos.{$cta['data']['id']}.photo_id", $photo->id) + Livewire::test(EditPhoto::class, ['record' => $photo->getRouteKey()]) + ->fillForm(['appearance_ids' => [(string) $winter->id, (string) $christmas->id]]) ->call('save') ->assertHasNoFormErrors(); - $this->assertSame($photo->id, (int) $winter->fresh()->section_photos[$cta['data']['id']]['photo_id']); + $this->assertSame([$winter->id, $christmas->id], $photo->fresh()->appearance_ids); + $this->assertSame(['Winter', 'Weihnachten'], $photo->fresh()->appearanceNames()); + $this->get(AppearanceResource::getUrl('edit', ['record' => $winter])) + ->assertOk() + ->assertSee('1 Foto ist diesem Erscheinungsbild zugeordnet.') + ->assertDontSee('Bilder je Baustein'); + + Livewire::test(ListPhotos::class) + ->callTableBulkAction('seasons', [$photo], ['appearance_ids' => []]) + ->assertHasNoTableBulkActionErrors(); + $this->assertNull($photo->fresh()->appearance_ids); + } + + public function test_appearance_photos_move_to_the_photos_and_sections(): void + { + $migration = require database_path('migrations/2026_10_29_184538_give_photos_their_seasons.php'); + $migration->down(); + $standard = $this->site->appearances()->where('is_default', true)->sole(); + $winter = $this->site->appearances()->where('name', 'Winter')->sole(); + $title = Photo::factory()->create(); + $snow = Photo::factory()->create(); + $closing = Photo::factory()->create(); + $page = $this->site->pages()->where('slug', 'start')->sole(); + $cta = collect($page->sections)->firstWhere('type', 'cta'); + $page->update(['sections' => collect($page->sections)->map(fn (array $section): array => $section['type'] === 'cta' + ? [...$section, 'data' => [...$section['data'], 'photo_id' => $closing->id]] + : $section)->all()]); + DB::table('appearances')->where('id', $standard->id)->update(['hero_photo_id' => $title->id]); + DB::table('appearances')->where('id', $winter->id)->update(['section_photos' => json_encode([$cta['data']['id'] => ['photo_id' => $snow->id]])]); + + $migration->up(); + + $sections = collect($page->fresh()->sections); + $this->assertSame([$title->id], $sections->firstWhere('type', 'hero')['data']['photo_ids']); + $this->assertSame([$snow->id, $closing->id], $sections->firstWhere('type', 'cta')['data']['photo_ids']); + $this->assertArrayNotHasKey('photo_id', $sections->firstWhere('type', 'cta')['data']); + $this->assertNull($title->fresh()->appearance_ids); + $this->assertSame([$winter->id], $snow->fresh()->appearance_ids); + } + + /** + * @param array $attributes + */ + private function photoWithFile(array $attributes): Photo + { + $photo = Photo::factory()->create($attributes); + $photo->addMedia(UploadedFile::fake()->image('foto.jpg', 1600, 1000))->toMediaCollection(Photo::COLLECTION); + + return $photo; } public function test_invalid_day_is_rejected(): void From d2b1a853dc3a4ffd645ba57a116303a78559fcb4 Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 29 Oct 2026 19:01:48 +0100 Subject: [PATCH 4/5] Banner zentral: je Website, Saison und Prioritaet, auch fuer Sonderangebote Hinweise werden zu Bannern mit Website, Erscheinungsbildern, Prioritaet und optionalem Sonderangebot (Text, Termin und Link aus dem Angebot, sichtbar nur solange es beworben wird). Sonderangebote lassen sich mit einem Klick als Banner zeigen; die Liste nennt das heute sichtbare Banner. Banner-Texte der Erscheinungsbilder werden zu saisonalen Bannern. Co-Authored-By: Claude Opus 5.5 --- .../Appearances/Schemas/AppearanceForm.php | 2 +- .../Resources/Notices/NoticeResource.php | 33 +++- .../Resources/Notices/Pages/ListNotices.php | 17 +++ .../Resources/Notices/Schemas/NoticeForm.php | 116 ++++++++++---- .../Resources/Notices/Tables/NoticesTable.php | 28 +++- .../SpecialOffersRelationManager.php | 21 +++ app/Models/Appearance.php | 13 +- app/Models/Concerns/BelongsToAppearances.php | 48 ++++++ app/Models/Notice.php | 28 +++- app/Models/Photo.php | 39 +---- app/Themes/Banner.php | 20 +++ app/Themes/BannerResolver.php | 88 +++++++++++ app/Themes/Theme.php | 17 +++ ...10_29_185454_turn_notices_into_banners.php | 60 ++++++++ database/seeders/SiteSeeder.php | 18 ++- docs/THEMES.md | 5 +- docs/ZUSAMMENARBEIT.md | 1 + docs/architecture/webseite.md | 2 +- .../views/partials/banner.blade.php | 12 +- .../seebad/views/partials/banner.blade.php | 12 +- tests/Feature/BannerTest.php | 144 ++++++++++++++++++ 21 files changed, 618 insertions(+), 106 deletions(-) create mode 100644 app/Models/Concerns/BelongsToAppearances.php create mode 100644 app/Themes/Banner.php create mode 100644 app/Themes/BannerResolver.php create mode 100644 database/migrations/2026_10_29_185454_turn_notices_into_banners.php create mode 100644 tests/Feature/BannerTest.php diff --git a/app/Filament/Resources/Appearances/Schemas/AppearanceForm.php b/app/Filament/Resources/Appearances/Schemas/AppearanceForm.php index defcf01..4d765a0 100644 --- a/app/Filament/Resources/Appearances/Schemas/AppearanceForm.php +++ b/app/Filament/Resources/Appearances/Schemas/AppearanceForm.php @@ -45,7 +45,7 @@ public static function configure(Schema $schema): Schema Text::make(fn (?Appearance $record): string => self::photoSummary($record)), ]), Section::make('Texte') - ->description('Leer lassen = Text der Seite bzw. kein Banner.') + ->description('Leer lassen = Text der Seite. Banner pflegen Sie unter Webseite › Banner & Hinweise – dort auch nur für dieses Erscheinungsbild.') ->columns(2) ->collapsible() ->schema(collect(Appearance::OVERRIDABLE) diff --git a/app/Filament/Resources/Notices/NoticeResource.php b/app/Filament/Resources/Notices/NoticeResource.php index 39d6e03..f430633 100644 --- a/app/Filament/Resources/Notices/NoticeResource.php +++ b/app/Filament/Resources/Notices/NoticeResource.php @@ -9,6 +9,10 @@ use App\Filament\Resources\Notices\Schemas\NoticeForm; use App\Filament\Resources\Notices\Tables\NoticesTable; use App\Models\Notice; +use App\Models\Site; +use App\Tenancy\TenantContext; +use App\Themes\Banner; +use App\Themes\ThemeFactory; use BackedEnum; use Filament\Resources\Resource; use Filament\Schemas\Schema; @@ -26,9 +30,9 @@ class NoticeResource extends Resource protected static string|UnitEnum|null $navigationGroup = 'Webseite'; - protected static ?string $modelLabel = 'Hinweis'; + protected static ?string $modelLabel = 'Banner'; - protected static ?string $pluralModelLabel = 'Hinweis-Banner'; + protected static ?string $pluralModelLabel = 'Banner & Hinweise'; protected static ?int $navigationSort = 6; @@ -49,6 +53,31 @@ public static function getRelations(): array ]; } + /** + * The banner each website shows today (none = null), with the website. + * + * @return list + */ + public static function bannersToday(): array + { + $tenantId = app(TenantContext::class)->id(); + + // once() keys its cache by the variables the closure uses, so each landlord gets its own entry. + return once(function () use ($tenantId): array { + return Site::query()->when($tenantId, fn ($query) => $query->where('tenant_id', $tenantId))->orderBy('name')->get() + ->map(fn (Site $site): array => ['site' => $site, 'banner' => app(ThemeFactory::class)->forSite($site)->banner()]) + ->all(); + }); + } + + /** + * @return list + */ + public static function noticeIdsShownToday(): array + { + return collect(self::bannersToday())->pluck('banner')->filter()->map(fn (Banner $banner): int => $banner->notice->id)->unique()->values()->all(); + } + public static function getPages(): array { return [ diff --git a/app/Filament/Resources/Notices/Pages/ListNotices.php b/app/Filament/Resources/Notices/Pages/ListNotices.php index b2870e2..5899295 100644 --- a/app/Filament/Resources/Notices/Pages/ListNotices.php +++ b/app/Filament/Resources/Notices/Pages/ListNotices.php @@ -10,6 +10,23 @@ class ListNotices extends ListRecords { protected static string $resource = NoticeResource::class; + /** + * Which banner the website shows today – the answer to "why do I see this banner?". + */ + public function getSubheading(): ?string + { + $today = NoticeResource::bannersToday(); + if ($today === []) { + return null; + } + + return collect($today)->map(function (array $entry) use ($today): string { + $prefix = count($today) > 1 ? $entry['site']->name.': ' : ''; + + return $prefix.($entry['banner'] ? 'Heute sichtbar: „'.$entry['banner']->text.'“' : 'Heute ist kein Banner sichtbar.'); + })->implode(' · '); + } + protected function getHeaderActions(): array { return [ diff --git a/app/Filament/Resources/Notices/Schemas/NoticeForm.php b/app/Filament/Resources/Notices/Schemas/NoticeForm.php index 650e885..9bbb7ab 100644 --- a/app/Filament/Resources/Notices/Schemas/NoticeForm.php +++ b/app/Filament/Resources/Notices/Schemas/NoticeForm.php @@ -3,10 +3,17 @@ namespace App\Filament\Resources\Notices\Schemas; use App\Enums\NoticeTone; +use App\Filament\Resources\Photos\Schemas\PhotoForm; +use App\Models\Appearance; +use App\Models\Property; +use App\Models\Site; +use App\Models\SpecialOffer; use Filament\Forms\Components\DatePicker; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; +use Filament\Schemas\Components\Section; +use Filament\Schemas\Components\Utilities\Get; use Filament\Schemas\Schema; class NoticeForm @@ -14,36 +21,87 @@ class NoticeForm public static function configure(Schema $schema): Schema { return $schema - ->columns(2) ->components([ - TextInput::make('text') - ->label('Hinweistext') - ->placeholder('z. B. Kurzfristig frei: 12.–15.11. mit 15 % Rabatt') - ->required() - ->maxLength(255) - ->columnSpanFull(), - Select::make('tone') - ->label('Art') - ->options(NoticeTone::class) - ->default(NoticeTone::Info) - ->required(), - Toggle::make('is_active') - ->label('Aktiv') - ->default(true) - ->inline(false), - DatePicker::make('starts_on') - ->label('Anzeigen ab (optional)'), - DatePicker::make('ends_on') - ->label('Anzeigen bis (optional)') - ->afterOrEqual('starts_on'), - TextInput::make('link_label') - ->label('Link-Text (optional)') - ->placeholder('z. B. Jetzt anfragen') - ->maxLength(100), - TextInput::make('link_url') - ->label('Link-Ziel (optional)') - ->placeholder('/buchen') - ->maxLength(255), + Section::make('Inhalt') + ->columns(2) + ->schema([ + Select::make('special_offer_id') + ->label('Sonderangebot bewerben (optional)') + ->options(fn (): array => self::offerOptions()) + ->placeholder('– kein Angebot –') + ->searchable() + ->live() + ->helperText('Mit Angebot kommen Text, Termin und Link aus dem Angebot, und das Banner erscheint nur, solange die Website das Angebot bewirbt – bei festen Terminen also nur, solange sie frei sind.') + ->columnSpanFull(), + TextInput::make('text') + ->label('Text') + ->placeholder(fn (Get $get): string => filled($get('special_offer_id')) ? 'leer = Text aus dem Angebot' : 'z. B. Kurzfristig frei: 12.–15.11. mit 15 % Rabatt') + ->required(fn (Get $get): bool => blank($get('special_offer_id'))) + ->maxLength(255) + ->columnSpanFull(), + TextInput::make('link_label') + ->label('Link-Text (optional)') + ->placeholder(fn (Get $get): string => filled($get('special_offer_id')) ? 'Zum Angebot' : 'z. B. Jetzt anfragen') + ->maxLength(100), + TextInput::make('link_url') + ->label('Link-Ziel (optional)') + ->placeholder(fn (Get $get): string => filled($get('special_offer_id')) ? 'Buchung mit den Angebotsterminen' : '/buchen') + ->maxLength(255), + Select::make('tone') + ->label('Art') + ->options(NoticeTone::class) + ->default(NoticeTone::Info) + ->required(), + ]), + Section::make('Wann und wo') + ->description('Es erscheint immer nur ein Banner: Gelten mehrere gleichzeitig, gewinnt die höchste Priorität, bei Gleichstand das neueste.') + ->columns(2) + ->schema([ + Select::make('site_id') + ->label('Website') + ->options(fn (): array => Site::query()->pluck('name', 'id')->all()) + ->placeholder('alle Websites') + ->visible(fn (): bool => Site::query()->count() > 1), + Select::make('appearance_ids') + ->label('Nur in Erscheinungsbildern') + ->multiple() + ->options(fn (): array => Appearance::photoOptions()) + ->placeholder('immer') + ->helperText('Leer = in jedem Erscheinungsbild, z. B. Weihnachten und Silvester für ein Festtagsbanner.') + ->dehydrateStateUsing(fn (?array $state): ?array => PhotoForm::appearanceIds($state)), + DatePicker::make('starts_on') + ->label('Anzeigen ab (optional)'), + DatePicker::make('ends_on') + ->label('Anzeigen bis (optional)') + ->afterOrEqual('starts_on'), + TextInput::make('priority') + ->label('Priorität') + ->integer() + ->minValue(0) + ->maxValue(999) + ->default(10) + ->required(), + Toggle::make('is_active') + ->label('Aktiv') + ->default(true) + ->inline(false), + ]), ]); } + + /** + * Offers the website can advertise (public, without a code), named with their apartment when there are several. + * + * @return array + */ + public static function offerOptions(): array + { + $severalProperties = Property::query()->count() > 1; + + return SpecialOffer::query()->with('property')->where('is_public', true)->whereNull('code')->orderBy('name')->get() + ->mapWithKeys(fn (SpecialOffer $offer): array => [$offer->id => $offer->name + .($severalProperties ? ' · '.$offer->property?->name : '') + .($offer->is_active ? '' : ' (inaktiv)')]) + ->all(); + } } diff --git a/app/Filament/Resources/Notices/Tables/NoticesTable.php b/app/Filament/Resources/Notices/Tables/NoticesTable.php index c0467bf..cec3464 100644 --- a/app/Filament/Resources/Notices/Tables/NoticesTable.php +++ b/app/Filament/Resources/Notices/Tables/NoticesTable.php @@ -2,8 +2,11 @@ namespace App\Filament\Resources\Notices\Tables; +use App\Filament\Resources\Notices\NoticeResource; +use App\Models\Notice; use Filament\Actions\DeleteAction; use Filament\Actions\EditAction; +use Filament\Tables\Columns\IconColumn; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Columns\ToggleColumn; use Filament\Tables\Table; @@ -13,14 +16,33 @@ class NoticesTable public static function configure(Table $table): Table { return $table - ->defaultSort('starts_on', 'desc') + ->defaultSort('priority', 'desc') ->columns([ - TextColumn::make('text')->label('Hinweis')->wrap()->searchable(), - TextColumn::make('tone')->label('Art')->badge(), + IconColumn::make('shown_today') + ->label('Heute') + ->state(fn (Notice $record): bool => in_array($record->id, NoticeResource::noticeIdsShownToday(), true)) + ->boolean() + ->trueIcon('heroicon-s-eye') + ->falseIcon('heroicon-o-minus') + ->tooltip(fn (bool $state): string => $state ? 'Wird heute auf der Website gezeigt' : 'Heute nicht sichtbar'), + TextColumn::make('text') + ->label('Banner') + ->state(fn (Notice $record): string => filled($record->text) ? $record->text : 'Text aus dem Angebot') + ->description(fn (Notice $record): ?string => $record->specialOffer ? 'Angebot: '.$record->specialOffer->name : null) + ->wrap() + ->searchable(), + TextColumn::make('appearance_ids') + ->label('Erscheinungsbilder') + ->state(fn (Notice $record): array => $record->appearanceNames()) + ->badge() + ->placeholder('immer'), + TextColumn::make('site.name')->label('Website')->placeholder('alle')->toggleable(isToggledHiddenByDefault: true), TextColumn::make('starts_on')->label('Ab')->date('d.m.Y')->placeholder('sofort'), TextColumn::make('ends_on')->label('Bis')->date('d.m.Y')->placeholder('unbegrenzt'), + TextColumn::make('priority')->label('Priorität')->sortable(), ToggleColumn::make('is_active')->label('Aktiv'), ]) + ->modifyQueryUsing(fn ($query) => $query->with(['specialOffer', 'site'])) ->recordActions([ EditAction::make(), DeleteAction::make(), diff --git a/app/Filament/Resources/Properties/RelationManagers/SpecialOffersRelationManager.php b/app/Filament/Resources/Properties/RelationManagers/SpecialOffersRelationManager.php index e45b7d0..22e61ef 100644 --- a/app/Filament/Resources/Properties/RelationManagers/SpecialOffersRelationManager.php +++ b/app/Filament/Resources/Properties/RelationManagers/SpecialOffersRelationManager.php @@ -3,8 +3,12 @@ namespace App\Filament\Resources\Properties\RelationManagers; use App\Enums\DiscountType; +use App\Enums\NoticeTone; use App\Enums\OfferKind; +use App\Filament\Resources\Notices\NoticeResource; +use App\Models\Notice; use App\Models\SpecialOffer; +use Filament\Actions\Action; use Filament\Actions\CreateAction; use Filament\Actions\DeleteAction; use Filament\Actions\EditAction; @@ -21,9 +25,11 @@ use Filament\Schemas\Components\Utilities\Get; use Filament\Schemas\Components\Utilities\Set; use Filament\Schemas\Schema; +use Filament\Support\Icons\Heroicon; use Filament\Tables\Columns\IconColumn; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; +use Illuminate\Support\Facades\Gate; class SpecialOffersRelationManager extends RelationManager { @@ -218,6 +224,21 @@ public function table(Table $table): Table ]) ->recordActions([ EditAction::make(), + Action::make('banner') + ->label('Als Banner zeigen') + ->icon(Heroicon::OutlinedMegaphone) + ->visible(fn (SpecialOffer $record): bool => $record->is_public && blank($record->code) && Gate::allows('create', Notice::class)) + ->action(function (SpecialOffer $record) { + $notice = Notice::query()->create([ + 'site_id' => $record->property?->site_id, + 'special_offer_id' => $record->id, + 'tone' => NoticeTone::Offer, + 'priority' => 30, + 'is_active' => true, + ]); + + return redirect(NoticeResource::getUrl('edit', ['record' => $notice])); + }), ReplicateAction::make()->label('Duplizieren')->schema(fn (Schema $schema): Schema => $this->form($schema)), DeleteAction::make(), ]); diff --git a/app/Models/Appearance.php b/app/Models/Appearance.php index 247313c..6cbc520 100644 --- a/app/Models/Appearance.php +++ b/app/Models/Appearance.php @@ -12,8 +12,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; /** - * A seasonal look of a site (e.g. summer, winter, Christmas, New Year's Eve): colour tokens, texts and banner - * change, photos made for it (Photo::appearance_ids) are shown – the page structure does not (sections may be limited to + * A seasonal look of a site (e.g. summer, winter, Christmas, New Year's Eve): colour tokens and texts change, + * photos and banners made for it (appearance_ids) are shown – the page structure does not (sections may be limited to * appearances, see SectionRegistry). Offers are advertised by their own rules (OfferShowcase). The period recurs every year ("MM-DD" to "MM-DD", * inclusive; a period may run over the turn of the year). The default appearance applies when none matches. */ @@ -27,9 +27,6 @@ class Appearance extends Model * Texts an appearance can replace, with their admin labels. Sections read them through Theme::text(). */ public const OVERRIDABLE = [ - 'banner.text' => 'Banner: Text', - 'banner.link_label' => 'Banner: Link-Text', - 'banner.link_url' => 'Banner: Link-Ziel', 'hero.eyebrow' => 'Titelbereich: kleine Überschrift', 'hero.title' => 'Titelbereich: Überschrift', 'hero.text' => 'Titelbereich: Text', @@ -67,12 +64,10 @@ public function site(): BelongsTo */ public static function names(): array { - // once() keys its cache by the closure's bound variables, so each landlord gets its own entry. $tenantId = app(TenantContext::class)->id(); - return once(function (): array { - return self::query()->pluck('name', 'id')->all(); - }); + // once() keys its cache by the variables the closure uses, so each landlord gets its own entry. + return once(fn (): array => self::query()->when($tenantId, fn ($query) => $query->where('tenant_id', $tenantId))->pluck('name', 'id')->all()); } /** diff --git a/app/Models/Concerns/BelongsToAppearances.php b/app/Models/Concerns/BelongsToAppearances.php new file mode 100644 index 0000000..a87109a --- /dev/null +++ b/app/Models/Concerns/BelongsToAppearances.php @@ -0,0 +1,48 @@ + + */ + public function appearanceIds(): array + { + return array_values(array_unique(array_map('intval', array_filter((array) $this->appearance_ids)))); + } + + /** + * Whether the record may be shown while this appearance is in effect: all-year ones always, seasonal ones in their seasons. + */ + public function fitsSeason(?Appearance $appearance): bool + { + return $this->appearanceIds() === [] || $this->isMadeFor($appearance); + } + + /** + * Whether the record was chosen for this appearance. + */ + public function isMadeFor(?Appearance $appearance): bool + { + return $appearance !== null && in_array($appearance->id, $this->appearanceIds(), true); + } + + /** + * Names of the appearances the record is made for (empty = all year). + * + * @return list + */ + public function appearanceNames(): array + { + return array_values(array_intersect_key(Appearance::names(), array_flip($this->appearanceIds()))); + } +} diff --git a/app/Models/Notice.php b/app/Models/Notice.php index 4f200a1..0a3775f 100644 --- a/app/Models/Notice.php +++ b/app/Models/Notice.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Enums\NoticeTone; +use App\Models\Concerns\BelongsToAppearances; use App\Models\Concerns\BelongsToTenant; use Database\Factories\NoticeFactory; use Illuminate\Database\Eloquent\Attributes\Fillable; @@ -10,15 +11,18 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; /** - * A banner shown on the website, optionally limited to a date range. + * A banner at the top of the website: for one website or all, optionally only in some appearances (seasons) + * and within a date range. It may advertise a special offer – then text, dates and link come from the offer + * and the banner only shows while the website advertises that offer. The highest priority wins (BannerResolver). */ -#[Fillable(['text', 'tone', 'link_url', 'link_label', 'starts_on', 'ends_on', 'is_active'])] +#[Fillable(['site_id', 'special_offer_id', 'appearance_ids', 'priority', 'text', 'tone', 'link_url', 'link_label', 'starts_on', 'ends_on', 'is_active'])] class Notice extends Model { /** @use HasFactory */ - use BelongsToTenant, HasFactory; + use BelongsToAppearances, BelongsToTenant, HasFactory; /** * Get the attributes that should be cast. @@ -29,12 +33,30 @@ protected function casts(): array { return [ 'tone' => NoticeTone::class, + 'appearance_ids' => 'array', + 'priority' => 'integer', 'starts_on' => 'immutable_date', 'ends_on' => 'immutable_date', 'is_active' => 'boolean', ]; } + /** + * @return BelongsTo + */ + public function site(): BelongsTo + { + return $this->belongsTo(Site::class); + } + + /** + * @return BelongsTo + */ + public function specialOffer(): BelongsTo + { + return $this->belongsTo(SpecialOffer::class); + } + /** * Active notices whose date range includes today. * diff --git a/app/Models/Photo.php b/app/Models/Photo.php index 70cc159..5982db4 100644 --- a/app/Models/Photo.php +++ b/app/Models/Photo.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Enums\PhotoCategory; +use App\Models\Concerns\BelongsToAppearances; use App\Models\Concerns\BelongsToTenant; use Database\Factories\PhotoFactory; use Illuminate\Database\Eloquent\Attributes\Fillable; @@ -26,7 +27,7 @@ class Photo extends Model implements HasMedia { /** @use HasFactory */ - use BelongsToTenant, HasFactory, InteractsWithMedia; + use BelongsToAppearances, BelongsToTenant, HasFactory, InteractsWithMedia; public const COLLECTION = 'image'; @@ -127,42 +128,6 @@ public static function automatic(?Property $property, ?Appearance $appearance, ? ->values(); } - /** - * Appearance ids as integers (the form may deliver strings). - * - * @return list - */ - public function appearanceIds(): array - { - return array_values(array_unique(array_map('intval', array_filter((array) $this->appearance_ids)))); - } - - /** - * Whether the photo may be shown while this appearance is in effect: all-year photos always, seasonal ones in their seasons. - */ - public function fitsSeason(?Appearance $appearance): bool - { - return $this->appearanceIds() === [] || $this->isMadeFor($appearance); - } - - /** - * Whether the photo was chosen for this appearance (seasonal photos come first while it is in effect). - */ - public function isMadeFor(?Appearance $appearance): bool - { - return $appearance !== null && in_array($appearance->id, $this->appearanceIds(), true); - } - - /** - * Names of the appearances the photo is made for (empty = all year). - * - * @return list - */ - public function appearanceNames(): array - { - return array_values(array_intersect_key(Appearance::names(), array_flip($this->appearanceIds()))); - } - public function url(string $size = 'md'): string { return $this->getFirstMediaUrl(self::COLLECTION, $size); diff --git a/app/Themes/Banner.php b/app/Themes/Banner.php new file mode 100644 index 0000000..99476eb --- /dev/null +++ b/app/Themes/Banner.php @@ -0,0 +1,20 @@ +candidates($site, $appearance) as $notice) { + $banner = $this->banner($notice); + if ($banner !== null) { + return $banner; + } + } + + return null; + } + + /** + * Visible notices for the website and the appearance, in the order they compete. + * + * @return Collection + */ + public function candidates(Site $site, ?Appearance $appearance): Collection + { + return Notice::query()->visible() + ->where(fn ($query) => $query->whereNull('site_id')->when($site->exists, fn ($query) => $query->orWhere('site_id', $site->id))) + ->with('specialOffer.property') + ->orderByDesc('priority') + ->latest() + ->orderByDesc('id') + ->get() + ->filter(fn (Notice $notice): bool => $notice->fitsSeason($appearance)) + ->values(); + } + + private function banner(Notice $notice): ?Banner + { + if ($notice->special_offer_id === null) { + return filled($notice->text) + ? new Banner($notice, (string) $notice->text, $notice->link_label, $notice->link_label ? ($notice->link_url ?: route('booking.create')) : null, $notice->tone) + : null; + } + + $offer = $notice->specialOffer; + $advertised = $offer?->property + ? $this->showcase->current($offer->property)->first(fn (AdvertisedOffer $advertised): bool => $advertised->offer->is($offer)) + : null; + if ($advertised === null) { + return null; + } + + return new Banner( + $notice, + filled($notice->text) ? (string) $notice->text : self::offerText($advertised), + $notice->link_label ?: 'Zum Angebot', + $notice->link_url ?: $advertised->bookingUrl(), + $notice->tone, + ); + } + + /** + * "Kurzfristig frei: 12.11.–15.11. · 15 % günstiger". + */ + public static function offerText(AdvertisedOffer $advertised): string + { + $dates = $advertised->arrival && $advertised->departure + ? ': '.$advertised->arrival->format('d.m.').'–'.$advertised->departure->format('d.m.') + : ''; + + return $advertised->title.$dates.' · '.$advertised->advantage; + } +} diff --git a/app/Themes/Theme.php b/app/Themes/Theme.php index 20c30b6..7bcfe53 100644 --- a/app/Themes/Theme.php +++ b/app/Themes/Theme.php @@ -23,6 +23,10 @@ class Theme private bool $propertyResolved = false; + private ?Banner $banner = null; + + private bool $bannerResolved = false; + /** @var array> */ private array $menus = []; @@ -115,6 +119,19 @@ public function sharePhoto(array $sections = []): ?Photo return $first ?? Photo::automatic($this->property(), $this->appearance)->first(); } + /** + * The banner at the top of the website right now (Admin › Webseite › Banner & Hinweise), or null. + */ + public function banner(): ?Banner + { + if (! $this->bannerResolved) { + $this->banner = app(BannerResolver::class)->for($this->site, $this->appearance); + $this->bannerResolved = true; + } + + return $this->banner; + } + public function appearanceKey(): string { return $this->appearance ? str($this->appearance->name)->slug()->toString() : 'standard'; diff --git a/database/migrations/2026_10_29_185454_turn_notices_into_banners.php b/database/migrations/2026_10_29_185454_turn_notices_into_banners.php new file mode 100644 index 0000000..69481c5 --- /dev/null +++ b/database/migrations/2026_10_29_185454_turn_notices_into_banners.php @@ -0,0 +1,60 @@ +string('text')->nullable()->change(); + $table->foreignId('site_id')->nullable()->after('tenant_id')->constrained()->cascadeOnDelete(); + $table->foreignId('special_offer_id')->nullable()->after('site_id')->constrained()->cascadeOnDelete(); + $table->json('appearance_ids')->nullable()->after('special_offer_id'); + $table->unsignedSmallInteger('priority')->default(10)->after('appearance_ids'); + }); + + foreach (DB::table('appearances')->get() as $appearance) { + $overrides = json_decode((string) $appearance->overrides, true) ?: []; + $banner = $overrides['banner'] ?? []; + if (filled($banner['text'] ?? null)) { + DB::table('notices')->insert([ + 'tenant_id' => $appearance->tenant_id, + 'site_id' => $appearance->site_id, + 'appearance_ids' => json_encode([$appearance->id]), + 'priority' => 20 + (int) $appearance->priority, + 'text' => $banner['text'], + 'tone' => 'info', + 'link_label' => $banner['link_label'] ?? null, + 'link_url' => $banner['link_url'] ?? null, + 'is_active' => $appearance->is_active, + 'created_at' => now(), + 'updated_at' => now(), + ]); + } + + if (array_key_exists('banner', $overrides)) { + unset($overrides['banner']); + DB::table('appearances')->where('id', $appearance->id)->update(['overrides' => json_encode($overrides)]); + } + } + } + + public function down(): void + { + Schema::table('notices', function (Blueprint $table) { + $table->dropConstrainedForeignId('special_offer_id'); + $table->dropConstrainedForeignId('site_id'); + $table->dropColumn(['appearance_ids', 'priority']); + }); + } +}; diff --git a/database/seeders/SiteSeeder.php b/database/seeders/SiteSeeder.php index 7fbb24c..00f87ba 100644 --- a/database/seeders/SiteSeeder.php +++ b/database/seeders/SiteSeeder.php @@ -2,6 +2,7 @@ namespace Database\Seeders; +use App\Models\Notice; use App\Models\Page; use App\Models\Property; use App\Models\Site; @@ -39,7 +40,13 @@ public function run(): void } foreach ($this->appearances() as $appearance) { - $site->appearances()->create([...$appearance, 'overrides' => Arr::undot($appearance['overrides'] ?? [])]); + $banner = Arr::pull($appearance, 'banner'); + $created = $site->appearances()->create([...$appearance, 'overrides' => Arr::undot($appearance['overrides'] ?? [])]); + + // Seasonal banners: shown only while their appearance is in effect, ahead of all-year notices. + if ($banner !== null) { + Notice::query()->create([...$banner, 'site_id' => $site->id, 'appearance_ids' => [$created->id], 'priority' => 20 + $created->priority]); + } } } @@ -139,9 +146,8 @@ private function appearances(): array [ 'name' => 'Sommer', 'starts_md' => '06-01', 'ends_md' => '08-31', 'priority' => 10, + 'banner' => ['text' => 'Sommer an der Ostsee – jetzt freie Termine prüfen.', 'link_label' => 'Termine ansehen'], 'overrides' => [ - 'banner.text' => 'Sommer an der Ostsee – jetzt freie Termine prüfen.', - 'banner.link_label' => 'Termine ansehen', 'hero.eyebrow' => 'Sommer in Kühlungsborn', 'hero.text' => '53 m² im Erdgeschoss, eigene Terrasse mit Blick auf Teich und Garten – ein paar Schritte, und Sie stehen im Sand.', 'cta.title' => 'Ihr Sommertermin ist frei?', @@ -162,9 +168,8 @@ private function appearances(): array 'name' => 'Weihnachten', 'starts_md' => '12-01', 'ends_md' => '12-25', 'priority' => 20, 'tokens' => ['ground' => '#F7F1EA', 'line' => '#E6D8C8', 'accent' => '#8C2F39', 'band' => '#3A2424', 'band-ink' => '#F7F1EA', 'band-muted' => '#E3D3C2', 'banner' => '#8C2F39'], + 'banner' => ['text' => 'Weihnachten an der Ostsee: 19.–26.12. · Mindestaufenthalt 4 Nächte.', 'link_label' => 'Verfügbarkeit prüfen'], 'overrides' => [ - 'banner.text' => 'Weihnachten an der Ostsee: 19.–26.12. · Mindestaufenthalt 4 Nächte.', - 'banner.link_label' => 'Verfügbarkeit prüfen', 'hero.eyebrow' => 'Weihnachten in Kühlungsborn', 'hero.title' => 'Besinnliche Tage *am Meer*', 'hero.text' => 'Kerzenlicht, ein Spaziergang am Winterstrand und Zeit für die Familie – Weihnachten ganz ohne Trubel.', @@ -176,9 +181,8 @@ private function appearances(): array 'name' => 'Silvester', 'starts_md' => '12-26', 'ends_md' => '01-03', 'priority' => 20, 'tokens' => ['ground' => '#141B24', 'surface' => '#1D2633', 'ink' => '#F2EEE6', 'muted' => '#B9C0C8', 'line' => '#2E3A49', 'accent' => '#C9A227', 'accent-ink' => '#141B24', 'band' => '#0D1219', 'band-ink' => '#F2EEE6', 'band-muted' => '#AEB6BF', 'banner' => '#C9A227', 'banner-ink' => '#141B24'], + 'banner' => ['text' => 'Silvester & Neujahr: 26.12.–03.01. · Mindestaufenthalt 6 Nächte.', 'link_label' => 'Noch frei?'], 'overrides' => [ - 'banner.text' => 'Silvester & Neujahr: 26.12.–03.01. · Mindestaufenthalt 6 Nächte.', - 'banner.link_label' => 'Noch frei?', 'hero.eyebrow' => 'Silvester in Kühlungsborn', 'hero.title' => 'Ins neue Jahr *mit Meerblick*', 'hero.text' => 'Feuerwerk über der Ostsee, Neujahrsspaziergang an der Promenade – und eine Wohnung, in der Sie danach ausschlafen.', diff --git a/docs/THEMES.md b/docs/THEMES.md index 3d2e428..f5b196a 100644 --- a/docs/THEMES.md +++ b/docs/THEMES.md @@ -85,6 +85,7 @@ ## 4. Was Layout und Vorlagen zur Verfügung haben | `$theme->isPreview` | Vorschau-Modus (Layout setzt `noindex` und zeigt einen Hinweis) | | `$theme->appearanceKey()` | z. B. `weihnachten` – steht als `data-appearance` am ``; für saisonale CSS-Details nutzbar: `[data-appearance=silvester] .hero {…}` | | `$theme->text($key, $fallback)` | Text des Erscheinungsbilds oder Fallback (Schlüssel: `Appearance::OVERRIDABLE`) | +| `$theme->banner()` | Das heute gezeigte Banner (`App\Themes\Banner`: `text`, `linkLabel`, `linkUrl`, `tone`) oder null | | `$theme->sharePhoto($sections)` | Vorschaubild beim Teilen und für Suchmaschinen: erstes zur Saison passendes Titelbild der Seite, sonst ein automatisches Foto der Wohnung | | `$theme->property()` | Hauptwohnung der Site | | `$theme->menu('main' \| 'footer')` | veröffentlichte Seiten des Menüs (`->url()`, `->label()`) | @@ -125,11 +126,11 @@ ## 5. Bausteinkatalog – Vertrag der Vorlagen ## 6. Erscheinungsbilder -- Felder: Name, Zeitraum `TT.MM.`–`TT.MM.` (jährlich, darf über Silvester laufen), Priorität, Standard, aktiv, Texte (`banner.text`, `banner.link_label`, `banner.link_url`, `hero.eyebrow`, `hero.title`, `hero.text`, `cta.title`, `cta.text`), Farben. +- Felder: Name, Zeitraum `TT.MM.`–`TT.MM.` (jährlich, darf über Silvester laufen), Priorität, Standard, aktiv, Texte (`hero.eyebrow`, `hero.title`, `hero.text`, `cta.title`, `cta.text`), Farben. - Startset (Seeder): Standard · Sommer 01.06.–31.08. · Winter 01.11.–31.03. · Weihnachten 01.12.–25.12. (Prio 20) · Silvester 26.12.–03.01. (Prio 20). - **Fotos:** nicht mehr am Erscheinungsbild, sondern am Foto (Webseite › Fotos › „Zeigen in“, auch als Sammelaktion). Das Erscheinungsbild zeigt nur, wie viele Fotos ihm zugeordnet sind. Umstellung 29.10.2026: Titelbild und „Bilder je Baustein“ wurden in die Bausteine übernommen (Migration `give_photos_their_seasons`). - **Vorschau:** Admin › Erscheinungsbilder › „Vorschau“ = signierter Link (24 h), `noindex` – zeigt auch die Saisonfotos. -- Ohne Erscheinungsbild-Banner wird der neueste aktive Hinweis (Admin › Hinweis-Banner) gezeigt. +- **Banner** (Admin › Webseite › Banner & Hinweise, Modell `Notice`, Auswahl `App\Themes\BannerResolver`): je Website oder für alle, optional nur in bestimmten Erscheinungsbildern (`appearance_ids`, mehrere), Zeitraum, Priorität. Es erscheint genau eines: höchste Priorität, dann das neueste. Ein Banner kann ein Sonderangebot bewerben (`special_offer_id`): Text, Termin und Link kommen dann aus dem Angebot, und es erscheint nur, solange `OfferShowcase` das Angebot bewirbt. Bei den Sonderangeboten erzeugt „Als Banner zeigen“ so ein Banner. Die Liste nennt das heute sichtbare Banner. Umstellung 29.10.2026: Banner-Texte der Erscheinungsbilder wurden zu Bannern, die auf ihr Erscheinungsbild beschränkt sind. ## 7. Assets, Schriften, Build diff --git a/docs/ZUSAMMENARBEIT.md b/docs/ZUSAMMENARBEIT.md index 125d2bc..afbf24f 100644 --- a/docs/ZUSAMMENARBEIT.md +++ b/docs/ZUSAMMENARBEIT.md @@ -84,6 +84,7 @@ ## 6. Änderungsprotokoll Vorlagen-Vertrag | Datum | Änderung | Betrifft | |---|---|---| +| 29.10.2026 | **Banner:** `partials/banner` liest `$theme->banner()` (`text`, `linkLabel`, `linkUrl`, `tone` → `data-tone`) statt `Notice::visible()` und `$theme->text('banner.*')`; die Schlüssel `banner.*` gibt es am Erscheinungsbild nicht mehr. Beide Themes angepasst. | partials/banner | | 29.10.2026 | **Fotos und Saisons:** Variablen der Vorlagen unverändert (`$photo`, `$photos`). Entfallen: `$theme->heroPhoto()`, `sectionPhotoIds()`, `sectionPhotoMode()`, `Section::photoSlots()` und die Saison-Helfer `seasonalPhoto(s)`/`withSeasonalPhotos`; neu `$theme->sharePhoto($sections)`, `chosenPhotos()`, `automaticPhotos()`, `sourcedPhotos()`. Titelbereich/Abschluss: `data.photo_ids` statt `photo_id`. Neue Fotokategorie `plan` erscheint nie automatisch. | nur Bausteinklassen; Vorlagen nicht betroffen | | 26.10.2026 | **Mandantenabschluss:** Beide Themes beziehen Logo und Favicon ausschließlich aus der Website-Marke; ohne Marke bleibt die Darstellung neutral. Dekoration und Bild-Platzhalter kommen aus Bildwelt-Plätzen. `partials/brand` bleibt als kompatible Platz-Zuordnung erhalten; Seebads `partials/motif` nutzt die Bildwelt-API. Bestehende Stommer-Marken werden vor Aktivierung ausdrücklich für diese Website importiert. | layouts/app, partials/brand, partials/logo, partials/motif, partials/image, header | | 22.10.2026 | `theme-base.css` (Schriften, Token-Mapping, Basis-Klassen) von `theme.css` getrennt – Child-Themes importieren `theme-base.css` | theme.css | diff --git a/docs/architecture/webseite.md b/docs/architecture/webseite.md index e9fcc3a..f795df7 100644 --- a/docs/architecture/webseite.md +++ b/docs/architecture/webseite.md @@ -43,7 +43,7 @@ ### Gestaltung, Marke und Saisons Eine Website wählt ein installiertes Theme. Vorhanden sind „Ostsee-Licht“ und „Seebad“. Der Vermieter kann das Theme auswählen, aber keine ausführbaren Gestaltungspakete hochladen. Vorschau-Links ermöglichen die Sichtung einer Gestaltung vor der Aktivierung. -Erscheinungsbilder ändern saisonal Texte, Farben und Banner. Fotos gehören zu einem, mehreren oder keinem Erscheinungsbild (dann ganzjährig); passende Saisonfotos erscheinen zuerst, fremde gar nicht. Grundrisse und Pläne haben eine eigene Kategorie, die keine Galerie zeigt. Der Seitenaufbau bleibt davon grundsätzlich unabhängig. Einzelne Bausteine können auf bestimmte Erscheinungsbilder begrenzt werden. Zeiträume können jährlich wiederkehren; Prioritäten und ein Standard regeln die Auswahl. Vorbereitet sind unter anderem Sommer, Winter, Weihnachten und Silvester. +Erscheinungsbilder ändern saisonal Texte und Farben. Banner werden zentral gepflegt: je Website, optional nur in bestimmten Erscheinungsbildern und Zeiträumen, mit Priorität; ein Banner kann ein Sonderangebot bewerben und verschwindet dann mit dem Angebot. Fotos gehören zu einem, mehreren oder keinem Erscheinungsbild (dann ganzjährig); passende Saisonfotos erscheinen zuerst, fremde gar nicht. Grundrisse und Pläne haben eine eigene Kategorie, die keine Galerie zeigt. Der Seitenaufbau bleibt davon grundsätzlich unabhängig. Einzelne Bausteine können auf bestimmte Erscheinungsbilder begrenzt werden. Zeiträume können jährlich wiederkehren; Prioritäten und ein Standard regeln die Auswahl. Vorbereitet sind unter anderem Sommer, Winter, Weihnachten und Silvester. Zur Website gehören Logo, Favicon und eine eigene Grafik für E-Mails beziehungsweise Vertragsunterlagen. Eine Bildwelt liefert passende Dekoration unabhängig vom Theme; eine Wohnung kann eine andere Bildwelt als ihre Website wählen. Damit können etwa eine Ostsee- und eine Bergwohnung unter derselben Grundgestaltung erscheinen. diff --git a/resources/themes/ostsee-licht/views/partials/banner.blade.php b/resources/themes/ostsee-licht/views/partials/banner.blade.php index c38c961..0977420 100644 --- a/resources/themes/ostsee-licht/views/partials/banner.blade.php +++ b/resources/themes/ostsee-licht/views/partials/banner.blade.php @@ -1,10 +1,10 @@ -@php($bannerText = $theme->text('banner.text', \App\Models\Notice::query()->visible()->latest()->value('text'))) -@if ($bannerText) -
+@php($banner = $theme->banner()) +@if ($banner) +
- {{ $bannerText }} - @if ($theme->text('banner.link_label')) - {{ $theme->text('banner.link_label') }} + {{ $banner->text }} + @if ($banner->linkLabel && $banner->linkUrl) + {{ $banner->linkLabel }} @endif
diff --git a/resources/themes/seebad/views/partials/banner.blade.php b/resources/themes/seebad/views/partials/banner.blade.php index 0fef749..f325fdb 100644 --- a/resources/themes/seebad/views/partials/banner.blade.php +++ b/resources/themes/seebad/views/partials/banner.blade.php @@ -1,11 +1,11 @@ -@php($bannerText = $theme->text('banner.text', \App\Models\Notice::query()->visible()->latest()->value('text'))) -@if ($bannerText) -
+@php($banner = $theme->banner()) +@if ($banner) +
@include('theme::partials.motif', ['slot' => 'gulls', 'class' => 'hidden h-5 w-auto opacity-80 sm:block']) - {{ $bannerText }} - @if ($theme->text('banner.link_label')) - {{ $theme->text('banner.link_label') }} + {{ $banner->text }} + @if ($banner->linkLabel && $banner->linkUrl) + {{ $banner->linkLabel }} @endif
diff --git a/tests/Feature/BannerTest.php b/tests/Feature/BannerTest.php new file mode 100644 index 0000000..74f3d92 --- /dev/null +++ b/tests/Feature/BannerTest.php @@ -0,0 +1,144 @@ +travelTo(CarbonImmutable::parse('2026-10-22 10:00')); + $this->seed([PropertySeeder::class, WebsiteContentSeeder::class, SiteSeeder::class]); + $this->withoutVite(); + $this->site = Site::sole(); + $this->property = Property::sole(); + Notice::query()->delete(); + } + + public function test_the_highest_priority_wins_and_seasonal_banners_show_only_in_their_appearances(): void + { + $christmas = $this->appearance('Weihnachten'); + $silvester = $this->appearance('Silvester'); + Notice::factory()->create(['text' => 'Ganzjährig geöffnet', 'priority' => 10]); + Notice::factory()->create(['text' => 'Festtage am Meer', 'priority' => 20, 'appearance_ids' => [$christmas->id, $silvester->id]]); + Notice::factory()->create(['text' => 'Andere Website', 'priority' => 99, 'site_id' => Site::factory()->create()->id]); + + $this->get('/')->assertOk()->assertSee('Ganzjährig geöffnet')->assertDontSee('Festtage am Meer')->assertDontSee('Andere Website'); + + $this->travelTo(CarbonImmutable::parse('2026-12-20 10:00')); + $this->get('/')->assertOk()->assertSee('Festtage am Meer')->assertDontSee('Ganzjährig geöffnet'); + + $this->travelTo(CarbonImmutable::parse('2026-12-30 10:00')); + $this->get('/')->assertOk()->assertSee('Festtage am Meer'); + } + + public function test_a_banner_for_an_offer_takes_text_and_link_from_the_offer_while_it_is_advertised(): void + { + $offer = SpecialOffer::factory()->for($this->property)->create(['name' => 'Herbstwochen', 'discount_value' => 15]); + Notice::factory()->create(['text' => 'Allgemeiner Hinweis', 'priority' => 10]); + Notice::factory()->create(['text' => null, 'special_offer_id' => $offer->id, 'priority' => 30, 'tone' => NoticeTone::Offer]); + + $this->get('/')->assertOk()->assertSee('Herbstwochen · −15 %', false)->assertSee('Zum Angebot')->assertDontSee('Allgemeiner Hinweis'); + + $offer->update(['is_active' => false]); + $this->get('/')->assertOk()->assertDontSee('Herbstwochen')->assertSee('Allgemeiner Hinweis'); + } + + public function test_offer_becomes_a_banner_with_one_click(): void + { + $this->actingAs(User::factory()->create()); + $offer = SpecialOffer::factory()->for($this->property)->create(['name' => 'Herbstwochen']); + + Livewire::test(SpecialOffersRelationManager::class, ['ownerRecord' => $this->property, 'pageClass' => EditProperty::class]) + ->callTableAction('banner', $offer); + + $notice = Notice::query()->sole(); + $this->assertSame($offer->id, $notice->special_offer_id); + $this->assertSame($this->site->id, $notice->site_id); + $this->assertSame(NoticeTone::Offer, $notice->tone); + $this->assertNull($notice->text); + } + + public function test_banner_list_names_the_banner_shown_today_and_a_text_banner_needs_a_text(): void + { + $this->actingAs(User::factory()->create()); + Notice::factory()->create(['text' => 'Neue Betten im Schlafzimmer', 'priority' => 10]); + Notice::factory()->create(['text' => 'Abgelaufen', 'ends_on' => '2026-10-01']); + + $this->get(NoticeResource::getUrl('index'))->assertOk()->assertSee('Heute sichtbar: „Neue Betten im Schlafzimmer“', false); + + Livewire::test(CreateNotice::class) + ->fillForm(['text' => null, 'special_offer_id' => null]) + ->call('create') + ->assertHasFormErrors(['text' => 'required']); + Livewire::test(ListNotices::class)->assertSuccessful(); + } + + public function test_banner_texts_of_appearances_become_seasonal_banners(): void + { + $migration = require database_path('migrations/2026_10_29_185454_turn_notices_into_banners.php'); + $migration->down(); + $summer = $this->appearance('Sommer'); + DB::table('appearances')->where('id', $summer->id)->update(['overrides' => json_encode([ + 'banner' => ['text' => 'Sommer an der Ostsee', 'link_label' => 'Termine ansehen', 'link_url' => null], + 'hero' => ['eyebrow' => 'Sommer in Kühlungsborn'], + ])]); + + $migration->up(); + + $notice = Notice::query()->sole(); + $this->assertSame('Sommer an der Ostsee', $notice->text); + $this->assertSame([$summer->id], $notice->appearance_ids); + $this->assertSame($this->site->id, $notice->site_id); + $this->assertSame(20 + $summer->priority, $notice->priority); + $this->assertSame(['hero' => ['eyebrow' => 'Sommer in Kühlungsborn']], $summer->fresh()->overrides); + + $this->travelTo(CarbonImmutable::parse('2026-07-10 10:00')); + $this->get('/')->assertOk()->assertSee('Sommer an der Ostsee')->assertSee('Termine ansehen'); + } + + public function test_appearance_names_are_kept_apart_per_landlord(): void + { + $this->assertContains('Winter', Appearance::names()); + $other = Tenant::factory()->create(); + + app(TenantContext::class)->run($other, function (): void { + $this->assertSame([], Appearance::names()); + }); + } + + private function appearance(string $name): Appearance + { + return $this->site->appearances()->where('name', $name)->sole(); + } +} From 4e6ad792eb015f2b52ae807709fe1b919e027a8d Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 29 Oct 2026 19:02:01 +0100 Subject: [PATCH 5/5] Stand Wohnungsumschalter, Saisonfotos und Banner dokumentieren Co-Authored-By: Claude Opus 5.5 --- docs/STATUS.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/STATUS.md b/docs/STATUS.md index 33c8786..b05593a 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -1,5 +1,11 @@ # Projektstand +**Wohnungen, Bilder und Banner neu geordnet (29.10.2026, Branch `feature/wohnungs-kontext`):** +- **Wohnungsumschalter** oben im Verwaltungsmenü (`App\Support\CurrentProperty`, je Mandant in der Sitzung). Listen (Fotos, Ausstattung, Bewertungen, Grundrisse, Sperrzeiten, Kanäle, Portal-Aufgaben/-Mails, Importereignisse), neue Einträge, Belegungsplan und Preise & Angebote folgen ihm; die Buchungsliste startet mit dem Filter auf die Wohnung. Ein geöffneter Eintrag einer anderen Wohnung (z. B. aus einer Mail) schaltet um. Website: Galerie und Ersatz-Titelbild zeigen nur Fotos der Wohnung des Bausteins und Fotos ohne Wohnung. +- **Grundriss & Pläne:** eigene Fotokategorie, die keine Galerie zeigt; vorhandene Grundriss-Bilder wurden umgestellt. Ausgeblendete Planbilder funktionieren im Grundriss weiterhin. +- **Saisonfotos am Foto:** „Zeigen in“ (mehrere Erscheinungsbilder, leer = ganzjährig; auch als Sammelaktion). Saisonfotos erscheinen nur in ihren Erscheinungsbildern und dort zuerst. Galerie und Lage: „automatisch“ oder „eigene Auswahl“; Titelbereich und Abschluss zeigen das erste passende Foto ihrer Liste. Titelbild und „Bilder je Baustein“ am Erscheinungsbild entfallen (Daten in die Bausteine übernommen, Testsystem: Titelbild Foto 5 → Titelbereich der Startseite). +- **Banner & Hinweise:** ein Banner zur Zeit, je Website, optional nur in Erscheinungsbildern, mit Zeitraum und Priorität; kann ein Sonderangebot bewerben (Text/Termin/Link aus dem Angebot, verschwindet mit ihm). „Als Banner zeigen“ bei den Sonderangeboten; die Liste nennt das heute sichtbare Banner. Banner-Texte von Sommer, Weihnachten und Silvester wurden zu saisonalen Bannern. +- Tests: **508 Feature-Tests / 2654 Assertions grün**, Pint. Zwei Migrationen mit Datenübernahme (`give_photos_their_seasons`, `turn_notices_into_banners`), eine für Plan-Fotos. Offen: Promotion Engine (automatische Banner-/Angebotsvorschläge nach Saison, Lücken, Last-Minute) als nächste Stufe. **Automatische iCal-Kalenderspiegelungen (29.10.2026, bereitgestellt):** Eindeutig per aktiver Regel erkannte zusätzliche allgemeine Belegtmeldungen ohne eigene Buchungsmerkmale werden einer einzigen führenden Portalreservierung eines anderen Kanals mit exakt gleichen Terminen zugeordnet. Keine Terminheuristik bei unbekannten Ereignissen, mehreren Quellbuchungen, widersprüchlichen Überschneidungen oder persönlichen Entscheidungen. Import und Regelanwendung prüfen die gesamte Wohnung; Kalender zeigt eine Belegung mit „Auch bei … gespiegelt“, geklärte Spiegelungen verschwinden aus Klärungsliste und Zähler. Neue Kennzeichnung `representation_automatic` trennt persönliche und automatische Zuordnungen. Nur automatische Verknüpfungen werden bei Änderungen, fehlender Quelle oder neuer Mehrdeutigkeit gelöst; weiterhin gemeldete Nächte bleiben intern belegt und vom Rückexport ausgeschlossen. Persönliche Entscheidungen bleiben erhalten. Konfliktprüfung erfolgt nach der Zuordnung, vermeidet falsche Doppelbuchungsmeldungen und erhält tatsächliche Konflikte. **198 relevante Tests / 1188 Assertions und Pint erfolgreich**, davon 24 neue Tests / 136 Assertions mit beiden Importreihenfolgen, Regelanwendung auf Bestand, Änderungen, fehlender Quelle/Wiederkehr, Buchungsmerkmalen, Mehrdeutigkeit und Mandantentrennung. Additive Migration, kein Bestandsumbau in der Migration. [Regeln und Lebenszyklus](architecture/ical-regelengine.md#führende-repräsentation-und-zuordnung). Mit `add2367` auf stommer.info bereitgestellt; Release `20261029160338-add23678`, Serverrevision und Migration in MariaDB-Batch 21 bestätigt. Private Sicherung 31.720.347 Bytes, Gesundheit/Anmeldung HTTP 200, Belegungsplan unangemeldet zur Anmeldung umgeleitet. Reguläre Importe danach um 17:05:04 MEZ (Destination) und 17:05:08 MEZ (FeWo-direkt) erfolgreich, kein Kanalfehler. Aktuell null automatische Zuordnungen: Der frühere zeitgleiche FeWo-Eintrag #4 ist archiviert; aktiver FeWo-Eintrag #15 endet am 01.01.2027, Destination #14 am 02.01.2027 (beide ab 27.12.2026). Unterschied bereits in gespeicherten Originalfeldern vorhanden (FeWo DTEND 20270101, Destination 20270102T120000), kein Parserfehler; daher bewusster Prüffall. Keine echten Testbelegungen angelegt oder Quelldaten passend gemacht. Keine zusätzliche visuelle Browserabnahme; Bedienung und Kalenderdarstellung mit Livewire geprüft. **Abbruch beim Anwenden von iCal-Regeln korrigiert (29.10.2026, bereitgestellt):** Destination Solution rein lesend geprüft: Entwurf vorhanden, aktive Regeln leer; nachfolgender Import unterscheidet sich von der Vorschau nur in DTSTAMP, bei gleichen Terminen und gleichem Regelergebnis. Bisher blockierte die Prüfung auf veraltete Originaldaten auch diese reine Zeitstempeländerung; die Validierungsnachricht blieb hinter dem Bestätigungsdialog unsichtbar. Reine DTSTAMP-/LAST-MODIFIED-Änderungen werden jetzt nur bei vollständig gleichem Regelergebnis toleriert, neueste importierte Originale bleiben erhalten. Fachliche Änderungen oder ein durch Zeitstempel geändertes Regelergebnis verlangen weiterhin eine neue Vorschau. Validierungsabbrüche schließen den Dialog, zeigen eine dauerhafte Meldung und behalten die Formulareingaben; gespeicherter Regelstand wird nach dem Transaktionsrückbau neu geladen. Erfolg schließt die Bestätigung und aktualisiert den aktiven Regelstand. **174 relevante Tests / 1052 Assertions und Pint erfolgreich**, darin 41 Regelengine-Tests / 289 Assertions und sieben zusätzliche Fälle mit tatsächlichem Öffnen und Bestätigen des Dialogs, Aktualisierungsrennen, fehlerhafter Extraktion und Formularvalidierung. Keine echten Kanalregeln aktiviert, keine Kalenderdaten zusammengeführt; identische Tage allein bleiben kein Identitätsnachweis. [Befund und Bedienung](architecture/ical-regelengine.md#vorschau-entwurf-und-aktivierung). Mit `a0497fc` über den vorhandenen PipelineManager bereitgestellt; Release `20261029152758-a0497fcc`, Serverrevision, private Sicherung (31.620.399 Bytes) und HTTP 200 für Gesundheit/Anmeldung bestätigt. Neue Regelseite unangemeldet zur Anmeldung umgeleitet. Die ausgelieferte Zeitstempelprüfung zusätzlich rein lesend gegen den echten Destination-Bestand ausgeführt: akzeptiert; Entwurf erkennt Portalreservierung/Führungskandidat. Aktive Regeln weiterhin leer, keine persönliche Anwendung vorweggenommen. Keine neue Migration oder zusätzliche visuelle Browserabnahme. Gitea-Status-API HTTP 401; Auslesen gespeicherter Git-Zugangsdaten dafür durch automatische Freigabeprüfung abgelehnt und nicht ausgeführt. Deployment über vorhandene SSH-Zugänge und aktive Serverrevision bestätigt, kein ungeprüfter API-Erfolgsstatus behauptet.