Files
fewo-stommer/app/Filament/Forms/ProcessSettingFields.php
LarsandClaude Opus 5.5 799869c6a4 v0.11 U1: Kanalmanager mit eigener Webseite und neuen Prozessparametern
- Eigene Webseite als Kanal eigener Art (channels.kind = website), nur zur
  Konfiguration: Webseiten-Anfragen bleiben direkt (A1) ohne Kanalbezug;
  der Eintrag nimmt an Sync, Export, Überwachung und Sperraufgaben nicht teil
  (active()/Property::channels() nur Portale, Feed nur für Portale).
- Neue Einstellungen im bestehenden ProcessSetting: Klärungsreservierung
  automatisch/Freigabe (15/180 min, 0 = keine), Rückfragemodus,
  Erinnerungen, Folgefragen, Erinnerungsabstand, Linkgültigkeit,
  Anschrift im Webformular verlangen (Standard: nein).
- „Kanäle“ in der einfachen Ansicht: Webseite und Portale an einer Stelle,
  Verweis auf „Ihre Standards“; „Wirksame Einstellungen“ mit Spalte
  „Eigene Webseite“ und Herkunft „Webseite“.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 12:52:50 +01:00

87 lines
5.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Filament\Forms;
use App\Enums\DataRequestMode;
use App\Enums\ProcessingMode;
use App\Enums\ProcessSetting;
use App\Enums\Responsibility;
use App\Models\ContractTemplate;
use Filament\Forms\Components\Field;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
/**
* Form fields of the process settings, asked as plain questions. On a deviation level (property, channel) an empty
* field means "as the level above" and the placeholder says which value that is; on the landlord level an empty field
* means the built-in default.
*/
class ProcessSettingFields
{
/**
* @param list<ProcessSetting> $settings
* @param callable(ProcessSetting): string $inherited plain-words value used when the field stays empty
* @return list<Field>
*/
public static function make(string $prefix, array $settings, callable $inherited): array
{
return array_map(fn (ProcessSetting $setting): Field => self::field($prefix.$setting->value, $setting, $inherited($setting)), $settings);
}
public static function field(string $name, ProcessSetting $setting, string $inheritedLabel): Field
{
$placeholder = 'wie Standard: '.$inheritedLabel;
return (match ($setting) {
ProcessSetting::Processing => Select::make($name)->options(ProcessingMode::class)->placeholder($placeholder)
->helperText('Automatisch: Das System sendet Angebote bzw. Unterlagen selbst, sobald alle Angaben da sind. Sonst bereitet es alles vor und Sie geben frei.'),
ProcessSetting::PreReservation => Select::make($name)->options(['1' => 'Ja – der Zeitraum ist bis zum Ablauf des Angebots reserviert', '0' => 'Nein – der Gast erhält eine unverbindliche Auskunft und kann daraus die Buchung anfragen (erneute Prüfung vor der Bestätigung)'])->placeholder($placeholder),
ProcessSetting::HoldHours => TextInput::make($name)->integer()->minValue(1)->maxValue(720)->suffix('Stunden')->placeholder($placeholder),
ProcessSetting::Documents, ProcessSetting::Payments, ProcessSetting::GuestMessages => Select::make($name)->options([Responsibility::Landlord->value => Responsibility::Landlord->getLabel(), Responsibility::Portal->value => Responsibility::Portal->getLabel()])->placeholder($placeholder),
ProcessSetting::ArrivalInfoDaysBefore => TextInput::make($name)->integer()->minValue(1)->maxValue(14)->suffix('Tage vor Anreise')->placeholder($placeholder),
ProcessSetting::ContractTemplate => Select::make($name)
->options(fn (): array => ContractTemplate::query()->orderBy('name')->orderBy('version')->get()->mapWithKeys(fn (ContractTemplate $template): array => [$template->id => $template->label()])->all())
->placeholder($placeholder),
ProcessSetting::ClarificationHoldAutoMinutes, ProcessSetting::ClarificationHoldManualMinutes => TextInput::make($name)->integer()->minValue(0)->maxValue(1440)->suffix('Minuten')->placeholder($placeholder)
->helperText('Nur für Anfragen, denen noch Angaben für ein Angebot fehlen, und nur wenn der Zeitraum frei ist. Endet von selbst und wird durch Rückfragen nicht verlängert. Die Reservierung eines Angebots bleibt davon unberührt.'),
ProcessSetting::DataRequest => Select::make($name)->options(DataRequestMode::class)->placeholder($placeholder)
->helperText('Unabhängig davon, ob Angebote automatisch hinausgehen.'),
ProcessSetting::DataRequestRemindersMax, ProcessSetting::DataRequestFollowupsMax => TextInput::make($name)->integer()->minValue(0)->maxValue(5)->placeholder($placeholder),
ProcessSetting::DataRequestReminderHours => TextInput::make($name)->integer()->minValue(1)->maxValue(336)->suffix('Stunden')->placeholder($placeholder),
ProcessSetting::GuestLinkValidDays => TextInput::make($name)->integer()->minValue(1)->maxValue(60)->suffix('Tage')->placeholder($placeholder),
ProcessSetting::FormRequiresAddress => Select::make($name)->options(['1' => 'Ja – ohne vollständige Anschrift kann nicht angefragt werden', '0' => 'Nein – fehlt sie, wird beim Gast nachgefragt'])->placeholder($placeholder),
})->label($setting->question());
}
/**
* Normalised values of submitted fields; empty fields are dropped (not set = inherit).
*
* @param array<string, mixed> $data
* @param list<ProcessSetting> $settings
* @return array<string, string|int|bool>
*/
public static function values(array $data, array $settings): array
{
$values = [];
foreach ($settings as $setting) {
$value = $setting->normalize($data[$setting->value] ?? null);
if ($value !== null) {
$values[$setting->value] = $value;
}
}
return $values;
}
/**
* Stored values as form state (booleans as the select keys).
*
* @param array<string, mixed> $values
* @return array<string, mixed>
*/
public static function state(array $values): array
{
return array_map(fn (mixed $value): mixed => is_bool($value) ? ($value ? '1' : '0') : $value, $values);
}
}