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>
70 lines
2.2 KiB
PHP
70 lines
2.2 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;
|
|
|
|
/**
|
|
* Anliegen (oberste Ebene) oder Unteranliegen. Wird nie gelöscht, nur deaktiviert oder archiviert.
|
|
*/
|
|
class InquiryIssue extends Model
|
|
{
|
|
protected $fillable = ['parent_id', 'key', 'label', 'description', 'sort_order', 'active', 'archived_at'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['active' => 'boolean', 'archived_at' => 'datetime', 'sort_order' => 'integer'];
|
|
}
|
|
|
|
public function parent(): BelongsTo
|
|
{
|
|
return $this->belongsTo(self::class, 'parent_id');
|
|
}
|
|
|
|
public function children(): HasMany
|
|
{
|
|
return $this->hasMany(self::class, 'parent_id')->orderBy('sort_order')->orderBy('id');
|
|
}
|
|
|
|
/** Anliegen, die Besuchern angeboten werden können. */
|
|
public function scopeOffered(Builder $query): Builder
|
|
{
|
|
return $query->where('active', true)->whereNull('archived_at');
|
|
}
|
|
|
|
public function isOffered(): bool
|
|
{
|
|
return $this->active && $this->archived_at === null;
|
|
}
|
|
|
|
/**
|
|
* Baum aus angebotenen Anliegen mit ihren angebotenen Unteranliegen, wie er in eine Fassung übernommen wird.
|
|
*
|
|
* @return list<array{key: string, label: string, description: ?string, children: list<array{key: string, label: string, description: ?string}>}>
|
|
*/
|
|
public static function tree(): array
|
|
{
|
|
$all = self::query()->offered()->orderBy('sort_order')->orderBy('id')->get();
|
|
$children = $all->whereNotNull('parent_id')->groupBy('parent_id');
|
|
$tree = [];
|
|
|
|
foreach ($all->whereNull('parent_id') as $issue) {
|
|
$tree[] = [
|
|
'key' => $issue->key,
|
|
'label' => $issue->label,
|
|
'description' => $issue->description,
|
|
'children' => ($children[$issue->id] ?? collect())->map(fn (self $child): array => [
|
|
'key' => $child->key,
|
|
'label' => $child->label,
|
|
'description' => $child->description,
|
|
])->values()->all(),
|
|
];
|
|
}
|
|
|
|
return $tree;
|
|
}
|
|
}
|