Enth\u00e4lt gemischt: Laravel-10-Upgrade + Phase 1 (Contacts-Modul, Duplicats-Commands, Soft-Delete+Merge-Fields) + Phase 2 Code-Umstellungen (inquiry_id, $table='contacts'/'inquiries') + Offers-Modul (Migrationen, Models, offer_id in Booking, offer-Disk in filesystems.php). Phase 2 + Offers werden im folgenden Commit nach dev/backups/phase2-offers-2026-04-17/ verschoben, damit der Workspace auf Phase-1-only (= Test-System-Stand) reduziert ist und direkt auf Live deploybar wird. Tarball-Backup zus\u00e4tzlich unter: ../backups-safety/workspace-pre-phase1-rollback-2026-04-17.tar.gz Made-with: Cursor
92 lines
2.6 KiB
PHP
92 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Airline;
|
|
use App\Models\CMSContent;
|
|
use App\Models\Insurance;
|
|
use App\Models\TravelCompany;
|
|
|
|
class MailDirService
|
|
{
|
|
private static array $outputDirs = [];
|
|
|
|
public static function setOutputDir(string $dir, string $subdir): void
|
|
{
|
|
self::$outputDirs[$dir][] = $subdir;
|
|
}
|
|
|
|
/**
|
|
* @return string[]
|
|
*/
|
|
public static function getCustomerMailDirs(): \Illuminate\Database\Eloquent\Collection
|
|
{
|
|
return CMSContent::where('identifier', '=', 'customer-mail-dirs')->get()->sortBy('pos');
|
|
}
|
|
|
|
public static function getCustomerMailDir(int $id): ?CMSContent
|
|
{
|
|
return CMSContent::where('identifier', '=', 'customer-mail-dirs')->where('pos', '=', $id)->first();
|
|
}
|
|
|
|
public static function getCustomerMailName(CMSContent $mailDir, int $mailDirId): string
|
|
{
|
|
$model = self::resolveModel($mailDir, $mailDirId);
|
|
|
|
if ($model === null) {
|
|
return '';
|
|
}
|
|
|
|
if ($mailDir->getArrayContent('model') === 'TravelCountry') {
|
|
return $model->mail_dir_name ?? '';
|
|
}
|
|
|
|
return $model->name ?? '';
|
|
}
|
|
|
|
/**
|
|
* @return array<string>|string
|
|
*/
|
|
public static function getCustomerMailEmails(CMSContent $mailDir, int $mailDirId): array|string
|
|
{
|
|
$model = self::resolveModel($mailDir, $mailDirId);
|
|
|
|
if ($model === null) {
|
|
// Default: emails come directly from CMSContent
|
|
return $mailDir->getArrayContent('emails') ?? [];
|
|
}
|
|
|
|
return $model->contact_emails ?? [];
|
|
}
|
|
|
|
/**
|
|
* Returns subdirs from a mail collection that were not already in the output.
|
|
*
|
|
* @param \Illuminate\Database\Eloquent\Collection $mails Collection of CustomerMail or LeadMail
|
|
* @return string[]
|
|
*/
|
|
public static function getMailDirsNotInOutput(iterable $mails, string $dir): array
|
|
{
|
|
$processed = self::$outputDirs[$dir] ?? [];
|
|
$result = [];
|
|
|
|
foreach ($mails as $mail) {
|
|
if (!in_array($mail->subdir, $processed, true)) {
|
|
$result[] = $mail->subdir;
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private static function resolveModel(CMSContent $mailDir, int $mailDirId): mixed
|
|
{
|
|
return match ($mailDir->getArrayContent('model')) {
|
|
'TravelCountry' => \App\Models\Sym\TravelCountry::find($mailDirId),
|
|
'Airline' => Airline::find($mailDirId),
|
|
'Insurance' => Insurance::find($mailDirId),
|
|
'TravelCompany' => TravelCompany::find($mailDirId),
|
|
default => null,
|
|
};
|
|
}
|
|
}
|