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>
62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Communication;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
/**
|
|
* Anfragevorlage: bearbeitbarer Entwurf (draft) und unveränderliche, veröffentlichte Fassungen.
|
|
*/
|
|
class InquiryTemplate extends Model
|
|
{
|
|
protected $fillable = ['key', 'name', 'description', 'draft', 'published_version_id', 'archived_at'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['draft' => 'array', 'archived_at' => 'datetime'];
|
|
}
|
|
|
|
public function versions(): HasMany
|
|
{
|
|
return $this->hasMany(InquiryTemplateVersion::class, 'template_id')->orderByDesc('version');
|
|
}
|
|
|
|
public function publishedVersion(): BelongsTo
|
|
{
|
|
return $this->belongsTo(InquiryTemplateVersion::class, 'published_version_id');
|
|
}
|
|
|
|
public function entries(): HasMany
|
|
{
|
|
return $this->hasMany(InquiryEntry::class, 'template_id');
|
|
}
|
|
|
|
public function isPublished(): bool
|
|
{
|
|
return $this->published_version_id !== null;
|
|
}
|
|
|
|
/** Ob der Entwurf von der veröffentlichten Fassung abweicht. */
|
|
public function hasUnpublishedChanges(): bool
|
|
{
|
|
$version = $this->publishedVersion;
|
|
|
|
return $version === null || FormJson::normalize($version->source) !== FormJson::normalize((array) $this->draft);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public static function emptyDraft(): array
|
|
{
|
|
return [
|
|
'texts' => [],
|
|
'issues' => [],
|
|
'steps' => [],
|
|
'rules' => [],
|
|
];
|
|
}
|
|
}
|