Compare commits
97
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc40aba26c | ||
|
|
32837639e6 | ||
|
|
3825f53a9b | ||
|
|
604e1791c5 | ||
|
|
cd66561ca9 | ||
|
|
886715af96 | ||
|
|
05bd36509c | ||
|
|
96bb661239 | ||
|
|
340b898b7b | ||
|
|
9701777011 | ||
|
|
4520dba2f0 | ||
|
|
d49b178ebd | ||
|
|
da7ebca999 | ||
|
|
f72b79fd8c | ||
|
|
4e0760db1e | ||
|
|
6c8bbee363 | ||
|
|
7ad5929588 | ||
|
|
ed1f706d46 | ||
|
|
7c48a6480c | ||
|
|
d5c2b34b9d | ||
|
|
eb6192b067 | ||
|
|
061bc00564 | ||
|
|
8a97d9c334 | ||
|
|
e20f428a57 | ||
|
|
70695db290 | ||
|
|
f774d43647 | ||
|
|
c84ae10809 | ||
|
|
f3eda56021 | ||
|
|
4f3b7c351e | ||
|
|
75596bdaec | ||
|
|
5548106c31 | ||
|
|
dd3ee39f69 | ||
|
|
a7d369bab1 | ||
|
|
d4110b1d51 | ||
|
|
0c6519be28 | ||
|
|
30dd0f9eb8 | ||
|
|
07592f57bd | ||
|
|
bc6e4ec7ad | ||
|
|
77ebb0c1d5 | ||
|
|
4e00c4254b | ||
|
|
aaad2fa19b | ||
|
|
b23b30e897 | ||
|
|
afe35fc11f | ||
|
|
514eb46217 | ||
|
|
71e71b4ef2 | ||
|
|
0a0e4edbc2 | ||
|
|
b60029431f | ||
|
|
f4376ae819 | ||
|
|
51d58ac55c | ||
|
|
3aa1bad859 | ||
|
|
660b50f418 | ||
|
|
532979aa86 | ||
|
|
f846c0b2ee | ||
|
|
335b09f40e | ||
|
|
7b712e0c45 | ||
|
|
4847303a6f | ||
|
|
608550b620 | ||
|
|
0a8ff0761a | ||
|
|
a994c875ee | ||
|
|
d33ce86ae3 | ||
|
|
d1b10ef11d | ||
|
|
60f5b8e6c0 | ||
|
|
105d27f9c9 | ||
|
|
7eb3cd6230 | ||
|
|
156cdd6976 | ||
|
|
baa7691ab5 | ||
|
|
494e9fa0fb | ||
|
|
e7b0932e54 | ||
|
|
872f156d7d | ||
|
|
2d63109553 | ||
|
|
9dc4b4e64d | ||
|
|
1b271e0ce7 | ||
|
|
e1fd59491c | ||
|
|
41658d98dd | ||
|
|
b9fe0e3791 | ||
|
|
4c29ab2593 | ||
|
|
a359a5fb69 | ||
|
|
7b325f0d66 | ||
|
|
5590225f4f | ||
|
|
f29ea58fd5 | ||
|
|
c4be6ed8dc | ||
|
|
053a8d4648 | ||
|
|
7c63424ea6 | ||
|
|
13530b8171 | ||
|
|
72130d66c5 | ||
|
|
d37a7093dd | ||
|
|
3e56314cf9 | ||
|
|
8a6678aad7 | ||
|
|
b178939852 | ||
|
|
a08067c078 | ||
|
|
bc1f84ac89 | ||
|
|
39ab25d8c6 | ||
|
|
127ea86817 | ||
|
|
cca069be48 | ||
|
|
f511ad10de | ||
|
|
f4d225d0b2 | ||
|
|
89fd95b243 |
No files matched your search
@@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
description: Gemeinsame verbindliche UX-Vorgaben für Verwaltungsänderungen bei Lara & Felix. Ergänzt die Betriebsregeln, ersetzt sie nicht.
|
||||||
|
alwaysApply: true
|
||||||
|
---
|
||||||
|
|
||||||
|
# Verwaltung – gemeinsame Designgrundlage
|
||||||
|
|
||||||
|
Betriebsregeln in `CLAUDE.md` und `.cursor/rules/luf-betrieb.mdc` bleiben verbindlich. Diese Datei ergänzt sie für die Verwaltungsoberfläche.
|
||||||
|
|
||||||
|
1. `CLAUDE.md`, vorhandene aktive Repository-Regeln und `docs/ux/verwaltung/README.md` lesen.
|
||||||
|
2. `docs/ux/verwaltung/14-verwaltungsstandard.md` ist die maßgebliche UX-Grundlage. `15-umbauauftrag.md` beschreibt Umsetzung und Nachweise. Keine erneute allgemeine Designfreigabe oder neue Mockups je Screen verlangen.
|
||||||
|
3. Gemeinsame Komponenten statt kopierter Masken: Rahmen, Listen, Picker, Redaktion, geordnete Zuordnung, Status/Aktionen und Vorschau. Fachlich zulässige Typen und Referenzen sind Kontext derselben Komponente. Vorhanden in `resources/views/filament/verwaltung/`: `kopf` (Objektkopf, Status, Aktionen, Weitere Aktionen), `redaktion` (Manager), `texte`/`textfeld`, `praesentation`/`zuordnung-menue`, `einordnung`, `varianten`, `picker` (auch Aufbau, Vorschaubild und CMS-Bilder; Logik im Trait `ChoosesMedia`), `bestand` (gemeinsame Bestandsliste mit Suche, Filtern, aktiven Filterchips, Zeilen/Kacheln, „Weitere anzeigen“ und Dialogbereich; Trait `ShowsBestand`), Komponente `<x-vw.eintrag>` (Vorschau, Titel, Typzeile; Picker und Listen), `aufbau` (Struktur links, Detail rechts; auch Fassungen eines Mediums), `catalog/objekt` (Angebot, Paket, Rechteprofil), `cms/seite-kopf` (Seiteneditor mit Registern und Kontexten), Webpräsenz `cms/menues` mit `menue-zeile`, `menue-detail`, `ziel-auswahl` (Menüs als Arbeitsstand, breit Liste mit Detail, schmal ein aufgeklappter Eintrag), `bestaetigung` (statt `wire:confirm`), `abgang` (Warnung bei ungespeicherten Änderungen), `styles` (Tokens, einmal je Seite über den Panel-Hook). Logik im Trait `App\Filament\Support\ManagesEditorialSurface`; neue Objektarten liefern nur Feldliste, Einordnungsgruppen und Kopfangaben.
|
||||||
|
4. Eindeutigen Speicherumfang, Zustand und Vorschau-Datenstand anzeigen. Keine pauschale neue Genehmigungskette. Produktbeschreibung, Lehrinhalt, kommerzielle Daten und technische Verwaltung gezielt gliedern.
|
||||||
|
5. Redaktion für Medien einschließlich Filmen, Module, Programme und Lizenzartikel gemeinsam nutzen. Zentrale Medien referenzieren, mehrere Medien je Rolle und reine Präsentationsmedien ohne Lehrfassung erhalten.
|
||||||
|
6. Rückkehr mit offenen Eingaben sicherstellen; kein Pflichtspeichern vor dem Redaktionswechsel, kein heimliches Mitspeichern und kein veraltetes Zurückschreiben.
|
||||||
|
7. Bestehende Erwerbe, Rechte, Historie und fachliche Fassungsregeln erhalten. Offene Fragen in Dokument 04 nicht selbst durch neue Geschäftsregeln entscheiden; nur tatsächlich abhängige Teile gezielt klären.
|
||||||
|
8. Bestehende Tokens und freigegebene Assets nutzen. Verwaltungsmaße: `docs/ux/verwaltung/tokens.md`. Bilder sind räumliche Referenzen, keine autoritative Farbquelle oder auszuliefernde UI-Grafik.
|
||||||
|
9. Betroffene Abläufe funktional und visuell prüfen: Rückkehr, relevante Fehler-/Leer-/Ladezustände, Tastatur, breite/schmalere Fenster und fachliche Regressionen. Bestehende Betriebs- und Testregeln erfüllen.
|
||||||
|
10. Tatsächliche Komponentenwiederverwendung, Prüfergebnisse, gerenderte Screenshots und konkrete Abweichungen liefern; `docs/ux/verwaltung/regeln/ux-abnahme-vorlage.md` verwenden. Keine unbewiesene Abnahme behaupten.
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Einstieg für Coding-Agenten
|
||||||
|
|
||||||
|
Betriebs-, Test-, Deployment- und Medienschutzregeln stehen in `CLAUDE.md` und in `.cursor/rules/luf-betrieb.mdc`. Sie gelten unverändert.
|
||||||
|
|
||||||
|
Für die Verwaltung zusätzlich:
|
||||||
|
|
||||||
|
- `docs/ux/verwaltung/14-verwaltungsstandard.md` ist die maßgebliche Designgrundlage, `docs/ux/verwaltung/15-umbauauftrag.md` der konkrete Auftrag. Keine neue allgemeine Designfreigabe oder Screenserie verlangen.
|
||||||
|
- `docs/ux/verwaltung/README.md` und Dokument 04 für Herkunft und offene Geschäftsfragen. Historische Entwürfe nach der Rangfolge in Dokument 14 lesen.
|
||||||
|
- Gleichartige Aufgaben mit den gemeinsamen Komponenten unter `resources/views/filament/verwaltung/` und `resources/views/filament/editorial/` lösen. Fachfunktionen, Datenbeziehungen, Rechte und Fassungsbindungen erhalten.
|
||||||
|
- Offene Eingaben beim Wechsel zur Redaktion und zurück erhalten. Speicherwirkung benennen. Maße in `docs/ux/verwaltung/tokens.md`.
|
||||||
|
- Hauptabläufe prüfen, bestehende Testpflichten erfüllen, Abweichungen konkret benennen. Keine ungeprüfte Abnahme behaupten.
|
||||||
|
|
||||||
|
Diese Datei ergänzt die Betriebsregeln und löst kein Deployment aus.
|
||||||
@@ -59,3 +59,10 @@ ## Entwicklung
|
|||||||
- Commits: kurze, deutsche oder englische Betreffzeile im Imperativ, ein logischer Schritt pro Commit.
|
- Commits: kurze, deutsche oder englische Betreffzeile im Imperativ, ein logischer Schritt pro Commit.
|
||||||
- Änderungen an `.gitea/workflows/`, `Dockerfile`, `docker-compose.yml` und `scripts/deploy.sh` wirken direkt auf Test und Prod. Sie werden nur gezielt und mit Begründung geändert und in `docs/betrieb/DEPLOYMENT.md` nachgeführt.
|
- Änderungen an `.gitea/workflows/`, `Dockerfile`, `docker-compose.yml` und `scripts/deploy.sh` wirken direkt auf Test und Prod. Sie werden nur gezielt und mit Begründung geändert und in `docs/betrieb/DEPLOYMENT.md` nachgeführt.
|
||||||
- Nicht verifizierte Aussagen zu Servern oder Kapazitäten werden als solche gekennzeichnet. Nichts erfinden (Ports, Hostnamen, Pfade, Zugangsdaten).
|
- Nicht verifizierte Aussagen zu Servern oder Kapazitäten werden als solche gekennzeichnet. Nichts erfinden (Ports, Hostnamen, Pfade, Zugangsdaten).
|
||||||
|
|
||||||
|
## Verwaltungsoberfläche
|
||||||
|
|
||||||
|
- Maßgeblich sind `docs/ux/verwaltung/14-verwaltungsstandard.md` (Design und Interaktion) und `15-umbauauftrag.md` (Auftrag, Nachweise). Keine neue allgemeine Designabstimmung verlangen. Einstieg für alle Agenten: `AGENTS.md`, `.cursor/rules/verwaltung-ux.mdc`.
|
||||||
|
- Gemeinsame Bausteine wiederverwenden statt neue Masken bauen: `resources/views/filament/verwaltung/` (`kopf`, `redaktion`, `texte`, `praesentation`, `einordnung`, `picker`, `bestaetigung`, `abgang`, `aufbau`, `bestand`) mit dem Trait `App\Filament\Support\ManagesEditorialSurface`. Listen nutzen `verwaltung/bestand` mit `ShowsBestand` (bzw. `ListsCompositions`, `ListsCatalog`) und den Eintrag `<x-vw.eintrag>`, den auch der Picker verwendet; Katalogobjekte die Seite `catalog/objekt`. CMS: Seitenkopf `cms/seite-kopf` (Register, Kontexte „Abschnitt gestalten“ und „Konfigurieren“); Seiten und Menüs in der Webpräsenz (`App\Filament\Pages\Webpraesenz`, Menüs als Arbeitsstand mit einer Speicherhandlung). Der Picker liegt im Trait `ChoosesMedia` (Redaktion über `ManagesEditorialSurface`, CMS-Bilder über `ChoosesWebsiteImages`); keine eigenen Auswahllisten für Medien bauen. Redaktionelle Auswahlwerte (Materialart, Einordnung) nur über `App\Domain\Catalog\EditorialVocabulary` anbieten und prüfen (aktiv, zulässiger Kontext, vorhandene Zuordnungen erhalten); gepflegt werden sie unter „Redaktionelle Stammdaten“. Fachliche Säulen gibt es nur in der Säulenverwaltung (`pillars`); Zuordnung über `PillarService::assign`, nie über eine Dimension. Ersetzt eine Seite die Filament-Tabelle, muss sie den Dialogbereich ausgeben (in `bestand` enthalten), sonst öffnen „… anlegen“-Dialoge nicht. Gestaltungswerte nur in `verwaltung/styles.blade.php` (Tokens `--vw-…`, dokumentiert in `docs/ux/verwaltung/tokens.md`).
|
||||||
|
- Die Redaktion ist ein Arbeitsstand: nur „Redaktion speichern“ schreibt Texte, Einordnung, Präsentationsmedien und Abweichungen. Kein verdecktes Mitspeichern aus anderen Dialogen, offene Eingaben bleiben beim Wechsel erhalten.
|
||||||
|
- Jede UI-Änderung in der echten Anwendung prüfen (luf-test, breite und schmale Fenster, Tastatur) und mit Screenshots in `docs/ux/verwaltung/abnahme/` belegen. Stand der Abnahme: `abnahme/teil-a.md`, `abnahme/teil-b.md`, `abnahme/teil-c.md`, `abnahme/stammdaten.md`.
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\LegacyPillarAdoption;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class AdoptLegacyPillars extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'luf:saeulen-uebernehmen {--dry-run : Nur berichten, nichts schreiben}';
|
||||||
|
|
||||||
|
protected $description = 'Übernimmt die alte Dimension „Fachliche Säule“ in die zentrale Säulenverwaltung und berichtet ungeklärte Fälle';
|
||||||
|
|
||||||
|
public function handle(): int
|
||||||
|
{
|
||||||
|
$dryRun = (bool) $this->option('dry-run');
|
||||||
|
$report = (new LegacyPillarAdoption)->run($dryRun);
|
||||||
|
|
||||||
|
foreach (LegacyPillarAdoption::lines($report, $dryRun) as $line) {
|
||||||
|
$this->line($line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $report['unresolved'] === [] ? self::SUCCESS : self::FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,7 +67,7 @@ private function createFixture(
|
|||||||
$kind = EditorialContentKind::query()->where('slug', 'programm')->first();
|
$kind = EditorialContentKind::query()->where('slug', 'programm')->first();
|
||||||
|
|
||||||
if ($kind === null) {
|
if ($kind === null) {
|
||||||
$this->error('Die Inhaltsart Programm fehlt.');
|
$this->error('Die fachliche Materialart Programm fehlt.');
|
||||||
|
|
||||||
return self::FAILURE;
|
return self::FAILURE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
class Composition extends Model
|
class Composition extends Model
|
||||||
@@ -11,8 +12,10 @@ class Composition extends Model
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'designation',
|
'designation',
|
||||||
'display_title',
|
'display_title',
|
||||||
|
'teaser',
|
||||||
'summary',
|
'summary',
|
||||||
'description',
|
'description',
|
||||||
|
'search_terms',
|
||||||
'thumbnail_path',
|
'thumbnail_path',
|
||||||
'thumbnail_alt',
|
'thumbnail_alt',
|
||||||
'thumbnail_source',
|
'thumbnail_source',
|
||||||
@@ -42,4 +45,13 @@ public function versions(): HasMany
|
|||||||
{
|
{
|
||||||
return $this->hasMany(CompositionVersion::class);
|
return $this->hasMany(CompositionVersion::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Direkt zugeordnete fachliche Säulen (zentrale Säulenverwaltung). Die Säulen der enthaltenen Medien sind davon
|
||||||
|
* getrennt und werden zur Laufzeit abgeleitet (CatalogReading::memberPillars).
|
||||||
|
*/
|
||||||
|
public function pillars(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Pillar::class)->orderBy('pillars.sort_order')->orderBy('pillars.name');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,14 +14,21 @@ class ContentElement extends Model
|
|||||||
'output_class',
|
'output_class',
|
||||||
'working_title',
|
'working_title',
|
||||||
'display_title',
|
'display_title',
|
||||||
|
'teaser',
|
||||||
'description',
|
'description',
|
||||||
'usage_note',
|
'usage_note',
|
||||||
'license_note',
|
'license_note',
|
||||||
|
'website_credit',
|
||||||
|
'website_alt',
|
||||||
|
'website_released_at',
|
||||||
|
'website_public_path',
|
||||||
'summary',
|
'summary',
|
||||||
|
'search_terms',
|
||||||
'thumbnail_path',
|
'thumbnail_path',
|
||||||
'thumbnail_alt',
|
'thumbnail_alt',
|
||||||
'thumbnail_source',
|
'thumbnail_source',
|
||||||
'thumbnail_error',
|
'thumbnail_error',
|
||||||
|
'preview_path',
|
||||||
'editorial_content_kind_id',
|
'editorial_content_kind_id',
|
||||||
'archived_at',
|
'archived_at',
|
||||||
];
|
];
|
||||||
@@ -30,6 +37,7 @@ protected function casts(): array
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'archived_at' => 'datetime',
|
'archived_at' => 'datetime',
|
||||||
|
'website_released_at' => 'datetime',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,17 +2,49 @@
|
|||||||
|
|
||||||
namespace App\Domain\Catalog;
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fachliche Materialart (FACH-56 bis FACH-58). Die Bezeichnung ist pflegbar, die Kennung (slug) bleibt nach dem Anlegen
|
||||||
|
* fest. Zulässige Objektkontexte bestimmen, wo eine Materialart neu gewählt werden kann; vorhandene Zuordnungen bleiben
|
||||||
|
* immer erhalten (siehe EditorialVocabulary).
|
||||||
|
*/
|
||||||
class EditorialContentKind extends Model
|
class EditorialContentKind extends Model
|
||||||
{
|
{
|
||||||
|
/** Objektkontexte aus dem Fachmodell: Medium (ContentElement), Modul und Programm (Composition), Lizenzartikel. */
|
||||||
|
public const CONTEXTS = [
|
||||||
|
'medium' => 'Medium',
|
||||||
|
'modul' => 'Modul',
|
||||||
|
'programm' => 'Programm',
|
||||||
|
'lizenzartikel' => 'Lizenzartikel',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kennungen, auf die der Code fachlich verweist: öffentliche Programmseiten und das Anlegen von Programmen und
|
||||||
|
* Modulen (programm, modul), Vertraulichkeit von Traineranleitungen (traineranleitung). Ihre Bezeichnung bleibt
|
||||||
|
* pflegbar; deaktivieren, Kontexte ändern und löschen sind gesperrt.
|
||||||
|
*/
|
||||||
|
public const SYSTEM_SLUGS = ['programm', 'modul', 'traineranleitung'];
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'slug',
|
'slug',
|
||||||
'label',
|
'label',
|
||||||
'sort_order',
|
'sort_order',
|
||||||
|
'is_active',
|
||||||
|
'contexts',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'is_active' => 'boolean',
|
||||||
|
'contexts' => 'array',
|
||||||
|
'sort_order' => 'integer',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function compositions(): HasMany
|
public function compositions(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Composition::class);
|
return $this->hasMany(Composition::class);
|
||||||
@@ -23,11 +55,37 @@ public function contentElements(): HasMany
|
|||||||
return $this->hasMany(ContentElement::class);
|
return $this->hasMany(ContentElement::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function licenseArticles(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(LicenseArticle::class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param Builder<EditorialContentKind> $query
|
||||||
|
*/
|
||||||
|
public function scopeActive(Builder $query): void
|
||||||
|
{
|
||||||
|
$query->where('is_active', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function allows(string $context): bool
|
||||||
|
{
|
||||||
|
return in_array($context, (array) ($this->contexts ?? []), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isSystem(): bool
|
||||||
|
{
|
||||||
|
return in_array($this->slug, self::SYSTEM_SLUGS, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alle Materialarten in Pflegereihenfolge (ohne Kontext- oder Aktivfilter). Für Auswahlstellen gilt
|
||||||
|
* EditorialVocabulary.
|
||||||
|
*
|
||||||
* @return array<int, string>
|
* @return array<int, string>
|
||||||
*/
|
*/
|
||||||
public static function selectOptions(): array
|
public static function selectOptions(): array
|
||||||
{
|
{
|
||||||
return static::query()->orderBy('sort_order')->pluck('label', 'id')->all();
|
return static::query()->orderBy('sort_order')->orderBy('id')->pluck('label', 'id')->all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,15 +2,43 @@
|
|||||||
|
|
||||||
namespace App\Domain\Catalog;
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
class EditorialDimension extends Model
|
class EditorialDimension extends Model
|
||||||
{
|
{
|
||||||
|
/** Gespiegelte Säulen; gepflegt werden Säulen über die Säulenverwaltung, nicht als Stammdaten. */
|
||||||
|
public const PILLAR_SLUG = 'saeule';
|
||||||
|
|
||||||
protected $fillable = ['slug', 'label'];
|
protected $fillable = ['slug', 'label'];
|
||||||
|
|
||||||
|
/** Werte in Pflegereihenfolge. */
|
||||||
public function values(): HasMany
|
public function values(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(EditorialDimensionValue::class);
|
return $this->hasMany(EditorialDimensionValue::class)->orderBy('sort_order')->orderBy('id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fachliche Säulen werden für alle Objektarten über die zentrale Säulenverwaltung gewählt (`pillars`), nie über
|
||||||
|
* eine Dimension. Die alte Dimension „Fachliche Säule“ bleibt nur als Verlauf in der Datenbank und wird nirgends
|
||||||
|
* mehr angeboten, geändert oder gefiltert.
|
||||||
|
*
|
||||||
|
* @return Collection<int, self>
|
||||||
|
*/
|
||||||
|
public static function forSubject(Model $subject): Collection
|
||||||
|
{
|
||||||
|
return static::query()->with('values')->where('slug', '!=', self::PILLAR_SLUG)->orderBy('label')->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<int>
|
||||||
|
*/
|
||||||
|
public static function offeredValueIds(Model $subject): array
|
||||||
|
{
|
||||||
|
return static::forSubject($subject)
|
||||||
|
->flatMap(fn (self $dimension) => $dimension->values->pluck('id'))
|
||||||
|
->map(fn ($id): int => (int) $id)
|
||||||
|
->all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,15 @@
|
|||||||
|
|
||||||
class EditorialDimensionValue extends Model
|
class EditorialDimensionValue extends Model
|
||||||
{
|
{
|
||||||
protected $fillable = ['editorial_dimension_id', 'slug', 'label'];
|
protected $fillable = ['editorial_dimension_id', 'pillar_id', 'slug', 'label', 'sort_order', 'is_active'];
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'is_active' => 'boolean',
|
||||||
|
'sort_order' => 'integer',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function dimension(): BelongsTo
|
public function dimension(): BelongsTo
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aufgelöste Klasse-A-Angaben eines Fachobjekts.
|
||||||
|
* Fehlende Felder bleiben leer. Es wird nichts materialisiert.
|
||||||
|
*/
|
||||||
|
final readonly class EditorialProfile
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, ResolvedText> $texts
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public ?string $workingTitle,
|
||||||
|
public array $texts,
|
||||||
|
public ?string $searchTerms,
|
||||||
|
public string $searchOrigin,
|
||||||
|
public ?string $kindLabel,
|
||||||
|
public ?Model $source,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function text(string $field): ResolvedText
|
||||||
|
{
|
||||||
|
return $this->texts[$field] ?? new ResolvedText(null, 'leer', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function value(string $field): ?string
|
||||||
|
{
|
||||||
|
return $this->text($field)->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function origin(string $field): string
|
||||||
|
{
|
||||||
|
return $this->text($field)->origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function originLabel(string $field): string
|
||||||
|
{
|
||||||
|
$text = $this->text($field);
|
||||||
|
|
||||||
|
return match ($text->origin) {
|
||||||
|
'eigen' => 'Eigene Angabe',
|
||||||
|
'variante' => 'Abweichung für '.($text->label ?? 'diesen Kontext'),
|
||||||
|
'quelle' => 'Übernommen von '.($text->label ?? 'der fachlichen Quelle'),
|
||||||
|
default => 'Keine Angabe',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,225 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Löst die Klasse-A-Texte eines Fachobjekts auf.
|
||||||
|
*
|
||||||
|
* Reihenfolge: abweichende Formulierung für den Kontext, eigene Angabe am Objekt,
|
||||||
|
* bei einem Lizenzartikel die Angabe der eindeutigen fachlichen Quelle.
|
||||||
|
* Eine Quelle gibt es nur, wenn der aktuelle Artikelstand genau eine Wurzel hat.
|
||||||
|
* Preise, Rechte und Fassungen werden nicht gelesen und nicht geschrieben.
|
||||||
|
*/
|
||||||
|
class EditorialProfileReader
|
||||||
|
{
|
||||||
|
public const AUDIENCES = [
|
||||||
|
'kachel' => 'Öffentliche Kachel',
|
||||||
|
'detail' => 'Öffentliche Detailvorstellung',
|
||||||
|
'bibliothek' => 'Mitgliederbibliothek',
|
||||||
|
'trainer' => 'Fachliche Traineransicht',
|
||||||
|
'artikel' => 'Lizenzartikelpräsentation',
|
||||||
|
'cms' => 'CMS-Teaser',
|
||||||
|
'suche' => 'Suchergebnis',
|
||||||
|
];
|
||||||
|
|
||||||
|
public const TEXT_FIELDS = ['display_title', 'teaser', 'summary', 'description'];
|
||||||
|
|
||||||
|
public function read(Model $subject, ?string $audience = null): EditorialProfile
|
||||||
|
{
|
||||||
|
if ($audience !== null && ! array_key_exists($audience, self::AUDIENCES)) {
|
||||||
|
throw new DomainRuleException('Diese Zielgruppe ist nicht vorgesehen.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$source = $subject instanceof LicenseArticle ? $this->sourceOf($subject) : null;
|
||||||
|
$texts = [];
|
||||||
|
|
||||||
|
foreach (self::TEXT_FIELDS as $field) {
|
||||||
|
$texts[$field] = $this->resolve($subject, $field, $audience, $source);
|
||||||
|
}
|
||||||
|
|
||||||
|
$search = $this->own($subject, 'search_terms');
|
||||||
|
$searchOrigin = 'eigen';
|
||||||
|
|
||||||
|
if ($search === null && $source instanceof Model) {
|
||||||
|
$search = $this->own($source, 'search_terms');
|
||||||
|
$searchOrigin = $search === null ? 'leer' : 'quelle';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($search === null) {
|
||||||
|
$searchOrigin = 'leer';
|
||||||
|
}
|
||||||
|
|
||||||
|
return new EditorialProfile(
|
||||||
|
workingTitle: $this->workingTitle($subject),
|
||||||
|
texts: $texts,
|
||||||
|
searchTerms: $search,
|
||||||
|
searchOrigin: $searchOrigin,
|
||||||
|
kindLabel: $subject->editorialContentKind?->label
|
||||||
|
?? ($source?->editorialContentKind?->label),
|
||||||
|
source: $source,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sourceOf(LicenseArticle $article): ?Model
|
||||||
|
{
|
||||||
|
$release = $article->relationLoaded('currentRelease')
|
||||||
|
? $article->currentRelease
|
||||||
|
: $article->currentRelease()->first();
|
||||||
|
|
||||||
|
if (! $release instanceof ArticleRelease) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$elementId = $release->root_element_version_id;
|
||||||
|
$compositionId = $release->root_composition_version_id;
|
||||||
|
|
||||||
|
if (($elementId === null) === ($compositionId === null)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($elementId !== null) {
|
||||||
|
return ContentElementVersion::query()->with('element.editorialContentKind')->find($elementId)?->element;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CompositionVersion::query()->with('composition.editorialContentKind')->find($compositionId)?->composition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putVariant(Model $subject, string $field, string $audience, ?string $body, ?User $actor = null): string
|
||||||
|
{
|
||||||
|
if (! in_array($field, self::TEXT_FIELDS, true) || ! array_key_exists($audience, self::AUDIENCES)) {
|
||||||
|
throw new DomainRuleException('Diese Abweichung ist nicht vorgesehen.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = is_string($body) ? trim($body) : '';
|
||||||
|
$existing = $this->variant($subject, $field, $audience);
|
||||||
|
|
||||||
|
if ($body === '') {
|
||||||
|
if ($existing instanceof EditorialTextVariant) {
|
||||||
|
$this->record($subject, $audience, $field, $existing->body, null, $actor);
|
||||||
|
$existing->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'Die abweichende Formulierung ist entfernt. Es gilt wieder die zentrale Angabe.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($existing instanceof EditorialTextVariant && $existing->body === $body) {
|
||||||
|
return 'Die abweichende Formulierung ist unverändert.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->record($subject, $audience, $field, $existing?->body, $body, $actor);
|
||||||
|
|
||||||
|
EditorialTextVariant::query()->updateOrCreate(
|
||||||
|
[
|
||||||
|
'subject_type' => $subject->getMorphClass(),
|
||||||
|
'subject_id' => $subject->getKey(),
|
||||||
|
'field' => $field,
|
||||||
|
'audience' => $audience,
|
||||||
|
],
|
||||||
|
['body' => $body],
|
||||||
|
);
|
||||||
|
|
||||||
|
return 'Die abweichende Formulierung gilt nur für '.self::AUDIENCES[$audience].'. Die zentrale Angabe bleibt.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function forgetVariant(Model $subject, EditorialTextVariant $variant, ?User $actor = null): void
|
||||||
|
{
|
||||||
|
if ($variant->subject_type !== $subject->getMorphClass() || (int) $variant->subject_id !== (int) $subject->getKey()) {
|
||||||
|
throw new DomainRuleException('Diese Abweichung gehört zu einem anderen Objekt.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->record($subject, $variant->audience, $variant->field, $variant->body, null, $actor);
|
||||||
|
$variant->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolve(Model $subject, string $field, ?string $audience, ?Model $source): ResolvedText
|
||||||
|
{
|
||||||
|
if ($audience !== null) {
|
||||||
|
$variant = $this->variant($subject, $field, $audience);
|
||||||
|
|
||||||
|
if ($variant instanceof EditorialTextVariant && trim($variant->body) !== '') {
|
||||||
|
return new ResolvedText(trim($variant->body), 'variante', self::AUDIENCES[$audience]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$own = $this->own($subject, $field);
|
||||||
|
|
||||||
|
if ($own !== null) {
|
||||||
|
return new ResolvedText($own, 'eigen', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($source instanceof Model) {
|
||||||
|
$fromSource = $this->resolve($source, $field, $audience, null);
|
||||||
|
|
||||||
|
if ($fromSource->value !== null) {
|
||||||
|
return new ResolvedText($fromSource->value, 'quelle', $this->sourceLabel($source));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResolvedText(null, 'leer', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function variant(Model $subject, string $field, string $audience): ?EditorialTextVariant
|
||||||
|
{
|
||||||
|
return EditorialTextVariant::query()
|
||||||
|
->where('subject_type', $subject->getMorphClass())
|
||||||
|
->where('subject_id', $subject->getKey())
|
||||||
|
->where('field', $field)
|
||||||
|
->where('audience', $audience)
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function own(Model $subject, string $field): ?string
|
||||||
|
{
|
||||||
|
$value = $subject->getAttribute($field);
|
||||||
|
|
||||||
|
if (! is_string($value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = trim($value);
|
||||||
|
|
||||||
|
return $value === '' ? null : $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function workingTitle(Model $subject): ?string
|
||||||
|
{
|
||||||
|
if ($subject instanceof Composition) {
|
||||||
|
return $this->own($subject, 'designation');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($subject instanceof LicenseArticle) {
|
||||||
|
return $this->own($subject, 'working_title') ?? $this->own($subject, 'code');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->own($subject, 'working_title');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sourceLabel(Model $source): string
|
||||||
|
{
|
||||||
|
if ($source instanceof Composition) {
|
||||||
|
return (string) ($source->display_title ?: $source->designation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($source instanceof ContentElement) {
|
||||||
|
return (string) ($source->display_title ?: $source->working_title);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'der fachlichen Quelle';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function record(Model $subject, string $audience, string $field, ?string $before, ?string $after, ?User $actor): void
|
||||||
|
{
|
||||||
|
IdentityChange::query()->create([
|
||||||
|
'subject_type' => $subject->getMorphClass(),
|
||||||
|
'subject_id' => $subject->getKey(),
|
||||||
|
'field' => 'variante:'.$audience.':'.$field,
|
||||||
|
'before' => $before,
|
||||||
|
'after' => $after,
|
||||||
|
'actor_id' => $actor?->id,
|
||||||
|
'occurred_at' => now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class EditorialTextVariant extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'subject_type',
|
||||||
|
'subject_id',
|
||||||
|
'field',
|
||||||
|
'audience',
|
||||||
|
'body',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eine Regelquelle für redaktionelle Stammdaten (FACH-56 bis FACH-58): Welche fachlichen Materialarten und welche
|
||||||
|
* Einordnungswerte Editor, Filter und Picker anbieten.
|
||||||
|
*
|
||||||
|
* - Neu wählbar sind nur aktive Werte; Materialarten zusätzlich nur im zulässigen Objektkontext.
|
||||||
|
* - Vorhandene Zuordnungen bleiben sichtbar und erhalten, auch wenn der Wert inaktiv ist oder sein Kontext geändert
|
||||||
|
* wurde; sie sind gekennzeichnet.
|
||||||
|
* - Filter finden auch Objekte mit inaktiven Werten; ein gewählter Filter bleibt erhalten.
|
||||||
|
*/
|
||||||
|
final class EditorialVocabulary
|
||||||
|
{
|
||||||
|
public const INACTIVE_SUFFIX = ' (inaktiv)';
|
||||||
|
|
||||||
|
public const OUT_OF_CONTEXT_SUFFIX = ' (hier nicht vorgesehen)';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Objektkontext eines Fachobjekts nach dem Fachmodell, null wenn es keine Materialart trägt.
|
||||||
|
*/
|
||||||
|
public function contextOf(Model $subject): ?string
|
||||||
|
{
|
||||||
|
if ($subject instanceof ContentElement) {
|
||||||
|
return 'medium';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($subject instanceof LicenseArticle) {
|
||||||
|
return 'lizenzartikel';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($subject instanceof Composition) {
|
||||||
|
return self::compositionContext($subject->kind instanceof CompositionKind ? $subject->kind : CompositionKind::tryFrom((string) $subject->kind));
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function compositionContext(?CompositionKind $kind): ?string
|
||||||
|
{
|
||||||
|
return match ($kind) {
|
||||||
|
CompositionKind::Kurs => 'programm',
|
||||||
|
CompositionKind::Uebung => 'modul',
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auswahl der Materialart in einem Editor: aktive, im Kontext zulässige Arten in Pflegereihenfolge, dazu die
|
||||||
|
* bereits zugeordnete Art mit Kennzeichnung, falls sie inaktiv oder hier nicht vorgesehen ist.
|
||||||
|
*
|
||||||
|
* @return array<int, string>
|
||||||
|
*/
|
||||||
|
public function kindOptions(string $context, ?int $currentId = null): array
|
||||||
|
{
|
||||||
|
$options = [];
|
||||||
|
|
||||||
|
foreach (EditorialContentKind::query()->orderBy('sort_order')->orderBy('id')->get() as $kind) {
|
||||||
|
$offered = $kind->is_active && $kind->allows($context);
|
||||||
|
|
||||||
|
if ($offered) {
|
||||||
|
$options[$kind->id] = (string) $kind->label;
|
||||||
|
} elseif ($currentId !== null && $kind->id === $currentId) {
|
||||||
|
$options[$kind->id] = $this->kindLabel($kind, $context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prüft eine neue Materialart serverseitig. Die bereits gespeicherte Art bleibt immer zulässig.
|
||||||
|
*/
|
||||||
|
public function kindError(string $context, ?int $newId, ?int $storedId): ?string
|
||||||
|
{
|
||||||
|
if ($newId === null || $newId === $storedId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$kind = EditorialContentKind::query()->find($newId);
|
||||||
|
|
||||||
|
if (! $kind instanceof EditorialContentKind) {
|
||||||
|
return 'Diese fachliche Materialart gibt es nicht mehr.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $kind->is_active) {
|
||||||
|
return 'Die fachliche Materialart „'.$kind->label.'“ ist deaktiviert und kann nicht neu gewählt werden.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $kind->allows($context)) {
|
||||||
|
return 'Die fachliche Materialart „'.$kind->label.'“ ist für '.(EditorialContentKind::CONTEXTS[$context] ?? $context).' nicht vorgesehen.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filteroptionen der Materialart für einen Bestand: im Kontext zulässige Arten und Arten, die dort tatsächlich
|
||||||
|
* vorkommen (gekennzeichnet), dazu ein bereits gewählter Filter.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function kindFilterOptions(string $context, string $selected = ''): array
|
||||||
|
{
|
||||||
|
$used = $this->usedKindIds($context);
|
||||||
|
$options = [];
|
||||||
|
|
||||||
|
foreach (EditorialContentKind::query()->orderBy('sort_order')->orderBy('id')->get() as $kind) {
|
||||||
|
$show = ($kind->allows($context) && $kind->is_active) || in_array($kind->id, $used, true) || (string) $kind->id === $selected;
|
||||||
|
|
||||||
|
if ($show) {
|
||||||
|
$options[(string) $kind->id] = $this->kindLabel($kind, $context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function kindLabel(EditorialContentKind $kind, string $context): string
|
||||||
|
{
|
||||||
|
return (string) $kind->label
|
||||||
|
.(! $kind->is_active ? self::INACTIVE_SUFFIX : (! $kind->allows($context) ? self::OUT_OF_CONTEXT_SUFFIX : ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<int>
|
||||||
|
*/
|
||||||
|
private function usedKindIds(string $context): array
|
||||||
|
{
|
||||||
|
$query = match ($context) {
|
||||||
|
'medium' => DB::table('content_elements'),
|
||||||
|
'lizenzartikel' => DB::table('license_articles'),
|
||||||
|
'programm' => DB::table('compositions')->where('kind', CompositionKind::Kurs->value),
|
||||||
|
'modul' => DB::table('compositions')->where('kind', CompositionKind::Uebung->value),
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
|
||||||
|
return $query === null ? [] : $query->whereNotNull('editorial_content_kind_id')->distinct()
|
||||||
|
->pluck('editorial_content_kind_id')->map(fn ($id): int => (int) $id)->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Einordnung im Editor: je angebotener Dimension aktive Werte und bereits zugeordnete inaktive Werte (gekennzeichnet).
|
||||||
|
*
|
||||||
|
* @param list<int> $assignedIds
|
||||||
|
* @return list<array{label: string, values: list<array{id: int, label: string, inactive: bool}>}>
|
||||||
|
*/
|
||||||
|
public function dimensionGroups(Model $subject, array $assignedIds): array
|
||||||
|
{
|
||||||
|
$groups = [];
|
||||||
|
|
||||||
|
foreach (EditorialDimension::forSubject($subject) as $dimension) {
|
||||||
|
$values = [];
|
||||||
|
|
||||||
|
foreach ($dimension->values as $value) {
|
||||||
|
if ($value->is_active || in_array((int) $value->id, $assignedIds, true)) {
|
||||||
|
$values[] = [
|
||||||
|
'id' => (int) $value->id,
|
||||||
|
'label' => (string) $value->label.($value->is_active ? '' : self::INACTIVE_SUFFIX),
|
||||||
|
'inactive' => ! $value->is_active,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($values !== []) {
|
||||||
|
$groups[] = ['label' => (string) $dimension->label, 'values' => $values];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filtergruppen der Einordnung: aktive Werte, verwendete inaktive Werte (gekennzeichnet) und gewählte Filter.
|
||||||
|
*
|
||||||
|
* @param list<int> $selectedIds
|
||||||
|
* @return list<array{label: string, values: list<array{id: int, label: string}>}>
|
||||||
|
*/
|
||||||
|
public function dimensionFilterGroups(array $selectedIds = []): array
|
||||||
|
{
|
||||||
|
$used = DB::table('identity_dimension_values')->distinct()->pluck('editorial_dimension_value_id')->map(fn ($id): int => (int) $id)->all();
|
||||||
|
$groups = [];
|
||||||
|
|
||||||
|
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
|
||||||
|
if ($dimension->slug === EditorialDimension::PILLAR_SLUG) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$values = [];
|
||||||
|
|
||||||
|
foreach ($dimension->values as $value) {
|
||||||
|
$id = (int) $value->id;
|
||||||
|
|
||||||
|
if ($value->is_active || in_array($id, $used, true) || in_array($id, $selectedIds, true)) {
|
||||||
|
$values[] = ['id' => $id, 'label' => (string) $value->label.($value->is_active ? '' : self::INACTIVE_SUFFIX)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($values !== []) {
|
||||||
|
$groups[] = ['label' => (string) $dimension->label, 'values' => $values];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Öffentliche Filter der Mitgliederbibliothek: nur aktive Werte, ein bereits gewählter Wert bleibt sichtbar.
|
||||||
|
*
|
||||||
|
* @param list<int> $selectedIds
|
||||||
|
* @return Collection<int, EditorialDimension>
|
||||||
|
*/
|
||||||
|
public function memberFilterDimensions(array $selectedIds = []): Collection
|
||||||
|
{
|
||||||
|
$dimensions = EditorialDimension::query()->with('values')->where('slug', '!=', EditorialDimension::PILLAR_SLUG)->orderBy('label')->get();
|
||||||
|
|
||||||
|
foreach ($dimensions as $dimension) {
|
||||||
|
$dimension->setRelation('values', $dimension->values
|
||||||
|
->filter(fn (EditorialDimensionValue $value): bool => $value->is_active || in_array((int) $value->id, $selectedIds, true))
|
||||||
|
->values());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dimensions->filter(fn (EditorialDimension $dimension): bool => $dimension->values->isNotEmpty())->values();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Für replaceOffered: Werte, die bei diesem Fachobjekt gesetzt oder entfernt werden dürfen. Aktive Werte der
|
||||||
|
* angebotenen Dimensionen und die bereits zugeordneten inaktiven (der Editor zeigt sie gekennzeichnet an).
|
||||||
|
*
|
||||||
|
* @param list<int> $assignedIds
|
||||||
|
* @return list<int>
|
||||||
|
*/
|
||||||
|
public function editableValueIds(Model $subject, array $assignedIds): array
|
||||||
|
{
|
||||||
|
$ids = [];
|
||||||
|
|
||||||
|
foreach (EditorialDimension::forSubject($subject) as $dimension) {
|
||||||
|
foreach ($dimension->values as $value) {
|
||||||
|
if ($value->is_active || in_array((int) $value->id, $assignedIds, true)) {
|
||||||
|
$ids[] = (int) $value->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,4 +52,44 @@ public function matches(Model $subject, array $valueIds): bool
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ersetzt nur die Werte der Dimensionen, die dieses Fachobjekt anbietet.
|
||||||
|
* Nicht angebotene Zuordnungen, etwa gespiegelte Säulen am Inhaltselement, bleiben.
|
||||||
|
*
|
||||||
|
* Inaktive Werte (Stammdatenpflege) sind nicht neu wählbar. Bereits zugeordnete inaktive Werte zeigt der Editor
|
||||||
|
* gekennzeichnet an; sie bleiben, solange sie mitgeschickt werden, und werden nur bei ausdrücklicher Abwahl entfernt.
|
||||||
|
*
|
||||||
|
* @param list<int> $valueIds
|
||||||
|
*/
|
||||||
|
public function replaceOffered(Model $subject, array $valueIds): void
|
||||||
|
{
|
||||||
|
$assigned = IdentityDimensionValue::query()
|
||||||
|
->where('subject_type', $subject->getMorphClass())
|
||||||
|
->where('subject_id', $subject->getKey())
|
||||||
|
->pluck('editorial_dimension_value_id')
|
||||||
|
->map(fn ($id): int => (int) $id)
|
||||||
|
->all();
|
||||||
|
$offeredIds = app(EditorialVocabulary::class)->editableValueIds($subject, $assigned);
|
||||||
|
$ids = array_values(array_intersect(
|
||||||
|
array_values(array_unique(array_map(intval(...), $valueIds))),
|
||||||
|
$offeredIds,
|
||||||
|
));
|
||||||
|
|
||||||
|
$query = IdentityDimensionValue::query()
|
||||||
|
->where('subject_type', $subject->getMorphClass())
|
||||||
|
->where('subject_id', $subject->getKey())
|
||||||
|
->where('origin', 'direkt')
|
||||||
|
->whereIn('editorial_dimension_value_id', $offeredIds === [] ? [0] : $offeredIds);
|
||||||
|
|
||||||
|
if ($ids !== []) {
|
||||||
|
$query->whereNotIn('editorial_dimension_value_id', $ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->delete();
|
||||||
|
|
||||||
|
foreach (EditorialDimensionValue::query()->whereIn('id', $ids)->get() as $value) {
|
||||||
|
$this->assign($subject, $value, 'direkt');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,270 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Übernimmt die frühere Kopie „Fachliche Säule“ (Dimension `saeule`) in die zentrale Säulenverwaltung (Tabelle
|
||||||
|
* `pillars`). Verlustfrei, wiederholbar und ohne Raten:
|
||||||
|
*
|
||||||
|
* - **Zuordnung Wert → Säule** nur über die gespeicherte Kennung `pfeiler-{Säulenkennung}`, die die Migration
|
||||||
|
* vom 16.11.2026 beim Spiegeln geschrieben hat, und nur, wenn die Säule existiert und nicht jünger als der Wert ist
|
||||||
|
* (sonst kann die Kennung nicht aus ihr entstanden sein). Eine abweichende Bezeichnung ist nach einem Umbenennen
|
||||||
|
* erwartet und wird nur berichtet. Die Verknüpfung steht in `editorial_dimension_values.pillar_id`.
|
||||||
|
* - **Übernommen** werden nur direkte Zuordnungen von Modulen, Programmen und Lizenzartikeln in `composition_pillar`
|
||||||
|
* und `license_article_pillar` (insert-or-ignore, daher beliebig oft ausführbar).
|
||||||
|
* - **Nicht übernommen, sondern gemeldet:** Werte ohne belastbare Kennung, Zuordnungen zu fehlenden Objekten,
|
||||||
|
* abgeleitete Zuordnungen und unbekannte Objektarten. Abgeleitete Säulen eines Programms oder Moduls entstehen zur
|
||||||
|
* Laufzeit aus den enthaltenen Medien und werden nie als direkte Zuordnung gespeichert.
|
||||||
|
* - **Medien:** Die gespiegelten Zeilen sind eine veraltete Kopie; maßgeblich ist `content_element_pillar`. Sie werden
|
||||||
|
* nicht zurückgemischt, nur gezählt.
|
||||||
|
* - Alte Zeilen werden weder geändert noch gelöscht.
|
||||||
|
*
|
||||||
|
* Nur die Datenbankfassade, damit spätere Änderungen an Modellen die Migration nicht berühren.
|
||||||
|
*/
|
||||||
|
final class LegacyPillarAdoption
|
||||||
|
{
|
||||||
|
/** @var array<string, array{table: string, column: string, subjects: string}> */
|
||||||
|
private const TARGETS = [
|
||||||
|
'composition' => ['table' => 'composition_pillar', 'column' => 'composition_id', 'subjects' => 'compositions'],
|
||||||
|
'license_article' => ['table' => 'license_article_pillar', 'column' => 'license_article_id', 'subjects' => 'license_articles'],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{
|
||||||
|
* mapping: list<array<string, mixed>>,
|
||||||
|
* unresolved: list<array<string, mixed>>,
|
||||||
|
* copied: array<string, int>,
|
||||||
|
* already: array<string, int>,
|
||||||
|
* before: array<string, int>,
|
||||||
|
* after: array<string, int>,
|
||||||
|
* mirror: array<string, int>
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public function run(bool $dryRun = false): array
|
||||||
|
{
|
||||||
|
$report = [
|
||||||
|
'mapping' => [],
|
||||||
|
'unresolved' => [],
|
||||||
|
'copied' => ['composition' => 0, 'license_article' => 0],
|
||||||
|
'already' => ['composition' => 0, 'license_article' => 0],
|
||||||
|
'before' => $this->counts(),
|
||||||
|
'after' => [],
|
||||||
|
'mirror' => ['element_rows' => 0, 'missing_in_pivot' => 0, 'only_in_pivot' => 0],
|
||||||
|
];
|
||||||
|
|
||||||
|
$dimension = DB::table('editorial_dimensions')->where('slug', 'saeule')->first();
|
||||||
|
|
||||||
|
if ($dimension === null) {
|
||||||
|
$report['after'] = $report['before'];
|
||||||
|
|
||||||
|
return $report;
|
||||||
|
}
|
||||||
|
|
||||||
|
$resolved = [];
|
||||||
|
|
||||||
|
foreach (DB::table('editorial_dimension_values')->where('editorial_dimension_id', $dimension->id)->orderBy('id')->get() as $value) {
|
||||||
|
$pillar = $this->pillarFor($value);
|
||||||
|
|
||||||
|
if (is_string($pillar)) {
|
||||||
|
$report['unresolved'][] = ['art' => 'Wert', 'wert_id' => (int) $value->id, 'wert' => $value->label, 'kennung' => $value->slug, 'grund' => $pillar];
|
||||||
|
$report['mapping'][] = ['wert_id' => (int) $value->id, 'wert' => $value->label, 'saeule_id' => null, 'status' => 'offen'];
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$resolved[(int) $value->id] = (int) $pillar->id;
|
||||||
|
$status = $value->pillar_id === null ? 'zugeordnet' : 'bereits zugeordnet';
|
||||||
|
$hint = $value->label !== $pillar->name ? 'über Kennung zugeordnet, Bezeichnung weicht ab („'.$pillar->name.'“)' : null;
|
||||||
|
$report['mapping'][] = ['wert_id' => (int) $value->id, 'wert' => $value->label, 'saeule_id' => (int) $pillar->id, 'saeule' => $pillar->name, 'status' => $status, 'hinweis' => $hint];
|
||||||
|
|
||||||
|
if ($value->pillar_id === null && ! $dryRun) {
|
||||||
|
DB::table('editorial_dimension_values')->where('id', $value->id)->update(['pillar_id' => $pillar->id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$subjectTypes = $this->subjectTypes();
|
||||||
|
|
||||||
|
foreach (DB::table('identity_dimension_values')
|
||||||
|
->whereIn('editorial_dimension_value_id', DB::table('editorial_dimension_values')->where('editorial_dimension_id', $dimension->id)->select('id'))
|
||||||
|
->orderBy('id')->get() as $row) {
|
||||||
|
$valueId = (int) $row->editorial_dimension_value_id;
|
||||||
|
$label = DB::table('editorial_dimension_values')->where('id', $valueId)->value('label');
|
||||||
|
$target = $subjectTypes[$row->subject_type] ?? null;
|
||||||
|
|
||||||
|
if ($target === 'content_element') {
|
||||||
|
$report['mirror']['element_rows']++;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$where = ['art' => 'Zuordnung', 'zuordnung_id' => (int) $row->id, 'wert_id' => $valueId, 'wert' => $label, 'objektart' => $row->subject_type, 'objekt_id' => (int) $row->subject_id, 'herkunft' => $row->origin];
|
||||||
|
|
||||||
|
if ($target === null) {
|
||||||
|
$report['unresolved'][] = $where + ['grund' => 'unbekannte Objektart'];
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($row->origin !== 'direkt') {
|
||||||
|
$report['unresolved'][] = $where + ['grund' => 'abgeleitete Zuordnung (wird nicht als direkte übernommen)'];
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! isset($resolved[$valueId])) {
|
||||||
|
$report['unresolved'][] = $where + ['grund' => 'Wert ohne belastbare Säule'];
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = self::TARGETS[$target];
|
||||||
|
|
||||||
|
if (! DB::table($config['subjects'])->where('id', $row->subject_id)->exists()) {
|
||||||
|
$report['unresolved'][] = $where + ['grund' => 'Objekt nicht mehr vorhanden'];
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$present = DB::table($config['table'])->where($config['column'], $row->subject_id)->where('pillar_id', $resolved[$valueId])->exists();
|
||||||
|
|
||||||
|
if ($present) {
|
||||||
|
$report['already'][$target]++;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $dryRun) {
|
||||||
|
DB::table($config['table'])->insertOrIgnore([$config['column'] => $row->subject_id, 'pillar_id' => $resolved[$valueId]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$report['copied'][$target]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$report['mirror'] = array_merge($report['mirror'], $this->mirrorDivergence($dimension->id, $resolved));
|
||||||
|
$report['after'] = $dryRun ? $report['before'] : $this->counts();
|
||||||
|
|
||||||
|
return $report;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $report
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
public static function lines(array $report, bool $dryRun = false): array
|
||||||
|
{
|
||||||
|
$names = ['composition' => 'Module und Programme', 'license_article' => 'Lizenzartikel'];
|
||||||
|
$lines = [$dryRun ? 'Probelauf, es wird nichts geschrieben.' : 'Übernahme abgeschlossen.', ''];
|
||||||
|
|
||||||
|
foreach ($report['mapping'] as $row) {
|
||||||
|
$lines[] = sprintf('Wert %d „%s“ → %s%s', $row['wert_id'], $row['wert'], $row['saeule_id'] === null ? 'keine Säule (offen)' : 'Säule '.$row['saeule_id'].' „'.($row['saeule'] ?? '').'“ ('.$row['status'].')', ! empty($row['hinweis']) ? ' – '.$row['hinweis'] : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
$lines[] = '';
|
||||||
|
|
||||||
|
foreach ($names as $key => $label) {
|
||||||
|
$lines[] = sprintf('%s: %d übernommen, %d bereits vorhanden, Zuordnungen vorher %d, nachher %d', $label, $report['copied'][$key], $report['already'][$key], $report['before'][$key], $report['after'][$key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lines[] = sprintf('Medien (nur Information): %d gespiegelte Zeilen, %d nicht mehr in der Medienzuordnung, %d nur dort. Maßgeblich bleibt die Medienzuordnung.', $report['mirror']['element_rows'], $report['mirror']['missing_in_pivot'], $report['mirror']['only_in_pivot']);
|
||||||
|
|
||||||
|
if ($report['unresolved'] === []) {
|
||||||
|
$lines[] = 'Keine ungeklärten Fälle.';
|
||||||
|
} else {
|
||||||
|
$lines[] = '';
|
||||||
|
$lines[] = 'Ungeklärt, bitte entscheiden (nichts wurde geändert):';
|
||||||
|
|
||||||
|
foreach ($report['unresolved'] as $row) {
|
||||||
|
$lines[] = '- '.json_encode($row, JSON_UNESCAPED_UNICODE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Säule zu einem alten Wert, oder der Grund, warum es keine belastbare gibt.
|
||||||
|
*/
|
||||||
|
private function pillarFor(object $value): object|string
|
||||||
|
{
|
||||||
|
if (preg_match('/^pfeiler-(\d+)$/', (string) $value->slug, $match) !== 1) {
|
||||||
|
return 'Kennung ist nicht „pfeiler-<Nummer>“, keine belastbare Verknüpfung';
|
||||||
|
}
|
||||||
|
|
||||||
|
$pillar = DB::table('pillars')->where('id', (int) $match[1])->first();
|
||||||
|
|
||||||
|
if ($pillar === null) {
|
||||||
|
return 'Die Säule zur Kennung existiert nicht mehr';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value->pillar_id !== null && (int) $value->pillar_id !== (int) $pillar->id) {
|
||||||
|
return 'Gespeicherte Verknüpfung (Säule '.$value->pillar_id.') und Kennung (Säule '.$pillar->id.') widersprechen sich';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($pillar->created_at !== null && $value->created_at !== null && $pillar->created_at > $value->created_at) {
|
||||||
|
return 'Die Säule ist jünger als der Wert; die Kennung kann nicht aus ihr entstanden sein';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $pillar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string> Objektart wie gespeichert => Ziel
|
||||||
|
*/
|
||||||
|
private function subjectTypes(): array
|
||||||
|
{
|
||||||
|
$types = [];
|
||||||
|
|
||||||
|
foreach ([
|
||||||
|
'composition' => [Composition::class],
|
||||||
|
'license_article' => [LicenseArticle::class],
|
||||||
|
'content_element' => [ContentElement::class],
|
||||||
|
] as $target => $classes) {
|
||||||
|
foreach ($classes as $class) {
|
||||||
|
$types[$class] = $target;
|
||||||
|
$types[(new $class)->getMorphClass()] = $target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $types;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, int>
|
||||||
|
*/
|
||||||
|
private function counts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'composition' => DB::table('composition_pillar')->count(),
|
||||||
|
'license_article' => DB::table('license_article_pillar')->count(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, int> $resolved
|
||||||
|
* @return array{missing_in_pivot: int, only_in_pivot: int}
|
||||||
|
*/
|
||||||
|
private function mirrorDivergence(int $dimensionId, array $resolved): array
|
||||||
|
{
|
||||||
|
$mirrored = [];
|
||||||
|
|
||||||
|
foreach (DB::table('identity_dimension_values')
|
||||||
|
->whereIn('subject_type', array_unique([ContentElement::class, (new ContentElement)->getMorphClass()]))
|
||||||
|
->whereIn('editorial_dimension_value_id', array_keys($resolved) ?: [0])
|
||||||
|
->get() as $row) {
|
||||||
|
$mirrored[$row->subject_id.':'.$resolved[(int) $row->editorial_dimension_value_id]] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pivot = [];
|
||||||
|
|
||||||
|
foreach (DB::table('content_element_pillar')->get() as $row) {
|
||||||
|
$pivot[$row->content_element_id.':'.$row->pillar_id] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'missing_in_pivot' => count(array_diff_key($mirrored, $pivot)),
|
||||||
|
'only_in_pivot' => count(array_diff_key($pivot, $mirrored)),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,12 +4,20 @@
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
class LicenseArticle extends Model
|
class LicenseArticle extends Model
|
||||||
{
|
{
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'code',
|
'code',
|
||||||
|
'working_title',
|
||||||
|
'display_title',
|
||||||
|
'teaser',
|
||||||
|
'summary',
|
||||||
|
'description',
|
||||||
|
'search_terms',
|
||||||
|
'editorial_content_kind_id',
|
||||||
'product_line',
|
'product_line',
|
||||||
'successor_of_id',
|
'successor_of_id',
|
||||||
'current_release_id',
|
'current_release_id',
|
||||||
@@ -37,4 +45,15 @@ public function successorOf(): BelongsTo
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(self::class, 'successor_of_id');
|
return $this->belongsTo(self::class, 'successor_of_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function editorialContentKind(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(EditorialContentKind::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Direkt zugeordnete fachliche Säulen (zentrale Säulenverwaltung). */
|
||||||
|
public function pillars(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Pillar::class)->orderBy('pillars.sort_order')->orderBy('pillars.name');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,14 +3,29 @@
|
|||||||
namespace App\Domain\Catalog;
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
class Offer extends Model
|
class Offer extends Model
|
||||||
{
|
{
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
|
'composition_id',
|
||||||
|
'option_label',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** Komposition, deren öffentliche Seite die Produktseite dieser Lizenzoption ist. */
|
||||||
|
public function composition(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Composition::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Bezeichnung der Option auf der Produktseite. */
|
||||||
|
public function optionName(): string
|
||||||
|
{
|
||||||
|
return filled($this->option_label) ? (string) $this->option_label : (string) $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
public function versions(): HasMany
|
public function versions(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(OfferVersion::class);
|
return $this->hasMany(OfferVersion::class);
|
||||||
|
|||||||
@@ -22,6 +22,23 @@ public function currentActiveVersion(Offer $offer): OfferVersion
|
|||||||
return $version;
|
return $version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die aktive, als Kauf angebotene Fassung mit Preis; sonst null (nicht kaufbar, zurückgezogen oder kostenlos).
|
||||||
|
*/
|
||||||
|
public function purchasableVersion(Offer $offer): ?OfferVersion
|
||||||
|
{
|
||||||
|
$version = $offer->versions()
|
||||||
|
->where('status', OfferStatus::Aktiv)
|
||||||
|
->orderByDesc('number')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($version === null || $version->grant_kind !== 'kauf' || $version->price_cents === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $version;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, mixed> $capabilities
|
* @param array<string, mixed> $capabilities
|
||||||
* @param array<string, mixed> $options
|
* @param array<string, mixed> $options
|
||||||
@@ -138,6 +155,40 @@ public function activate(Offer $offer, array $lines, array $attributes = []): Of
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zieht die Option aus dem Verkauf zurück: Die aktive Fassung wird beendet und bleibt gespeichert. Bereits
|
||||||
|
* begründete Berechtigungen und Bestellungen ändern sich nicht; offene Warenkörbe zeigen die Position als
|
||||||
|
* zurückgezogen und blockieren den Abschluss, bis der Käufer sie entfernt.
|
||||||
|
*/
|
||||||
|
public function end(Offer $offer): OfferVersion
|
||||||
|
{
|
||||||
|
return DB::transaction(function () use ($offer): OfferVersion {
|
||||||
|
$offer = Offer::query()->lockForUpdate()->findOrFail($offer->id);
|
||||||
|
$version = $this->currentActiveVersion($offer);
|
||||||
|
$version->status = OfferStatus::Beendet;
|
||||||
|
$version->save();
|
||||||
|
|
||||||
|
return $version;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produktzuordnung der Option: Die Komposition bestimmt die öffentliche Produktseite und die Alternativgruppe,
|
||||||
|
* die Bezeichnung benennt die Option auf dieser Seite. Beides sind keine bindenden Konditionen.
|
||||||
|
*/
|
||||||
|
public function assignProduct(Offer $offer, ?int $compositionId, ?string $optionLabel): Offer
|
||||||
|
{
|
||||||
|
if ($compositionId !== null) {
|
||||||
|
Composition::query()->findOrFail($compositionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
$offer->composition_id = $compositionId;
|
||||||
|
$offer->option_label = filled($optionLabel) ? trim((string) $optionLabel) : null;
|
||||||
|
$offer->save();
|
||||||
|
|
||||||
|
return $offer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return list<int>
|
* @return list<int>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -34,6 +34,16 @@ public function pages(): BelongsToMany
|
|||||||
return $this->belongsToMany(Page::class);
|
return $this->belongsToMany(Page::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function compositions(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Composition::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function licenseArticles(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(LicenseArticle::class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Builder<Pillar> $query
|
* @param Builder<Pillar> $query
|
||||||
* @return Builder<Pillar>
|
* @return Builder<Pillar>
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alte Filteradressen: Vor der Vereinheitlichung war „Fachliche Säule“ ein Wert der redaktionellen Einordnung
|
||||||
|
* (`?einordnung=…`, `?pillar=…`, `dimension[]=…`). Verweist ein solcher Wert über `pillar_id` auf eine zentrale Säule,
|
||||||
|
* gilt der Filter jetzt für diese Säule, statt stillschweigend zu entfallen.
|
||||||
|
*/
|
||||||
|
final class PillarFilterCompat
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return int|null|false Kennung der Säule; null: alter Säulenwert ohne belastbare Verknüpfung; false: kein Säulenwert
|
||||||
|
*/
|
||||||
|
public static function pillarOfLegacyValue(int $valueId): int|false|null
|
||||||
|
{
|
||||||
|
$row = DB::table('editorial_dimension_values')
|
||||||
|
->join('editorial_dimensions', 'editorial_dimensions.id', '=', 'editorial_dimension_values.editorial_dimension_id')
|
||||||
|
->where('editorial_dimension_values.id', $valueId)
|
||||||
|
->where('editorial_dimensions.slug', EditorialDimension::PILLAR_SLUG)
|
||||||
|
->first(['editorial_dimension_values.pillar_id']);
|
||||||
|
|
||||||
|
if ($row === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $row->pillar_id === null ? null : (int) $row->pillar_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,19 +40,55 @@ public function present(Pillar $pillar, string $name, string $slug, ?string $sum
|
|||||||
|
|
||||||
public function delete(Pillar $pillar): void
|
public function delete(Pillar $pillar): void
|
||||||
{
|
{
|
||||||
if ($pillar->elements()->exists() || $pillar->pages()->exists()) {
|
$usage = $this->usage($pillar);
|
||||||
throw new DomainRuleException('Eine Säule mit zugeordneten Medien oder Seiten wird nicht gelöscht.');
|
|
||||||
|
if (array_sum($usage) > 0) {
|
||||||
|
throw new DomainRuleException('Eine Säule mit zugeordneten Objekten wird nicht gelöscht ('.$this->usageText($usage).'). Ordnen Sie sie zuerst anders zu.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$pillar->delete();
|
$pillar->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param list<int> $pillarIds
|
* Zuordnungen je Objektart: Medien, Module und Programme, Lizenzartikel, Seiten.
|
||||||
|
*
|
||||||
|
* @return array{medien: int, zusammenstellungen: int, lizenzartikel: int, seiten: int}
|
||||||
*/
|
*/
|
||||||
public function assign(ContentElement $element, array $pillarIds): void
|
public function usage(Pillar $pillar): array
|
||||||
{
|
{
|
||||||
$element->pillars()->sync($this->ids($pillarIds));
|
return [
|
||||||
|
'medien' => $pillar->elements()->count(),
|
||||||
|
'zusammenstellungen' => $pillar->compositions()->count(),
|
||||||
|
'lizenzartikel' => $pillar->licenseArticles()->count(),
|
||||||
|
'seiten' => $pillar->pages()->count(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array{medien: int, zusammenstellungen: int, lizenzartikel: int, seiten: int} $usage
|
||||||
|
*/
|
||||||
|
public function usageText(array $usage): string
|
||||||
|
{
|
||||||
|
$parts = [];
|
||||||
|
|
||||||
|
foreach (['medien' => ['Medium', 'Medien'], 'zusammenstellungen' => ['Modul oder Programm', 'Module und Programme'], 'lizenzartikel' => ['Lizenzartikel', 'Lizenzartikel'], 'seiten' => ['Seite', 'Seiten']] as $key => [$one, $many]) {
|
||||||
|
if ($usage[$key] > 0) {
|
||||||
|
$parts[] = $usage[$key].' '.($usage[$key] === 1 ? $one : $many);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $parts === [] ? 'nirgends zugeordnet' : implode(', ', $parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ordnet einem Medium, Modul, Programm, Lizenzartikel oder einer Seite Säulen zu. Alle Objektarten verwenden
|
||||||
|
* dieselbe zentrale Säule und dieselbe Speicherregel; die Zuordnung ersetzt die bisherige vollständig.
|
||||||
|
*
|
||||||
|
* @param list<int|string> $pillarIds
|
||||||
|
*/
|
||||||
|
public function assign(ContentElement|Composition|LicenseArticle|Page $subject, array $pillarIds): void
|
||||||
|
{
|
||||||
|
$subject->pillars()->sync($this->ids($pillarIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +96,7 @@ public function assign(ContentElement $element, array $pillarIds): void
|
|||||||
*/
|
*/
|
||||||
public function assignPages(Page $page, array $pillarIds): void
|
public function assignPages(Page $page, array $pillarIds): void
|
||||||
{
|
{
|
||||||
$page->pillars()->sync($this->ids($pillarIds));
|
$this->assign($page, $pillarIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
class PresentationAssignment extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'subject_type',
|
||||||
|
'subject_id',
|
||||||
|
'content_element_id',
|
||||||
|
'presentation_role_id',
|
||||||
|
'position',
|
||||||
|
'source_version_id',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function role(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(PresentationRole::class, 'presentation_role_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function element(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ContentElement::class, 'content_element_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sourceVersion(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ContentElementVersion::class, 'source_version_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,515 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use App\Domain\Media\ThumbnailRef;
|
||||||
|
use App\Domain\Media\WebsiteMedia;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Präsentationsmedien sind Referenzen auf Inhaltselemente.
|
||||||
|
* Die Rolle gehört zur Zuordnung. Eine Zuordnung gibt nichts frei und ändert keine Fassung.
|
||||||
|
*/
|
||||||
|
class PresentationMedia
|
||||||
|
{
|
||||||
|
public function __construct(private readonly WebsiteMedia $website) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array<string, mixed>>
|
||||||
|
*/
|
||||||
|
public function rows(Model $subject): array
|
||||||
|
{
|
||||||
|
$assignments = PresentationAssignment::query()
|
||||||
|
->with(['role', 'element.editorialContentKind', 'sourceVersion'])
|
||||||
|
->where('subject_type', $subject->getMorphClass())
|
||||||
|
->where('subject_id', $subject->getKey())
|
||||||
|
->orderBy('position')
|
||||||
|
->orderBy('id')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$rows = [];
|
||||||
|
|
||||||
|
foreach ($assignments as $assignment) {
|
||||||
|
$element = $assignment->element;
|
||||||
|
$released = $element instanceof ContentElement && $this->website->present($element) !== null;
|
||||||
|
$binding = $this->binding($assignment);
|
||||||
|
|
||||||
|
$rows[] = [
|
||||||
|
'id' => $assignment->id,
|
||||||
|
'role' => (string) $assignment->role?->slug,
|
||||||
|
'role_label' => (string) ($assignment->role?->label ?? ''),
|
||||||
|
'ordered' => (bool) $assignment->role?->ordered,
|
||||||
|
'position' => (int) $assignment->position,
|
||||||
|
'standard' => $assignment->role?->slug === 'titelbild',
|
||||||
|
'element_id' => (int) $assignment->content_element_id,
|
||||||
|
'title' => $element instanceof ContentElement
|
||||||
|
? (string) ($element->display_title ?: $element->working_title)
|
||||||
|
: 'Medium fehlt',
|
||||||
|
'image' => $element instanceof ContentElement
|
||||||
|
? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path)
|
||||||
|
: null,
|
||||||
|
'kind' => $element?->editorialContentKind?->label,
|
||||||
|
'output' => $element instanceof ContentElement ? (string) $element->output_class : '',
|
||||||
|
'released' => $released,
|
||||||
|
'release_label' => $released ? 'Für die Website freigegeben' : 'Nicht für die Website freigegeben',
|
||||||
|
'binding' => $binding,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gespeicherte Zuordnungen als bearbeitbarer Arbeitsstand, nach Rolle und Position geordnet.
|
||||||
|
*
|
||||||
|
* @return list<array{key: string, id: int|null, role: string, element_id: int, source: int|null}>
|
||||||
|
*/
|
||||||
|
public function staged(Model $subject): array
|
||||||
|
{
|
||||||
|
$assignments = PresentationAssignment::query()
|
||||||
|
->with('role')
|
||||||
|
->where('subject_type', $subject->getMorphClass())
|
||||||
|
->where('subject_id', $subject->getKey())
|
||||||
|
->get()
|
||||||
|
->sortBy(fn (PresentationAssignment $row): string => sprintf('%05d-%05d-%08d', (int) $row->role?->sort_order, (int) $row->position, (int) $row->id))
|
||||||
|
->values();
|
||||||
|
|
||||||
|
$rows = [];
|
||||||
|
|
||||||
|
foreach ($assignments as $assignment) {
|
||||||
|
$rows[] = [
|
||||||
|
'key' => 'a'.$assignment->id,
|
||||||
|
'id' => (int) $assignment->id,
|
||||||
|
'role' => (string) $assignment->role?->slug,
|
||||||
|
'element_id' => (int) $assignment->content_element_id,
|
||||||
|
'source' => $assignment->source_version_id !== null ? (int) $assignment->source_version_id : null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anzeigezeilen für einen Arbeitsstand, gruppiert nach Rolle. Liest nur, schreibt nichts.
|
||||||
|
*
|
||||||
|
* @param list<array{key: string, id: int|null, role: string, element_id: int, source: int|null}> $staged
|
||||||
|
* @return list<array{role: string, label: string, multiple: bool, ordered: bool, rows: list<array<string, mixed>>}>
|
||||||
|
*/
|
||||||
|
public function describe(array $staged): array
|
||||||
|
{
|
||||||
|
$roles = PresentationRole::query()->orderBy('sort_order')->get()->keyBy('slug');
|
||||||
|
$elements = ContentElement::query()
|
||||||
|
->with('editorialContentKind')
|
||||||
|
->whereIn('id', array_values(array_unique(array_map(fn (array $row): int => (int) $row['element_id'], $staged))))
|
||||||
|
->get()
|
||||||
|
->keyBy('id');
|
||||||
|
$sources = ContentElementVersion::query()
|
||||||
|
->whereIn('id', array_values(array_filter(array_map(fn (array $row): ?int => $row['source'] ?? null, $staged))))
|
||||||
|
->get()
|
||||||
|
->keyBy('id');
|
||||||
|
$groups = [];
|
||||||
|
|
||||||
|
foreach ($roles as $slug => $role) {
|
||||||
|
$rows = array_values(array_filter($staged, fn (array $row): bool => $row['role'] === $slug));
|
||||||
|
|
||||||
|
if ($rows === []) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$described = [];
|
||||||
|
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$element = $elements->get((int) $row['element_id']);
|
||||||
|
$released = $element instanceof ContentElement && $this->website->present($element) !== null;
|
||||||
|
$source = $row['source'] !== null ? $sources->get((int) $row['source']) : null;
|
||||||
|
|
||||||
|
$described[] = [
|
||||||
|
'key' => $row['key'],
|
||||||
|
'id' => $row['id'],
|
||||||
|
'element_id' => (int) $row['element_id'],
|
||||||
|
'title' => $element instanceof ContentElement
|
||||||
|
? (string) ($element->display_title ?: $element->working_title)
|
||||||
|
: 'Medium fehlt',
|
||||||
|
'image' => $element instanceof ContentElement
|
||||||
|
? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path)
|
||||||
|
: null,
|
||||||
|
'kind' => $element?->editorialContentKind?->label,
|
||||||
|
'output' => $element instanceof ContentElement ? (string) $element->output_class : '',
|
||||||
|
'released' => $released,
|
||||||
|
'release_label' => $released ? 'Für die Website freigegeben' : 'Nicht für die Website freigegeben',
|
||||||
|
'binding' => $source instanceof ContentElementVersion ? $this->bindingFor($source) : null,
|
||||||
|
'new' => $row['id'] === null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$groups[] = [
|
||||||
|
'role' => (string) $slug,
|
||||||
|
'label' => PresentationRole::displayLabel((string) $slug, (string) $role->label),
|
||||||
|
'multiple' => (bool) $role->multiple,
|
||||||
|
'ordered' => (bool) $role->ordered,
|
||||||
|
'rows' => $described,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prüft, ob ein Medium im Arbeitsstand einer Rolle zugeordnet werden darf. Liefert den Ablehnungsgrund oder null.
|
||||||
|
*/
|
||||||
|
public function refusal(Model $subject, string $roleSlug, int $elementId): ?string
|
||||||
|
{
|
||||||
|
$role = PresentationRole::query()->where('slug', $roleSlug)->first();
|
||||||
|
$element = ContentElement::query()->find($elementId);
|
||||||
|
|
||||||
|
if (! $role instanceof PresentationRole || ! $element instanceof ContentElement) {
|
||||||
|
return 'Rolle oder Medium fehlt.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($element->archived_at !== null) {
|
||||||
|
return 'Ein archiviertes Medium wird nicht zugeordnet.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($subject instanceof ContentElement && (int) $subject->getKey() === (int) $element->id) {
|
||||||
|
return 'Ein Medium kann nicht seine eigene Präsentation sein.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schreibt einen Arbeitsstand: entfernte Zuordnungen lösen, neue anlegen, Bindung und Reihenfolge je Rolle setzen.
|
||||||
|
* Medien, Fassungen und Website-Freigaben bleiben unberührt.
|
||||||
|
*
|
||||||
|
* Mit $baseline (dem beim Laden gelesenen Stand) werden nur Zuordnungen gelöst, die dort standen und im
|
||||||
|
* Arbeitsstand fehlen. Was inzwischen an anderer Stelle hinzugekommen ist, bleibt erhalten.
|
||||||
|
*
|
||||||
|
* @param list<array{key: string, id: int|null, role: string, element_id: int, source: int|null}> $staged
|
||||||
|
* @param list<array{key: string, id: int|null, role: string, element_id: int, source: int|null}>|null $baseline
|
||||||
|
*/
|
||||||
|
public function commit(Model $subject, array $staged, ?User $actor = null, ?array $baseline = null): void
|
||||||
|
{
|
||||||
|
$roles = PresentationRole::query()->get()->keyBy('slug');
|
||||||
|
$seen = [];
|
||||||
|
|
||||||
|
foreach ($staged as $row) {
|
||||||
|
$role = $roles->get($row['role']);
|
||||||
|
|
||||||
|
if (! $role instanceof PresentationRole) {
|
||||||
|
throw new DomainRuleException('Diese Rolle gibt es nicht.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$refusal = $this->refusal($subject, $row['role'], (int) $row['element_id']);
|
||||||
|
|
||||||
|
if ($refusal !== null) {
|
||||||
|
throw new DomainRuleException($refusal);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pair = $row['role'].':'.$row['element_id'];
|
||||||
|
|
||||||
|
if (isset($seen[$pair])) {
|
||||||
|
throw new DomainRuleException('Ein Medium steht in derselben Rolle nur einmal.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$seen[$pair] = true;
|
||||||
|
$count = count(array_filter($staged, fn (array $other): bool => $other['role'] === $row['role']));
|
||||||
|
|
||||||
|
if (! $role->multiple && $count > 1) {
|
||||||
|
throw new DomainRuleException($role->label.' hat nur eine Zuordnung.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$element = ContentElement::query()->findOrFail((int) $row['element_id']);
|
||||||
|
$this->checkedSource($subject, $element, $row['source']);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::transaction(function () use ($subject, $staged, $roles, $actor, $baseline): void {
|
||||||
|
$existing = PresentationAssignment::query()
|
||||||
|
->with(['role', 'element'])
|
||||||
|
->where('subject_type', $subject->getMorphClass())
|
||||||
|
->where('subject_id', $subject->getKey())
|
||||||
|
->get()
|
||||||
|
->keyBy('id');
|
||||||
|
$kept = array_filter(array_map(fn (array $row): ?int => $row['id'], $staged));
|
||||||
|
$known = $baseline === null ? null : array_filter(array_map(fn (array $row): ?int => $row['id'], $baseline));
|
||||||
|
|
||||||
|
foreach ($existing as $id => $assignment) {
|
||||||
|
$wasLoaded = $known === null || in_array((int) $id, $known, true);
|
||||||
|
$replacedSingle = ! (bool) $assignment->role?->multiple
|
||||||
|
&& ! in_array((int) $id, $kept, true)
|
||||||
|
&& array_filter($staged, fn (array $row): bool => $row['role'] === $assignment->role?->slug) !== [];
|
||||||
|
|
||||||
|
if (! in_array((int) $id, $kept, true) && ($wasLoaded || $replacedSingle)) {
|
||||||
|
$this->record($subject, ($assignment->role?->label ?? 'Präsentation').': '.($assignment->element?->working_title ?? ''), null, $actor);
|
||||||
|
$assignment->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$positions = [];
|
||||||
|
|
||||||
|
foreach ($staged as $row) {
|
||||||
|
$role = $roles->get($row['role']);
|
||||||
|
$position = $positions[$row['role']] = ($positions[$row['role']] ?? 0) + 1;
|
||||||
|
$assignment = $row['id'] !== null ? $existing->get($row['id']) : null;
|
||||||
|
|
||||||
|
if ($assignment instanceof PresentationAssignment) {
|
||||||
|
$changed = (int) $assignment->position !== $position
|
||||||
|
|| (int) ($assignment->source_version_id ?? 0) !== (int) ($row['source'] ?? 0);
|
||||||
|
$assignment->position = $position;
|
||||||
|
$assignment->source_version_id = $row['source'];
|
||||||
|
|
||||||
|
if ($changed) {
|
||||||
|
$assignment->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$element = ContentElement::query()->findOrFail((int) $row['element_id']);
|
||||||
|
$same = PresentationAssignment::query()
|
||||||
|
->where('subject_type', $subject->getMorphClass())
|
||||||
|
->where('subject_id', $subject->getKey())
|
||||||
|
->where('presentation_role_id', $role->id)
|
||||||
|
->where('content_element_id', $element->id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($same instanceof PresentationAssignment) {
|
||||||
|
$same->position = $position;
|
||||||
|
$same->source_version_id = $row['source'];
|
||||||
|
$same->save();
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
PresentationAssignment::query()->create([
|
||||||
|
'subject_type' => $subject->getMorphClass(),
|
||||||
|
'subject_id' => $subject->getKey(),
|
||||||
|
'content_element_id' => $element->id,
|
||||||
|
'presentation_role_id' => $role->id,
|
||||||
|
'position' => $position,
|
||||||
|
'source_version_id' => $row['source'],
|
||||||
|
]);
|
||||||
|
$this->record($subject, null, $role->label.': '.$element->working_title, $actor);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function assign(Model $subject, string $roleSlug, int $elementId, ?int $sourceVersionId, ?User $actor = null): string
|
||||||
|
{
|
||||||
|
$role = PresentationRole::query()->where('slug', $roleSlug)->first();
|
||||||
|
$element = ContentElement::query()->find($elementId);
|
||||||
|
|
||||||
|
if (! $role instanceof PresentationRole || ! $element instanceof ContentElement) {
|
||||||
|
throw new DomainRuleException('Rolle oder Medium fehlt.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($element->archived_at !== null) {
|
||||||
|
throw new DomainRuleException('Ein archiviertes Medium wird nicht zugeordnet.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($subject instanceof ContentElement && (int) $subject->getKey() === (int) $element->id) {
|
||||||
|
throw new DomainRuleException('Ein Medium kann nicht seine eigene Präsentation sein.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$source = $this->checkedSource($subject, $element, $sourceVersionId);
|
||||||
|
|
||||||
|
$existing = PresentationAssignment::query()
|
||||||
|
->where('subject_type', $subject->getMorphClass())
|
||||||
|
->where('subject_id', $subject->getKey())
|
||||||
|
->where('presentation_role_id', $role->id)
|
||||||
|
->where('content_element_id', $element->id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($existing instanceof PresentationAssignment) {
|
||||||
|
if ((int) $existing->source_version_id !== (int) ($source?->id ?? 0) && ($source !== null || $existing->source_version_id !== null)) {
|
||||||
|
$existing->source_version_id = $source?->id;
|
||||||
|
$existing->save();
|
||||||
|
$this->record($subject, null, $role->label.': '.$element->working_title, $actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $element->working_title.' ist in dieser Rolle bereits zugeordnet.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $role->multiple) {
|
||||||
|
PresentationAssignment::query()
|
||||||
|
->where('subject_type', $subject->getMorphClass())
|
||||||
|
->where('subject_id', $subject->getKey())
|
||||||
|
->where('presentation_role_id', $role->id)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
$position = (int) PresentationAssignment::query()
|
||||||
|
->where('subject_type', $subject->getMorphClass())
|
||||||
|
->where('subject_id', $subject->getKey())
|
||||||
|
->where('presentation_role_id', $role->id)
|
||||||
|
->max('position') + 1;
|
||||||
|
|
||||||
|
PresentationAssignment::query()->create([
|
||||||
|
'subject_type' => $subject->getMorphClass(),
|
||||||
|
'subject_id' => $subject->getKey(),
|
||||||
|
'content_element_id' => $element->id,
|
||||||
|
'presentation_role_id' => $role->id,
|
||||||
|
'position' => max(1, $position),
|
||||||
|
'source_version_id' => $source?->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->record($subject, null, $role->label.': '.$element->working_title, $actor);
|
||||||
|
|
||||||
|
return $element->working_title.' ist als '.$role->label.' zugeordnet. Es entsteht keine Fassung und keine Freigabe.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function detach(Model $subject, int $assignmentId, ?User $actor = null): string
|
||||||
|
{
|
||||||
|
$assignment = $this->owned($subject, $assignmentId);
|
||||||
|
$label = ($assignment->role?->label ?? 'Präsentation').': '.($assignment->element?->working_title ?? '');
|
||||||
|
$assignment->delete();
|
||||||
|
$this->record($subject, $label, null, $actor);
|
||||||
|
|
||||||
|
return 'Die Zuordnung ist entfernt. Das Medium bleibt im Bestand.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function move(Model $subject, int $assignmentId, int $direction, ?User $actor = null): void
|
||||||
|
{
|
||||||
|
$assignment = $this->owned($subject, $assignmentId);
|
||||||
|
|
||||||
|
if (! $assignment->role?->ordered || $direction === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$neighbors = PresentationAssignment::query()
|
||||||
|
->where('subject_type', $subject->getMorphClass())
|
||||||
|
->where('subject_id', $subject->getKey())
|
||||||
|
->where('presentation_role_id', $assignment->presentation_role_id)
|
||||||
|
->orderBy('position')
|
||||||
|
->orderBy('id')
|
||||||
|
->get()
|
||||||
|
->values();
|
||||||
|
|
||||||
|
$index = $neighbors->search(fn (PresentationAssignment $row): bool => $row->id === $assignment->id);
|
||||||
|
|
||||||
|
if ($index === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$swap = $index + ($direction < 0 ? -1 : 1);
|
||||||
|
$other = $neighbors->get($swap);
|
||||||
|
|
||||||
|
if (! $other instanceof PresentationAssignment) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$position = $assignment->position;
|
||||||
|
$assignment->position = $other->position === $position ? $position + ($direction < 0 ? -1 : 1) : $other->position;
|
||||||
|
$other->position = $position;
|
||||||
|
$assignment->save();
|
||||||
|
$other->save();
|
||||||
|
$this->record($subject, null, 'Reihenfolge '.$assignment->role?->label, $actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kennung des ersten Titel- oder Galeriebildes. Ob es öffentlich erscheint, entscheidet WebsiteMedia.
|
||||||
|
*/
|
||||||
|
public function coverElementId(Model $subject): ?int
|
||||||
|
{
|
||||||
|
$assignments = PresentationAssignment::query()
|
||||||
|
->with('role')
|
||||||
|
->where('subject_type', $subject->getMorphClass())
|
||||||
|
->where('subject_id', $subject->getKey())
|
||||||
|
->orderBy('position')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
foreach (PresentationRole::COVER_ROLES as $slug) {
|
||||||
|
$match = $assignments->first(fn (PresentationAssignment $row): bool => $row->role?->slug === $slug);
|
||||||
|
|
||||||
|
if ($match instanceof PresentationAssignment) {
|
||||||
|
return (int) $match->content_element_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function owned(Model $subject, int $assignmentId): PresentationAssignment
|
||||||
|
{
|
||||||
|
$assignment = PresentationAssignment::query()
|
||||||
|
->with(['role', 'element'])
|
||||||
|
->where('subject_type', $subject->getMorphClass())
|
||||||
|
->where('subject_id', $subject->getKey())
|
||||||
|
->whereKey($assignmentId)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $assignment instanceof PresentationAssignment) {
|
||||||
|
throw new DomainRuleException('Diese Zuordnung gehört zu einem anderen Objekt.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $assignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function checkedSource(Model $subject, ContentElement $element, ?int $sourceVersionId): ?ContentElementVersion
|
||||||
|
{
|
||||||
|
if ($sourceVersionId === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = ContentElementVersion::query()->find($sourceVersionId);
|
||||||
|
|
||||||
|
if (! $version instanceof ContentElementVersion) {
|
||||||
|
throw new DomainRuleException('Die gebundene Fassung fehlt.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$ownsFilm = $subject instanceof ContentElement && (int) $version->content_element_id === (int) $subject->getKey();
|
||||||
|
$ownsClip = (int) $version->content_element_id === (int) $element->id;
|
||||||
|
|
||||||
|
if (! $ownsFilm && ! $ownsClip) {
|
||||||
|
throw new DomainRuleException('Die gebundene Fassung gehört weder zum Fachobjekt noch zum zugeordneten Medium.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $version;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{label: string, stale: bool}|null
|
||||||
|
*/
|
||||||
|
private function binding(PresentationAssignment $assignment): ?array
|
||||||
|
{
|
||||||
|
if ($assignment->source_version_id === null || ! $assignment->sourceVersion instanceof ContentElementVersion) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->bindingFor($assignment->sourceVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{label: string, stale: bool}
|
||||||
|
*/
|
||||||
|
private function bindingFor(ContentElementVersion $version): array
|
||||||
|
{
|
||||||
|
$latestId = ContentElementVersion::query()
|
||||||
|
->where('content_element_id', $version->content_element_id)
|
||||||
|
->where('status', ContentVersionStatus::Bereit)
|
||||||
|
->orderByDesc('number')
|
||||||
|
->value('id');
|
||||||
|
$stale = $latestId !== null && (int) $latestId !== (int) $version->id;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'label' => $stale
|
||||||
|
? 'Gebunden an Fassung '.$version->number.'. Die aktuelle Fassung ist eine andere. Der Clip wurde nicht neu erzeugt.'
|
||||||
|
: 'Gebunden an Fassung '.$version->number.'.',
|
||||||
|
'stale' => $stale,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function record(Model $subject, ?string $before, ?string $after, ?User $actor): void
|
||||||
|
{
|
||||||
|
IdentityChange::query()->create([
|
||||||
|
'subject_type' => $subject->getMorphClass(),
|
||||||
|
'subject_id' => $subject->getKey(),
|
||||||
|
'field' => 'praesentation',
|
||||||
|
'before' => $before,
|
||||||
|
'after' => $after,
|
||||||
|
'actor_id' => $actor?->id,
|
||||||
|
'occurred_at' => now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
class PresentationRole extends Model
|
||||||
|
{
|
||||||
|
/** Rollen, deren Herkunft an einer Film- oder Audiofassung festgehalten werden kann. */
|
||||||
|
public const BOUND_ROLES = ['trailer', 'vorschauclip', 'audiovorschau'];
|
||||||
|
|
||||||
|
/** Reihenfolge, in der ein öffentliches Titelbild gesucht wird. */
|
||||||
|
public const COVER_ROLES = ['titelbild', 'hero', 'hover', 'titelbild_alternativ', 'galerie'];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'slug',
|
||||||
|
'label',
|
||||||
|
'multiple',
|
||||||
|
'ordered',
|
||||||
|
'sort_order',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'multiple' => 'boolean',
|
||||||
|
'ordered' => 'boolean',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function assignments(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(PresentationAssignment::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public static function selectOptions(): array
|
||||||
|
{
|
||||||
|
return static::query()->orderBy('sort_order')->pluck('label', 'slug')->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kurze Bezeichnung für Überschriften und Auswahl in der Verwaltung.
|
||||||
|
*/
|
||||||
|
public static function displayLabel(string $slug, string $label): string
|
||||||
|
{
|
||||||
|
return match ($slug) {
|
||||||
|
'titelbild' => 'Titelbild',
|
||||||
|
'titelbild_alternativ' => 'Alternative Titelbilder',
|
||||||
|
'trailer' => 'Trailer',
|
||||||
|
'vorschauclip' => 'Vorschauclips',
|
||||||
|
'interview' => 'Interviews',
|
||||||
|
'galerie' => 'Galerie',
|
||||||
|
default => $label,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ein aufgelöster redaktioneller Text. Der Wert wird nicht kopiert:
|
||||||
|
* eigen steht am Fachobjekt, variante ist eine Abweichung für einen Kontext,
|
||||||
|
* quelle verweist auf das eindeutig zugeordnete Fachobjekt eines Lizenzartikels.
|
||||||
|
*/
|
||||||
|
final readonly class ResolvedText
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public ?string $value,
|
||||||
|
public string $origin,
|
||||||
|
public ?string $label,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Cms\Catalog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anzeigedaten des Fachobjekts hinter einer Premium-Karte (Thema, Medium/Material, Programm/Modul).
|
||||||
|
* Wird zur Laufzeit aus den maßgeblichen Fachdaten gelesen und nie im CMS gespeichert.
|
||||||
|
*
|
||||||
|
* - url: nur ein öffentlich freigegebenes Ziel aus dem Fachobjekt (Themenseite, Programmseite), sonst null.
|
||||||
|
* - public: false heißt „nur in der Redaktionsvorschau“; öffentlich entfällt die Karte dann.
|
||||||
|
* - notice: redaktioneller Hinweis für die Vorschau, warum die Karte öffentlich nicht erscheint.
|
||||||
|
* - visual: Darstellung ohne Kartenbild: 'film' (Medientafel Film), 'material' (Materialsymbol),
|
||||||
|
* 'catalog' (Navy-Tafel Programm/Modul) oder null (Karte ohne Bildbereich).
|
||||||
|
* - previewImage: geschütztes Vorschaubild der Bibliothek (Filmstandbild, Vorschau des Moduls). Nur für die
|
||||||
|
* Redaktionsvorschau (Route editorial.card, nur für angemeldete Redaktion); öffentlich nie ausgegeben, weil es
|
||||||
|
* keine Freigabe für die Website hat.
|
||||||
|
* - missing: was für eine vollständige Karte fehlt, als Hinweis nur in der Redaktionsvorschau.
|
||||||
|
* - texts: die zentralen Texte des Fachobjekts, aus denen die Karte einen wählen kann (teaser, summary, description).
|
||||||
|
* summary bleibt der Text der Vorgabe („Automatisch“); texts wird nur gelesen, wenn die Redaktion einen wählt.
|
||||||
|
*/
|
||||||
|
final readonly class CardSubject
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param list<string> $meta reine Anzeigetexte aus Fachdaten
|
||||||
|
* @param list<string> $missing Hinweise für die Redaktion
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public string $title,
|
||||||
|
public ?string $summary,
|
||||||
|
public string $kind,
|
||||||
|
public ?string $badge,
|
||||||
|
public array $meta,
|
||||||
|
public ?string $url,
|
||||||
|
public bool $public,
|
||||||
|
public ?string $notice = null,
|
||||||
|
public ?string $visual = null,
|
||||||
|
public ?string $visualLabel = null,
|
||||||
|
public ?string $previewImage = null,
|
||||||
|
public array $missing = [],
|
||||||
|
public ?string $style = null,
|
||||||
|
public array $texts = [],
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function withText(?string $title, ?string $summary): self
|
||||||
|
{
|
||||||
|
return $this->copy(['title' => $title ?? $this->title, 'summary' => $summary ?? $this->summary]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text der Karte aus einem zentralen Text des Fachobjekts. Ist er nicht gepflegt, bleibt die Karte ohne Text
|
||||||
|
* (kein stiller Ersatz aus einem anderen Feld); in der Redaktionsvorschau steht dann ein Hinweis.
|
||||||
|
*/
|
||||||
|
public function withTextChoice(string $field, string $missingHint): self
|
||||||
|
{
|
||||||
|
if (! array_key_exists($field, $this->texts)) {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
$text = $this->texts[$field];
|
||||||
|
$missing = array_values(array_filter($this->missing, fn (string $hint): bool => ! str_contains($hint, 'Kurzbeschreibung')));
|
||||||
|
|
||||||
|
if ($text === null) {
|
||||||
|
$missing[] = $missingHint;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->copy(['summary' => $text, 'missing' => $missing]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $changes
|
||||||
|
*/
|
||||||
|
private function copy(array $changes): self
|
||||||
|
{
|
||||||
|
return new self(...array_merge(get_object_vars($this), $changes));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,10 @@
|
|||||||
use App\Domain\Catalog\Composition;
|
use App\Domain\Catalog\Composition;
|
||||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||||
use App\Domain\Catalog\CompositionVersion;
|
use App\Domain\Catalog\CompositionVersion;
|
||||||
|
use App\Domain\Catalog\ContentVersionStatus;
|
||||||
use App\Domain\Catalog\EditorialContentKind;
|
use App\Domain\Catalog\EditorialContentKind;
|
||||||
|
use App\Domain\Catalog\EditorialProfileReader;
|
||||||
|
use App\Domain\Media\ThumbnailRef;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,7 +96,9 @@ public function search(?string $term, int $limit = 25): array
|
|||||||
$like = '%'.mb_strtolower($term).'%';
|
$like = '%'.mb_strtolower($term).'%';
|
||||||
$query->where(fn ($inner) => $inner
|
$query->where(fn ($inner) => $inner
|
||||||
->whereRaw('LOWER(designation) LIKE ?', [$like])
|
->whereRaw('LOWER(designation) LIKE ?', [$like])
|
||||||
->orWhereRaw('LOWER(COALESCE(display_title, \'\')) LIKE ?', [$like]));
|
->orWhereRaw('LOWER(COALESCE(display_title, \'\')) LIKE ?', [$like])
|
||||||
|
->orWhereRaw('LOWER(COALESCE(teaser, \'\')) LIKE ?', [$like])
|
||||||
|
->orWhereRaw('LOWER(COALESCE(search_terms, \'\')) LIKE ?', [$like]));
|
||||||
})
|
})
|
||||||
->orderBy('designation')
|
->orderBy('designation')
|
||||||
->limit($limit * 3)
|
->limit($limit * 3)
|
||||||
@@ -171,6 +176,173 @@ public function entries(array $refs, bool $includeNonPublic): array
|
|||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Für die Programm- oder Modulkarte wählbar: Programm oder Modul, nicht archiviert, mit mindestens einer
|
||||||
|
* bereitgestellten Fassung. Anders als bei den Katalogkarten ist keine Anzeigefreigabe nötig, damit die Redaktion
|
||||||
|
* eine Karte vorbereiten kann; öffentlich gilt unverändert isPublic().
|
||||||
|
*/
|
||||||
|
public function isCardSelectable(Composition $composition): bool
|
||||||
|
{
|
||||||
|
return $composition->archived_at === null
|
||||||
|
&& in_array($composition->editorialContentKind?->slug, self::SELECTABLE_KINDS, true)
|
||||||
|
&& $this->latestReadyVersion($composition) !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, string>
|
||||||
|
*/
|
||||||
|
public function cardSearch(?string $term, int $limit = 25): array
|
||||||
|
{
|
||||||
|
$term = trim((string) $term);
|
||||||
|
|
||||||
|
$candidates = Composition::query()
|
||||||
|
->with('editorialContentKind')
|
||||||
|
->whereNull('archived_at')
|
||||||
|
->whereHas('editorialContentKind', fn ($query) => $query->whereIn('slug', self::SELECTABLE_KINDS))
|
||||||
|
->when($term !== '', function ($query) use ($term): void {
|
||||||
|
$like = '%'.mb_strtolower($term).'%';
|
||||||
|
$query->where(fn ($inner) => $inner
|
||||||
|
->whereRaw('LOWER(designation) LIKE ?', [$like])
|
||||||
|
->orWhereRaw('LOWER(COALESCE(display_title, \'\')) LIKE ?', [$like])
|
||||||
|
->orWhereRaw('LOWER(COALESCE(teaser, \'\')) LIKE ?', [$like])
|
||||||
|
->orWhereRaw('LOWER(COALESCE(search_terms, \'\')) LIKE ?', [$like]));
|
||||||
|
})
|
||||||
|
->orderBy('designation')
|
||||||
|
->limit($limit * 3)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$options = [];
|
||||||
|
foreach ($candidates as $composition) {
|
||||||
|
if (! $this->isCardSelectable($composition)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$options[$composition->id] = $this->cardOptionLabel($composition);
|
||||||
|
|
||||||
|
if (count($options) >= $limit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cardLabelFor(mixed $id): ?string
|
||||||
|
{
|
||||||
|
$composition = is_numeric($id) ? Composition::query()->with('editorialContentKind')->find((int) $id) : null;
|
||||||
|
|
||||||
|
return $composition === null ? null : $this->cardOptionLabel($composition);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anzeigedaten für eine Programm- oder Modulkarte (Premium-Karte).
|
||||||
|
*
|
||||||
|
* - Öffentlich nur Programme mit Anzeigefreigabe (dieselbe Regel wie /programme), mit Programmseite als Ziel.
|
||||||
|
* Module haben keine öffentliche Seitenart (ADR-29) und erscheinen nur in der Redaktionsvorschau, ohne Link.
|
||||||
|
* - Text: Kurzbeschreibung, sonst das Lernziel der gezeigten (öffentlich) bzw. neuesten bereitgestellten Fassung;
|
||||||
|
* das Lernziel steht auf der öffentlichen Programmseite bereits öffentlich.
|
||||||
|
* - Zusatzangaben: Zahl der Module, Dauer. Kein Preis, kein Angebot, keine Kaufaktion; eine Karte ist kein
|
||||||
|
* Lizenzartikel. Das Vorschaubild der Bibliothek erscheint nur in der Redaktionsvorschau.
|
||||||
|
*/
|
||||||
|
public function subject(mixed $id, bool $includeNonPublic): ?CardSubject
|
||||||
|
{
|
||||||
|
$composition = is_numeric($id) ? Composition::query()->with('editorialContentKind')->find((int) $id) : null;
|
||||||
|
|
||||||
|
if ($composition === null || ! $this->isCardSelectable($composition)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$shown = $this->shownVersion($composition);
|
||||||
|
$public = $shown !== null && $composition->archived_at === null;
|
||||||
|
|
||||||
|
if (! $public && ! $includeNonPublic) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = $shown ?? $this->latestReadyVersion($composition);
|
||||||
|
$program = $composition->editorialContentKind?->slug === 'programm';
|
||||||
|
$kind = (string) ($composition->editorialContentKind?->label ?? ($program ? 'Programm' : 'Modul'));
|
||||||
|
$profile = app(EditorialProfileReader::class)->read($composition, 'kachel');
|
||||||
|
$summary = $profile->value('teaser') ?: $profile->value('summary');
|
||||||
|
$goal = filled($version?->learning_goal) ? trim((string) $version->learning_goal) : null;
|
||||||
|
// Zentrale Texte, aus denen die Redaktion den Kartentext wählen kann (Zielgruppe „Öffentliche Kachel“).
|
||||||
|
$texts = [
|
||||||
|
'teaser' => $profile->value('teaser'),
|
||||||
|
'summary' => $profile->value('summary'),
|
||||||
|
'description' => $profile->value('description'),
|
||||||
|
'goal' => $goal,
|
||||||
|
];
|
||||||
|
$missing = [];
|
||||||
|
|
||||||
|
if ($summary === null) {
|
||||||
|
$missing[] = $goal !== null
|
||||||
|
? 'Keine Kurzbeschreibung gepflegt; die Karte zeigt das Lernziel.'
|
||||||
|
: 'Weder Kurzbeschreibung noch Lernziel gepflegt.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$meta = [];
|
||||||
|
if ($version !== null) {
|
||||||
|
$modules = $version->members()
|
||||||
|
->whereNotNull('nested_composition_version_id')
|
||||||
|
->with('nestedCompositionVersion.composition.editorialContentKind')
|
||||||
|
->get()
|
||||||
|
->filter(fn ($member): bool => $member->nestedCompositionVersion?->composition?->editorialContentKind?->slug === 'modul')
|
||||||
|
->count();
|
||||||
|
|
||||||
|
if ($program && $modules > 0) {
|
||||||
|
$meta[] = $modules === 1 ? '1 Modul' : $modules.' Module';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_numeric($version->duration_minutes) && (int) $version->duration_minutes > 0) {
|
||||||
|
$meta[] = 'Dauer '.(int) $version->duration_minutes.' Min.';
|
||||||
|
} else {
|
||||||
|
$missing[] = 'Keine Dauer gepflegt.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$notice = null;
|
||||||
|
if (! $public) {
|
||||||
|
$notice = 'Nur in der Redaktionsvorschau sichtbar: '.($program
|
||||||
|
? 'Das Programm hat keine Anzeigefreigabe.'
|
||||||
|
: 'Für Module gibt es noch keine öffentliche Seitenart (öffentliches Profil, ADR-29); die Karte erhält deshalb keinen Link.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CardSubject(
|
||||||
|
title: $profile->value('display_title') ?: $this->title($composition),
|
||||||
|
summary: $summary ?? $goal,
|
||||||
|
kind: $kind,
|
||||||
|
badge: null,
|
||||||
|
meta: $meta,
|
||||||
|
url: $public ? route('public.program', $composition) : null,
|
||||||
|
public: $public,
|
||||||
|
notice: $notice,
|
||||||
|
visual: 'catalog',
|
||||||
|
visualLabel: $kind,
|
||||||
|
previewImage: $includeNonPublic ? ThumbnailRef::url('editorial.card', 'komposition', (int) $composition->id, $composition->thumbnail_path) : null,
|
||||||
|
missing: $missing,
|
||||||
|
texts: $texts,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function latestReadyVersion(Composition $composition): ?CompositionVersion
|
||||||
|
{
|
||||||
|
return $composition->versions()
|
||||||
|
->where('status', ContentVersionStatus::Bereit->value)
|
||||||
|
->orderByDesc('number')
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function cardOptionLabel(Composition $composition): string
|
||||||
|
{
|
||||||
|
$visibility = match (true) {
|
||||||
|
$this->isPublic($composition) => 'öffentlich sichtbar',
|
||||||
|
$composition->editorialContentKind?->slug === 'modul' => 'Modul, nur Redaktionsvorschau',
|
||||||
|
default => 'ohne Anzeigefreigabe, nur Redaktionsvorschau',
|
||||||
|
};
|
||||||
|
|
||||||
|
return $this->title($composition).' · '.($composition->editorialContentKind?->label ?? '').' · '.$visibility;
|
||||||
|
}
|
||||||
|
|
||||||
private function title(Composition $composition): string
|
private function title(Composition $composition): string
|
||||||
{
|
{
|
||||||
return (string) ($composition->display_title ?: $composition->designation);
|
return (string) ($composition->display_title ?: $composition->designation);
|
||||||
|
|||||||
@@ -0,0 +1,302 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Cms\Catalog;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\CompositionStructureReader;
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\ContentVersionStatus;
|
||||||
|
use App\Domain\Catalog\EditorialProfileReader;
|
||||||
|
use App\Domain\Catalog\StructureNode;
|
||||||
|
use App\Domain\Media\ThumbnailRef;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lesesicht „Medien und Materialien“ für Premium-Karten (Website-CMS-Zielarchitektur 6.2).
|
||||||
|
*
|
||||||
|
* Auswahl in der Redaktion: jedes nicht archivierte Inhaltselement mit mindestens einer nicht gesperrten Fassung.
|
||||||
|
*
|
||||||
|
* Öffentliche Sichtbarkeit (Übergangsregel, solange öffentliche Fachobjektprofile nach ADR-29 fehlen):
|
||||||
|
* Ein Medium hat keine eigene öffentliche Seite. Öffentlich genannt wird es heute nur als Bestandteil der gezeigten
|
||||||
|
* Fassung eines öffentlichen Programms (Programmseite /programme/{id}). Genau dann erscheint auch die Karte
|
||||||
|
* öffentlich, mit Verweis auf diese Programmseite, und nur mit bereitgestellter Fassung. Traineranleitungen erscheinen
|
||||||
|
* nie öffentlich (vertraulich für Trainerinnen und Trainer).
|
||||||
|
*
|
||||||
|
* Öffentlich gelesen werden Anzeigetitel (sonst Arbeitstitel), Inhaltsart und Ausgabeart sowie einer der Texte
|
||||||
|
* Teaser, Kurzbeschreibung oder ausführliche Beschreibung. Welcher Text erscheint, entscheidet die Redaktion je Karte
|
||||||
|
* (Einstellung „Text der Karte“); ohne Wahl gilt die Kurzbeschreibung, sonst der Teaser. Die ausführliche Beschreibung
|
||||||
|
* erscheint nur, wenn die Redaktion sie ausdrücklich wählt. Nie: Einsatzhinweis, Lizenzvermerk, Dateien, Lehrtexte,
|
||||||
|
* Ausgabeadressen. Das Vorschaubild der Bibliothek ist nicht für die Website freigegeben; es erscheint nur in der
|
||||||
|
* Redaktionsvorschau und kann in der Karte ausdrücklich als Website-Bild übernommen werden (FilmStill).
|
||||||
|
* Eine Karte spielt nichts ab, bietet keinen Download und gibt kein Medium frei.
|
||||||
|
*/
|
||||||
|
class PublicMaterialReader
|
||||||
|
{
|
||||||
|
/** Inhaltsarten, die nie öffentlich auf einer Karte erscheinen. */
|
||||||
|
public const CONFIDENTIAL_KINDS = ['traineranleitung'];
|
||||||
|
|
||||||
|
/** @var array<int, array{id: int, title: string}>|null Element-ID => erstes öffentliches Programm */
|
||||||
|
private ?array $publicIndex = null;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly PublicCatalogReader $catalog,
|
||||||
|
private readonly CompositionStructureReader $structure,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function isSelectable(ContentElement $element): bool
|
||||||
|
{
|
||||||
|
return $element->archived_at === null
|
||||||
|
&& $element->versions()->where('status', '!=', ContentVersionStatus::Gesperrt->value)->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isReady(ContentElement $element): bool
|
||||||
|
{
|
||||||
|
return $element->versions()->where('status', ContentVersionStatus::Bereit->value)->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Öffentliches Programm, in dessen gezeigter Fassung das Element vorkommt, sonst null.
|
||||||
|
*
|
||||||
|
* @return array{id: int, title: string}|null
|
||||||
|
*/
|
||||||
|
public function publicProgramFor(ContentElement $element): ?array
|
||||||
|
{
|
||||||
|
return $this->publicIndex()[$element->id] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isPublic(ContentElement $element): bool
|
||||||
|
{
|
||||||
|
return $this->isSelectable($element)
|
||||||
|
&& $this->isReady($element)
|
||||||
|
&& ! in_array($element->editorialContentKind?->slug, self::CONFIDENTIAL_KINDS, true)
|
||||||
|
&& $this->publicProgramFor($element) !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, string>
|
||||||
|
*/
|
||||||
|
public function search(?string $term, int $limit = 25): array
|
||||||
|
{
|
||||||
|
$term = trim((string) $term);
|
||||||
|
|
||||||
|
$candidates = ContentElement::query()
|
||||||
|
->with('editorialContentKind')
|
||||||
|
->whereNull('archived_at')
|
||||||
|
->whereHas('versions', fn ($query) => $query->where('status', '!=', ContentVersionStatus::Gesperrt->value))
|
||||||
|
->when($term !== '', function ($query) use ($term): void {
|
||||||
|
$like = '%'.mb_strtolower($term).'%';
|
||||||
|
$query->where(fn ($inner) => $inner
|
||||||
|
->whereRaw('LOWER(working_title) LIKE ?', [$like])
|
||||||
|
->orWhereRaw('LOWER(COALESCE(display_title, \'\')) LIKE ?', [$like]));
|
||||||
|
})
|
||||||
|
->orderBy('working_title')
|
||||||
|
->limit($limit)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$options = [];
|
||||||
|
foreach ($candidates as $element) {
|
||||||
|
$options[$element->id] = $this->optionLabel($element);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function labelFor(mixed $id): ?string
|
||||||
|
{
|
||||||
|
$element = is_numeric($id) ? ContentElement::query()->with('editorialContentKind')->find((int) $id) : null;
|
||||||
|
|
||||||
|
return $element === null ? null : $this->optionLabel($element);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anzeigedaten für eine Karte. Öffentlich null, wenn das Element nicht öffentlich genannt wird.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $draft ungespeicherte Anzeigedaten, nur für die Redaktionsvorschau
|
||||||
|
*/
|
||||||
|
public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ?CardSubject
|
||||||
|
{
|
||||||
|
$element = is_numeric($id) ? ContentElement::query()->with('editorialContentKind')->find((int) $id) : null;
|
||||||
|
|
||||||
|
if ($element === null || ! $this->isSelectable($element)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$public = $this->isPublic($element);
|
||||||
|
|
||||||
|
if (! $public && ! $includeNonPublic) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$shown = clone $element;
|
||||||
|
|
||||||
|
foreach (['working_title', 'display_title', 'teaser', 'summary', 'description', 'thumbnail_path', 'thumbnail_alt'] as $field) {
|
||||||
|
if (! array_key_exists($field, $draft)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = $draft[$field];
|
||||||
|
$shown->setAttribute($field, is_string($value) && trim($value) === '' ? null : $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$program = $this->publicProgramFor($element);
|
||||||
|
$output = self::outputLabel((string) $shown->output_class);
|
||||||
|
$film = $shown->output_class === 'film';
|
||||||
|
$editorialKind = $element->editorialContentKind?->label;
|
||||||
|
$summary = filled($shown->summary) ? trim((string) $shown->summary) : null;
|
||||||
|
$profile = app(EditorialProfileReader::class)->read($shown, 'bibliothek');
|
||||||
|
|
||||||
|
if (! array_key_exists('summary', $draft) && $profile->origin('summary') === 'variante') {
|
||||||
|
$summary = $profile->value('summary');
|
||||||
|
} elseif ($summary === null && filled($shown->teaser)) {
|
||||||
|
$summary = trim((string) $shown->teaser);
|
||||||
|
}
|
||||||
|
|
||||||
|
$texts = [];
|
||||||
|
|
||||||
|
foreach (['teaser', 'summary', 'description'] as $field) {
|
||||||
|
$own = filled($shown->getAttribute($field)) ? trim((string) $shown->getAttribute($field)) : null;
|
||||||
|
|
||||||
|
if (! array_key_exists($field, $draft) && $profile->origin($field) === 'variante') {
|
||||||
|
$own = $profile->value($field);
|
||||||
|
}
|
||||||
|
|
||||||
|
$texts[$field] = $own;
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = (string) ($shown->display_title ?: $shown->working_title);
|
||||||
|
|
||||||
|
if (! array_key_exists('display_title', $draft) && $profile->origin('display_title') === 'variante') {
|
||||||
|
$title = (string) $profile->value('display_title');
|
||||||
|
}
|
||||||
|
|
||||||
|
$meta = [$output];
|
||||||
|
if ($program !== null) {
|
||||||
|
$meta[] = 'Im Programm „'.$program['title'].'“';
|
||||||
|
}
|
||||||
|
if ($film) {
|
||||||
|
$meta[] = 'Vollständiger Film nur mit Lizenz im Mitgliederbereich';
|
||||||
|
}
|
||||||
|
|
||||||
|
$missing = [];
|
||||||
|
if ($summary === null) {
|
||||||
|
$missing[] = 'Keine Kurzbeschreibung gepflegt (Medium bearbeiten → Kurzbeschreibung).';
|
||||||
|
}
|
||||||
|
if (! filled($shown->display_title)) {
|
||||||
|
$missing[] = 'Kein Anzeigetitel gepflegt; die Karte zeigt den Arbeitstitel.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$previewImage = $includeNonPublic ? ThumbnailRef::url('editorial.card', 'element', (int) $element->id, $shown->thumbnail_path) : null;
|
||||||
|
|
||||||
|
return new CardSubject(
|
||||||
|
title: $title,
|
||||||
|
summary: $summary,
|
||||||
|
kind: filled($editorialKind) ? (string) $editorialKind : $output,
|
||||||
|
badge: $output,
|
||||||
|
meta: $meta,
|
||||||
|
url: $public && $program !== null ? route('public.program', $program['id']) : null,
|
||||||
|
public: $public,
|
||||||
|
notice: $public ? null : $this->notice($element, $program),
|
||||||
|
visual: $film ? 'film' : 'material',
|
||||||
|
visualLabel: $output,
|
||||||
|
previewImage: $previewImage,
|
||||||
|
missing: $missing,
|
||||||
|
style: $film ? 'media' : 'material',
|
||||||
|
texts: $texts,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Bezeichnung der Ausgabeart, wie in der Redaktionsstruktur (CompositionRelease::outputLabel). */
|
||||||
|
public static function outputLabel(string $outputClass): string
|
||||||
|
{
|
||||||
|
return match ($outputClass) {
|
||||||
|
'film' => 'Film',
|
||||||
|
'audio' => 'Hörstück',
|
||||||
|
'bild' => 'Bild',
|
||||||
|
'document', 'pdf' => 'Dokument',
|
||||||
|
default => 'Text',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function visibilityNote(ContentElement $element): string
|
||||||
|
{
|
||||||
|
if ($this->isPublic($element)) {
|
||||||
|
$program = $this->publicProgramFor($element);
|
||||||
|
|
||||||
|
return 'Öffentlich nur als Teil der Programmseite „'.($program['title'] ?? '').'“. Die Mediendatei wird dabei nicht ausgeliefert.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->notice($element, $this->publicProgramFor($element));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array{id: int, title: string}|null $program
|
||||||
|
*/
|
||||||
|
private function notice(ContentElement $element, ?array $program): string
|
||||||
|
{
|
||||||
|
$reason = match (true) {
|
||||||
|
in_array($element->editorialContentKind?->slug, self::CONFIDENTIAL_KINDS, true) => 'Traineranleitungen erscheinen nie öffentlich.',
|
||||||
|
! $this->isReady($element) => 'Das Medium hat noch keine bereitgestellte Fassung.',
|
||||||
|
$program === null => 'Das Medium gehört zu keinem öffentlich gezeigten Programm. Medien haben noch keine eigene öffentliche Freigabe (öffentliches Profil, ADR-29).',
|
||||||
|
default => 'Das Medium ist nicht öffentlich.',
|
||||||
|
};
|
||||||
|
|
||||||
|
return 'Nur in der Redaktionsvorschau sichtbar: '.$reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function optionLabel(ContentElement $element): string
|
||||||
|
{
|
||||||
|
$visibility = $this->isPublic($element)
|
||||||
|
? 'öffentlich über Programmseite'
|
||||||
|
: ($this->isReady($element) ? 'nur Redaktionsvorschau' : 'Entwurf, nur Redaktionsvorschau');
|
||||||
|
$kind = $element->editorialContentKind?->label ?: self::outputLabel((string) $element->output_class);
|
||||||
|
|
||||||
|
return (string) ($element->display_title ?: $element->working_title).' · '.$kind.' · '.$visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index aller Elemente, die in der gezeigten Fassung eines öffentlichen Programms vorkommen (auch verschachtelt).
|
||||||
|
*
|
||||||
|
* @return array<int, array{id: int, title: string}>
|
||||||
|
*/
|
||||||
|
private function publicIndex(): array
|
||||||
|
{
|
||||||
|
if ($this->publicIndex !== null) {
|
||||||
|
return $this->publicIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
$index = [];
|
||||||
|
|
||||||
|
foreach ($this->catalog->publicPrograms() as $program) {
|
||||||
|
$version = $this->catalog->shownVersion($program);
|
||||||
|
|
||||||
|
if ($version === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$entry = ['id' => (int) $program->id, 'title' => (string) ($program->display_title ?: $program->designation)];
|
||||||
|
|
||||||
|
foreach ($this->elementIds($this->structure->tree($version)) as $elementId) {
|
||||||
|
$index[$elementId] ??= $entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->publicIndex = $index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<StructureNode> $nodes
|
||||||
|
* @return list<int>
|
||||||
|
*/
|
||||||
|
private function elementIds(array $nodes): array
|
||||||
|
{
|
||||||
|
$ids = [];
|
||||||
|
|
||||||
|
foreach ($nodes as $node) {
|
||||||
|
if ($node->contentElementId !== null) {
|
||||||
|
$ids[] = (int) $node->contentElementId;
|
||||||
|
}
|
||||||
|
|
||||||
|
array_push($ids, ...$this->elementIds($node->children));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -148,6 +148,9 @@ private function storeRevision(Page $page, array $blocks, ?array $sections, ?str
|
|||||||
|
|
||||||
$revision = $page->revisions()->create($attributes);
|
$revision = $page->revisions()->create($attributes);
|
||||||
|
|
||||||
|
// „Geändert“ in der Seitenliste zeigt die letzte Bearbeitung, nicht das Anlagedatum.
|
||||||
|
$page->touch();
|
||||||
|
|
||||||
foreach ($this->sections->mediaPaths($revision->sections()) as $path) {
|
foreach ($this->sections->mediaPaths($revision->sections()) as $path) {
|
||||||
PublishPublicMedia::dispatch($path);
|
PublishPublicMedia::dispatch($path);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Domain\Cms\Sections;
|
namespace App\Domain\Cms\Sections;
|
||||||
|
|
||||||
|
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
||||||
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
||||||
|
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||||
use App\Domain\Cms\Widgets\WidgetRegistry;
|
use App\Domain\Cms\Widgets\WidgetRegistry;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
@@ -11,14 +13,17 @@
|
|||||||
* Abschnitts- und Slotmodell einer Seite: Seite → Abschnitte → Slots → Widget-Instanzen.
|
* Abschnitts- und Slotmodell einer Seite: Seite → Abschnitte → Slots → Widget-Instanzen.
|
||||||
*
|
*
|
||||||
* Gespeicherte Hülle eines Abschnitts (Version 1):
|
* Gespeicherte Hülle eines Abschnitts (Version 1):
|
||||||
* {id, v, layout, style: {background, image, focus, overlay, width, spacing, divider}, slots: [Widget-Hülle|null, …]}
|
* {id, v, layout, style: {background, image, focus, overlay, width, spacing_top, spacing_bottom, gap, divider}, slots: [Widget-Hülle|null, …]}
|
||||||
|
*
|
||||||
|
* Version 2 (Abstände): oben, unten und Widget-Abstand sind drei unabhängige Werte. Hüllen der Version 1 werden beim
|
||||||
|
* Lesen übersetzt (SectionStyle::migrateSpacing), ohne die Darstellung zu ändern; gespeicherte Revisionen bleiben.
|
||||||
*
|
*
|
||||||
* Jeder Slot enthält höchstens ein Widget aus dem zentralen Widget-Register. Abschnitte sind nicht verschachtelbar.
|
* Jeder Slot enthält höchstens ein Widget aus dem zentralen Widget-Register. Abschnitte sind nicht verschachtelbar.
|
||||||
* Revisionen ohne Abschnitte (Bestand vor dieser Fassung) werden beim Lesen als einspaltige Abschnitte gelesen.
|
* Revisionen ohne Abschnitte (Bestand vor dieser Fassung) werden beim Lesen als einspaltige Abschnitte gelesen.
|
||||||
*/
|
*/
|
||||||
class PageSections
|
class PageSections
|
||||||
{
|
{
|
||||||
public const VERSION = 1;
|
public const VERSION = 2;
|
||||||
|
|
||||||
public const MAX_SECTIONS = 30;
|
public const MAX_SECTIONS = 30;
|
||||||
|
|
||||||
@@ -41,10 +46,8 @@ public function read(?array $sections, ?array $blocks = null): array
|
|||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
foreach (array_values($sections) as $section) {
|
foreach (SectionStyle::migrateSpacing(array_values(array_filter($sections, 'is_array')), byVersion: true) as $section) {
|
||||||
if (is_array($section)) {
|
$result[] = $this->upcastSection($section);
|
||||||
$result[] = $this->upcastSection($section);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -74,6 +77,12 @@ public function normalize(array $content): array
|
|||||||
$seenWidgetIds = [];
|
$seenWidgetIds = [];
|
||||||
$widgetCount = 0;
|
$widgetCount = 0;
|
||||||
|
|
||||||
|
// Eingaben mit Abständen der Version 1 (zum Beispiel ältere Aufrufer) werden wie beim Lesen übersetzt.
|
||||||
|
$migrated = SectionStyle::migrateSpacing(array_map(
|
||||||
|
fn ($item) => is_array($item) && array_key_exists('slots', $item) ? $item : ['style' => [], 'slots' => [$item]],
|
||||||
|
$items,
|
||||||
|
));
|
||||||
|
|
||||||
foreach ($items as $index => $item) {
|
foreach ($items as $index => $item) {
|
||||||
if (! is_array($item)) {
|
if (! is_array($item)) {
|
||||||
$errors["sections.$index"] = ['Ein Abschnitt ist unvollständig.'];
|
$errors["sections.$index"] = ['Ein Abschnitt ist unvollständig.'];
|
||||||
@@ -83,6 +92,8 @@ public function normalize(array $content): array
|
|||||||
|
|
||||||
if (! array_key_exists('slots', $item)) {
|
if (! array_key_exists('slots', $item)) {
|
||||||
$item = ['id' => null, 'layout' => SectionLayouts::DEFAULT, 'style' => [], 'slots' => [$item]];
|
$item = ['id' => null, 'layout' => SectionLayouts::DEFAULT, 'style' => [], 'slots' => [$item]];
|
||||||
|
} else {
|
||||||
|
$item['style'] = $migrated[$index]['style'] ?? ($item['style'] ?? []);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sections[] = $this->normalizeSection($item, $index, $errors, $seenSectionIds, $seenWidgetIds, $widgetCount);
|
$sections[] = $this->normalizeSection($item, $index, $errors, $seenSectionIds, $seenWidgetIds, $widgetCount);
|
||||||
@@ -136,7 +147,7 @@ public function mediaPaths(array $sections): array
|
|||||||
|
|
||||||
foreach ($sections as $section) {
|
foreach ($sections as $section) {
|
||||||
$style = SectionStyle::fromStored($section['style'] ?? []);
|
$style = SectionStyle::fromStored($section['style'] ?? []);
|
||||||
if ($style['image'] !== null && PublicMedia::isPublicPath($style['image'])) {
|
if (is_string($style['image']) && PublicMedia::isPublicPath($style['image'])) {
|
||||||
$paths[] = $style['image'];
|
$paths[] = $style['image'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,13 +175,14 @@ private function wrapWidgets(array $blocks): array
|
|||||||
{
|
{
|
||||||
$sections = [];
|
$sections = [];
|
||||||
|
|
||||||
foreach ($this->widgets->read($blocks) as $widget) {
|
foreach ($this->widgets->read($blocks) as $position => $widget) {
|
||||||
$sections[] = [
|
$sections[] = [
|
||||||
'id' => null,
|
'id' => null,
|
||||||
'v' => self::VERSION,
|
'v' => self::VERSION,
|
||||||
'layout' => SectionLayouts::DEFAULT,
|
'layout' => SectionLayouts::DEFAULT,
|
||||||
// Bestand vor dem Raster stand in einem durchgehenden Blatt: kompakte Abstände kommen dem am nächsten.
|
// Bestand vor dem Raster stand in einem durchgehenden Blatt: kompakte Abstände, zwischen den Widgets
|
||||||
'style' => ['spacing' => 'compact'] + SectionStyle::DEFAULTS,
|
// nur einmal (oben kein Abstand ab dem zweiten), wie bisher.
|
||||||
|
'style' => ['spacing_top' => $position === 0 ? 'compact' : 'none', 'spacing_bottom' => 'compact', 'gap' => 'normal'] + SectionStyle::DEFAULTS,
|
||||||
'slots' => [$widget],
|
'slots' => [$widget],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -325,14 +337,17 @@ private function normalizeStyle(array $style, string $prefix, array &$errors): a
|
|||||||
$result[$key] = $value;
|
$result[$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$upload = PublicMedia::fromUploadState($style['_upload'] ?? null);
|
|
||||||
$image = $upload ?? PublicMedia::fromUploadState($style['image'] ?? null);
|
|
||||||
|
|
||||||
if ($result['background'] === 'image') {
|
if ($result['background'] === 'image') {
|
||||||
if ($image === null) {
|
$widgetErrors = new WidgetErrors;
|
||||||
$errors["$prefix.style.image"] = ['Bitte ein Hintergrundbild wählen oder hochladen.'];
|
$refs = ImageRefFields::clean(['image' => $style['image'] ?? null, '_upload' => $style['_upload'] ?? null], $widgetErrors, errorKey: 'image');
|
||||||
} elseif (! PublicMedia::isPublicPath($image)) {
|
$image = $refs['image'];
|
||||||
$errors["$prefix.style.image"] = ['Das Hintergrundbild liegt nicht im öffentlichen Medienbereich.'];
|
|
||||||
|
foreach ($widgetErrors->all() as $messages) {
|
||||||
|
$errors["$prefix.style.image"] = $messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($image === null && ! isset($errors["$prefix.style.image"])) {
|
||||||
|
$errors["$prefix.style.image"] = ['Bitte ein Hintergrundbild aus dem Medienmanager wählen oder hochladen.'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$result['image'] = $image;
|
$result['image'] = $image;
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ final class SectionLayouts
|
|||||||
'u3_1' => [3, 1],
|
'u3_1' => [3, 1],
|
||||||
'u1_2_1' => [1, 2, 1],
|
'u1_2_1' => [1, 2, 1],
|
||||||
'u1_1_1_1' => [1, 1, 1, 1],
|
'u1_1_1_1' => [1, 1, 1, 1],
|
||||||
|
'u1_1_2' => [1, 1, 2],
|
||||||
|
'u2_1_1' => [2, 1, 1],
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var array<string, string> */
|
/** @var array<string, string> */
|
||||||
@@ -32,6 +34,8 @@ final class SectionLayouts
|
|||||||
'u3_1' => 'Breit und schmal',
|
'u3_1' => 'Breit und schmal',
|
||||||
'u1_2_1' => 'Mitte betont',
|
'u1_2_1' => 'Mitte betont',
|
||||||
'u1_1_1_1' => 'Vier gleich breit',
|
'u1_1_1_1' => 'Vier gleich breit',
|
||||||
|
'u1_1_2' => 'Zwei schmal, eins breit',
|
||||||
|
'u2_1_1' => 'Eins breit, zwei schmal',
|
||||||
];
|
];
|
||||||
|
|
||||||
public static function has(mixed $key): bool
|
public static function has(mixed $key): bool
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace App\Domain\Cms\Sections;
|
namespace App\Domain\Cms\Sections;
|
||||||
|
|
||||||
use App\Domain\Cms\Widgets\RenderContext;
|
use App\Domain\Cms\Widgets\RenderContext;
|
||||||
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||||
use App\Domain\Cms\Widgets\WidgetRenderer;
|
use App\Domain\Cms\Widgets\WidgetRenderer;
|
||||||
use Illuminate\Support\HtmlString;
|
use Illuminate\Support\HtmlString;
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ public function renderAll(array $sections, RenderContext $context): HtmlString
|
|||||||
$last = count($rendered) - 1;
|
$last = count($rendered) - 1;
|
||||||
|
|
||||||
foreach ($rendered as $index => $item) {
|
foreach ($rendered as $index => $item) {
|
||||||
$html .= $this->renderSection($item['section'], $item['cells'], $index);
|
$html .= $this->renderSection($item['section'], $item['cells'], $index, $context);
|
||||||
|
|
||||||
$divider = $item['section']['style']['divider'] ?? 'none';
|
$divider = $item['section']['style']['divider'] ?? 'none';
|
||||||
if ($index < $last && in_array($divider, ['line', 'accent'], true)) {
|
if ($index < $last && in_array($divider, ['line', 'accent'], true)) {
|
||||||
@@ -71,17 +71,21 @@ public function renderAll(array $sections, RenderContext $context): HtmlString
|
|||||||
* @param array<string, mixed> $section
|
* @param array<string, mixed> $section
|
||||||
* @param list<array{units: int, html: string}> $cells
|
* @param list<array{units: int, html: string}> $cells
|
||||||
*/
|
*/
|
||||||
private function renderSection(array $section, array $cells, int $index): string
|
private function renderSection(array $section, array $cells, int $index, RenderContext $context): string
|
||||||
{
|
{
|
||||||
$style = SectionStyle::fromStored($section['style'] ?? []);
|
$style = SectionStyle::fromStored($section['style'] ?? []);
|
||||||
$columns = SectionLayouts::columns(array_column($cells, 'units'));
|
$columns = SectionLayouts::columns(array_column($cells, 'units'));
|
||||||
$hasImage = $style['background'] === 'image' && $style['image'] !== null && PublicMedia::isPublicPath($style['image']);
|
// Hintergrundbild aus dem Medienmanager: öffentlich nur mit Website-Freigabe (WebsiteImage → WebsiteMedia).
|
||||||
|
$imageUrl = $style['background'] === 'image' ? app(WebsiteImage::class)->url($style['image'], $context->preview) : null;
|
||||||
|
$hasImage = $imageUrl !== null;
|
||||||
|
|
||||||
$classes = [
|
$classes = [
|
||||||
'page-section',
|
'page-section',
|
||||||
'section-bg-'.($hasImage ? 'image' : ($style['background'] === 'image' ? 'default' : $style['background'])),
|
'section-bg-'.($hasImage ? 'image' : ($style['background'] === 'image' ? 'default' : $style['background'])),
|
||||||
'section-width-'.$style['width'],
|
'section-width-'.$style['width'],
|
||||||
'section-space-'.$style['spacing'],
|
'section-space-top-'.$style['spacing_top'],
|
||||||
|
'section-space-bottom-'.$style['spacing_bottom'],
|
||||||
|
'section-gap-'.$style['gap'],
|
||||||
'section-layout-'.str_replace('_', '-', $section['layout']),
|
'section-layout-'.str_replace('_', '-', $section['layout']),
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -101,17 +105,13 @@ private function renderSection(array $section, array $cells, int $index): string
|
|||||||
$classes[] = $scope;
|
$classes[] = $scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($style['divider'] === 'space') {
|
|
||||||
$classes[] = 'section-divider-space';
|
|
||||||
}
|
|
||||||
|
|
||||||
$id = is_string($section['id'] ?? null) ? ' id="bereich-'.e($section['id']).'"' : '';
|
$id = is_string($section['id'] ?? null) ? ' id="bereich-'.e($section['id']).'"' : '';
|
||||||
$html = '<div class="'.e(implode(' ', $classes)).'"'.$id.'>';
|
$html = '<div class="'.e(implode(' ', $classes)).'"'.$id.'>';
|
||||||
|
|
||||||
if ($hasImage) {
|
if ($hasImage) {
|
||||||
// Das Bild des ersten Abschnitts ist meist das größte sichtbare Element und wird nicht verzögert geladen.
|
// Das Bild des ersten Abschnitts ist meist das größte sichtbare Element und wird nicht verzögert geladen.
|
||||||
$loading = $index === 0 ? 'loading="eager" fetchpriority="high"' : 'loading="lazy"';
|
$loading = $index === 0 ? 'loading="eager" fetchpriority="high"' : 'loading="lazy"';
|
||||||
$html .= '<img class="page-section-image" src="'.e(PublicMedia::url($style['image'])).'" alt="" '.$loading.' decoding="async"'
|
$html .= '<img class="page-section-image" src="'.e($imageUrl).'" alt="" '.$loading.' decoding="async"'
|
||||||
.' style="object-position: '.e(SectionStyle::FOCUS_POSITIONS[$style['focus']]).'">';
|
.' style="object-position: '.e(SectionStyle::FOCUS_POSITIONS[$style['focus']]).'">';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Domain\Cms\Sections;
|
namespace App\Domain\Cms\Sections;
|
||||||
|
|
||||||
|
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Semantische Abschnittsgestaltung. Jeder Wert ist eine Aufzählung, die auf zentrale Design-Tokens
|
* Semantische Abschnittsgestaltung. Jeder Wert ist eine Aufzählung, die auf zentrale Design-Tokens
|
||||||
* abgebildet wird (resources/css/app.css, Abschnitt „Abschnitte“). Keine freie CSS- oder Farbangabe.
|
* abgebildet wird (resources/css/app.css, Abschnitt „Abschnitte“). Keine freie CSS- oder Farbangabe.
|
||||||
@@ -25,8 +27,19 @@ final class SectionStyle
|
|||||||
'full' => 'Vollbreite',
|
'full' => 'Vollbreite',
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var array<string, string> */
|
/**
|
||||||
|
* Gemeinsame Stufen der drei Abstände eines Abschnitts (Hülle Version 2):
|
||||||
|
* - spacing_top: Abstand vor dem Inhalt (oben),
|
||||||
|
* - spacing_bottom: Abstand nach dem Inhalt (unten),
|
||||||
|
* - gap: Abstand zwischen den Plätzen im Abschnittsraster, nebeneinander und gestapelt.
|
||||||
|
* Zwischen zwei Abschnitten addieren sich „unten“ des ersten und „oben“ des zweiten; es gibt keine weitere
|
||||||
|
* versteckte Vorgabe. Liegt eine eigene Fläche (Hintergrund) vor, liegen oben und unten innerhalb dieser Fläche.
|
||||||
|
* Werte: resources/css/tokens.css (--section-space-*, --section-gap-*).
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
public const SPACINGS = [
|
public const SPACINGS = [
|
||||||
|
'none' => 'Kein Abstand',
|
||||||
'compact' => 'Kompakt',
|
'compact' => 'Kompakt',
|
||||||
'normal' => 'Normal',
|
'normal' => 'Normal',
|
||||||
'large' => 'Großzügig',
|
'large' => 'Großzügig',
|
||||||
@@ -35,7 +48,6 @@ final class SectionStyle
|
|||||||
/** @var array<string, string> */
|
/** @var array<string, string> */
|
||||||
public const DIVIDERS = [
|
public const DIVIDERS = [
|
||||||
'none' => 'Kein Trenner',
|
'none' => 'Kein Trenner',
|
||||||
'space' => 'Zusätzlicher Abstand',
|
|
||||||
'line' => 'Dezente Linie',
|
'line' => 'Dezente Linie',
|
||||||
'accent' => 'Markenakzent',
|
'accent' => 'Markenakzent',
|
||||||
];
|
];
|
||||||
@@ -79,7 +91,9 @@ final class SectionStyle
|
|||||||
'focus' => 'center',
|
'focus' => 'center',
|
||||||
'overlay' => 'light',
|
'overlay' => 'light',
|
||||||
'width' => 'standard',
|
'width' => 'standard',
|
||||||
'spacing' => 'normal',
|
'spacing_top' => 'compact',
|
||||||
|
'spacing_bottom' => 'compact',
|
||||||
|
'gap' => 'normal',
|
||||||
'divider' => 'none',
|
'divider' => 'none',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -95,7 +109,9 @@ public static function enums(): array
|
|||||||
'focus' => self::FOCUS,
|
'focus' => self::FOCUS,
|
||||||
'overlay' => self::OVERLAYS,
|
'overlay' => self::OVERLAYS,
|
||||||
'width' => self::WIDTHS,
|
'width' => self::WIDTHS,
|
||||||
'spacing' => self::SPACINGS,
|
'spacing_top' => self::SPACINGS,
|
||||||
|
'spacing_bottom' => self::SPACINGS,
|
||||||
|
'gap' => self::SPACINGS,
|
||||||
'divider' => self::DIVIDERS,
|
'divider' => self::DIVIDERS,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -104,7 +120,7 @@ public static function enums(): array
|
|||||||
* Lesepfad: gespeicherte Werte; Unbekanntes fällt auf die Vorgabe zurück, damit alte oder fremde Daten
|
* Lesepfad: gespeicherte Werte; Unbekanntes fällt auf die Vorgabe zurück, damit alte oder fremde Daten
|
||||||
* nie eine Seite brechen.
|
* nie eine Seite brechen.
|
||||||
*
|
*
|
||||||
* @return array{background: string, image: ?string, focus: string, overlay: string, width: string, spacing: string, divider: string}
|
* @return array{background: string, image: ?string, focus: string, overlay: string, width: string, spacing_top: string, spacing_bottom: string, gap: string, divider: string}
|
||||||
*/
|
*/
|
||||||
public static function fromStored(mixed $style): array
|
public static function fromStored(mixed $style): array
|
||||||
{
|
{
|
||||||
@@ -118,7 +134,7 @@ public static function fromStored(mixed $style): array
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result['image'] = $result['background'] === 'image' && is_string($style['image'] ?? null) ? $style['image'] : null;
|
$result['image'] = $result['background'] === 'image' ? WebsiteImage::normalize($style['image'] ?? null) : null;
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@@ -137,8 +153,13 @@ public static function summary(array $style): string
|
|||||||
$parts[] = self::WIDTHS[$style['width']];
|
$parts[] = self::WIDTHS[$style['width']];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($style['spacing'] !== 'normal') {
|
if ($style['spacing_top'] !== self::DEFAULTS['spacing_top'] || $style['spacing_bottom'] !== self::DEFAULTS['spacing_bottom']) {
|
||||||
$parts[] = 'Abstand '.mb_strtolower(self::SPACINGS[$style['spacing']]);
|
$parts[] = 'Abstand oben '.mb_strtolower(self::SPACINGS[$style['spacing_top']])
|
||||||
|
.', unten '.mb_strtolower(self::SPACINGS[$style['spacing_bottom']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($style['gap'] !== 'normal') {
|
||||||
|
$parts[] = 'Widget-Abstand '.mb_strtolower(self::SPACINGS[$style['gap']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($style['divider'] !== 'none') {
|
if ($style['divider'] !== 'none') {
|
||||||
@@ -147,4 +168,77 @@ public static function summary(array $style): string
|
|||||||
|
|
||||||
return implode(' · ', $parts);
|
return implode(' · ', $parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ob eine gespeicherte Gestaltung noch die Abstände der Hülle Version 1 trägt
|
||||||
|
* („Abstand oben und unten“ spacing, Abweichung „Abstand oben“ same/small/none).
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $style
|
||||||
|
*/
|
||||||
|
public static function hasLegacySpacing(array $style): bool
|
||||||
|
{
|
||||||
|
return array_key_exists('spacing', $style)
|
||||||
|
|| in_array($style['spacing_top'] ?? null, ['same', 'small'], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Übersetzt die Abstände der Hülle Version 1 in die drei Werte der Version 2, ohne die Darstellung zu ändern.
|
||||||
|
*
|
||||||
|
* Version 1 rechnete so: jeder Abschnitt oben und unten „spacing“ (Vorgabe normal); die Abweichung
|
||||||
|
* „Abstand oben“ ersetzte nur oben (small/none); und eine versteckte Regel setzte oben auf null, wenn ein Abschnitt
|
||||||
|
* ohne eigene Fläche direkt auf einen Abschnitt ohne eigene Fläche folgte (ohne Linien- oder Akzenttrenner dazwischen).
|
||||||
|
* Diese Regel wird hier als „oben: kein Abstand“ ausgeschrieben. „Gering“ hat keine eigene Stufe mehr und wird
|
||||||
|
* „Kompakt“ (dokumentierte Abweichung). Der Widget-Abstand entspricht dem bisherigen festen Rasterabstand („normal“).
|
||||||
|
*
|
||||||
|
* @param list<array<string, mixed>> $sections Abschnitte in Lesereihenfolge (mit style und slots)
|
||||||
|
* @param bool $byVersion true: jede Hülle mit v < 2 gilt als Version 1 (Lesepfad gespeicherter Revisionen);
|
||||||
|
* false: nur Gestaltungen mit alten Schlüsseln (Eingaben ohne Versionsangabe)
|
||||||
|
* @return list<array<string, mixed>> dieselben Abschnitte mit übersetzter Gestaltung
|
||||||
|
*/
|
||||||
|
public static function migrateSpacing(array $sections, bool $byVersion = false): array
|
||||||
|
{
|
||||||
|
$previous = null;
|
||||||
|
|
||||||
|
foreach ($sections as $index => $section) {
|
||||||
|
$style = is_array($section['style'] ?? null) ? $section['style'] : [];
|
||||||
|
$rendered = is_array($section['slots'] ?? null) && array_filter($section['slots'], 'is_array') !== [];
|
||||||
|
|
||||||
|
$background = is_string($style['background'] ?? null) && isset(self::BACKGROUNDS[$style['background']]) ? $style['background'] : 'default';
|
||||||
|
if ($background === 'image' && WebsiteImage::normalize($style['image'] ?? null) === null) {
|
||||||
|
$background = 'default';
|
||||||
|
}
|
||||||
|
$divider = in_array($style['divider'] ?? null, ['line', 'accent'], true) ? $style['divider'] : 'none';
|
||||||
|
|
||||||
|
$legacy = $byVersion ? (int) ($section['v'] ?? 1) < 2 : self::hasLegacySpacing($style);
|
||||||
|
|
||||||
|
if ($legacy) {
|
||||||
|
$level = in_array($style['spacing'] ?? null, ['compact', 'normal', 'large'], true) ? $style['spacing'] : 'normal';
|
||||||
|
$override = $style['spacing_top'] ?? 'same';
|
||||||
|
$collapsed = $background === 'default' && $previous !== null && $previous['background'] === 'default' && ! in_array($previous['divider'], ['line', 'accent'], true);
|
||||||
|
|
||||||
|
$style['spacing_top'] = match (true) {
|
||||||
|
$override === 'none' => 'none',
|
||||||
|
$override === 'small' => 'compact',
|
||||||
|
$collapsed => 'none',
|
||||||
|
default => $level,
|
||||||
|
};
|
||||||
|
$style['spacing_bottom'] = $level;
|
||||||
|
$style['gap'] = 'normal';
|
||||||
|
|
||||||
|
// Trenner „Zusätzlicher Abstand“ (Version 1) fügte unten noch einmal den Abschnittsabstand an.
|
||||||
|
if (($style['divider'] ?? null) === 'space') {
|
||||||
|
$style['spacing_bottom'] = ['compact' => 'normal', 'normal' => 'large', 'large' => 'large'][$level];
|
||||||
|
$style['divider'] = 'none';
|
||||||
|
}
|
||||||
|
unset($style['spacing']);
|
||||||
|
$sections[$index]['style'] = $style;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($rendered) {
|
||||||
|
$previous = ['background' => $background, 'divider' => $divider];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sections;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Cms;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Media\WebsiteMediaAlias;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wo ein Medium auf Website-Seiten als Bild verwendet wird (veröffentlichte Fassung und neuester Entwurf).
|
||||||
|
* Für den Medienmanager: Vor dem Zurücknehmen einer Website-Freigabe ist sichtbar, welche Seiten das Bild verlieren.
|
||||||
|
*/
|
||||||
|
class WebsiteImageUsage
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return list<array{path: string, published: bool, draft: bool}>
|
||||||
|
*/
|
||||||
|
public function pages(ContentElement $element): array
|
||||||
|
{
|
||||||
|
$legacy = WebsiteMediaAlias::query()->where('content_element_id', $element->id)->pluck('legacy_path')->all();
|
||||||
|
$usages = [];
|
||||||
|
|
||||||
|
foreach (Page::query()->with(['publishedRevision', 'latestRevision'])->orderBy('path')->get() as $page) {
|
||||||
|
$published = $page->publishedRevision !== null && $this->uses($page->publishedRevision->sections ?? [], $element->id, $legacy);
|
||||||
|
$draft = $page->latestRevision !== null && $page->latestRevision->id !== $page->published_revision_id
|
||||||
|
&& $this->uses($page->latestRevision->sections ?? [], $element->id, $legacy);
|
||||||
|
|
||||||
|
if ($published || $draft) {
|
||||||
|
$usages[] = ['path' => (string) $page->path, 'published' => $published, 'draft' => $draft];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $usages;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<string> $legacy
|
||||||
|
*/
|
||||||
|
private function uses(mixed $value, int $id, array $legacy): bool
|
||||||
|
{
|
||||||
|
if (! is_array($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($value as $key => $item) {
|
||||||
|
if ($key === 'image' && (($item === $id || (is_string($item) && ($item === (string) $id || in_array($item, $legacy, true)))))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($item) && $this->uses($item, $id, $legacy)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,40 +5,76 @@
|
|||||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||||
use Filament\Forms\Components\Field;
|
use Filament\Forms\Components\Field;
|
||||||
use Filament\Forms\Components\FileUpload;
|
use Filament\Forms\Components\FileUpload;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Placeholder;
|
||||||
use Illuminate\Support\Str;
|
use Filament\Forms\Components\ViewField;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Schemas\Components\Utilities\Get;
|
||||||
|
use Filament\Schemas\Components\Utilities\Set;
|
||||||
|
use Illuminate\Support\HtmlString;
|
||||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gemeinsame Bildauswahl für Widgets: vorhandenes Bild aus dem öffentlichen Website-Bereich wählen
|
* Gemeinsame Bildauswahl aller Widgets und des Abschnittshintergrunds: Bilder aus dem zentralen Medienmanager
|
||||||
* oder ein neues hochladen. Keine eigene Medienverwaltung.
|
* (siehe WebsiteImage, docs/architektur/medienzugriff-fuer-komponenten.md). Keine eigene CMS-Medienverwaltung.
|
||||||
|
*
|
||||||
|
* - Auswahl: durchsuchbare Liste mit Vorschaubild, Titel und Website-Status.
|
||||||
|
* - Neu hochladen: Das Bild wird sofort als Medium im Medienmanager angelegt (WebsiteIntake) und ausgewählt.
|
||||||
|
* - Anzeige des gewählten Mediums mit Status und Verweis auf die Freigabe im Medienmanager.
|
||||||
|
*
|
||||||
|
* Das Bedienmuster folgt der Bildauswahl im Modul- und Programmeditor (Suche, Vorschaubild, Auswählen); jene ist an
|
||||||
|
* die Livewire-Seite des Editors gebunden und lässt sich nicht als Formularfeld im Widget-Dialog einhängen.
|
||||||
*/
|
*/
|
||||||
final class ImageRefFields
|
final class ImageRefFields
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param bool $live Änderungen sofort an die Vorschau im Bearbeitungsdialog geben.
|
* @param bool $live Änderungen sofort an die Vorschau im Bearbeitungsdialog geben.
|
||||||
* @return list<Field>
|
* @param string|null $altField Name des Alternativtext-Felds im selben Formular (für neue Medien), falls vorhanden.
|
||||||
|
* @return list<Field|Placeholder>
|
||||||
*/
|
*/
|
||||||
public static function fields(string $label = 'Bild', bool $live = false): array
|
public static function fields(string $label = 'Bild', bool $live = false, string $key = 'image', ?string $altField = null): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Select::make('image')
|
// Auswahl über den gemeinsamen visuellen Picker (Suche, Vorschau, Website-Freigabe im Detail).
|
||||||
->live($live)
|
ViewField::make($key)
|
||||||
->label($label.': vorhandenes Bild')
|
->live()
|
||||||
->options(fn (): array => PublicMedia::imageOptions())
|
->label($label.' aus dem Medienmanager')
|
||||||
->searchable()
|
->view('filament.cms.bild-feld')
|
||||||
->placeholder('Kein Bild')
|
->helperText('Öffentlich erscheint ein Bild nur mit Website-Freigabe; die Auswahl gibt es nicht frei.'),
|
||||||
->helperText('Auswahl aus den Bildern, die bereits für die Website hochgeladen wurden.'),
|
|
||||||
FileUpload::make('_upload')
|
FileUpload::make('_upload')
|
||||||
->live($live)
|
->live()
|
||||||
->label($label.': neu hochladen')
|
->label($label.': neues Bild hochladen')
|
||||||
->disk('cms_incoming')
|
|
||||||
->directory('cms')
|
|
||||||
->image()
|
->image()
|
||||||
->maxSize(8192)
|
->maxSize(8192)
|
||||||
->acceptedFileTypes(['image/jpeg', 'image/png', 'image/webp'])
|
->acceptedFileTypes(['image/jpeg', 'image/png', 'image/webp'])
|
||||||
->getUploadedFileNameForStorageUsing(fn (TemporaryUploadedFile $file): string => Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)).'-'.Str::lower(Str::random(6)).'.'.$file->guessExtension())
|
->storeFiles(false)
|
||||||
->helperText('Ein neues Bild ersetzt die Auswahl oben. Es wird beim Speichern im öffentlichen Bereich der Website abgelegt.'),
|
->afterStateUpdated(function (mixed $state, Set $set, Get $get) use ($key, $altField): void {
|
||||||
|
$file = is_array($state) ? (array_values($state)[0] ?? null) : $state;
|
||||||
|
|
||||||
|
if (! $file instanceof TemporaryUploadedFile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$element = app(WebsiteImage::class)->accept($file, $altField !== null ? $get($altField) : null);
|
||||||
|
$set('_upload', null);
|
||||||
|
|
||||||
|
if ($element === null) {
|
||||||
|
Notification::make()->danger()->title('Das Bild konnte nicht übernommen werden.')->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$set($key, $element->id);
|
||||||
|
Notification::make()
|
||||||
|
->success()
|
||||||
|
->title('Im Medienmanager angelegt: „'.($element->display_title ?: $element->working_title).'“')
|
||||||
|
->body('Das Bild ist ausgewählt. Nach der Verarbeitung wird es automatisch für die Website freigegeben.')
|
||||||
|
->send();
|
||||||
|
})
|
||||||
|
->helperText('Das Bild wird im Medienmanager angelegt und hier ausgewählt. Nur Bilder mit geklärten Rechten hochladen.'),
|
||||||
|
Placeholder::make('_media_status')
|
||||||
|
->label('Gewähltes Bild')
|
||||||
|
->visible(fn (Get $get): bool => WebsiteImage::normalize($get($key)) !== null)
|
||||||
|
->content(fn (Get $get): HtmlString => self::statusHtml($get($key))),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,29 +84,49 @@ public static function fields(string $label = 'Bild', bool $live = false): array
|
|||||||
public static function rules(): array
|
public static function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'image' => ['nullable', 'string', 'max:255'],
|
'image' => ['nullable'],
|
||||||
'_upload' => ['nullable'],
|
'_upload' => ['nullable'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Übernimmt einen neuen Upload als Bild und prüft, dass das Bild im öffentlichen Bereich liegt.
|
* Prüft das gewählte Bild. Ein früherer CMS-Pfad mit wirksamer Zuordnung wird zur Kennung des Mediums.
|
||||||
|
* Ein noch als Datei übergebener Upload (frühere Formulare) wird über den Medienmanager aufgenommen.
|
||||||
*
|
*
|
||||||
* @param array<string, mixed> $refs
|
* @param array<string, mixed> $refs
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
public static function clean(array $refs, WidgetErrors $errors, string $key = 'image', ?string $errorKey = null): array
|
public static function clean(array $refs, WidgetErrors $errors, string $key = 'image', ?string $errorKey = null): array
|
||||||
{
|
{
|
||||||
$upload = PublicMedia::fromUploadState($refs['_upload'] ?? null);
|
$images = app(WebsiteImage::class);
|
||||||
$image = $upload ?? PublicMedia::fromUploadState($refs[$key] ?? null);
|
$upload = $refs['_upload'] ?? null;
|
||||||
|
$upload = is_array($upload) ? (array_values($upload)[0] ?? null) : $upload;
|
||||||
|
|
||||||
if ($image !== null && ! PublicMedia::isPublicPath($image)) {
|
if ($upload instanceof TemporaryUploadedFile) {
|
||||||
$errors->add($errorKey ?? "refs.$key", 'Das Bild liegt nicht im öffentlichen Medienbereich.');
|
$element = $images->accept($upload);
|
||||||
|
$refs[$key] = $element?->id ?? $refs[$key] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$refs[$key] = $image;
|
$refs[$key] = $images->clean($refs[$key] ?? null, $errors, $errorKey ?? "refs.$key");
|
||||||
unset($refs['_upload']);
|
unset($refs['_upload']);
|
||||||
|
|
||||||
return $refs;
|
return $refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function statusHtml(mixed $value): HtmlString
|
||||||
|
{
|
||||||
|
$status = app(WebsiteImage::class)->status($value);
|
||||||
|
|
||||||
|
if ($status === null) {
|
||||||
|
return new HtmlString('');
|
||||||
|
}
|
||||||
|
|
||||||
|
$thumb = $status['thumb'] !== null ? '<img src="'.e($status['thumb']).'" alt="">' : '';
|
||||||
|
$link = $status['manageUrl'] !== null
|
||||||
|
? '<a href="'.e($status['manageUrl']).'" target="_blank" rel="noopener">Im Medienmanager öffnen</a>'
|
||||||
|
: '';
|
||||||
|
|
||||||
|
return new HtmlString('<div class="luf-media-status luf-media-status-'.e($status['state']).'">'.$thumb
|
||||||
|
.'<div><strong>'.e($status['title']).'</strong><p>'.e($status['note']).'</p>'.$link.'</div></div>');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -98,10 +98,10 @@ public static function focusFields(int $defaultX = 50, int $defaultY = 50): arra
|
|||||||
public static function altField(): TextInput
|
public static function altField(): TextInput
|
||||||
{
|
{
|
||||||
return TextInput::make('alt')
|
return TextInput::make('alt')
|
||||||
->label('Alternativtext des Bildes')
|
->label('Alternativtext (optional)')
|
||||||
->maxLength(300)
|
->maxLength(300)
|
||||||
->live(onBlur: true)
|
->live(onBlur: true)
|
||||||
->helperText('Beschreibt, was auf dem Bild zu sehen ist. Pflicht, sobald ein Bild gewählt ist.');
|
->helperText('Leer lassen, dann gilt der Alternativtext des Mediums aus dem Medienmanager. Nur ausfüllen, wenn das Bild hier etwas anderes aussagen soll.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,10 +127,6 @@ public static function clean(array $data, WidgetErrors $errors, bool $hasImage):
|
|||||||
$data[$key] = is_numeric($value) ? (int) round(max(0, min(100, (float) $value))) : null;
|
$data[$key] = is_numeric($value) ? (int) round(max(0, min(100, (float) $value))) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($hasImage && $data['alt'] === null) {
|
|
||||||
$errors->add('data.alt', 'Bitte einen Alternativtext für das Bild angeben.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,20 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Domain\Cms\Widgets\Support;
|
namespace App\Domain\Cms\Widgets\Support;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
|
||||||
use Throwable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Öffentlicher Medienbereich der Website ("cms/"). Nur Dateien aus diesem Bereich dürfen in Widgets
|
* Frühere öffentliche CMS-Bilder („cms/“, Route media.public). Neue Bilder kommen aus dem Medienmanager (WebsiteImage);
|
||||||
* verwendet werden. Geschützte Bibliotheksmedien (Inhaltsdateien, Vorschaubilder) sind hier nie wählbar.
|
* dieser Bereich bleibt nur für gespeicherte Revisionen mit früheren Pfaden, die (noch) keinem Medium zugeordnet sind.
|
||||||
*/
|
*/
|
||||||
final class PublicMedia
|
final class PublicMedia
|
||||||
{
|
{
|
||||||
public const PREFIX = 'cms/';
|
public const PREFIX = 'cms/';
|
||||||
|
|
||||||
private const IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'avif'];
|
|
||||||
|
|
||||||
public static function isPublicPath(mixed $path): bool
|
public static function isPublicPath(mixed $path): bool
|
||||||
{
|
{
|
||||||
return is_string($path)
|
return is_string($path)
|
||||||
@@ -29,36 +23,6 @@ public static function url(string $path): string
|
|||||||
return route('media.public', ['path' => $path]);
|
return route('media.public', ['path' => $path]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Bereits vorhandene Bilder im öffentlichen Bereich (veröffentlicht oder zur Veröffentlichung vorgemerkt).
|
|
||||||
*
|
|
||||||
* @return array<string, string>
|
|
||||||
*/
|
|
||||||
public static function imageOptions(): array
|
|
||||||
{
|
|
||||||
$options = [];
|
|
||||||
|
|
||||||
foreach (['media_public', 'cms_incoming'] as $disk) {
|
|
||||||
try {
|
|
||||||
$files = Storage::disk($disk)->allFiles(rtrim(self::PREFIX, '/'));
|
|
||||||
} catch (Throwable) {
|
|
||||||
$files = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
|
|
||||||
|
|
||||||
if (self::isPublicPath($file) && in_array($extension, self::IMAGE_EXTENSIONS, true)) {
|
|
||||||
$options[$file] = substr($file, strlen(self::PREFIX));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ksort($options);
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pfad aus dem Zustand eines Upload-Felds (Zeichenkette oder Liste).
|
* Pfad aus dem Zustand eines Upload-Felds (Zeichenkette oder Liste).
|
||||||
*/
|
*/
|
||||||
@@ -70,31 +34,4 @@ public static function fromUploadState(mixed $state): ?string
|
|||||||
|
|
||||||
return is_string($state) && $state !== '' ? $state : null;
|
return is_string($state) && $state !== '' ? $state : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Bildadresse für Darstellung und Blockvorschau. In der Vorschau kann ein noch nicht gespeicherter Upload vorliegen.
|
|
||||||
*
|
|
||||||
* @param array<string, mixed> $refs
|
|
||||||
*/
|
|
||||||
public static function imageUrl(array $refs, string $key = 'image'): ?string
|
|
||||||
{
|
|
||||||
$upload = $refs['_upload'] ?? null;
|
|
||||||
$upload = is_array($upload) ? (array_values($upload)[0] ?? null) : $upload;
|
|
||||||
|
|
||||||
if ($upload instanceof TemporaryUploadedFile) {
|
|
||||||
try {
|
|
||||||
return $upload->temporaryUrl();
|
|
||||||
} catch (Throwable) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self::isPublicPath($upload)) {
|
|
||||||
return self::url($upload);
|
|
||||||
}
|
|
||||||
|
|
||||||
$path = $refs[$key] ?? null;
|
|
||||||
|
|
||||||
return self::isPublicPath($path) ? self::url($path) : null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,357 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Cms\Widgets\Support;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\EditorialContentKind;
|
||||||
|
use App\Domain\Cms\Catalog\PublicMaterialReader;
|
||||||
|
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||||
|
use App\Domain\Media\ThumbnailRef;
|
||||||
|
use App\Domain\Media\WebsiteIntake;
|
||||||
|
use App\Domain\Media\WebsiteMedia;
|
||||||
|
use App\Domain\Media\WebsiteMediaAlias;
|
||||||
|
use App\Domain\Media\WebsitePresentation;
|
||||||
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bilder in CMS-Widgets und Abschnittshintergründen aus dem zentralen Medienbestand
|
||||||
|
* (docs/architektur/medienzugriff-fuer-komponenten.md).
|
||||||
|
*
|
||||||
|
* Gespeichert wird im jeweiligen Bildschlüssel (refs.image, style.image, data.items[].image) die Kennung des
|
||||||
|
* Inhaltselements (int). Frühere Werte sind Pfade unter cms/ (string):
|
||||||
|
* - mit wirksamer Zuordnung (WebsiteMediaAlias) gelten sie als das zugeordnete Medium,
|
||||||
|
* - ohne Zuordnung gelten sie weiter als öffentliches CMS-Bild (PublicMedia), bis das Widget umgestellt ist.
|
||||||
|
*
|
||||||
|
* Öffentlich erscheint ein Medium nur über WebsiteMedia (Website-Freigabe, Route website.media). In der
|
||||||
|
* Redaktionsvorschau erscheint ein nicht freigegebenes Bild als Vorschaubild der Bibliothek (Route editorial.card)
|
||||||
|
* mit Hinweis. Eine CMS-Verwendung gibt nichts frei.
|
||||||
|
*
|
||||||
|
* Je Anfrage gebunden (scoped): Ergebnisse werden innerhalb einer Anfrage zwischengespeichert.
|
||||||
|
*/
|
||||||
|
class WebsiteImage
|
||||||
|
{
|
||||||
|
/** @var array<string, int|string|null> */
|
||||||
|
private array $resolved = [];
|
||||||
|
|
||||||
|
/** @var array<int, WebsitePresentation|false> */
|
||||||
|
private array $presentations = [];
|
||||||
|
|
||||||
|
public function __construct(private readonly WebsiteMedia $media) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gespeicherter oder eingegebener Wert → Kennung (int), früherer Pfad (string) oder null.
|
||||||
|
*/
|
||||||
|
public static function normalize(mixed $value): int|string|null
|
||||||
|
{
|
||||||
|
if (is_array($value)) {
|
||||||
|
$value = array_values($value)[0] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_int($value) && $value > 0) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_string($value) && preg_match('/^[1-9][0-9]*$/', $value) === 1) {
|
||||||
|
return (int) $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PublicMedia::isPublicPath($value) ? $value : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kennung des Mediums: gespeicherte Kennung oder wirksam zugeordneter früherer Pfad; sonst null.
|
||||||
|
*/
|
||||||
|
public function elementId(mixed $value): ?int
|
||||||
|
{
|
||||||
|
$value = self::normalize($value);
|
||||||
|
|
||||||
|
if (is_int($value)) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! array_key_exists($value, $this->resolved)) {
|
||||||
|
$this->resolved[$value] = WebsiteMediaAlias::effectiveFor($value)?->content_element_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $this->resolved[$value];
|
||||||
|
|
||||||
|
return is_int($id) ? $id : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function presentation(mixed $value): ?WebsitePresentation
|
||||||
|
{
|
||||||
|
$id = $this->elementId($value);
|
||||||
|
|
||||||
|
if ($id === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! array_key_exists($id, $this->presentations)) {
|
||||||
|
$this->presentations[$id] = $this->media->present($id) ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->presentations[$id] ?: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bildadresse für die Darstellung. Öffentlich nur freigegebene Medien (oder frühere CMS-Bilder ohne Zuordnung);
|
||||||
|
* in der Redaktionsvorschau zusätzlich das Vorschaubild eines nicht freigegebenen Mediums.
|
||||||
|
*/
|
||||||
|
public function url(mixed $value, bool $preview = false): ?string
|
||||||
|
{
|
||||||
|
$presentation = $this->presentation($value);
|
||||||
|
|
||||||
|
if ($presentation !== null) {
|
||||||
|
return $presentation->kind === 'bild' ? $presentation->url : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $this->elementId($value);
|
||||||
|
|
||||||
|
if ($id !== null) {
|
||||||
|
if (! $preview) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$element = ContentElement::query()->find($id);
|
||||||
|
|
||||||
|
return $element === null ? null : ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$legacy = self::normalize($value);
|
||||||
|
|
||||||
|
if (is_string($legacy) && WebsiteMediaAlias::isRetired($legacy)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return is_string($legacy) ? PublicMedia::url($legacy) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Alternativtext: Angabe im Widget, sonst der Alternativtext des Mediums. */
|
||||||
|
public function alt(mixed $value, mixed $override = null): string
|
||||||
|
{
|
||||||
|
if (is_string($override) && trim($override) !== '') {
|
||||||
|
return trim($override);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->presentation($value)?->alt ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Öffentliche Quellenzeile des Mediums (nur solange es freigegeben ist). */
|
||||||
|
public function credit(mixed $value): ?string
|
||||||
|
{
|
||||||
|
return $this->presentation($value)?->credit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hinweis für die Redaktionsvorschau, wenn das gewählte Bild öffentlich nicht erscheint; sonst null.
|
||||||
|
*/
|
||||||
|
public function previewNotice(mixed $value, string $label = 'Das gewählte Bild'): ?string
|
||||||
|
{
|
||||||
|
$status = $this->status($value);
|
||||||
|
|
||||||
|
if ($status === null || $status['public']) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $label.' „'.$status['title'].'“ erscheint öffentlich nicht: '.$status['note'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zustand für Editor und Vorschau.
|
||||||
|
*
|
||||||
|
* @return array{public: bool, state: string, title: string, note: string, thumb: ?string, manageUrl: ?string}|null
|
||||||
|
*/
|
||||||
|
public function status(mixed $value): ?array
|
||||||
|
{
|
||||||
|
$value = self::normalize($value);
|
||||||
|
|
||||||
|
if ($value === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $this->elementId($value);
|
||||||
|
|
||||||
|
if ($id === null && WebsiteMediaAlias::isRetired($value)) {
|
||||||
|
return ['public' => false, 'state' => 'missing', 'title' => basename((string) $value), 'note' => 'Das Medium wurde gelöscht.', 'thumb' => null, 'manageUrl' => null];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($id === null) {
|
||||||
|
return [
|
||||||
|
'public' => true,
|
||||||
|
'state' => 'legacy',
|
||||||
|
'title' => basename((string) $value),
|
||||||
|
'note' => 'Früheres CMS-Bild, noch nicht in den Medienmanager übernommen.',
|
||||||
|
'thumb' => PublicMedia::url((string) $value),
|
||||||
|
'manageUrl' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$element = ContentElement::query()->with('editorialContentKind')->find($id);
|
||||||
|
|
||||||
|
if ($element === null) {
|
||||||
|
return ['public' => false, 'state' => 'missing', 'title' => 'Medium '.$id, 'note' => 'Das Medium gibt es nicht mehr.', 'thumb' => null, 'manageUrl' => null];
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = (string) ($element->display_title ?: $element->working_title);
|
||||||
|
$thumb = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path);
|
||||||
|
$manageUrl = ContentElementResource::getUrl('view', ['record' => $element]);
|
||||||
|
$public = $this->presentation($id) !== null;
|
||||||
|
|
||||||
|
$note = match (true) {
|
||||||
|
$public => 'Für die Website freigegeben.',
|
||||||
|
$element->archived_at !== null => 'Das Medium ist archiviert.',
|
||||||
|
filled($element->thumbnail_error) => 'Die Datei ließ sich nicht verarbeiten: '.Str::limit((string) $element->thumbnail_error, 120),
|
||||||
|
$element->thumbnail_path === null => 'Wird gerade verarbeitet. Danach wird es automatisch für die Website freigegeben.',
|
||||||
|
default => 'Nicht für die Website freigegeben. Die Freigabe steht im Medienmanager beim Medium unter „Beschreibung“ (Website-Freigabe).',
|
||||||
|
};
|
||||||
|
|
||||||
|
return [
|
||||||
|
'public' => $public,
|
||||||
|
'state' => $public ? 'released' : ($element->thumbnail_path === null && ! filled($element->thumbnail_error) ? 'pending' : 'unreleased'),
|
||||||
|
'title' => $title,
|
||||||
|
'note' => $note,
|
||||||
|
'thumb' => $thumb,
|
||||||
|
'manageUrl' => $manageUrl,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prüft einen Wert beim Speichern. Ein früherer Pfad mit wirksamer Zuordnung wird zur Kennung des Mediums.
|
||||||
|
*/
|
||||||
|
public function clean(mixed $value, WidgetErrors $errors, string $errorKey): int|string|null
|
||||||
|
{
|
||||||
|
$raw = is_array($value) ? (array_values($value)[0] ?? null) : $value;
|
||||||
|
$value = self::normalize($raw);
|
||||||
|
|
||||||
|
if ($value === null) {
|
||||||
|
if ($raw !== null && $raw !== '') {
|
||||||
|
$errors->add($errorKey, 'Bitte ein Bild aus dem Medienmanager wählen.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_string($value)) {
|
||||||
|
return $this->elementId($value) ?? $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$element = ContentElement::query()->find($value);
|
||||||
|
|
||||||
|
if ($element === null || ! self::isSelectable($element)) {
|
||||||
|
$errors->add($errorKey, 'Dieses Medium ist kein Bild für die Website (nur Bilder aus dem Medienmanager, keine Traineranleitungen).');
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $element->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isSelectable(ContentElement $element): bool
|
||||||
|
{
|
||||||
|
if ($element->output_class !== 'bild' || $element->archived_at !== null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$slug = $element->editorialContentKind?->slug
|
||||||
|
?? ($element->editorial_content_kind_id !== null ? EditorialContentKind::query()->whereKey($element->editorial_content_kind_id)->value('slug') : null);
|
||||||
|
|
||||||
|
return ! in_array($slug, PublicMaterialReader::CONFIDENTIAL_KINDS, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auswahl für den Medienpicker: Bilder aus dem Medienmanager mit Vorschaubild, Titel und Freigabestatus (HTML).
|
||||||
|
*
|
||||||
|
* @return array<int, string>
|
||||||
|
*/
|
||||||
|
public function options(?string $search = null, int $limit = 60): array
|
||||||
|
{
|
||||||
|
$search = trim((string) $search);
|
||||||
|
|
||||||
|
$elements = ContentElement::query()
|
||||||
|
->with('editorialContentKind')
|
||||||
|
->where('output_class', 'bild')
|
||||||
|
->whereNull('archived_at')
|
||||||
|
->when($search !== '', function ($query) use ($search): void {
|
||||||
|
$like = '%'.mb_strtolower($search).'%';
|
||||||
|
$query->where(fn ($inner) => $inner
|
||||||
|
->whereRaw('LOWER(working_title) LIKE ?', [$like])
|
||||||
|
->orWhereRaw('LOWER(COALESCE(display_title, \'\')) LIKE ?', [$like]));
|
||||||
|
})
|
||||||
|
->orderByDesc('id')
|
||||||
|
->limit($limit)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$options = [];
|
||||||
|
foreach ($elements as $element) {
|
||||||
|
if (self::isSelectable($element)) {
|
||||||
|
$options[$element->id] = $this->optionHtml($element->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** HTML-Bezeichnung einer Option oder des gewählten Werts (auch für frühere Pfade). */
|
||||||
|
public function optionHtml(mixed $value): ?string
|
||||||
|
{
|
||||||
|
$status = $this->status($value);
|
||||||
|
|
||||||
|
if ($status === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$badge = match ($status['state']) {
|
||||||
|
'released' => ['ok', 'Website: freigegeben'],
|
||||||
|
'pending' => ['wait', 'Wird verarbeitet'],
|
||||||
|
'legacy' => ['quiet', 'Früheres CMS-Bild'],
|
||||||
|
default => ['warn', 'Website: nicht freigegeben'],
|
||||||
|
};
|
||||||
|
$thumb = $status['thumb'] !== null
|
||||||
|
? '<img src="'.e($status['thumb']).'" alt="" loading="lazy">'
|
||||||
|
: '<span class="luf-media-option-empty" aria-hidden="true"></span>';
|
||||||
|
|
||||||
|
return '<span class="luf-media-option">'.$thumb
|
||||||
|
.'<span class="luf-media-option-text"><strong>'.e($status['title']).'</strong>'
|
||||||
|
.'<span class="luf-media-badge luf-media-badge-'.$badge[0].'">'.e($badge[1]).'</span></span></span>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Neues Bild direkt aus dem CMS: Datei in den Eingang legen und über WebsiteIntake als Medium anlegen.
|
||||||
|
* Die Warteschlange leitet das Bild ab und gibt die Ableitung für die Website frei.
|
||||||
|
*/
|
||||||
|
public function accept(TemporaryUploadedFile $file, ?string $alt = null): ?ContentElement
|
||||||
|
{
|
||||||
|
$base = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)) ?: 'bild';
|
||||||
|
$name = $base.'-'.Str::lower(Str::random(6)).'.'.($file->guessExtension() ?: 'jpg');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$path = $file->storeAs('cms', $name, 'cms_incoming');
|
||||||
|
} catch (Throwable $exception) {
|
||||||
|
report($exception);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! is_string($path) || $path === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$actor = auth('staff')->user();
|
||||||
|
|
||||||
|
return app(WebsiteIntake::class)->acceptImage(
|
||||||
|
$path,
|
||||||
|
Str::title(str_replace(['-', '_'], ' ', $base)),
|
||||||
|
null,
|
||||||
|
filled($alt) ? trim((string) $alt) : null,
|
||||||
|
$actor instanceof User ? $actor : null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
||||||
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
||||||
use App\Domain\Cms\Widgets\Support\SafeUrl;
|
use App\Domain\Cms\Widgets\Support\SafeUrl;
|
||||||
|
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||||
use App\Domain\Cms\Widgets\WidgetType;
|
use App\Domain\Cms\Widgets\WidgetType;
|
||||||
use Filament\Forms\Components\Repeater;
|
use Filament\Forms\Components\Repeater;
|
||||||
@@ -84,14 +85,14 @@ public function dataRules(): array
|
|||||||
'items.*.title' => ['required', 'string', 'max:120'],
|
'items.*.title' => ['required', 'string', 'max:120'],
|
||||||
'items.*.text' => ['nullable', 'string', 'max:500'],
|
'items.*.text' => ['nullable', 'string', 'max:500'],
|
||||||
'items.*.url' => ['nullable', 'string', 'max:500'],
|
'items.*.url' => ['nullable', 'string', 'max:500'],
|
||||||
'items.*.image' => ['nullable', 'string', 'max:255'],
|
'items.*.image' => ['nullable'],
|
||||||
'items.*._upload' => ['nullable'],
|
'items.*._upload' => ['nullable'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataFields(): array
|
public function dataFields(): array
|
||||||
{
|
{
|
||||||
[$image, $upload] = ImageRefFields::fields('Bild (optional)');
|
[$image, $upload, $status] = ImageRefFields::fields('Bild (optional)');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Repeater::make('items')
|
Repeater::make('items')
|
||||||
@@ -106,6 +107,7 @@ public function dataFields(): array
|
|||||||
->helperText('Seitenpfad wie /praevention oder eine http(s)-Adresse. Leer lassen für eine Karte ohne Link.'),
|
->helperText('Seitenpfad wie /praevention oder eine http(s)-Adresse. Leer lassen für eine Karte ohne Link.'),
|
||||||
$image,
|
$image,
|
||||||
$upload,
|
$upload,
|
||||||
|
$status,
|
||||||
])
|
])
|
||||||
->minItems(1)
|
->minItems(1)
|
||||||
->maxItems(12)
|
->maxItems(12)
|
||||||
@@ -139,7 +141,9 @@ public function clean(array $data, array $refs, WidgetErrors $errors): array
|
|||||||
|
|
||||||
public function resolve(array $widget, RenderContext $context): array
|
public function resolve(array $widget, RenderContext $context): array
|
||||||
{
|
{
|
||||||
|
$images = app(WebsiteImage::class);
|
||||||
$items = [];
|
$items = [];
|
||||||
|
$notices = [];
|
||||||
|
|
||||||
foreach ($widget['data']['items'] ?? [] as $item) {
|
foreach ($widget['data']['items'] ?? [] as $item) {
|
||||||
if (! is_array($item) || ! filled($item['title'] ?? null)) {
|
if (! is_array($item) || ! filled($item['title'] ?? null)) {
|
||||||
@@ -150,11 +154,15 @@ public function resolve(array $widget, RenderContext $context): array
|
|||||||
'title' => $item['title'],
|
'title' => $item['title'],
|
||||||
'text' => $item['text'] ?? null,
|
'text' => $item['text'] ?? null,
|
||||||
'url' => SafeUrl::isSafe($item['url'] ?? null) ? $item['url'] : null,
|
'url' => SafeUrl::isSafe($item['url'] ?? null) ? $item['url'] : null,
|
||||||
'imageUrl' => PublicMedia::imageUrl($item),
|
'imageUrl' => $images->url($item['image'] ?? null, $context->preview),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($context->preview && ($notice = $images->previewNotice($item['image'] ?? null, 'Das Bild der Karte „'.$item['title'].'“')) !== null) {
|
||||||
|
$notices[] = $notice;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['items' => $items];
|
return ['items' => $items, 'imageNotice' => $notices === [] ? null : implode(' ', $notices)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function mediaPaths(array $widget): array
|
public function mediaPaths(array $widget): array
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
||||||
use App\Domain\Cms\Widgets\Support\PremiumFields;
|
use App\Domain\Cms\Widgets\Support\PremiumFields;
|
||||||
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
||||||
|
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||||
use App\Domain\Cms\Widgets\WidgetType;
|
use App\Domain\Cms\Widgets\WidgetType;
|
||||||
use Filament\Forms\Components\Textarea;
|
use Filament\Forms\Components\Textarea;
|
||||||
@@ -202,8 +203,13 @@ public function resolve(array $widget, RenderContext $context): array
|
|||||||
{
|
{
|
||||||
$actions = PremiumFields::actions($widget['data']);
|
$actions = PremiumFields::actions($widget['data']);
|
||||||
|
|
||||||
|
$images = app(WebsiteImage::class);
|
||||||
|
$image = $widget['refs']['image'] ?? null;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'imageUrl' => PublicMedia::imageUrl($widget['refs']),
|
'imageUrl' => $images->url($image, $context->preview),
|
||||||
|
'imageAlt' => $images->alt($image, $widget['data']['alt'] ?? null),
|
||||||
|
'imageNotice' => $context->preview ? $images->previewNotice($image) : null,
|
||||||
'actions' => $actions,
|
'actions' => $actions,
|
||||||
'action' => $actions[0] ?? null,
|
'action' => $actions[0] ?? null,
|
||||||
'focus' => PremiumFields::focus($widget['data'], 68, 50),
|
'focus' => PremiumFields::focus($widget['data'], 68, 50),
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
use App\Domain\Cms\Widgets\Support\PremiumFields;
|
use App\Domain\Cms\Widgets\Support\PremiumFields;
|
||||||
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
||||||
use App\Domain\Cms\Widgets\Support\RichText;
|
use App\Domain\Cms\Widgets\Support\RichText;
|
||||||
|
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||||
use App\Domain\Cms\Widgets\WidgetType;
|
use App\Domain\Cms\Widgets\WidgetType;
|
||||||
use Filament\Forms\Components\RichEditor;
|
use Filament\Forms\Components\RichEditor;
|
||||||
@@ -229,8 +230,13 @@ public function resolve(array $widget, RenderContext $context): array
|
|||||||
{
|
{
|
||||||
$surface = $widget['settings']['surface'] ?? 'cream';
|
$surface = $widget['settings']['surface'] ?? 'cream';
|
||||||
|
|
||||||
|
$images = app(WebsiteImage::class);
|
||||||
|
$image = $widget['refs']['image'] ?? null;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'imageUrl' => PublicMedia::imageUrl($widget['refs']),
|
'imageUrl' => $images->url($image, $context->preview),
|
||||||
|
'imageAlt' => $images->alt($image, $widget['data']['alt'] ?? null),
|
||||||
|
'imageNotice' => $context->preview ? $images->previewNotice($image) : null,
|
||||||
'body' => RichText::sanitize(is_string($widget['data']['body'] ?? null) ? $widget['data']['body'] : ''),
|
'body' => RichText::sanitize(is_string($widget['data']['body'] ?? null) ? $widget['data']['body'] : ''),
|
||||||
'actions' => PremiumFields::actions($widget['data']),
|
'actions' => PremiumFields::actions($widget['data']),
|
||||||
'focus' => PremiumFields::focus($widget['data'], 64, 43),
|
'focus' => PremiumFields::focus($widget['data'], 64, 43),
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Cms\Widgets\Types;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\PresentationMedia;
|
||||||
|
use App\Domain\Cms\Catalog\CardSubject;
|
||||||
|
use App\Domain\Cms\Catalog\PublicMaterialReader;
|
||||||
|
use App\Domain\Cms\Widgets\RenderContext;
|
||||||
|
use App\Domain\Media\FilmStill;
|
||||||
|
use App\Domain\Media\ThumbnailRef;
|
||||||
|
use Filament\Forms\Components\ViewField;
|
||||||
|
use Filament\Schemas\Components\Utilities\Get;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Medien- und Materialkarte (Kit v1.7 „media“): ein Inhaltselement mit Anzeigetitel, Kurzbeschreibung, Inhaltsart und
|
||||||
|
* Ausgabeart. Filme erscheinen als Medienkarte (grüne Aktion, Filmtafel ohne freigegebenes Bild), Dokumente und andere
|
||||||
|
* Materialien als Materialkarte (Materialsymbol). Öffentlich nur nach den Regeln von PublicMaterialReader; die Aktion
|
||||||
|
* führt auf die öffentliche Programmseite. Die Karte spielt nichts ab, bietet keinen Download und gibt kein Medium frei.
|
||||||
|
*/
|
||||||
|
class MediaCardWidget extends PremiumCardWidget
|
||||||
|
{
|
||||||
|
public function key(): string
|
||||||
|
{
|
||||||
|
return 'media_card';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return 'Medien- und Materialkarte';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function description(): string
|
||||||
|
{
|
||||||
|
return 'Karte zu einem Film oder Material aus der Bibliothek; Titel und Art kommen aus den Fachdaten, kein Abspielen, kein Download.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function icon(): string
|
||||||
|
{
|
||||||
|
return 'heroicon-o-film';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function schematic(): array
|
||||||
|
{
|
||||||
|
return [[2, 2, 56, 32, 'line'], [5, 5, 22, 26, 'image'], [7, 7, 8, 3, 'accent'], [31, 8, 22, 4, 'ink'], [31, 15, 22, 5, 'line'], [31, 25, 14, 5, 'accent']];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function refKey(): string
|
||||||
|
{
|
||||||
|
return 'element';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function refLabel(): string
|
||||||
|
{
|
||||||
|
return 'Medium oder Material';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function refHelp(): string
|
||||||
|
{
|
||||||
|
return 'Wählbar sind alle nicht archivierten, nicht gesperrten Filme und Materialien. Öffentlich erscheint die Karte nur mit bereitgestellter Fassung und wenn der Inhalt zu einem öffentlich gezeigten Programm gehört; Traineranleitungen nie. Titel, Teaser, Kurzbeschreibung und Beschreibung pflegen Sie im Medium; welcher Text auf der Karte erscheint, wählen Sie unter „Darstellung“.';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function searchSubjects(?string $term): array
|
||||||
|
{
|
||||||
|
return app(PublicMaterialReader::class)->search($term);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function subjectLabel(mixed $id): ?string
|
||||||
|
{
|
||||||
|
return app(PublicMaterialReader::class)->labelFor($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function rejectSubject(int $id): ?string
|
||||||
|
{
|
||||||
|
$element = ContentElement::query()->find($id);
|
||||||
|
|
||||||
|
return $element !== null && app(PublicMaterialReader::class)->isSelectable($element)
|
||||||
|
? null
|
||||||
|
: 'Dieser Inhalt ist archiviert oder gesperrt.';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function subject(mixed $id, RenderContext $context): ?CardSubject
|
||||||
|
{
|
||||||
|
return app(PublicMaterialReader::class)->subject($id, includeNonPublic: $context->preview);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function defaultActionLabel(): string
|
||||||
|
{
|
||||||
|
return 'Im Programm ansehen';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function cardStyle(): string
|
||||||
|
{
|
||||||
|
return 'media';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bei einem Film: das Vorschaubild des Films oder eine Stelle des Films als Kartenbild übernehmen. Das Bild wird
|
||||||
|
* einmal als Bild-Medium abgelegt (FilmStill) und wie jedes andere Bild ausgewählt; die Karte liest nur diese Datei.
|
||||||
|
*/
|
||||||
|
protected function imageSourceFields(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
ViewField::make('_filmbild')
|
||||||
|
->label('Bild aus dem Film')
|
||||||
|
->view('filament.cms.filmbild-feld')
|
||||||
|
->dehydrated(false)
|
||||||
|
->visible(fn (Get $get): bool => $this->filmFor($get('element')) !== null)
|
||||||
|
->viewData(function (Get $get): array {
|
||||||
|
$film = $this->filmFor($get('element'));
|
||||||
|
$stills = app(FilmStill::class);
|
||||||
|
$version = $film instanceof ContentElement ? $stills->version($film) : null;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'film' => $film,
|
||||||
|
'filmTitle' => $film instanceof ContentElement ? (string) ($film->display_title ?: $film->working_title) : '',
|
||||||
|
'filmVersionId' => $version?->id,
|
||||||
|
'filmHasThumbnail' => $film instanceof ContentElement && is_string($film->thumbnail_path) && $film->thumbnail_path !== '',
|
||||||
|
'filmThumbnailUrl' => $film instanceof ContentElement ? ThumbnailRef::url('editorial.card', 'element', (int) $film->id, $film->thumbnail_path) : null,
|
||||||
|
'filmStartSecond' => $film instanceof ContentElement ? ($stills->thumbnailSecond($film) ?? '0') : '0',
|
||||||
|
];
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function filmFor(mixed $id): ?ContentElement
|
||||||
|
{
|
||||||
|
$element = is_numeric($id) ? ContentElement::query()->with('editorialContentKind')->find((int) $id) : null;
|
||||||
|
|
||||||
|
return $element instanceof ContentElement && app(FilmStill::class)->refusal($element) === null ? $element : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function subjectNoun(): string
|
||||||
|
{
|
||||||
|
return 'Medium';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function textChoices(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'auto' => 'Automatisch (Kurzbeschreibung, sonst Teaser)',
|
||||||
|
'teaser' => 'Teaser',
|
||||||
|
'summary' => 'Kurzbeschreibung',
|
||||||
|
'description' => 'Ausführliche Beschreibung (erscheint öffentlich)',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function centralCoverId(mixed $id): ?int
|
||||||
|
{
|
||||||
|
$element = is_numeric($id) ? ContentElement::query()->find((int) $id) : null;
|
||||||
|
|
||||||
|
return $element instanceof ContentElement
|
||||||
|
? app(PresentationMedia::class)->coverElementId($element)
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,389 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Cms\Widgets\Types;
|
||||||
|
|
||||||
|
use App\Domain\Cms\Catalog\CardSubject;
|
||||||
|
use App\Domain\Cms\Widgets\RenderContext;
|
||||||
|
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
||||||
|
use App\Domain\Cms\Widgets\Support\PremiumFields;
|
||||||
|
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
||||||
|
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||||
|
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||||
|
use App\Domain\Cms\Widgets\WidgetType;
|
||||||
|
use Filament\Forms\Components\Field;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Schemas\Components\Group;
|
||||||
|
use Filament\Schemas\Components\Utilities\Get;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gemeinsame Basis der Premium-Karten (Brand-UI-Kit v1.7, Entwurf zur visuellen Freigabe):
|
||||||
|
* Redaktionelle Themenkarte, Medien- und Materialkarte, Modul- und Programmkarte.
|
||||||
|
*
|
||||||
|
* - Eine Karte je Widget, ein Widget je Platz. Das Raster ist das bestehende Abschnittsraster (1 bis 4 Einheiten);
|
||||||
|
* es gibt kein zweites Kartenraster.
|
||||||
|
* - refs: genau ein Fachobjekt (Kennung) und optional ein Bild aus dem öffentlichen Website-Bereich.
|
||||||
|
* Titel, Kurzbeschreibung, Art, Zusatzangaben und Linkziel kommen zur Laufzeit aus den Fachdaten.
|
||||||
|
* - data: nur Redaktionelles, das es im Fachobjekt nicht gibt: Beschriftung der Aktion, Hinweis, Alternativtext,
|
||||||
|
* Bildausschnitt. Ein freies Linkziel gibt es nicht; das Ziel ist immer die öffentliche Seite des Fachobjekts.
|
||||||
|
* - Bilder der Bibliothek (Vorschaubilder, Filmstandbilder) werden nie gezeigt.
|
||||||
|
*/
|
||||||
|
abstract class PremiumCardWidget extends WidgetType
|
||||||
|
{
|
||||||
|
public const SHOW = ['yes' => 'Anzeigen', 'no' => 'Ausblenden'];
|
||||||
|
|
||||||
|
/** Schlüssel des Fachobjekts in refs, zum Beispiel 'pillar'. */
|
||||||
|
abstract protected function refKey(): string;
|
||||||
|
|
||||||
|
abstract protected function refLabel(): string;
|
||||||
|
|
||||||
|
abstract protected function refHelp(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, string>
|
||||||
|
*/
|
||||||
|
abstract protected function searchSubjects(?string $term): array;
|
||||||
|
|
||||||
|
abstract protected function subjectLabel(mixed $id): ?string;
|
||||||
|
|
||||||
|
/** Prüft beim Speichern, ob das Objekt gewählt werden darf; liefert sonst die Fehlermeldung. */
|
||||||
|
abstract protected function rejectSubject(int $id): ?string;
|
||||||
|
|
||||||
|
abstract protected function subject(mixed $id, RenderContext $context): ?CardSubject;
|
||||||
|
|
||||||
|
abstract protected function defaultActionLabel(): string;
|
||||||
|
|
||||||
|
/** Gestaltungsvariante des Kits: editorial, media oder catalog. */
|
||||||
|
abstract protected function cardStyle(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Weitere Wege zum Kartenbild im Reiter „Medien“, zum Beispiel ein Bild aus dem Film. Standard: keine.
|
||||||
|
*
|
||||||
|
* @return list<Field>
|
||||||
|
*/
|
||||||
|
protected function imageSourceFields(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zentrale Texte des Fachobjekts, aus denen die Redaktion den Kartentext wählen kann: Wert => Bezeichnung.
|
||||||
|
* Leer: keine Wahl (die Karte nimmt den Text ihrer Vorgabe). Mit Wahl gilt „auto“ als Vorgabe.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function textChoices(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Was die Redaktion bearbeitet, um einen Text zu pflegen („Medium“, „Programm oder Modul“); für Hinweise. */
|
||||||
|
protected function subjectNoun(): string
|
||||||
|
{
|
||||||
|
return 'Objekt';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Hinweis der Redaktionsvorschau, wenn der gewählte zentrale Text nicht gepflegt ist. */
|
||||||
|
private function missingTextHint(string $field): string
|
||||||
|
{
|
||||||
|
$noun = $this->subjectNoun();
|
||||||
|
|
||||||
|
return match ($field) {
|
||||||
|
'teaser' => 'Kein Teaser gepflegt ('.$noun.' bearbeiten → Teaser).',
|
||||||
|
'summary' => 'Keine Kurzbeschreibung gepflegt ('.$noun.' bearbeiten → Kurzbeschreibung).',
|
||||||
|
'description' => 'Keine ausführliche Beschreibung gepflegt ('.$noun.' bearbeiten → Beschreibung).',
|
||||||
|
'goal' => 'Kein Lernziel gepflegt ('.$noun.' bearbeiten → Lernziel der Fassung).',
|
||||||
|
default => '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view(): string
|
||||||
|
{
|
||||||
|
return 'widgets.premium_card';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportedUnits(): array
|
||||||
|
{
|
||||||
|
return [1, 2, 3, 4];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function preferredUnits(): int
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'stacked' => 'unter 520 px Kartenbreite: Bild oder Tafel über dem Text',
|
||||||
|
'side' => 'ab 520 px: Bild links (42 %), Text rechts (58 %); das gewählte Bildformat bleibt erhalten',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function narrowBehavior(): string
|
||||||
|
{
|
||||||
|
return 'Unter 520 px Kartenbreite steht das Bild über dem Text. Ab etwa 240 px nutzbar, empfohlen ab 280 px (eine Einheit ab Tablet). Texte werden nie gekürzt.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function heights(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'auto' => 'Natürliche Höhe',
|
||||||
|
'fill' => 'An die Zeile angleichen',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function variants(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'adaptive' => 'Anpassend (ab 520 px Bild neben Text)',
|
||||||
|
'stacked' => 'Bild immer über dem Text',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function optionIcons(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'variant' => ['adaptive' => 'heroicon-o-view-columns', 'stacked' => 'heroicon-o-bars-3-bottom-left'],
|
||||||
|
'height' => ['auto' => 'heroicon-o-arrows-pointing-in', 'fill' => 'heroicon-o-arrows-up-down'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settings(): array
|
||||||
|
{
|
||||||
|
$choices = $this->textChoices();
|
||||||
|
|
||||||
|
return ($choices === [] ? [] : ['text_source' => $choices]) + [
|
||||||
|
'format' => ['landscape' => 'Querformat 16:9', 'square' => 'Quadrat 1:1', 'portrait' => 'Hochformat 3:4'],
|
||||||
|
'fit' => ['cover' => 'Ausschnitt füllt die Fläche', 'contain' => 'Ganzes Bild zeigen (Dokument, Poster)'],
|
||||||
|
'heading_level' => ['h3' => 'H3', 'h2' => 'H2', 'h4' => 'H4'],
|
||||||
|
'show_summary' => self::SHOW,
|
||||||
|
'show_kind' => self::SHOW,
|
||||||
|
'show_meta' => self::SHOW,
|
||||||
|
'show_action' => self::SHOW,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settingLabels(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'text_source' => ['Text der Karte', 'Welche Angabe aus der Redaktion die Karte zeigt. Vorgabe: Automatisch. Der gewählte Text erscheint öffentlich, wenn die Karte öffentlich ist; ist er nicht gepflegt, bleibt die Karte ohne Text.'],
|
||||||
|
'format' => ['Bildformat', 'Vorgabe: Querformat 16:9. Gilt auch neben dem Text; das Motiv wird nicht nachträglich hochkant beschnitten.'],
|
||||||
|
'fit' => ['Bilddarstellung', 'Vorgabe: Ausschnitt. „Ganzes Bild“ zeigt Dokumente und Poster vollständig auf ruhiger Fläche.'],
|
||||||
|
'heading_level' => ['Überschriftenebene', 'Vorgabe: H3, passend unter einer Abschnittsüberschrift (H2).'],
|
||||||
|
'show_summary' => ['Text anzeigen', 'Aus den Fachdaten. Vorgabe: anzeigen.'],
|
||||||
|
'show_kind' => ['Art oder Label', 'Zum Beispiel „Thema“ oder „Merkblatt“. Vorgabe: anzeigen.'],
|
||||||
|
'show_meta' => ['Zusatzangaben', 'Aus den Fachdaten, zum Beispiel Ausgabeart oder Programmzugehörigkeit. Vorgabe: anzeigen.'],
|
||||||
|
'show_action' => ['Aktion', 'Verweis auf die öffentliche Seite des Fachobjekts, falls es eine gibt. Vorgabe: anzeigen.'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dataRules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'action_label' => ['nullable', 'string', 'max:60'],
|
||||||
|
'note' => ['nullable', 'string', 'max:200'],
|
||||||
|
'heading' => ['nullable', 'string', 'max:200'],
|
||||||
|
'summary' => ['nullable', 'string', 'max:500'],
|
||||||
|
'alt' => ['nullable', 'string', 'max:300'],
|
||||||
|
'focus_x' => ['nullable', 'numeric', 'between:0,100'],
|
||||||
|
'focus_y' => ['nullable', 'numeric', 'between:0,100'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function refRules(): array
|
||||||
|
{
|
||||||
|
return [$this->refKey() => ['required', 'integer']] + ImageRefFields::rules();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dataFields(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
TextInput::make('action_label')
|
||||||
|
->label('Beschriftung der Aktion (optional)')
|
||||||
|
->maxLength(60)
|
||||||
|
->placeholder($this->defaultActionLabel())
|
||||||
|
->live(onBlur: true)
|
||||||
|
->helperText('Das Linkziel ist immer die öffentliche Seite des gewählten Objekts und kann nicht frei gesetzt werden.'),
|
||||||
|
TextInput::make('note')
|
||||||
|
->label('Hinweis (optional)')
|
||||||
|
->maxLength(200)
|
||||||
|
->live(onBlur: true)
|
||||||
|
->helperText('Kurzer redaktioneller Satz über der Aktion, zum Beispiel „Für die nächste Kursstunde“. Begründet keine Berechtigung.'),
|
||||||
|
PremiumFields::altField(),
|
||||||
|
...PremiumFields::focusFields(66, 45),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function refFields(): array
|
||||||
|
{
|
||||||
|
return [$this->subjectField(), ...ImageRefFields::fields(live: true)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function editorSchema(): array
|
||||||
|
{
|
||||||
|
[$action, $note] = $this->dataFields();
|
||||||
|
|
||||||
|
return [
|
||||||
|
Group::make([$this->subjectField()])->statePath('refs'),
|
||||||
|
Group::make([
|
||||||
|
$action,
|
||||||
|
$note,
|
||||||
|
// Zentrale Angaben aus der Redaktion als Platzhalter; eine eigene Eintragung ist als solche markiert.
|
||||||
|
TextInput::make('heading')
|
||||||
|
->label('Anzeigename nur für diese Karte')
|
||||||
|
->maxLength(200)
|
||||||
|
->live(onBlur: true)
|
||||||
|
->placeholder(fn (Get $get): string => $this->centralText($get('../refs.'.$this->refKey()), 'title') ?? 'Zentraler Anzeigename')
|
||||||
|
->hint(fn (?string $state): string => filled($state) ? 'Eigene Angabe für diese Karte' : 'Aus der Redaktion')
|
||||||
|
->hintColor(fn (?string $state): string => filled($state) ? 'warning' : 'gray')
|
||||||
|
->helperText('Leer übernimmt den Anzeigenamen des Fachobjekts. Eine Eintragung gilt nur für diese Karte und ändert die Quelle nicht.'),
|
||||||
|
TextInput::make('summary')
|
||||||
|
->label('Text nur für diese Karte')
|
||||||
|
->maxLength(500)
|
||||||
|
->live(onBlur: true)
|
||||||
|
->placeholder(fn (Get $get): string => $this->centralText($get('../refs.'.$this->refKey()), 'summary', $get('../settings.text_source')) ?? 'Zentraler Text aus der Redaktion')
|
||||||
|
->hint(fn (?string $state): string => filled($state) ? 'Eigene Angabe für diese Karte' : 'Aus der Redaktion')
|
||||||
|
->hintColor(fn (?string $state): string => filled($state) ? 'warning' : 'gray')
|
||||||
|
->helperText('Leer übernimmt den Text, den „Text der Karte“ (Darstellung) wählt. Lehrinhalt, Rechte und Preise bleiben unberührt.'),
|
||||||
|
])->statePath('data'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mediaSchema(): array
|
||||||
|
{
|
||||||
|
[, , $alt, $focusX, $focusY] = $this->dataFields();
|
||||||
|
|
||||||
|
return [
|
||||||
|
Group::make([...ImageRefFields::fields('Kartenbild', live: true), ...$this->imageSourceFields()])->statePath('refs'),
|
||||||
|
Group::make([$alt, $focusX, $focusY])->statePath('data'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||||
|
{
|
||||||
|
$key = $this->refKey();
|
||||||
|
$id = (int) $refs[$key];
|
||||||
|
$rejection = $this->rejectSubject($id);
|
||||||
|
|
||||||
|
if ($rejection !== null) {
|
||||||
|
$errors->add("refs.$key", $rejection);
|
||||||
|
}
|
||||||
|
|
||||||
|
$refs[$key] = $id;
|
||||||
|
$refs = ImageRefFields::clean($refs, $errors);
|
||||||
|
|
||||||
|
foreach (['action_label', 'note', 'alt', 'heading', 'summary'] as $field) {
|
||||||
|
$data[$field] = filled($data[$field] ?? null) ? trim((string) $data[$field]) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (['focus_x', 'focus_y'] as $field) {
|
||||||
|
$value = $data[$field] ?? null;
|
||||||
|
$data[$field] = is_numeric($value) ? (int) round(max(0, min(100, (float) $value))) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [$data, $refs];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resolve(array $widget, RenderContext $context): array
|
||||||
|
{
|
||||||
|
$settings = $widget['settings'];
|
||||||
|
$option = fn (string $key, string $default): string => is_string($settings[$key] ?? null) && isset($this->settingOptions()[$key][$settings[$key]]) ? $settings[$key] : $default;
|
||||||
|
$data = $widget['data'];
|
||||||
|
|
||||||
|
$subject = $this->subject($widget['refs'][$this->refKey()] ?? null, $context);
|
||||||
|
$textSource = $option('text_source', 'auto');
|
||||||
|
|
||||||
|
if ($subject instanceof CardSubject && $textSource !== 'auto' && isset($this->textChoices()[$textSource])) {
|
||||||
|
$subject = $subject->withTextChoice($textSource, $this->missingTextHint($textSource));
|
||||||
|
}
|
||||||
|
|
||||||
|
$heading = filled($data['heading'] ?? null) ? trim((string) $data['heading']) : null;
|
||||||
|
$lead = filled($data['summary'] ?? null) ? trim((string) $data['summary']) : null;
|
||||||
|
|
||||||
|
if ($subject instanceof CardSubject && ($heading !== null || $lead !== null)) {
|
||||||
|
$subject = $subject->withText($heading, $lead);
|
||||||
|
}
|
||||||
|
|
||||||
|
$storedImage = WebsiteImage::normalize($widget['refs']['image'] ?? null);
|
||||||
|
$imageRef = $storedImage ?? $this->centralCoverId($widget['refs'][$this->refKey()] ?? null);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'subject' => $subject,
|
||||||
|
'cardStyle' => $subject?->style ?? $this->cardStyle(),
|
||||||
|
'imageUrl' => app(WebsiteImage::class)->url($imageRef, $context->preview),
|
||||||
|
'alt' => app(WebsiteImage::class)->alt($imageRef, $data['alt'] ?? null),
|
||||||
|
'imageNotice' => $context->preview ? app(WebsiteImage::class)->previewNotice($imageRef, 'Das Kartenbild') : null,
|
||||||
|
'focus' => PremiumFields::focus($data, 66, 45),
|
||||||
|
'format' => $option('format', 'landscape'),
|
||||||
|
'fit' => $option('fit', 'cover'),
|
||||||
|
'headingTag' => $option('heading_level', 'h3'),
|
||||||
|
'show' => [
|
||||||
|
'summary' => ! array_key_exists('show_summary', $this->settings()) || $option('show_summary', 'yes') === 'yes',
|
||||||
|
'kind' => ! array_key_exists('show_kind', $this->settings()) || $option('show_kind', 'yes') === 'yes',
|
||||||
|
'meta' => $option('show_meta', 'yes') === 'yes',
|
||||||
|
'action' => $option('show_action', 'yes') === 'yes',
|
||||||
|
],
|
||||||
|
'actionLabel' => filled($data['action_label'] ?? null) ? (string) $data['action_label'] : $this->defaultActionLabel(),
|
||||||
|
'note' => filled($data['note'] ?? null) ? (string) $data['note'] : null,
|
||||||
|
'stacked' => $widget['variant'] === 'stacked',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mediaPaths(array $widget): array
|
||||||
|
{
|
||||||
|
$image = $widget['refs']['image'] ?? null;
|
||||||
|
|
||||||
|
return PublicMedia::isPublicPath($image) ? [$image] : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function summary(array $widget): string
|
||||||
|
{
|
||||||
|
$label = $this->subjectLabel($widget['refs'][$this->refKey()] ?? null);
|
||||||
|
|
||||||
|
return $label ?? 'Kein Objekt gewählt';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function centralCoverId(mixed $id): ?int
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zentraler Anzeigename oder Teaser des gewählten Objekts (Redaktionsstand) für Platzhalter im Editor.
|
||||||
|
*/
|
||||||
|
private function centralText(mixed $id, string $field, mixed $textSource = null): ?string
|
||||||
|
{
|
||||||
|
if (blank($id)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$subject = $this->subject($id, RenderContext::preview());
|
||||||
|
} catch (\Throwable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($subject instanceof CardSubject && is_string($textSource) && isset($this->textChoices()[$textSource]) && $textSource !== 'auto') {
|
||||||
|
$subject = $subject->withTextChoice($textSource, $this->missingTextHint($textSource));
|
||||||
|
}
|
||||||
|
|
||||||
|
$text = $subject?->{$field};
|
||||||
|
|
||||||
|
return is_string($text) && trim($text) !== '' ? Str::limit(trim($text), 120) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function subjectField(): Select
|
||||||
|
{
|
||||||
|
return Select::make($this->refKey())
|
||||||
|
->label($this->refLabel())
|
||||||
|
->helperText($this->refHelp())
|
||||||
|
->required()
|
||||||
|
->live()
|
||||||
|
->searchable()
|
||||||
|
->getSearchResultsUsing(fn (?string $search): array => $this->searchSubjects($search))
|
||||||
|
->getOptionLabelUsing(fn (mixed $value): ?string => $this->subjectLabel($value))
|
||||||
|
->options(fn (): array => $this->searchSubjects(null));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Cms\Widgets\Types;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\Composition;
|
||||||
|
use App\Domain\Catalog\PresentationMedia;
|
||||||
|
use App\Domain\Cms\Catalog\CardSubject;
|
||||||
|
use App\Domain\Cms\Catalog\PublicCatalogReader;
|
||||||
|
use App\Domain\Cms\Widgets\RenderContext;
|
||||||
|
use App\Domain\Media\CompositionStill;
|
||||||
|
use App\Domain\Media\ThumbnailRef;
|
||||||
|
use Filament\Forms\Components\ViewField;
|
||||||
|
use Filament\Schemas\Components\Utilities\Get;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modul- und Programmkarte (Kit v1.7 „catalog“): ein Programm oder Modul über PublicCatalogReader, dieselbe
|
||||||
|
* Freigaberegel wie die Programm- und Modulkarten (Programme öffentlich mit Programmseite, Module nur in der
|
||||||
|
* Redaktionsvorschau). Die Art ist immer sichtbar benannt. Ohne Bild trägt eine Navy-Tafel die Art.
|
||||||
|
* Kein Preis, kein Angebot, keine Kaufaktion; eine Karte ist kein Lizenzartikel.
|
||||||
|
*/
|
||||||
|
class ProgramCardWidget extends PremiumCardWidget
|
||||||
|
{
|
||||||
|
public function key(): string
|
||||||
|
{
|
||||||
|
return 'program_card';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return 'Programm- oder Modulkarte';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function description(): string
|
||||||
|
{
|
||||||
|
return 'Karte zu einem Programm oder Modul; Titel, Beschreibung und Art kommen aus den Fachdaten, ohne Preis und ohne Kaufaktion.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function icon(): string
|
||||||
|
{
|
||||||
|
return 'heroicon-o-academic-cap';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function schematic(): array
|
||||||
|
{
|
||||||
|
return [[2, 2, 56, 32, 'line'], [5, 5, 22, 26, 'ink'], [8, 24, 10, 2, 'accent'], [31, 8, 10, 2, 'line'], [31, 13, 22, 4, 'ink'], [31, 25, 14, 5, 'ink']];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Das Vorschaubild des Programms oder Moduls als Kartenbild übernehmen. Es wird einmal als Bild-Medium abgelegt
|
||||||
|
* (CompositionStill) und wie jedes andere Bild ausgewählt; die Karte liest nur diese Datei.
|
||||||
|
*/
|
||||||
|
protected function imageSourceFields(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
ViewField::make('_programmbild')
|
||||||
|
->label('Bild aus dem Programm oder Modul')
|
||||||
|
->view('filament.cms.kompositionsbild-feld')
|
||||||
|
->dehydrated(false)
|
||||||
|
->visible(fn (Get $get): bool => $this->compositionFor($get('composition')) !== null)
|
||||||
|
->viewData(function (Get $get): array {
|
||||||
|
$composition = $this->compositionFor($get('composition'));
|
||||||
|
|
||||||
|
return [
|
||||||
|
'composition' => $composition,
|
||||||
|
'compositionTitle' => $composition instanceof Composition ? (string) ($composition->display_title ?: $composition->designation) : '',
|
||||||
|
'compositionThumbnailUrl' => $composition instanceof Composition && app(CompositionStill::class)->hasThumbnail($composition)
|
||||||
|
? ThumbnailRef::url('editorial.card', 'komposition', (int) $composition->id, $composition->thumbnail_path)
|
||||||
|
: null,
|
||||||
|
];
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function compositionFor(mixed $id): ?Composition
|
||||||
|
{
|
||||||
|
$composition = is_numeric($id) ? Composition::query()->with('editorialContentKind')->find((int) $id) : null;
|
||||||
|
|
||||||
|
return $composition instanceof Composition && app(PublicCatalogReader::class)->isCardSelectable($composition) ? $composition : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function subjectNoun(): string
|
||||||
|
{
|
||||||
|
return 'Programm oder Modul';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wählbare Texte: die zentralen Texte des Programms oder Moduls und das Lernziel der Fassung. „Automatisch“ bleibt
|
||||||
|
* wie bisher: Teaser, sonst Kurzbeschreibung, sonst Lernziel. Die ausführliche Beschreibung erscheint nur auf Wahl.
|
||||||
|
*/
|
||||||
|
protected function textChoices(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'auto' => 'Automatisch (Teaser, sonst Kurzbeschreibung, sonst Lernziel)',
|
||||||
|
'teaser' => 'Teaser',
|
||||||
|
'summary' => 'Kurzbeschreibung',
|
||||||
|
'description' => 'Ausführliche Beschreibung (erscheint öffentlich)',
|
||||||
|
'goal' => 'Lernziel der Fassung',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settings(): array
|
||||||
|
{
|
||||||
|
// Die Art (Programm oder Modul) bleibt immer sichtbar; sie lässt sich nicht ausblenden.
|
||||||
|
$settings = parent::settings();
|
||||||
|
unset($settings['show_kind']);
|
||||||
|
|
||||||
|
return $settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function refKey(): string
|
||||||
|
{
|
||||||
|
return 'composition';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function refLabel(): string
|
||||||
|
{
|
||||||
|
return 'Programm oder Modul';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function refHelp(): string
|
||||||
|
{
|
||||||
|
return 'Wählbar sind Programme und Module mit bereitgestellter Fassung. Öffentlich erscheinen nur Programme mit Anzeigefreigabe (mit Programmseite); Module haben keine öffentliche Seite und erscheinen nur in der Redaktionsvorschau.';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function searchSubjects(?string $term): array
|
||||||
|
{
|
||||||
|
return app(PublicCatalogReader::class)->cardSearch($term);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function subjectLabel(mixed $id): ?string
|
||||||
|
{
|
||||||
|
return app(PublicCatalogReader::class)->cardLabelFor($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function rejectSubject(int $id): ?string
|
||||||
|
{
|
||||||
|
$composition = Composition::query()->with('editorialContentKind')->find($id);
|
||||||
|
|
||||||
|
return $composition !== null && app(PublicCatalogReader::class)->isCardSelectable($composition)
|
||||||
|
? null
|
||||||
|
: 'Dieses Objekt ist kein Programm oder Modul mit bereitgestellter Fassung.';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function subject(mixed $id, RenderContext $context): ?CardSubject
|
||||||
|
{
|
||||||
|
return app(PublicCatalogReader::class)->subject($id, includeNonPublic: $context->preview);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function defaultActionLabel(): string
|
||||||
|
{
|
||||||
|
return 'Programm ansehen';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function cardStyle(): string
|
||||||
|
{
|
||||||
|
return 'catalog';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function centralCoverId(mixed $id): ?int
|
||||||
|
{
|
||||||
|
$composition = is_numeric($id) ? Composition::query()->find((int) $id) : null;
|
||||||
|
|
||||||
|
return $composition instanceof Composition
|
||||||
|
? app(PresentationMedia::class)->coverElementId($composition)
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Cms\Widgets\Types;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\Pillar;
|
||||||
|
use App\Domain\Cms\Catalog\CardSubject;
|
||||||
|
use App\Domain\Cms\Widgets\RenderContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redaktionelle Themenkarte (Kit v1.7 „editorial“): ein Thema (fachliche Säule) mit Name, Text für die Website und
|
||||||
|
* Verweis auf die Themenseite /themen/{slug}. Ruhige Textaktion mit gelber Unterstreichung. Wählbar sind alle Säulen;
|
||||||
|
* ein nicht veröffentlichtes Thema erscheint nur in der Redaktionsvorschau, öffentlich nicht.
|
||||||
|
*/
|
||||||
|
class TopicCardWidget extends PremiumCardWidget
|
||||||
|
{
|
||||||
|
public function key(): string
|
||||||
|
{
|
||||||
|
return 'topic_card';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return 'Themenkarte';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function description(): string
|
||||||
|
{
|
||||||
|
return 'Redaktionelle Karte zu einem veröffentlichten Thema; Name, Kurzbeschreibung und Ziel kommen aus dem Thema.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function icon(): string
|
||||||
|
{
|
||||||
|
return 'heroicon-o-bookmark-square';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function schematic(): array
|
||||||
|
{
|
||||||
|
return [[2, 2, 56, 32, 'line'], [5, 5, 22, 26, 'image'], [31, 8, 10, 2, 'accent'], [31, 13, 22, 4, 'ink'], [31, 20, 20, 3, 'line'], [31, 27, 12, 2, 'accent']];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function refKey(): string
|
||||||
|
{
|
||||||
|
return 'pillar';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function refLabel(): string
|
||||||
|
{
|
||||||
|
return 'Thema';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function refHelp(): string
|
||||||
|
{
|
||||||
|
return 'Alle fachlichen Säulen sind wählbar. Öffentlich erscheint die Karte nur, wenn das Thema veröffentlicht ist; Name und Text pflegen Sie unter „Fachliche Säulen“, nicht hier.';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function searchSubjects(?string $term): array
|
||||||
|
{
|
||||||
|
$term = trim((string) $term);
|
||||||
|
|
||||||
|
return Pillar::query()
|
||||||
|
->orderBy('sort_order')
|
||||||
|
->orderBy('name')
|
||||||
|
->when($term !== '', fn ($query) => $query->whereRaw('LOWER(name) LIKE ?', ['%'.mb_strtolower($term).'%']))
|
||||||
|
->limit(50)
|
||||||
|
->get()
|
||||||
|
->mapWithKeys(fn (Pillar $pillar): array => [$pillar->id => $this->optionLabel($pillar)])
|
||||||
|
->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function subjectLabel(mixed $id): ?string
|
||||||
|
{
|
||||||
|
$pillar = is_numeric($id) ? Pillar::query()->find((int) $id) : null;
|
||||||
|
|
||||||
|
return $pillar === null ? null : $this->optionLabel($pillar);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function rejectSubject(int $id): ?string
|
||||||
|
{
|
||||||
|
return Pillar::query()->whereKey($id)->exists() ? null : 'Dieses Thema gibt es nicht.';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function subject(mixed $id, RenderContext $context): ?CardSubject
|
||||||
|
{
|
||||||
|
$pillar = is_numeric($id) ? Pillar::query()->find((int) $id) : null;
|
||||||
|
|
||||||
|
if ($pillar === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$public = self::isPublic($pillar);
|
||||||
|
|
||||||
|
if (! $public && ! $context->preview) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$summary = filled($pillar->public_summary) ? trim((string) $pillar->public_summary) : null;
|
||||||
|
$pages = $pillar->pages()->whereNotNull('published_revision_id')->count();
|
||||||
|
$missing = [];
|
||||||
|
|
||||||
|
if ($summary === null) {
|
||||||
|
$missing[] = 'Kein Text für die Website gepflegt (Fachliche Säulen → Text für die Website).';
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CardSubject(
|
||||||
|
title: (string) $pillar->name,
|
||||||
|
summary: $summary,
|
||||||
|
kind: 'Thema',
|
||||||
|
badge: null,
|
||||||
|
meta: $pages > 0 ? [$pages === 1 ? '1 Seite zum Thema' : $pages.' Seiten zum Thema'] : [],
|
||||||
|
url: $public ? $pillar->publicUrl() : null,
|
||||||
|
public: $public,
|
||||||
|
notice: $public ? null : 'Nur in der Redaktionsvorschau sichtbar: Das Thema ist nicht veröffentlicht (Fachliche Säulen → Öffentliche Adresse und „Auf der Website veröffentlichen“).',
|
||||||
|
missing: $missing,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Öffentlich ist ein Thema mit Veröffentlichung und öffentlicher Adresse (dieselbe Regel wie /themen). */
|
||||||
|
public static function isPublic(Pillar $pillar): bool
|
||||||
|
{
|
||||||
|
return $pillar->published_at !== null && filled($pillar->slug);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function optionLabel(Pillar $pillar): string
|
||||||
|
{
|
||||||
|
return $pillar->name.' · Thema · '.(self::isPublic($pillar) ? 'veröffentlicht' : 'nicht veröffentlicht, nur Redaktionsvorschau');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function defaultActionLabel(): string
|
||||||
|
{
|
||||||
|
return 'Thema entdecken';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function cardStyle(): string
|
||||||
|
{
|
||||||
|
return 'editorial';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,244 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Commerce;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
use App\Domain\Catalog\Offer;
|
||||||
|
use App\Domain\Catalog\OfferService;
|
||||||
|
use App\Domain\Catalog\OfferVersion;
|
||||||
|
use App\Domain\Identity\Party;
|
||||||
|
use App\Domain\Identity\PartyType;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sitzungsgebundener Mehrangebotswarenkorb (Etappe 1). Er bleibt in derselben Browsersitzung über Anmeldung,
|
||||||
|
* Registrierung und E-Mail-Bestätigung erhalten. Je Option gibt es genau eine Position. Optionen derselben Produktseite
|
||||||
|
* (gleiche Komposition) sind Alternativen und werden nur nach ausdrücklichem Wechsel ersetzt.
|
||||||
|
* Der Warenkorb reserviert weder Preis noch Konditionen; er merkt sich, was der Käufer gesehen hat.
|
||||||
|
*/
|
||||||
|
class Cart
|
||||||
|
{
|
||||||
|
public const KEY = 'shop.cart';
|
||||||
|
|
||||||
|
public const ADDED = 'added';
|
||||||
|
|
||||||
|
public const PRESENT = 'present';
|
||||||
|
|
||||||
|
public const ALTERNATIVE = 'alternative';
|
||||||
|
|
||||||
|
public const UNAVAILABLE = 'unavailable';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly OwnershipCheck $ownership,
|
||||||
|
private readonly OrderHolders $holders,
|
||||||
|
private readonly OfferService $offers,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, array{version_id: int, price_cents: int}>
|
||||||
|
*/
|
||||||
|
public function items(): array
|
||||||
|
{
|
||||||
|
return (array) session()->get(self::KEY, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function count(): int
|
||||||
|
{
|
||||||
|
return count($this->items());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function has(Offer $offer): bool
|
||||||
|
{
|
||||||
|
return isset($this->items()[$offer->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die bereits enthaltene Alternative derselben Produktseite, falls vorhanden.
|
||||||
|
*/
|
||||||
|
public function alternativeTo(Offer $offer): ?Offer
|
||||||
|
{
|
||||||
|
if ($offer->composition_id === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ids = array_diff(array_keys($this->items()), [$offer->id]);
|
||||||
|
|
||||||
|
return $ids === [] ? null : Offer::query()
|
||||||
|
->whereIn('id', $ids)
|
||||||
|
->where('composition_id', $offer->composition_id)
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add(Offer $offer): string
|
||||||
|
{
|
||||||
|
$version = $this->purchasable($offer);
|
||||||
|
|
||||||
|
if ($version === null) {
|
||||||
|
return self::UNAVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->has($offer)) {
|
||||||
|
return self::PRESENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->alternativeTo($offer) !== null) {
|
||||||
|
return self::ALTERNATIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->put($offer, $version);
|
||||||
|
|
||||||
|
return self::ADDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ausdrücklicher Wechsel: die Alternative wird durch die gewählte Option ersetzt.
|
||||||
|
*/
|
||||||
|
public function switchTo(Offer $offer): bool
|
||||||
|
{
|
||||||
|
$version = $this->purchasable($offer);
|
||||||
|
|
||||||
|
if ($version === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$alternative = $this->alternativeTo($offer);
|
||||||
|
|
||||||
|
if ($alternative !== null) {
|
||||||
|
$this->remove($alternative);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->put($offer, $version);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function remove(Offer $offer): void
|
||||||
|
{
|
||||||
|
$items = $this->items();
|
||||||
|
unset($items[$offer->id]);
|
||||||
|
session()->put(self::KEY, $items);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Der Käufer übernimmt Preis und Fassung, die der Shop jetzt zeigt.
|
||||||
|
*/
|
||||||
|
public function acceptCurrent(Offer $offer): void
|
||||||
|
{
|
||||||
|
$version = $this->purchasable($offer);
|
||||||
|
|
||||||
|
if ($version !== null && $this->has($offer)) {
|
||||||
|
$this->put($offer, $version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clear(): void
|
||||||
|
{
|
||||||
|
session()->forget(self::KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serverseitige Prüfung: aktuelle Fassung, Preis, Kaufbarkeit, passende Inhaberart, vorhandene Rechte.
|
||||||
|
*/
|
||||||
|
public function review(?User $user = null, ?int $holderPartyId = null): CartReview
|
||||||
|
{
|
||||||
|
$offers = Offer::query()
|
||||||
|
->whereIn('id', array_keys($this->items()))
|
||||||
|
->with('composition')
|
||||||
|
->get()
|
||||||
|
->keyBy('id');
|
||||||
|
$versions = [];
|
||||||
|
|
||||||
|
foreach ($this->items() as $offerId => $item) {
|
||||||
|
$offer = $offers->get($offerId);
|
||||||
|
|
||||||
|
if ($offer !== null) {
|
||||||
|
$versions[$offerId] = $this->purchasable($offer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$holder = $user === null ? null : $this->holderFor($user, $holderPartyId, $versions);
|
||||||
|
$lines = [];
|
||||||
|
|
||||||
|
foreach ($this->items() as $offerId => $item) {
|
||||||
|
$offer = $offers->get($offerId);
|
||||||
|
|
||||||
|
if ($offer === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = $versions[$offerId] ?? null;
|
||||||
|
$seen = (int) $item['price_cents'];
|
||||||
|
|
||||||
|
if ($version === null) {
|
||||||
|
$lines[] = new CartLine($offer, null, CartLine::WITHDRAWN, $seen, null,
|
||||||
|
'Diese Option ist nicht mehr erhältlich. Entferne sie, um mit den übrigen Positionen fortzufahren.');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$current = (int) $version->price_cents;
|
||||||
|
|
||||||
|
if ($holder !== null && ! $this->suitsHolder($version, $holder)) {
|
||||||
|
$lines[] = new CartLine($offer, $version, CartLine::WRONG_HOLDER, $seen, $current,
|
||||||
|
$version->holder_kind === 'organisation'
|
||||||
|
? 'Diese Option ist für Organisationen. Bestelle als Verein oder entferne sie.'
|
||||||
|
: 'Diese Option ist für Privatpersonen. Bestelle als Privatperson oder entferne sie.');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($holder !== null && $this->ownership->covers($holder, $version)) {
|
||||||
|
$lines[] = new CartLine($offer, $version, CartLine::OWNED, $seen, $current);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($current !== $seen) {
|
||||||
|
$lines[] = new CartLine($offer, $version, CartLine::PRICE_CHANGED, $seen, $current);
|
||||||
|
} elseif ((int) $item['version_id'] !== $version->id) {
|
||||||
|
$lines[] = new CartLine($offer, $version, CartLine::TERMS_CHANGED, $seen, $current,
|
||||||
|
'Die Bedingungen dieser Option wurden aktualisiert. Bitte prüfe die Übersicht.');
|
||||||
|
} else {
|
||||||
|
$lines[] = new CartLine($offer, $version, CartLine::OK, $seen, $current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CartReview($lines, $holder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die aktive, als Kauf angebotene Fassung der Option; sonst null (nicht kaufbar oder zurückgezogen).
|
||||||
|
*/
|
||||||
|
public function purchasable(Offer $offer): ?OfferVersion
|
||||||
|
{
|
||||||
|
return $this->offers->purchasableVersion($offer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function put(Offer $offer, OfferVersion $version): void
|
||||||
|
{
|
||||||
|
$items = $this->items();
|
||||||
|
$items[$offer->id] = ['version_id' => $version->id, 'price_cents' => (int) $version->price_cents];
|
||||||
|
session()->put(self::KEY, $items);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, OfferVersion|null> $versions
|
||||||
|
*/
|
||||||
|
private function holderFor(User $user, ?int $partyId, array $versions): ?Party
|
||||||
|
{
|
||||||
|
$onlyOrganisations = $versions !== [] && collect($versions)
|
||||||
|
->filter()
|
||||||
|
->every(fn (OfferVersion $version): bool => $version->holder_kind === 'organisation');
|
||||||
|
|
||||||
|
try {
|
||||||
|
return $this->holders->resolve($user, $partyId, $onlyOrganisations);
|
||||||
|
} catch (DomainRuleException) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function suitsHolder(OfferVersion $version, Party $holder): bool
|
||||||
|
{
|
||||||
|
return ($version->holder_kind === 'organisation') === ($holder->type === PartyType::Organisation);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Commerce;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\Offer;
|
||||||
|
use App\Domain\Catalog\OfferVersion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eine Position des Warenkorbs mit dem Ergebnis der serverseitigen Prüfung.
|
||||||
|
*/
|
||||||
|
final class CartLine
|
||||||
|
{
|
||||||
|
public const OK = 'ok';
|
||||||
|
|
||||||
|
public const PRICE_CHANGED = 'preis_geaendert';
|
||||||
|
|
||||||
|
public const TERMS_CHANGED = 'bedingungen_geaendert';
|
||||||
|
|
||||||
|
public const WITHDRAWN = 'zurueckgezogen';
|
||||||
|
|
||||||
|
public const OWNED = 'bereits_erworben';
|
||||||
|
|
||||||
|
public const WRONG_HOLDER = 'falscher_inhaber';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public readonly Offer $offer,
|
||||||
|
public readonly ?OfferVersion $version,
|
||||||
|
public readonly string $state,
|
||||||
|
public readonly int $seenPriceCents,
|
||||||
|
public readonly ?int $currentPriceCents,
|
||||||
|
public readonly ?string $note = null,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/** Geht in Summe und Bestellung ein. */
|
||||||
|
public function orderable(): bool
|
||||||
|
{
|
||||||
|
return in_array($this->state, [self::OK, self::PRICE_CHANGED, self::TERMS_CHANGED], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Verhindert den Abschluss, bis der Käufer die Position selbst entfernt oder den Inhaber wechselt. */
|
||||||
|
public function blocks(): bool
|
||||||
|
{
|
||||||
|
return in_array($this->state, [self::WITHDRAWN, self::WRONG_HOLDER], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function title(): string
|
||||||
|
{
|
||||||
|
$composition = $this->offer->composition;
|
||||||
|
|
||||||
|
return $composition !== null
|
||||||
|
? (string) ($composition->display_title ?: $composition->designation)
|
||||||
|
: (string) $this->offer->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Commerce;
|
||||||
|
|
||||||
|
use App\Domain\Identity\Party;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prüfergebnis des Warenkorbs für einen vorgesehenen Lizenzinhaber. Die Prüfsumme bindet die Bestellung an genau
|
||||||
|
* diese Übersicht: Inhaber, Fassung und Preis jeder Position samt Zustand, auch der ausgeschlossenen.
|
||||||
|
*/
|
||||||
|
final class CartReview
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param list<CartLine> $lines
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public readonly array $lines,
|
||||||
|
public readonly ?Party $holder,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/** @return list<CartLine> */
|
||||||
|
public function orderable(): array
|
||||||
|
{
|
||||||
|
return array_values(array_filter($this->lines, fn (CartLine $line): bool => $line->orderable()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function totalCents(): int
|
||||||
|
{
|
||||||
|
return array_sum(array_map(fn (CartLine $line): int => (int) $line->currentPriceCents, $this->orderable()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function blocked(): bool
|
||||||
|
{
|
||||||
|
foreach ($this->lines as $line) {
|
||||||
|
if ($line->blocks()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function empty(): bool
|
||||||
|
{
|
||||||
|
return $this->orderable() === [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canOrder(): bool
|
||||||
|
{
|
||||||
|
return $this->holder !== null && ! $this->blocked() && ! $this->empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function digest(): string
|
||||||
|
{
|
||||||
|
$parts = [];
|
||||||
|
|
||||||
|
foreach ($this->lines as $line) {
|
||||||
|
$parts[] = $line->offer->id.':'.($line->version?->id ?? 0).':'.$line->currentPriceCents.':'.$line->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
sort($parts);
|
||||||
|
|
||||||
|
return hash('sha256', ($this->holder?->id ?? 0).'|'.implode(',', $parts));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,11 +5,13 @@
|
|||||||
use App\Domain\Catalog\DomainRuleException;
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
use App\Domain\Catalog\Offer;
|
use App\Domain\Catalog\Offer;
|
||||||
use App\Domain\Catalog\OfferService;
|
use App\Domain\Catalog\OfferService;
|
||||||
|
use App\Domain\Catalog\OfferVersion;
|
||||||
use App\Domain\Entitlement\Acquisition;
|
use App\Domain\Entitlement\Acquisition;
|
||||||
use App\Domain\Entitlement\AcquisitionType;
|
use App\Domain\Entitlement\AcquisitionType;
|
||||||
use App\Domain\Entitlement\GrantIssuer;
|
use App\Domain\Entitlement\GrantIssuer;
|
||||||
use App\Domain\Entitlement\GrantStatus;
|
use App\Domain\Entitlement\GrantStatus;
|
||||||
use App\Domain\Identity\AccountStatus;
|
use App\Domain\Identity\AccountStatus;
|
||||||
|
use App\Domain\Identity\Party;
|
||||||
use App\Mail\OrderConfirmed;
|
use App\Mail\OrderConfirmed;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
@@ -20,13 +22,15 @@ class Checkout
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly GrantIssuer $grants,
|
private readonly GrantIssuer $grants,
|
||||||
private readonly OfferService $offers,
|
private readonly OfferService $offers,
|
||||||
|
private readonly OrderHolders $holders,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Einzelkauf einer Option als Person (bestehender Weg, ohne Warenkorb).
|
||||||
|
*/
|
||||||
public function place(User $user, Offer $offer): Order
|
public function place(User $user, Offer $offer): Order
|
||||||
{
|
{
|
||||||
if ($user->status !== AccountStatus::Aktiv || $user->party_id === null) {
|
$this->assertActive($user);
|
||||||
throw new DomainRuleException('Nur ein aktives Mitglied kann kaufen.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$version = $this->offers->currentActiveVersion($offer);
|
$version = $this->offers->currentActiveVersion($offer);
|
||||||
|
|
||||||
@@ -38,20 +42,78 @@ public function place(User $user, Offer $offer): Order
|
|||||||
throw new DomainRuleException('Der Kauf braucht einen Preis an der Angebotsfassung.');
|
throw new DomainRuleException('Der Kauf braucht einen Preis an der Angebotsfassung.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return DB::transaction(function () use ($user, $offer, $version): Order {
|
$holder = $this->holders->resolve($user, null);
|
||||||
$order = Order::query()->create([
|
|
||||||
'user_id' => $user->id,
|
return DB::transaction(fn (): Order => $this->createOrder($user, $holder, [[$offer, $version]]));
|
||||||
'party_id' => $user->party_id,
|
}
|
||||||
'status' => 'offen',
|
|
||||||
'holder_kind' => 'person',
|
/**
|
||||||
]);
|
* Bestellung aus dem Warenkorb, erst nach serverseitiger Prüfung. Die Prüfsumme bindet die Bestellung an die
|
||||||
|
* Übersicht, die der Käufer gesehen hat: Hat sich Preis, Fassung oder Bedingung seither geändert, entsteht keine
|
||||||
|
* Bestellung und der Käufer sieht zuerst die aktualisierte Übersicht. Positionen, deren Umfang der Inhaber bereits
|
||||||
|
* mit denselben Rechten besitzt, erzeugen keine Bestellposition.
|
||||||
|
*/
|
||||||
|
public function placeFromCart(User $user, Cart $cart, ?int $holderPartyId, string $digest): Order
|
||||||
|
{
|
||||||
|
$this->assertActive($user);
|
||||||
|
|
||||||
|
$order = DB::transaction(function () use ($user, $cart, $holderPartyId, $digest): Order {
|
||||||
|
// Optionen sperren, damit eine gleichzeitige Aktivierung die Prüfung nicht unterläuft.
|
||||||
|
Offer::query()->whereIn('id', array_keys($cart->items()))->orderBy('id')->lockForUpdate()->get();
|
||||||
|
$review = $cart->review($user, $holderPartyId);
|
||||||
|
|
||||||
|
if ($review->holder === null) {
|
||||||
|
throw new DomainRuleException('Für diesen Lizenzinhaber ist das Konto nicht bestellberechtigt.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! hash_equals($review->digest(), $digest)) {
|
||||||
|
throw new StaleOverview('Die Übersicht hat sich geändert. Bitte prüfe die aktualisierte Bestellübersicht.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($review->blocked()) {
|
||||||
|
throw new DomainRuleException('Entferne zuerst die Positionen, die nicht bestellt werden können.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($review->empty()) {
|
||||||
|
throw new DomainRuleException('Es gibt nichts zu bestellen. Alle Positionen sind bereits erworben.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$pairs = array_map(fn (CartLine $line): array => [$line->offer, $line->version], $review->orderable());
|
||||||
|
|
||||||
|
return $this->createOrder($user, $review->holder, $pairs);
|
||||||
|
});
|
||||||
|
|
||||||
|
$cart->clear();
|
||||||
|
|
||||||
|
return $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<array{0: Offer, 1: OfferVersion}> $pairs
|
||||||
|
*/
|
||||||
|
private function createOrder(User $user, Party $holder, array $pairs): Order
|
||||||
|
{
|
||||||
|
$order = Order::query()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'party_id' => $holder->id,
|
||||||
|
'status' => 'offen',
|
||||||
|
'holder_kind' => $holder->type->value,
|
||||||
|
'total_cents' => array_sum(array_map(fn (array $pair): int => (int) $pair[1]->price_cents, $pairs)),
|
||||||
|
'currency' => 'EUR',
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach ($pairs as [$offer, $version]) {
|
||||||
$line = $order->lines()->create([
|
$line = $order->lines()->create([
|
||||||
'offer_version_id' => $version->id,
|
'offer_version_id' => $version->id,
|
||||||
'offer_name' => $offer->name,
|
'offer_name' => $offer->name,
|
||||||
'price_cents' => $version->price_cents,
|
'price_cents' => $version->price_cents,
|
||||||
|
'currency' => 'EUR',
|
||||||
'term_rule' => $version->term_rule,
|
'term_rule' => $version->term_rule,
|
||||||
'update_promise' => $version->update_promise,
|
'update_promise' => $version->update_promise,
|
||||||
'holder_kind' => $version->holder_kind,
|
'holder_kind' => $version->holder_kind,
|
||||||
|
'tax_class' => $version->tax_class,
|
||||||
|
'grant_kind' => $version->grant_kind,
|
||||||
|
'holder_party_id' => $holder->id,
|
||||||
]);
|
]);
|
||||||
$version->load('resolvedScopes.rights');
|
$version->load('resolvedScopes.rights');
|
||||||
|
|
||||||
@@ -66,11 +128,15 @@ public function place(User $user, Offer $offer): Order
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $order->load('lines.scopeItems');
|
return $order->load('lines.scopeItems');
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Freischaltung nach bestätigter Testzahlung: alle Bestellpositionen aus ihrem festgehaltenen Umfang, in einer
|
||||||
|
* Transaktion. Wiederholte Bestätigung ist wirkungslos; ein Fehler hinterlässt weder Zahlung noch Rechte.
|
||||||
|
*/
|
||||||
public function confirmTestPayment(Order $order, string $reference): Order
|
public function confirmTestPayment(Order $order, string $reference): Order
|
||||||
{
|
{
|
||||||
$this->assertTestDriver();
|
$this->assertTestDriver();
|
||||||
@@ -100,14 +166,12 @@ public function confirmTestPayment(Order $order, string $reference): Order
|
|||||||
$order->status = 'bezahlt';
|
$order->status = 'bezahlt';
|
||||||
$order->save();
|
$order->save();
|
||||||
$paidNow = true;
|
$paidNow = true;
|
||||||
$line = $order->lines()->firstOrFail();
|
$actor = User::query()->findOrFail($order->user_id);
|
||||||
$this->grants->issue(
|
|
||||||
$order->user,
|
foreach ($order->lines()->orderBy('id')->get() as $line) {
|
||||||
$line->offerVersion,
|
$holder = Party::query()->findOrFail($line->holder_party_id ?? $order->party_id);
|
||||||
AcquisitionType::Bestellposition,
|
$this->grants->issueFromOrderLine($line, $holder, $actor);
|
||||||
'order_line',
|
}
|
||||||
$line->id,
|
|
||||||
);
|
|
||||||
|
|
||||||
return $order->load('lines', 'payments');
|
return $order->load('lines', 'payments');
|
||||||
});
|
});
|
||||||
@@ -142,6 +206,10 @@ public function failTestPayment(Order $order, string $reference): Order
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vollerstattung: widerruft die Berechtigungen aller Positionen dieser Bestellung. Andere Erwerbsquellen
|
||||||
|
* (kostenlose Vergabe, frühere Käufe) bleiben unberührt.
|
||||||
|
*/
|
||||||
public function refund(Order $order, string $reason): Order
|
public function refund(Order $order, string $reason): Order
|
||||||
{
|
{
|
||||||
$reason = trim($reason);
|
$reason = trim($reason);
|
||||||
@@ -157,15 +225,14 @@ public function refund(Order $order, string $reason): Order
|
|||||||
throw new DomainRuleException('Nur eine bezahlte Bestellung kann erstattet werden.');
|
throw new DomainRuleException('Nur eine bezahlte Bestellung kann erstattet werden.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$line = $order->lines()->firstOrFail();
|
foreach ($order->lines()->orderBy('id')->get() as $line) {
|
||||||
$acquisition = Acquisition::query()->where([
|
$acquisition = Acquisition::query()->where([
|
||||||
'type' => AcquisitionType::Bestellposition,
|
'type' => AcquisitionType::Bestellposition,
|
||||||
'reference_type' => 'order_line',
|
'reference_type' => 'order_line',
|
||||||
'reference_id' => $line->id,
|
'reference_id' => $line->id,
|
||||||
])->first();
|
])->first();
|
||||||
|
|
||||||
if ($acquisition !== null) {
|
foreach ($acquisition?->grants ?? [] as $grant) {
|
||||||
foreach ($acquisition->grants as $grant) {
|
|
||||||
if ($grant->status === GrantStatus::Aktiv) {
|
if ($grant->status === GrantStatus::Aktiv) {
|
||||||
$grant->status = GrantStatus::Widerrufen;
|
$grant->status = GrantStatus::Widerrufen;
|
||||||
$grant->status_reason = $reason;
|
$grant->status_reason = $reason;
|
||||||
@@ -182,6 +249,13 @@ public function refund(Order $order, string $reason): Order
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function assertActive(User $user): void
|
||||||
|
{
|
||||||
|
if ($user->status !== AccountStatus::Aktiv || $user->party_id === null) {
|
||||||
|
throw new DomainRuleException('Nur ein aktives Mitglied kann kaufen.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function assertTestDriver(): void
|
private function assertTestDriver(): void
|
||||||
{
|
{
|
||||||
if (app()->isProduction() || config('services.payment.driver') !== 'test') {
|
if (app()->isProduction() || config('services.payment.driver') !== 'test') {
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Commerce;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Beträge werden als ganze Cent gespeichert und in Euro angezeigt und eingegeben (deutsches Format).
|
||||||
|
*/
|
||||||
|
final class Money
|
||||||
|
{
|
||||||
|
/** Obergrenze eines Preises (1.000.000 €), weit unter dem Wertebereich der Datenbank. */
|
||||||
|
public const MAX_CENTS = 100_000_000;
|
||||||
|
|
||||||
|
public static function format(?int $cents): string
|
||||||
|
{
|
||||||
|
return $cents === null ? '–' : number_format($cents / 100, 2, ',', '.').' €';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Euro-Eingabe („12,50“, „1.299“, „5“) als Cent. Leere Eingabe ergibt null.
|
||||||
|
*/
|
||||||
|
public static function parse(string|int|float|null $input): ?int
|
||||||
|
{
|
||||||
|
if ($input === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$text = trim((string) $input);
|
||||||
|
|
||||||
|
if ($text === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$text = str_replace([' ', '€'], '', $text);
|
||||||
|
|
||||||
|
if (str_contains($text, ',')) {
|
||||||
|
$text = str_replace('.', '', $text);
|
||||||
|
$text = str_replace(',', '.', $text);
|
||||||
|
} elseif (preg_match('/^\d{1,3}(\.\d{3})+$/', $text) === 1) {
|
||||||
|
$text = str_replace('.', '', $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('/^\d+(\.\d{1,2})?$/', $text) !== 1) {
|
||||||
|
throw new DomainRuleException('Der Preis ist kein gültiger Eurobetrag, zum Beispiel 12,50.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$cents = (int) round(((float) $text) * 100);
|
||||||
|
|
||||||
|
if ($cents > self::MAX_CENTS) {
|
||||||
|
throw new DomainRuleException('Der Preis ist zu hoch. Zulässig sind höchstens '.self::format(self::MAX_CENTS).'.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cents;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,8 @@ class Order extends Model
|
|||||||
'party_id',
|
'party_id',
|
||||||
'status',
|
'status',
|
||||||
'holder_kind',
|
'holder_kind',
|
||||||
|
'total_cents',
|
||||||
|
'currency',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function user(): BelongsTo
|
public function user(): BelongsTo
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Commerce;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
use App\Domain\Identity\Membership;
|
||||||
|
use App\Domain\Identity\Party;
|
||||||
|
use App\Domain\Identity\PartyType;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Für wen ein Konto bestellen darf: für sich selbst (Person) und für Organisationen, bei denen es eine aktive
|
||||||
|
* Mitgliedschaft mit Bestellberechtigung hat. Eine Bestellung hat genau einen Lizenzinhaber.
|
||||||
|
*/
|
||||||
|
class OrderHolders
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Party>
|
||||||
|
*/
|
||||||
|
public function for(User $user): Collection
|
||||||
|
{
|
||||||
|
$holders = collect();
|
||||||
|
|
||||||
|
if ($user->party_id !== null) {
|
||||||
|
$person = Party::query()->find($user->party_id);
|
||||||
|
|
||||||
|
if ($person !== null) {
|
||||||
|
$holders->push($person);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$organisations = Membership::query()
|
||||||
|
->active()
|
||||||
|
->where('user_id', $user->id)
|
||||||
|
->where('may_order', true)
|
||||||
|
->with('organisation')
|
||||||
|
->orderBy('id')
|
||||||
|
->get()
|
||||||
|
->map(fn (Membership $membership): ?Party => $membership->organisation)
|
||||||
|
->filter(fn (?Party $party): bool => $party !== null && $party->type === PartyType::Organisation);
|
||||||
|
|
||||||
|
return $holders->concat($organisations)->values();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Der gewählte Inhaber; ohne Wahl die Person, bei Angeboten nur für Organisationen die erste Organisation.
|
||||||
|
*/
|
||||||
|
public function resolve(User $user, ?int $partyId, bool $preferOrganisation = false): Party
|
||||||
|
{
|
||||||
|
$holders = $this->for($user);
|
||||||
|
|
||||||
|
if ($partyId !== null) {
|
||||||
|
$chosen = $holders->first(fn (Party $party): bool => $party->id === $partyId);
|
||||||
|
|
||||||
|
if ($chosen === null) {
|
||||||
|
throw new DomainRuleException('Für diesen Lizenzinhaber ist das Konto nicht bestellberechtigt.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $chosen;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($preferOrganisation) {
|
||||||
|
$organisation = $holders->first(fn (Party $party): bool => $party->type === PartyType::Organisation);
|
||||||
|
|
||||||
|
if ($organisation !== null) {
|
||||||
|
return $organisation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$person = $holders->first(fn (Party $party): bool => $party->type === PartyType::Person);
|
||||||
|
|
||||||
|
return $person ?? throw new DomainRuleException('Nur ein aktives Mitglied kann kaufen.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Domain\Commerce;
|
namespace App\Domain\Commerce;
|
||||||
|
|
||||||
use App\Domain\Catalog\OfferVersion;
|
use App\Domain\Catalog\OfferVersion;
|
||||||
|
use App\Domain\Identity\Party;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
@@ -17,6 +18,10 @@ class OrderLine extends Model
|
|||||||
'term_rule',
|
'term_rule',
|
||||||
'update_promise',
|
'update_promise',
|
||||||
'holder_kind',
|
'holder_kind',
|
||||||
|
'currency',
|
||||||
|
'tax_class',
|
||||||
|
'grant_kind',
|
||||||
|
'holder_party_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function order(): BelongsTo
|
public function order(): BelongsTo
|
||||||
@@ -24,6 +29,11 @@ public function order(): BelongsTo
|
|||||||
return $this->belongsTo(Order::class);
|
return $this->belongsTo(Order::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function holder(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Party::class, 'holder_party_id');
|
||||||
|
}
|
||||||
|
|
||||||
public function offerVersion(): BelongsTo
|
public function offerVersion(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(OfferVersion::class);
|
return $this->belongsTo(OfferVersion::class);
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Commerce;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\OfferVersion;
|
||||||
|
use App\Domain\Entitlement\Grant;
|
||||||
|
use App\Domain\Entitlement\GrantStatus;
|
||||||
|
use App\Domain\Identity\Party;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* „Bereits erworben“ (FACH-59): Der vorgesehene Lizenzinhaber hat bereits eine gültige Lizenz mit demselben Umfang
|
||||||
|
* und denselben Nutzungsrechten. Maßgeblich ist genau ein Erwerb, der jeden Umfangsposten der Angebotsfassung mit
|
||||||
|
* gleichem Zweck, gleichen Fähigkeiten und gleichen Optionen trägt. Rechte mehrerer Erwerbe werden nicht zu einer
|
||||||
|
* neuen Lizenz kombiniert. Alle Erwerbsarten zählen (Kauf, freier Abruf, manuelle Vergabe), sofern aktiv und gültig.
|
||||||
|
*/
|
||||||
|
class OwnershipCheck
|
||||||
|
{
|
||||||
|
public function covers(Party $holder, OfferVersion $version): bool
|
||||||
|
{
|
||||||
|
$needed = $this->needed($version);
|
||||||
|
|
||||||
|
if ($needed === []) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$now = now();
|
||||||
|
$byAcquisition = Grant::query()
|
||||||
|
->where('status', GrantStatus::Aktiv)
|
||||||
|
->whereHas('acquisition', fn ($query) => $query->where('party_id', $holder->id))
|
||||||
|
->get()
|
||||||
|
->filter(fn (Grant $grant): bool => ($grant->valid_from === null || ! $grant->valid_from->greaterThan($now))
|
||||||
|
&& ($grant->valid_until === null || $grant->valid_until->greaterThan($now)))
|
||||||
|
->groupBy('acquisition_id');
|
||||||
|
|
||||||
|
foreach ($byAcquisition as $grants) {
|
||||||
|
$have = [];
|
||||||
|
|
||||||
|
foreach ($grants as $grant) {
|
||||||
|
$have[$grant->license_article_id.'|'.$this->fingerprint($grant->rights_snapshot ?? [])] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_diff_key($needed, $have) === []) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, true>
|
||||||
|
*/
|
||||||
|
private function needed(OfferVersion $version): array
|
||||||
|
{
|
||||||
|
$needed = [];
|
||||||
|
$version->loadMissing('resolvedScopes.rights');
|
||||||
|
|
||||||
|
foreach ($version->resolvedScopes as $scope) {
|
||||||
|
$needed[$scope->license_article_id.'|'.$this->fingerprint([
|
||||||
|
'purpose' => $scope->rights->purpose,
|
||||||
|
'capabilities' => $scope->rights->capabilities,
|
||||||
|
'options' => $scope->rights->options ?? [],
|
||||||
|
])] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $needed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reihenfolge von Schlüsseln und Aktionen spielt keine Rolle.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $rights
|
||||||
|
*/
|
||||||
|
private function fingerprint(array $rights): string
|
||||||
|
{
|
||||||
|
$capabilities = [];
|
||||||
|
|
||||||
|
foreach ((array) ($rights['capabilities'] ?? []) as $class => $actions) {
|
||||||
|
$actions = array_values(array_unique((array) $actions));
|
||||||
|
sort($actions);
|
||||||
|
$capabilities[(string) $class] = $actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
ksort($capabilities);
|
||||||
|
$options = (array) ($rights['options'] ?? []);
|
||||||
|
ksort($options);
|
||||||
|
|
||||||
|
return md5(json_encode([
|
||||||
|
'purpose' => (string) ($rights['purpose'] ?? ''),
|
||||||
|
'capabilities' => $capabilities,
|
||||||
|
'options' => $options,
|
||||||
|
], JSON_THROW_ON_ERROR));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Commerce;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\Composition;
|
||||||
|
use App\Domain\Catalog\EditorialProfileReader;
|
||||||
|
use App\Domain\Catalog\LicenseArticle;
|
||||||
|
use App\Domain\Catalog\Offer;
|
||||||
|
use App\Domain\Catalog\OfferService;
|
||||||
|
use App\Domain\Catalog\OfferVersion;
|
||||||
|
use App\Filament\Support\CatalogLabels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kaufbare Lizenzoptionen einer Produktseite aus dem veröffentlichten Katalog: aktive Angebotsfassungen mit Preis,
|
||||||
|
* Eignung, Laufzeit, Umfang und Nutzungsrechten. Die Seite selbst (Titel, Beschreibung, Struktur) kommt aus der
|
||||||
|
* zur Anzeige freigegebenen Komposition; hier entsteht kein zweiter Text.
|
||||||
|
*/
|
||||||
|
class ProductOptions
|
||||||
|
{
|
||||||
|
public function __construct(private readonly OfferService $offers) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array<string, mixed>>
|
||||||
|
*/
|
||||||
|
public function forComposition(Composition $composition): array
|
||||||
|
{
|
||||||
|
$options = [];
|
||||||
|
|
||||||
|
foreach (Offer::query()->where('composition_id', $composition->id)->orderBy('id')->get() as $offer) {
|
||||||
|
$version = $this->offers->purchasableVersion($offer);
|
||||||
|
|
||||||
|
if ($version !== null) {
|
||||||
|
$options[] = $this->describe($offer, $version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zeilen für Shop-Suche und Kacheln: je Komposition die günstigste Option.
|
||||||
|
*
|
||||||
|
* @return array<int, array{from_cents: int, count: int}>
|
||||||
|
*/
|
||||||
|
public function summaries(): array
|
||||||
|
{
|
||||||
|
$summary = [];
|
||||||
|
|
||||||
|
foreach (Offer::query()->whereNotNull('composition_id')->orderBy('id')->get() as $offer) {
|
||||||
|
$version = $this->offers->purchasableVersion($offer);
|
||||||
|
|
||||||
|
if ($version === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$current = $summary[$offer->composition_id] ?? ['from_cents' => PHP_INT_MAX, 'count' => 0];
|
||||||
|
$summary[$offer->composition_id] = [
|
||||||
|
'from_cents' => min($current['from_cents'], (int) $version->price_cents),
|
||||||
|
'count' => $current['count'] + 1,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function describe(Offer $offer, OfferVersion $version): array
|
||||||
|
{
|
||||||
|
$version->loadMissing('resolvedScopes.article', 'resolvedScopes.rights');
|
||||||
|
$scope = [];
|
||||||
|
|
||||||
|
foreach ($version->resolvedScopes as $item) {
|
||||||
|
$faehigkeiten = CatalogLabels::faehigkeiten($item->rights?->capabilities);
|
||||||
|
$scope[] = [
|
||||||
|
'article' => $this->articleTitle($item->article),
|
||||||
|
'purpose' => CatalogLabels::zweck($item->rights?->purpose),
|
||||||
|
'rights' => $faehigkeiten,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'offer' => $offer,
|
||||||
|
'version' => $version,
|
||||||
|
'name' => $offer->optionName(),
|
||||||
|
'price_cents' => (int) $version->price_cents,
|
||||||
|
'price' => Money::format((int) $version->price_cents),
|
||||||
|
'for' => $version->holder_kind === 'organisation' ? 'Organisationen und Vereine' : 'Privatpersonen',
|
||||||
|
'holder_kind' => $version->holder_kind,
|
||||||
|
'term' => self::termLabel($version),
|
||||||
|
'scope' => $scope,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function termLabel(OfferVersion $version): string
|
||||||
|
{
|
||||||
|
return match ($version->term_rule) {
|
||||||
|
'dauerhaft' => 'Dauerhaft nutzbar',
|
||||||
|
'befristet' => 'Befristet',
|
||||||
|
'solange_angebot_aktiv' => 'Solange das Angebot aktiv ist',
|
||||||
|
'periodisch' => 'Laufend, periodisch',
|
||||||
|
default => (string) $version->term_rule,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function articleTitle(?LicenseArticle $article): string
|
||||||
|
{
|
||||||
|
if ($article === null) {
|
||||||
|
return '–';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->articleName($article) ?: (string) $article->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name wie in der Redaktion: eigener Name, sonst der Name des Inhalts (Anzeigename, Arbeitstitel oder
|
||||||
|
* Bezeichnung), sonst der eigene Arbeitstitel; leer, wenn nichts davon vorhanden ist.
|
||||||
|
*/
|
||||||
|
public function articleName(LicenseArticle $article): string
|
||||||
|
{
|
||||||
|
$profile = app(EditorialProfileReader::class)->read($article, 'detail');
|
||||||
|
$source = $profile->source;
|
||||||
|
$candidates = [
|
||||||
|
$profile->value('display_title'),
|
||||||
|
$article->working_title,
|
||||||
|
$source?->getAttribute('working_title'),
|
||||||
|
$source?->getAttribute('designation'),
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($candidates as $candidate) {
|
||||||
|
if (filled($candidate)) {
|
||||||
|
return trim((string) $candidate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Commerce;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Etappe 1 verwendet ausschließlich Testzahlung und erteilt keine Produktivfreigabe. Der Shop (Warenkorb, Kasse,
|
||||||
|
* Kopflink) ist deshalb nur aktiv, wenn die Umgebung nicht Produktion ist und der Zahlungstreiber „test“ gilt.
|
||||||
|
* Dieselbe Bedingung gilt für die Testzahlung der Bestellseite.
|
||||||
|
*/
|
||||||
|
final class Shop
|
||||||
|
{
|
||||||
|
public static function enabled(): bool
|
||||||
|
{
|
||||||
|
return ! app()->isProduction() && config('services.payment.driver') === 'test';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Commerce;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preis oder bindende Bedingungen haben sich nach Anzeige der Bestellübersicht geändert. Es entsteht keine
|
||||||
|
* Bestellung; der Käufer sieht zuerst die aktualisierte Übersicht (FACH-59).
|
||||||
|
*/
|
||||||
|
class StaleOverview extends DomainRuleException {}
|
||||||
@@ -19,6 +19,7 @@ class Acquisition extends Model
|
|||||||
'reference_type',
|
'reference_type',
|
||||||
'reference_id',
|
'reference_id',
|
||||||
'conditions',
|
'conditions',
|
||||||
|
'acting_user_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public function __invoke(
|
|||||||
$candidates = Grant::query()
|
$candidates = Grant::query()
|
||||||
->where('license_article_id', $article->id)
|
->where('license_article_id', $article->id)
|
||||||
->where('status', GrantStatus::Aktiv)
|
->where('status', GrantStatus::Aktiv)
|
||||||
->whereHas('acquisition', fn ($query) => $query->where('party_id', $user->party_id))
|
->usableBy($user)
|
||||||
->get()
|
->get()
|
||||||
->filter(function (Grant $grant) use ($now): bool {
|
->filter(function (Grant $grant) use ($now): bool {
|
||||||
if ($grant->valid_from !== null && $grant->valid_from->greaterThan($now)) {
|
if ($grant->valid_from !== null && $grant->valid_from->greaterThan($now)) {
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
use App\Domain\Catalog\ArticleRelease;
|
use App\Domain\Catalog\ArticleRelease;
|
||||||
use App\Domain\Catalog\LicenseArticle;
|
use App\Domain\Catalog\LicenseArticle;
|
||||||
use App\Domain\Catalog\RightsProfileVersion;
|
use App\Domain\Catalog\RightsProfileVersion;
|
||||||
|
use App\Domain\Identity\Membership;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
@@ -32,6 +35,32 @@ protected function casts(): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Berechtigungen, die ein Konto nutzen darf (zentrale Regel für Entscheidung, Bibliothek und Vorschaubilder):
|
||||||
|
* - persönliche Erwerbe: Inhaber ist die Person des Kontos;
|
||||||
|
* - Erwerbe einer Organisation: nur das auslösende Konto und nur, solange seine Mitgliedschaft mit
|
||||||
|
* Bestellberechtigung besteht (Etappe 1, Domänenmodell 04; Sitzpools folgen mit A4).
|
||||||
|
*
|
||||||
|
* @param Builder<Grant> $query
|
||||||
|
* @return Builder<Grant>
|
||||||
|
*/
|
||||||
|
public function scopeUsableBy(Builder $query, User $user): Builder
|
||||||
|
{
|
||||||
|
return $query->whereHas('acquisition', function (Builder $acquisition) use ($user): void {
|
||||||
|
$acquisition->where(function (Builder $either) use ($user): void {
|
||||||
|
$either->where('party_id', $user->party_id)
|
||||||
|
->orWhere(function (Builder $organisation) use ($user): void {
|
||||||
|
$organisation->where('acting_user_id', $user->id)
|
||||||
|
->whereIn('party_id', Membership::query()
|
||||||
|
->active()
|
||||||
|
->where('user_id', $user->id)
|
||||||
|
->where('may_order', true)
|
||||||
|
->select('party_id'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function acquisition(): BelongsTo
|
public function acquisition(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Acquisition::class);
|
return $this->belongsTo(Acquisition::class);
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
use App\Domain\Catalog\OfferService;
|
use App\Domain\Catalog\OfferService;
|
||||||
use App\Domain\Catalog\OfferStatus;
|
use App\Domain\Catalog\OfferStatus;
|
||||||
use App\Domain\Catalog\OfferVersion;
|
use App\Domain\Catalog\OfferVersion;
|
||||||
|
use App\Domain\Commerce\OrderLine;
|
||||||
|
use App\Domain\Identity\Party;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
@@ -69,6 +71,56 @@ public function grantManually(User $user, Offer $offer, User $actor, string $rea
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Freischaltung einer bezahlten Bestellposition aus deren festgehaltenem Umfang (Umfangskopie und Bedingungen der
|
||||||
|
* Position, nicht aus der Angebotsfassung). Inhaber ist der Lizenzinhaber der Position, das auslösende Konto wird
|
||||||
|
* am Erwerb festgehalten. Wiederholsicher: je Bestellposition genau ein Erwerb.
|
||||||
|
*/
|
||||||
|
public function issueFromOrderLine(OrderLine $line, Party $holder, User $actor): Acquisition
|
||||||
|
{
|
||||||
|
return DB::transaction(function () use ($line, $holder, $actor): Acquisition {
|
||||||
|
$existing = Acquisition::query()->where([
|
||||||
|
'party_id' => $holder->id,
|
||||||
|
'type' => AcquisitionType::Bestellposition,
|
||||||
|
'reference_type' => 'order_line',
|
||||||
|
'reference_id' => $line->id,
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
if ($existing !== null) {
|
||||||
|
return $existing->load('grants');
|
||||||
|
}
|
||||||
|
|
||||||
|
$acquisition = Acquisition::query()->create([
|
||||||
|
'party_id' => $holder->id,
|
||||||
|
'type' => AcquisitionType::Bestellposition,
|
||||||
|
'reference_type' => 'order_line',
|
||||||
|
'reference_id' => $line->id,
|
||||||
|
'acting_user_id' => $actor->id,
|
||||||
|
'conditions' => [
|
||||||
|
'term_rule' => $line->term_rule,
|
||||||
|
'update_promise' => $line->update_promise,
|
||||||
|
'holder_kind' => $line->holder_kind,
|
||||||
|
'offer_version_id' => $line->offer_version_id,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$line->loadMissing('scopeItems.article');
|
||||||
|
|
||||||
|
foreach ($line->scopeItems as $item) {
|
||||||
|
$acquisition->grants()->create([
|
||||||
|
'license_article_id' => $item->license_article_id,
|
||||||
|
'rights_profile_version_id' => $item->rights_profile_version_id,
|
||||||
|
'rights_snapshot' => $item->rights_snapshot,
|
||||||
|
'release_at_grant_id' => $item->article?->current_release_id,
|
||||||
|
'status' => GrantStatus::Aktiv,
|
||||||
|
'valid_from' => now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $acquisition->load('grants');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function issue(
|
public function issue(
|
||||||
User $user,
|
User $user,
|
||||||
OfferVersion $version,
|
OfferVersion $version,
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Identity;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mitgliedschaft eines Kontos in einer Organisation (Domänenmodell 04, MEMBERSHIP). Etappe 1 nutzt sie für die
|
||||||
|
* Bestellberechtigung: Ein Konto bestellt nur für eine Organisation, bei der eine aktive Mitgliedschaft mit
|
||||||
|
* `may_order` besteht. Sitzpools und Selbstverwaltung folgen mit A4.
|
||||||
|
*/
|
||||||
|
class Membership extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'user_id',
|
||||||
|
'party_id',
|
||||||
|
'role',
|
||||||
|
'may_order',
|
||||||
|
'valid_from',
|
||||||
|
'valid_until',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'may_order' => 'boolean',
|
||||||
|
'valid_from' => 'date',
|
||||||
|
'valid_until' => 'date',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function organisation(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Party::class, 'party_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mitgliedschaften, die heute gelten. */
|
||||||
|
public function scopeActive(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query
|
||||||
|
->where(fn (Builder $inner) => $inner->whereNull('valid_from')->orWhereDate('valid_from', '<=', now()))
|
||||||
|
->where(fn (Builder $inner) => $inner->whereNull('valid_until')->orWhereDate('valid_until', '>=', now()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Media;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\Composition;
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Übernimmt das Vorschaubild eines Programms oder Moduls als gewöhnliches Bild-Medium im Medienmanager
|
||||||
|
* (Programm- und Modulkarte), nach demselben Prinzip wie FilmStill.
|
||||||
|
*
|
||||||
|
* - Ausdrückliche Handlung der Redaktion. Das Vorschaubild ist ein geschütztes Bibliotheksbild; erst die Übernahme
|
||||||
|
* legt ein Medium an, das für die Website freigegeben werden kann (WebsiteIntake, Warteschlange).
|
||||||
|
* - Die Datei wird einmal kopiert. Dieselbe Vorschaudatei ergibt dasselbe Medium (composition_still_sources).
|
||||||
|
* - Es entsteht keine Fassung, keine Berechtigung, kein Lizenzartikel.
|
||||||
|
*/
|
||||||
|
class CompositionStill
|
||||||
|
{
|
||||||
|
/** Wahr, wenn der letzte Aufruf ein schon vorhandenes Bild geliefert hat. */
|
||||||
|
public bool $reused = false;
|
||||||
|
|
||||||
|
public function __construct(private readonly WebsiteIntake $intake) {}
|
||||||
|
|
||||||
|
public function refusal(Composition $composition): ?string
|
||||||
|
{
|
||||||
|
if ($composition->archived_at !== null) {
|
||||||
|
return 'Das Programm oder Modul ist archiviert.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasThumbnail(Composition $composition): bool
|
||||||
|
{
|
||||||
|
$path = $composition->thumbnail_path;
|
||||||
|
|
||||||
|
return is_string($path) && str_starts_with($path, 'vorschau/') && ! str_contains($path, '..')
|
||||||
|
&& Storage::disk('media_derived')->exists($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fromThumbnail(Composition $composition, ?User $actor = null): ContentElement
|
||||||
|
{
|
||||||
|
$this->reused = false;
|
||||||
|
$refusal = $this->refusal($composition);
|
||||||
|
|
||||||
|
if ($refusal !== null) {
|
||||||
|
throw new DomainRuleException($refusal);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->hasThumbnail($composition)) {
|
||||||
|
throw new DomainRuleException('Dieses Programm oder Modul hat noch kein Vorschaubild. Setzen Sie es im Redaktionsmanager.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$bytes = Storage::disk('media_derived')->get((string) $composition->thumbnail_path);
|
||||||
|
|
||||||
|
if (! is_string($bytes) || $bytes === '') {
|
||||||
|
throw new DomainRuleException('Das Vorschaubild ließ sich nicht lesen.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = 'file:'.hash('sha256', $bytes);
|
||||||
|
$existing = $this->existing($composition, $key);
|
||||||
|
|
||||||
|
if ($existing instanceof ContentElement) {
|
||||||
|
$this->reused = true;
|
||||||
|
|
||||||
|
return $existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = (string) ($composition->display_title ?: $composition->designation);
|
||||||
|
$path = 'cms/titelbild-'.$composition->id.'-'.Str::lower(Str::random(8)).'.jpg';
|
||||||
|
Storage::disk('cms_incoming')->put($path, $bytes);
|
||||||
|
|
||||||
|
$still = $this->intake->acceptImage($path, 'Titelbild: '.$title, null, 'Titelbild zu „'.$title.'“', $actor);
|
||||||
|
|
||||||
|
try {
|
||||||
|
CompositionStillSource::query()->updateOrCreate(
|
||||||
|
['composition_id' => $composition->id, 'source_key' => $key],
|
||||||
|
['still_element_id' => $still->id, 'actor_id' => $actor?->id],
|
||||||
|
);
|
||||||
|
} catch (QueryException) {
|
||||||
|
return $this->existing($composition, $key) ?? $still;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $still;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function existing(Composition $composition, string $key): ?ContentElement
|
||||||
|
{
|
||||||
|
$source = CompositionStillSource::query()->with('still')->where('composition_id', $composition->id)->where('source_key', $key)->first();
|
||||||
|
$still = $source?->still;
|
||||||
|
|
||||||
|
// Ein archiviertes oder bei der Verarbeitung gescheitertes Bild wird nicht wiederverwendet.
|
||||||
|
return $still instanceof ContentElement && $still->archived_at === null && ! filled($still->thumbnail_error) ? $still : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Media;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\Composition;
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Herkunft eines Bild-Mediums aus dem Vorschaubild eines Programms oder Moduls (source_key file:{SHA-256}).
|
||||||
|
*/
|
||||||
|
class CompositionStillSource extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = ['composition_id', 'still_element_id', 'source_key', 'actor_id'];
|
||||||
|
|
||||||
|
public function composition(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Composition::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function still(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ContentElement::class, 'still_element_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,213 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Media;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
|
use App\Domain\Catalog\ContentVersionStatus;
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
use App\Domain\Cms\Catalog\PublicMaterialReader;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Legt ein Bild aus einem Film als gewöhnliches Bild-Medium im Medienmanager ab (Medien- und Materialkarte).
|
||||||
|
*
|
||||||
|
* - Zwei Wege: das Vorschaubild des Films übernehmen oder eine Stelle (Sekunde) wählen. Beides ist eine
|
||||||
|
* ausdrückliche Handlung der Redaktion; erst dadurch entsteht ein Bild, das für die Website freigegeben werden kann.
|
||||||
|
* - Das Bild wird einmal gezogen und gespeichert (WebsiteIntake legt es an, die Warteschlange leitet es ab und gibt
|
||||||
|
* es frei). Seitenaufrufe lesen nur die gespeicherte Datei und starten nie ffmpeg.
|
||||||
|
* - Dieselbe Stelle (oder dieselbe Vorschaudatei) ergibt dasselbe Medium (film_still_sources).
|
||||||
|
* - Es wird nie der Film selbst, nur ein Einzelbild bis 1600 px Breite abgelegt. Traineranleitungen und
|
||||||
|
* archivierte oder gesperrte Filme sind ausgeschlossen. Eine Rechte- oder Lizenzentscheidung entsteht nicht.
|
||||||
|
*/
|
||||||
|
class FilmStill
|
||||||
|
{
|
||||||
|
/** Breite eines übernommenen Standbilds; die kleine Filmstufe (640 px) wäre auf der Website sichtbar unscharf. */
|
||||||
|
public const WIDTH = 1600;
|
||||||
|
|
||||||
|
/** Wahr, wenn der letzte Aufruf ein schon vorhandenes Bild geliefert hat (keine neue Extraktion). */
|
||||||
|
public bool $reused = false;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly ThumbnailDeriver $deriver,
|
||||||
|
private readonly WebsiteIntake $intake,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/** Grund, warum aus diesem Medium kein Standbild übernommen wird, sonst null. */
|
||||||
|
public function refusal(ContentElement $film): ?string
|
||||||
|
{
|
||||||
|
if ($film->output_class !== 'film') {
|
||||||
|
return 'Nur aus einem Film lässt sich ein Bild übernehmen.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($film->archived_at !== null) {
|
||||||
|
return 'Der Film ist archiviert.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$slug = $film->editorialContentKind?->slug;
|
||||||
|
|
||||||
|
if (in_array($slug, PublicMaterialReader::CONFIDENTIAL_KINDS, true)) {
|
||||||
|
return 'Aus Traineranleitungen werden keine Bilder für die Website übernommen.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Die bereitgestellte Fassung, aus der Stellen gezogen werden (die höchste). */
|
||||||
|
public function version(ContentElement $film): ?ContentElementVersion
|
||||||
|
{
|
||||||
|
return $film->versions()
|
||||||
|
->where('status', ContentVersionStatus::Bereit->value)
|
||||||
|
->orderByDesc('number')
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sekunde der Stelle, aus der das aktuelle Vorschaubild des Films stammt, sonst null. */
|
||||||
|
public function thumbnailSecond(ContentElement $film): ?string
|
||||||
|
{
|
||||||
|
$source = $film->thumbnail_source;
|
||||||
|
|
||||||
|
return is_string($source) && preg_match('/^frame:\d+@([\d.]+)$/', $source, $match) === 1 ? $match[1] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fromSecond(ContentElement $film, float $seconds, ?User $actor = null): ContentElement
|
||||||
|
{
|
||||||
|
$this->reused = false;
|
||||||
|
$this->guard($film);
|
||||||
|
|
||||||
|
if ($seconds < 0 || $seconds > 7200) {
|
||||||
|
throw new DomainRuleException('Die Zeitposition liegt außerhalb des Films.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = $this->version($film);
|
||||||
|
|
||||||
|
if (! $version instanceof ContentElementVersion) {
|
||||||
|
throw new DomainRuleException('Der Film hat noch keine bereitgestellte Fassung.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->fromFrame($film, $version, $seconds, $actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fromThumbnail(ContentElement $film, ?User $actor = null): ContentElement
|
||||||
|
{
|
||||||
|
$this->reused = false;
|
||||||
|
$this->guard($film);
|
||||||
|
|
||||||
|
// Stammt das Vorschaubild aus einer Filmstelle, wird dieselbe Stelle in voller Auflösung gezogen.
|
||||||
|
$second = $this->thumbnailSecond($film);
|
||||||
|
|
||||||
|
if ($second !== null && preg_match('/^frame:(\d+)@/', (string) $film->thumbnail_source, $match) === 1) {
|
||||||
|
$version = ContentElementVersion::query()->find((int) $match[1]);
|
||||||
|
|
||||||
|
if ($version instanceof ContentElementVersion
|
||||||
|
&& (int) $version->content_element_id === (int) $film->id
|
||||||
|
&& $version->status !== ContentVersionStatus::Gesperrt) {
|
||||||
|
try {
|
||||||
|
return $this->fromFrame($film, $version, (float) $second, $actor);
|
||||||
|
} catch (DomainRuleException) {
|
||||||
|
// Die Stelle lässt sich nicht mehr ziehen: das gespeicherte Vorschaubild selbst übernehmen.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = $film->thumbnail_path;
|
||||||
|
|
||||||
|
if (! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..') || ! Storage::disk('media_derived')->exists($path)) {
|
||||||
|
throw new DomainRuleException('Dieser Film hat noch kein Vorschaubild. Setzen Sie es im Medienmanager oder wählen Sie eine Stelle.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$bytes = Storage::disk('media_derived')->get($path);
|
||||||
|
|
||||||
|
if (! is_string($bytes) || $bytes === '') {
|
||||||
|
throw new DomainRuleException('Das Vorschaubild ließ sich nicht lesen.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = 'file:'.hash('sha256', $bytes);
|
||||||
|
$existing = $this->existing($film, $key);
|
||||||
|
|
||||||
|
if ($existing instanceof ContentElement) {
|
||||||
|
$this->reused = true;
|
||||||
|
|
||||||
|
return $existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->store($film, $key, $bytes, 'Vorschaubild', $actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fromFrame(ContentElement $film, ContentElementVersion $version, float $seconds, ?User $actor): ContentElement
|
||||||
|
{
|
||||||
|
$second = $this->secondText($seconds);
|
||||||
|
$key = 'frame:'.$version->id.'@'.$second;
|
||||||
|
$existing = $this->existing($film, $key);
|
||||||
|
|
||||||
|
if ($existing instanceof ContentElement) {
|
||||||
|
$this->reused = true;
|
||||||
|
|
||||||
|
return $existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
$bytes = $this->deriver->frameJpeg($version, (float) $second, self::WIDTH, original: true);
|
||||||
|
|
||||||
|
if (! is_string($bytes)) {
|
||||||
|
throw new DomainRuleException('Aus dieser Filmstelle ließ sich kein Bild erzeugen.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->store($film, $key, $bytes, 'Fassung '.$version->number.', '.str_replace('.', ',', $second).' s', $actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function guard(ContentElement $film): void
|
||||||
|
{
|
||||||
|
$refusal = $this->refusal($film);
|
||||||
|
|
||||||
|
if ($refusal !== null) {
|
||||||
|
throw new DomainRuleException($refusal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function existing(ContentElement $film, string $key): ?ContentElement
|
||||||
|
{
|
||||||
|
$source = FilmStillSource::query()->with('still')->where('film_element_id', $film->id)->where('source_key', $key)->first();
|
||||||
|
$still = $source?->still;
|
||||||
|
|
||||||
|
// Ein archiviertes oder an der Verarbeitung gescheitertes Bild wird nicht wiederverwendet; die Stelle kann neu
|
||||||
|
// übernommen werden (store() ordnet dann das neue Bild zu).
|
||||||
|
return $still instanceof ContentElement && $still->archived_at === null && ! filled($still->thumbnail_error) ? $still : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function store(ContentElement $film, string $key, string $bytes, string $label, ?User $actor): ContentElement
|
||||||
|
{
|
||||||
|
$title = (string) ($film->display_title ?: $film->working_title);
|
||||||
|
$path = 'cms/standbild-'.$film->id.'-'.Str::lower(Str::random(8)).'.jpg';
|
||||||
|
Storage::disk('cms_incoming')->put($path, $bytes);
|
||||||
|
|
||||||
|
$still = $this->intake->acceptImage(
|
||||||
|
$path,
|
||||||
|
'Standbild: '.$title.' ('.$label.')',
|
||||||
|
filled($film->website_credit) ? (string) $film->website_credit : null,
|
||||||
|
'Szene aus dem Film „'.$title.'“',
|
||||||
|
$actor,
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
FilmStillSource::query()->updateOrCreate(
|
||||||
|
['film_element_id' => $film->id, 'source_key' => $key],
|
||||||
|
['still_element_id' => $still->id, 'actor_id' => $actor?->id],
|
||||||
|
);
|
||||||
|
} catch (QueryException) {
|
||||||
|
// Gleichzeitige Übernahme derselben Stelle: das zuerst angelegte Bild gilt.
|
||||||
|
return $this->existing($film, $key) ?? $still;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $still;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function secondText(float $seconds): string
|
||||||
|
{
|
||||||
|
$text = number_format(max(0, min(7200, $seconds)), 3, '.', '');
|
||||||
|
|
||||||
|
return rtrim(rtrim($text, '0'), '.') ?: '0';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Media;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Herkunft eines Standbilds: aus welchem Film und welcher Stelle (frame:{Fassung}@{Sekunde}) oder aus welcher Datei
|
||||||
|
* (file:{SHA-256}) das Bild-Medium stammt.
|
||||||
|
*/
|
||||||
|
class FilmStillSource extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = ['film_element_id', 'still_element_id', 'source_key', 'actor_id'];
|
||||||
|
|
||||||
|
public function film(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ContentElement::class, 'film_element_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function still(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ContentElement::class, 'still_element_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Media;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Legt die technische Ableitung eines Präsentationsmediums an der Medienidentität ab.
|
||||||
|
* Es entsteht keine Inhaltsfassung, keine Freigabe und keine Berechtigung.
|
||||||
|
*/
|
||||||
|
class PresentationFile
|
||||||
|
{
|
||||||
|
public function store(ContentElement $element, string $incoming): void
|
||||||
|
{
|
||||||
|
if (! in_array($element->output_class, ['bild', 'film', 'audio'], true)) {
|
||||||
|
throw new DomainRuleException('Eine Präsentationsdatei ist ein Bild, ein Film oder ein Hörstück.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($element->versions()->exists()) {
|
||||||
|
throw new DomainRuleException('Dieses Medium hat bereits eine Inhaltsfassung. Die Präsentationsdatei ersetzt sie nicht.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->readable($incoming)) {
|
||||||
|
throw new DomainRuleException('Die Datei liegt nicht im Eingang.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$extension = strtolower(pathinfo($incoming, PATHINFO_EXTENSION));
|
||||||
|
$allowed = match ($element->output_class) {
|
||||||
|
'bild' => ['jpg', 'jpeg', 'png', 'webp', 'gif'],
|
||||||
|
'audio' => ['mp3', 'm4a', 'ogg'],
|
||||||
|
default => ['mp4', 'webm'],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (! in_array($extension, $allowed, true)) {
|
||||||
|
throw new DomainRuleException('Diese Datei ist keine freigebbare Ableitung. Es wird keine Inhaltsfassung angelegt.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$prefix = $element->output_class === 'bild' ? 'vorschau' : 'teaser';
|
||||||
|
$target = $prefix.'/'.$element->id.'/datei.'.$extension;
|
||||||
|
$stream = Storage::disk('cms_incoming')->readStream($incoming);
|
||||||
|
|
||||||
|
if (! is_resource($stream)) {
|
||||||
|
throw new DomainRuleException('Die Datei ließ sich nicht lesen.');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Storage::disk('media_derived')->writeStream($target, $stream);
|
||||||
|
} finally {
|
||||||
|
fclose($stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($element->output_class === 'bild') {
|
||||||
|
$element->thumbnail_path = $target;
|
||||||
|
$element->thumbnail_source = 'eigen';
|
||||||
|
} else {
|
||||||
|
$element->preview_path = $target;
|
||||||
|
}
|
||||||
|
|
||||||
|
$element->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function readable(string $path): bool
|
||||||
|
{
|
||||||
|
return (str_starts_with($path, 'inhalte/') || str_starts_with($path, 'cms/') || str_starts_with($path, 'vorschau/'))
|
||||||
|
&& ! str_contains($path, '..')
|
||||||
|
&& preg_match('#^(inhalte|cms|vorschau)/[A-Za-z0-9._\-/]+$#', $path) === 1
|
||||||
|
&& Storage::disk('cms_incoming')->exists($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,6 +52,18 @@ public function forElementUpload(ContentElement $element, string $incoming): voi
|
|||||||
$this->rememberElement($element, 'eigen');
|
$this->rememberElement($element, 'eigen');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function forWebsiteImage(ContentElement $element, string $incoming): void
|
||||||
|
{
|
||||||
|
if ($element->output_class !== 'bild' || ! $this->incomingIsSafe($incoming)) {
|
||||||
|
$this->fail($element, 'Das Bild für die Website wurde nicht übernommen.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->still($element, Storage::disk('cms_incoming'), $incoming, 'element-'.$element->id);
|
||||||
|
$this->rememberElement($element, 'eigen');
|
||||||
|
}
|
||||||
|
|
||||||
public function forElementFrame(ContentElement $element, ContentElementVersion $version, float $seconds): void
|
public function forElementFrame(ContentElement $element, ContentElementVersion $version, float $seconds): void
|
||||||
{
|
{
|
||||||
if ($version->content_element_id !== $element->id || $element->output_class !== 'film') {
|
if ($version->content_element_id !== $element->id || $element->output_class !== 'film') {
|
||||||
@@ -126,8 +138,20 @@ public function forCompositionFrame(Composition $composition, ContentElementVers
|
|||||||
$this->rememberChoice($composition, 'frame:'.$version->id.'@'.$this->secondText($seconds));
|
$this->rememberChoice($composition, 'frame:'.$version->id.'@'.$this->secondText($seconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function frameInput(ContentElementVersion $version): ?string
|
/**
|
||||||
|
* Datei, aus der ein Bild gezogen wird. Vorgabe: die kleine Filmstufe (schnell, für die Vorschau). Mit $original
|
||||||
|
* zuerst die Mediendatei selbst, damit ein übernommenes Standbild nicht aus der kleinen Stufe hochgerechnet wird.
|
||||||
|
*/
|
||||||
|
public function frameInput(ContentElementVersion $version, bool $original = false): ?string
|
||||||
{
|
{
|
||||||
|
if ($original) {
|
||||||
|
$master = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null;
|
||||||
|
|
||||||
|
if ($this->readableDerived($master, 'inhalte/')) {
|
||||||
|
return $master;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$proxy = MediaRendition::query()
|
$proxy = MediaRendition::query()
|
||||||
->where('content_element_version_id', $version->id)
|
->where('content_element_version_id', $version->id)
|
||||||
->where('role', 'variant')
|
->where('role', 'variant')
|
||||||
@@ -143,13 +167,25 @@ public function frameInput(ContentElementVersion $version): ?string
|
|||||||
return $this->readableDerived($file, 'inhalte/') ? $file : null;
|
return $this->readableDerived($file, 'inhalte/') ? $file : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Einzelbild einer Filmstelle als JPEG, 640 px breit aus der kleinen Stufe (Vorschau im Editor und Vorschaubild).
|
||||||
|
*/
|
||||||
public function jpegAtVersion(ContentElementVersion $version, float $seconds): ?string
|
public function jpegAtVersion(ContentElementVersion $version, float $seconds): ?string
|
||||||
|
{
|
||||||
|
return $this->frameJpeg($version, $seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Einzelbild einer Filmstelle als JPEG. Ein übernommenes Standbild (FilmStill) wird mit $width und $original aus der
|
||||||
|
* Mediendatei gezogen statt aus der kleinen Stufe und dabei nie über die Breite der Quelle hinaus vergrößert.
|
||||||
|
*/
|
||||||
|
public function frameJpeg(ContentElementVersion $version, float $seconds, int $width = 640, bool $original = false): ?string
|
||||||
{
|
{
|
||||||
if ($seconds < 0 || $seconds > 7200) {
|
if ($seconds < 0 || $seconds > 7200) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = $this->frameInput($version);
|
$file = $this->frameInput($version, $original);
|
||||||
|
|
||||||
if ($file === null) {
|
if ($file === null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -174,7 +210,7 @@ public function jpegAtVersion(ContentElementVersion $version, float $seconds): ?
|
|||||||
'-frames:v',
|
'-frames:v',
|
||||||
'1',
|
'1',
|
||||||
'-vf',
|
'-vf',
|
||||||
'scale=640:-2',
|
$width === 640 ? 'scale=640:-2' : 'scale=min('.max(160, min(2400, $width)).'\,iw):-2',
|
||||||
'-f',
|
'-f',
|
||||||
'image2pipe',
|
'image2pipe',
|
||||||
'-vcodec',
|
'-vcodec',
|
||||||
@@ -201,6 +237,14 @@ private function readableDerived(mixed $path, string $prefix): bool
|
|||||||
return Storage::disk('media_derived')->exists($path);
|
return Storage::disk('media_derived')->exists($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function incomingIsSafe(string $incoming): bool
|
||||||
|
{
|
||||||
|
return (str_starts_with($incoming, 'cms/') || str_starts_with($incoming, 'vorschau/'))
|
||||||
|
&& ! str_contains($incoming, '..')
|
||||||
|
&& preg_match('#^(cms|vorschau)/[A-Za-z0-9._\-/]+$#', $incoming) === 1
|
||||||
|
&& Storage::disk('cms_incoming')->exists($incoming);
|
||||||
|
}
|
||||||
|
|
||||||
private function secondText(float $seconds): string
|
private function secondText(float $seconds): string
|
||||||
{
|
{
|
||||||
$seconds = max(0, min(7200, $seconds));
|
$seconds = max(0, min(7200, $seconds));
|
||||||
@@ -271,9 +315,15 @@ private function still(ContentElement|Composition $subject, Filesystem $disk, st
|
|||||||
|
|
||||||
$width = imagesx($image);
|
$width = imagesx($image);
|
||||||
$height = imagesy($image);
|
$height = imagesy($image);
|
||||||
$targetWidth = 640;
|
// Bilder (Ausgabeart „bild“) dienen auch als Website-Ableitung für Einstieg und Hintergrund. 640 px wären dort
|
||||||
|
// sichtbar unscharf; deshalb bis 2400 px, nie vergrößert. Filmstandbilder und Modulvorschauen bleiben bei 640 px.
|
||||||
|
$targetWidth = $subject instanceof ContentElement && $subject->output_class === 'bild'
|
||||||
|
? max(1, min(2400, $width))
|
||||||
|
: 640;
|
||||||
$targetHeight = (int) max(1, round($height * ($targetWidth / max(1, $width))));
|
$targetHeight = (int) max(1, round($height * ($targetWidth / max(1, $width))));
|
||||||
$canvas = imagecreatetruecolor($targetWidth, $targetHeight);
|
$canvas = imagecreatetruecolor($targetWidth, $targetHeight);
|
||||||
|
// Transparente Flächen (PNG, GIF) werden im JPEG weiß statt schwarz.
|
||||||
|
imagefill($canvas, 0, 0, (int) imagecolorallocate($canvas, 255, 255, 255));
|
||||||
imagecopyresampled($canvas, $image, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height);
|
imagecopyresampled($canvas, $image, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height);
|
||||||
ob_start();
|
ob_start();
|
||||||
imagejpeg($canvas, null, 82);
|
imagejpeg($canvas, null, 82);
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Media;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\ContentService;
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
use App\Domain\Catalog\IdentityProfile;
|
||||||
|
use App\Jobs\AcceptWebsiteImage;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nimmt ein neues Website-Bild in den Medienmanager auf.
|
||||||
|
* Die Warteschlange erzeugt danach die Ableitung und gibt sie frei.
|
||||||
|
*/
|
||||||
|
class WebsiteIntake
|
||||||
|
{
|
||||||
|
public function acceptImage(
|
||||||
|
string $incomingPath,
|
||||||
|
string $title,
|
||||||
|
?string $credit = null,
|
||||||
|
?string $alt = null,
|
||||||
|
?User $actor = null,
|
||||||
|
): ContentElement {
|
||||||
|
$title = trim($title);
|
||||||
|
|
||||||
|
if ($title === '') {
|
||||||
|
throw new DomainRuleException('Der Titel fehlt.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->incomingIsReadable($incomingPath)) {
|
||||||
|
throw new DomainRuleException('Die Bilddatei liegt nicht im Eingang.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$element = app(ContentService::class)->createElement('bild', 'bild', $title);
|
||||||
|
app(IdentityProfile::class)->fill($element, [
|
||||||
|
'display_title' => $title,
|
||||||
|
'website_credit' => $credit,
|
||||||
|
'website_alt' => $alt,
|
||||||
|
], $actor);
|
||||||
|
AcceptWebsiteImage::dispatch($element->id, $incomingPath, $actor?->id);
|
||||||
|
|
||||||
|
return $element->fresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function incomingIsReadable(string $path): bool
|
||||||
|
{
|
||||||
|
return (str_starts_with($path, 'cms/') || str_starts_with($path, 'vorschau/'))
|
||||||
|
&& ! str_contains($path, '..')
|
||||||
|
&& preg_match('#^(cms|vorschau)/[A-Za-z0-9._\-/]+$#', $path) === 1
|
||||||
|
&& Storage::disk('cms_incoming')->exists($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Media;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lesesicht für Hero, Teaser und Slideshow.
|
||||||
|
* Liefert nur eine freigegebene öffentliche Ableitung, sonst nichts.
|
||||||
|
*/
|
||||||
|
class WebsiteMedia
|
||||||
|
{
|
||||||
|
public function present(ContentElement|int $element): ?WebsitePresentation
|
||||||
|
{
|
||||||
|
$element = $element instanceof ContentElement
|
||||||
|
? $element
|
||||||
|
: ContentElement::query()->find($element);
|
||||||
|
|
||||||
|
if (! $element instanceof ContentElement || $element->website_released_at === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = $element->website_public_path;
|
||||||
|
$expected = '#^website/'.$element->id.'/datei\.[a-z0-9]+$#';
|
||||||
|
|
||||||
|
if (! is_string($path) || preg_match($expected, $path) !== 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! Storage::disk('media_public')->exists($path)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = trim((string) ($element->display_title ?: $element->working_title));
|
||||||
|
$alt = trim((string) ($element->website_alt ?? ''));
|
||||||
|
|
||||||
|
return new WebsitePresentation(
|
||||||
|
elementId: $element->id,
|
||||||
|
title: $title,
|
||||||
|
alt: $alt !== '' ? $alt : $title,
|
||||||
|
credit: filled($element->website_credit) ? trim((string) $element->website_credit) : null,
|
||||||
|
kind: match ($element->output_class) {
|
||||||
|
'film' => 'film',
|
||||||
|
'audio' => 'audio',
|
||||||
|
default => 'bild',
|
||||||
|
},
|
||||||
|
url: route('website.media', $element),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Slideshow: freigegebene Medien in der angegebenen Reihenfolge. Nicht freigegebene Einträge entfallen.
|
||||||
|
*
|
||||||
|
* @param list<int|string> $ids
|
||||||
|
* @return list<WebsitePresentation>
|
||||||
|
*/
|
||||||
|
public function presentMany(array $ids): array
|
||||||
|
{
|
||||||
|
$presentations = [];
|
||||||
|
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
if (! is_numeric($id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$presentation = $this->present((int) $id);
|
||||||
|
|
||||||
|
if ($presentation !== null) {
|
||||||
|
$presentations[] = $presentation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $presentations;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Media;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\IdentityChange;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Früherer CMS-Bildpfad (cms/…), der in den Medienmanager übernommen wurde.
|
||||||
|
*
|
||||||
|
* Wirksam ist die Zuordnung erst, wenn das Medium mindestens einmal für die Website freigegeben war. Bis dahin
|
||||||
|
* (Ableitung läuft noch oder ist fehlgeschlagen) bleibt der frühere Pfad gültig, damit keine Seite ihr Bild verliert.
|
||||||
|
* Danach entscheidet allein die Website-Freigabe des Mediums, auch über die frühere Adresse /medien/cms/….
|
||||||
|
*/
|
||||||
|
class WebsiteMediaAlias extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = ['legacy_path', 'content_element_id', 'sha256'];
|
||||||
|
|
||||||
|
public function element(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ContentElement::class, 'content_element_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wirksame Zuordnung für einen früheren Pfad, sonst null. Zwischengespeichert wird im Aufrufer (WebsiteImage, je Anfrage).
|
||||||
|
*/
|
||||||
|
public static function effectiveFor(mixed $path): ?self
|
||||||
|
{
|
||||||
|
if (! is_string($path) || $path === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$alias = self::query()->with('element')->where('legacy_path', $path)->first();
|
||||||
|
|
||||||
|
return $alias instanceof self && $alias->everReleased() ? $alias : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Früherer Pfad, dessen übernommenes Medium inzwischen gelöscht wurde. Die Datei unter cms/ bleibt liegen, wird aber
|
||||||
|
* weder ausgeliefert noch als Bild gezeigt: Das Löschen des Mediums gilt auch für die frühere Adresse.
|
||||||
|
*/
|
||||||
|
public static function isRetired(mixed $path): bool
|
||||||
|
{
|
||||||
|
return is_string($path) && $path !== ''
|
||||||
|
&& self::query()->where('legacy_path', $path)->whereNull('content_element_id')->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function everReleased(): bool
|
||||||
|
{
|
||||||
|
$element = $this->element;
|
||||||
|
|
||||||
|
if ($element === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($element->website_released_at !== null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return IdentityChange::query()
|
||||||
|
->where('subject_type', $element->getMorphClass())
|
||||||
|
->where('subject_id', $element->id)
|
||||||
|
->where('field', 'website_released_at')
|
||||||
|
->whereNotNull('after')
|
||||||
|
->exists();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Media;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Öffentliche Ableitung eines für die Website freigegebenen Mediums.
|
||||||
|
* Enthält keine internen Vermerke und keine Adresse einer Bestandsdatei.
|
||||||
|
*/
|
||||||
|
final class WebsitePresentation
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public readonly int $elementId,
|
||||||
|
public readonly string $title,
|
||||||
|
public readonly string $alt,
|
||||||
|
public readonly ?string $credit,
|
||||||
|
public readonly string $kind,
|
||||||
|
public readonly string $url,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Media;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\ContentVersionStatus;
|
||||||
|
use App\Domain\Catalog\EditorialContentKind;
|
||||||
|
use App\Domain\Cms\Catalog\PublicMaterialReader;
|
||||||
|
use App\Jobs\PublishWebsiteMedia;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt eine Ableitung für die Website frei oder nimmt sie zurück.
|
||||||
|
* Legt keinen Lizenzartikel an und ruft DecideAccess nicht auf.
|
||||||
|
* Der Web-Prozess schreibt die öffentliche Datei nicht selbst; das tut die Warteschlange.
|
||||||
|
*/
|
||||||
|
class WebsiteRelease
|
||||||
|
{
|
||||||
|
public function release(ContentElement $element, ?User $actor = null): string
|
||||||
|
{
|
||||||
|
$refusal = $this->refusal($element);
|
||||||
|
|
||||||
|
if ($refusal !== null) {
|
||||||
|
return $refusal;
|
||||||
|
}
|
||||||
|
|
||||||
|
PublishWebsiteMedia::dispatch($element->id, 'release', $actor?->id);
|
||||||
|
|
||||||
|
return 'Für die Website freigegeben. Öffentliche Seiten lesen nur diese Ableitung.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withdraw(ContentElement $element, ?User $actor = null): string
|
||||||
|
{
|
||||||
|
PublishWebsiteMedia::dispatch($element->id, 'withdraw', $actor?->id);
|
||||||
|
|
||||||
|
return 'Die Website-Freigabe ist zurückgenommen.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function refusal(ContentElement $element): ?string
|
||||||
|
{
|
||||||
|
if ($this->isConfidential($element)) {
|
||||||
|
return 'Traineranleitungen werden nicht für die Website freigegeben.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->derivedPath($element) === null) {
|
||||||
|
return 'Für die Website fehlt eine freigebbare Ableitung. Beim Bild ist das das Vorschaubild. Film und Hörstück ohne Inhaltsfassung nutzen die Datei am Medium unter teaser/. Ein Film mit Inhaltsfassung nutzt die Teaserfassung seiner bereitgestellten Fassung. Die Originaldatei bleibt geschützt.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function derivedPath(ContentElement $element): ?string
|
||||||
|
{
|
||||||
|
if ($this->isConfidential($element)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($element->output_class === 'bild') {
|
||||||
|
return $this->allowedDerivedPath($element->thumbnail_path, 'vorschau/', ['jpg', 'jpeg', 'png', 'webp', 'gif']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($element->output_class, ['film', 'audio'], true)) {
|
||||||
|
$extensions = $element->output_class === 'audio'
|
||||||
|
? ['mp3', 'm4a', 'ogg']
|
||||||
|
: ['mp4', 'webm'];
|
||||||
|
$own = $this->allowedDerivedPath($element->preview_path, 'teaser/', $extensions);
|
||||||
|
|
||||||
|
if ($own !== null) {
|
||||||
|
return $own;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($element->output_class !== 'film') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = $element->versions()
|
||||||
|
->where('status', ContentVersionStatus::Bereit->value)
|
||||||
|
->orderByDesc('number')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($version === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = MediaRendition::query()
|
||||||
|
->where('content_element_version_id', $version->id)
|
||||||
|
->where('role', 'preview')
|
||||||
|
->orderByDesc('id')
|
||||||
|
->value('path');
|
||||||
|
|
||||||
|
return $this->allowedDerivedPath($path, 'teaser/', ['mp4', 'webm']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function publicPath(ContentElement $element, string $derivedPath): string
|
||||||
|
{
|
||||||
|
$extension = strtolower(pathinfo($derivedPath, PATHINFO_EXTENSION));
|
||||||
|
|
||||||
|
return 'website/'.$element->id.'/datei.'.$extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isConfidential(ContentElement $element): bool
|
||||||
|
{
|
||||||
|
$slug = $element->editorialContentKind?->slug;
|
||||||
|
|
||||||
|
if ($slug === null && $element->editorial_content_kind_id !== null) {
|
||||||
|
$slug = EditorialContentKind::query()->whereKey($element->editorial_content_kind_id)->value('slug');
|
||||||
|
}
|
||||||
|
|
||||||
|
return in_array($slug, PublicMaterialReader::CONFIDENTIAL_KINDS, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<string> $extensions
|
||||||
|
*/
|
||||||
|
private function allowedDerivedPath(mixed $path, string $prefix, array $extensions): ?string
|
||||||
|
{
|
||||||
|
if (! is_string($path) || ! str_starts_with($path, $prefix) || str_contains($path, '..')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||||
|
|
||||||
|
if (! in_array($extension, $extensions, true)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! Storage::disk('media_derived')->exists($path)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,20 +2,21 @@
|
|||||||
|
|
||||||
namespace App\Filament\Pages;
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
use App\Domain\Catalog\Composition;
|
|
||||||
use App\Domain\Catalog\CompositionKind;
|
use App\Domain\Catalog\CompositionKind;
|
||||||
use App\Domain\Catalog\ContentVersionStatus;
|
|
||||||
use App\Domain\Catalog\EditorialDimension;
|
|
||||||
use App\Domain\Catalog\IdentityDimensionValue;
|
|
||||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
use App\Filament\Support\EditorialCatalog;
|
use App\Filament\Support\ListsCompositions;
|
||||||
use Filament\Pages\Page;
|
use Filament\Pages\Page;
|
||||||
use Filament\Support\Enums\Width;
|
use Filament\Support\Enums\Width;
|
||||||
use Illuminate\Contracts\Support\Htmlable;
|
use Illuminate\Contracts\Support\Htmlable;
|
||||||
use Livewire\Attributes\Url;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arbeitsplatz: Programme und Module in der gemeinsamen Bestandsliste. Die Listen „Module“ und „Programme“ zeigen
|
||||||
|
* dieselben Zeilen mit festem Typ (ListsCompositions).
|
||||||
|
*/
|
||||||
class EditorialDesk extends Page
|
class EditorialDesk extends Page
|
||||||
{
|
{
|
||||||
|
use ListsCompositions;
|
||||||
|
|
||||||
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||||
|
|
||||||
protected static ?string $navigationLabel = 'Arbeitsplatz';
|
protected static ?string $navigationLabel = 'Arbeitsplatz';
|
||||||
@@ -28,24 +29,6 @@ class EditorialDesk extends Page
|
|||||||
|
|
||||||
protected string $view = 'filament.editorial.desk-page';
|
protected string $view = 'filament.editorial.desk-page';
|
||||||
|
|
||||||
#[Url]
|
|
||||||
public string $query = '';
|
|
||||||
|
|
||||||
#[Url]
|
|
||||||
public string $kindFilter = 'alle';
|
|
||||||
|
|
||||||
#[Url]
|
|
||||||
public string $pillar = '';
|
|
||||||
|
|
||||||
#[Url]
|
|
||||||
public string $visibility = 'alle';
|
|
||||||
|
|
||||||
public string $programName = '';
|
|
||||||
|
|
||||||
public string $moduleName = '';
|
|
||||||
|
|
||||||
public string $feedback = '';
|
|
||||||
|
|
||||||
public function getHeading(): string|Htmlable|null
|
public function getHeading(): string|Htmlable|null
|
||||||
{
|
{
|
||||||
return 'Programme und Module';
|
return 'Programme und Module';
|
||||||
@@ -53,7 +36,7 @@ public function getHeading(): string|Htmlable|null
|
|||||||
|
|
||||||
public function getSubheading(): string|Htmlable|null
|
public function getSubheading(): string|Htmlable|null
|
||||||
{
|
{
|
||||||
return 'Vorhandene Einträge öffnen oder einen neuen anlegen. Technische Kennungen sind dafür nicht nötig.';
|
return 'Vorhandene Einträge öffnen oder einen neuen anlegen. Ein Programm ordnet Module; ein Modul ordnet Medien und Texte.';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMaxContentWidth(): Width|string|null
|
public function getMaxContentWidth(): Width|string|null
|
||||||
@@ -66,185 +49,11 @@ public static function canAccess(): bool
|
|||||||
return ContentElementResource::editor();
|
return ContentElementResource::editor();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function getHeaderActions(): array
|
||||||
* @return list<array{label: string, values: list<array{id: int, label: string}>}>
|
|
||||||
*/
|
|
||||||
public function dimensionFilters(): array
|
|
||||||
{
|
{
|
||||||
$groups = [];
|
return [
|
||||||
|
$this->createCompositionAction(CompositionKind::Uebung),
|
||||||
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
|
$this->createCompositionAction(CompositionKind::Kurs),
|
||||||
$values = [];
|
];
|
||||||
|
|
||||||
foreach ($dimension->values as $value) {
|
|
||||||
$values[] = ['id' => $value->id, 'label' => $value->label];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($values !== []) {
|
|
||||||
$groups[] = ['label' => $dimension->label, 'values' => $values];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $groups;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function resetFilters(): void
|
|
||||||
{
|
|
||||||
$this->query = '';
|
|
||||||
$this->kindFilter = 'alle';
|
|
||||||
$this->pillar = '';
|
|
||||||
$this->visibility = 'alle';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasActiveFilters(): bool
|
|
||||||
{
|
|
||||||
return trim($this->query) !== '' || $this->kindFilter !== 'alle' || $this->pillar !== '' || $this->visibility !== 'alle';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return list<array<string, mixed>>
|
|
||||||
*/
|
|
||||||
public function entries(): array
|
|
||||||
{
|
|
||||||
$query = trim($this->query);
|
|
||||||
$needle = mb_strtolower($query);
|
|
||||||
$catalog = app(EditorialCatalog::class);
|
|
||||||
$offered = $catalog->offeredCompositionIds();
|
|
||||||
$pillarIds = $this->pillar === '' ? null : $this->pillarSubjects((int) $this->pillar);
|
|
||||||
$rows = [];
|
|
||||||
|
|
||||||
$compositions = Composition::query()
|
|
||||||
->whereIn('kind', [CompositionKind::Kurs, CompositionKind::Uebung])
|
|
||||||
->with(['editorialContentKind', 'versions.members.contentElementVersion.element'])
|
|
||||||
->orderBy('designation')
|
|
||||||
->get();
|
|
||||||
|
|
||||||
foreach ($compositions as $composition) {
|
|
||||||
$kind = $composition->kind instanceof CompositionKind
|
|
||||||
? $composition->kind
|
|
||||||
: CompositionKind::from((string) $composition->kind);
|
|
||||||
|
|
||||||
if ($this->kindFilter === 'programm' && $kind !== CompositionKind::Kurs) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->kindFilter === 'modul' && $kind !== CompositionKind::Uebung) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($pillarIds !== null && ! in_array($composition->id, $pillarIds, true)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$stand = $catalog->stand($composition);
|
|
||||||
|
|
||||||
if (! $this->matchesVisibility($stand)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$title = $catalog->compositionTitle($composition);
|
|
||||||
$summary = (string) ($composition->summary ?? '');
|
|
||||||
$haystack = mb_strtolower($title.' '.$composition->designation.' '.$summary.' '.(string) $composition->description);
|
|
||||||
|
|
||||||
if ($needle !== '' && ! str_contains($haystack, $needle)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cover = $catalog->cover($composition, $this->coverMembers($composition));
|
|
||||||
$rows[] = [
|
|
||||||
'title' => $title,
|
|
||||||
'kind' => $kind->deskLabel(),
|
|
||||||
'tone' => $kind === CompositionKind::Kurs ? 'programm' : 'modul',
|
|
||||||
'summary' => $summary,
|
|
||||||
'url' => EditorialCatalog::editUrl($composition),
|
|
||||||
'image' => $cover['url'],
|
|
||||||
'image_note' => $cover['note'],
|
|
||||||
'chips' => $catalog->statusChips($composition, in_array($composition->id, $offered, true)),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return list<array{target: string}>
|
|
||||||
*/
|
|
||||||
private function coverMembers(Composition $composition): array
|
|
||||||
{
|
|
||||||
$draft = $composition->working_draft;
|
|
||||||
|
|
||||||
if (is_array($draft) && is_array($draft['members'] ?? null) && $draft['members'] !== []) {
|
|
||||||
return $draft['members'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$version = $composition->versions
|
|
||||||
->filter(fn ($item): bool => $item->status === ContentVersionStatus::Bereit)
|
|
||||||
->sortByDesc('number')
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if ($version === null) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$members = [];
|
|
||||||
|
|
||||||
foreach ($version->members as $member) {
|
|
||||||
$target = $member->content_element_version_id
|
|
||||||
? 'element:'.$member->content_element_version_id
|
|
||||||
: 'composition:'.$member->nested_composition_version_id;
|
|
||||||
$members[] = ['target' => $target];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $members;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return list<int>
|
|
||||||
*/
|
|
||||||
private function pillarSubjects(int $valueId): array
|
|
||||||
{
|
|
||||||
return IdentityDimensionValue::query()
|
|
||||||
->where('subject_type', (new Composition)->getMorphClass())
|
|
||||||
->where('editorial_dimension_value_id', $valueId)
|
|
||||||
->pluck('subject_id')
|
|
||||||
->map(fn (mixed $id): int => (int) $id)
|
|
||||||
->all();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array{text: string, number: int|null, released_number: int|null} $stand
|
|
||||||
*/
|
|
||||||
private function matchesVisibility(array $stand): bool
|
|
||||||
{
|
|
||||||
return match ($this->visibility) {
|
|
||||||
'bibliothek' => $stand['released_number'] !== null,
|
|
||||||
'verborgen' => $stand['number'] !== null && $stand['released_number'] === null,
|
|
||||||
'entwurf' => $stand['number'] === null,
|
|
||||||
default => true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createProgram(): void
|
|
||||||
{
|
|
||||||
$this->create(CompositionKind::Kurs, $this->programName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createModule(): void
|
|
||||||
{
|
|
||||||
$this->create(CompositionKind::Uebung, $this->moduleName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function create(CompositionKind $kind, string $name): void
|
|
||||||
{
|
|
||||||
$name = trim($name);
|
|
||||||
|
|
||||||
if ($name === '') {
|
|
||||||
$this->feedback = 'Der Name fehlt.';
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$composition = app(EditorialCatalog::class)->create($name, $kind);
|
|
||||||
$this->redirect(EditorialCatalog::editUrl($composition), navigate: false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,693 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\Composition;
|
||||||
|
use App\Domain\Catalog\CompositionKind;
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\EditorialContentKind;
|
||||||
|
use App\Domain\Catalog\EditorialDimension;
|
||||||
|
use App\Domain\Catalog\EditorialDimensionValue;
|
||||||
|
use App\Domain\Catalog\EditorialVocabulary;
|
||||||
|
use App\Domain\Catalog\LicenseArticle;
|
||||||
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
|
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
|
||||||
|
use App\Filament\Resources\Pillars\PillarResource;
|
||||||
|
use App\Filament\Support\EditorialCatalog;
|
||||||
|
use Filament\Actions\Action;
|
||||||
|
use Filament\Actions\ActionGroup;
|
||||||
|
use Filament\Forms\Components\Checkbox;
|
||||||
|
use Filament\Forms\Components\CheckboxList;
|
||||||
|
use Filament\Forms\Components\Placeholder;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Pages\Page;
|
||||||
|
use Filament\Schemas\Components\Utilities\Get;
|
||||||
|
use Filament\Support\Enums\Width;
|
||||||
|
use Filament\Support\Exceptions\Halt;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Concerns\InteractsWithTable;
|
||||||
|
use Filament\Tables\Contracts\HasTable;
|
||||||
|
use Filament\Tables\Filters\SelectFilter;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Contracts\Support\Htmlable;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\HtmlString;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Livewire\Attributes\Url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redaktionelle Stammdaten (FACH-56 bis FACH-58): fachliche Materialarten und die Werte der Einordnung (Altersbereich
|
||||||
|
* und Zielgruppe, Einsatzbereiche, Verwendungszwecke) zentral pflegen. Bestehende Tabellen, keine Kopien.
|
||||||
|
*
|
||||||
|
* - Bezeichnung pflegbar, Kennung fest; Zuordnungen hängen an der Kennung des Datensatzes und bleiben beim Umbenennen.
|
||||||
|
* - Verwendete Werte werden deaktiviert statt gelöscht; Löschen nur ohne jede Zuordnung.
|
||||||
|
* - Materialarten haben zulässige Objektkontexte; vorhandene Zuordnungen bleiben bei einer Änderung erhalten.
|
||||||
|
* - Säulen werden in der vorhandenen Säulenverwaltung gepflegt (verlinkt), nicht hier.
|
||||||
|
*/
|
||||||
|
class RedaktionelleStammdaten extends Page implements HasTable
|
||||||
|
{
|
||||||
|
use InteractsWithTable;
|
||||||
|
|
||||||
|
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'Redaktionelle Stammdaten';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 6;
|
||||||
|
|
||||||
|
protected static ?string $slug = 'stammdaten';
|
||||||
|
|
||||||
|
protected static ?string $title = 'Redaktionelle Stammdaten';
|
||||||
|
|
||||||
|
protected string $view = 'filament.stammdaten';
|
||||||
|
|
||||||
|
/** Bevorzugte Reihenfolge der Einordnungsgruppen; weitere Dimensionen folgen nach Bezeichnung. */
|
||||||
|
private const DIMENSION_ORDER = ['zielgruppe', 'einsatzbereich', 'verwendungszweck'];
|
||||||
|
|
||||||
|
#[Url(as: 'gruppe', except: 'materialart')]
|
||||||
|
public string $gruppe = 'materialart';
|
||||||
|
|
||||||
|
/** @var array<int, array<string, int>>|null */
|
||||||
|
private ?array $verwendungCache = null;
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return self::darfPflegen();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function darfPflegen(): bool
|
||||||
|
{
|
||||||
|
return ContentElementResource::editor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mount(): void
|
||||||
|
{
|
||||||
|
if (! array_key_exists($this->gruppe, $this->gruppen())) {
|
||||||
|
$this->gruppe = 'materialart';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSubheading(): string|Htmlable|null
|
||||||
|
{
|
||||||
|
return 'Auswahlwerte für Redaktion, Filter und Picker. Bezeichnungen sind änderbar, Zuordnungen bleiben erhalten; verwendete Werte werden deaktiviert statt gelöscht.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMaxContentWidth(): Width|string|null
|
||||||
|
{
|
||||||
|
return Width::Full;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string> Schlüssel => Bezeichnung
|
||||||
|
*/
|
||||||
|
public function gruppen(): array
|
||||||
|
{
|
||||||
|
$gruppen = ['materialart' => 'Fachliche Materialarten'];
|
||||||
|
$dimensionen = EditorialDimension::query()->where('slug', '!=', EditorialDimension::PILLAR_SLUG)->get()
|
||||||
|
->sortBy(fn (EditorialDimension $d): string => sprintf('%02d', array_search($d->slug, self::DIMENSION_ORDER, true) === false ? 99 : array_search($d->slug, self::DIMENSION_ORDER, true)).$d->label);
|
||||||
|
|
||||||
|
foreach ($dimensionen as $dimension) {
|
||||||
|
$gruppen[$dimension->slug] = (string) $dimension->label;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $gruppen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function zeigeGruppe(string $gruppe): void
|
||||||
|
{
|
||||||
|
if (array_key_exists($gruppe, $this->gruppen())) {
|
||||||
|
$this->gruppe = $gruppe;
|
||||||
|
$this->verwendungCache = null;
|
||||||
|
$this->resetTable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saeulenUrl(): string
|
||||||
|
{
|
||||||
|
return PillarResource::getUrl('index');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function istMaterialart(): bool
|
||||||
|
{
|
||||||
|
return $this->gruppe === 'materialart';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function dimension(): ?EditorialDimension
|
||||||
|
{
|
||||||
|
return $this->istMaterialart() ? null : EditorialDimension::query()->where('slug', $this->gruppe)->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------
|
||||||
|
// Tabelle
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
public function table(Table $table): Table
|
||||||
|
{
|
||||||
|
$materialart = $this->istMaterialart();
|
||||||
|
|
||||||
|
return $table
|
||||||
|
->query(function (): Builder {
|
||||||
|
if ($this->istMaterialart()) {
|
||||||
|
return EditorialContentKind::query();
|
||||||
|
}
|
||||||
|
|
||||||
|
return EditorialDimensionValue::query()->where('editorial_dimension_id', $this->dimension()?->id ?? 0);
|
||||||
|
})
|
||||||
|
->defaultSort('sort_order')
|
||||||
|
->reorderable('sort_order')
|
||||||
|
->reorderRecordsTriggerAction(fn (Action $action, bool $isReordering): Action => $action
|
||||||
|
->button()
|
||||||
|
->label($isReordering ? 'Sortieren beenden' : 'Per Ziehen sortieren'))
|
||||||
|
->paginated(false)
|
||||||
|
->searchPlaceholder('Bezeichnung oder Kennung')
|
||||||
|
->columns(array_values(array_filter([
|
||||||
|
TextColumn::make('label')
|
||||||
|
->label('Bezeichnung')
|
||||||
|
->searchable(['label', 'slug'])
|
||||||
|
->weight('semibold')
|
||||||
|
->wrap()
|
||||||
|
->description(fn (Model $record): string => 'Kennung: '.$record->slug
|
||||||
|
.($record instanceof EditorialContentKind && $record->isSystem() ? ' · vom System verwendet' : '')),
|
||||||
|
$materialart ? TextColumn::make('contexts')
|
||||||
|
->label('Zulässig für')
|
||||||
|
->state(fn (EditorialContentKind $record): array => array_values(array_map(
|
||||||
|
fn (string $context): string => EditorialContentKind::CONTEXTS[$context] ?? $context,
|
||||||
|
(array) ($record->contexts ?? []),
|
||||||
|
)))
|
||||||
|
->badge()
|
||||||
|
->color('gray')
|
||||||
|
->wrap() : null,
|
||||||
|
TextColumn::make('is_active')
|
||||||
|
->label('Status')
|
||||||
|
->formatStateUsing(fn (bool $state): string => $state ? 'Aktiv' : 'Inaktiv')
|
||||||
|
->badge()
|
||||||
|
->color(fn (bool $state): string => $state ? 'success' : 'gray'),
|
||||||
|
TextColumn::make('verwendung')
|
||||||
|
->label('Verwendung')
|
||||||
|
->state(fn (Model $record): string => $this->verwendungText($record))
|
||||||
|
->wrap()
|
||||||
|
->action($this->verwendungAction()->name('verwendungZeigen')),
|
||||||
|
])))
|
||||||
|
->filters([
|
||||||
|
SelectFilter::make('is_active')
|
||||||
|
->label('Status')
|
||||||
|
->options(['1' => 'Aktiv', '0' => 'Inaktiv']),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
Action::make('hoch')
|
||||||
|
->label('Nach oben')
|
||||||
|
->icon('heroicon-m-arrow-up')
|
||||||
|
->iconButton()
|
||||||
|
->color('gray')
|
||||||
|
->authorize(fn (): bool => self::darfPflegen())
|
||||||
|
->disabled(fn (Model $record): bool => $this->nachbar($record, -1) === null)
|
||||||
|
->action(fn (Model $record) => $this->verschiebe($record, -1)),
|
||||||
|
Action::make('runter')
|
||||||
|
->label('Nach unten')
|
||||||
|
->icon('heroicon-m-arrow-down')
|
||||||
|
->iconButton()
|
||||||
|
->color('gray')
|
||||||
|
->authorize(fn (): bool => self::darfPflegen())
|
||||||
|
->disabled(fn (Model $record): bool => $this->nachbar($record, 1) === null)
|
||||||
|
->action(fn (Model $record) => $this->verschiebe($record, 1)),
|
||||||
|
$this->bearbeitenAction(),
|
||||||
|
ActionGroup::make([
|
||||||
|
$this->verwendungAction(),
|
||||||
|
$this->umschaltenAction(),
|
||||||
|
$this->loeschenAction(),
|
||||||
|
])->label('Weitere')->icon('heroicon-m-chevron-down')->button()->size('sm')->color('gray'),
|
||||||
|
])
|
||||||
|
->emptyStateHeading('Noch keine Werte')
|
||||||
|
->emptyStateDescription('Mit „Wert anlegen“ entsteht der erste Wert dieser Gruppe.');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Action::make('anlegen')
|
||||||
|
->label('Wert anlegen')
|
||||||
|
->icon('heroicon-o-plus')
|
||||||
|
->authorize(fn (): bool => self::darfPflegen())
|
||||||
|
->modalHeading(fn (): string => 'Neuer Wert: '.($this->gruppen()[$this->gruppe] ?? ''))
|
||||||
|
->schema(fn (): array => $this->formular(null))
|
||||||
|
->fillForm(fn (): array => ['contexts' => ['medium']])
|
||||||
|
->modalSubmitActionLabel('Anlegen')
|
||||||
|
->action(function (array $data): void {
|
||||||
|
$this->anlegen($data);
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------
|
||||||
|
// Formular, Anlegen, Bearbeiten
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<mixed>
|
||||||
|
*/
|
||||||
|
private function formular(?Model $record): array
|
||||||
|
{
|
||||||
|
$felder = [
|
||||||
|
TextInput::make('label')
|
||||||
|
->label('Bezeichnung')
|
||||||
|
->required()
|
||||||
|
->maxLength(120)
|
||||||
|
->helperText($record !== null
|
||||||
|
? 'Die Kennung „'.$record->slug.'“ bleibt; vorhandene Zuordnungen behalten den Wert und zeigen die neue Bezeichnung.'
|
||||||
|
: 'Die Kennung entsteht aus der Bezeichnung und bleibt danach fest.'),
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($this->istMaterialart()) {
|
||||||
|
$system = $record instanceof EditorialContentKind && $record->isSystem();
|
||||||
|
$felder[] = CheckboxList::make('contexts')
|
||||||
|
->label('Zulässig für')
|
||||||
|
->options(EditorialContentKind::CONTEXTS)
|
||||||
|
->required()
|
||||||
|
->live()
|
||||||
|
->columns(['default' => 2, 'md' => 4])
|
||||||
|
->disabled($system)
|
||||||
|
->dehydrated(! $system)
|
||||||
|
->helperText($system
|
||||||
|
? 'Diese Materialart verwendet das System; ihre Kontexte bleiben fest.'
|
||||||
|
: 'Nur hier wird die Materialart neu angeboten. Programm und Modul gehören zu den Objektarten Programm und Modul, nicht zu Medien.');
|
||||||
|
|
||||||
|
if ($record instanceof EditorialContentKind) {
|
||||||
|
$felder[] = Placeholder::make('konflikt')
|
||||||
|
->label('Bestehende Zuordnungen')
|
||||||
|
->visible(fn (Get $get): bool => $this->kontextKonflikte($record, (array) $get('contexts')) !== [])
|
||||||
|
->content(fn (Get $get): HtmlString => new HtmlString('<span style="color: #9a5b00">'
|
||||||
|
.e(implode(' ', $this->kontextKonflikte($record, (array) $get('contexts'))))
|
||||||
|
.' Diese Zuordnungen bleiben erhalten und werden dort als „hier nicht vorgesehen“ gekennzeichnet; neu wählbar ist die Materialart dort nicht mehr.</span>'));
|
||||||
|
$felder[] = Checkbox::make('konflikt_bestaetigt')
|
||||||
|
->label('Ich habe die bestehenden Zuordnungen geprüft.')
|
||||||
|
->accepted()
|
||||||
|
->visible(fn (Get $get): bool => $this->kontextKonflikte($record, (array) $get('contexts')) !== []);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $felder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<string> Meldungen je entferntem Kontext mit Verwendung
|
||||||
|
*/
|
||||||
|
private function kontextKonflikte(EditorialContentKind $kind, array $neu): array
|
||||||
|
{
|
||||||
|
$verwendung = $this->verwendung($kind);
|
||||||
|
$meldungen = [];
|
||||||
|
$zeilen = null;
|
||||||
|
|
||||||
|
foreach ((array) ($kind->contexts ?? []) as $context) {
|
||||||
|
if (! in_array($context, $neu, true) && ($verwendung[$context] ?? 0) > 0) {
|
||||||
|
$zeilen ??= $this->verwendungListe($kind)['zeilen'];
|
||||||
|
$titel = array_slice(array_column(array_filter($zeilen, fn (array $z): bool => $z['art'] === (EditorialContentKind::CONTEXTS[$context] ?? '')), 'titel'), 0, 5);
|
||||||
|
$meldungen[] = (EditorialContentKind::CONTEXTS[$context] ?? $context).': '.$verwendung[$context].' '.($verwendung[$context] === 1 ? 'Zuordnung' : 'Zuordnungen')
|
||||||
|
.($titel !== [] ? ' („'.implode('“, „', $titel).'“'.($verwendung[$context] > count($titel) ? ' und weitere' : '').')' : '').'.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $meldungen;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function bearbeitenAction(): Action
|
||||||
|
{
|
||||||
|
return Action::make('bearbeiten')
|
||||||
|
->label('Bearbeiten')
|
||||||
|
->icon('heroicon-o-pencil-square')
|
||||||
|
->button()
|
||||||
|
->size('sm')
|
||||||
|
->color('gray')
|
||||||
|
->authorize(fn (): bool => self::darfPflegen())
|
||||||
|
->modalHeading(fn (Model $record): string => '„'.$record->label.'“ bearbeiten')
|
||||||
|
->schema(fn (Model $record): array => $this->formular($record))
|
||||||
|
->fillForm(fn (Model $record): array => [
|
||||||
|
'label' => $record->label,
|
||||||
|
'contexts' => $record instanceof EditorialContentKind ? (array) ($record->contexts ?? []) : [],
|
||||||
|
])
|
||||||
|
->modalSubmitActionLabel('Speichern')
|
||||||
|
->action(function (Model $record, array $data): void {
|
||||||
|
$label = trim((string) $data['label']);
|
||||||
|
$this->pruefeBezeichnung($label, $record);
|
||||||
|
$record->label = $label;
|
||||||
|
|
||||||
|
if ($record instanceof EditorialContentKind && ! $record->isSystem() && isset($data['contexts'])) {
|
||||||
|
$record->contexts = $this->kontexte((array) $data['contexts']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$record->save();
|
||||||
|
Notification::make()->success()->title('Gespeichert')->body('Die neue Bezeichnung gilt sofort in Redaktion, Filtern und Picker.')->send();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function anlegen(array $data): void
|
||||||
|
{
|
||||||
|
$label = trim((string) $data['label']);
|
||||||
|
$this->pruefeBezeichnung($label, null);
|
||||||
|
|
||||||
|
if ($this->istMaterialart()) {
|
||||||
|
EditorialContentKind::query()->create([
|
||||||
|
'label' => $label,
|
||||||
|
'slug' => $this->freieKennung($label, EditorialContentKind::query()),
|
||||||
|
'sort_order' => (int) EditorialContentKind::query()->max('sort_order') + 10,
|
||||||
|
'is_active' => true,
|
||||||
|
'contexts' => $this->kontexte((array) ($data['contexts'] ?? [])),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$dimension = $this->dimension();
|
||||||
|
abort_if($dimension === null, 404);
|
||||||
|
$werte = EditorialDimensionValue::query()->where('editorial_dimension_id', $dimension->id);
|
||||||
|
EditorialDimensionValue::query()->create([
|
||||||
|
'editorial_dimension_id' => $dimension->id,
|
||||||
|
'label' => $label,
|
||||||
|
'slug' => $this->freieKennung($label, clone $werte),
|
||||||
|
'sort_order' => (int) (clone $werte)->max('sort_order') + 10,
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->verwendungCache = null;
|
||||||
|
Notification::make()->success()->title('Angelegt: „'.$label.'“')->body('Der Wert ist sofort in der passenden Redaktion wählbar.')->send();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function pruefeBezeichnung(string $label, ?Model $ausser): void
|
||||||
|
{
|
||||||
|
$query = $this->istMaterialart()
|
||||||
|
? EditorialContentKind::query()
|
||||||
|
: EditorialDimensionValue::query()->where('editorial_dimension_id', $this->dimension()?->id ?? 0);
|
||||||
|
|
||||||
|
$doppelt = $query->whereRaw('LOWER(label) = ?', [mb_strtolower($label)])
|
||||||
|
->when($ausser !== null, fn (Builder $q) => $q->whereKeyNot($ausser->getKey()))
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($label === '' || $doppelt) {
|
||||||
|
Notification::make()->danger()->title($label === '' ? 'Die Bezeichnung fehlt.' : 'Diese Bezeichnung gibt es in der Gruppe schon.')->send();
|
||||||
|
throw new Halt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function kontexte(array $kontexte): array
|
||||||
|
{
|
||||||
|
$erlaubt = array_keys(EditorialContentKind::CONTEXTS);
|
||||||
|
|
||||||
|
return array_values(array_filter($erlaubt, fn (string $context): bool => in_array($context, $kontexte, true)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function freieKennung(string $label, Builder $query): string
|
||||||
|
{
|
||||||
|
$basis = Str::slug($label) ?: 'wert';
|
||||||
|
$kennung = $basis;
|
||||||
|
$nummer = 2;
|
||||||
|
|
||||||
|
while ((clone $query)->where('slug', $kennung)->exists()) {
|
||||||
|
$kennung = $basis.'-'.$nummer++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $kennung;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------
|
||||||
|
// Aktiv, Löschen, Reihenfolge
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
private function umschaltenAction(): Action
|
||||||
|
{
|
||||||
|
return Action::make('umschalten')
|
||||||
|
->label(fn (Model $record): string => $record->is_active ? 'Deaktivieren' : 'Reaktivieren')
|
||||||
|
->icon(fn (Model $record): string => $record->is_active ? 'heroicon-o-eye-slash' : 'heroicon-o-eye')
|
||||||
|
->authorize(fn (): bool => self::darfPflegen())
|
||||||
|
->hidden(fn (Model $record): bool => $record instanceof EditorialContentKind && $record->isSystem())
|
||||||
|
->requiresConfirmation()
|
||||||
|
->modalHeading(fn (Model $record): string => '„'.$record->label.'“ '.($record->is_active ? 'deaktivieren?' : 'reaktivieren?'))
|
||||||
|
->modalDescription(fn (Model $record): string => $record->is_active
|
||||||
|
? 'Der Wert wird für neue Zuordnungen nicht mehr angeboten. '.$this->verwendungSatz($record).' Filter finden diese Objekte weiterhin.'
|
||||||
|
: 'Der Wert wird wieder für neue Zuordnungen angeboten.')
|
||||||
|
->modalSubmitActionLabel(fn (Model $record): string => $record->is_active ? 'Deaktivieren' : 'Reaktivieren')
|
||||||
|
->action(function (Model $record): void {
|
||||||
|
abort_if($record instanceof EditorialContentKind && $record->isSystem(), 403);
|
||||||
|
$record->is_active = ! $record->is_active;
|
||||||
|
$record->save();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function loeschenAction(): Action
|
||||||
|
{
|
||||||
|
return Action::make('loeschen')
|
||||||
|
->label('Löschen')
|
||||||
|
->icon('heroicon-o-trash')
|
||||||
|
->color('danger')
|
||||||
|
->authorize(fn (): bool => self::darfPflegen())
|
||||||
|
->visible(fn (Model $record): bool => $this->loeschbar($record))
|
||||||
|
->requiresConfirmation()
|
||||||
|
->modalHeading(fn (Model $record): string => '„'.$record->label.'“ löschen?')
|
||||||
|
->modalDescription('Der Wert ist nirgends zugeordnet und wird endgültig entfernt.')
|
||||||
|
->modalSubmitActionLabel('Löschen')
|
||||||
|
->action(function (Model $record): void {
|
||||||
|
// Erneut prüfen: Zwischenzeitlich entstandene Zuordnungen würden die Datenbank sonst still lösen.
|
||||||
|
if (! $this->loeschbar($record)) {
|
||||||
|
Notification::make()->danger()->title('Nicht gelöscht: Der Wert ist inzwischen zugeordnet. Deaktivieren Sie ihn stattdessen.')->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$record->delete();
|
||||||
|
$this->verwendungCache = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function loeschbar(Model $record): bool
|
||||||
|
{
|
||||||
|
if ($record instanceof EditorialContentKind && $record->isSystem()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_sum($this->verwendung($record, frisch: true)) === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function nachbar(Model $record, int $richtung): ?Model
|
||||||
|
{
|
||||||
|
$liste = $this->geordnet();
|
||||||
|
$index = $liste->search(fn (Model $m): bool => $m->is($record));
|
||||||
|
|
||||||
|
return $index === false ? null : $liste->get($index + $richtung);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function verschiebe(Model $record, int $richtung): void
|
||||||
|
{
|
||||||
|
$liste = $this->geordnet()->values();
|
||||||
|
$index = $liste->search(fn (Model $m): bool => $m->is($record));
|
||||||
|
|
||||||
|
if ($index === false || $liste->get($index + $richtung) === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$nachbar = $liste->get($index + $richtung);
|
||||||
|
|
||||||
|
// Nur die beiden Einträge tauschen; neu nummeriert wird nur bei gleicher Reihenfolgezahl.
|
||||||
|
if ((int) $record->sort_order !== (int) $nachbar->sort_order) {
|
||||||
|
DB::transaction(function () use ($record, $nachbar): void {
|
||||||
|
[$a, $b] = [(int) $record->sort_order, (int) $nachbar->sort_order];
|
||||||
|
$record->sort_order = $b;
|
||||||
|
$record->save();
|
||||||
|
$nachbar->sort_order = $a;
|
||||||
|
$nachbar->save();
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$neu = $liste->all();
|
||||||
|
[$neu[$index], $neu[$index + $richtung]] = [$neu[$index + $richtung], $neu[$index]];
|
||||||
|
|
||||||
|
DB::transaction(function () use ($neu): void {
|
||||||
|
foreach (array_values($neu) as $position => $eintrag) {
|
||||||
|
if ((int) $eintrag->sort_order !== ($position + 1) * 10) {
|
||||||
|
$eintrag->sort_order = ($position + 1) * 10;
|
||||||
|
$eintrag->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Model>
|
||||||
|
*/
|
||||||
|
private function geordnet(): Collection
|
||||||
|
{
|
||||||
|
$query = $this->istMaterialart()
|
||||||
|
? EditorialContentKind::query()
|
||||||
|
: EditorialDimensionValue::query()->where('editorial_dimension_id', $this->dimension()?->id ?? 0);
|
||||||
|
|
||||||
|
return $query->orderBy('sort_order')->orderBy('id')->get()->values();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------
|
||||||
|
// Verwendung
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zuordnungen je Objektkontext.
|
||||||
|
*
|
||||||
|
* @return array<string, int>
|
||||||
|
*/
|
||||||
|
public function verwendung(Model $record, bool $frisch = false): array
|
||||||
|
{
|
||||||
|
if ($frisch || $this->verwendungCache === null) {
|
||||||
|
$this->verwendungCache = $this->istMaterialart() ? $this->materialartVerwendung() : $this->einordnungVerwendung();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->verwendungCache[(int) $record->getKey()] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function verwendungText(Model $record): string
|
||||||
|
{
|
||||||
|
$teile = [];
|
||||||
|
|
||||||
|
foreach ($this->verwendung($record) as $context => $anzahl) {
|
||||||
|
if ($anzahl > 0) {
|
||||||
|
$teile[] = $anzahl.' '.$this->einheit($context, $anzahl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $teile === [] ? 'Nicht verwendet' : implode(' · ', $teile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function verwendungSatz(Model $record): string
|
||||||
|
{
|
||||||
|
$text = $this->verwendungText($record);
|
||||||
|
|
||||||
|
return $text === 'Nicht verwendet'
|
||||||
|
? 'Er ist derzeit nirgends zugeordnet.'
|
||||||
|
: 'Bestehende Zuordnungen ('.$text.') bleiben erhalten und sichtbar.';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function einheit(string $context, int $anzahl): string
|
||||||
|
{
|
||||||
|
return match ($context) {
|
||||||
|
'medium' => $anzahl === 1 ? 'Medium' : 'Medien',
|
||||||
|
'modul' => $anzahl === 1 ? 'Modul' : 'Module',
|
||||||
|
'programm' => $anzahl === 1 ? 'Programm' : 'Programme',
|
||||||
|
'lizenzartikel' => 'Lizenzartikel',
|
||||||
|
default => $anzahl === 1 ? 'Kombination' : 'Kombinationen',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, array<string, int>>
|
||||||
|
*/
|
||||||
|
private function materialartVerwendung(): array
|
||||||
|
{
|
||||||
|
$ergebnis = [];
|
||||||
|
|
||||||
|
foreach (DB::table('content_elements')->whereNotNull('editorial_content_kind_id')->groupBy('editorial_content_kind_id')->selectRaw('editorial_content_kind_id as id, count(*) as anzahl')->get() as $zeile) {
|
||||||
|
$ergebnis[(int) $zeile->id]['medium'] = (int) $zeile->anzahl;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (DB::table('compositions')->whereNotNull('editorial_content_kind_id')->groupBy('editorial_content_kind_id', 'kind')->selectRaw('editorial_content_kind_id as id, kind, count(*) as anzahl')->get() as $zeile) {
|
||||||
|
$context = EditorialVocabulary::compositionContext(CompositionKind::tryFrom((string) $zeile->kind)) ?? 'kombination';
|
||||||
|
$ergebnis[(int) $zeile->id][$context] = ($ergebnis[(int) $zeile->id][$context] ?? 0) + (int) $zeile->anzahl;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (DB::table('license_articles')->whereNotNull('editorial_content_kind_id')->groupBy('editorial_content_kind_id')->selectRaw('editorial_content_kind_id as id, count(*) as anzahl')->get() as $zeile) {
|
||||||
|
$ergebnis[(int) $zeile->id]['lizenzartikel'] = (int) $zeile->anzahl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ergebnis;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, array<string, int>>
|
||||||
|
*/
|
||||||
|
private function einordnungVerwendung(): array
|
||||||
|
{
|
||||||
|
$ergebnis = [];
|
||||||
|
$zeilen = DB::table('identity_dimension_values')
|
||||||
|
->leftJoin('compositions', function ($join): void {
|
||||||
|
$join->on('compositions.id', '=', 'identity_dimension_values.subject_id')
|
||||||
|
->where('identity_dimension_values.subject_type', (new Composition)->getMorphClass());
|
||||||
|
})
|
||||||
|
->groupBy('identity_dimension_values.editorial_dimension_value_id', 'identity_dimension_values.subject_type', 'compositions.kind')
|
||||||
|
->selectRaw('identity_dimension_values.editorial_dimension_value_id as id, identity_dimension_values.subject_type as typ, compositions.kind as kind, count(*) as anzahl')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
foreach ($zeilen as $zeile) {
|
||||||
|
$context = match ($zeile->typ) {
|
||||||
|
(new ContentElement)->getMorphClass() => 'medium',
|
||||||
|
(new LicenseArticle)->getMorphClass() => 'lizenzartikel',
|
||||||
|
default => EditorialVocabulary::compositionContext(CompositionKind::tryFrom((string) $zeile->kind)) ?? 'kombination',
|
||||||
|
};
|
||||||
|
$ergebnis[(int) $zeile->id][$context] = ($ergebnis[(int) $zeile->id][$context] ?? 0) + (int) $zeile->anzahl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ergebnis;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function verwendungAction(): Action
|
||||||
|
{
|
||||||
|
return Action::make('verwendung')
|
||||||
|
->label('Verwendung')
|
||||||
|
->icon('heroicon-m-list-bullet')
|
||||||
|
->authorize(fn (): bool => self::darfPflegen())
|
||||||
|
->modalHeading(fn (Model $record): string => 'Verwendung von „'.$record->label.'“')
|
||||||
|
->modalContent(fn (Model $record) => view('filament.stammdaten-verwendung', $this->verwendungListe($record)))
|
||||||
|
->modalSubmitAction(false)
|
||||||
|
->modalCancelActionLabel('Schließen');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zugeordnete Objekte mit Links in ihre Bearbeitung und gefilterte Bestandslisten.
|
||||||
|
*
|
||||||
|
* @return array{zeilen: list<array{art: string, titel: string, url: string}>, mehr: int, filter: list<array{label: string, url: string}>}
|
||||||
|
*/
|
||||||
|
public function verwendungListe(Model $record): array
|
||||||
|
{
|
||||||
|
$grenze = 40;
|
||||||
|
$zeilen = [];
|
||||||
|
$filter = [];
|
||||||
|
|
||||||
|
if ($record instanceof EditorialContentKind) {
|
||||||
|
$medien = ContentElement::query()->where('editorial_content_kind_id', $record->id);
|
||||||
|
$kompositionen = Composition::query()->where('editorial_content_kind_id', $record->id);
|
||||||
|
$artikel = LicenseArticle::query()->where('editorial_content_kind_id', $record->id);
|
||||||
|
if ((clone $medien)->exists()) {
|
||||||
|
$filter[] = ['label' => 'Im Medienmanager filtern', 'url' => ContentElementResource::getUrl('index', ['inhaltsart' => $record->id])];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$zuordnung = fn (string $klasse) => DB::table('identity_dimension_values')
|
||||||
|
->where('editorial_dimension_value_id', $record->getKey())
|
||||||
|
->where('subject_type', (new $klasse)->getMorphClass())
|
||||||
|
->pluck('subject_id');
|
||||||
|
$medien = ContentElement::query()->whereKey($zuordnung(ContentElement::class));
|
||||||
|
$kompositionen = Composition::query()->whereKey($zuordnung(Composition::class));
|
||||||
|
$artikel = LicenseArticle::query()->whereKey($zuordnung(LicenseArticle::class));
|
||||||
|
if ((clone $medien)->exists()) {
|
||||||
|
$filter[] = ['label' => 'Im Medienmanager filtern', 'url' => ContentElementResource::getUrl('index', ['einordnung' => $record->getKey()])];
|
||||||
|
}
|
||||||
|
if ((clone $kompositionen)->exists()) {
|
||||||
|
$filter[] = ['label' => 'Programme und Module filtern', 'url' => EditorialDesk::getUrl(['pillar' => $record->getKey()])];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$gesamt = (clone $medien)->count() + (clone $kompositionen)->count() + (clone $artikel)->count();
|
||||||
|
|
||||||
|
foreach ($medien->orderBy('working_title')->limit($grenze)->get() as $element) {
|
||||||
|
$zeilen[] = ['art' => 'Medium', 'titel' => (string) ($element->display_title ?: $element->working_title), 'url' => ContentElementResource::getUrl('view', ['record' => $element])];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($kompositionen->orderBy('designation')->limit($grenze)->get() as $composition) {
|
||||||
|
$context = EditorialVocabulary::compositionContext($composition->kind instanceof CompositionKind ? $composition->kind : CompositionKind::tryFrom((string) $composition->kind));
|
||||||
|
$zeilen[] = ['art' => EditorialContentKind::CONTEXTS[$context ?? ''] ?? 'Kombination', 'titel' => (string) ($composition->display_title ?: $composition->designation), 'url' => EditorialCatalog::editUrl($composition)];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($artikel->orderBy('code')->limit($grenze)->get() as $article) {
|
||||||
|
$zeilen[] = ['art' => 'Lizenzartikel', 'titel' => trim($article->code.' '.($article->display_title ?: $article->working_title)), 'url' => LicenseArticleResource::getUrl('view', ['record' => $article])];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['zeilen' => $zeilen, 'mehr' => max(0, $gesamt - count($zeilen)), 'filter' => $filter];
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -2,8 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Bundles\Pages;
|
namespace App\Filament\Resources\Bundles\Pages;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\Bundle;
|
||||||
use App\Domain\Catalog\BundleService;
|
use App\Domain\Catalog\BundleService;
|
||||||
|
use App\Domain\Catalog\BundleStatus;
|
||||||
|
use App\Domain\Catalog\StatusValue;
|
||||||
use App\Filament\Resources\Bundles\BundleResource;
|
use App\Filament\Resources\Bundles\BundleResource;
|
||||||
|
use App\Filament\Support\ListsCatalog;
|
||||||
use App\Filament\Support\ReportsDomainRules;
|
use App\Filament\Support\ReportsDomainRules;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
@@ -12,6 +16,7 @@
|
|||||||
|
|
||||||
class ListBundles extends ListRecords
|
class ListBundles extends ListRecords
|
||||||
{
|
{
|
||||||
|
use ListsCatalog;
|
||||||
use ReportsDomainRules;
|
use ReportsDomainRules;
|
||||||
|
|
||||||
protected static string $resource = BundleResource::class;
|
protected static string $resource = BundleResource::class;
|
||||||
@@ -24,13 +29,83 @@ public function getSubheading(): string|Htmlable|null
|
|||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Action::make('create')->label('Paket anlegen')->schema([
|
Action::make('create')->label('Paket anlegen')
|
||||||
TextInput::make('name')->label('Name')->required(),
|
->modalHeading('Neues Paket')
|
||||||
])->action(function (array $data): void {
|
->modalDescription('Der Name genügt. Bestandteile stellst du danach am Paket zusammen.')
|
||||||
$this->report(function () use ($data): void {
|
->modalSubmitActionLabel('Paket anlegen')
|
||||||
app(BundleService::class)->create($data['name']);
|
->schema([
|
||||||
}, 'Das Paket ist angelegt.');
|
TextInput::make('name')->label('Name')->required(),
|
||||||
}),
|
])->action(function (array $data): void {
|
||||||
|
$bundle = null;
|
||||||
|
$this->report(function () use ($data, &$bundle): void {
|
||||||
|
$bundle = app(BundleService::class)->create($data['name']);
|
||||||
|
}, 'Das Paket ist angelegt.');
|
||||||
|
|
||||||
|
if ($bundle instanceof Bundle) {
|
||||||
|
$this->redirect(BundleResource::getUrl('view', ['record' => $bundle]));
|
||||||
|
}
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function catalogRows(): array
|
||||||
|
{
|
||||||
|
$rows = [];
|
||||||
|
|
||||||
|
foreach (Bundle::query()->with(['versions.items'])->orderBy('name')->get() as $bundle) {
|
||||||
|
$versions = $bundle->versions->sortByDesc('number');
|
||||||
|
$published = $versions->first(fn ($version): bool => StatusValue::of($version->status) === BundleStatus::Veroeffentlicht->value);
|
||||||
|
$draft = $versions->first(fn ($version): bool => StatusValue::of($version->status) === BundleStatus::Entwurf->value);
|
||||||
|
$chips = [];
|
||||||
|
$zustand = [];
|
||||||
|
|
||||||
|
if ($published !== null) {
|
||||||
|
$chips[] = ['label' => 'Fassung '.$published->number.' veröffentlicht', 'ton' => 'gut'];
|
||||||
|
$chips[] = ['label' => $published->items->count() === 1 ? '1 Bestandteil' : $published->items->count().' Bestandteile', 'ton' => 'leise'];
|
||||||
|
$zustand[] = 'veroeffentlicht';
|
||||||
|
} else {
|
||||||
|
$chips[] = ['label' => $versions->isEmpty() ? 'Noch keine Fassung' : 'Noch nicht veröffentlicht', 'ton' => 'offen'];
|
||||||
|
$zustand[] = 'ohne';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($draft !== null) {
|
||||||
|
$chips[] = ['label' => 'Fassung '.$draft->number.' in Arbeit', 'ton' => 'offen'];
|
||||||
|
$zustand[] = 'entwurf';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($bundle->archived_at !== null) {
|
||||||
|
$chips[] = ['label' => 'Archiviert', 'ton' => 'leise'];
|
||||||
|
$zustand[] = 'archiviert';
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = BundleResource::getUrl('view', ['record' => $bundle]);
|
||||||
|
$rows[] = [
|
||||||
|
'schluessel' => 'p'.$bundle->id,
|
||||||
|
'titel' => $bundle->name,
|
||||||
|
'meta' => 'Paket',
|
||||||
|
'symbol' => 'modul',
|
||||||
|
'url' => $url,
|
||||||
|
'chips' => $chips,
|
||||||
|
'zustand' => $zustand,
|
||||||
|
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function zustandOptionen(): array
|
||||||
|
{
|
||||||
|
return ['alle' => 'Jeder Zustand', 'veroeffentlicht' => 'Veröffentlicht', 'ohne' => 'Noch nicht veröffentlicht', 'entwurf' => 'Fassung in Arbeit', 'archiviert' => 'Archiviert'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function einheit(): array
|
||||||
|
{
|
||||||
|
return ['Paket', 'Pakete'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function leer(): array
|
||||||
|
{
|
||||||
|
return ['titel' => 'Noch keine Pakete', 'text' => 'Mit „Paket anlegen“ oben entsteht das erste Paket.'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,54 +4,202 @@
|
|||||||
|
|
||||||
use App\Domain\Catalog\Bundle;
|
use App\Domain\Catalog\Bundle;
|
||||||
use App\Domain\Catalog\BundleService;
|
use App\Domain\Catalog\BundleService;
|
||||||
|
use App\Domain\Catalog\BundleStatus;
|
||||||
|
use App\Domain\Catalog\BundleVersion;
|
||||||
use App\Domain\Catalog\LicenseArticle;
|
use App\Domain\Catalog\LicenseArticle;
|
||||||
|
use App\Domain\Catalog\StatusValue;
|
||||||
use App\Filament\Resources\Bundles\BundleResource;
|
use App\Filament\Resources\Bundles\BundleResource;
|
||||||
use App\Filament\Support\CatalogOptions;
|
use App\Filament\Support\CatalogOptions;
|
||||||
|
use App\Filament\Support\CatalogReading;
|
||||||
|
use App\Filament\Support\PublicationReadiness;
|
||||||
use App\Filament\Support\ReportsDomainRules;
|
use App\Filament\Support\ReportsDomainRules;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Forms\Components\CheckboxList;
|
use Filament\Forms\Components\CheckboxList;
|
||||||
use Filament\Resources\Pages\ViewRecord;
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
use Filament\Schemas\Components\View;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Enums\Width;
|
||||||
|
use Illuminate\Contracts\Support\Htmlable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paket in der gemeinsamen Katalog-Objektseite. Erste und geänderte Fassung nutzen dieselbe Maske; eine Änderung
|
||||||
|
* ist mit der neuesten veröffentlichten Fassung vorbelegt. Wirkung unverändert BundleService::publish.
|
||||||
|
*/
|
||||||
class ViewBundle extends ViewRecord
|
class ViewBundle extends ViewRecord
|
||||||
{
|
{
|
||||||
use ReportsDomainRules;
|
use ReportsDomainRules;
|
||||||
|
|
||||||
protected static string $resource = BundleResource::class;
|
protected static string $resource = BundleResource::class;
|
||||||
|
|
||||||
|
public function getTitle(): string|Htmlable
|
||||||
|
{
|
||||||
|
return (string) $this->getRecord()->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHeading(): string|Htmlable
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function getBreadcrumbs(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMaxContentWidth(): Width|string|null
|
||||||
|
{
|
||||||
|
return Width::Full;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function infolist(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema->components([
|
||||||
|
View::make('filament.catalog.objekt')->viewData(fn (): array => $this->paketDaten())->columnSpanFull(),
|
||||||
|
])->columns(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function publishedVersion(): ?BundleVersion
|
||||||
|
{
|
||||||
|
/** @var Bundle $bundle */
|
||||||
|
$bundle = $this->getRecord();
|
||||||
|
|
||||||
|
return $bundle->versions()
|
||||||
|
->where('status', BundleStatus::Veroeffentlicht)
|
||||||
|
->orderByDesc('number')
|
||||||
|
->with(['items.article', 'items.nestedBundle'])
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function publishAction(): Action
|
||||||
|
{
|
||||||
|
return Action::make('publish')
|
||||||
|
->label(fn (): string => $this->publishedVersion() !== null ? 'Geänderte Fassung veröffentlichen' : 'Fassung veröffentlichen')
|
||||||
|
->modalHeading(fn (): string => $this->publishedVersion() !== null
|
||||||
|
? 'Paket ändern: Fassung '.$this->nextNumber().' veröffentlichen'
|
||||||
|
: 'Erste Fassung veröffentlichen')
|
||||||
|
->modalDescription(fn (): string => ($published = $this->publishedVersion()) !== null
|
||||||
|
? 'Die Maske ist mit Fassung '.$published->number.' vorbelegt. Fassung '.$published->number.' bleibt veröffentlicht und unverändert; Angebote verweisen weiter auf die Paketfassung, die sie nennen.'
|
||||||
|
: 'Die gewählten Lizenzartikel und Pakete bilden die erste Fassung. Sie ist danach unveränderlich.')
|
||||||
|
->modalSubmitActionLabel(fn (): string => 'Fassung '.$this->nextNumber().' veröffentlichen')
|
||||||
|
->fillForm(fn (): array => $this->formFromPublished())
|
||||||
|
->schema([
|
||||||
|
CheckboxList::make('articles')->label('Lizenzartikel')->options(fn (): array => app(PublicationReadiness::class)->articleOptions())
|
||||||
|
->helperText('Artikel ohne Stand lassen sich aufnehmen, aber erst verkaufen, wenn sie einen Inhalt haben.'),
|
||||||
|
CheckboxList::make('bundles')->label('Enthaltene Pakete')
|
||||||
|
->options(function (): array {
|
||||||
|
$options = CatalogOptions::bundles();
|
||||||
|
unset($options[$this->getRecord()->getKey()]);
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
->action(function (array $data): void {
|
||||||
|
$this->report(function () use ($data): string {
|
||||||
|
/** @var Bundle $bundle */
|
||||||
|
$bundle = $this->getRecord();
|
||||||
|
$items = [];
|
||||||
|
|
||||||
|
foreach ($data['articles'] ?? [] as $id) {
|
||||||
|
$items[] = LicenseArticle::query()->findOrFail($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($data['bundles'] ?? [] as $id) {
|
||||||
|
$items[] = Bundle::query()->findOrFail($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = app(BundleService::class)->publish($bundle, $items);
|
||||||
|
|
||||||
|
$bundle->unsetRelations();
|
||||||
|
$readiness = app(PublicationReadiness::class)->forBundle($bundle->refresh());
|
||||||
|
|
||||||
|
return 'Fassung '.$version->number.' ist veröffentlicht.'.($readiness['naechster'] !== null
|
||||||
|
? ' Nächster Schritt: '.$readiness['naechster']['titel'].'.'
|
||||||
|
: '');
|
||||||
|
}, 'Die Paketfassung ist veröffentlicht.');
|
||||||
|
$this->getRecord()->unsetRelations();
|
||||||
|
$this->getRecord()->refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{articles: list<int>, bundles: list<int>}
|
||||||
|
*/
|
||||||
|
private function formFromPublished(): array
|
||||||
|
{
|
||||||
|
$published = $this->publishedVersion();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Action::make('publish')
|
'articles' => $published?->items->pluck('license_article_id')->filter()->values()->all() ?? [],
|
||||||
->label('Fassung veröffentlichen')
|
'bundles' => $published?->items->pluck('nested_bundle_id')->filter()->values()->all() ?? [],
|
||||||
->schema([
|
];
|
||||||
CheckboxList::make('articles')->label('Lizenzartikel')->options(fn (): array => CatalogOptions::articles()),
|
}
|
||||||
CheckboxList::make('bundles')->label('Enthaltene Pakete')
|
|
||||||
->options(function (): array {
|
|
||||||
$options = CatalogOptions::bundles();
|
|
||||||
unset($options[$this->getRecord()->getKey()]);
|
|
||||||
|
|
||||||
return $options;
|
private function nextNumber(): int
|
||||||
}),
|
{
|
||||||
])
|
return ((int) $this->getRecord()->versions()->max('number')) + 1;
|
||||||
->action(function (array $data): void {
|
}
|
||||||
$this->report(function () use ($data): void {
|
|
||||||
/** @var Bundle $bundle */
|
|
||||||
$bundle = $this->getRecord();
|
|
||||||
$items = [];
|
|
||||||
|
|
||||||
foreach ($data['articles'] ?? [] as $id) {
|
/**
|
||||||
$items[] = LicenseArticle::query()->findOrFail($id);
|
* @return array<string, mixed>
|
||||||
}
|
*/
|
||||||
|
private function paketDaten(): array
|
||||||
|
{
|
||||||
|
/** @var Bundle $bundle */
|
||||||
|
$bundle = $this->getRecord();
|
||||||
|
$published = $this->publishedVersion();
|
||||||
|
$articles = $published !== null ? app(CatalogReading::class)->bundleArticles($bundle) : [];
|
||||||
|
|
||||||
foreach ($data['bundles'] ?? [] as $id) {
|
return [
|
||||||
$items[] = Bundle::query()->findOrFail($id);
|
'kopf' => [
|
||||||
}
|
'brot' => [['label' => 'Pakete', 'href' => BundleResource::getUrl('index')], $bundle->name],
|
||||||
|
'titel' => $bundle->name,
|
||||||
app(BundleService::class)->publish($bundle, $items);
|
'typ' => 'Paket',
|
||||||
}, 'Die Paketfassung ist veröffentlicht.');
|
'status' => $published !== null
|
||||||
$this->getRecord()->unsetRelations();
|
? ['text' => 'Fassung '.$published->number.' veröffentlicht', 'ton' => 'gut']
|
||||||
$this->getRecord()->refresh();
|
: ['text' => 'Noch keine veröffentlichte Fassung. Bestandteile werden mit der Fassung festgeschrieben.', 'ton' => 'offen'],
|
||||||
}),
|
'aktionen' => [[
|
||||||
|
'label' => $published !== null ? 'Geänderte Fassung veröffentlichen' : 'Fassung veröffentlichen',
|
||||||
|
'wire' => "mountAction('publish')",
|
||||||
|
'art' => 'primary',
|
||||||
|
]],
|
||||||
|
],
|
||||||
|
'voraussetzungen' => app(PublicationReadiness::class)->forBundle($bundle),
|
||||||
|
'haupt' => [
|
||||||
|
[
|
||||||
|
'titel' => 'Bestandteile',
|
||||||
|
'zusatz' => $published !== null ? 'Fassung '.$published->number : null,
|
||||||
|
'hilfe' => 'Was diese Fassung direkt enthält.',
|
||||||
|
'zeilen' => $published === null ? [] : $published->items->sortBy('position')->map(fn ($item): array => [
|
||||||
|
'text' => $item->article !== null ? 'Lizenzartikel '.$item->article->code : 'Paket '.($item->nestedBundle?->name ?? 'fehlt'),
|
||||||
|
])->values()->all(),
|
||||||
|
'leer' => ['titel' => 'Noch keine Bestandteile', 'text' => 'Mit „Fassung veröffentlichen“ wählst du Lizenzartikel und andere Pakete.'],
|
||||||
|
],
|
||||||
|
...($published !== null ? [[
|
||||||
|
'titel' => 'Aufgelöste Lizenzartikel',
|
||||||
|
'hilfe' => 'Darauf werden beim Erwerb die Berechtigungen vergeben.',
|
||||||
|
'zeilen' => array_map(fn (string $code): array => ['text' => $code], $articles),
|
||||||
|
]] : []),
|
||||||
|
],
|
||||||
|
'seite' => [[
|
||||||
|
'titel' => 'Fassungen',
|
||||||
|
'zeilen' => $bundle->versions()->withCount('items')->orderByDesc('number')->get()->map(fn (BundleVersion $version): array => [
|
||||||
|
'text' => 'Fassung '.$version->number,
|
||||||
|
'zustand' => StatusValue::of($version->status) === BundleStatus::Veroeffentlicht->value
|
||||||
|
? ['label' => 'Veröffentlicht', 'ton' => 'gut']
|
||||||
|
: ['label' => 'Entwurf', 'ton' => 'offen'],
|
||||||
|
'neben' => $version->items_count === 1 ? '1 Bestandteil' : $version->items_count.' Bestandteile',
|
||||||
|
])->all(),
|
||||||
|
'leer' => 'Noch keine Fassung.',
|
||||||
|
'hilfe' => 'Veröffentlichte Fassungen bleiben unverändert; ein Angebot nennt die Paketfassung, auf die es sich bezieht.',
|
||||||
|
]],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -4,38 +4,66 @@
|
|||||||
|
|
||||||
use App\Domain\Catalog\CompositionKind;
|
use App\Domain\Catalog\CompositionKind;
|
||||||
use App\Domain\Catalog\ContentService;
|
use App\Domain\Catalog\ContentService;
|
||||||
use App\Domain\Catalog\EditorialContentKind;
|
|
||||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
|
use App\Filament\Support\ListsCompositions;
|
||||||
use App\Filament\Support\ReportsDomainRules;
|
use App\Filament\Support\ReportsDomainRules;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Resources\Pages\ListRecords;
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
use Filament\Schemas\Components\View;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Enums\Width;
|
||||||
use Illuminate\Contracts\Support\Htmlable;
|
use Illuminate\Contracts\Support\Htmlable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listen „Module“, „Programme“ und „Fachliche Kombinationen“: dieselbe Bestandsliste wie der Arbeitsplatz, mit festem
|
||||||
|
* Typ. Module und Programme teilen den Anlegedialog des Arbeitsplatzes; Kombinationen behalten ihren.
|
||||||
|
*/
|
||||||
abstract class ListCompositionKind extends ListRecords
|
abstract class ListCompositionKind extends ListRecords
|
||||||
{
|
{
|
||||||
|
use ListsCompositions;
|
||||||
use ReportsDomainRules;
|
use ReportsDomainRules;
|
||||||
|
|
||||||
abstract protected function kind(): CompositionKind;
|
abstract protected function kind(): CompositionKind;
|
||||||
|
|
||||||
|
protected function fixedKind(): ?CompositionKind
|
||||||
|
{
|
||||||
|
return $this->kind();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onDesk(): bool
|
||||||
|
{
|
||||||
|
return in_array($this->kind(), [CompositionKind::Kurs, CompositionKind::Uebung], true);
|
||||||
|
}
|
||||||
|
|
||||||
public function getSubheading(): string|Htmlable|null
|
public function getSubheading(): string|Htmlable|null
|
||||||
{
|
{
|
||||||
$desk = in_array($this->kind(), [CompositionKind::Kurs, CompositionKind::Uebung], true)
|
$desk = $this->onDesk() ? ' Programme und Module stehen gemeinsam auch auf dem Arbeitsplatz.' : '';
|
||||||
? ' Programme und Module liegen gemeinsam auf dem Arbeitsplatz.'
|
|
||||||
: '';
|
|
||||||
|
|
||||||
return $this->kind()->deskExplanation().$desk;
|
return $this->kind()->deskExplanation().$desk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMaxContentWidth(): Width|string|null
|
||||||
|
{
|
||||||
|
return Width::Full;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function content(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema->components([View::make('filament.verwaltung.bestand')]);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
|
if ($this->onDesk()) {
|
||||||
|
return [$this->createCompositionAction($this->kind())];
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Action::make('create')
|
Action::make('create')
|
||||||
->label(match ($this->kind()) {
|
->label($this->kind()->createLabel())
|
||||||
CompositionKind::Kurs => 'Programm anlegen',
|
->modalHeading('Neue '.lcfirst($this->kind()->label()))
|
||||||
CompositionKind::Uebung => 'Modul anlegen',
|
->modalSubmitActionLabel($this->kind()->createLabel())
|
||||||
default => $this->kind()->createLabel(),
|
|
||||||
})
|
|
||||||
->visible(fn (): bool => ContentElementResource::editor())
|
->visible(fn (): bool => ContentElementResource::editor())
|
||||||
->schema([
|
->schema([
|
||||||
TextInput::make('designation')->label('Bezeichnung')->required(),
|
TextInput::make('designation')->label('Bezeichnung')->required(),
|
||||||
@@ -44,16 +72,6 @@ protected function getHeaderActions(): array
|
|||||||
$composition = null;
|
$composition = null;
|
||||||
$this->report(function () use ($data, &$composition): void {
|
$this->report(function () use ($data, &$composition): void {
|
||||||
$composition = app(ContentService::class)->createComposition($data['designation'], $this->kind());
|
$composition = app(ContentService::class)->createComposition($data['designation'], $this->kind());
|
||||||
$slug = match ($this->kind()) {
|
|
||||||
CompositionKind::Kurs => 'programm',
|
|
||||||
CompositionKind::Uebung => 'modul',
|
|
||||||
default => null,
|
|
||||||
};
|
|
||||||
$editorial = $slug === null ? null : EditorialContentKind::query()->where('slug', $slug)->first();
|
|
||||||
if ($editorial !== null) {
|
|
||||||
$composition->editorial_content_kind_id = $editorial->id;
|
|
||||||
$composition->save();
|
|
||||||
}
|
|
||||||
}, $this->kind()->label().' ist angelegt.');
|
}, $this->kind()->label().' ist angelegt.');
|
||||||
|
|
||||||
if ($composition !== null) {
|
if ($composition !== null) {
|
||||||
|
|||||||
@@ -7,9 +7,7 @@
|
|||||||
use App\Domain\Catalog\ContentElementVersion;
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
use App\Domain\Catalog\ContentService;
|
use App\Domain\Catalog\ContentService;
|
||||||
use App\Domain\Catalog\DomainRuleException;
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
use App\Domain\Catalog\EditorialContentKind;
|
use App\Domain\Catalog\EditorialVocabulary;
|
||||||
use App\Domain\Catalog\EditorialDimension;
|
|
||||||
use App\Domain\Catalog\EditorialDimensionValue;
|
|
||||||
use App\Domain\Catalog\IdentityDimension;
|
use App\Domain\Catalog\IdentityDimension;
|
||||||
use App\Domain\Catalog\IdentityDimensionValue;
|
use App\Domain\Catalog\IdentityDimensionValue;
|
||||||
use App\Domain\Catalog\IdentityProfile;
|
use App\Domain\Catalog\IdentityProfile;
|
||||||
@@ -37,12 +35,23 @@
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\HtmlString;
|
use Illuminate\Support\HtmlString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Früheres Gesamtformular. Texte und Einordnung bearbeitet die gemeinsame Redaktion, Datei und Fassungen der
|
||||||
|
* Medieneditor; ein zweiter Editor für dieselben Felder ist nach Dokument 14 nicht zulässig. Die Adresse bleibt
|
||||||
|
* für alte Lesezeichen erhalten und führt nach der Rechteprüfung in die Redaktion des Mediums.
|
||||||
|
*/
|
||||||
class EditContentElement extends EditRecord
|
class EditContentElement extends EditRecord
|
||||||
{
|
{
|
||||||
use ReportsDomainRules;
|
use ReportsDomainRules;
|
||||||
|
|
||||||
protected static string $resource = ContentElementResource::class;
|
protected static string $resource = ContentElementResource::class;
|
||||||
|
|
||||||
|
public function mount(int|string $record): void
|
||||||
|
{
|
||||||
|
parent::mount($record);
|
||||||
|
$this->redirect(ContentElementResource::getUrl('view', ['record' => $this->getRecord(), 'redaktion' => 1]));
|
||||||
|
}
|
||||||
|
|
||||||
public function getSubheading(): string|Htmlable|null
|
public function getSubheading(): string|Htmlable|null
|
||||||
{
|
{
|
||||||
return 'Titel, Beschreibung, Hinweise und Vorschaubild gehören zum Medium. Ein Text bleibt dieselbe Fassung, solange er nicht freigegeben und verwendet wird.';
|
return 'Titel, Beschreibung, Hinweise und Vorschaubild gehören zum Medium. Ein Text bleibt dieselbe Fassung, solange er nicht freigegeben und verwendet wird.';
|
||||||
@@ -64,8 +73,8 @@ public function form(Schema $schema): Schema
|
|||||||
->helperText('Erscheint in der Bibliothek. Leer lässt den Arbeitstitel stehen. Speichern legt keine Fassung an.'),
|
->helperText('Erscheint in der Bibliothek. Leer lässt den Arbeitstitel stehen. Speichern legt keine Fassung an.'),
|
||||||
Textarea::make('summary')->label('Kurzbeschreibung')->rows(3),
|
Textarea::make('summary')->label('Kurzbeschreibung')->rows(3),
|
||||||
Select::make('editorial_content_kind_id')
|
Select::make('editorial_content_kind_id')
|
||||||
->label('Inhaltsart')
|
->label('Fachliche Materialart')
|
||||||
->options(fn (): array => EditorialContentKind::selectOptions())
|
->options(fn (): array => app(EditorialVocabulary::class)->kindOptions('medium', $this->getRecord()->editorial_content_kind_id !== null ? (int) $this->getRecord()->editorial_content_kind_id : null))
|
||||||
->nullable()
|
->nullable()
|
||||||
->helperText('Optional für Bibliothek und Website. Ändert weder die Ausgabeart noch eine Fassung.'),
|
->helperText('Optional für Bibliothek und Website. Ändert weder die Ausgabeart noch eine Fassung.'),
|
||||||
Placeholder::make('usage')->label('Verwendung')->content(function (): HtmlString {
|
Placeholder::make('usage')->label('Verwendung')->content(function (): HtmlString {
|
||||||
@@ -93,9 +102,12 @@ public function form(Schema $schema): Schema
|
|||||||
CheckboxList::make('dimension_ids')->label('Fachliche Einordnung')
|
CheckboxList::make('dimension_ids')->label('Fachliche Einordnung')
|
||||||
->options(function (): array {
|
->options(function (): array {
|
||||||
$options = [];
|
$options = [];
|
||||||
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
|
foreach (app(EditorialVocabulary::class)->dimensionGroups($this->getRecord(), IdentityDimensionValue::query()
|
||||||
foreach ($dimension->values as $value) {
|
->where('subject_type', $this->getRecord()->getMorphClass())
|
||||||
$options[$value->id] = $dimension->label.': '.$value->label;
|
->where('subject_id', $this->getRecord()->getKey())
|
||||||
|
->pluck('editorial_dimension_value_id')->map(fn ($id): int => (int) $id)->all()) as $dimension) {
|
||||||
|
foreach ($dimension['values'] as $value) {
|
||||||
|
$options[$value['id']] = $dimension['label'].': '.$value['label'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,16 +245,7 @@ protected function handleRecordUpdate(Model $record, array $data): Model
|
|||||||
DeriveThumbnail::dispatch('element', $record->id, $data['thumbnail_upload']);
|
DeriveThumbnail::dispatch('element', $record->id, $data['thumbnail_upload']);
|
||||||
}
|
}
|
||||||
if (array_key_exists('dimension_ids', $data)) {
|
if (array_key_exists('dimension_ids', $data)) {
|
||||||
$ids = array_map(intval(...), $data['dimension_ids'] ?? []);
|
app(IdentityDimension::class)->replaceOffered($record, array_map(intval(...), $data['dimension_ids'] ?? []));
|
||||||
IdentityDimensionValue::query()
|
|
||||||
->where('subject_type', $record->getMorphClass())
|
|
||||||
->where('subject_id', $record->id)
|
|
||||||
->where('origin', 'direkt')
|
|
||||||
->whereNotIn('editorial_dimension_value_id', $ids === [] ? [0] : $ids)
|
|
||||||
->delete();
|
|
||||||
foreach (EditorialDimensionValue::query()->whereIn('id', $ids)->get() as $value) {
|
|
||||||
app(IdentityDimension::class)->assign($record, $value, 'direkt');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
app(PillarService::class)->assign($record, array_map(intval(...), $data['pillars'] ?? []));
|
app(PillarService::class)->assign($record, array_map(intval(...), $data['pillars'] ?? []));
|
||||||
} catch (DomainRuleException $exception) {
|
} catch (DomainRuleException $exception) {
|
||||||
|
|||||||
@@ -2,22 +2,285 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\ContentElements\Pages;
|
namespace App\Filament\Resources\ContentElements\Pages;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\EditorialVocabulary;
|
||||||
|
use App\Domain\Catalog\PillarFilterCompat;
|
||||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
|
use App\Filament\Support\Bestand;
|
||||||
|
use App\Filament\Support\MediaLibrary;
|
||||||
use App\Filament\Support\MediumForm;
|
use App\Filament\Support\MediumForm;
|
||||||
use App\Filament\Support\ReportsDomainRules;
|
use App\Filament\Support\ReportsDomainRules;
|
||||||
|
use App\Filament\Support\ShowsBestand;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Resources\Pages\ListRecords;
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
use Filament\Schemas\Components\RenderHook;
|
||||||
|
use Filament\Schemas\Components\View;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Enums\Width;
|
||||||
|
use Filament\View\PanelsRenderHook;
|
||||||
use Illuminate\Contracts\Support\Htmlable;
|
use Illuminate\Contracts\Support\Htmlable;
|
||||||
|
use Livewire\Attributes\Url;
|
||||||
|
|
||||||
class ListContentElements extends ListRecords
|
class ListContentElements extends ListRecords
|
||||||
{
|
{
|
||||||
use ReportsDomainRules;
|
use ReportsDomainRules;
|
||||||
|
use ShowsBestand;
|
||||||
|
|
||||||
protected static string $resource = ContentElementResource::class;
|
protected static string $resource = ContentElementResource::class;
|
||||||
|
|
||||||
|
#[Url(as: 'suche', except: '')]
|
||||||
|
public string $suche = '';
|
||||||
|
|
||||||
|
/** Dokument 14 §3: kompakte Liste als Grundansicht; Kacheln bleiben wählbar. */
|
||||||
|
#[Url(as: 'ansicht', except: 'liste')]
|
||||||
|
public string $ansicht = 'liste';
|
||||||
|
|
||||||
|
#[Url(as: 'art', except: '')]
|
||||||
|
public string $art = '';
|
||||||
|
|
||||||
|
#[Url(as: 'freigabe', except: '')]
|
||||||
|
public string $freigabe = '';
|
||||||
|
|
||||||
|
#[Url(as: 'entwurf', except: '')]
|
||||||
|
public string $entwurf = '';
|
||||||
|
|
||||||
|
#[Url(as: 'fassung', except: '')]
|
||||||
|
public string $fassung = '';
|
||||||
|
|
||||||
|
#[Url(as: 'nutzung', except: '')]
|
||||||
|
public string $nutzung = '';
|
||||||
|
|
||||||
|
#[Url(as: 'saeule', except: '')]
|
||||||
|
public string $saeule = '';
|
||||||
|
|
||||||
|
#[Url(as: 'inhaltsart', except: '')]
|
||||||
|
public string $inhaltsart = '';
|
||||||
|
|
||||||
|
#[Url(as: 'einordnung', except: '')]
|
||||||
|
public string $einordnung = '';
|
||||||
|
|
||||||
|
#[Url(as: 'verarbeitung', except: '')]
|
||||||
|
public string $verarbeitung = '';
|
||||||
|
|
||||||
|
#[Url(as: 'archiv', except: 'aktiv')]
|
||||||
|
public string $archiv = 'aktiv';
|
||||||
|
|
||||||
public function getSubheading(): string|Htmlable|null
|
public function getSubheading(): string|Htmlable|null
|
||||||
{
|
{
|
||||||
return 'Die Dateien und Texte. Eine Übung, ein Kurs oder eine fachliche Kombination verweist darauf; die Datei wird nicht für jede Verwendung neu hochgeladen.';
|
return 'Die Dateien und Texte. Ein Modul oder ein Programm verweist auf eine Fassung; die Datei wird nicht für jede Verwendung neu hochgeladen.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMaxContentWidth(): Width|string|null
|
||||||
|
{
|
||||||
|
return Width::Full;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function content(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema->components([
|
||||||
|
RenderHook::make(PanelsRenderHook::RESOURCE_PAGES_LIST_RECORDS_TABLE_BEFORE),
|
||||||
|
View::make('filament.verwaltung.bestand'),
|
||||||
|
RenderHook::make(PanelsRenderHook::RESOURCE_PAGES_LIST_RECORDS_TABLE_AFTER),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function bestandFilterEigenschaften(): array
|
||||||
|
{
|
||||||
|
return ['suche', 'art', 'freigabe', 'entwurf', 'fassung', 'nutzung', 'saeule', 'inhaltsart', 'einordnung', 'verarbeitung', 'archiv'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showingList(): bool
|
||||||
|
{
|
||||||
|
return $this->ansicht === 'liste';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array<string, mixed>>
|
||||||
|
*/
|
||||||
|
public function cards(): array
|
||||||
|
{
|
||||||
|
return app(MediaLibrary::class)->cards($this->libraryFilters(), ContentElementResource::editor());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{value: string, label: string}>
|
||||||
|
*/
|
||||||
|
public function typeOptions(): array
|
||||||
|
{
|
||||||
|
return app(MediaLibrary::class)->types();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{id: int, name: string}>
|
||||||
|
*/
|
||||||
|
public function pillarOptions(): array
|
||||||
|
{
|
||||||
|
return app(MediaLibrary::class)->pillars();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{id: int, label: string}>
|
||||||
|
*/
|
||||||
|
public function classificationOptions(): array
|
||||||
|
{
|
||||||
|
return app(MediaLibrary::class)->classifications(ctype_digit($this->einordnung) ? [(int) $this->einordnung] : []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, string>
|
||||||
|
*/
|
||||||
|
public function contentKindOptions(): array
|
||||||
|
{
|
||||||
|
return app(EditorialVocabulary::class)->kindFilterOptions('medium', $this->inhaltsart);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function filtersActive(): bool
|
||||||
|
{
|
||||||
|
return trim($this->suche) !== ''
|
||||||
|
|| $this->art !== ''
|
||||||
|
|| $this->freigabe !== ''
|
||||||
|
|| $this->entwurf !== ''
|
||||||
|
|| $this->fassung !== ''
|
||||||
|
|| $this->nutzung !== ''
|
||||||
|
|| $this->saeule !== ''
|
||||||
|
|| $this->einordnung !== ''
|
||||||
|
|| $this->inhaltsart !== ''
|
||||||
|
|| $this->verarbeitung !== ''
|
||||||
|
|| $this->archiv !== 'aktiv';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resetFilters(): void
|
||||||
|
{
|
||||||
|
$this->suche = '';
|
||||||
|
$this->art = '';
|
||||||
|
$this->freigabe = '';
|
||||||
|
$this->entwurf = '';
|
||||||
|
$this->fassung = '';
|
||||||
|
$this->nutzung = '';
|
||||||
|
$this->saeule = '';
|
||||||
|
$this->einordnung = '';
|
||||||
|
$this->inhaltsart = '';
|
||||||
|
$this->verarbeitung = '';
|
||||||
|
$this->archiv = 'aktiv';
|
||||||
|
$this->bestandGrenze = Bestand::SCHRITT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gemeinsame Bestandsliste: Suche und häufige Filter sichtbar, die übrigen unter „Weitere Filter“.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function bestand(): array
|
||||||
|
{
|
||||||
|
// Alte Adressen mit einem Säulenwert der Einordnung gelten für die zentrale Säule.
|
||||||
|
if (ctype_digit($this->einordnung) && $this->saeule === '' && is_int($pillar = PillarFilterCompat::pillarOfLegacyValue((int) $this->einordnung))) {
|
||||||
|
[$this->saeule, $this->einordnung] = [(string) $pillar, ''];
|
||||||
|
}
|
||||||
|
|
||||||
|
$optionen = fn (array $liste, string $wert, string $label): array => collect($liste)
|
||||||
|
->mapWithKeys(fn (array $eintrag): array => [(string) $eintrag[$wert] => $eintrag[$label]])
|
||||||
|
->all();
|
||||||
|
$weitere = [
|
||||||
|
['eigenschaft' => 'inhaltsart', 'label' => 'Fachliche Materialart', 'vorgabe' => '', 'alle' => 'Alle Materialarten', 'optionen' => $this->contentKindOptions()],
|
||||||
|
['eigenschaft' => 'entwurf', 'label' => 'Entwurf', 'vorgabe' => '', 'alle' => 'Entwurf egal', 'optionen' => ['offen' => 'Offener Entwurf', 'keiner' => 'Kein offener Entwurf']],
|
||||||
|
['eigenschaft' => 'fassung', 'label' => 'Deaktivierte Fassungen', 'vorgabe' => '', 'alle' => 'Regulärer Bestand', 'optionen' => ['mit' => 'Mit deaktivierter Fassung', 'nur' => 'Nur deaktivierte Fassungen']],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (($pillars = $this->pillarOptions()) !== []) {
|
||||||
|
$weitere[] = ['eigenschaft' => 'saeule', 'label' => 'Fachliche Säule', 'vorgabe' => '', 'alle' => 'Alle Säulen', 'optionen' => $optionen($pillars, 'id', 'name')];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($classes = $this->classificationOptions()) !== []) {
|
||||||
|
$weitere[] = ['eigenschaft' => 'einordnung', 'label' => 'Einordnung', 'vorgabe' => '', 'alle' => 'Alle Einordnungen', 'optionen' => $optionen($classes, 'id', 'label')];
|
||||||
|
}
|
||||||
|
|
||||||
|
$weitere[] = ['eigenschaft' => 'verarbeitung', 'label' => 'Verarbeitung', 'vorgabe' => '', 'alle' => 'Verarbeitung egal', 'optionen' => ['fehler' => 'Verarbeitungsfehler', 'uebernahme' => 'Datei wird übernommen']];
|
||||||
|
$weitere[] = ['eigenschaft' => 'archiv', 'label' => 'Archiv', 'vorgabe' => 'aktiv', 'optionen' => ['aktiv' => 'Aktive Medien', 'archiviert' => 'Archivierte Medien', 'alle' => 'Auch archivierte']];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'suche' => ['eigenschaft' => 'suche', 'label' => 'Suche', 'platzhalter' => 'Titel, Beschreibung oder Suchbegriff'],
|
||||||
|
'filter' => [
|
||||||
|
['eigenschaft' => 'art', 'label' => 'Technische Art', 'vorgabe' => '', 'alle' => 'Alle Arten', 'optionen' => $optionen($this->typeOptions(), 'value', 'label')],
|
||||||
|
['eigenschaft' => 'freigabe', 'label' => 'Freigabe', 'vorgabe' => '', 'alle' => 'Alle Freigaben', 'optionen' => ['freigegeben' => 'Freigegebene Fassung', 'entwurf' => 'Nur offener Entwurf', 'ohne' => 'Keine freigegebene Fassung']],
|
||||||
|
['eigenschaft' => 'nutzung', 'label' => 'Verwendung', 'vorgabe' => '', 'alle' => 'Verwendung egal', 'optionen' => ['verwendet' => 'Verwendet', 'unbenutzt' => 'Nicht verwendet']],
|
||||||
|
],
|
||||||
|
'weitere' => $weitere,
|
||||||
|
'hinweis' => 'Freigabe meint die Fassung des Mediums, nicht die Website und keinen Zugriff. Materialart und Einordnung sind die redaktionelle Klassifikation; Verwendung zeigt, wo das Medium tatsächlich eingebunden ist. Deaktivierte und archivierte Medien bleiben über „Weitere Filter“ auffindbar.',
|
||||||
|
'zeilen' => array_map($this->zeile(...), $this->cards()),
|
||||||
|
'einheit' => ['Medium', 'Medien'],
|
||||||
|
'leer' => ['titel' => 'Noch keine Medien', 'text' => 'Mit „Medium anlegen“ oben lädst du eine Datei hoch oder schreibst einen Text.'],
|
||||||
|
'ansicht' => 'ansicht',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $card
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
private function zeile(array $card): array
|
||||||
|
{
|
||||||
|
$chips = [['label' => $card['stand'], 'ton' => match ($card['standTone']) {
|
||||||
|
'ready' => 'gut',
|
||||||
|
'draft' => 'offen',
|
||||||
|
'blocked' => 'achtung',
|
||||||
|
default => 'leise',
|
||||||
|
}]];
|
||||||
|
|
||||||
|
foreach ([['draftNote', 'offen'], ['blockedNote', 'achtung'], ['processing', 'offen'], ['versionLabel', 'leise']] as [$feld, $ton]) {
|
||||||
|
if (filled($card[$feld] ?? null)) {
|
||||||
|
$chips[] = ['label' => (string) $card[$feld], 'ton' => $ton];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($card['archived']) {
|
||||||
|
$chips[] = ['label' => 'Archiviert', 'ton' => 'leise'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'schluessel' => 'm'.$card['id'],
|
||||||
|
'titel' => $card['title'],
|
||||||
|
'meta' => $card['type'].(filled($card['editorialKind'] ?? null) ? ' · '.$card['editorialKind'] : ''),
|
||||||
|
'text' => $card['description'],
|
||||||
|
'bild' => $card['image'],
|
||||||
|
'bildAlt' => $card['imageAlt'],
|
||||||
|
'symbol' => match ($card['typeKey']) {
|
||||||
|
'film' => 'film',
|
||||||
|
'bild' => 'bild',
|
||||||
|
'audio' => 'audio',
|
||||||
|
default => 'dokument',
|
||||||
|
},
|
||||||
|
'url' => $card['url'],
|
||||||
|
'chips' => $chips,
|
||||||
|
'hinweise' => array_values(array_filter([
|
||||||
|
$card['imageNote'] ? 'Vorschaubild: '.$card['imageNote'] : null,
|
||||||
|
$card['usageNote'] ? 'Einsatz: '.$card['usageNote'] : null,
|
||||||
|
$card['licenseNote'] ? 'Interner Lizenzvermerk: '.$card['licenseNote'] : null,
|
||||||
|
])),
|
||||||
|
'zusatz' => ['view' => 'filament.media.usages', 'daten' => ['card' => $card]],
|
||||||
|
'aktionen' => array_values(array_filter([
|
||||||
|
['label' => 'Ansehen', 'href' => $card['url'], 'icon' => 'auge'],
|
||||||
|
$card['editUrl'] ? ['label' => 'Redaktion', 'href' => $card['editUrl'], 'icon' => 'stift'] : null,
|
||||||
|
])),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
private function libraryFilters(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'suche' => $this->suche,
|
||||||
|
'art' => $this->art,
|
||||||
|
'freigabe' => $this->freigabe,
|
||||||
|
'entwurf' => $this->entwurf,
|
||||||
|
'fassung' => $this->fassung,
|
||||||
|
'nutzung' => $this->nutzung,
|
||||||
|
'saeule' => $this->saeule,
|
||||||
|
'einordnung' => $this->einordnung,
|
||||||
|
'inhaltsart' => $this->inhaltsart,
|
||||||
|
'verarbeitung' => $this->verarbeitung,
|
||||||
|
'archiv' => $this->archiv,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
@@ -25,6 +288,7 @@ protected function getHeaderActions(): array
|
|||||||
return [
|
return [
|
||||||
Action::make('create')
|
Action::make('create')
|
||||||
->label('Medium anlegen')
|
->label('Medium anlegen')
|
||||||
|
->modalSubmitActionLabel('Medium anlegen')
|
||||||
->visible(fn (): bool => ContentElementResource::editor())
|
->visible(fn (): bool => ContentElementResource::editor())
|
||||||
->modalDescription('Dieselbe Maske gilt im Medienbestand, im Modul und im Programm. Der Upload zeigt seinen Fortschritt. Beschreibung, Hinweise und Vorschaubild gehören dazu.')
|
->modalDescription('Dieselbe Maske gilt im Medienbestand, im Modul und im Programm. Der Upload zeigt seinen Fortschritt. Beschreibung, Hinweise und Vorschaubild gehören dazu.')
|
||||||
->schema(fn (): array => MediumForm::fields(creating: true))
|
->schema(fn (): array => MediumForm::fields(creating: true))
|
||||||
|
|||||||
@@ -6,23 +6,35 @@
|
|||||||
use App\Domain\Catalog\ContentElementVersion;
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
use App\Domain\Catalog\ContentService;
|
use App\Domain\Catalog\ContentService;
|
||||||
use App\Domain\Catalog\ContentVersionStatus;
|
use App\Domain\Catalog\ContentVersionStatus;
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
use App\Domain\Catalog\EditorialVocabulary;
|
||||||
|
use App\Domain\Catalog\IdentityChange;
|
||||||
|
use App\Domain\Catalog\IdentityDimension;
|
||||||
|
use App\Domain\Catalog\IdentityDimensionValue;
|
||||||
use App\Domain\Catalog\IdentityProfile;
|
use App\Domain\Catalog\IdentityProfile;
|
||||||
use App\Domain\Catalog\Pillar;
|
use App\Domain\Catalog\Pillar;
|
||||||
use App\Domain\Catalog\PillarService;
|
use App\Domain\Catalog\PillarService;
|
||||||
|
use App\Domain\Cms\Catalog\PublicMaterialReader;
|
||||||
|
use App\Domain\Cms\WebsiteImageUsage;
|
||||||
|
use App\Domain\Cms\Widgets\RenderContext;
|
||||||
use App\Domain\Media\ThumbnailRef;
|
use App\Domain\Media\ThumbnailRef;
|
||||||
|
use App\Domain\Media\WebsiteMedia;
|
||||||
|
use App\Domain\Media\WebsiteRelease;
|
||||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
use App\Filament\Support\CatalogReading;
|
use App\Filament\Support\CatalogReading;
|
||||||
|
use App\Filament\Support\EditorialCatalog;
|
||||||
use App\Filament\Support\ElementRevision;
|
use App\Filament\Support\ElementRevision;
|
||||||
|
use App\Filament\Support\ManagesEditorialSurface;
|
||||||
|
use App\Filament\Support\MediaLibrary;
|
||||||
use App\Filament\Support\ReportsDomainRules;
|
use App\Filament\Support\ReportsDomainRules;
|
||||||
use App\Http\Controllers\ContentPreviewController;
|
use App\Http\Controllers\ContentPreviewController;
|
||||||
use App\Jobs\DeriveThumbnail;
|
use App\Jobs\DeriveThumbnail;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Forms\Components\CheckboxList;
|
|
||||||
use Filament\Forms\Components\Textarea;
|
use Filament\Forms\Components\Textarea;
|
||||||
use Filament\Forms\Components\TextInput;
|
|
||||||
use Filament\Resources\Pages\ViewRecord;
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
use Filament\Schemas\Components\View;
|
use Filament\Schemas\Components\View;
|
||||||
use Filament\Schemas\Schema;
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Enums\Width;
|
||||||
use Illuminate\Contracts\Support\Htmlable;
|
use Illuminate\Contracts\Support\Htmlable;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||||
@@ -30,6 +42,7 @@
|
|||||||
|
|
||||||
class ViewContentElement extends ViewRecord
|
class ViewContentElement extends ViewRecord
|
||||||
{
|
{
|
||||||
|
use ManagesEditorialSurface;
|
||||||
use ReportsDomainRules;
|
use ReportsDomainRules;
|
||||||
use WithFileUploads;
|
use WithFileUploads;
|
||||||
|
|
||||||
@@ -45,8 +58,60 @@ class ViewContentElement extends ViewRecord
|
|||||||
|
|
||||||
public string $pictureFeedback = '';
|
public string $pictureFeedback = '';
|
||||||
|
|
||||||
|
/** Rückmeldung zur ausgewählten Fassung, direkt im Detailbereich. */
|
||||||
|
public string $fassungFeedback = '';
|
||||||
|
|
||||||
|
public bool $fassungFeedbackError = false;
|
||||||
|
|
||||||
|
/** Gewählte Quelle für ein neues Vorschaubild: film oder upload. */
|
||||||
|
public string $bildQuelle = '';
|
||||||
|
|
||||||
public mixed $previewUpload = null;
|
public mixed $previewUpload = null;
|
||||||
|
|
||||||
|
public string $bereich = 'inhalt';
|
||||||
|
|
||||||
|
public string $workingTitle = '';
|
||||||
|
|
||||||
|
public string $displayTitle = '';
|
||||||
|
|
||||||
|
public string $teaser = '';
|
||||||
|
|
||||||
|
public string $summary = '';
|
||||||
|
|
||||||
|
public string $searchTerms = '';
|
||||||
|
|
||||||
|
public string $descriptionText = '';
|
||||||
|
|
||||||
|
public string $usageNote = '';
|
||||||
|
|
||||||
|
public string $licenseNote = '';
|
||||||
|
|
||||||
|
public string $websiteCredit = '';
|
||||||
|
|
||||||
|
public string $websiteAlt = '';
|
||||||
|
|
||||||
|
public string $websiteFeedback = '';
|
||||||
|
|
||||||
|
public int|string|null $kindId = null;
|
||||||
|
|
||||||
|
/** @var list<int|string> */
|
||||||
|
public array $pillarIds = [];
|
||||||
|
|
||||||
|
/** @var list<int|string> */
|
||||||
|
public array $dimensionIds = [];
|
||||||
|
|
||||||
|
public string $editorialFeedback = '';
|
||||||
|
|
||||||
|
public int $versionsBeforeSave = 0;
|
||||||
|
|
||||||
|
public string $previewWidth = '640';
|
||||||
|
|
||||||
|
public string $previewSurface = 'website';
|
||||||
|
|
||||||
|
public string $pickerContext = 'modul';
|
||||||
|
|
||||||
|
public string $pickerLayout = 'kacheln';
|
||||||
|
|
||||||
public function mount(int|string $record): void
|
public function mount(int|string $record): void
|
||||||
{
|
{
|
||||||
parent::mount($record);
|
parent::mount($record);
|
||||||
@@ -57,26 +122,103 @@ public function mount(int|string $record): void
|
|||||||
$this->fassung = $requested;
|
$this->fassung = $requested;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$bereich = (string) request()->query('bereich', 'inhalt');
|
||||||
|
$this->bereich = $this->normalBereich($bereich);
|
||||||
$this->thumbnailAlt = (string) ($this->getRecord()->thumbnail_alt ?? '');
|
$this->thumbnailAlt = (string) ($this->getRecord()->thumbnail_alt ?? '');
|
||||||
|
$this->bildQuelle = $this->getRecord()->output_class === 'film' ? 'film' : 'upload';
|
||||||
|
$this->fillEditorial();
|
||||||
|
// Die gezeigte Fassung wird festgehalten. Sonst wechselte die Anzeige still auf eine andere Fassung, sobald
|
||||||
|
// eine Freigabe oder neue Fassung die Vorgabe „neueste freigegebene“ ändert, während das Textfeld noch den
|
||||||
|
// Wortlaut der bisherigen enthält. Eine fremde oder ungültige Angabe in der Adresse wird dabei ersetzt.
|
||||||
|
$this->fassung = $this->shownVersion()?->id;
|
||||||
$this->syncBodyDraft();
|
$this->syncBodyDraft();
|
||||||
|
|
||||||
|
if (in_array($bereich, ['praesentation', 'redaktion'], true) && $this->canEditEditorial()) {
|
||||||
|
$this->openRedaktion($bereich === 'praesentation' ? 'medien' : 'texte');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSubheading(): string|Htmlable|null
|
public function updatedBereich(string $value): void
|
||||||
{
|
{
|
||||||
return 'Jede Fassung hat eine eigene Nummer und bleibt einsehbar. Beschreibung, Arbeitstitel und Säulen gehören zum Medium und ändern keine Fassung. Eine deaktivierte Fassung wird nicht mehr ausgeliefert und lässt sich nicht neu einbauen.';
|
$this->bereich = $this->normalBereich($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bereiche des Medieneditors. Fassungen und Inhalt bilden einen Bereich (Fassungen links, ausgewählte Fassung rechts);
|
||||||
|
* „fassungen“ bleibt als Adresse gültig. Die früheren Werte „beschreibung“ und „praesentation“ führen zur
|
||||||
|
* Website-Ansicht, weil Texte und Präsentationsmedien in der gemeinsamen Redaktion bearbeitet werden.
|
||||||
|
*/
|
||||||
|
public function normalBereich(string $value): string
|
||||||
|
{
|
||||||
|
return match ($value) {
|
||||||
|
'inhalt', 'vorschaubild', 'verwendung', 'vorschau', 'website' => $value,
|
||||||
|
'fassungen' => 'inhalt',
|
||||||
|
'beschreibung', 'praesentation', 'redaktion' => 'website',
|
||||||
|
default => 'inhalt',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle(): string|Htmlable
|
||||||
|
{
|
||||||
|
return (string) $this->getRecord()->working_title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMaxContentWidth(): Width|string|null
|
||||||
|
{
|
||||||
|
return Width::Full;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function infolist(Schema $schema): Schema
|
public function infolist(Schema $schema): Schema
|
||||||
{
|
{
|
||||||
return $schema->components([
|
return $schema->components([
|
||||||
View::make('filament.media.viewer')->viewData(fn (): array => $this->viewerData()),
|
View::make('filament.media.viewer')->viewData(fn (): array => $this->viewerData())->columnSpanFull(),
|
||||||
]);
|
])->columns(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wählt eine Fassung. Ein geänderter, noch nicht gespeicherter Text geht dabei nicht stillschweigend verloren.
|
||||||
|
*/
|
||||||
public function showVersion(int $version): void
|
public function showVersion(int $version): void
|
||||||
{
|
{
|
||||||
abort_unless($this->ownedVersion($version) instanceof ContentElementVersion, 404);
|
abort_unless($this->ownedVersion($version) instanceof ContentElementVersion, 404);
|
||||||
|
$this->bereich = 'inhalt';
|
||||||
|
|
||||||
|
if ($this->shownVersion()?->id === $version) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->textUnsaved()) {
|
||||||
|
$this->askConfirmation('showVersion', $version);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->selectVersion($version);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Der Text der gezeigten Fassung weicht vom gespeicherten Stand ab.
|
||||||
|
*/
|
||||||
|
public function textUnsaved(): bool
|
||||||
|
{
|
||||||
|
$shown = $this->shownVersion();
|
||||||
|
|
||||||
|
return $shown instanceof ContentElementVersion
|
||||||
|
&& $this->getRecord()->output_class === 'text'
|
||||||
|
&& $shown->status !== ContentVersionStatus::Gesperrt
|
||||||
|
&& trim($this->bodyDraft) !== trim((string) $shown->body);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function discardShownText(): void
|
||||||
|
{
|
||||||
|
$this->syncBodyDraft();
|
||||||
|
$this->fassungFeedback = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function selectVersion(int $version): void
|
||||||
|
{
|
||||||
$this->fassung = $version;
|
$this->fassung = $version;
|
||||||
|
$this->fassungFeedback = '';
|
||||||
$this->syncBodyDraft();
|
$this->syncBodyDraft();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,12 +230,28 @@ public function saveShownText(): void
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$created = app(ContentService::class)->isCommitted($shown);
|
if (! $this->textUnsaved()) {
|
||||||
$this->report(function () use ($shown): void {
|
$this->fassungFeedback = 'Der Text ist unverändert. Es gibt nichts zu speichern.';
|
||||||
app(ContentService::class)->reviseElementContent($shown, $this->bodyDraft);
|
$this->fassungFeedbackError = false;
|
||||||
}, $created
|
|
||||||
? 'Die neue Fassung ist angelegt. Die bisherige bleibt erhalten.'
|
return;
|
||||||
: 'Der Text ist in derselben Fassung gespeichert.');
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$saved = app(ContentService::class)->reviseElementContent($shown, $this->bodyDraft);
|
||||||
|
} catch (DomainRuleException $exception) {
|
||||||
|
$this->fassungFeedback = $exception->getMessage();
|
||||||
|
$this->fassungFeedbackError = true;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Eine freigegebene Fassung bleibt unverändert; die Auswahl folgt der neu angelegten Fassung.
|
||||||
|
$this->fassungFeedback = $saved->id !== $shown->id
|
||||||
|
? 'Fassung '.$saved->number.' ist angelegt. Fassung '.$shown->number.' bleibt erhalten.'
|
||||||
|
: 'Der Text ist in Fassung '.$saved->number.' gespeichert. Es entsteht keine neue Fassung.';
|
||||||
|
$this->fassungFeedbackError = false;
|
||||||
|
$this->fassung = $saved->id;
|
||||||
$this->getRecord()->unsetRelation('versions');
|
$this->getRecord()->unsetRelation('versions');
|
||||||
$this->syncBodyDraft();
|
$this->syncBodyDraft();
|
||||||
}
|
}
|
||||||
@@ -221,7 +379,7 @@ public function deactivateAction(): Action
|
|||||||
{
|
{
|
||||||
return Action::make('deactivate')
|
return Action::make('deactivate')
|
||||||
->label('Deaktivieren')
|
->label('Deaktivieren')
|
||||||
->modalHeading('Fassung deaktivieren')
|
->modalHeading(fn (array $arguments): string => 'Fassung '.($this->ownedVersion((int) ($arguments['version'] ?? 0))?->number ?? '').' deaktivieren')
|
||||||
->modalDescription('Die Fassung bleibt hier einsehbar. Sie wird nicht mehr ausgeliefert und kann nicht in eine neue Übung oder einen neuen Kurs übernommen werden.')
|
->modalDescription('Die Fassung bleibt hier einsehbar. Sie wird nicht mehr ausgeliefert und kann nicht in eine neue Übung oder einen neuen Kurs übernommen werden.')
|
||||||
->modalSubmitActionLabel('Deaktivieren')
|
->modalSubmitActionLabel('Deaktivieren')
|
||||||
->visible(fn (): bool => ContentElementResource::editor())
|
->visible(fn (): bool => ContentElementResource::editor())
|
||||||
@@ -241,83 +399,141 @@ public function deactivateAction(): Action
|
|||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [];
|
||||||
Action::make('describe')
|
}
|
||||||
->label('Beschreibung ändern')
|
|
||||||
->visible(fn (): bool => ContentElementResource::editor())
|
public function releaseVersionAction(): Action
|
||||||
->fillForm(fn (): array => [
|
{
|
||||||
'working_title' => $this->getRecord()->working_title,
|
return Action::make('releaseVersion')
|
||||||
'description' => $this->getRecord()->description,
|
->label('Fassung freigeben')
|
||||||
'usage_note' => $this->getRecord()->usage_note,
|
->modalHeading(function (array $arguments): string {
|
||||||
'license_note' => $this->getRecord()->license_note,
|
$versionId = (int) ($arguments['version'] ?? 0);
|
||||||
'pillars' => $this->getRecord()->pillars()->pluck('pillars.id')->all(),
|
$version = $versionId > 0
|
||||||
])
|
? $this->ownedVersion($versionId)
|
||||||
->schema([
|
: $this->getRecord()->versions()->where('status', ContentVersionStatus::Entwurf)->orderByDesc('number')->first();
|
||||||
TextInput::make('working_title')->label('Arbeitstitel')->required(),
|
|
||||||
Textarea::make('description')->label('Beschreibung')->rows(4)
|
return $version instanceof ContentElementVersion ? 'Fassung '.$version->number.' freigeben' : 'Fassung freigeben';
|
||||||
->helperText('Gilt für das Medium. Speichern legt keine neue Fassung an.'),
|
})
|
||||||
Textarea::make('usage_note')->label('Hinweise für den Einsatz')->rows(4),
|
->modalDescription('Diese Fassung wird freigegeben. Sie erscheint dadurch nicht in der Mitgliederbibliothek, nicht auf der Website und nicht in einem Angebot. Eine deaktivierte Fassung bleibt unverändert.')
|
||||||
Textarea::make('license_note')->label('Interner Lizenzvermerk')->rows(3)
|
->modalSubmitActionLabel('Freigeben')
|
||||||
->helperText('Nur in der Verwaltung. Nicht in der Bibliothek und nicht auf der Website.'),
|
->visible(function (): bool {
|
||||||
CheckboxList::make('pillars')
|
/** @var ContentElement $element */
|
||||||
->label('Fachliche Säulen')
|
$element = $this->getRecord();
|
||||||
->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all()),
|
|
||||||
])
|
return ContentElementResource::editor()
|
||||||
->action(function (array $data): void {
|
&& $element->versions()->where('status', ContentVersionStatus::Entwurf)->exists();
|
||||||
$this->report(function () use ($data): void {
|
})
|
||||||
/** @var ContentElement $element */
|
->action(function (array $arguments): void {
|
||||||
$element = $this->getRecord();
|
abort_unless(ContentElementResource::editor(), 403);
|
||||||
app(ContentService::class)->describe($element, (string) $data['working_title'], $data['description'] ?? null);
|
$this->report(function () use ($arguments): string {
|
||||||
app(IdentityProfile::class)->fill($element, [
|
/** @var ContentElement $element */
|
||||||
'usage_note' => $data['usage_note'] ?? null,
|
$element = $this->getRecord();
|
||||||
'license_note' => $data['license_note'] ?? null,
|
$versionId = (int) ($arguments['version'] ?? 0);
|
||||||
], auth()->user());
|
$version = $versionId > 0
|
||||||
app(PillarService::class)->assign($element, array_map(intval(...), $data['pillars'] ?? []));
|
? $this->ownedVersion($versionId)
|
||||||
}, 'Die Beschreibung ist gespeichert.');
|
: $element->versions()->where('status', ContentVersionStatus::Entwurf)->orderByDesc('number')->first();
|
||||||
$this->getRecord()->refresh();
|
abort_unless($version instanceof ContentElementVersion, 404);
|
||||||
}),
|
$released = app(ContentService::class)->releaseElementVersion($version);
|
||||||
Action::make('releaseVersion')
|
|
||||||
->label('Fassung freigeben')
|
return 'Fassung '.$released->number.' ist freigegeben.';
|
||||||
->modalHeading('Fassung freigeben')
|
}, 'Die Fassung ist freigegeben.');
|
||||||
->modalDescription('Diese Fassung wird freigegeben. Sie erscheint dadurch nicht in der Mitgliederbibliothek, nicht auf der Website und nicht in einem Angebot. Eine deaktivierte Fassung bleibt unverändert.')
|
$this->getRecord()->unsetRelation('versions');
|
||||||
->modalSubmitActionLabel('Freigeben')
|
});
|
||||||
->visible(function (): bool {
|
}
|
||||||
|
|
||||||
|
public function reviseAction(): Action
|
||||||
|
{
|
||||||
|
return Action::make('revise')
|
||||||
|
->label('Neue Fassung anlegen')
|
||||||
|
->modalHeading('Neue Fassung anlegen')
|
||||||
|
->modalDescription('Für eine neue Datei oder einen geänderten Lehrtext. Die bisherigen Fassungen bleiben unverändert. Redaktion, Vorschaubild und Website-Angaben gehören nicht zur Fassung.')
|
||||||
|
->modalSubmitActionLabel('Fassung anlegen')
|
||||||
|
->visible(fn (): bool => ContentElementResource::editor())
|
||||||
|
->schema(fn (): array => ElementRevision::fields($this->getRecord()))
|
||||||
|
->action(function (array $data): void {
|
||||||
|
// Vor dem Anlegen prüfen: danach gäbe es eine andere neueste Fassung.
|
||||||
|
$textOffen = $this->textUnsaved();
|
||||||
|
$this->report(function () use ($data): string {
|
||||||
/** @var ContentElement $element */
|
/** @var ContentElement $element */
|
||||||
$element = $this->getRecord();
|
$element = $this->getRecord();
|
||||||
|
|
||||||
return ContentElementResource::editor()
|
return ElementRevision::publish($element, $data);
|
||||||
&& $element->versions()->where('status', ContentVersionStatus::Entwurf)->exists();
|
}, 'Die neue Fassung ist angelegt.');
|
||||||
})
|
$this->getRecord()->unsetRelation('versions');
|
||||||
->action(function (array $arguments): void {
|
|
||||||
abort_unless(ContentElementResource::editor(), 403);
|
|
||||||
$this->report(function () use ($arguments): string {
|
|
||||||
/** @var ContentElement $element */
|
|
||||||
$element = $this->getRecord();
|
|
||||||
$versionId = (int) ($arguments['version'] ?? 0);
|
|
||||||
$version = $versionId > 0
|
|
||||||
? $this->ownedVersion($versionId)
|
|
||||||
: $element->versions()->where('status', ContentVersionStatus::Entwurf)->orderByDesc('number')->first();
|
|
||||||
abort_unless($version instanceof ContentElementVersion, 404);
|
|
||||||
$released = app(ContentService::class)->releaseElementVersion($version);
|
|
||||||
|
|
||||||
return 'Fassung '.$released->number.' ist freigegeben.';
|
// Die neue Fassung wird gezeigt, sofern dabei kein offener Text verloren geht.
|
||||||
}, 'Die Fassung ist freigegeben.');
|
if (! $textOffen) {
|
||||||
$this->getRecord()->unsetRelation('versions');
|
$neueste = $this->getRecord()->versions()->orderByDesc('number')->value('id');
|
||||||
}),
|
$this->fassung = $neueste !== null ? (int) $neueste : $this->fassung;
|
||||||
Action::make('revise')
|
$this->fassungFeedback = '';
|
||||||
->label('Neue Fassung anlegen')
|
$this->syncBodyDraft();
|
||||||
->visible(fn (): bool => ContentElementResource::editor())
|
}
|
||||||
->schema(fn (): array => ElementRevision::fields($this->getRecord()))
|
});
|
||||||
->action(function (array $data): void {
|
}
|
||||||
$this->report(function () use ($data): string {
|
|
||||||
/** @var ContentElement $element */
|
|
||||||
$element = $this->getRecord();
|
|
||||||
|
|
||||||
return ElementRevision::publish($element, $data);
|
/**
|
||||||
}, 'Die neue Fassung ist angelegt.');
|
* Löschen bleibt Medien ohne Fassung vorbehalten. Bisher nur im separaten Formular, jetzt unter „Weitere Aktionen“.
|
||||||
$this->getRecord()->unsetRelation('versions');
|
*/
|
||||||
}),
|
public function deleteAction(): Action
|
||||||
];
|
{
|
||||||
|
return Action::make('delete')
|
||||||
|
->label('Medium löschen')
|
||||||
|
->color('danger')
|
||||||
|
->requiresConfirmation()
|
||||||
|
->modalHeading('Medium löschen')
|
||||||
|
->modalDescription('Das Medium hat keine Fassung und wird endgültig gelöscht. Zuordnungen als Präsentationsmedium entfallen.')
|
||||||
|
->modalSubmitActionLabel('Löschen')
|
||||||
|
->visible(fn (): bool => ContentElementResource::editor() && $this->getRecord()->versions()->doesntExist())
|
||||||
|
->action(function (): void {
|
||||||
|
abort_unless(ContentElementResource::editor() && $this->getRecord()->versions()->doesntExist(), 403);
|
||||||
|
$this->getRecord()->delete();
|
||||||
|
$this->redirect(ContentElementResource::getUrl('index'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function openThumbnailPicker(): void
|
||||||
|
{
|
||||||
|
abort_unless(ContentElementResource::editor(), 403);
|
||||||
|
$this->resetPicker('vorschaubild');
|
||||||
|
$this->pickerKind = 'bild';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function adoptThumbnailFromPicker(string $target): void
|
||||||
|
{
|
||||||
|
$this->pickerSelected = $target;
|
||||||
|
$this->adoptLibraryImage();
|
||||||
|
$this->pickerSelected = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{aktion: string, argument: int|string|null, titel: string, text: string, label: string, gefahr: bool}|null
|
||||||
|
*/
|
||||||
|
protected function extraConfirmation(string $aktion, int|string|null $argument): ?array
|
||||||
|
{
|
||||||
|
$gezeigt = $this->shownVersion();
|
||||||
|
|
||||||
|
return match ($aktion) {
|
||||||
|
'withdrawWebsite' => ['aktion' => $aktion, 'argument' => null, 'titel' => 'Website-Freigabe zurücknehmen?', 'text' => 'Das Medium verschwindet sofort von allen öffentlichen Seiten. Zuordnungen und Fassungen bleiben erhalten.', 'label' => 'Freigabe zurücknehmen', 'gefahr' => true],
|
||||||
|
'showVersion' => ['aktion' => $aktion, 'argument' => $argument, 'titel' => 'Ungespeicherten Text verwerfen?', 'text' => 'Der geänderte Text von Fassung '.($gezeigt?->number ?? '').' ist noch nicht gespeichert und geht beim Wechsel verloren. Gespeicherte Fassungen bleiben unverändert.', 'label' => 'Verwerfen und wechseln', 'gefahr' => true],
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function runExtraConfirmation(string $aktion, int|string|null $argument): void
|
||||||
|
{
|
||||||
|
match ($aktion) {
|
||||||
|
'withdrawWebsite' => $this->withdrawWebsite(),
|
||||||
|
'showVersion' => $this->ownedVersion((int) $argument) instanceof ContentElementVersion ? $this->selectVersion((int) $argument) : null,
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasDraftVersion(): bool
|
||||||
|
{
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
|
||||||
|
return $element->versions()->where('status', ContentVersionStatus::Entwurf)->exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -395,6 +611,7 @@ private function pictureCaption(ContentElement $element): string
|
|||||||
return match ($source) {
|
return match ($source) {
|
||||||
'eigen' => 'Eigenes Vorschaubild.',
|
'eigen' => 'Eigenes Vorschaubild.',
|
||||||
'datei' => 'Vorschaubild aus der Datei des Mediums.',
|
'datei' => 'Vorschaubild aus der Datei des Mediums.',
|
||||||
|
'bestand' => 'Vorschaubild aus einem Bild im Bestand. Es ist damit nicht für die Website freigegeben.',
|
||||||
default => '',
|
default => '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -406,4 +623,461 @@ private function ownedVersion(int $id): ?ContentElementVersion
|
|||||||
|
|
||||||
return $element->versions()->whereKey($id)->first();
|
return $element->versions()->whereKey($id)->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Speichert die Redaktion: Texte, Einordnung, Präsentationsmedien und Abweichungen. Datei und Fassungen bleiben.
|
||||||
|
*/
|
||||||
|
public function saveEditorial(): void
|
||||||
|
{
|
||||||
|
$this->saveRedaktion();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function saveRedaktionTexte(): bool
|
||||||
|
{
|
||||||
|
abort_unless(ContentElementResource::editor(), 403);
|
||||||
|
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
$title = trim($this->workingTitle);
|
||||||
|
|
||||||
|
if ($title === '') {
|
||||||
|
$this->deskFeedback = 'Der Arbeitstitel fehlt. Er bezeichnet das Medium in der Verwaltung.';
|
||||||
|
$this->redaktionFehlerFeld = 'workingTitle';
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$kindError = app(EditorialVocabulary::class)->kindError(
|
||||||
|
'medium',
|
||||||
|
filled($this->kindId) ? (int) $this->kindId : null,
|
||||||
|
$element->editorial_content_kind_id !== null ? (int) $element->editorial_content_kind_id : null,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($kindError !== null) {
|
||||||
|
$this->deskFeedback = $kindError;
|
||||||
|
$this->redaktionFehlerFeld = 'kindId';
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->versionsBeforeSave = $element->versions()->count();
|
||||||
|
app(IdentityProfile::class)->fill($element, [
|
||||||
|
'working_title' => $title,
|
||||||
|
'display_title' => $this->displayTitle,
|
||||||
|
'teaser' => $this->teaser,
|
||||||
|
'summary' => $this->summary,
|
||||||
|
'search_terms' => $this->searchTerms,
|
||||||
|
'description' => $this->descriptionText,
|
||||||
|
'usage_note' => $this->usageNote,
|
||||||
|
'license_note' => $this->licenseNote,
|
||||||
|
'website_credit' => $this->websiteCredit,
|
||||||
|
'website_alt' => $this->websiteAlt,
|
||||||
|
'editorial_content_kind_id' => filled($this->kindId) ? (int) $this->kindId : null,
|
||||||
|
], auth()->user());
|
||||||
|
app(PillarService::class)->assign($element, array_map(intval(...), $this->pillarIds));
|
||||||
|
app(IdentityDimension::class)->replaceOffered($element, array_map(intval(...), $this->dimensionIds));
|
||||||
|
|
||||||
|
$element->refresh();
|
||||||
|
$this->fillEditorial();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function redaktionSavedMessage(): string
|
||||||
|
{
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
$this->editorialFeedback = $element->versions()->count() === $this->versionsBeforeSave
|
||||||
|
? 'Gespeichert. Es gibt keine neue Fassung.'
|
||||||
|
: 'Gespeichert. Prüfe die Fassungen, ihre Zahl hat sich geändert.';
|
||||||
|
|
||||||
|
return $this->editorialFeedback.' Datei, Inhaltsfassung und Website-Freigabe bleiben unverändert.';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function resetRedaktionTexte(): void
|
||||||
|
{
|
||||||
|
$this->fillEditorial();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function einordnungUnsaved(): bool
|
||||||
|
{
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord()->fresh() ?? $this->getRecord();
|
||||||
|
$kind = filled($this->kindId) ? (int) $this->kindId : null;
|
||||||
|
$storedKind = $element->editorial_content_kind_id !== null ? (int) $element->editorial_content_kind_id : null;
|
||||||
|
|
||||||
|
if ($kind !== $storedKind) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pillars = $element->pillars()->pluck('pillars.id')->map(fn ($id): int => (int) $id)->all();
|
||||||
|
$currentPillars = array_map(intval(...), $this->pillarIds);
|
||||||
|
sort($pillars);
|
||||||
|
sort($currentPillars);
|
||||||
|
|
||||||
|
if ($pillars !== $currentPillars) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stored = IdentityDimensionValue::query()
|
||||||
|
->where('subject_type', $element->getMorphClass())
|
||||||
|
->where('subject_id', $element->getKey())
|
||||||
|
->where('origin', 'direkt')
|
||||||
|
->pluck('editorial_dimension_value_id')
|
||||||
|
->map(fn ($id): int => (int) $id)
|
||||||
|
->all();
|
||||||
|
$current = array_map(intval(...), $this->dimensionIds);
|
||||||
|
sort($stored);
|
||||||
|
sort($current);
|
||||||
|
|
||||||
|
return $stored !== $current;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{art: string, fuer: string, liste: string, zurueck: string, typ: ?string, umfang: string}
|
||||||
|
*/
|
||||||
|
public function redaktionKopf(): array
|
||||||
|
{
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'art' => 'Medium',
|
||||||
|
'fuer' => 'das Medium',
|
||||||
|
'liste' => 'Medien',
|
||||||
|
'zurueck' => 'Zurück zur Medienbearbeitung',
|
||||||
|
'typ' => $element->editorialContentKind?->label ?? PublicMaterialReader::outputLabel((string) $element->output_class),
|
||||||
|
'umfang' => '„Redaktion speichern“ sichert Texte, Präsentationsmedien und Einordnung dieses Mediums. Verwendende Ansichten übernehmen die Angaben. Datei, Inhaltsfassung und Website-Freigabe bleiben unverändert.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function redaktionTitel(): string
|
||||||
|
{
|
||||||
|
$title = trim($this->displayTitle) !== '' ? trim($this->displayTitle) : trim($this->workingTitle);
|
||||||
|
|
||||||
|
return $title !== '' ? $title : (string) $this->getRecord()->working_title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array<string, mixed>>
|
||||||
|
*/
|
||||||
|
public function redaktionFelder(): array
|
||||||
|
{
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
$stored = fn (string $column): string => (string) ($element->getAttribute($column) ?? '');
|
||||||
|
|
||||||
|
return [
|
||||||
|
['id' => 'arbeitstitel', 'label' => 'Arbeitstitel', 'model' => 'workingTitle', 'kind' => 'text', 'stored' => $stored('working_title'), 'required' => true, 'hilfe' => 'Bezeichnung in der Verwaltung. Pflichtangabe.'],
|
||||||
|
['id' => 'anzeigename', 'label' => 'Anzeigename', 'model' => 'displayTitle', 'kind' => 'text', 'stored' => $stored('display_title'), 'hilfe' => 'Erscheint auf Karten und in der Bibliothek. Leer zeigt den Arbeitstitel.'],
|
||||||
|
['id' => 'teaser', 'label' => 'Teaser', 'model' => 'teaser', 'kind' => 'textarea', 'rows' => 2, 'stored' => $stored('teaser')],
|
||||||
|
['id' => 'kurz', 'label' => 'Kurzbeschreibung', 'model' => 'summary', 'kind' => 'textarea', 'rows' => 3, 'stored' => $stored('summary'), 'hilfe' => 'Erscheint auf Website- und Bibliothekskarten.'],
|
||||||
|
['id' => 'beschreibung', 'label' => 'Ausführliche Beschreibung', 'model' => 'descriptionText', 'kind' => 'textarea', 'rows' => 8, 'stored' => $stored('description'), 'hilfe' => 'Bleibt in der Verwaltung und in Detailansichten. Kein Lehrtext.'],
|
||||||
|
['id' => 'suche', 'label' => 'Suchbegriffe', 'model' => 'searchTerms', 'kind' => 'text', 'gruppe' => 'weitere', 'stored' => $stored('search_terms'), 'placeholder' => 'Begriffe, durch Komma getrennt'],
|
||||||
|
['id' => 'einsatz', 'label' => 'Hinweise für den Einsatz', 'model' => 'usageNote', 'kind' => 'textarea', 'rows' => 3, 'gruppe' => 'weitere', 'stored' => $stored('usage_note')],
|
||||||
|
['id' => 'lizenz', 'label' => 'Interner Lizenzvermerk', 'model' => 'licenseNote', 'kind' => 'textarea', 'rows' => 3, 'gruppe' => 'weitere', 'stored' => $stored('license_note'), 'hilfe' => 'Nur intern sichtbar.'],
|
||||||
|
['id' => 'quelle', 'label' => 'Quellenzeile für die Website', 'model' => 'websiteCredit', 'kind' => 'textarea', 'rows' => 2, 'gruppe' => 'weitere', 'stored' => $stored('website_credit')],
|
||||||
|
['id' => 'alt', 'label' => 'Alternativtext für die Website', 'model' => 'websiteAlt', 'kind' => 'text', 'gruppe' => 'weitere', 'stored' => $stored('website_alt'), 'hilfe' => 'Beschreibt das Bild für Menschen, die es nicht sehen.'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{model: string, options: array<int|string, string>, hilfe: string}
|
||||||
|
*/
|
||||||
|
public function einordnungArt(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'model' => 'kindId',
|
||||||
|
'options' => app(EditorialVocabulary::class)->kindOptions('medium', $this->getRecord()->editorial_content_kind_id !== null ? (int) $this->getRecord()->editorial_content_kind_id : null),
|
||||||
|
'hilfe' => 'Fachliche Materialart, unabhängig von der technischen Medienart.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{legend: string, model: string, values: list<array{id: int, label: string}>}>
|
||||||
|
*/
|
||||||
|
public function einordnungGruppen(): array
|
||||||
|
{
|
||||||
|
$groups = [[
|
||||||
|
'legend' => 'Fachliche Säulen',
|
||||||
|
'model' => 'pillarIds',
|
||||||
|
'values' => Pillar::query()->orderBy('name')->get(['id', 'name'])
|
||||||
|
->map(fn (Pillar $pillar): array => ['id' => (int) $pillar->id, 'label' => (string) $pillar->name])->all(),
|
||||||
|
]];
|
||||||
|
|
||||||
|
foreach (app(EditorialVocabulary::class)->dimensionGroups($this->getRecord(), IdentityDimensionValue::query()
|
||||||
|
->where('subject_type', $this->getRecord()->getMorphClass())
|
||||||
|
->where('subject_id', $this->getRecord()->getKey())
|
||||||
|
->pluck('editorial_dimension_value_id')->map(fn ($id): int => (int) $id)->all()) as $dimension) {
|
||||||
|
$groups[] = [
|
||||||
|
'legend' => $dimension['label'],
|
||||||
|
'model' => 'dimensionIds',
|
||||||
|
'values' => $dimension['values'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values(array_filter($groups, fn (array $group): bool => $group['values'] !== []));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{view: string, stand: string}
|
||||||
|
*/
|
||||||
|
public function redaktionAusgabe(): ?array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'view' => 'filament.media.preview-frame',
|
||||||
|
'stand' => 'Arbeitstitel, Anzeigename und Kurzbeschreibung zeigen deine aktuellen Eingaben, auch ungespeicherte. Bild und übrige Angaben zeigen den gespeicherten Stand.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt das Medium für die Website frei. Quellenzeile und Alternativtext gelten im gespeicherten Stand der Redaktion;
|
||||||
|
* offene Eingaben in der Redaktion werden dabei weder gespeichert noch zurückgesetzt.
|
||||||
|
*/
|
||||||
|
public function releaseForWebsite(): void
|
||||||
|
{
|
||||||
|
abort_unless(ContentElementResource::editor(), 403);
|
||||||
|
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
$this->websiteFeedback = app(WebsiteRelease::class)->release($element, auth()->user());
|
||||||
|
$element->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withdrawWebsite(): void
|
||||||
|
{
|
||||||
|
abort_unless(ContentElementResource::editor(), 403);
|
||||||
|
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
$this->websiteFeedback = app(WebsiteRelease::class)->withdraw($element, auth()->user());
|
||||||
|
$element->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveThumbnailAlt(): void
|
||||||
|
{
|
||||||
|
abort_unless(ContentElementResource::editor(), 403);
|
||||||
|
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
app(IdentityProfile::class)->fill($element, ['thumbnail_alt' => trim($this->thumbnailAlt)], auth()->user());
|
||||||
|
$element->refresh();
|
||||||
|
$this->thumbnailAlt = (string) ($element->thumbnail_alt ?? '');
|
||||||
|
$this->pictureFeedback = 'Der Alternativtext des Vorschaubilds ist gespeichert. Die Fassung bleibt unverändert.';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Website-Seiten, die dieses Medium als Bild verwenden (CMS-Widgets und Abschnittshintergründe).
|
||||||
|
*
|
||||||
|
* @return list<array{path: string, published: bool, draft: bool}>
|
||||||
|
*/
|
||||||
|
public function websitePages(): array
|
||||||
|
{
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
|
||||||
|
return app(WebsiteImageUsage::class)->pages($element);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function websiteIsPublic(): bool
|
||||||
|
{
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
|
||||||
|
return app(WebsiteMedia::class)->present($element->fresh()) !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function adoptLibraryImage(): void
|
||||||
|
{
|
||||||
|
abort_unless(ContentElementResource::editor(), 403);
|
||||||
|
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
$detail = $this->selectionDetail();
|
||||||
|
$sourceId = (int) ($detail['element_id'] ?? 0);
|
||||||
|
$source = $sourceId > 0 ? ContentElement::query()->find($sourceId) : null;
|
||||||
|
$path = $source?->thumbnail_path;
|
||||||
|
|
||||||
|
if (! $source instanceof ContentElement || $source->output_class !== 'bild' || ! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) {
|
||||||
|
$this->pictureFeedback = 'Dieses Bild hat noch kein übernehmbares Vorschaubild.';
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$versions = $element->versions()->count();
|
||||||
|
app(IdentityProfile::class)->fill($element, [
|
||||||
|
'thumbnail_path' => $path,
|
||||||
|
'thumbnail_alt' => filled($source->thumbnail_alt) ? $source->thumbnail_alt : $source->working_title,
|
||||||
|
'thumbnail_source' => 'bestand',
|
||||||
|
'thumbnail_error' => null,
|
||||||
|
], auth()->user());
|
||||||
|
$element->refresh();
|
||||||
|
$this->thumbnailAlt = (string) ($element->thumbnail_alt ?? '');
|
||||||
|
$this->pictureFeedback = $element->versions()->count() === $versions
|
||||||
|
? 'Vorschaubild übernommen. Es gibt keine neue Fassung. Für die Website ist es damit nicht freigegeben.'
|
||||||
|
: 'Vorschaubild übernommen. Prüfe die Fassungen.';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{items: list<array<string, mixed>>, more: bool}
|
||||||
|
*/
|
||||||
|
public function selection(): array
|
||||||
|
{
|
||||||
|
return app(EditorialCatalog::class)->browse(
|
||||||
|
$this->pickerQuery,
|
||||||
|
$this->pickerContext === 'bild' ? 'bild' : 'alle',
|
||||||
|
'',
|
||||||
|
0,
|
||||||
|
elementsOnly: $this->pickerContext !== 'modul',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>|null
|
||||||
|
*/
|
||||||
|
public function selectionDetail(): ?array
|
||||||
|
{
|
||||||
|
if ($this->pickerSelected === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$row = app(EditorialCatalog::class)->rowForTarget($this->pickerSelected, 0, allowDraft: true);
|
||||||
|
|
||||||
|
if ($row === null || ! isset($row['element_id'])) {
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
$element = ContentElement::query()->with('editorialContentKind')->find((int) $row['element_id']);
|
||||||
|
|
||||||
|
if ($element instanceof ContentElement) {
|
||||||
|
$row['visibility'] = app(PublicMaterialReader::class)->visibilityNote($element);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function previewHtml(): string
|
||||||
|
{
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
$draft = [
|
||||||
|
'working_title' => $this->workingTitle,
|
||||||
|
'display_title' => $this->displayTitle,
|
||||||
|
'summary' => $this->summary,
|
||||||
|
'thumbnail_alt' => $this->thumbnailAlt,
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($this->previewSurface === 'bibliothek') {
|
||||||
|
$title = trim($this->displayTitle) !== '' ? trim($this->displayTitle) : trim($this->workingTitle);
|
||||||
|
|
||||||
|
return view('member.partials.card', [
|
||||||
|
'href' => '#vorschau',
|
||||||
|
'card' => [
|
||||||
|
'title' => $title !== '' ? $title : $element->working_title,
|
||||||
|
'summary' => trim($this->summary) !== '' ? trim($this->summary) : null,
|
||||||
|
'kind' => PublicMaterialReader::outputLabel((string) $element->output_class),
|
||||||
|
'coverage' => 'offen',
|
||||||
|
'image' => trim($this->thumbnailAlt) !== '' ? trim($this->thumbnailAlt) : $title,
|
||||||
|
'image_url' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path),
|
||||||
|
'error' => 'Vorschau der Kartenform. Ob jemand sie öffnen darf, entscheidet die Lizenz.',
|
||||||
|
],
|
||||||
|
])->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
$subject = app(PublicMaterialReader::class)->subject($element->id, true, $draft);
|
||||||
|
|
||||||
|
if ($subject === null) {
|
||||||
|
return '<p class="preview-note">Für dieses Medium liegt noch keine anzeigbare Fassung vor. Die Karte erscheint deshalb auch in der Vorschau nicht.</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('widgets.premium_card', [
|
||||||
|
'subject' => $subject,
|
||||||
|
'context' => RenderContext::preview(),
|
||||||
|
'cardStyle' => $subject->style ?? 'media',
|
||||||
|
'imageUrl' => null,
|
||||||
|
'alt' => '',
|
||||||
|
'focus' => ['x' => 50, 'y' => 45],
|
||||||
|
'format' => 'landscape',
|
||||||
|
'fit' => 'cover',
|
||||||
|
'headingTag' => 'h3',
|
||||||
|
'show' => ['summary' => true, 'kind' => true, 'meta' => true, 'action' => true],
|
||||||
|
'actionLabel' => 'Ansehen',
|
||||||
|
'note' => null,
|
||||||
|
'stacked' => $this->previewWidth === '390',
|
||||||
|
])->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{field: string, after: string, when: string}>
|
||||||
|
*/
|
||||||
|
public function editorialHistory(): array
|
||||||
|
{
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
$labels = [
|
||||||
|
'working_title' => 'Arbeitstitel',
|
||||||
|
'display_title' => 'Anzeigename',
|
||||||
|
'teaser' => 'Teaser',
|
||||||
|
'description' => 'Beschreibung',
|
||||||
|
'summary' => 'Kurzbeschreibung',
|
||||||
|
'search_terms' => 'Suchbegriffe',
|
||||||
|
'usage_note' => 'Einsatzhinweis',
|
||||||
|
'license_note' => 'Interner Lizenzvermerk',
|
||||||
|
'website_credit' => 'Quellenzeile',
|
||||||
|
'website_alt' => 'Alternativtext der Website',
|
||||||
|
'website_released_at' => 'Website-Freigabe',
|
||||||
|
'thumbnail_alt' => 'Alternativtext',
|
||||||
|
'thumbnail_path' => 'Vorschaubild',
|
||||||
|
'thumbnail_source' => 'Herkunft des Vorschaubilds',
|
||||||
|
'editorial_content_kind_id' => 'Fachliche Materialart',
|
||||||
|
];
|
||||||
|
|
||||||
|
return IdentityChange::query()
|
||||||
|
->where('subject_type', $element->getMorphClass())
|
||||||
|
->where('subject_id', $element->id)
|
||||||
|
->latest('occurred_at')
|
||||||
|
->limit(8)
|
||||||
|
->get()
|
||||||
|
->map(fn (IdentityChange $change): array => [
|
||||||
|
'field' => $labels[$change->field] ?? $change->field,
|
||||||
|
'after' => is_scalar($change->after) ? (string) $change->after : '',
|
||||||
|
'when' => $change->occurred_at?->timezone(config('app.timezone'))->format('d.m.Y H:i') ?? '',
|
||||||
|
])
|
||||||
|
->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function usageCard(): array
|
||||||
|
{
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
|
||||||
|
return app(MediaLibrary::class)->cardFor($element, ContentElementResource::editor());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fillEditorial(): void
|
||||||
|
{
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
$this->workingTitle = (string) $element->working_title;
|
||||||
|
$this->displayTitle = (string) ($element->display_title ?? '');
|
||||||
|
$this->teaser = (string) ($element->teaser ?? '');
|
||||||
|
$this->summary = (string) ($element->summary ?? '');
|
||||||
|
$this->searchTerms = (string) ($element->search_terms ?? '');
|
||||||
|
$this->descriptionText = (string) ($element->description ?? '');
|
||||||
|
$this->usageNote = (string) ($element->usage_note ?? '');
|
||||||
|
$this->licenseNote = (string) ($element->license_note ?? '');
|
||||||
|
$this->websiteCredit = (string) ($element->website_credit ?? '');
|
||||||
|
$this->websiteAlt = (string) ($element->website_alt ?? '');
|
||||||
|
$this->kindId = $element->editorial_content_kind_id;
|
||||||
|
$this->pillarIds = $element->pillars()->pluck('pillars.id')->all();
|
||||||
|
$this->dimensionIds = IdentityDimensionValue::query()
|
||||||
|
->where('subject_type', $element->getMorphClass())
|
||||||
|
->where('subject_id', $element->id)
|
||||||
|
->where('origin', 'direkt')
|
||||||
|
->pluck('editorial_dimension_value_id')
|
||||||
|
->all();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,11 +7,11 @@
|
|||||||
use App\Filament\Resources\LicenseArticles\Pages\ListLicenseArticles;
|
use App\Filament\Resources\LicenseArticles\Pages\ListLicenseArticles;
|
||||||
use App\Filament\Resources\LicenseArticles\Pages\ViewLicenseArticle;
|
use App\Filament\Resources\LicenseArticles\Pages\ViewLicenseArticle;
|
||||||
use App\Filament\Support\CatalogReading;
|
use App\Filament\Support\CatalogReading;
|
||||||
|
use App\Filament\Support\PublicationReadiness;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Infolists\Components\TextEntry;
|
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Schemas\Components\Section;
|
use Filament\Schemas\Components\View;
|
||||||
use Filament\Schemas\Schema;
|
use Filament\Schemas\Schema;
|
||||||
use Filament\Tables\Columns\TextColumn;
|
use Filament\Tables\Columns\TextColumn;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
@@ -53,15 +53,14 @@ public static function getViewAuthorizationResponse(Model $record): Response
|
|||||||
|
|
||||||
public static function infolist(Schema $schema): Schema
|
public static function infolist(Schema $schema): Schema
|
||||||
{
|
{
|
||||||
return $schema->components([
|
return $schema->columns(1)->components([
|
||||||
Section::make('Aktueller Stand')->schema([
|
View::make('filament.editorial.license-desk')
|
||||||
TextEntry::make('stand')->hiddenLabel()->listWithLineBreaks()
|
->viewData(fn (LicenseArticle $record): array => [
|
||||||
->state(fn (LicenseArticle $record): array => app(CatalogReading::class)->articleStand($record)),
|
'stand' => app(CatalogReading::class)->articleStand($record),
|
||||||
]),
|
'kontext' => app(CatalogReading::class)->articleContext($record),
|
||||||
Section::make('Pakete und Angebote')->description('Wo dieser Artikel lizenziert wird.')->schema([
|
'voraussetzungen' => app(PublicationReadiness::class)->forArticle($record),
|
||||||
TextEntry::make('context')->hiddenLabel()->listWithLineBreaks()
|
])
|
||||||
->state(fn (LicenseArticle $record): array => app(CatalogReading::class)->articleContext($record)),
|
->columnSpanFull(),
|
||||||
]),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,24 @@
|
|||||||
namespace App\Filament\Resources\LicenseArticles\Pages;
|
namespace App\Filament\Resources\LicenseArticles\Pages;
|
||||||
|
|
||||||
use App\Domain\Catalog\ArticleService;
|
use App\Domain\Catalog\ArticleService;
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\LicenseArticle;
|
||||||
|
use App\Domain\Catalog\PresentationMedia;
|
||||||
|
use App\Domain\Catalog\ReleaseStatus;
|
||||||
|
use App\Domain\Catalog\StatusValue;
|
||||||
|
use App\Domain\Media\ThumbnailRef;
|
||||||
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
|
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
|
||||||
|
use App\Filament\Support\ListsCatalog;
|
||||||
use App\Filament\Support\ReportsDomainRules;
|
use App\Filament\Support\ReportsDomainRules;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Resources\Pages\ListRecords;
|
use Filament\Resources\Pages\ListRecords;
|
||||||
use Illuminate\Contracts\Support\Htmlable;
|
use Illuminate\Contracts\Support\Htmlable;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class ListLicenseArticles extends ListRecords
|
class ListLicenseArticles extends ListRecords
|
||||||
{
|
{
|
||||||
|
use ListsCatalog;
|
||||||
use ReportsDomainRules;
|
use ReportsDomainRules;
|
||||||
|
|
||||||
protected static string $resource = LicenseArticleResource::class;
|
protected static string $resource = LicenseArticleResource::class;
|
||||||
@@ -26,15 +35,118 @@ protected function getHeaderActions(): array
|
|||||||
return [
|
return [
|
||||||
Action::make('create')
|
Action::make('create')
|
||||||
->label('Artikel anlegen')
|
->label('Artikel anlegen')
|
||||||
|
->modalHeading('Neuer Lizenzartikel')
|
||||||
|
->modalDescription('Kennung und Produktlinie genügen. Titel, Texte und Stand pflegst du danach am Artikel.')
|
||||||
|
->modalSubmitActionLabel('Artikel anlegen')
|
||||||
->schema([
|
->schema([
|
||||||
TextInput::make('code')->label('Kennung')->required(),
|
TextInput::make('code')->label('Kennung')->required(),
|
||||||
TextInput::make('product_line')->label('Produktlinie'),
|
TextInput::make('product_line')->label('Produktlinie'),
|
||||||
])
|
])
|
||||||
->action(function (array $data): void {
|
->action(function (array $data): void {
|
||||||
$this->report(function () use ($data): void {
|
$article = null;
|
||||||
app(ArticleService::class)->create($data['code'], $data['product_line'] ?? null);
|
$this->report(function () use ($data, &$article): void {
|
||||||
|
$article = app(ArticleService::class)->create($data['code'], $data['product_line'] ?? null);
|
||||||
}, 'Der Lizenzartikel ist angelegt.');
|
}, 'Der Lizenzartikel ist angelegt.');
|
||||||
|
|
||||||
|
if ($article instanceof LicenseArticle) {
|
||||||
|
$this->redirect(LicenseArticleResource::getUrl('view', ['record' => $article]));
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function catalogRows(): array
|
||||||
|
{
|
||||||
|
$offered = DB::table('resolved_scopes')
|
||||||
|
->join('offer_versions', 'offer_versions.id', '=', 'resolved_scopes.offer_version_id')
|
||||||
|
->where('offer_versions.status', 'aktiv')
|
||||||
|
->distinct()
|
||||||
|
->pluck('resolved_scopes.license_article_id')
|
||||||
|
->map(fn (mixed $id): int => (int) $id)
|
||||||
|
->all();
|
||||||
|
$presentation = app(PresentationMedia::class);
|
||||||
|
$rows = [];
|
||||||
|
|
||||||
|
foreach (LicenseArticle::query()->with(['currentRelease', 'releases'])->orderBy('code')->get() as $article) {
|
||||||
|
$current = $article->currentRelease;
|
||||||
|
$currentStatus = $current !== null ? StatusValue::of($current->status) : null;
|
||||||
|
$draft = $article->releases->first(fn ($release): bool => StatusValue::of($release->status) === ReleaseStatus::Entwurf->value);
|
||||||
|
$chips = [];
|
||||||
|
$zustand = [];
|
||||||
|
|
||||||
|
if ($current === null) {
|
||||||
|
$chips[] = ['label' => 'Noch kein Stand', 'ton' => 'offen'];
|
||||||
|
$zustand[] = 'ohne';
|
||||||
|
} elseif ($currentStatus === ReleaseStatus::Gesperrt->value) {
|
||||||
|
$chips[] = ['label' => 'Stand '.$current->number.' gesperrt', 'ton' => 'achtung'];
|
||||||
|
$zustand[] = 'gesperrt';
|
||||||
|
} else {
|
||||||
|
$chips[] = ['label' => 'Stand '.$current->number.' veröffentlicht', 'ton' => 'gut'];
|
||||||
|
$zustand[] = 'stand';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($draft !== null) {
|
||||||
|
$chips[] = ['label' => 'Stand '.$draft->number.' in Arbeit', 'ton' => 'offen'];
|
||||||
|
$zustand[] = 'entwurf';
|
||||||
|
}
|
||||||
|
|
||||||
|
$inOffer = in_array($article->id, $offered, true);
|
||||||
|
$chips[] = $inOffer ? ['label' => 'In einem aktiven Angebot', 'ton' => 'gut'] : ['label' => 'In keinem aktiven Angebot', 'ton' => 'leise'];
|
||||||
|
$zustand[] = $inOffer ? 'angebot' : 'ohne-angebot';
|
||||||
|
|
||||||
|
if ($article->archived_at !== null) {
|
||||||
|
$chips[] = ['label' => 'Archiviert', 'ton' => 'leise'];
|
||||||
|
$zustand[] = 'archiviert';
|
||||||
|
}
|
||||||
|
|
||||||
|
$coverId = $presentation->coverElementId($article);
|
||||||
|
$cover = $coverId !== null ? ContentElement::query()->find($coverId) : null;
|
||||||
|
$title = trim((string) ($article->display_title ?: $article->working_title)) ?: $article->code;
|
||||||
|
$url = LicenseArticleResource::getUrl('view', ['record' => $article]);
|
||||||
|
$rows[] = [
|
||||||
|
'schluessel' => 'a'.$article->id,
|
||||||
|
'titel' => $title,
|
||||||
|
'meta' => 'Lizenzartikel · '.$article->code.(filled($article->product_line) ? ' · '.$article->product_line : ''),
|
||||||
|
'text' => trim((string) ($article->teaser ?: $article->summary)),
|
||||||
|
'bild' => $cover !== null ? ThumbnailRef::url('editorial.card', 'element', $cover->id, $cover->thumbnail_path) : null,
|
||||||
|
'symbol' => 'dokument',
|
||||||
|
'url' => $url,
|
||||||
|
'chips' => $chips,
|
||||||
|
'zustand' => $zustand,
|
||||||
|
'suchtext' => implode(' ', array_filter([$article->code, $article->working_title, $article->display_title, $article->summary, $article->product_line, $article->search_terms])),
|
||||||
|
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function zustandOptionen(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'alle' => 'Jeder Zustand',
|
||||||
|
'stand' => 'Mit veröffentlichtem Stand',
|
||||||
|
'ohne' => 'Noch ohne Stand',
|
||||||
|
'entwurf' => 'Stand in Arbeit',
|
||||||
|
'gesperrt' => 'Gesperrter Stand',
|
||||||
|
'angebot' => 'In einem aktiven Angebot',
|
||||||
|
'ohne-angebot' => 'In keinem aktiven Angebot',
|
||||||
|
'archiviert' => 'Archiviert',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function einheit(): array
|
||||||
|
{
|
||||||
|
return ['Lizenzartikel', 'Lizenzartikel'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function leer(): array
|
||||||
|
{
|
||||||
|
return ['titel' => 'Noch keine Lizenzartikel', 'text' => 'Mit „Artikel anlegen“ oben entsteht der erste Artikel.'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function suchPlatzhalter(): string
|
||||||
|
{
|
||||||
|
return 'Kennung, Titel oder Produktlinie';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,78 +3,407 @@
|
|||||||
namespace App\Filament\Resources\LicenseArticles\Pages;
|
namespace App\Filament\Resources\LicenseArticles\Pages;
|
||||||
|
|
||||||
use App\Domain\Catalog\ArticleService;
|
use App\Domain\Catalog\ArticleService;
|
||||||
|
use App\Domain\Catalog\Composition;
|
||||||
|
use App\Domain\Catalog\CompositionKind;
|
||||||
use App\Domain\Catalog\CompositionVersion;
|
use App\Domain\Catalog\CompositionVersion;
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
use App\Domain\Catalog\ContentElementVersion;
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
|
use App\Domain\Catalog\EditorialProfileReader;
|
||||||
|
use App\Domain\Catalog\EditorialVocabulary;
|
||||||
|
use App\Domain\Catalog\IdentityDimension;
|
||||||
|
use App\Domain\Catalog\IdentityDimensionValue;
|
||||||
|
use App\Domain\Catalog\IdentityProfile;
|
||||||
use App\Domain\Catalog\LicenseArticle;
|
use App\Domain\Catalog\LicenseArticle;
|
||||||
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
|
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
|
||||||
|
use App\Filament\Support\AssignsPillars;
|
||||||
use App\Filament\Support\CatalogOptions;
|
use App\Filament\Support\CatalogOptions;
|
||||||
|
use App\Filament\Support\EditorialCatalog;
|
||||||
|
use App\Filament\Support\ManagesEditorialSurface;
|
||||||
use App\Filament\Support\ReportsDomainRules;
|
use App\Filament\Support\ReportsDomainRules;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\Textarea;
|
use Filament\Forms\Components\Textarea;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Resources\Pages\ViewRecord;
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
use Illuminate\Contracts\Support\Htmlable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class ViewLicenseArticle extends ViewRecord
|
class ViewLicenseArticle extends ViewRecord
|
||||||
{
|
{
|
||||||
|
use AssignsPillars;
|
||||||
|
use ManagesEditorialSurface;
|
||||||
use ReportsDomainRules;
|
use ReportsDomainRules;
|
||||||
|
|
||||||
protected static string $resource = LicenseArticleResource::class;
|
protected static string $resource = LicenseArticleResource::class;
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
public string $workingTitle = '';
|
||||||
|
|
||||||
|
public string $displayTitle = '';
|
||||||
|
|
||||||
|
public string $teaser = '';
|
||||||
|
|
||||||
|
public string $summary = '';
|
||||||
|
|
||||||
|
public string $descriptionText = '';
|
||||||
|
|
||||||
|
public string $searchTerms = '';
|
||||||
|
|
||||||
|
public int|string|null $kindId = null;
|
||||||
|
|
||||||
|
public ?int $releaseBeforeSave = null;
|
||||||
|
|
||||||
|
public int $releaseCountBeforeSave = 0;
|
||||||
|
|
||||||
|
/** @var list<int|string> */
|
||||||
|
public array $dimensionIds = [];
|
||||||
|
|
||||||
|
public function mount(int|string $record): void
|
||||||
|
{
|
||||||
|
parent::mount($record);
|
||||||
|
$this->fillLicenseEditorial();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canEditEditorial(): bool
|
||||||
|
{
|
||||||
|
return LicenseArticleResource::keeper();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canViewEditorial(): bool
|
||||||
|
{
|
||||||
|
return LicenseArticleResource::keeper();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle(): string|Htmlable
|
||||||
|
{
|
||||||
|
return $this->redaktionTitel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveLicenseEditorial(): void
|
||||||
|
{
|
||||||
|
$this->saveRedaktion();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function saveRedaktionTexte(): bool
|
||||||
|
{
|
||||||
|
$this->guardEditorial();
|
||||||
|
|
||||||
|
/** @var LicenseArticle $article */
|
||||||
|
$article = $this->getRecord();
|
||||||
|
$this->releaseBeforeSave = $article->current_release_id;
|
||||||
|
$this->releaseCountBeforeSave = $article->releases()->count();
|
||||||
|
|
||||||
|
$kindError = app(EditorialVocabulary::class)->kindError(
|
||||||
|
'lizenzartikel',
|
||||||
|
filled($this->kindId) ? (int) $this->kindId : null,
|
||||||
|
$article->editorial_content_kind_id !== null ? (int) $article->editorial_content_kind_id : null,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($kindError !== null) {
|
||||||
|
$this->deskFeedback = $kindError;
|
||||||
|
$this->redaktionFehlerFeld = 'kindId';
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
app(IdentityProfile::class)->fill($article, [
|
||||||
|
'working_title' => $this->workingTitle,
|
||||||
|
'display_title' => $this->displayTitle,
|
||||||
|
'teaser' => $this->teaser,
|
||||||
|
'summary' => $this->summary,
|
||||||
|
'description' => $this->descriptionText,
|
||||||
|
'search_terms' => $this->searchTerms,
|
||||||
|
'editorial_content_kind_id' => filled($this->kindId) ? (int) $this->kindId : null,
|
||||||
|
], auth()->user());
|
||||||
|
|
||||||
|
app(IdentityDimension::class)->replaceOffered($article, array_map(intval(...), $this->dimensionIds));
|
||||||
|
$this->persistPillarIds($article);
|
||||||
|
|
||||||
|
$article->refresh();
|
||||||
|
$this->fillLicenseEditorial();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function redaktionSavedMessage(): string
|
||||||
|
{
|
||||||
|
/** @var LicenseArticle $article */
|
||||||
|
$article = $this->getRecord();
|
||||||
|
|
||||||
|
return $article->current_release_id === $this->releaseBeforeSave && $article->releases()->count() === $this->releaseCountBeforeSave
|
||||||
|
? 'Gespeichert. Stand, Preis und Rechte bleiben unverändert.'
|
||||||
|
: 'Gespeichert. Prüfe den Artikelstand, er hat sich geändert.';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function resetRedaktionTexte(): void
|
||||||
|
{
|
||||||
|
$this->fillLicenseEditorial();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function einordnungUnsaved(): bool
|
||||||
|
{
|
||||||
|
/** @var LicenseArticle $article */
|
||||||
|
$article = $this->getRecord()->fresh() ?? $this->getRecord();
|
||||||
|
$kind = filled($this->kindId) ? (int) $this->kindId : null;
|
||||||
|
$storedKind = $article->editorial_content_kind_id !== null ? (int) $article->editorial_content_kind_id : null;
|
||||||
|
|
||||||
|
if ($kind !== $storedKind) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stored = IdentityDimensionValue::query()
|
||||||
|
->where('subject_type', $article->getMorphClass())
|
||||||
|
->where('subject_id', $article->getKey())
|
||||||
|
->where('origin', 'direkt')
|
||||||
|
->pluck('editorial_dimension_value_id')
|
||||||
|
->map(fn ($id): int => (int) $id)
|
||||||
|
->all();
|
||||||
|
$current = array_map(intval(...), $this->dimensionIds);
|
||||||
|
sort($stored);
|
||||||
|
sort($current);
|
||||||
|
|
||||||
|
return $stored !== $current || $this->pillarsUnsaved($article);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{art: string, fuer: string, liste: string, zurueck: string, typ: ?string, umfang: string}
|
||||||
|
*/
|
||||||
|
public function redaktionKopf(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Action::make('release')
|
'art' => 'Lizenzartikel',
|
||||||
->label('Stand veröffentlichen')
|
'fuer' => 'den Lizenzartikel',
|
||||||
->schema([
|
'liste' => 'Lizenzartikel',
|
||||||
Select::make('root')->label('Wurzel')->options(fn (): array => CatalogOptions::readyTargets())->required(),
|
'zurueck' => 'Zurück zum Lizenzartikel',
|
||||||
Textarea::make('classification')->label('Einordnung')->required()
|
'typ' => null,
|
||||||
->helperText('Warum dies derselbe Lizenzartikel bleibt und kein neues Produkt ist.'),
|
'umfang' => '„Redaktion speichern“ sichert die eigenen Texte, Präsentationsmedien und Einordnung dieses Lizenzartikels. Leere Angaben übernehmen weiter die fachliche Quelle. Stand, Preis und Rechte bleiben unverändert.',
|
||||||
TextInput::make('change_note')->label('Änderungshinweis'),
|
|
||||||
])
|
|
||||||
->action(function (array $data): void {
|
|
||||||
$this->report(function () use ($data): string {
|
|
||||||
/** @var LicenseArticle $article */
|
|
||||||
$article = $this->getRecord();
|
|
||||||
[$type, $id] = explode(':', $data['root'], 2);
|
|
||||||
$root = $type === 'composition'
|
|
||||||
? CompositionVersion::query()->findOrFail($id)
|
|
||||||
: ContentElementVersion::query()->findOrFail($id);
|
|
||||||
$release = app(ArticleService::class)->publishRelease(
|
|
||||||
$article,
|
|
||||||
$root,
|
|
||||||
$data['classification'],
|
|
||||||
$data['change_note'] ?? null,
|
|
||||||
);
|
|
||||||
$report = $release->impact_report ?? [];
|
|
||||||
$offers = $report['offers'] ?? [];
|
|
||||||
|
|
||||||
return 'Stand '.$release->number.' ist veröffentlicht. Inhalte: '.($report['contents'] ?? 0)
|
|
||||||
.', Inhaber: '.($report['holders'] ?? 0)
|
|
||||||
.', Angebote: '.(implode(', ', $offers) !== '' ? implode(', ', $offers) : 'keins').'.';
|
|
||||||
}, 'Der Artikel-Stand ist veröffentlicht.');
|
|
||||||
$this->refreshRecord();
|
|
||||||
}),
|
|
||||||
Action::make('withdraw')
|
|
||||||
->label('Stand zurückziehen')
|
|
||||||
->schema([
|
|
||||||
Textarea::make('reason')->label('Begründung')->required(),
|
|
||||||
])
|
|
||||||
->action(function (array $data): void {
|
|
||||||
$this->report(function () use ($data): string {
|
|
||||||
$result = app(ArticleService::class)->withdraw($this->getRecord(), $data['reason']);
|
|
||||||
$current = $result['fallback_number'] === null
|
|
||||||
? 'Es gibt keinen früheren Stand.'
|
|
||||||
: 'Aktuell ist wieder Stand '.$result['fallback_number'].'.';
|
|
||||||
$holders = $result['holders'] === [] ? 'niemand' : implode(', ', $result['holders']);
|
|
||||||
|
|
||||||
return 'Der Stand ist zurückgezogen. '.$current.' Betroffen: '.$holders.'.';
|
|
||||||
}, 'Der Stand ist zurückgezogen.');
|
|
||||||
$this->refreshRecord();
|
|
||||||
}),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function redaktionTitel(): string
|
||||||
|
{
|
||||||
|
foreach ([$this->displayTitle, $this->workingTitle] as $title) {
|
||||||
|
if (trim($title) !== '') {
|
||||||
|
return trim($title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$profile = $this->editorialProfile('artikel');
|
||||||
|
|
||||||
|
if ($profile->value('display_title') !== null) {
|
||||||
|
return (string) $profile->value('display_title');
|
||||||
|
}
|
||||||
|
|
||||||
|
$source = $profile->source;
|
||||||
|
|
||||||
|
return $source !== null ? $this->sourceTitle($source) : (string) $this->getRecord()->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array<string, mixed>>
|
||||||
|
*/
|
||||||
|
public function redaktionFelder(): array
|
||||||
|
{
|
||||||
|
/** @var LicenseArticle $article */
|
||||||
|
$article = $this->getRecord();
|
||||||
|
$source = app(EditorialProfileReader::class)->sourceOf($article);
|
||||||
|
$sourceTitle = $source !== null ? $this->sourceTitle($source) : null;
|
||||||
|
$stored = fn (string $column): string => (string) ($article->getAttribute($column) ?? '');
|
||||||
|
$quelle = fn (string $column): ?array => $sourceTitle === null ? null : [
|
||||||
|
'titel' => $sourceTitle,
|
||||||
|
'wert' => (string) ($source->getAttribute($column) ?? ''),
|
||||||
|
];
|
||||||
|
|
||||||
|
return [
|
||||||
|
['id' => 'arbeitstitel', 'label' => 'Interner Arbeitstitel', 'model' => 'workingTitle', 'kind' => 'text', 'stored' => $stored('working_title'), 'hilfe' => 'Nur in der Verwaltung sichtbar.'],
|
||||||
|
['id' => 'anzeigename', 'label' => 'Name', 'model' => 'displayTitle', 'kind' => 'text', 'stored' => $stored('display_title'), 'quelle' => $quelle('display_title')],
|
||||||
|
['id' => 'teaser', 'label' => 'Teaser', 'model' => 'teaser', 'kind' => 'textarea', 'rows' => 2, 'stored' => $stored('teaser'), 'quelle' => $quelle('teaser')],
|
||||||
|
['id' => 'kurz', 'label' => 'Kurzbeschreibung', 'model' => 'summary', 'kind' => 'textarea', 'rows' => 4, 'stored' => $stored('summary'), 'quelle' => $quelle('summary')],
|
||||||
|
['id' => 'beschreibung', 'label' => 'Beschreibung', 'model' => 'descriptionText', 'kind' => 'textarea', 'rows' => 6, 'stored' => $stored('description'), 'quelle' => $quelle('description')],
|
||||||
|
['id' => 'suche', 'label' => 'Suchbegriffe', 'model' => 'searchTerms', 'kind' => 'text', 'gruppe' => 'weitere', 'stored' => $stored('search_terms'), 'quelle' => $quelle('search_terms')],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{titel: string, art: string, fuer: string, url: ?string}|null
|
||||||
|
*/
|
||||||
|
public function redaktionQuelle(): ?array
|
||||||
|
{
|
||||||
|
/** @var LicenseArticle $article */
|
||||||
|
$article = $this->getRecord();
|
||||||
|
$source = app(EditorialProfileReader::class)->sourceOf($article);
|
||||||
|
|
||||||
|
if ($source === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = match (true) {
|
||||||
|
$source instanceof Composition => EditorialCatalog::editUrl($source),
|
||||||
|
$source instanceof ContentElement => ContentElementResource::getUrl('view', ['record' => $source]),
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
|
||||||
|
return [
|
||||||
|
'titel' => $this->sourceTitle($source),
|
||||||
|
'art' => $source instanceof ContentElement ? 'Medium' : ($source instanceof Composition && $source->kind === CompositionKind::Kurs ? 'Programm' : 'Modul'),
|
||||||
|
'fuer' => 'diesen Lizenzartikel',
|
||||||
|
'url' => $url,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function redaktionOhneQuelle(): string
|
||||||
|
{
|
||||||
|
return 'Keine eindeutige fachliche Quelle. Es wird nichts aus einem Modul, Programm oder Medium übernommen.';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{model: string, options: array<int|string, string>, hilfe: string}
|
||||||
|
*/
|
||||||
|
public function einordnungArt(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'model' => 'kindId',
|
||||||
|
'options' => app(EditorialVocabulary::class)->kindOptions('lizenzartikel', $this->getRecord()->editorial_content_kind_id !== null ? (int) $this->getRecord()->editorial_content_kind_id : null),
|
||||||
|
'hilfe' => 'Die Einordnung des Artikels ändert weder die Quelle noch den Preis.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{legend: string, model: string, values: list<array{id: int, label: string}>}>
|
||||||
|
*/
|
||||||
|
public function einordnungGruppen(): array
|
||||||
|
{
|
||||||
|
$groups = array_map(fn (array $group): array => [
|
||||||
|
'legend' => $group['label'],
|
||||||
|
'model' => 'dimensionIds',
|
||||||
|
'values' => $group['values'],
|
||||||
|
], $this->licenseDimensionGroups());
|
||||||
|
|
||||||
|
$pillars = $this->pillarGroup();
|
||||||
|
|
||||||
|
return $pillars === null ? $groups : [$pillars, ...$groups];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sourceTitle(Model $source): string
|
||||||
|
{
|
||||||
|
$title = $source->getAttribute('display_title') ?: ($source->getAttribute('working_title') ?? $source->getAttribute('designation'));
|
||||||
|
|
||||||
|
return (string) $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{label: string, values: list<array{id: int, label: string}>}>
|
||||||
|
*/
|
||||||
|
public function licenseDimensionGroups(): array
|
||||||
|
{
|
||||||
|
return app(EditorialVocabulary::class)->dimensionGroups($this->getRecord(), IdentityDimensionValue::query()
|
||||||
|
->where('subject_type', $this->getRecord()->getMorphClass())
|
||||||
|
->where('subject_id', $this->getRecord()->getKey())
|
||||||
|
->pluck('editorial_dimension_value_id')->map(fn ($id): int => (int) $id)->all());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fillLicenseEditorial(): void
|
||||||
|
{
|
||||||
|
/** @var LicenseArticle $article */
|
||||||
|
$article = $this->getRecord();
|
||||||
|
$this->workingTitle = (string) ($article->working_title ?? '');
|
||||||
|
$this->displayTitle = (string) ($article->display_title ?? '');
|
||||||
|
$this->teaser = (string) ($article->teaser ?? '');
|
||||||
|
$this->summary = (string) ($article->summary ?? '');
|
||||||
|
$this->descriptionText = (string) ($article->description ?? '');
|
||||||
|
$this->searchTerms = (string) ($article->search_terms ?? '');
|
||||||
|
$this->kindId = $article->editorial_content_kind_id;
|
||||||
|
$this->dimensionIds = IdentityDimensionValue::query()
|
||||||
|
->where('subject_type', $article->getMorphClass())
|
||||||
|
->where('subject_id', $article->id)
|
||||||
|
->where('origin', 'direkt')
|
||||||
|
->pluck('editorial_dimension_value_id')
|
||||||
|
->all();
|
||||||
|
$this->loadPillarIds($article);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function releaseAction(): Action
|
||||||
|
{
|
||||||
|
return Action::make('release')
|
||||||
|
->label(fn (): string => $this->isFirstStand() ? 'Inhalt festlegen' : 'Neuen Stand veröffentlichen')
|
||||||
|
->modalHeading(fn (): string => $this->isFirstStand() ? 'Inhalt festlegen: ersten Stand veröffentlichen' : 'Neuen Stand veröffentlichen')
|
||||||
|
->modalDescription(fn (): string => $this->isFirstStand()
|
||||||
|
? 'Der Stand legt fest, welche Inhalte dieser Lizenzartikel lizenziert: der gewählte Inhalt samt allem, was er enthält. Er ist danach unveränderlich. Pakete und Angebote können den Artikel danach verwenden; verkauft wird er erst über ein Angebot.'
|
||||||
|
: 'Ein neuer Stand ersetzt den aktuellen für künftige Ausgaben. Bestehende Käufer erhalten ihn im Rahmen ihrer Lizenz; frühere Stände bleiben gespeichert.')
|
||||||
|
->modalSubmitActionLabel('Stand veröffentlichen')
|
||||||
|
->fillForm(fn (): array => $this->isFirstStand() ? ['classification' => 'Erster Stand dieses Lizenzartikels.'] : [])
|
||||||
|
->schema([
|
||||||
|
Select::make('root')->label('Freigegebener Inhalt')
|
||||||
|
->options(fn (): array => CatalogOptions::assignmentTargets())
|
||||||
|
->searchable()
|
||||||
|
->required()
|
||||||
|
->helperText(fn (): string => CatalogOptions::assignmentTargets() === []
|
||||||
|
? 'Es gibt noch keinen freigegebenen Inhalt. Gib zuerst ein Medium, Modul oder Programm frei.'
|
||||||
|
: 'Medien, Module und Programme mit freigegebener Fassung. Bei Modulen und Programmen gehört alles Enthaltene zum Stand.'),
|
||||||
|
Textarea::make('classification')->label('Einordnung')
|
||||||
|
->required(fn (): bool => ! $this->isFirstStand())
|
||||||
|
->helperText(fn (): string => $this->isFirstStand()
|
||||||
|
? 'Beim ersten Stand genügt der vorgegebene Text.'
|
||||||
|
: 'Warum dies derselbe Lizenzartikel bleibt und kein neues Produkt ist.'),
|
||||||
|
TextInput::make('change_note')->label('Änderungshinweis')
|
||||||
|
->visible(fn (): bool => ! $this->isFirstStand()),
|
||||||
|
])
|
||||||
|
->action(function (array $data): void {
|
||||||
|
$this->report(function () use ($data): string {
|
||||||
|
/** @var LicenseArticle $article */
|
||||||
|
$article = $this->getRecord();
|
||||||
|
[$type, $id] = explode(':', $data['root'], 2);
|
||||||
|
$root = $type === 'composition'
|
||||||
|
? CompositionVersion::query()->findOrFail($id)
|
||||||
|
: ContentElementVersion::query()->findOrFail($id);
|
||||||
|
$release = app(ArticleService::class)->publishRelease(
|
||||||
|
$article,
|
||||||
|
$root,
|
||||||
|
(string) ($data['classification'] ?? 'Erster Stand dieses Lizenzartikels.'),
|
||||||
|
$data['change_note'] ?? null,
|
||||||
|
);
|
||||||
|
$report = $release->impact_report ?? [];
|
||||||
|
$offers = $report['offers'] ?? [];
|
||||||
|
|
||||||
|
return 'Stand '.$release->number.' ist veröffentlicht. Inhalte: '.($report['contents'] ?? 0)
|
||||||
|
.', Inhaber: '.($report['holders'] ?? 0)
|
||||||
|
.', Angebote: '.(implode(', ', $offers) !== '' ? implode(', ', $offers) : 'keins').'.';
|
||||||
|
}, 'Der Artikel-Stand ist veröffentlicht.');
|
||||||
|
$this->refreshRecord();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withdrawAction(): Action
|
||||||
|
{
|
||||||
|
return Action::make('withdraw')
|
||||||
|
->label('Stand zurückziehen')
|
||||||
|
->schema([
|
||||||
|
Textarea::make('reason')->label('Begründung')->required(),
|
||||||
|
])
|
||||||
|
->action(function (array $data): void {
|
||||||
|
$this->report(function () use ($data): string {
|
||||||
|
$result = app(ArticleService::class)->withdraw($this->getRecord(), $data['reason']);
|
||||||
|
$current = $result['fallback_number'] === null
|
||||||
|
? 'Es gibt keinen früheren Stand.'
|
||||||
|
: 'Aktuell ist wieder Stand '.$result['fallback_number'].'.';
|
||||||
|
$holders = $result['holders'] === [] ? 'niemand' : implode(', ', $result['holders']);
|
||||||
|
|
||||||
|
return 'Der Stand ist zurückgezogen. '.$current.' Betroffen: '.$holders.'.';
|
||||||
|
}, 'Der Stand ist zurückgezogen.');
|
||||||
|
$this->refreshRecord();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isFirstStand(): bool
|
||||||
|
{
|
||||||
|
return ! $this->getRecord()->releases()->exists();
|
||||||
|
}
|
||||||
|
|
||||||
private function refreshRecord(): void
|
private function refreshRecord(): void
|
||||||
{
|
{
|
||||||
$this->getRecord()->unsetRelations();
|
$this->getRecord()->unsetRelations();
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ class NavigationItemResource extends Resource
|
|||||||
|
|
||||||
protected static ?string $navigationLabel = 'Navigation';
|
protected static ?string $navigationLabel = 'Navigation';
|
||||||
|
|
||||||
|
/** Menüs werden in der Webpräsenz bearbeitet. */
|
||||||
|
protected static bool $shouldRegisterNavigation = false;
|
||||||
|
|
||||||
protected static ?string $modelLabel = 'Navigationspunkt';
|
protected static ?string $modelLabel = 'Navigationspunkt';
|
||||||
|
|
||||||
protected static ?string $pluralModelLabel = 'Navigation';
|
protected static ?string $pluralModelLabel = 'Navigation';
|
||||||
|
|||||||
@@ -2,18 +2,22 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\NavigationItems\Pages;
|
namespace App\Filament\Resources\NavigationItems\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Pages\Webpraesenz;
|
||||||
use App\Filament\Resources\NavigationItems\NavigationItemResource;
|
use App\Filament\Resources\NavigationItems\NavigationItemResource;
|
||||||
use Filament\Actions\CreateAction;
|
|
||||||
use Filament\Resources\Pages\ManageRecords;
|
use Filament\Resources\Pages\ManageRecords;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Menüs werden in der Webpräsenz bearbeitet (Dokument 13). Die bisherige Adresse führt dorthin, nach derselben
|
||||||
|
* Rechteprüfung wie bisher.
|
||||||
|
*/
|
||||||
class ManageNavigationItems extends ManageRecords
|
class ManageNavigationItems extends ManageRecords
|
||||||
{
|
{
|
||||||
protected static string $resource = NavigationItemResource::class;
|
protected static string $resource = NavigationItemResource::class;
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
public function mount(): void
|
||||||
{
|
{
|
||||||
return [
|
parent::mount();
|
||||||
CreateAction::make(),
|
|
||||||
];
|
$this->redirect(Webpraesenz::getUrl(['bereich' => 'menues']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,13 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Offers\Pages;
|
namespace App\Filament\Resources\Offers\Pages;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\Offer;
|
||||||
use App\Domain\Catalog\OfferService;
|
use App\Domain\Catalog\OfferService;
|
||||||
|
use App\Domain\Catalog\OfferStatus;
|
||||||
|
use App\Domain\Catalog\StatusValue;
|
||||||
use App\Filament\Resources\Offers\OfferResource;
|
use App\Filament\Resources\Offers\OfferResource;
|
||||||
|
use App\Filament\Support\CatalogLabels;
|
||||||
|
use App\Filament\Support\ListsCatalog;
|
||||||
use App\Filament\Support\ReportsDomainRules;
|
use App\Filament\Support\ReportsDomainRules;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
@@ -12,6 +17,7 @@
|
|||||||
|
|
||||||
class ListOffers extends ListRecords
|
class ListOffers extends ListRecords
|
||||||
{
|
{
|
||||||
|
use ListsCatalog;
|
||||||
use ReportsDomainRules;
|
use ReportsDomainRules;
|
||||||
|
|
||||||
protected static string $resource = OfferResource::class;
|
protected static string $resource = OfferResource::class;
|
||||||
@@ -24,13 +30,83 @@ public function getSubheading(): string|Htmlable|null
|
|||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Action::make('create')->label('Angebot anlegen')->schema([
|
Action::make('create')->label('Angebot anlegen')
|
||||||
TextInput::make('name')->label('Name')->required(),
|
->modalHeading('Neues Angebot')
|
||||||
])->action(function (array $data): void {
|
->modalDescription('Der Name genügt. Positionen, Vergabe und Preis legst du danach am Angebot fest.')
|
||||||
$this->report(function () use ($data): void {
|
->modalSubmitActionLabel('Angebot anlegen')
|
||||||
app(OfferService::class)->create($data['name']);
|
->schema([
|
||||||
}, 'Das Angebot ist angelegt.');
|
TextInput::make('name')->label('Name')->required(),
|
||||||
}),
|
])->action(function (array $data): void {
|
||||||
|
$offer = null;
|
||||||
|
$this->report(function () use ($data, &$offer): void {
|
||||||
|
$offer = app(OfferService::class)->create($data['name']);
|
||||||
|
}, 'Das Angebot ist angelegt.');
|
||||||
|
|
||||||
|
if ($offer instanceof Offer) {
|
||||||
|
$this->redirect(OfferResource::getUrl('view', ['record' => $offer]));
|
||||||
|
}
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function catalogRows(): array
|
||||||
|
{
|
||||||
|
$rows = [];
|
||||||
|
|
||||||
|
foreach (Offer::query()->with(['versions.lines.article', 'versions.lines.bundleVersion.bundle', 'versions.lines.rights.profile'])->orderBy('name')->get() as $offer) {
|
||||||
|
$versions = $offer->versions->sortByDesc('number');
|
||||||
|
$active = $versions->first(fn ($version): bool => StatusValue::of($version->status) === OfferStatus::Aktiv->value);
|
||||||
|
$ended = $versions->filter(fn ($version): bool => StatusValue::of($version->status) === OfferStatus::Beendet->value)->count();
|
||||||
|
$chips = [];
|
||||||
|
$zustand = [];
|
||||||
|
$text = '';
|
||||||
|
|
||||||
|
if ($active !== null) {
|
||||||
|
$chips[] = ['label' => 'Fassung '.$active->number.' aktiv', 'ton' => 'gut'];
|
||||||
|
$chips[] = ['label' => CatalogLabels::vergabe($active), 'ton' => 'neutral'];
|
||||||
|
$chips[] = ['label' => $active->holder_kind === 'organisation' ? 'Für Organisationen' : 'Für Privatpersonen', 'ton' => 'neutral'];
|
||||||
|
$zustand[] = 'aktiv';
|
||||||
|
$text = $active->lines->map(fn ($line): string => ($line->article !== null
|
||||||
|
? 'Lizenzartikel '.$line->article->code
|
||||||
|
: 'Paket '.($line->bundleVersion?->bundle?->name ?? '–')).' · '.($line->rights?->profile?->name ?? ''))->implode('; ');
|
||||||
|
} else {
|
||||||
|
$chips[] = ['label' => 'Keine aktive Fassung', 'ton' => 'offen'];
|
||||||
|
$zustand[] = 'ohne';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ended > 0) {
|
||||||
|
$chips[] = ['label' => $ended === 1 ? '1 beendete Fassung' : $ended.' beendete Fassungen', 'ton' => 'leise'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = OfferResource::getUrl('view', ['record' => $offer]);
|
||||||
|
$rows[] = [
|
||||||
|
'schluessel' => 'o'.$offer->id,
|
||||||
|
'titel' => $offer->name,
|
||||||
|
'meta' => 'Angebot',
|
||||||
|
'text' => $text,
|
||||||
|
'symbol' => 'etikett',
|
||||||
|
'url' => $url,
|
||||||
|
'chips' => $chips,
|
||||||
|
'zustand' => $zustand,
|
||||||
|
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function zustandOptionen(): array
|
||||||
|
{
|
||||||
|
return ['alle' => 'Jeder Zustand', 'aktiv' => 'Mit aktiver Fassung', 'ohne' => 'Ohne aktive Fassung'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function einheit(): array
|
||||||
|
{
|
||||||
|
return ['Angebot', 'Angebote'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function leer(): array
|
||||||
|
{
|
||||||
|
return ['titel' => 'Noch keine Angebote', 'text' => 'Mit „Angebot anlegen“ oben entsteht das erste Angebot.'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,14 +2,25 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Offers\Pages;
|
namespace App\Filament\Resources\Offers\Pages;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\BundleService;
|
||||||
use App\Domain\Catalog\BundleVersion;
|
use App\Domain\Catalog\BundleVersion;
|
||||||
|
use App\Domain\Catalog\Composition;
|
||||||
use App\Domain\Catalog\CompositionVersion;
|
use App\Domain\Catalog\CompositionVersion;
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
use App\Domain\Catalog\LicenseArticle;
|
use App\Domain\Catalog\LicenseArticle;
|
||||||
use App\Domain\Catalog\Offer;
|
use App\Domain\Catalog\Offer;
|
||||||
use App\Domain\Catalog\OfferService;
|
use App\Domain\Catalog\OfferService;
|
||||||
|
use App\Domain\Catalog\OfferStatus;
|
||||||
|
use App\Domain\Catalog\OfferVersion;
|
||||||
use App\Domain\Catalog\RightsProfileVersion;
|
use App\Domain\Catalog\RightsProfileVersion;
|
||||||
|
use App\Domain\Catalog\StatusValue;
|
||||||
|
use App\Domain\Cms\Catalog\PublicCatalogReader;
|
||||||
|
use App\Domain\Commerce\Money;
|
||||||
|
use App\Domain\Commerce\ProductOptions;
|
||||||
use App\Filament\Resources\Offers\OfferResource;
|
use App\Filament\Resources\Offers\OfferResource;
|
||||||
|
use App\Filament\Support\CatalogLabels;
|
||||||
use App\Filament\Support\CatalogOptions;
|
use App\Filament\Support\CatalogOptions;
|
||||||
|
use App\Filament\Support\PublicationReadiness;
|
||||||
use App\Filament\Support\ReportsDomainRules;
|
use App\Filament\Support\ReportsDomainRules;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Forms\Components\Repeater;
|
use Filament\Forms\Components\Repeater;
|
||||||
@@ -17,24 +28,105 @@
|
|||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Resources\Pages\ViewRecord;
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
use Filament\Schemas\Components\Utilities\Get;
|
use Filament\Schemas\Components\Utilities\Get;
|
||||||
|
use Filament\Schemas\Components\View;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Enums\Width;
|
||||||
|
use Illuminate\Contracts\Support\Htmlable;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Angebot im gemeinsamen Rahmen. Anlegen und Ändern nutzen dieselbe Maske (FACH-20): „Fassung aktivieren“ legt die
|
||||||
|
* nächste, danach unveränderliche Angebotsfassung an; bei einer Änderung ist die Maske mit der aktiven Fassung
|
||||||
|
* vorbelegt (FACH-08). Die Wirkung bleibt die bestehende von OfferService::activate.
|
||||||
|
*/
|
||||||
class ViewOffer extends ViewRecord
|
class ViewOffer extends ViewRecord
|
||||||
{
|
{
|
||||||
use ReportsDomainRules;
|
use ReportsDomainRules;
|
||||||
|
|
||||||
protected static string $resource = OfferResource::class;
|
protected static string $resource = OfferResource::class;
|
||||||
|
|
||||||
|
public function getTitle(): string|Htmlable
|
||||||
|
{
|
||||||
|
return (string) $this->getRecord()->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHeading(): string|Htmlable
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMaxContentWidth(): Width|string|null
|
||||||
|
{
|
||||||
|
return Width::Full;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [];
|
||||||
Action::make('activate')->label('Fassung aktivieren')->schema([
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Der gemeinsame Objektkopf zeigt den Pfad; Filaments eigener Pfad entfällt wie bei Medien und Aufbau.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function getBreadcrumbs(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function infolist(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema->components([
|
||||||
|
View::make('filament.catalog.objekt')->viewData(fn (): array => $this->angebotDaten())->columnSpanFull(),
|
||||||
|
])->columns(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function activeVersion(): ?OfferVersion
|
||||||
|
{
|
||||||
|
/** @var Offer $offer */
|
||||||
|
$offer = $this->getRecord();
|
||||||
|
|
||||||
|
return $offer->versions()
|
||||||
|
->where('status', OfferStatus::Aktiv)
|
||||||
|
->orderByDesc('number')
|
||||||
|
->with(['lines.article', 'lines.bundleVersion.bundle', 'lines.rights.profile'])
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function activateAction(): Action
|
||||||
|
{
|
||||||
|
return Action::make('activate')
|
||||||
|
->label(fn (): string => $this->activeVersion() !== null ? 'Geänderte Fassung aktivieren' : 'Fassung aktivieren')
|
||||||
|
->modalHeading(fn (): string => $this->activeVersion() !== null
|
||||||
|
? 'Option „'.$this->getRecord()->optionName().'“ ändern: Fassung '.$this->nextNumber().' aktivieren'
|
||||||
|
: 'Option „'.$this->getRecord()->optionName().'“: erste Fassung aktivieren')
|
||||||
|
->modalDescription(fn (): string => ($active = $this->activeVersion()) !== null
|
||||||
|
? 'Betroffen ist nur die Option „'.$this->getRecord()->optionName().'“'.$this->productPageSuffix().'. Die Maske ist mit Fassung '.$active->number.' vorbelegt. Erst „Fassung '.$this->nextNumber().' aktivieren“ schaltet die Änderung öffentlich (auch Bezeichnung und Produktseite, sie erzeugen ebenfalls eine neue Fassung und zeigen offenen Warenkörben „Bedingungen aktualisiert“): Fassung '.$active->number.' wird beendet und bleibt gespeichert, neue Käufe nutzen Fassung '.$this->nextNumber().'. Bereits begründete Berechtigungen und Bestellungen ändern sich nicht. Andere Optionen derselben Produktseite bleiben unverändert kaufbar. „Abbrechen“ verwirft die Eingaben.'
|
||||||
|
: 'Positionen, Vergabe, Eignung und Preis bilden die erste Fassung dieser Option. Erst das Aktivieren macht sie öffentlich; danach ist sie unveränderlich, Änderungen ergeben eine weitere Fassung.')
|
||||||
|
->modalSubmitActionLabel(fn (): string => 'Fassung '.$this->nextNumber().' aktivieren')
|
||||||
|
->modalWidth('4xl')
|
||||||
|
->fillForm(fn (): array => $this->formFromActive())
|
||||||
|
->schema([
|
||||||
|
TextInput::make('option_label')->label('Bezeichnung der Option')
|
||||||
|
->helperText('So heißt die Option auf der Produktseite, zum Beispiel „Einzellizenz für Privatpersonen“. Sie ist keine bindende Bedingung, wird aber wie die übrigen Angaben erst mit „Fassung aktivieren“ übernommen.')
|
||||||
|
->maxLength(120),
|
||||||
|
Select::make('composition_id')->label('Produktseite')
|
||||||
|
->options(fn (): array => $this->productPages())
|
||||||
|
->searchable()
|
||||||
|
->helperText('Optionen derselben Produktseite sind Alternativen; im Warenkorb liegt nur eine davon. Die Beschreibung der Seite wird zentral an der Komposition gepflegt. Die Zuordnung wird mit „Fassung aktivieren“ übernommen.'),
|
||||||
|
Select::make('holder_kind')->label('Geeignet für')->options([
|
||||||
|
'person' => 'Privatpersonen',
|
||||||
|
'organisation' => 'Organisationen und Vereine',
|
||||||
|
])->required()
|
||||||
|
->helperText('Wähle die Eignung passend zu den Rechten: Organisationslizenzen brauchen institutionelle Rechte. Das System erzwingt diese Kopplung nicht.'),
|
||||||
Select::make('grant_kind')->label('Vergabe')->options([
|
Select::make('grant_kind')->label('Vergabe')->options([
|
||||||
'kauf' => 'Kauf',
|
'kauf' => 'Kauf',
|
||||||
'auf_abruf' => 'Auf Abruf',
|
'auf_abruf' => 'Auf Abruf',
|
||||||
'bei_registrierung' => 'Bei Registrierung',
|
'bei_registrierung' => 'Bei Registrierung',
|
||||||
])->required(),
|
])->required(),
|
||||||
TextInput::make('price_cents')->label('Preis in Cent')->numeric()
|
TextInput::make('price_euro')->label('Preis in Euro')->suffix('€')
|
||||||
->helperText('Nur bei einem Kauf. 500 bedeutet 5,00 €.'),
|
->helperText('Nur bei einem Kauf, zum Beispiel 49,00.'),
|
||||||
Select::make('composition_version_id')->label('Programmfassung, die abgedeckt sein muss')
|
Select::make('composition_version_id')->label('Programmfassung, die abgedeckt sein muss')
|
||||||
->options(function (): array {
|
->options(function (): array {
|
||||||
return CompositionVersion::query()
|
return CompositionVersion::query()
|
||||||
@@ -52,14 +144,18 @@ protected function getHeaderActions(): array
|
|||||||
'article' => 'Lizenzartikel',
|
'article' => 'Lizenzartikel',
|
||||||
'bundle' => 'Paketfassung',
|
'bundle' => 'Paketfassung',
|
||||||
])->required()->live(),
|
])->required()->live(),
|
||||||
Select::make('article_id')->label('Artikel')->options(fn (): array => CatalogOptions::articles())
|
Select::make('article_id')->label('Artikel')->options(fn (): array => app(PublicationReadiness::class)->articleOptions())
|
||||||
|
->searchable()
|
||||||
|
->helperText('Nur Artikel mit veröffentlichtem Stand lassen sich verkaufen. Artikel ohne Stand sind gekennzeichnet.')
|
||||||
->visible(fn (Get $get): bool => $get('kind') === 'article'),
|
->visible(fn (Get $get): bool => $get('kind') === 'article'),
|
||||||
Select::make('bundle_version_id')->label('Paketfassung')->options(fn (): array => CatalogOptions::bundleVersions())
|
Select::make('bundle_version_id')->label('Paketfassung')->options(fn (): array => app(PublicationReadiness::class)->bundleVersionOptions())
|
||||||
|
->searchable()
|
||||||
->visible(fn (Get $get): bool => $get('kind') === 'bundle'),
|
->visible(fn (Get $get): bool => $get('kind') === 'bundle'),
|
||||||
Select::make('rights_id')->label('Rechte')->options(fn (): array => CatalogOptions::rights())->required(),
|
Select::make('rights_id')->label('Rechte')->options(fn (): array => CatalogOptions::rights())->required(),
|
||||||
])->minItems(1),
|
])->minItems(1)->addActionLabel('Position hinzufügen'),
|
||||||
])->action(function (array $data): void {
|
])
|
||||||
$this->report(function () use ($data): void {
|
->action(function (array $data): void {
|
||||||
|
$this->report(function () use ($data): string {
|
||||||
/** @var Offer $offer */
|
/** @var Offer $offer */
|
||||||
$offer = $this->getRecord();
|
$offer = $this->getRecord();
|
||||||
$lines = [];
|
$lines = [];
|
||||||
@@ -74,16 +170,270 @@ protected function getHeaderActions(): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
app(OfferService::class)->activate($offer, $lines, [
|
// Voraussetzung: Jeder Artikel der Positionen hat einen veröffentlichten Stand, sonst erhielten Käufer nichts.
|
||||||
'grant_kind' => $data['grant_kind'],
|
$articleIds = [];
|
||||||
'price_cents' => $data['price_cents'] === null || $data['price_cents'] === '' ? null : (int) $data['price_cents'],
|
|
||||||
'holder_kind' => 'person',
|
foreach ($lines as $line) {
|
||||||
'composition_version_id' => filled($data['composition_version_id'] ?? null) ? (int) $data['composition_version_id'] : null,
|
$target = $line['target'];
|
||||||
]);
|
array_push($articleIds, ...($target instanceof BundleVersion ? app(BundleService::class)->articleIds($target) : [$target->id]));
|
||||||
|
}
|
||||||
|
|
||||||
|
$unusable = app(PublicationReadiness::class)->unusableArticles($articleIds);
|
||||||
|
|
||||||
|
if ($unusable !== []) {
|
||||||
|
throw new DomainRuleException(app(PublicationReadiness::class)->unusableMessage($unusable, 'das Angebot aktivierst'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bedingungen, die die Maske nicht zeigt, bleiben bei einer Änderung die der aktiven Fassung.
|
||||||
|
$active = $this->activeVersion();
|
||||||
|
$kept = $active === null ? [] : [
|
||||||
|
'term_rule' => $active->term_rule,
|
||||||
|
'tax_class' => $active->tax_class,
|
||||||
|
'dynamic' => (bool) $active->dynamic,
|
||||||
|
];
|
||||||
|
$price = Money::parse($data['price_euro'] ?? null);
|
||||||
|
|
||||||
|
if ($data['grant_kind'] === 'kauf' && ($price === null || $price <= 0)) {
|
||||||
|
throw new DomainRuleException('Ein Kauf braucht einen Preis über 0,00 €.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$service = app(OfferService::class);
|
||||||
|
$version = DB::transaction(function () use ($service, $offer, $data, $lines, $kept, $price) {
|
||||||
|
$service->assignProduct(
|
||||||
|
$offer,
|
||||||
|
filled($data['composition_id'] ?? null) ? (int) $data['composition_id'] : null,
|
||||||
|
$data['option_label'] ?? null,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $service->activate($offer, $lines, [
|
||||||
|
...$kept,
|
||||||
|
'holder_kind' => $data['holder_kind'],
|
||||||
|
'grant_kind' => $data['grant_kind'],
|
||||||
|
'price_cents' => $price,
|
||||||
|
'composition_version_id' => filled($data['composition_version_id'] ?? null) ? (int) $data['composition_version_id'] : null,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
$offer->unsetRelations();
|
||||||
|
$readiness = app(PublicationReadiness::class)->forOffer($offer->refresh());
|
||||||
|
|
||||||
|
return 'Fassung '.$version->number.' ist aktiv.'.($readiness['bereit']
|
||||||
|
? ' Die Option ist öffentlich kaufbar und im Shop auffindbar.'
|
||||||
|
: ' Noch nicht im Shop kaufbar. Nächster Schritt: '.$readiness['naechster']['titel'].'.');
|
||||||
}, 'Die Angebotsfassung ist aktiv.');
|
}, 'Die Angebotsfassung ist aktiv.');
|
||||||
$this->getRecord()->unsetRelations();
|
$this->getRecord()->unsetRelations();
|
||||||
$this->getRecord()->refresh();
|
$this->getRecord()->refresh();
|
||||||
}),
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Option aus dem Verkauf nehmen: nur die aktive Fassung dieser Option wird beendet.
|
||||||
|
*/
|
||||||
|
public function endAction(): Action
|
||||||
|
{
|
||||||
|
return Action::make('end')
|
||||||
|
->label('Aus dem Verkauf nehmen')
|
||||||
|
->color('danger')
|
||||||
|
->requiresConfirmation()
|
||||||
|
->modalHeading(fn (): string => 'Option „'.$this->getRecord()->optionName().'“ aus dem Verkauf nehmen?')
|
||||||
|
->modalDescription(fn (): string => 'Betroffen ist nur die Option „'.$this->getRecord()->optionName().'“'.$this->productPageSuffix().'. Die aktive Fassung wird beendet und bleibt gespeichert. Die Option ist danach nicht mehr kaufbar; in vorhandenen Warenkörben bleibt sie mit Hinweis sichtbar und blockiert den Abschluss, bis der Käufer sie entfernt. Bestehende Berechtigungen und Bestellungen ändern sich nicht. Andere Optionen derselben Produktseite bleiben kaufbar.')
|
||||||
|
->modalSubmitActionLabel('Aus dem Verkauf nehmen')
|
||||||
|
->visible(fn (): bool => $this->activeVersion() !== null)
|
||||||
|
->action(function (): void {
|
||||||
|
$this->report(function (): string {
|
||||||
|
$version = app(OfferService::class)->end($this->getRecord());
|
||||||
|
|
||||||
|
return 'Fassung '.$version->number.' ist beendet. Die Option ist nicht mehr kaufbar.';
|
||||||
|
}, 'Die Option ist aus dem Verkauf genommen.');
|
||||||
|
$this->getRecord()->unsetRelations();
|
||||||
|
$this->getRecord()->refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** „ der Produktseite „Titel““ oder leer, wenn die Option noch keiner Produktseite zugeordnet ist. */
|
||||||
|
private function productPageSuffix(): string
|
||||||
|
{
|
||||||
|
$page = $this->getRecord()->composition;
|
||||||
|
|
||||||
|
return $page === null ? '' : ' der Produktseite „'.($page->display_title ?: $page->designation).'“';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produktseiten, die als Ziel wählbar sind: Kompositionen mit Bezeichnung und Art.
|
||||||
|
*
|
||||||
|
* @return array<int, string>
|
||||||
|
*/
|
||||||
|
private function productPages(): array
|
||||||
|
{
|
||||||
|
$catalog = app(PublicCatalogReader::class);
|
||||||
|
|
||||||
|
return Composition::query()
|
||||||
|
->with('editorialContentKind')
|
||||||
|
->whereNull('archived_at')
|
||||||
|
->orderBy('designation')
|
||||||
|
->get()
|
||||||
|
->sortBy(fn (Composition $composition): int => $catalog->shownVersion($composition) !== null ? 0 : 1)
|
||||||
|
->mapWithKeys(fn (Composition $composition): array => [
|
||||||
|
$composition->id => ($composition->display_title ?: $composition->designation)
|
||||||
|
.' ('.($composition->editorialContentKind?->label ?? 'Zusammenstellung').')'
|
||||||
|
.($catalog->shownVersion($composition) !== null ? ' · im Shop auffindbar' : ' · nicht öffentlich, im Shop nicht auffindbar'),
|
||||||
|
])
|
||||||
|
->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vorbelegung aus der aktiven Fassung; ohne aktive Fassung eine leere Position.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
private function formFromActive(): array
|
||||||
|
{
|
||||||
|
$active = $this->activeVersion();
|
||||||
|
/** @var Offer $offer */
|
||||||
|
$offer = $this->getRecord();
|
||||||
|
$option = ['option_label' => $offer->option_label, 'composition_id' => $offer->composition_id];
|
||||||
|
|
||||||
|
if ($active === null) {
|
||||||
|
return [...$option, 'holder_kind' => 'person', 'grant_kind' => 'kauf', 'lines' => [['kind' => 'article']]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
...$option,
|
||||||
|
'holder_kind' => $active->holder_kind,
|
||||||
|
'grant_kind' => $active->grant_kind,
|
||||||
|
'price_euro' => $active->price_cents === null ? null : number_format($active->price_cents / 100, 2, ',', ''),
|
||||||
|
'lines' => $active->lines->sortBy('position')->map(fn ($line): array => [
|
||||||
|
'kind' => $line->license_article_id !== null ? 'article' : 'bundle',
|
||||||
|
'article_id' => $line->license_article_id,
|
||||||
|
'bundle_version_id' => $line->bundle_version_id,
|
||||||
|
'rights_id' => $line->rights_profile_version_id,
|
||||||
|
])->values()->all(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function nextNumber(): int
|
||||||
|
{
|
||||||
|
return ((int) $this->getRecord()->versions()->max('number')) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daten der gemeinsamen Katalog-Objektseite.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
private function angebotDaten(): array
|
||||||
|
{
|
||||||
|
/** @var Offer $offer */
|
||||||
|
$offer = $this->getRecord();
|
||||||
|
$active = $this->activeVersion();
|
||||||
|
$vergabe = $active !== null ? CatalogLabels::vergabe($active) : null;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'kopf' => [
|
||||||
|
'brot' => [['label' => 'Angebote', 'href' => OfferResource::getUrl('index')], $offer->name],
|
||||||
|
'titel' => $offer->name,
|
||||||
|
'typ' => 'Angebot',
|
||||||
|
'status' => $active !== null
|
||||||
|
? ['text' => 'Fassung '.$active->number.' aktiv · '.$vergabe, 'ton' => 'gut']
|
||||||
|
: ['text' => 'Noch keine aktive Fassung. Ein Angebot ohne aktive Fassung kann niemand erwerben.', 'ton' => 'offen'],
|
||||||
|
'aktionen' => [
|
||||||
|
[
|
||||||
|
'label' => $active !== null ? 'Geänderte Fassung aktivieren' : 'Fassung aktivieren',
|
||||||
|
'wire' => "mountAction('activate')",
|
||||||
|
'art' => 'primary',
|
||||||
|
],
|
||||||
|
...($active !== null ? [[
|
||||||
|
'label' => 'Aus dem Verkauf nehmen',
|
||||||
|
'wire' => "mountAction('end')",
|
||||||
|
'art' => 'line',
|
||||||
|
]] : []),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'voraussetzungen' => app(PublicationReadiness::class)->forOffer($offer),
|
||||||
|
'haupt' => [
|
||||||
|
...($active !== null ? [$this->optionAbschnitt($offer, $active)] : []),
|
||||||
|
[
|
||||||
|
'titel' => 'Positionen',
|
||||||
|
'zusatz' => $active !== null ? 'Fassung '.$active->number : null,
|
||||||
|
'hilfe' => $active !== null ? 'Vergabe: '.$vergabe.'. Diese Fassung ist unveränderlich; eine Änderung aktiviert die nächste Fassung.' : null,
|
||||||
|
'zeilen' => $active === null ? [] : $active->lines->sortBy('position')->map(fn ($line): array => [
|
||||||
|
'text' => $line->article !== null ? 'Lizenzartikel '.$line->article->code : 'Paket '.($line->bundleVersion?->bundle?->name ?? '–').' · Fassung '.($line->bundleVersion?->number ?? '–'),
|
||||||
|
'neben' => 'Rechte: '.($line->rights?->profile?->name ?? '–'),
|
||||||
|
])->values()->all(),
|
||||||
|
'leer' => ['titel' => 'Noch keine Positionen', 'text' => 'Mit „Fassung aktivieren“ legst du fest, welche Lizenzartikel oder Paketfassungen mit welchem Rechteprofil angeboten werden, wie vergeben wird und zu welchem Preis.'],
|
||||||
|
],
|
||||||
|
...($active !== null ? [[
|
||||||
|
'titel' => 'Aufgelöster Leistungsumfang',
|
||||||
|
'hilfe' => 'Diese Artikel-Rechte entstehen beim Erwerb dieser Fassung.',
|
||||||
|
'zeilen' => $this->leistungsumfang($active),
|
||||||
|
'leer' => ['titel' => 'Kein Leistungsumfang', 'text' => 'Diese Fassung hat keinen aufgelösten Leistungsumfang.'],
|
||||||
|
]] : []),
|
||||||
|
],
|
||||||
|
'seite' => [[
|
||||||
|
'titel' => 'Fassungen',
|
||||||
|
'zeilen' => $offer->versions()->orderByDesc('number')->get()->map(fn (OfferVersion $version): array => [
|
||||||
|
'text' => 'Fassung '.$version->number,
|
||||||
|
'zustand' => match (StatusValue::of($version->status)) {
|
||||||
|
'aktiv' => ['label' => 'Aktiv', 'ton' => 'gut'],
|
||||||
|
'beendet' => ['label' => 'Beendet', 'ton' => 'leise'],
|
||||||
|
default => ['label' => 'Entwurf', 'ton' => 'offen'],
|
||||||
|
},
|
||||||
|
'neben' => CatalogLabels::vergabe($version).($version->activated_at ? ' · aktiviert am '.$version->activated_at->format('d.m.Y') : ''),
|
||||||
|
])->all(),
|
||||||
|
'leer' => 'Noch keine Fassung.',
|
||||||
|
'hilfe' => 'Beendete Fassungen bleiben gespeichert; Erwerbe verweisen auf ihre Fassung. Ob ein Angebot künftig auch als Vorlage für ein weiteres dienen soll, ist fachlich noch offen (OFF-04).',
|
||||||
|
]],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Option auf einen Blick: Preis in Euro, Eignung, Rechte, zugrunde liegender Inhalt, Status und Produktseite.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
private function optionAbschnitt(Offer $offer, OfferVersion $active): array
|
||||||
|
{
|
||||||
|
$option = app(ProductOptions::class)->describe($offer, $active);
|
||||||
|
$inhalt = collect($option['scope'])->pluck('article')->unique()->implode(', ');
|
||||||
|
$rechte = collect($option['scope'])
|
||||||
|
->map(fn (array $item): string => $item['purpose'].($item['rights'] === [] ? '' : ': '.implode(', ', $item['rights'])))
|
||||||
|
->unique()
|
||||||
|
->implode('; ');
|
||||||
|
$seite = $offer->composition;
|
||||||
|
$kaufbar = app(OfferService::class)->purchasableVersion($offer) !== null;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'titel' => 'Die Option auf einen Blick',
|
||||||
|
'zusatz' => 'Fassung '.$active->number,
|
||||||
|
'hilfe' => 'So erscheint die Option auf der öffentlichen Produktseite und im Warenkorb. Die Angaben dieser Fassung sind unveränderlich.',
|
||||||
|
'zeilen' => [
|
||||||
|
['text' => 'Preis: '.$option['price'], 'neben' => $active->grant_kind === 'kauf' ? 'Kauf mit Testzahlung' : CatalogLabels::vergabe($active)],
|
||||||
|
['text' => 'Geeignet für: '.$option['for'], 'neben' => $option['term']],
|
||||||
|
['text' => 'Rechte: '.($rechte !== '' ? $rechte : 'keine'), 'neben' => null],
|
||||||
|
['text' => 'Zugrunde liegender Inhalt: '.($inhalt !== '' ? $inhalt : '–'), 'neben' => null],
|
||||||
|
['text' => 'Status: '.($kaufbar ? 'Öffentlich kaufbar' : 'Nicht als Kauf angeboten'), 'neben' => $kaufbar ? 'Aktive Fassung '.$active->number : null],
|
||||||
|
['text' => 'Produktseite: '.($seite !== null ? ($seite->display_title ?: $seite->designation) : 'noch nicht zugeordnet'), 'neben' => $seite !== null ? 'Option „'.$offer->optionName().'“' : 'Mit „Geänderte Fassung aktivieren“ zuordnen.'],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aufgelöster Leistungsumfang in lesbaren Fähigkeiten (dieselben Bezeichnungen wie beim Rechteprofil).
|
||||||
|
*
|
||||||
|
* @return list<array{text: string, neben: string}>
|
||||||
|
*/
|
||||||
|
private function leistungsumfang(OfferVersion $version): array
|
||||||
|
{
|
||||||
|
$zeilen = [];
|
||||||
|
|
||||||
|
foreach ($version->resolvedScopes()->with(['article', 'rights.profile'])->get() as $scope) {
|
||||||
|
$faehigkeiten = CatalogLabels::faehigkeiten($scope->rights?->capabilities);
|
||||||
|
$zeilen[] = [
|
||||||
|
'text' => 'Lizenzartikel '.$scope->article?->code,
|
||||||
|
'neben' => ($scope->rights?->profile?->name ?? '–').': '.($faehigkeiten === [] ? 'keine Fähigkeiten' : implode(', ', $faehigkeiten)),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $zeilen;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,9 @@ class PageResource extends Resource
|
|||||||
|
|
||||||
protected static ?string $navigationLabel = 'Seiten';
|
protected static ?string $navigationLabel = 'Seiten';
|
||||||
|
|
||||||
|
/** Der Seitenbestand steht in der Webpräsenz; Anlegen und Bearbeiten bleiben hier. */
|
||||||
|
protected static bool $shouldRegisterNavigation = false;
|
||||||
|
|
||||||
protected static ?string $modelLabel = 'Seite';
|
protected static ?string $modelLabel = 'Seite';
|
||||||
|
|
||||||
protected static ?string $pluralModelLabel = 'Seiten';
|
protected static ?string $pluralModelLabel = 'Seiten';
|
||||||
@@ -38,11 +41,9 @@ public static function form(Schema $schema): Schema
|
|||||||
return $schema->components([
|
return $schema->components([
|
||||||
Section::make('Seite und Suchmaschinen')
|
Section::make('Seite und Suchmaschinen')
|
||||||
->description('Adresse, Titel für Suchmaschinen und Zuordnung zu Themenbereichen.')
|
->description('Adresse, Titel für Suchmaschinen und Zuordnung zu Themenbereichen.')
|
||||||
->collapsible()
|
|
||||||
->collapsed(fn (string $operation): bool => $operation === 'edit')
|
|
||||||
->persistCollapsed()
|
|
||||||
->columns(2)
|
->columns(2)
|
||||||
->columnSpanFull()
|
->columnSpanFull()
|
||||||
|
->extraAttributes(fn ($livewire): array => ['class' => self::registerClass($livewire, 'einstellungen')])
|
||||||
->schema([
|
->schema([
|
||||||
TextInput::make('path')
|
TextInput::make('path')
|
||||||
->label('Pfad')
|
->label('Pfad')
|
||||||
@@ -63,25 +64,43 @@ public static function form(Schema $schema): Schema
|
|||||||
->columns(['default' => 1, 'lg' => 2]),
|
->columns(['default' => 1, 'lg' => 2]),
|
||||||
]),
|
]),
|
||||||
Section::make('Inhalt der Seite')
|
Section::make('Inhalt der Seite')
|
||||||
->description('Abschnitt hinzufügen, Raster wählen, Widgets in die Plätze einsetzen. Ein Klick auf die Vorschau eines Widgets öffnet seinen Dialog; Hintergrund, Breite, Abstand und Trenner stehen unter „Gestaltung des Abschnitts“. Speichern legt einen Entwurf an; veröffentlicht wird erst über „Veröffentlichen“.')
|
->description(fn ($livewire): string => is_object($livewire) && method_exists($livewire, 'openAbschnitt')
|
||||||
|
? 'Seitenaufbau: Plätze und Bausteine im Rasterverhältnis der Website. „Abschnitt gestalten“ öffnet Raster, Breite, Hintergrund, Abstände und Trenner; ein Klick auf einen Baustein öffnet seine Konfiguration. Gesichert wird mit „Entwurf speichern“, veröffentlicht erst über „Veröffentlichen …“.'
|
||||||
|
: 'Abschnitt hinzufügen, Raster wählen, Widgets in die Plätze einsetzen. Ein Klick auf die Vorschau eines Widgets öffnet seinen Dialog; Hintergrund, Breite, Abstand und Trenner stehen unter „Gestaltung des Abschnitts“. Speichern legt einen Entwurf an; veröffentlicht wird erst über „Veröffentlichen“.')
|
||||||
->columnSpanFull()
|
->columnSpanFull()
|
||||||
->extraAttributes(['class' => 'luf-page-content'])
|
->extraAttributes(fn ($livewire): array => ['class' => 'luf-page-content '.self::registerClass($livewire, 'inhalt')])
|
||||||
->schema([
|
->schema([
|
||||||
SectionEditor::repeater('sections'),
|
SectionEditor::repeater('sections'),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Im Seiten-Arbeitsplatz (EditPage) zeigt jedes Register nur seinen Teil; ausgeblendete Felder bleiben im
|
||||||
|
* Formularzustand und werden mitgespeichert. Beim Anlegen ist alles sichtbar.
|
||||||
|
*/
|
||||||
|
public static function registerClass(mixed $livewire, string $register): string
|
||||||
|
{
|
||||||
|
return is_object($livewire) && property_exists($livewire, 'register') && $livewire->register !== $register ? 'vw-ausgeblendet' : '';
|
||||||
|
}
|
||||||
|
|
||||||
public static function table(Table $table): Table
|
public static function table(Table $table): Table
|
||||||
{
|
{
|
||||||
return $table
|
return $table
|
||||||
|
// Zuletzt bearbeitete Seiten zuerst; jede Seite ist ohne Suche auffindbar (Spalten sortierbar, bis 100 je Seite).
|
||||||
->columns([
|
->columns([
|
||||||
TextColumn::make('path')->label('Pfad')->searchable(),
|
TextColumn::make('path')->label('Pfad')->searchable()->sortable(),
|
||||||
TextColumn::make('published_revision_id')
|
TextColumn::make('published_revision_id')
|
||||||
->label('Veröffentlicht')
|
->label('Veröffentlicht')
|
||||||
->formatStateUsing(fn ($state): string => $state ? 'Ja' : 'Entwurf'),
|
->formatStateUsing(fn ($state): string => $state ? 'Ja' : 'Entwurf'),
|
||||||
TextColumn::make('updated_at')->label('Geändert')->dateTime('d.m.Y H:i'),
|
TextColumn::make('updated_at')
|
||||||
|
->label('Zuletzt bearbeitet')
|
||||||
|
->dateTime('d.m.Y H:i', timezone: 'Europe/Berlin')
|
||||||
|
->sortable(),
|
||||||
])
|
])
|
||||||
|
->defaultSort('updated_at', 'desc')
|
||||||
|
->paginated([25, 50, 100])
|
||||||
|
->defaultPaginationPageOption(25)
|
||||||
->recordUrl(fn (Page $record): string => static::getUrl('edit', ['record' => $record]))
|
->recordUrl(fn (Page $record): string => static::getUrl('edit', ['record' => $record]))
|
||||||
->recordActions([
|
->recordActions([
|
||||||
Action::make('duplicate')
|
Action::make('duplicate')
|
||||||
|
|||||||
@@ -6,16 +6,19 @@
|
|||||||
use App\Domain\Cms\Page;
|
use App\Domain\Cms\Page;
|
||||||
use App\Domain\Cms\PageService;
|
use App\Domain\Cms\PageService;
|
||||||
use App\Filament\Resources\Pages\PageResource;
|
use App\Filament\Resources\Pages\PageResource;
|
||||||
|
use App\Filament\Support\ChoosesWebsiteImages;
|
||||||
use App\Filament\Support\ReportsSectionErrors;
|
use App\Filament\Support\ReportsSectionErrors;
|
||||||
use App\Filament\Support\SectionEditor;
|
use App\Filament\Support\SectionEditor;
|
||||||
use Filament\Resources\Pages\CreateRecord;
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
use Filament\Support\Enums\Width;
|
use Filament\Support\Enums\Width;
|
||||||
|
use Illuminate\Contracts\View\View;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class CreatePage extends CreateRecord
|
class CreatePage extends CreateRecord
|
||||||
{
|
{
|
||||||
|
use ChoosesWebsiteImages;
|
||||||
use ReportsSectionErrors;
|
use ReportsSectionErrors;
|
||||||
|
|
||||||
protected static string $resource = PageResource::class;
|
protected static string $resource = PageResource::class;
|
||||||
@@ -28,6 +31,12 @@ class CreatePage extends CreateRecord
|
|||||||
|
|
||||||
protected static bool $canCreateAnother = false;
|
protected static bool $canCreateAnother = false;
|
||||||
|
|
||||||
|
/** Gemeinsamer Bild-Picker über dem Formular und dem Bausteindialog. */
|
||||||
|
public function getFooter(): ?View
|
||||||
|
{
|
||||||
|
return view('filament.cms.bild-picker');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, mixed> $data
|
* @param array<string, mixed> $data
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -6,17 +6,23 @@
|
|||||||
use App\Domain\Cms\Page;
|
use App\Domain\Cms\Page;
|
||||||
use App\Domain\Cms\PageService;
|
use App\Domain\Cms\PageService;
|
||||||
use App\Filament\Resources\Pages\PageResource;
|
use App\Filament\Resources\Pages\PageResource;
|
||||||
|
use App\Filament\Support\ChoosesWebsiteImages;
|
||||||
use App\Filament\Support\ReportsSectionErrors;
|
use App\Filament\Support\ReportsSectionErrors;
|
||||||
use App\Filament\Support\SectionEditor;
|
use App\Filament\Support\SectionEditor;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Resources\Pages\EditRecord;
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
use Filament\Schemas\Components\Group;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
use Filament\Support\Enums\Width;
|
use Filament\Support\Enums\Width;
|
||||||
|
use Illuminate\Contracts\View\View;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Livewire\Attributes\Url;
|
||||||
|
|
||||||
class EditPage extends EditRecord
|
class EditPage extends EditRecord
|
||||||
{
|
{
|
||||||
|
use ChoosesWebsiteImages;
|
||||||
use ReportsSectionErrors;
|
use ReportsSectionErrors;
|
||||||
|
|
||||||
protected static string $resource = PageResource::class;
|
protected static string $resource = PageResource::class;
|
||||||
@@ -27,50 +33,234 @@ class EditPage extends EditRecord
|
|||||||
/** Warnt vor dem Verlassen oder Neuladen, wenn Änderungen noch nicht gespeichert sind. */
|
/** Warnt vor dem Verlassen oder Neuladen, wenn Änderungen noch nicht gespeichert sind. */
|
||||||
protected ?bool $hasUnsavedDataChangesAlert = true;
|
protected ?bool $hasUnsavedDataChangesAlert = true;
|
||||||
|
|
||||||
|
/** Register des Seiten-Arbeitsplatzes: inhalt, einstellungen, verlauf (Dokument 12, CMS-R01). */
|
||||||
|
#[Url(as: 'bereich', except: 'inhalt')]
|
||||||
|
public string $register = 'inhalt';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kontext „Abschnitt gestalten“: Position des Abschnitts (die Repeater-Schlüssel wechseln beim Speichern,
|
||||||
|
* die Reihenfolge nicht). null ist der Seitenaufbau.
|
||||||
|
*/
|
||||||
|
#[Url(as: 'abschnitt', except: null)]
|
||||||
|
public ?int $abschnitt = null;
|
||||||
|
|
||||||
|
/** Fingerabdruck des zuletzt geladenen oder gespeicherten Stands; Grundlage für „nicht gespeichert“. */
|
||||||
|
public string $gespeicherterStand = '';
|
||||||
|
|
||||||
|
public function showRegister(string $register): void
|
||||||
|
{
|
||||||
|
$this->register = in_array($register, ['inhalt', 'einstellungen', 'verlauf'], true) ? $register : 'inhalt';
|
||||||
|
$this->abschnitt = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function openAbschnitt(string $key): void
|
||||||
|
{
|
||||||
|
$index = array_search($key, array_map('strval', array_keys($this->data['sections'] ?? [])), true);
|
||||||
|
|
||||||
|
if ($index === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->register = 'inhalt';
|
||||||
|
$this->abschnitt = (int) $index;
|
||||||
|
$this->js('window.scrollTo({ top: 0 })');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zurück zum Seitenaufbau, an die Stelle des gestalteten Abschnitts (Fokus auf „Abschnitt gestalten“).
|
||||||
|
*/
|
||||||
|
public function closeAbschnitt(): void
|
||||||
|
{
|
||||||
|
$key = $this->abschnittSchluessel();
|
||||||
|
$this->abschnitt = null;
|
||||||
|
|
||||||
|
if ($key !== null) {
|
||||||
|
$selector = json_encode('.luf-sections [x-sortable-item="'.$key.'"]');
|
||||||
|
$this->js("requestAnimationFrame(() => requestAnimationFrame(() => { const el = document.querySelector($selector); if (! el) return; window.scrollTo({ top: el.getBoundingClientRect().top + window.scrollY - 96 }); [...el.querySelectorAll('button')].find((b) => b.textContent.includes('Abschnitt gestalten'))?.focus({ preventScroll: true }); }))");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repeater-Schlüssel des gestalteten Abschnitts, aufgelöst zur Laufzeit.
|
||||||
|
*/
|
||||||
|
public function abschnittSchluessel(): ?string
|
||||||
|
{
|
||||||
|
if ($this->abschnitt === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$keys = array_map('strval', array_keys($this->data['sections'] ?? []));
|
||||||
|
|
||||||
|
return $keys[$this->abschnitt] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gemeinsamer Objektkopf statt Filaments Titel, Pfad und Kopfaktionen.
|
||||||
|
*/
|
||||||
|
public function getHeader(): ?View
|
||||||
|
{
|
||||||
|
return view('filament.cms.seite-kopf', ['seite' => $this->record, 'ungespeichert' => $this->hasUnsavedEditorChanges()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Weicht der Editorstand vom geladenen oder gespeicherten Stand ab? Verglichen wird derselbe normalisierte
|
||||||
|
* Zustand, der auch gespeichert würde; Vorschaubreiten zählen nicht.
|
||||||
|
*/
|
||||||
|
public function hasUnsavedEditorChanges(): bool
|
||||||
|
{
|
||||||
|
return $this->gespeicherterStand !== '' && $this->editorFingerprint() !== $this->gespeicherterStand;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function afterFill(): void
|
||||||
|
{
|
||||||
|
$this->gespeicherterStand = $this->editorFingerprint();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function editorFingerprint(): string
|
||||||
|
{
|
||||||
|
$data = is_array($this->data ?? null) ? $this->data : [];
|
||||||
|
$pillars = array_map('intval', (array) ($data['pillars'] ?? []));
|
||||||
|
sort($pillars);
|
||||||
|
|
||||||
|
return md5(json_encode([
|
||||||
|
self::withoutPreviewKeys(SectionEditor::fromEditorState(is_array($data['sections'] ?? null) ? $data['sections'] : [])),
|
||||||
|
(string) ($data['path'] ?? ''),
|
||||||
|
(string) ($data['seo_title'] ?? ''),
|
||||||
|
(string) ($data['seo_description'] ?? ''),
|
||||||
|
$pillars,
|
||||||
|
], JSON_UNESCAPED_UNICODE) ?: '');
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function withoutPreviewKeys(mixed $value): mixed
|
||||||
|
{
|
||||||
|
if (! is_array($value)) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($value['_preview_width']);
|
||||||
|
|
||||||
|
return array_map(self::withoutPreviewKeys(...), $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formular und Verlauf (Revisionen) als Register; ausgeblendete Teile bleiben im Formularzustand.
|
||||||
|
*/
|
||||||
|
public function content(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema->components([
|
||||||
|
$this->getFormContentComponent(),
|
||||||
|
Group::make([$this->getRelationManagersContentComponent()])
|
||||||
|
->extraAttributes(fn (): array => ['class' => $this->register === 'verlauf' ? '' : 'vw-ausgeblendet']),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Speichern steht im Kopf; die Leiste unter dem Formular entfällt.
|
||||||
|
*/
|
||||||
|
protected function getFormActions(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ein Fehler in einem gerade ausgeblendeten Register oder Abschnittsteil wird sichtbar gemacht (CMS-12).
|
||||||
|
*/
|
||||||
|
public function save(bool $shouldRedirect = true, bool $shouldSendSavedNotification = true): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
parent::save($shouldRedirect, $shouldSendSavedNotification);
|
||||||
|
} catch (ValidationException $exception) {
|
||||||
|
$keys = implode(' ', array_keys($exception->errors()));
|
||||||
|
$this->register = str_contains($keys, 'data.sections') ? 'inhalt' : (preg_match('/data\.(path|seo_|pillars)/', $keys) === 1 ? 'einstellungen' : $this->register);
|
||||||
|
$this->showFailingSection(array_keys($exception->errors()));
|
||||||
|
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Raster und Gestaltung stehen nur im Kontext „Abschnitt gestalten“, andere Abschnitte sind dort ausgeblendet.
|
||||||
|
* Liegt der Fehler im gestalteten Abschnitt, bleibt der Kontext. Ein Raster- oder Gestaltungsfehler öffnet den
|
||||||
|
* betroffenen Abschnitt; jeder andere Abschnittsfehler (etwa die Platzübersicht) steht im Seitenaufbau.
|
||||||
|
*
|
||||||
|
* @param list<string> $errorKeys
|
||||||
|
*/
|
||||||
|
private function showFailingSection(array $errorKeys): void
|
||||||
|
{
|
||||||
|
$sectionKeys = array_map('strval', array_keys($this->data['sections'] ?? []));
|
||||||
|
$failing = [];
|
||||||
|
$design = null;
|
||||||
|
|
||||||
|
foreach ($errorKeys as $key) {
|
||||||
|
if (preg_match('/^data\.sections\.([^.]+)(?:\.(.*))?$/', $key, $match) !== 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$index = array_search($match[1], $sectionKeys, true);
|
||||||
|
if ($index === false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$failing[] = $index;
|
||||||
|
if ($design === null && preg_match('/^(layout|style)(\.|$)/', $match[2] ?? '') === 1) {
|
||||||
|
$design = $index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($failing === [] || ($this->abschnitt !== null && in_array($this->abschnitt, $failing, true))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->abschnitt = $design;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* „Entwurf speichern“ aus dem Bausteindialog: Der Baustein ist bereits übernommen, der Dialog schließt. Ein Fehler
|
||||||
|
* wird wie beim Speichern im Kopf gezeigt (Register, Abschnitt, Meldung), ohne den Baustein erneut zu öffnen.
|
||||||
|
*/
|
||||||
|
public function saveFromBlock(): void
|
||||||
|
{
|
||||||
|
// Nach einer Dialogaktion rendert Filament sonst nur den Dialog neu; der Kopf zeigte den alten Speicherstand.
|
||||||
|
$this->forceRender();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->save(shouldRedirect: false);
|
||||||
|
} catch (ValidationException $exception) {
|
||||||
|
foreach ($exception->errors() as $key => $messages) {
|
||||||
|
foreach ((array) $messages as $message) {
|
||||||
|
$this->addError($key, $message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [];
|
||||||
Action::make('preview')
|
}
|
||||||
->label('Vorschau')
|
|
||||||
->icon('heroicon-o-device-phone-mobile')
|
|
||||||
->color('gray')
|
|
||||||
->tooltip('Zuletzt gespeicherten Entwurf in Smartphone-, Tablet- und Desktopbreite ansehen')
|
|
||||||
->url(function (): string {
|
|
||||||
$revision = $this->record->latestRevision;
|
|
||||||
|
|
||||||
return $revision === null
|
public function publishAction(): Action
|
||||||
? '#'
|
{
|
||||||
: route('pages.preview.devices', $revision);
|
return Action::make('publish')
|
||||||
})
|
->label('Veröffentlichen')
|
||||||
->openUrlInNewTab(),
|
->icon('heroicon-o-globe-alt')
|
||||||
Action::make('publish')
|
->requiresConfirmation()
|
||||||
->label('Veröffentlichen')
|
->modalHeading('Seite veröffentlichen?')
|
||||||
->icon('heroicon-o-globe-alt')
|
->modalDescription('Der aktuelle Stand im Editor wird als Entwurf gespeichert und genau dieser Stand wird veröffentlicht. Enthält er Fehler, wird nichts veröffentlicht.')
|
||||||
->requiresConfirmation()
|
->modalSubmitActionLabel('Speichern und veröffentlichen')
|
||||||
->modalHeading('Seite veröffentlichen?')
|
->visible(fn (): bool => auth()->user()?->can('publish', $this->record) ?? false)
|
||||||
->modalDescription('Der aktuelle Stand im Editor wird als Entwurf gespeichert und genau dieser Stand wird veröffentlicht. Enthält er Fehler, wird nichts veröffentlicht.')
|
->action(function (PageService $service): void {
|
||||||
->modalSubmitActionLabel('Speichern und veröffentlichen')
|
// Ungespeicherte Änderungen (zum Beispiel ein eben gewähltes Bild) gingen sonst beim Veröffentlichen verloren.
|
||||||
->visible(fn (): bool => auth()->user()?->can('publish', $this->record) ?? false)
|
$this->save(shouldRedirect: false, shouldSendSavedNotification: false);
|
||||||
->action(function (PageService $service): void {
|
|
||||||
// Ungespeicherte Änderungen (zum Beispiel ein eben gewähltes Bild) gingen sonst beim Veröffentlichen verloren.
|
|
||||||
$this->save(shouldRedirect: false, shouldSendSavedNotification: false);
|
|
||||||
|
|
||||||
$this->record->unsetRelation('latestRevision');
|
$this->record->unsetRelation('latestRevision');
|
||||||
$revision = $this->record->latestRevision;
|
$revision = $this->record->latestRevision;
|
||||||
abort_if($revision === null, 404);
|
abort_if($revision === null, 404);
|
||||||
$service->publish($this->record, $revision);
|
$service->publish($this->record, $revision);
|
||||||
$this->record->refresh();
|
$this->record->refresh();
|
||||||
|
|
||||||
Notification::make()->title('Seite veröffentlicht')->success()->send();
|
Notification::make()->title('Seite veröffentlicht')->success()->send();
|
||||||
}),
|
});
|
||||||
Action::make('open')
|
|
||||||
->label('Live-Seite')
|
|
||||||
->icon('heroicon-o-arrow-top-right-on-square')
|
|
||||||
->color('gray')
|
|
||||||
->visible(fn (): bool => $this->record->isPublished())
|
|
||||||
->url(fn (): string => $this->record->publicUrl())
|
|
||||||
->openUrlInNewTab(),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getSaveFormAction(): Action
|
protected function getSaveFormAction(): Action
|
||||||
|
|||||||
@@ -2,18 +2,22 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Pages\Pages;
|
namespace App\Filament\Resources\Pages\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Pages\Webpraesenz;
|
||||||
use App\Filament\Resources\Pages\PageResource;
|
use App\Filament\Resources\Pages\PageResource;
|
||||||
use Filament\Actions\CreateAction;
|
|
||||||
use Filament\Resources\Pages\ListRecords;
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Der Seitenbestand steht in der Webpräsenz (Dokument 13). Die bisherige Adresse führt dorthin, nach derselben
|
||||||
|
* Rechteprüfung wie bisher.
|
||||||
|
*/
|
||||||
class ListPages extends ListRecords
|
class ListPages extends ListRecords
|
||||||
{
|
{
|
||||||
protected static string $resource = PageResource::class;
|
protected static string $resource = PageResource::class;
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
public function mount(): void
|
||||||
{
|
{
|
||||||
return [
|
parent::mount();
|
||||||
CreateAction::make(),
|
|
||||||
];
|
$this->redirect(Webpraesenz::getUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,9 @@ class RevisionsRelationManager extends RelationManager
|
|||||||
|
|
||||||
protected static ?string $title = 'Revisionen';
|
protected static ?string $title = 'Revisionen';
|
||||||
|
|
||||||
|
/** Steht im Register „Verlauf“ zunächst ausgeblendet; verzögertes Laden würde dort nie ausgelöst. */
|
||||||
|
protected static ?bool $isLazyLoaded = false;
|
||||||
|
|
||||||
public function table(Table $table): Table
|
public function table(Table $table): Table
|
||||||
{
|
{
|
||||||
return $table
|
return $table
|
||||||
|
|||||||
@@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Pillars\Pages;
|
namespace App\Filament\Resources\Pillars\Pages;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\Pillar;
|
||||||
use App\Domain\Catalog\PillarService;
|
use App\Domain\Catalog\PillarService;
|
||||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
use App\Filament\Resources\Pillars\PillarResource;
|
use App\Filament\Resources\Pillars\PillarResource;
|
||||||
|
use App\Filament\Support\ListsCatalog;
|
||||||
use App\Filament\Support\ReportsDomainRules;
|
use App\Filament\Support\ReportsDomainRules;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
@@ -13,13 +15,14 @@
|
|||||||
|
|
||||||
class ListPillars extends ListRecords
|
class ListPillars extends ListRecords
|
||||||
{
|
{
|
||||||
|
use ListsCatalog;
|
||||||
use ReportsDomainRules;
|
use ReportsDomainRules;
|
||||||
|
|
||||||
protected static string $resource = PillarResource::class;
|
protected static string $resource = PillarResource::class;
|
||||||
|
|
||||||
public function getSubheading(): string|Htmlable|null
|
public function getSubheading(): string|Htmlable|null
|
||||||
{
|
{
|
||||||
return 'Die fachlichen Säulen des Materials. Eine veröffentlichte Säule ist ein Themenbereich der Website. Ein Medium und eine Seite können mehreren Säulen zugeordnet sein.';
|
return 'Die fachlichen Säulen des Materials. Eine veröffentlichte Säule ist ein Themenbereich der Website. Medien, Module, Programme, Lizenzartikel und Seiten können mehreren Säulen zugeordnet sein. Hier ist die einzige Pflegestelle der Säulen.';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
@@ -27,6 +30,9 @@ protected function getHeaderActions(): array
|
|||||||
return [
|
return [
|
||||||
Action::make('create')
|
Action::make('create')
|
||||||
->label('Säule anlegen')
|
->label('Säule anlegen')
|
||||||
|
->modalHeading('Neue fachliche Säule')
|
||||||
|
->modalDescription('Der Name genügt. Website-Text, Adresse und Veröffentlichung legst du danach fest.')
|
||||||
|
->modalSubmitActionLabel('Säule anlegen')
|
||||||
->visible(fn (): bool => ContentElementResource::editor())
|
->visible(fn (): bool => ContentElementResource::editor())
|
||||||
->schema([
|
->schema([
|
||||||
TextInput::make('name')->label('Name')->required(),
|
TextInput::make('name')->label('Name')->required(),
|
||||||
@@ -43,4 +49,62 @@ protected function getHeaderActions(): array
|
|||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zuordnungen aller Objektarten; ohne Zuordnung wie bisher „0 Medien“.
|
||||||
|
*/
|
||||||
|
private function usageLabel(PillarService $service, Pillar $pillar): string
|
||||||
|
{
|
||||||
|
$usage = [
|
||||||
|
'medien' => (int) $pillar->elements_count,
|
||||||
|
'zusammenstellungen' => (int) $pillar->compositions_count,
|
||||||
|
'lizenzartikel' => (int) $pillar->license_articles_count,
|
||||||
|
'seiten' => (int) $pillar->pages_count,
|
||||||
|
];
|
||||||
|
|
||||||
|
return array_sum($usage) === 0 ? '0 Medien' : $service->usageText($usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function catalogRows(): array
|
||||||
|
{
|
||||||
|
$rows = [];
|
||||||
|
|
||||||
|
$service = app(PillarService::class);
|
||||||
|
|
||||||
|
foreach (Pillar::query()->withCount(['elements', 'compositions', 'licenseArticles', 'pages'])->orderBy('sort_order')->orderBy('name')->get() as $pillar) {
|
||||||
|
$public = $pillar->published_at !== null;
|
||||||
|
$url = PillarResource::getUrl('edit', ['record' => $pillar]);
|
||||||
|
$rows[] = [
|
||||||
|
'schluessel' => 's'.$pillar->id,
|
||||||
|
'titel' => $pillar->name,
|
||||||
|
'meta' => 'Fachliche Säule'.(filled($pillar->slug) ? ' · /themen/'.$pillar->slug : ''),
|
||||||
|
'text' => (string) ($pillar->public_summary ?? ''),
|
||||||
|
'symbol' => 'modul',
|
||||||
|
'url' => $url,
|
||||||
|
'chips' => [
|
||||||
|
$public ? ['label' => 'Auf der Website veröffentlicht', 'ton' => 'gut'] : ['label' => 'Intern', 'ton' => 'leise'],
|
||||||
|
['label' => $this->usageLabel($service, $pillar), 'ton' => 'neutral'],
|
||||||
|
],
|
||||||
|
'zustand' => [$public ? 'oeffentlich' : 'intern'],
|
||||||
|
'aktionen' => [['label' => 'Bearbeiten', 'href' => $url, 'icon' => 'stift']],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function zustandOptionen(): array
|
||||||
|
{
|
||||||
|
return ['alle' => 'Jeder Zustand', 'oeffentlich' => 'Auf der Website veröffentlicht', 'intern' => 'Intern'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function einheit(): array
|
||||||
|
{
|
||||||
|
return ['Fachliche Säule', 'Fachliche Säulen'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function leer(): array
|
||||||
|
{
|
||||||
|
return ['titel' => 'Noch keine Säulen', 'text' => 'Mit „Säule anlegen“ oben entsteht die erste Säule.'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,10 @@
|
|||||||
namespace App\Filament\Resources\RightsProfiles\Pages;
|
namespace App\Filament\Resources\RightsProfiles\Pages;
|
||||||
|
|
||||||
use App\Domain\Catalog\OfferService;
|
use App\Domain\Catalog\OfferService;
|
||||||
|
use App\Domain\Catalog\RightsProfile;
|
||||||
use App\Filament\Resources\RightsProfiles\RightsProfileResource;
|
use App\Filament\Resources\RightsProfiles\RightsProfileResource;
|
||||||
|
use App\Filament\Support\CatalogLabels;
|
||||||
|
use App\Filament\Support\ListsCatalog;
|
||||||
use App\Filament\Support\ReportsDomainRules;
|
use App\Filament\Support\ReportsDomainRules;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Forms\Components\CheckboxList;
|
use Filament\Forms\Components\CheckboxList;
|
||||||
@@ -14,6 +17,7 @@
|
|||||||
|
|
||||||
class ListRightsProfiles extends ListRecords
|
class ListRightsProfiles extends ListRecords
|
||||||
{
|
{
|
||||||
|
use ListsCatalog;
|
||||||
use ReportsDomainRules;
|
use ReportsDomainRules;
|
||||||
|
|
||||||
protected static string $resource = RightsProfileResource::class;
|
protected static string $resource = RightsProfileResource::class;
|
||||||
@@ -26,36 +30,78 @@ public function getSubheading(): string|Htmlable|null
|
|||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Action::make('create')->label('Rechteprofil anlegen')->schema([
|
Action::make('create')->label('Rechteprofil anlegen')
|
||||||
TextInput::make('name')->label('Name')->required(),
|
->modalHeading('Neues Rechteprofil')
|
||||||
Select::make('purpose')->label('Zweck')->options([
|
->modalDescription('Zweck und erlaubte Handlungen. Ein Angebot verbindet das Profil später mit Artikeln.')
|
||||||
'ehrenamtlich' => 'Ehrenamtlich',
|
->modalSubmitActionLabel('Rechteprofil anlegen')
|
||||||
'kommerziell' => 'Kommerziell',
|
->schema([
|
||||||
'institutionell' => 'Institutionell',
|
TextInput::make('name')->label('Name')->required(),
|
||||||
])->required(),
|
Select::make('purpose')->label('Zweck')->options([
|
||||||
CheckboxList::make('capabilities')->label('Fähigkeiten')->options([
|
'ehrenamtlich' => 'Ehrenamtlich',
|
||||||
'film:streamen' => 'Film ansehen',
|
'kommerziell' => 'Kommerziell',
|
||||||
'film:laden' => 'Film herunterladen',
|
'institutionell' => 'Institutionell',
|
||||||
'audio:streamen' => 'Hörstück ansehen',
|
])->required(),
|
||||||
'document:ansehen' => 'Dokument ansehen',
|
CheckboxList::make('capabilities')->label('Fähigkeiten')->options(CatalogLabels::FAEHIGKEITEN)->required(),
|
||||||
'document:laden' => 'Dokument herunterladen',
|
])->action(function (array $data): void {
|
||||||
'pdf:ansehen' => 'PDF ansehen',
|
$this->report(function () use ($data): void {
|
||||||
'pdf:laden' => 'PDF herunterladen',
|
$capabilities = [];
|
||||||
'text:ansehen' => 'Text ansehen',
|
|
||||||
'bild:ansehen' => 'Bild ansehen',
|
|
||||||
])->required(),
|
|
||||||
])->action(function (array $data): void {
|
|
||||||
$this->report(function () use ($data): void {
|
|
||||||
$capabilities = [];
|
|
||||||
|
|
||||||
foreach ($data['capabilities'] as $entry) {
|
foreach ($data['capabilities'] as $entry) {
|
||||||
[$class, $action] = explode(':', $entry, 2);
|
[$class, $action] = explode(':', $entry, 2);
|
||||||
$capabilities[$class][] = $action;
|
$capabilities[$class][] = $action;
|
||||||
}
|
}
|
||||||
|
|
||||||
app(OfferService::class)->createRightsProfile($data['name'], $data['purpose'], $capabilities);
|
app(OfferService::class)->createRightsProfile($data['name'], $data['purpose'], $capabilities);
|
||||||
}, 'Das Rechteprofil ist angelegt.');
|
}, 'Das Rechteprofil ist angelegt.');
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function catalogRows(): array
|
||||||
|
{
|
||||||
|
$rows = [];
|
||||||
|
|
||||||
|
foreach (RightsProfile::query()->with('versions')->orderBy('name')->get() as $profile) {
|
||||||
|
$version = $profile->versions->sortByDesc('number')->first();
|
||||||
|
$faehigkeiten = CatalogLabels::faehigkeiten($version?->capabilities);
|
||||||
|
$purpose = CatalogLabels::zweck($version?->purpose);
|
||||||
|
$chips = $version === null
|
||||||
|
? [['label' => 'Noch keine Fassung', 'ton' => 'offen']]
|
||||||
|
: [['label' => 'Fassung '.$version->number, 'ton' => 'neutral'], ['label' => $purpose, 'ton' => 'leise']];
|
||||||
|
|
||||||
|
if ($version?->locked_at !== null) {
|
||||||
|
$chips[] = ['label' => 'Festgeschrieben', 'ton' => 'leise'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = RightsProfileResource::getUrl('view', ['record' => $profile]);
|
||||||
|
$rows[] = [
|
||||||
|
'schluessel' => 'r'.$profile->id,
|
||||||
|
'titel' => $profile->name,
|
||||||
|
'meta' => 'Rechteprofil',
|
||||||
|
'text' => $faehigkeiten === [] ? 'Keine Fähigkeiten' : implode(', ', $faehigkeiten),
|
||||||
|
'symbol' => 'schluessel',
|
||||||
|
'url' => $url,
|
||||||
|
'chips' => $chips,
|
||||||
|
'zustand' => [(string) $version?->purpose],
|
||||||
|
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function zustandOptionen(): array
|
||||||
|
{
|
||||||
|
return ['alle' => 'Jeder Zweck', 'ehrenamtlich' => 'Ehrenamtlich', 'kommerziell' => 'Kommerziell', 'institutionell' => 'Institutionell'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function einheit(): array
|
||||||
|
{
|
||||||
|
return ['Rechteprofil', 'Rechteprofile'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function leer(): array
|
||||||
|
{
|
||||||
|
return ['titel' => 'Noch keine Rechteprofile', 'text' => 'Mit „Rechteprofil anlegen“ oben entsteht das erste Profil.'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,119 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\RightsProfiles\Pages;
|
namespace App\Filament\Resources\RightsProfiles\Pages;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\OfferLine;
|
||||||
|
use App\Domain\Catalog\OfferStatus;
|
||||||
|
use App\Domain\Catalog\RightsProfile;
|
||||||
|
use App\Domain\Catalog\RightsProfileVersion;
|
||||||
|
use App\Domain\Catalog\StatusValue;
|
||||||
use App\Filament\Resources\RightsProfiles\RightsProfileResource;
|
use App\Filament\Resources\RightsProfiles\RightsProfileResource;
|
||||||
|
use App\Filament\Support\CatalogLabels;
|
||||||
use Filament\Resources\Pages\ViewRecord;
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
use Filament\Schemas\Components\View;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Enums\Width;
|
||||||
|
use Illuminate\Contracts\Support\Htmlable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rechteprofil in der gemeinsamen Katalog-Objektseite: Zweck, erlaubte Handlungen und Verwendung in Angeboten.
|
||||||
|
* Ein Rechteprofil wird hier nur gelesen; es gibt keine Bearbeitung.
|
||||||
|
*/
|
||||||
class ViewRightsProfile extends ViewRecord
|
class ViewRightsProfile extends ViewRecord
|
||||||
{
|
{
|
||||||
protected static string $resource = RightsProfileResource::class;
|
protected static string $resource = RightsProfileResource::class;
|
||||||
|
|
||||||
|
public function getTitle(): string|Htmlable
|
||||||
|
{
|
||||||
|
return (string) $this->getRecord()->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHeading(): string|Htmlable
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function getBreadcrumbs(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMaxContentWidth(): Width|string|null
|
||||||
|
{
|
||||||
|
return Width::Full;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function infolist(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema->components([
|
||||||
|
View::make('filament.catalog.objekt')->viewData(fn (): array => $this->profilDaten())->columnSpanFull(),
|
||||||
|
])->columns(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
private function profilDaten(): array
|
||||||
|
{
|
||||||
|
/** @var RightsProfile $profile */
|
||||||
|
$profile = $this->getRecord();
|
||||||
|
$versions = $profile->versions()->orderByDesc('number')->get();
|
||||||
|
$current = $versions->first();
|
||||||
|
$faehigkeiten = CatalogLabels::faehigkeiten($current?->capabilities);
|
||||||
|
$optionen = collect($current?->options ?? [])->map(fn (mixed $wert, string $schluessel): array => [
|
||||||
|
'text' => $schluessel,
|
||||||
|
'neben' => is_scalar($wert) ? (string) $wert : json_encode($wert, JSON_UNESCAPED_UNICODE),
|
||||||
|
])->values()->all();
|
||||||
|
$verwendung = OfferLine::query()
|
||||||
|
->whereIn('rights_profile_version_id', $versions->pluck('id'))
|
||||||
|
->with(['offerVersion.offer', 'article', 'bundleVersion.bundle'])
|
||||||
|
->get()
|
||||||
|
->map(fn (OfferLine $line): array => [
|
||||||
|
'text' => ($line->offerVersion?->offer?->name ?? 'Angebot').' · Fassung '.($line->offerVersion?->number ?? '–'),
|
||||||
|
'zustand' => StatusValue::of($line->offerVersion?->status) === OfferStatus::Aktiv->value
|
||||||
|
? ['label' => 'Aktiv', 'ton' => 'gut']
|
||||||
|
: ['label' => StatusValue::of($line->offerVersion?->status) === OfferStatus::Beendet->value ? 'Beendet' : 'Entwurf', 'ton' => 'leise'],
|
||||||
|
'neben' => $line->article !== null ? 'Lizenzartikel '.$line->article->code : 'Paket '.($line->bundleVersion?->bundle?->name ?? '–'),
|
||||||
|
])->all();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'kopf' => [
|
||||||
|
'brot' => [['label' => 'Rechteprofile', 'href' => RightsProfileResource::getUrl('index')], $profile->name],
|
||||||
|
'titel' => $profile->name,
|
||||||
|
'typ' => 'Rechteprofil',
|
||||||
|
'status' => $current === null
|
||||||
|
? ['text' => 'Noch keine Fassung', 'ton' => 'offen']
|
||||||
|
: ['text' => 'Fassung '.$current->number.' · '.CatalogLabels::zweck($current->purpose).($current->locked_at !== null ? ' · festgeschrieben seit '.$current->locked_at->format('d.m.Y') : ''), 'ton' => 'neutral'],
|
||||||
|
],
|
||||||
|
'haupt' => [
|
||||||
|
[
|
||||||
|
'titel' => 'Erlaubte Handlungen',
|
||||||
|
'zusatz' => $current !== null ? 'Fassung '.$current->number : null,
|
||||||
|
'hilfe' => $current?->locked_at !== null
|
||||||
|
? 'Diese Fassung wird in einem aktiven Angebot verwendet und ist deshalb unveränderlich.'
|
||||||
|
: 'Zweck und erlaubte Handlungen. Angebote verbinden das Profil mit Lizenzartikeln.',
|
||||||
|
'zeilen' => array_map(fn (string $label): array => ['text' => $label], $faehigkeiten),
|
||||||
|
'leer' => ['titel' => 'Keine Handlungen', 'text' => 'Diese Fassung erlaubt keine Handlung.'],
|
||||||
|
],
|
||||||
|
...($optionen !== [] ? [['titel' => 'Optionen', 'zeilen' => $optionen]] : []),
|
||||||
|
],
|
||||||
|
'seite' => [
|
||||||
|
[
|
||||||
|
'titel' => 'In Angeboten',
|
||||||
|
'zeilen' => $verwendung,
|
||||||
|
'leer' => 'In keinem Angebot verwendet.',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'titel' => 'Fassungen',
|
||||||
|
'zeilen' => $versions->map(fn (RightsProfileVersion $version): array => [
|
||||||
|
'text' => 'Fassung '.$version->number,
|
||||||
|
'zustand' => $version->locked_at !== null ? ['label' => 'Festgeschrieben', 'ton' => 'leise'] : null,
|
||||||
|
'neben' => CatalogLabels::zweck($version->purpose),
|
||||||
|
])->all(),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,18 +2,70 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Users\Pages;
|
namespace App\Filament\Resources\Users\Pages;
|
||||||
|
|
||||||
|
use App\Domain\Identity\AccountStatus;
|
||||||
|
use App\Domain\Identity\StaffRole;
|
||||||
use App\Filament\Resources\Users\UserResource;
|
use App\Filament\Resources\Users\UserResource;
|
||||||
|
use App\Filament\Support\ListsCatalog;
|
||||||
|
use App\Models\User;
|
||||||
use Filament\Actions\CreateAction;
|
use Filament\Actions\CreateAction;
|
||||||
use Filament\Resources\Pages\ListRecords;
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
class ListUsers extends ListRecords
|
class ListUsers extends ListRecords
|
||||||
{
|
{
|
||||||
|
use ListsCatalog;
|
||||||
|
|
||||||
protected static string $resource = UserResource::class;
|
protected static string $resource = UserResource::class;
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
CreateAction::make(),
|
CreateAction::make()->label('Benutzer anlegen'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function catalogRows(): array
|
||||||
|
{
|
||||||
|
$rows = [];
|
||||||
|
|
||||||
|
foreach (User::query()->with('staffRoles')->orderBy('name')->get() as $user) {
|
||||||
|
$status = $user->status instanceof AccountStatus ? $user->status->label() : (string) $user->status;
|
||||||
|
$rollen = $user->staffRoles->map(fn ($role): string => $role->role instanceof StaffRole ? $role->role->label() : StaffRole::from((string) $role->role)->label())->all();
|
||||||
|
$url = UserResource::getUrl('edit', ['record' => $user]);
|
||||||
|
$rows[] = [
|
||||||
|
'schluessel' => 'u'.$user->id,
|
||||||
|
'titel' => (string) $user->name,
|
||||||
|
'meta' => (string) $user->email,
|
||||||
|
'symbol' => 'schluessel',
|
||||||
|
'url' => $url,
|
||||||
|
'chips' => [
|
||||||
|
['label' => $status !== '' ? $status : 'Ohne Status', 'ton' => 'neutral'],
|
||||||
|
...array_map(fn (string $rolle): array => ['label' => $rolle, 'ton' => 'gut'], $rollen),
|
||||||
|
],
|
||||||
|
'zustand' => $rollen === [] ? ['ohne-rolle'] : ['mit-rolle'],
|
||||||
|
'aktionen' => [['label' => 'Bearbeiten', 'href' => $url, 'icon' => 'stift']],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function zustandOptionen(): array
|
||||||
|
{
|
||||||
|
return ['alle' => 'Alle Konten', 'mit-rolle' => 'Mit Verwaltungsrolle', 'ohne-rolle' => 'Ohne Verwaltungsrolle'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function einheit(): array
|
||||||
|
{
|
||||||
|
return ['Konto', 'Konten'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function leer(): array
|
||||||
|
{
|
||||||
|
return ['titel' => 'Noch keine Konten', 'text' => 'Mit „Benutzer anlegen“ oben entsteht das erste Konto.'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function suchPlatzhalter(): string
|
||||||
|
{
|
||||||
|
return 'Name oder E-Mail';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loaded 100 of 727 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user