Formulare, WordPress-Import und E-Mail-Versand
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m0s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m11s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m52s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m2s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m31s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m27s
CI / Build-Artefakte aktuell (pull_request) Successful in 53s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m0s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m11s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m52s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m2s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m31s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m27s
CI / Build-Artefakte aktuell (pull_request) Successful in 53s
- Formular-Plugin: Baukasten mit 13 Feldtypen, Bedingungen, Vorbelegung aus dem Profil, Datei-Uploads (geschützt), anonyme Formulare, „nur einmal“, Einsendeschluss, Sichtbarkeit, Löschfrist; Einsendungen im Backend und per Mail (optional ohne Angaben, Kopie an die Person); Rechte je Formular und Rolle für Ansehen/Export und Löschen; CSV für Excel; Pagebuilder-Block - WordPress-Import (Plugin): WXR-Datei einlesen, Kategorien/Personen zuordnen, Beiträge mit Status, Datum, Beitragsbild und Bildern im Text übernehmen, optional Seiten mit Hierarchie; in Portionen, wiederholbar ohne Doppelungen - E-Mail-Versand im Admin (SMTP, verschlüsseltes Passwort, Test-Mail) - Speichertest unabhängig vom Verbrauch der Test-Suite Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f3987e8386
commit
11123fecc0
118 changed files with 4446 additions and 169 deletions
116
plugins-core/forms/src/Models/Form.php
Normal file
116
plugins-core/forms/src/Models/Form.php
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Forms\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Support\Permissions\Audiences;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Str;
|
||||
use Inhaus\Plugins\Forms\FormFields;
|
||||
|
||||
/**
|
||||
* Ein Formular. „fields“ ist die Liste der Felder aus dem Formularbaukasten
|
||||
* (siehe FormFields), „settings“ Benachrichtigung, Anonymität, Löschfrist u. a.
|
||||
*/
|
||||
#[Fillable(['title', 'slug', 'description', 'fields', 'settings', 'is_open', 'closes_at', 'created_by'])]
|
||||
class Form extends Model
|
||||
{
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (Form $form) {
|
||||
if (blank($form->slug)) {
|
||||
$base = Str::slug($form->title, language: 'de') ?: 'formular';
|
||||
$slug = $base;
|
||||
|
||||
for ($i = 2; static::query()->where('slug', $slug)->whereKeyNot($form->id)->exists(); $i++) {
|
||||
$slug = "{$base}-{$i}";
|
||||
}
|
||||
|
||||
$form->slug = $slug;
|
||||
}
|
||||
|
||||
$form->fields = FormFields::normalize((array) $form->fields);
|
||||
});
|
||||
|
||||
static::deleting(fn (Form $form) => $form->submissions()->with('files')->get()->each->delete());
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'fields' => 'array',
|
||||
'settings' => 'array',
|
||||
'is_open' => 'boolean',
|
||||
'closes_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: string, 1: int}
|
||||
*/
|
||||
public function permissionResource(): array
|
||||
{
|
||||
return ['form', $this->id];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<FormSubmission, $this>
|
||||
*/
|
||||
public function submissions(): HasMany
|
||||
{
|
||||
return $this->hasMany(FormSubmission::class);
|
||||
}
|
||||
|
||||
public function setting(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return $this->settings[$key] ?? $default;
|
||||
}
|
||||
|
||||
public function isAnonymous(): bool
|
||||
{
|
||||
return (bool) $this->setting('anonymous', false);
|
||||
}
|
||||
|
||||
public function acceptsSubmissions(): bool
|
||||
{
|
||||
return $this->is_open && ($this->closes_at === null || $this->closes_at->isFuture());
|
||||
}
|
||||
|
||||
public function url(): string
|
||||
{
|
||||
return '/formulare/'.$this->slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kennung für „nur einmal ausfüllen“, ohne bei anonymen Formularen die Person zu speichern.
|
||||
*/
|
||||
public function userHash(User $user): string
|
||||
{
|
||||
return hash_hmac('sha256', $this->id.':'.$user->id, (string) config('app.key'));
|
||||
}
|
||||
|
||||
public function alreadySubmittedBy(User $user): bool
|
||||
{
|
||||
return $this->submissions()
|
||||
->where(fn ($q) => $q->where('user_hash', $this->userHash($user))->orWhere('user_id', $user->id))
|
||||
->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<Form> $query
|
||||
*/
|
||||
public function scopeVisibleTo(Builder $query, ?User $user): void
|
||||
{
|
||||
if (! $user?->can('forms.manage')) {
|
||||
Audiences::constrain($query, 'form', 'forms.id', $user);
|
||||
}
|
||||
}
|
||||
|
||||
public function isVisibleTo(?User $user): bool
|
||||
{
|
||||
return $user?->can('forms.manage') || Audiences::allows('form', $this->id, $user);
|
||||
}
|
||||
}
|
||||
36
plugins-core/forms/src/Models/FormFile.php
Normal file
36
plugins-core/forms/src/Models/FormFile.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Forms\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Hochgeladene Datei zu einem Formular. Liegt außerhalb von public/; ausgeliefert
|
||||
* nur an Personen mit Zugriff auf die Ergebnisse des Formulars.
|
||||
*/
|
||||
#[Fillable(['submission_id', 'field', 'name', 'path', 'mime', 'size'])]
|
||||
class FormFile extends Model
|
||||
{
|
||||
public const DISK = 'local';
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::deleted(fn (FormFile $file) => Storage::disk(self::DISK)->delete($file->path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<FormSubmission, $this>
|
||||
*/
|
||||
public function submission(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(FormSubmission::class, 'submission_id');
|
||||
}
|
||||
|
||||
public function url(): string
|
||||
{
|
||||
return route('forms.file', $this);
|
||||
}
|
||||
}
|
||||
74
plugins-core/forms/src/Models/FormSubmission.php
Normal file
74
plugins-core/forms/src/Models/FormSubmission.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Forms\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* Ein ausgefülltes Formular. „data“ enthält je Feld Bezeichnung, Typ und Wert –
|
||||
* so bleiben Ergebnisse lesbar, auch wenn das Formular später geändert wird.
|
||||
*/
|
||||
#[Fillable(['form_id', 'user_id', 'user_hash', 'data', 'read_at'])]
|
||||
class FormSubmission extends Model
|
||||
{
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::deleting(fn (FormSubmission $submission) => $submission->files->each->delete());
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['data' => 'array', 'read_at' => 'datetime'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Form, $this>
|
||||
*/
|
||||
public function form(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Form::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<FormFile, $this>
|
||||
*/
|
||||
public function files(): HasMany
|
||||
{
|
||||
return $this->hasMany(FormFile::class, 'submission_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Wert als Text (Listen mit Komma, Ja/Nein, Dateinamen).
|
||||
*/
|
||||
public function display(string $key): string
|
||||
{
|
||||
$answer = $this->data[$key] ?? null;
|
||||
|
||||
if ($answer === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$value = $answer['value'] ?? null;
|
||||
|
||||
return match (true) {
|
||||
($answer['type'] ?? null) === 'checkbox' => $value ? 'Ja' : 'Nein',
|
||||
($answer['type'] ?? null) === 'file' => implode(', ', array_column((array) $value, 'name')),
|
||||
($answer['type'] ?? null) === 'date' && is_string($value) && preg_match('/^\d{4}-\d{2}-\d{2}$/', $value) => Carbon::parse($value)->format('d.m.Y'),
|
||||
is_array($value) => implode(', ', $value),
|
||||
default => (string) $value,
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue