Files
laraundfelix/app/Domain/Communication/InquiryEntry.php
T
LarsandClaude Sonnet 5.5 2ee1fc9866 Lege das Datenmodell und den Anfrageservice der Kommunikationsverwaltung an
Anliegen, Feldkatalog, Feldgruppen, Anfragevorlagen mit unveränderlichen Fassungen,
Anfrage-Einstiege und eingegangene Anfragen. Eine gemeinsame Regelauswertung bedient
Besucher, Vorschau und Anfrageservice; Werte nicht mehr relevanter Felder werden verworfen,
Anliegen und Auswahlwerte serverseitig geprüft, doppeltes Absenden bleibt eine Anfrage.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-27 17:26:42 +01:00

65 lines
2.0 KiB
PHP

<?php
namespace App\Domain\Communication;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Anfrage-Einstieg: die veröffentlichbare Nutzungsvariante einer Anfragevorlage. config ist der Entwurf,
* published_config der wirksame Stand.
*/
class InquiryEntry extends Model
{
protected $fillable = ['key', 'name', 'template_id', 'config', 'published_config', 'published_at', 'archived_at'];
protected function casts(): array
{
return ['config' => 'array', 'published_config' => 'array', 'published_at' => 'datetime', 'archived_at' => 'datetime'];
}
public function template(): BelongsTo
{
return $this->belongsTo(InquiryTemplate::class, 'template_id');
}
public function inquiries(): HasMany
{
return $this->hasMany(Inquiry::class, 'entry_id');
}
/** Einstiege, die Besuchern ausgeliefert werden können (Vorlage zusätzlich in isLive() prüfen). */
public function scopeLive(Builder $query): Builder
{
return $query->whereNotNull('published_at')->whereNull('archived_at')->whereNotNull('published_config');
}
public function isLive(): bool
{
return $this->published_at !== null && $this->archived_at === null && $this->published_config !== null
&& $this->template?->published_version_id !== null && $this->template->archived_at === null;
}
public function hasUnpublishedChanges(): bool
{
return $this->published_config === null || FormJson::normalize($this->published_config) !== FormJson::normalize((array) $this->config);
}
/**
* @return array<string, mixed>
*/
public static function emptyConfig(): array
{
return [
'mode' => 'compact',
'open' => 'inline',
'allowed_issues' => [],
'allowed_subissues' => [],
'defaults' => [],
'texts' => [],
];
}
}