Titelvideo, Rundgang mit Kapiteln, naechste freie Termine, ruhigere Buchungsseite
- Webseite > Videos (Datei, Standbild, Kapitel mit Raum im Grundriss); Upload bis 100 MB - Titelbereich: Video statt Foto (stumme Schleife, respektiert Bewegung reduzieren/Save-Data) und naechste freie Termine mit Gesamtpreis (NextFreeStays) - Neuer Baustein Rundgang (Video) mit waehlbarer Anordnung; Grundriss springt ins Video - Buchungsseite: Preis unter dem Kalender, Formular rechts, Ablauf als Grafik - Seebad: Fahrkarten, Fahrplan-Kapitel, Sonnenaufgang als einmaliges Ereignis Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f5f18cd984
commit
d42c42059c
38 files changed
+1279
-23
No files matched your search
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Availability;
|
||||
|
||||
use App\Models\Property;
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\PriceQuote;
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\StayRequest;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* The next bookable stays from tomorrow on, for the "next free dates" in the hero section: free nights
|
||||
* that the PriceCalculator accepts (minimum stay, offers applied), at least $nights long, not overlapping.
|
||||
* Cached briefly per apartment because each candidate is a full price calculation (dates as strings: the cache
|
||||
* does not unserialize objects).
|
||||
*/
|
||||
class NextFreeStays
|
||||
{
|
||||
public const HORIZON_DAYS = 120;
|
||||
|
||||
public const MAX_NIGHTS = 7;
|
||||
|
||||
public function __construct(
|
||||
private AvailabilityChecker $availability,
|
||||
private PriceCalculator $calculator,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return list<array{arrival: CarbonImmutable, departure: CarbonImmutable, nights: int, total: int, url: string}>
|
||||
*/
|
||||
public function for(Property $property, int $count = 3, int $nights = 3, int $guests = 2): array
|
||||
{
|
||||
$key = "next-free-stays:{$property->id}:{$count}:{$nights}:{$guests}:".today()->toDateString();
|
||||
|
||||
$stays = Cache::remember($key, now()->addMinutes(10), fn (): array => $this->find($property, $count, $nights, min($guests, $property->max_guests)));
|
||||
|
||||
return array_map(fn (array $stay): array => [
|
||||
...$stay,
|
||||
'arrival' => CarbonImmutable::parse($stay['arrival']),
|
||||
'departure' => CarbonImmutable::parse($stay['departure']),
|
||||
], $stays);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{arrival: string, departure: string, nights: int, total: int, url: string}>
|
||||
*/
|
||||
private function find(Property $property, int $count, int $nights, int $guests): array
|
||||
{
|
||||
$from = CarbonImmutable::tomorrow();
|
||||
$until = $from->addDays(self::HORIZON_DAYS + self::MAX_NIGHTS);
|
||||
$occupied = $this->availability->occupiedNights($property, $from, $until);
|
||||
$stays = [];
|
||||
|
||||
for ($arrival = $from; count($stays) < $count && $arrival->lessThan($from->addDays(self::HORIZON_DAYS)); $arrival = $arrival->addDay()) {
|
||||
if (isset($occupied[$arrival->toDateString()])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$quote = $this->firstPricedStay($property, $arrival, $nights, $guests, $occupied);
|
||||
if ($quote === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$stays[] = [
|
||||
'arrival' => $quote->arrival->toDateString(),
|
||||
'departure' => $quote->departure->toDateString(),
|
||||
'nights' => $quote->nights(),
|
||||
'total' => $quote->total(),
|
||||
'url' => route('booking.create', ['anreise' => $quote->arrival->toDateString(), 'abreise' => $quote->departure->toDateString(), 'personen' => $guests]),
|
||||
];
|
||||
$arrival = $quote->departure->subDay();
|
||||
}
|
||||
|
||||
return $stays;
|
||||
}
|
||||
|
||||
/**
|
||||
* The shortest stay of at least $nights from $arrival that is free and priceable, if any.
|
||||
*
|
||||
* @param array<string, true> $occupied
|
||||
*/
|
||||
private function firstPricedStay(Property $property, CarbonImmutable $arrival, int $nights, int $guests, array $occupied): ?PriceQuote
|
||||
{
|
||||
for ($length = 1; $length <= self::MAX_NIGHTS; $length++) {
|
||||
if (isset($occupied[$arrival->addDays($length - 1)->toDateString()])) {
|
||||
return null;
|
||||
}
|
||||
if ($length < $nights) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->calculator->calculate($property, new StayRequest($arrival, $arrival->addDays($length), $guests));
|
||||
} catch (QuoteException) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Videos\Pages;
|
||||
|
||||
use App\Filament\Resources\Videos\VideoResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateVideo extends CreateRecord
|
||||
{
|
||||
protected static string $resource = VideoResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Videos\Pages;
|
||||
|
||||
use App\Filament\Resources\Videos\VideoResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditVideo extends EditRecord
|
||||
{
|
||||
protected static string $resource = VideoResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Videos\Pages;
|
||||
|
||||
use App\Filament\Concerns\ListsCurrentProperty;
|
||||
use App\Filament\Resources\Videos\VideoResource;
|
||||
use App\Models\Property;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ListVideos extends ListRecords
|
||||
{
|
||||
use ListsCurrentProperty;
|
||||
|
||||
protected static string $resource = VideoResource::class;
|
||||
|
||||
/**
|
||||
* Videos of the chosen apartment and those without one (e.g. the area).
|
||||
*/
|
||||
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 [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Videos\Schemas;
|
||||
|
||||
use App\Models\FloorPlan;
|
||||
use App\Models\Property;
|
||||
use App\Models\Video;
|
||||
use App\Support\CurrentProperty;
|
||||
use Closure;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class VideoForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
SpatieMediaLibraryFileUpload::make('file')
|
||||
->label('Videodatei')
|
||||
->collection(Video::COLLECTION)
|
||||
->disk('public')
|
||||
->acceptedFileTypes(['video/mp4', 'application/mp4', 'video/webm'])
|
||||
->maxSize(Video::MAX_KB)
|
||||
->helperText('MP4 (H.264) oder WebM bis 100 MB. Für den Titelbereich reicht eine kurze stumme Schleife von 6–10 Sekunden und 2–4 MB – sie lädt auf jedem Handy mit.')
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
SpatieMediaLibraryFileUpload::make('poster')
|
||||
->label('Standbild')
|
||||
->collection(Video::POSTER)
|
||||
->disk('public')
|
||||
->image()
|
||||
->maxSize(25 * 1024)
|
||||
->helperText('Wird gezeigt, bis das Video läuft, und statt des Videos, wenn Besucher „Bewegung reduzieren“ eingestellt haben. Am besten ein Bild aus dem Video.')
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
TextInput::make('title')
|
||||
->label('Titel')
|
||||
->helperText('Für Sie zur Auswahl in den Bausteinen und für Screenreader („Video: …“).')
|
||||
->required()
|
||||
->maxLength(160),
|
||||
Select::make('property_id')
|
||||
->label('Wohnung')
|
||||
->options(fn (): array => Property::query()->pluck('name', 'id')->all())
|
||||
->default(fn (): ?int => app(CurrentProperty::class)->id())
|
||||
->placeholder('– keine (z. B. Umgebung) –')
|
||||
->live(),
|
||||
Section::make('Kapitel')
|
||||
->description('Für den Rundgang: Besucher springen per Knopf zu einem Raum. Ist ein Raum aus dem Grundriss gewählt, bietet der Grundriss bei diesem Raum „Im Video ansehen“ an.')
|
||||
->collapsible()
|
||||
->columnSpanFull()
|
||||
->schema([
|
||||
Repeater::make('chapters')
|
||||
->hiddenLabel()
|
||||
->addActionLabel('Kapitel hinzufügen')
|
||||
->columns(3)
|
||||
->defaultItems(0)
|
||||
->reorderable(false)
|
||||
->itemLabel(fn (array $state): ?string => trim(($state['at'] ?? '').' '.($state['label'] ?? '')) ?: null)
|
||||
->schema([
|
||||
TextInput::make('at')
|
||||
->label('Ab (Min:Sek)')
|
||||
->placeholder('0:16')
|
||||
->required()
|
||||
->rules([fn (): Closure => function (string $attribute, mixed $value, Closure $fail): void {
|
||||
if (Video::seconds($value) === null) {
|
||||
$fail('Bitte als Minuten:Sekunden angeben, z. B. 0:16 oder 1:05.');
|
||||
}
|
||||
}]),
|
||||
TextInput::make('label')
|
||||
->label('Bezeichnung')
|
||||
->placeholder('Wohnzimmer')
|
||||
->required()
|
||||
->maxLength(60),
|
||||
Select::make('room')
|
||||
->label('Raum im Grundriss')
|
||||
->options(fn (Get $get): array => self::roomOptions($get('../../property_id')))
|
||||
->placeholder('– keiner –'),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Names of the visible floor plan rooms of the apartment (name => name).
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function roomOptions(mixed $propertyId): array
|
||||
{
|
||||
$plan = filled($propertyId) ? FloorPlan::query()->where('property_id', $propertyId)->first() : null;
|
||||
|
||||
return $plan?->visibleRooms()->pluck('name', 'name')->all() ?? [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Videos\Tables;
|
||||
|
||||
use App\Models\Video;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\SpatieMediaLibraryImageColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class VideosTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('title')
|
||||
->emptyStateHeading('Noch keine Videos')
|
||||
->emptyStateDescription('Laden Sie ein Video hoch und wählen Sie es danach im Titelbereich oder im Baustein „Rundgang (Video)“ aus.')
|
||||
->columns([
|
||||
SpatieMediaLibraryImageColumn::make('poster')
|
||||
->label('')
|
||||
->collection(Video::POSTER)
|
||||
->conversion('poster')
|
||||
->imageHeight(64),
|
||||
TextColumn::make('title')->label('Titel')->searchable()->weight('medium'),
|
||||
TextColumn::make('property.name')->label('Wohnung')->placeholder('–'),
|
||||
TextColumn::make('chapters')
|
||||
->label('Kapitel')
|
||||
->state(fn (Video $record): string => (string) count($record->chapterList())),
|
||||
TextColumn::make('size')
|
||||
->label('Größe')
|
||||
->state(fn (Video $record): ?string => $record->getFirstMedia(Video::COLLECTION)?->human_readable_size),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Videos;
|
||||
|
||||
use App\Filament\Concerns\FollowsAdminMode;
|
||||
use App\Filament\Concerns\SelectsRecordProperty;
|
||||
use App\Filament\Resources\Videos\Pages\CreateVideo;
|
||||
use App\Filament\Resources\Videos\Pages\EditVideo;
|
||||
use App\Filament\Resources\Videos\Pages\ListVideos;
|
||||
use App\Filament\Resources\Videos\Schemas\VideoForm;
|
||||
use App\Filament\Resources\Videos\Tables\VideosTable;
|
||||
use App\Models\Video;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Website videos: chosen in the hero section (silent loop) and in the tour section (with chapters).
|
||||
*/
|
||||
class VideoResource extends Resource
|
||||
{
|
||||
use FollowsAdminMode, SelectsRecordProperty;
|
||||
|
||||
protected static ?string $model = Video::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedFilm;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
|
||||
|
||||
protected static ?string $modelLabel = 'Video';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Videos';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return VideoForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return VideosTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListVideos::route('/'),
|
||||
'create' => CreateVideo::route('/create'),
|
||||
'edit' => EditVideo::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use Database\Factories\VideoFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Spatie\Image\Enums\Fit;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
|
||||
/**
|
||||
* A website video: a short silent loop for the hero section or a tour with chapters (TourSection).
|
||||
* Chapters link a moment to a floor plan room by its name, so the floor plan can jump into the video.
|
||||
*
|
||||
* @property list<array{at?: string, label?: string, room?: string|null}>|null $chapters
|
||||
*/
|
||||
#[Fillable(['property_id', 'title', 'chapters'])]
|
||||
class Video extends Model implements HasMedia
|
||||
{
|
||||
/** @use HasFactory<VideoFactory> */
|
||||
use BelongsToTenant, HasFactory, InteractsWithMedia;
|
||||
|
||||
public const COLLECTION = 'video';
|
||||
|
||||
public const POSTER = 'poster';
|
||||
|
||||
/** Largest accepted video file in KB (Strato allows uploads up to 128 MB). */
|
||||
public const MAX_KB = 100 * 1024;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'chapters' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function registerMediaCollections(): void
|
||||
{
|
||||
$this->addMediaCollection(self::COLLECTION)
|
||||
->useDisk('public')
|
||||
->singleFile()
|
||||
->acceptsMimeTypes(['video/mp4', 'application/mp4', 'video/webm']);
|
||||
|
||||
$this->addMediaCollection(self::POSTER)
|
||||
->useDisk('public')
|
||||
->singleFile()
|
||||
->acceptsMimeTypes(['image/jpeg', 'image/png', 'image/webp']);
|
||||
}
|
||||
|
||||
public function registerMediaConversions(?Media $media = null): void
|
||||
{
|
||||
$this->addMediaConversion('poster')
|
||||
->fit(Fit::Max, 1920, 1920)
|
||||
->format('webp')
|
||||
->quality(80)
|
||||
->performOnCollections(self::POSTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Property, $this>
|
||||
*/
|
||||
public function property(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Property::class);
|
||||
}
|
||||
|
||||
public function url(): ?string
|
||||
{
|
||||
return $this->getFirstMediaUrl(self::COLLECTION) ?: null;
|
||||
}
|
||||
|
||||
public function mimeType(): string
|
||||
{
|
||||
return $this->getFirstMedia(self::COLLECTION)?->mime_type ?? 'video/mp4';
|
||||
}
|
||||
|
||||
public function posterUrl(): ?string
|
||||
{
|
||||
return $this->getFirstMediaUrl(self::POSTER, 'poster') ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Chapters in time order with the start in seconds; entries without a valid time or label are left out.
|
||||
*
|
||||
* @return list<array{seconds: int, time: string, label: string, room: string|null}>
|
||||
*/
|
||||
public function chapterList(): array
|
||||
{
|
||||
$chapters = [];
|
||||
foreach ($this->chapters ?? [] as $chapter) {
|
||||
$seconds = self::seconds($chapter['at'] ?? null);
|
||||
if ($seconds === null || blank($chapter['label'] ?? null)) {
|
||||
continue;
|
||||
}
|
||||
$chapters[] = [
|
||||
'seconds' => $seconds,
|
||||
'time' => sprintf('%d:%02d', intdiv($seconds, 60), $seconds % 60),
|
||||
'label' => (string) $chapter['label'],
|
||||
'room' => filled($chapter['room'] ?? null) ? (string) $chapter['room'] : null,
|
||||
];
|
||||
}
|
||||
|
||||
usort($chapters, fn (array $a, array $b): int => $a['seconds'] <=> $b['seconds']);
|
||||
|
||||
return $chapters;
|
||||
}
|
||||
|
||||
/**
|
||||
* The chapter showing a floor plan room (matched by name), if any.
|
||||
*
|
||||
* @return array{seconds: int, time: string, label: string, room: string|null}|null
|
||||
*/
|
||||
public function chapterForRoom(string $room): ?array
|
||||
{
|
||||
foreach ($this->chapterList() as $chapter) {
|
||||
if ($chapter['room'] !== null && mb_strtolower($chapter['room']) === mb_strtolower($room)) {
|
||||
return $chapter;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* "1:05" or "65" → 65; anything else → null.
|
||||
*/
|
||||
public static function seconds(mixed $value): ?int
|
||||
{
|
||||
$value = trim((string) $value);
|
||||
if (preg_match('/^(\d{1,3}):([0-5]\d)$/', $value, $match)) {
|
||||
return (int) $match[1] * 60 + (int) $match[2];
|
||||
}
|
||||
|
||||
return preg_match('/^\d{1,4}$/', $value) ? (int) $value : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\Permission;
|
||||
|
||||
class VideoPolicy extends RolePolicy
|
||||
{
|
||||
protected function permission(): Permission
|
||||
{
|
||||
return Permission::Content;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,21 @@
|
||||
use App\Themes\Theme;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
|
||||
/**
|
||||
* Availability calendar, live price and booking request (Livewire component App\Livewire\BookingRequest).
|
||||
* Availability calendar, live price and booking request (Livewire component App\Livewire\BookingRequest), optionally
|
||||
* with the three steps of the booking path (request → offer → acceptance) as a graphic.
|
||||
*/
|
||||
class BookingSection extends Section
|
||||
{
|
||||
/** Booking path 1 (KONZEPT §6a) in the guest's words: title => explanation. */
|
||||
public const STEPS = [
|
||||
'Anfrage senden' => 'Kostenlos und unverbindlich. Wir halten den Termin sofort für Sie frei.',
|
||||
'Angebot erhalten' => 'Per E-Mail mit Gesamtpreis und Mietvertrag – in Ruhe prüfen.',
|
||||
'Annehmen' => 'Mit einem Klick im Angebot. Erst dann ist die Buchung verbindlich.',
|
||||
];
|
||||
|
||||
public static function key(): string
|
||||
{
|
||||
return 'booking';
|
||||
@@ -31,6 +40,10 @@ public static function schema(): array
|
||||
return [
|
||||
TextInput::make('heading')->label('Überschrift')->default('Preise & Buchung')->maxLength(120),
|
||||
Textarea::make('text')->label('Text')->rows(2),
|
||||
Toggle::make('show_steps')
|
||||
->label('Ablauf als Grafik zeigen')
|
||||
->helperText('Anfrage → Angebot per E-Mail → Annahme, über dem Kalender.')
|
||||
->default(true),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -39,6 +52,8 @@ public function data(Theme $theme, array $data): array
|
||||
return [
|
||||
'heading' => $data['heading'] ?? null,
|
||||
'text' => $data['text'] ?? null,
|
||||
'showSteps' => (bool) ($data['show_steps'] ?? true),
|
||||
'steps' => self::STEPS,
|
||||
'property' => $theme->property(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
use App\Models\Amenity;
|
||||
use App\Models\FloorPlan;
|
||||
use App\Models\Photo;
|
||||
use App\Models\Video;
|
||||
use App\Themes\Theme;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
@@ -52,6 +53,7 @@ public function data(Theme $theme, array $data): array
|
||||
$amenities = Amenity::query()
|
||||
->whereIn('id', $rooms->flatMap(fn (array $room): array => $room['amenity_ids'] ?? [])->unique()->all())
|
||||
->pluck('name', 'id');
|
||||
$videos = $rooms->isEmpty() ? collect() : Video::query()->where('property_id', $plan->property_id)->whereNotNull('chapters')->get();
|
||||
|
||||
return [
|
||||
'heading' => $data['heading'] ?? 'Der Grundriss',
|
||||
@@ -65,6 +67,7 @@ public function data(Theme $theme, array $data): array
|
||||
'points' => collect(FloorPlan::points($room['points']))->map(fn (array $point): string => $point[0].','.$point[1])->implode(' '),
|
||||
'photos' => collect($room['photo_ids'] ?? [])->map(fn ($id) => $photos->get((int) $id))->filter()->values(),
|
||||
'amenities' => collect($room['amenity_ids'] ?? [])->map(fn ($id) => $amenities->get((int) $id))->filter()->values(),
|
||||
'videoChapter' => $videos->map(fn (Video $video): ?array => $video->chapterForRoom($room['name']))->filter()->first(),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -2,14 +2,18 @@
|
||||
|
||||
namespace App\Themes\Sections;
|
||||
|
||||
use App\Availability\NextFreeStays;
|
||||
use App\Pricing\OfferShowcase;
|
||||
use App\Themes\Theme;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
|
||||
/**
|
||||
* Large photo with headline and the availability search. Seasonal appearances replace photo and texts.
|
||||
* Large photo (or a silent video loop) with headline, the availability search and the next free dates.
|
||||
* Seasonal appearances replace photo and texts.
|
||||
*/
|
||||
class HeroSection extends Section
|
||||
{
|
||||
@@ -36,7 +40,20 @@ public static function schema(): array
|
||||
Textarea::make('text')->label('Text')->rows(2)->maxLength(400),
|
||||
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),
|
||||
static::videoSelect('video_id', 'Video statt Foto')
|
||||
->helperText('Läuft stumm in Schleife an der Stelle des Fotos (Webseite › Videos). Bei „Bewegung reduzieren“ und langsamer Verbindung bleibt das Standbild des Videos stehen.'),
|
||||
Toggle::make('show_search')->label('Verfügbarkeitssuche anzeigen')->default(true),
|
||||
Toggle::make('show_free_dates')
|
||||
->label('Nächste freie Termine zeigen')
|
||||
->helperText('Bis zu drei buchbare Zeiträume mit Gesamtpreis; ein Klick öffnet die Anfrage mit diesen Daten.')
|
||||
->default(true)
|
||||
->live(),
|
||||
Select::make('free_dates_nights')
|
||||
->label('Mindestens … Nächte')
|
||||
->options(array_combine(range(2, 7), array_map(fn (int $nights): string => "{$nights} Nächte", range(2, 7))))
|
||||
->default(3)
|
||||
->selectablePlaceholder(false)
|
||||
->visible(fn (Get $get): bool => (bool) $get('show_free_dates')),
|
||||
Toggle::make('show_offer')
|
||||
->label('Hervorgehobenes Sonderangebot im Titelbereich zeigen')
|
||||
->helperText('Das wichtigste als „hervorgehoben“ markierte Angebot, sofern gerade eins gilt.')
|
||||
@@ -46,18 +63,24 @@ public static function schema(): array
|
||||
|
||||
public function data(Theme $theme, array $data): array
|
||||
{
|
||||
$featuredOffer = ($data['show_offer'] ?? true) && $theme->property()
|
||||
? app(OfferShowcase::class)->current($theme->property(), limit: 1, featuredOnly: true)->first()
|
||||
$property = $theme->property();
|
||||
$featuredOffer = ($data['show_offer'] ?? true) && $property
|
||||
? app(OfferShowcase::class)->current($property, limit: 1, featuredOnly: true)->first()
|
||||
: null;
|
||||
$freeStays = ($data['show_free_dates'] ?? false) && $property
|
||||
? app(NextFreeStays::class)->for($property, nights: (int) ($data['free_dates_nights'] ?? 3))
|
||||
: [];
|
||||
|
||||
return [
|
||||
'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->chosenPhotos($theme, $data['photo_ids'] ?? [])->first() ?? $this->automaticPhotos($theme, limit: 1)->first(),
|
||||
'video' => $this->video($data['video_id'] ?? null),
|
||||
'freeStays' => $freeStays,
|
||||
'featuredOffer' => $featuredOffer,
|
||||
'showSearch' => (bool) ($data['show_search'] ?? true),
|
||||
'property' => $theme->property(),
|
||||
'property' => $property,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
use App\Filament\Forms\Components\PhotoSelect;
|
||||
use App\Models\Page;
|
||||
use App\Models\Photo;
|
||||
use App\Models\Video;
|
||||
use App\Themes\Theme;
|
||||
use Filament\Forms\Components\Radio;
|
||||
use Filament\Forms\Components\RichEditor\RichContentRenderer;
|
||||
@@ -173,6 +174,27 @@ protected static function photoSelect(string $name, string $label, bool $multipl
|
||||
->multiple($multiple);
|
||||
}
|
||||
|
||||
/**
|
||||
* Select field listing the website videos (Admin › Webseite › Videos).
|
||||
*/
|
||||
protected static function videoSelect(string $name, string $label): Select
|
||||
{
|
||||
return Select::make($name)
|
||||
->label($label)
|
||||
->options(fn (): array => Video::query()->orderBy('title')->pluck('title', 'id')->all())
|
||||
->placeholder('– kein Video –');
|
||||
}
|
||||
|
||||
/**
|
||||
* The chosen video, if it still exists and has a file.
|
||||
*/
|
||||
protected function video(mixed $id): ?Video
|
||||
{
|
||||
$video = filled($id) ? Video::query()->with('media')->find($id) : null;
|
||||
|
||||
return $video?->url() ? $video : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select field listing the pages of the site, for links.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Themes\Sections;
|
||||
|
||||
use App\Themes\Theme;
|
||||
use Filament\Forms\Components\Radio;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
|
||||
/**
|
||||
* A video tour through the apartment: plays only when a guest starts it, chapters jump to a room. Floor plan
|
||||
* rooms named in a chapter offer "Im Video ansehen" when the tour is on the same page.
|
||||
*/
|
||||
class TourSection extends Section
|
||||
{
|
||||
public const LAYOUTS = [
|
||||
'wide' => 'Video in voller Breite, Text darüber',
|
||||
'left' => 'Video links, Text und Kapitel rechts',
|
||||
'right' => 'Video rechts, Text und Kapitel links',
|
||||
];
|
||||
|
||||
public static function key(): string
|
||||
{
|
||||
return 'tour';
|
||||
}
|
||||
|
||||
public static function label(): string
|
||||
{
|
||||
return 'Rundgang (Video)';
|
||||
}
|
||||
|
||||
public static function icon(): string
|
||||
{
|
||||
return 'heroicon-o-film';
|
||||
}
|
||||
|
||||
public static function schema(): array
|
||||
{
|
||||
return [
|
||||
TextInput::make('eyebrow')->label('Kleine Überschrift')->maxLength(100),
|
||||
TextInput::make('heading')->label('Überschrift')->default('Ein Rundgang durch die Wohnung')->maxLength(160),
|
||||
Textarea::make('text')->label('Text')->rows(3)->maxLength(600),
|
||||
static::videoSelect('video_id', 'Video')
|
||||
->helperText('Webseite › Videos. Das Video lädt erst, wenn Besucher es starten – die Seite bleibt schnell.')
|
||||
->required(),
|
||||
Radio::make('layout')
|
||||
->label('Anordnung')
|
||||
->options(self::LAYOUTS)
|
||||
->default('left')
|
||||
->required(),
|
||||
Toggle::make('show_chapters')
|
||||
->label('Kapitel als Knöpfe zeigen')
|
||||
->helperText('Die Kapitel pflegen Sie am Video.')
|
||||
->default(true),
|
||||
];
|
||||
}
|
||||
|
||||
public function data(Theme $theme, array $data): array
|
||||
{
|
||||
$video = $this->video($data['video_id'] ?? null);
|
||||
|
||||
return [
|
||||
'eyebrow' => $data['eyebrow'] ?? null,
|
||||
'heading' => $data['heading'] ?? null,
|
||||
'text' => $data['text'] ?? null,
|
||||
'video' => $video,
|
||||
'chapters' => ($data['show_chapters'] ?? true) && $video ? $video->chapterList() : [],
|
||||
'layout' => array_key_exists($data['layout'] ?? '', self::LAYOUTS) ? $data['layout'] : 'left',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user