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>
76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Communication;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Eingabefeld des Feldkatalogs. Wiederverwendbar in beliebig vielen Feldgruppen und Vorlagen.
|
|
*/
|
|
class InquiryField extends Model
|
|
{
|
|
protected $fillable = ['key', 'name', 'label', 'help', 'type', 'options', 'settings', 'purpose', 'active', 'archived_at'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'type' => FieldType::class,
|
|
'purpose' => FieldPurpose::class,
|
|
'options' => 'array',
|
|
'settings' => 'array',
|
|
'active' => 'boolean',
|
|
'archived_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function scopeOffered(Builder $query): Builder
|
|
{
|
|
return $query->where('active', true)->whereNull('archived_at');
|
|
}
|
|
|
|
/**
|
|
* Auswahlwerte als Liste [{key, label}] in der gepflegten Reihenfolge.
|
|
*
|
|
* @return list<array{key: string, label: string}>
|
|
*/
|
|
public function optionList(): array
|
|
{
|
|
if ($this->type === FieldType::Boolean) {
|
|
return [['key' => 'ja', 'label' => 'Ja'], ['key' => 'nein', 'label' => 'Nein']];
|
|
}
|
|
|
|
if (! $this->type->hasOptions()) {
|
|
return [];
|
|
}
|
|
|
|
$list = [];
|
|
|
|
foreach ((array) $this->options as $option) {
|
|
if (is_array($option) && Keys::valid($option['key'] ?? null) && filled($option['label'] ?? null)) {
|
|
$list[] = ['key' => $option['key'], 'label' => (string) $option['label']];
|
|
}
|
|
}
|
|
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* Die Beschreibung des Feldes, wie sie in eine Fassung übernommen wird.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function snapshot(): array
|
|
{
|
|
return [
|
|
'key' => $this->key,
|
|
'label' => $this->label,
|
|
'help' => $this->help,
|
|
'type' => $this->type->value,
|
|
'options' => $this->optionList(),
|
|
'settings' => (array) $this->settings,
|
|
'purpose' => $this->purpose?->value,
|
|
];
|
|
}
|
|
}
|