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 <noreply@anthropic.com>
This commit is contained in:
1 parent
d02f3e05c7
commit
791786ed3e
21 files changed
+449
-235
No files matched your search
@@ -40,7 +40,8 @@ public static function optionLabel(Photo $photo): string
|
||||
? '<img src="'.e($thumbnail).'" alt="" loading="lazy" style="width:4.5rem;height:3rem;object-fit:cover;border-radius:.25rem;flex-shrink:0">'
|
||||
: '<span style="width:4.5rem;height:3rem;border-radius:.25rem;background:#e5e7eb;flex-shrink:0"></span>';
|
||||
$hidden = $photo->is_published ? '' : ' <em style="opacity:.6">(ausgeblendet)</em>';
|
||||
$seasons = $photo->appearanceNames() === [] ? '' : ' <em style="opacity:.75">· nur '.e(implode(', ', $photo->appearanceNames())).'</em>';
|
||||
|
||||
return '<span style="display:flex;align-items:center;gap:.75rem">'.$image.'<span>'.e($photo->alt_text).$hidden.'</span></span>';
|
||||
return '<span style="display:flex;align-items:center;gap:.75rem">'.$image.'<span>'.e($photo->alt_text).$seasons.$hidden.'</span></span>';
|
||||
}
|
||||
}
|
||||
@@ -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[<section id>][<slot>].
|
||||
*
|
||||
* @return list<Component>
|
||||
* 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.",
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<int|string>|null $state
|
||||
* @return list<int>|null
|
||||
*/
|
||||
public static function appearanceIds(?array $state): ?array
|
||||
{
|
||||
$ids = array_values(array_unique(array_map('intval', array_filter((array) $state))));
|
||||
|
||||
return $ids === [] ? null : $ids;
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
]),
|
||||
]);
|
||||
|
||||
@@ -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<string, mixed>|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'),
|
||||
|
||||
@@ -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<AppearanceFactory> */
|
||||
@@ -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<Photo, $this>
|
||||
* Names by id of the landlord's appearances, loaded once per request and landlord.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
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<int, string>
|
||||
*/
|
||||
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
|
||||
|
||||
+57
-1
@@ -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<PhotoFactory> */
|
||||
@@ -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<int, Photo>
|
||||
*/
|
||||
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<int>
|
||||
*/
|
||||
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<string>
|
||||
*/
|
||||
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);
|
||||
|
||||
@@ -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'),
|
||||
];
|
||||
|
||||
@@ -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),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
|
||||
@@ -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(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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<string, array{label: string, type: string, max?: int}>
|
||||
*/
|
||||
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<string, mixed> $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<string, mixed> $data
|
||||
* @return Collection<int, Photo>|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<string, mixed> $data
|
||||
* @param Collection<int, Photo> $automatic
|
||||
* @param list<int|string>|null $ids
|
||||
* @return Collection<int, Photo>
|
||||
*/
|
||||
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<int, Photo>
|
||||
*/
|
||||
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<string, mixed> $data
|
||||
* @return Collection<int, Photo>
|
||||
*/
|
||||
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<Component>
|
||||
*/
|
||||
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
|
||||
|
||||
@@ -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),
|
||||
|
||||
+13
-24
@@ -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<int>
|
||||
* @param list<array<string, mixed>> $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
|
||||
|
||||
Reference in new issue
Block a user