- Tabellen media und media_usages, Modelle Media/MediaUsage - App\Media\MediaLibrary (store/register/replace/delete/rebuild) und Registry App\Media\MediaUsages (Quellen: Seiten, Neuigkeiten inkl. künftiger content-Spalte, Termine, Startseiten-Kacheln), ImagePaths-Extraktor - Alle Uploads landen in der Mediathek (Seiten-Editor direkt, übrige über Beobachter beim Speichern); Daten-Migration und media:rebuild übernehmen bestehende Bilder - Recht media.manage, Zugang media.use für alle Redaktionsbereiche - /redaktion/mediathek (Suche, Filter, Upload mit Fortschritt, Details, Eingebunden in, Ersetzen, Löschen mit Warnung, Mehrfachauswahl), Abschnitt in der Redaktion und Menüpunkt im Admin-Bereich - MediaPicker (Hochladen/Mediathek) im Pagebuilder: Bildfelder und Galerie (Mehrfachauswahl), editor.pickMedia im provide-API - Bild-URLs mit ?v=Änderungszeit, null bei fehlender Datei; Modelle löschen geteilte Bilder nicht mehr selbst Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
94 lines
2.8 KiB
PHP
94 lines
2.8 KiB
PHP
<?php
|
||
|
||
namespace App\Models;
|
||
|
||
use App\Pagebuilder\Field;
|
||
use App\Support\Images;
|
||
use App\Support\Permissions\Audiences;
|
||
use App\Support\RichText;
|
||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||
use Illuminate\Database\Eloquent\Builder;
|
||
use Illuminate\Database\Eloquent\Model;
|
||
|
||
/**
|
||
* Eigene Kachel auf der Startseite („Administration → Portal → Startseite“).
|
||
*/
|
||
#[Fillable(['name', 'type', 'area', 'title', 'image_path', 'url', 'new_tab', 'alt', 'body', 'variant', 'is_active', 'starts_at', 'ends_at'])]
|
||
class DashboardTile extends Model
|
||
{
|
||
public const TYPES = [
|
||
'image' => 'Bild mit Link',
|
||
'text' => 'Text',
|
||
'notice' => 'Hinweis',
|
||
];
|
||
|
||
public const AREAS = [
|
||
'aside' => 'Seitenleiste (rechts)',
|
||
'main' => 'Hauptspalte (breit)',
|
||
'top' => 'Ganz oben (volle Breite)',
|
||
];
|
||
|
||
public const VARIANTS = [
|
||
'brand' => 'Markenfarbe',
|
||
'info' => 'Info (blau)',
|
||
'success' => 'Erfolg (grün)',
|
||
'warning' => 'Warnung (rot)',
|
||
'neutral' => 'Neutral (grau)',
|
||
];
|
||
|
||
protected static function booted(): void
|
||
{
|
||
static::saving(function (DashboardTile $tile) {
|
||
$tile->url = filled($tile->url) ? (Field::safeUrl($tile->url) ?: null) : null;
|
||
|
||
if ($tile->isDirty('body')) {
|
||
$tile->body_html = app(RichText::class)->toSafeHtml($tile->body);
|
||
}
|
||
});
|
||
|
||
// Das Bild bleibt in der Mediathek (evtl. auch anderswo eingebunden) – aufräumen lässt es sich dort.
|
||
}
|
||
|
||
protected function casts(): array
|
||
{
|
||
return ['new_tab' => 'boolean', 'is_active' => 'boolean', 'starts_at' => 'datetime', 'ends_at' => 'datetime'];
|
||
}
|
||
|
||
public function widgetKey(): string
|
||
{
|
||
return 'tile.'.$this->id;
|
||
}
|
||
|
||
/**
|
||
* Aktiv, im Zeitraum und für die Person sichtbar.
|
||
*
|
||
* @param Builder<DashboardTile> $query
|
||
*/
|
||
public function scopeVisibleTo(Builder $query, User $user): void
|
||
{
|
||
$query->where('is_active', true)
|
||
->where(fn ($q) => $q->whereNull('starts_at')->orWhere('starts_at', '<=', now()))
|
||
->where(fn ($q) => $q->whereNull('ends_at')->orWhere('ends_at', '>', now()));
|
||
|
||
Audiences::constrain($query, 'dashboard_tile', 'dashboard_tiles.id', $user);
|
||
}
|
||
|
||
/**
|
||
* @return array<string, mixed>
|
||
*/
|
||
public function toWidgetProps(): array
|
||
{
|
||
return [
|
||
'tile' => [
|
||
'type' => $this->type,
|
||
'title' => $this->title,
|
||
'image_url' => app(Images::class)->url($this->image_path, null),
|
||
'url' => $this->url,
|
||
'new_tab' => $this->new_tab,
|
||
'alt' => $this->alt ?: '',
|
||
'html' => $this->body_html,
|
||
'variant' => $this->variant ?: 'brand',
|
||
],
|
||
];
|
||
}
|
||
}
|