- press_release_images: Kundenangabe/Portalkennzeichnung getrennt, Herkunftsbefund, Beweisoriginal, Snapshot-Pfade, published_ever_at, rules_version, Fokus/Letterbox; Bestand unangetastet - legal_texts (insert-only) mit img-confirm-v1 (alter Wortlaut), v2 (AGB 0.6), v3 (AGB 0.7, noch ohne Datum); image-rights:backfill-confirmations - image_rights_confirmations polymorph, insert-only, IP als versionierter HMAC; Löschung nur für nie veröffentlichte Uploads - ImageProvenanceInspector (Imagick/exif): IPTC, XMP, EXIF; algorithmicallyEnhanced nur Vermerk; unlesbare Datei = error - PressReleaseImageUploader: Original vor Derivaten, Hash-Bindung, Titelbild-Regel unter Sperre, Dateien bei Fehlern zurückgerollt; Admin-Upload ohne Bestätigung - ImageService: kein Rückfall auf die Quelldatei, og-Variante, Fokuspunkt und no_crop Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
113 lines
3.5 KiB
PHP
113 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
/**
|
|
* Unveränderliche Fassung eines Bestätigungstextes (Bildkennzeichnung A.3).
|
|
*
|
|
* Zeilen werden nie geändert oder gelöscht. Eine Kennung (`key`) gehört zu
|
|
* genau einem Wortlaut; ein neuer Wortlaut bekommt eine neue Kennung. Der
|
|
* Text ist an die AGB-Fassung gebunden, deren Paragrafen er nennt
|
|
* (Decision-Update 3.3): Solange AGB 0.6 gilt, ist `img-confirm-v2` aktiv,
|
|
* mit AGB 0.7 wird `img-confirm-v3` wirksam.
|
|
*/
|
|
class LegalText extends Model
|
|
{
|
|
public const UPDATED_AT = null;
|
|
|
|
public const TYPE_IMAGE_RIGHTS_CONFIRMATION = 'image_rights_confirmation';
|
|
|
|
protected $fillable = [
|
|
'key',
|
|
'type',
|
|
'locale',
|
|
'title',
|
|
'body',
|
|
'short_body',
|
|
'bound_agb_version',
|
|
'body_sha256',
|
|
'effective_from',
|
|
'note',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'effective_from' => 'date',
|
|
];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $text): void {
|
|
$text->body_sha256 = hash('sha256', $text->body);
|
|
});
|
|
|
|
static::updating(fn () => throw new \LogicException('legal_texts ist unveränderlich — neue Fassung als neue Zeile anlegen.'));
|
|
static::deleting(fn () => throw new \LogicException('legal_texts ist unveränderlich — Fassungen werden nie gelöscht.'));
|
|
}
|
|
|
|
/**
|
|
* Die heute gültige Fassung eines Typs für die gegebene AGB-Fassung.
|
|
* Fällt auf die jüngste gültige Fassung ohne AGB-Bindung zurück, damit
|
|
* ein Text ohne Paragrafenverweis für jede AGB-Fassung taugt.
|
|
*/
|
|
public static function currentFor(string $type, ?string $agbVersion, string $locale = 'de'): ?self
|
|
{
|
|
$query = static::query()
|
|
->where('type', $type)
|
|
->where('locale', $locale)
|
|
->whereNotNull('effective_from')
|
|
->where('effective_from', '<=', today())
|
|
->orderByDesc('effective_from')
|
|
->orderByDesc('id');
|
|
|
|
if ($agbVersion !== null) {
|
|
$bound = (clone $query)->where('bound_agb_version', $agbVersion)->first();
|
|
|
|
if ($bound !== null) {
|
|
return $bound;
|
|
}
|
|
}
|
|
|
|
return (clone $query)->whereNull('bound_agb_version')->first();
|
|
}
|
|
|
|
public static function findByKey(string $key): ?self
|
|
{
|
|
return static::query()->where('key', $key)->first();
|
|
}
|
|
|
|
/**
|
|
* Ob eine Kennung heute abgegeben werden darf (aktive Fassung des Typs).
|
|
*/
|
|
public function isCurrentFor(?string $agbVersion, string $locale = 'de'): bool
|
|
{
|
|
return static::currentFor($this->type, $agbVersion, $locale)?->is($this) === true;
|
|
}
|
|
|
|
/**
|
|
* Platzhalter im Wortlaut auflösen. Der gerenderte Text wird mit der
|
|
* Bestätigung gespeichert, der Rohtext bleibt hier unverändert.
|
|
*
|
|
* @param array<string, string> $variables
|
|
*/
|
|
public function render(array $variables, bool $short = false): string
|
|
{
|
|
$template = $short ? ($this->short_body ?? $this->body) : $this->body;
|
|
|
|
return strtr($template, collect($variables)
|
|
->mapWithKeys(fn (string $value, string $name): array => ['{'.$name.'}' => $value])
|
|
->all());
|
|
}
|
|
|
|
public function effectiveFromFormatted(): ?string
|
|
{
|
|
return $this->effective_from
|
|
? Carbon::parse($this->effective_from)->locale('de')->isoFormat('D. MMMM YYYY')
|
|
: null;
|
|
}
|
|
}
|