Files
fewo-stommer/app/Support/Settings.php
T
LarsandClaude Opus 5.5 1c757f7429 Erinnerungsabstand und taegliche/woechentliche Zusammenfassung einstellbar
System > Betrieb > Benachrichtigungen: offene Meldungen (Doppelbuchungen im
Postfach, Portal-Aufgaben) nur einmal oder alle 1/2/3/7 Tage erneut senden;
Tages- und/oder Wochenuebersicht mit waehlbarer Uhrzeit, Wochentag und Inhalt
(Postfach, Anfragen, Neues, An-/Abreisen, Zahlungen, Portale, Bewertungen).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 10:11:15 +01:00

99 lines
3.1 KiB
PHP
Raw 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\Support;
use App\Models\Tenant;
use App\Tenancy\TenantConfig;
/**
* Operating mode and addresses of the current landlord (admin page System › Betrieb, stored on the landlord).
* In **test mode** (the default until the site is switched live) every e-mail goes to the test recipient only,
* whatever address was entered on the website. Without any landlord the .env values apply.
*/
class Settings
{
public const MODE_TEST = 'test';
public const MODE_LIVE = 'live';
/**
* The landlord of the context, else the only landlord.
*/
public static function tenant(): ?Tenant
{
return app(TenantConfig::class)->effectiveTenant();
}
/**
* The recipients of internal notifications (the landlord's setting, else FEWO_NOTIFICATION_EMAIL while no landlord is known).
*
* @return list<string>
*/
public static function notificationRecipients(): array
{
return self::tenant()?->notificationRecipients()
?: self::addressList((string) config('fewo.notification_email'));
}
/**
* "a@x.de, b@y.de; c@z.de" → valid addresses only.
*
* @return list<string>
*/
public static function addressList(?string $value): array
{
return array_values(array_filter(
array_map('trim', preg_split('/[,;\s]+/', (string) $value) ?: []),
fn (string $address): bool => filter_var($address, FILTER_VALIDATE_EMAIL) !== false,
));
}
public static function isLive(): bool
{
return (self::tenant()?->operating_mode ?? self::MODE_TEST) === self::MODE_LIVE;
}
/**
* Where all e-mails go instead of their real recipients, or null when mails are delivered normally.
* FEWO_MAIL_REDIRECT_TO in .env always wins (hard override for test servers).
*/
public static function mailRedirect(): ?string
{
return self::mailRedirectFor(self::tenant());
}
public static function mailRedirectFor(?Tenant $tenant): ?string
{
$override = config('fewo.mail_redirect_to');
if (filled($override)) {
return (string) $override;
}
if ($tenant?->isLive()) {
return null;
}
// A landlord without any address of their own must not fall through to normal delivery: the operator's
// address catches the mails until the landlord has entered their own.
$recipients = $tenant?->notificationRecipients() ?: self::addressList((string) config('fewo.notification_email'));
return $tenant?->test_recipient ?: ($recipients[0] ?? null);
}
/**
* After how many days an unread, still detected finding is e-mailed again; 0 = only once.
*/
public static function reminderIntervalDays(?Tenant $tenant = null): int
{
return (int) (($tenant ?? self::tenant())?->reminder_interval_days ?? 0);
}
/**
* Applies the redirect of the current landlord to the mailer; called after saving.
*/
public static function applyMailRouting(): void
{
app(TenantConfig::class)->refresh();
}
}