Baue die Verwaltung Kommunikation, die öffentliche Anfrageschnittstelle und das CMS-Widget Anfrage
Anliegen, Feldkatalog, Feldgruppen, Anfragevorlagen mit Fassungen, Anfrage-Einstiege, Posteingang mit Status und Notizen, Einstellungen mit Empfängern. Das Widget speichert nur die Kennung eines veröffentlichten Einstiegs; Formular, Bedingungen und Annahme kommen zur Laufzeit vom Server (Kompaktformular und mehrstufiger Dialog aus derselben Beschreibung). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2ee1fc9866
commit
c6a8167601
45 files changed
+5415
No files matched your search
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Communication;
|
||||
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
|
||||
/**
|
||||
* Wer die Kommunikationsverwaltung bedienen darf. Konfigurieren (Anliegen, Felder, Gruppen, Vorlagen, Einstiege):
|
||||
* Redaktion und Systemverwaltung. Anfragen lesen und bearbeiten sowie Einstellungen: Kundenbetreuung und
|
||||
* Systemverwaltung. Anfragen enthalten personenbezogene Daten und sind deshalb enger gefasst als die Konfiguration.
|
||||
*/
|
||||
final class CommunicationAccess
|
||||
{
|
||||
public static function user(): ?User
|
||||
{
|
||||
$user = Filament::auth()->user() ?? auth('staff')->user();
|
||||
|
||||
return $user instanceof User ? $user : null;
|
||||
}
|
||||
|
||||
public static function configure(?User $user = null): bool
|
||||
{
|
||||
$user ??= self::user();
|
||||
|
||||
return $user !== null && ($user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Systemverwalter));
|
||||
}
|
||||
|
||||
public static function inbox(?User $user = null): bool
|
||||
{
|
||||
$user ??= self::user();
|
||||
|
||||
return $user !== null && ($user->hasStaffRole(StaffRole::Kundenbetreuung) || $user->hasStaffRole(StaffRole::Systemverwalter));
|
||||
}
|
||||
|
||||
/** Anfragen endgültig löschen (Datenschutz): nur Systemverwaltung. */
|
||||
public static function erase(?User $user = null): bool
|
||||
{
|
||||
$user ??= self::user();
|
||||
|
||||
return $user !== null && $user->hasStaffRole(StaffRole::Systemverwalter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Communication;
|
||||
|
||||
/**
|
||||
* Die Beschreibung des Formulars für den Browser. Sie enthält, was zur Darstellung nötig ist (Texte, Schritte, Felder,
|
||||
* Auswahlwerte), und den ersten Zustand der Bedingungen, aber keine Regeln und keine Verwendungszwecke: Entscheidungen
|
||||
* über Sichtbarkeit und Pflicht trifft ausschließlich der Server (FormEvaluator).
|
||||
*/
|
||||
final class FormPayload
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $form wirksames Formular (FormFactory::effective)
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function definition(array $form, FormEvaluator $evaluator): array
|
||||
{
|
||||
$fields = [];
|
||||
|
||||
foreach ((array) $form['fields'] as $key => $field) {
|
||||
$settings = (array) ($field['settings'] ?? []);
|
||||
$fields[$key] = array_filter([
|
||||
'key' => $key,
|
||||
'label' => $field['label'],
|
||||
'help' => $field['help'],
|
||||
'type' => $field['type'],
|
||||
'options' => $field['options'] ?: null,
|
||||
'max_length' => $settings['max_length'] ?? null,
|
||||
'min' => $settings['min'] ?? null,
|
||||
'max' => $settings['max'] ?? null,
|
||||
], fn (mixed $value): bool => $value !== null);
|
||||
}
|
||||
|
||||
return [
|
||||
'mode' => $form['mode'] ?? 'compact',
|
||||
'open' => $form['open'] ?? 'inline',
|
||||
'texts' => $form['texts'],
|
||||
'issues' => $form['issues'],
|
||||
'defaults' => (object) ($form['defaults'] ?? []),
|
||||
'controls' => $form['controls'] ?? [],
|
||||
'steps' => $form['steps'],
|
||||
'fields' => $fields,
|
||||
'state' => self::state($form, (array) ($form['defaults'] ?? []), $evaluator),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $form
|
||||
* @param array<string, mixed> $values
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function state(array $form, array $values, FormEvaluator $evaluator): array
|
||||
{
|
||||
$state = $evaluator->evaluate($form, $values);
|
||||
|
||||
return [
|
||||
'steps' => (object) $state['steps'],
|
||||
'groups' => (object) $state['groups'],
|
||||
'fields' => (object) $state['fields'],
|
||||
'required' => (object) $state['required'],
|
||||
'presets' => (object) $state['presets'],
|
||||
'issue' => $state['issue'],
|
||||
'subissue' => $state['subissue'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -45,4 +45,45 @@ public static function from(string $label, array $taken = []): string
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ergänzt fehlende oder doppelte Kennungen von Auswahlwerten. Bestehende, gültige Kennungen bleiben unverändert,
|
||||
* damit gespeicherte Antworten und Bedingungen gültig bleiben, auch wenn eine Bezeichnung umbenannt wird.
|
||||
*
|
||||
* @param array<int|string, mixed> $options
|
||||
* @return list<array{key: string, label: string}>
|
||||
*/
|
||||
public static function withKeys(array $options): array
|
||||
{
|
||||
$result = [];
|
||||
$taken = [];
|
||||
|
||||
foreach ($options as $option) {
|
||||
$key = is_array($option) ? ($option['key'] ?? null) : null;
|
||||
|
||||
if (self::valid($key) && ! in_array($key, $taken, true)) {
|
||||
$taken[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($options as $option) {
|
||||
$option = is_array($option) ? $option : [];
|
||||
$label = trim((string) ($option['label'] ?? ''));
|
||||
|
||||
if ($label === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = $option['key'] ?? null;
|
||||
|
||||
if (! self::valid($key) || in_array($key, array_column($result, 'key'), true)) {
|
||||
$key = self::from($label, array_merge($taken, array_column($result, 'key')));
|
||||
$taken[] = $key;
|
||||
}
|
||||
|
||||
$result[] = ['key' => $key, 'label' => mb_substr($label, 0, 120)];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Communication;
|
||||
|
||||
/**
|
||||
* Bereinigt den Entwurf einer Anfragevorlage aus dem Formular der Verwaltung: Listen mit fortlaufenden Schlüsseln
|
||||
* (Repeater liefern Zufallsschlüssel), nur bekannte Felder, Texte begrenzt. Eine inhaltliche Prüfung geschieht erst beim
|
||||
* Veröffentlichen (TemplateCompiler); ein unfertiger Entwurf darf gespeichert werden.
|
||||
*/
|
||||
final class TemplateDraft
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $draft
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function clean(array $draft): array
|
||||
{
|
||||
$steps = [];
|
||||
|
||||
foreach (array_values((array) ($draft['steps'] ?? [])) as $step) {
|
||||
$step = is_array($step) ? $step : [];
|
||||
$items = [];
|
||||
|
||||
foreach (array_values((array) ($step['items'] ?? [])) as $item) {
|
||||
$item = is_array($item) ? $item : [];
|
||||
$kind = (string) ($item['kind'] ?? '');
|
||||
|
||||
$items[] = match ($kind) {
|
||||
'issue' => ['kind' => 'issue'],
|
||||
'group' => ['kind' => 'group', 'group' => (string) ($item['group'] ?? '')],
|
||||
'field' => ['kind' => 'field', 'field' => (string) ($item['field'] ?? ''), 'required' => (bool) ($item['required'] ?? false)],
|
||||
default => ['kind' => $kind],
|
||||
};
|
||||
}
|
||||
|
||||
$steps[] = [
|
||||
'key' => (string) ($step['key'] ?? ''),
|
||||
'title' => mb_substr(trim((string) ($step['title'] ?? '')), 0, 120),
|
||||
'intro' => filled($step['intro'] ?? null) ? mb_substr(trim((string) $step['intro']), 0, 600) : null,
|
||||
'items' => $items,
|
||||
];
|
||||
}
|
||||
|
||||
$rules = [];
|
||||
|
||||
foreach (array_values((array) ($draft['rules'] ?? [])) as $rule) {
|
||||
$rule = is_array($rule) ? $rule : [];
|
||||
$conditions = [];
|
||||
|
||||
foreach (array_values((array) ($rule['conditions'] ?? [])) as $condition) {
|
||||
$condition = is_array($condition) ? $condition : [];
|
||||
$conditions[] = [
|
||||
'source' => (string) ($condition['source'] ?? ''),
|
||||
'op' => (string) ($condition['op'] ?? 'eq'),
|
||||
'values' => array_values(array_filter((array) ($condition['values'] ?? []), 'is_string')),
|
||||
];
|
||||
}
|
||||
|
||||
$rules[] = [
|
||||
'effect' => (string) ($rule['effect'] ?? ''),
|
||||
'target' => (string) ($rule['target'] ?? ''),
|
||||
'match' => ($rule['match'] ?? 'all') === 'any' ? 'any' : 'all',
|
||||
'conditions' => $conditions,
|
||||
'value' => filled($rule['value'] ?? null) ? (string) $rule['value'] : null,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'texts' => FormTexts::clean((array) ($draft['texts'] ?? [])),
|
||||
'issues' => array_values(array_filter((array) ($draft['issues'] ?? []), 'is_string')),
|
||||
'steps' => $steps,
|
||||
'rules' => $rules,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user