Compare commits
84
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
936c85ef5e | ||
|
|
c61869f8aa | ||
|
|
08d03d0f56 | ||
|
|
ea4244487f | ||
|
|
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 |
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.
|
||||
- Ä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).
|
||||
|
||||
## 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();
|
||||
|
||||
if ($kind === null) {
|
||||
$this->error('Die Inhaltsart Programm fehlt.');
|
||||
$this->error('Die fachliche Materialart Programm fehlt.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Composition extends Model
|
||||
@@ -11,8 +12,10 @@ class Composition extends Model
|
||||
protected $fillable = [
|
||||
'designation',
|
||||
'display_title',
|
||||
'teaser',
|
||||
'summary',
|
||||
'description',
|
||||
'search_terms',
|
||||
'thumbnail_path',
|
||||
'thumbnail_alt',
|
||||
'thumbnail_source',
|
||||
@@ -42,4 +45,13 @@ public function versions(): HasMany
|
||||
{
|
||||
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,6 +14,7 @@ class ContentElement extends Model
|
||||
'output_class',
|
||||
'working_title',
|
||||
'display_title',
|
||||
'teaser',
|
||||
'description',
|
||||
'usage_note',
|
||||
'license_note',
|
||||
@@ -22,10 +23,12 @@ class ContentElement extends Model
|
||||
'website_released_at',
|
||||
'website_public_path',
|
||||
'summary',
|
||||
'search_terms',
|
||||
'thumbnail_path',
|
||||
'thumbnail_alt',
|
||||
'thumbnail_source',
|
||||
'thumbnail_error',
|
||||
'preview_path',
|
||||
'editorial_content_kind_id',
|
||||
'archived_at',
|
||||
];
|
||||
|
||||
@@ -2,17 +2,49 @@
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
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
|
||||
{
|
||||
/** 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 = [
|
||||
'slug',
|
||||
'label',
|
||||
'sort_order',
|
||||
'is_active',
|
||||
'contexts',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_active' => 'boolean',
|
||||
'contexts' => 'array',
|
||||
'sort_order' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function compositions(): HasMany
|
||||
{
|
||||
return $this->hasMany(Composition::class);
|
||||
@@ -23,11 +55,37 @@ public function contentElements(): HasMany
|
||||
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>
|
||||
*/
|
||||
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;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
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'];
|
||||
|
||||
/** Werte in Pflegereihenfolge. */
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class LicenseArticle extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'working_title',
|
||||
'display_title',
|
||||
'teaser',
|
||||
'summary',
|
||||
'description',
|
||||
'search_terms',
|
||||
'editorial_content_kind_id',
|
||||
'product_line',
|
||||
'successor_of_id',
|
||||
'current_release_id',
|
||||
@@ -37,4 +45,15 @@ public function successorOf(): BelongsTo
|
||||
{
|
||||
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;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Offer extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'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
|
||||
{
|
||||
return $this->hasMany(OfferVersion::class);
|
||||
|
||||
@@ -22,6 +22,23 @@ public function currentActiveVersion(Offer $offer): OfferVersion
|
||||
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> $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>
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,16 @@ public function pages(): BelongsToMany
|
||||
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
|
||||
* @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
|
||||
{
|
||||
if ($pillar->elements()->exists() || $pillar->pages()->exists()) {
|
||||
throw new DomainRuleException('Eine Säule mit zugeordneten Medien oder Seiten wird nicht gelöscht.');
|
||||
$usage = $this->usage($pillar);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$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,
|
||||
) {}
|
||||
}
|
||||
@@ -15,6 +15,8 @@
|
||||
* 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
|
||||
{
|
||||
@@ -36,5 +38,39 @@ public function __construct(
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\EditorialProfileReader;
|
||||
use App\Domain\Media\ThumbnailRef;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@@ -95,7 +96,9 @@ public function search(?string $term, int $limit = 25): array
|
||||
$like = '%'.mb_strtolower($term).'%';
|
||||
$query->where(fn ($inner) => $inner
|
||||
->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')
|
||||
->limit($limit * 3)
|
||||
@@ -200,7 +203,9 @@ public function cardSearch(?string $term, int $limit = 25): array
|
||||
$like = '%'.mb_strtolower($term).'%';
|
||||
$query->where(fn ($inner) => $inner
|
||||
->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')
|
||||
->limit($limit * 3)
|
||||
@@ -257,8 +262,16 @@ public function subject(mixed $id, bool $includeNonPublic): ?CardSubject
|
||||
$version = $shown ?? $this->latestReadyVersion($composition);
|
||||
$program = $composition->editorialContentKind?->slug === 'programm';
|
||||
$kind = (string) ($composition->editorialContentKind?->label ?? ($program ? 'Programm' : 'Modul'));
|
||||
$summary = filled($composition->summary) ? trim((string) $composition->summary) : null;
|
||||
$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) {
|
||||
@@ -295,7 +308,7 @@ public function subject(mixed $id, bool $includeNonPublic): ?CardSubject
|
||||
}
|
||||
|
||||
return new CardSubject(
|
||||
title: $this->title($composition),
|
||||
title: $profile->value('display_title') ?: $this->title($composition),
|
||||
summary: $summary ?? $goal,
|
||||
kind: $kind,
|
||||
badge: null,
|
||||
@@ -307,6 +320,7 @@ public function subject(mixed $id, bool $includeNonPublic): ?CardSubject
|
||||
visualLabel: $kind,
|
||||
previewImage: $includeNonPublic ? ThumbnailRef::url('editorial.card', 'komposition', (int) $composition->id, $composition->thumbnail_path) : null,
|
||||
missing: $missing,
|
||||
texts: $texts,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
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;
|
||||
|
||||
@@ -19,10 +20,13 @@
|
||||
* ö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), Kurzbeschreibung, Inhaltsart und Ausgabeart. Nie:
|
||||
* Beschreibung, Einsatzhinweis, Lizenzvermerk, Dateien, Lehrtexte, Ausgabeadressen. Das Vorschaubild (Filmstandbild)
|
||||
* der Bibliothek ist nicht für die Website freigegeben; es erscheint nur in der Redaktionsvorschau.
|
||||
* Eine Karte spielt nichts ab, bietet keinen Download und gibt kein Medium frei.
|
||||
* Ö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 höchstens den für die Website freigegebenen Trailer ab (CardClip), bietet keinen Download und gibt kein Medium frei.
|
||||
*/
|
||||
class PublicMaterialReader
|
||||
{
|
||||
@@ -123,7 +127,7 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ?
|
||||
|
||||
$shown = clone $element;
|
||||
|
||||
foreach (['working_title', 'display_title', 'summary', 'thumbnail_path', 'thumbnail_alt'] as $field) {
|
||||
foreach (['working_title', 'display_title', 'teaser', 'summary', 'description', 'thumbnail_path', 'thumbnail_alt'] as $field) {
|
||||
if (! array_key_exists($field, $draft)) {
|
||||
continue;
|
||||
}
|
||||
@@ -137,6 +141,31 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ?
|
||||
$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) {
|
||||
@@ -157,7 +186,7 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ?
|
||||
$previewImage = $includeNonPublic ? ThumbnailRef::url('editorial.card', 'element', (int) $element->id, $shown->thumbnail_path) : null;
|
||||
|
||||
return new CardSubject(
|
||||
title: (string) ($shown->display_title ?: $shown->working_title),
|
||||
title: $title,
|
||||
summary: $summary,
|
||||
kind: filled($editorialKind) ? (string) $editorialKind : $output,
|
||||
badge: $output,
|
||||
@@ -170,6 +199,7 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ?
|
||||
previewImage: $previewImage,
|
||||
missing: $missing,
|
||||
style: $film ? 'media' : 'material',
|
||||
texts: $texts,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Support;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\PresentationAssignment;
|
||||
use App\Domain\Media\WebsiteMedia;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Der kurze Clip, den eine Premium-Karte beim Überfahren oder Antippen abspielt.
|
||||
*
|
||||
* Gelesen wird nur, was die Redaktion ohnehin für die Website freigegeben hat (WebsiteMedia, Route website.media):
|
||||
* 1. der Trailer des Fachobjekts (Präsentationsrolle „Trailer“), sonst der Vorschauclip,
|
||||
* 2. bei einem Film ersatzweise dessen eigener freigegebener Teaser.
|
||||
* Der vollständige Film, die Originaldatei und nicht freigegebene Clips kommen nie über die Karte. Die Karte gibt
|
||||
* nichts frei; ohne freigegebenen Clip bleibt es beim Kartenbild.
|
||||
*
|
||||
* In der Redaktionsvorschau erklärt `notice`, warum kein Clip läuft (zugeordnet, aber nicht freigegeben).
|
||||
*/
|
||||
class CardClip
|
||||
{
|
||||
/** Rollen in der Reihenfolge, in der ein Clip gesucht wird. */
|
||||
public const ROLES = ['trailer', 'vorschauclip'];
|
||||
|
||||
public function __construct(private readonly WebsiteMedia $media) {}
|
||||
|
||||
/**
|
||||
* @return array{url: string|null, title: string, source: string, notice: string|null, hint: string|null}
|
||||
*/
|
||||
public function for(Model $subject, bool $preview): array
|
||||
{
|
||||
$assigned = PresentationAssignment::query()
|
||||
->with(['role', 'element'])
|
||||
->where('subject_type', $subject->getMorphClass())
|
||||
->where('subject_id', $subject->getKey())
|
||||
->whereHas('role', fn ($query) => $query->whereIn('slug', self::ROLES))
|
||||
->orderBy('position')
|
||||
->orderBy('id')
|
||||
->get()
|
||||
->sortBy(fn (PresentationAssignment $row): int => (int) array_search($row->role?->slug, self::ROLES, true))
|
||||
->values();
|
||||
|
||||
$unreleased = null;
|
||||
|
||||
foreach ($assigned as $assignment) {
|
||||
$element = $assignment->element;
|
||||
|
||||
if (! $element instanceof ContentElement || $element->archived_at !== null || $element->output_class !== 'film') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$present = $this->media->present($element);
|
||||
|
||||
if ($present !== null && $present->kind === 'film') {
|
||||
return $this->found($present->url, $present->title, $assignment->role?->slug === 'trailer' ? 'trailer' : 'vorschauclip');
|
||||
}
|
||||
|
||||
$unreleased ??= $element;
|
||||
}
|
||||
|
||||
if ($subject instanceof ContentElement && $subject->output_class === 'film') {
|
||||
$own = $this->media->present($subject);
|
||||
|
||||
if ($own !== null && $own->kind === 'film') {
|
||||
return $this->found($own->url, $own->title, 'teaser');
|
||||
}
|
||||
}
|
||||
|
||||
if (! $preview) {
|
||||
return $this->none();
|
||||
}
|
||||
|
||||
if ($unreleased instanceof ContentElement) {
|
||||
$title = (string) ($unreleased->display_title ?: $unreleased->working_title);
|
||||
|
||||
return $this->none('Der Trailer „'.$title.'“ ist nicht für die Website freigegeben; öffentlich bleibt es beim Kartenbild (Medium öffnen → Reiter „Website“ → freigeben).');
|
||||
}
|
||||
|
||||
return $this->none(null, 'Kein Trailer zugeordnet; die Karte zeigt nur das Bild (Rolle „Trailer“ in der Präsentation des Mediums).');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{url: string|null, title: string, source: string, notice: string|null, hint: string|null}
|
||||
*/
|
||||
private function found(string $url, string $title, string $source): array
|
||||
{
|
||||
return ['url' => $url, 'title' => $title, 'source' => $source, 'notice' => null, 'hint' => null];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{url: string|null, title: string, source: string, notice: string|null, hint: string|null}
|
||||
*/
|
||||
private function none(?string $notice = null, ?string $hint = null): array
|
||||
{
|
||||
return ['url' => null, 'title' => '', 'source' => 'none', 'notice' => $notice, 'hint' => $hint];
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
use Filament\Forms\Components\Field;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\ViewField;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
@@ -34,16 +34,12 @@ final class ImageRefFields
|
||||
public static function fields(string $label = 'Bild', bool $live = false, string $key = 'image', ?string $altField = null): array
|
||||
{
|
||||
return [
|
||||
Select::make($key)
|
||||
// Auswahl über den gemeinsamen visuellen Picker (Suche, Vorschau, Website-Freigabe im Detail).
|
||||
ViewField::make($key)
|
||||
->live()
|
||||
->label($label.' aus dem Medienmanager')
|
||||
->searchable()
|
||||
->allowHtml()
|
||||
->options(fn (): array => app(WebsiteImage::class)->options())
|
||||
->getSearchResultsUsing(fn (?string $search): array => app(WebsiteImage::class)->options($search))
|
||||
->getOptionLabelUsing(fn (mixed $value): ?string => app(WebsiteImage::class)->optionHtml($value))
|
||||
->placeholder('Kein Bild')
|
||||
->helperText('Alle Bilder des Medienmanagers. Öffentlich erscheint ein Bild nur mit Website-Freigabe.'),
|
||||
->view('filament.cms.bild-feld')
|
||||
->helperText('Öffentlich erscheint ein Bild nur mit Website-Freigabe; die Auswahl gibt es nicht frei.'),
|
||||
FileUpload::make('_upload')
|
||||
->live()
|
||||
->label($label.': neues Bild hochladen')
|
||||
|
||||
@@ -127,6 +127,10 @@ public function url(mixed $value, bool $preview = false): ?string
|
||||
|
||||
$legacy = self::normalize($value);
|
||||
|
||||
if (is_string($legacy) && WebsiteMediaAlias::isRetired($legacy)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return is_string($legacy) ? PublicMedia::url($legacy) : null;
|
||||
}
|
||||
|
||||
@@ -175,6 +179,10 @@ public function status(mixed $value): ?array
|
||||
|
||||
$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,
|
||||
|
||||
@@ -3,15 +3,21 @@
|
||||
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;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* führt auf die öffentliche Programmseite. Die Karte spielt höchstens den für die Website freigegebenen Trailer ab (CardClip), bietet keinen Download und gibt kein Medium frei.
|
||||
*/
|
||||
class MediaCardWidget extends PremiumCardWidget
|
||||
{
|
||||
@@ -27,7 +33,7 @@ public function label(): string
|
||||
|
||||
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.';
|
||||
return 'Karte zu einem Film oder Material aus der Bibliothek; Titel und Art kommen aus den Fachdaten, Trailer nur wenn freigegeben, kein Download.';
|
||||
}
|
||||
|
||||
public function icon(): string
|
||||
@@ -52,7 +58,7 @@ protected function refLabel(): string
|
||||
|
||||
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 und Kurzbeschreibung pflegen Sie im Medium.';
|
||||
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
|
||||
@@ -88,4 +94,76 @@ 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 supportsClip(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function clipSubject(mixed $id): ?Model
|
||||
{
|
||||
$element = is_numeric($id) ? ContentElement::query()->find((int) $id) : null;
|
||||
|
||||
return $element instanceof ContentElement ? $element : null;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,20 @@
|
||||
|
||||
use App\Domain\Cms\Catalog\CardSubject;
|
||||
use App\Domain\Cms\Widgets\RenderContext;
|
||||
use App\Domain\Cms\Widgets\Support\CardClip;
|
||||
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\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Gemeinsame Basis der Premium-Karten (Brand-UI-Kit v1.7, Entwurf zur visuellen Freigabe):
|
||||
@@ -54,6 +59,56 @@ 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 [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fachobjekt, dessen Trailer die Karte beim Überfahren oder Antippen abspielt (Medium, Programm, Modul).
|
||||
* Null: diese Karte hat keinen Clip (Thema). Der Clip kommt aus der Präsentation des Objekts (CardClip).
|
||||
*/
|
||||
protected function clipSubject(mixed $id): ?Model
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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';
|
||||
@@ -108,7 +163,9 @@ public function optionIcons(): array
|
||||
|
||||
public function settings(): array
|
||||
{
|
||||
return [
|
||||
$choices = $this->textChoices();
|
||||
|
||||
return ($choices === [] ? [] : ['text_source' => $choices]) + ($this->supportsClip() ? ['clip' => ['yes' => 'Abspielen', 'no' => 'Nicht abspielen']] : []) + [
|
||||
'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'],
|
||||
@@ -122,10 +179,12 @@ public function settings(): array
|
||||
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.'],
|
||||
'clip' => ['Trailer auf der Karte', 'Spielt den freigegebenen Trailer stumm ab, solange die Maus auf der Karte steht; am Handy mit Tippen auf das Bild, per Tastatur über die Schaltfläche am Bild. Gewählt wird der Trailer (sonst der Vorschauclip) in der Präsentation des Objekts, bei einem Film ersatzweise sein freigegebener Teaser. Ohne freigegebenen Clip bleibt das Kartenbild. Vorgabe: Abspielen.'],
|
||||
'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' => ['Kurzbeschreibung', 'Aus den Fachdaten. Vorgabe: anzeigen.'],
|
||||
'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.'],
|
||||
@@ -137,6 +196,8 @@ 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'],
|
||||
@@ -178,7 +239,27 @@ public function editorSchema(): array
|
||||
|
||||
return [
|
||||
Group::make([$this->subjectField()])->statePath('refs'),
|
||||
Group::make([$action, $note])->statePath('data'),
|
||||
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'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -187,7 +268,7 @@ public function mediaSchema(): array
|
||||
[, , $alt, $focusX, $focusY] = $this->dataFields();
|
||||
|
||||
return [
|
||||
Group::make(ImageRefFields::fields('Kartenbild', live: true))->statePath('refs'),
|
||||
Group::make([...ImageRefFields::fields('Kartenbild', live: true), ...$this->imageSourceFields()])->statePath('refs'),
|
||||
Group::make([$alt, $focusX, $focusY])->statePath('data'),
|
||||
];
|
||||
}
|
||||
@@ -205,7 +286,7 @@ public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||
$refs[$key] = $id;
|
||||
$refs = ImageRefFields::clean($refs, $errors);
|
||||
|
||||
foreach (['action_label', 'note', 'alt'] as $field) {
|
||||
foreach (['action_label', 'note', 'alt', 'heading', 'summary'] as $field) {
|
||||
$data[$field] = filled($data[$field] ?? null) ? trim((string) $data[$field]) : null;
|
||||
}
|
||||
|
||||
@@ -224,13 +305,36 @@ public function resolve(array $widget, RenderContext $context): array
|
||||
$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);
|
||||
|
||||
$clip = null;
|
||||
|
||||
if ($this->supportsClip() && $option('clip', 'yes') === 'yes' && $subject instanceof CardSubject) {
|
||||
$owner = $this->clipSubject($widget['refs'][$this->refKey()] ?? null);
|
||||
$clip = $owner instanceof Model ? app(CardClip::class)->for($owner, $context->preview) : null;
|
||||
}
|
||||
|
||||
return [
|
||||
'subject' => $subject,
|
||||
'clip' => $clip,
|
||||
'cardStyle' => $subject?->style ?? $this->cardStyle(),
|
||||
'imageUrl' => app(WebsiteImage::class)->url($widget['refs']['image'] ?? null, $context->preview),
|
||||
'alt' => app(WebsiteImage::class)->alt($widget['refs']['image'] ?? null, $data['alt'] ?? null),
|
||||
'imageNotice' => $context->preview ? app(WebsiteImage::class)->previewNotice($widget['refs']['image'] ?? null, 'Das Kartenbild') : null,
|
||||
'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'),
|
||||
@@ -261,6 +365,40 @@ public function summary(array $widget): string
|
||||
return $label ?? 'Kein Objekt gewählt';
|
||||
}
|
||||
|
||||
protected function centralCoverId(mixed $id): ?int
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function supportsClip(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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())
|
||||
|
||||
@@ -3,9 +3,15 @@
|
||||
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;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Modul- und Programmkarte (Kit v1.7 „catalog“): ein Programm oder Modul über PublicCatalogReader, dieselbe
|
||||
@@ -40,6 +46,59 @@ 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.
|
||||
@@ -97,4 +156,25 @@ protected function cardStyle(): string
|
||||
{
|
||||
return 'catalog';
|
||||
}
|
||||
|
||||
protected function supportsClip(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function clipSubject(mixed $id): ?Model
|
||||
{
|
||||
$composition = is_numeric($id) ? Composition::query()->find((int) $id) : null;
|
||||
|
||||
return $composition instanceof Composition ? $composition : null;
|
||||
}
|
||||
|
||||
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,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\Offer;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Catalog\OfferVersion;
|
||||
use App\Domain\Entitlement\Acquisition;
|
||||
use App\Domain\Entitlement\AcquisitionType;
|
||||
use App\Domain\Entitlement\GrantIssuer;
|
||||
use App\Domain\Entitlement\GrantStatus;
|
||||
use App\Domain\Identity\AccountStatus;
|
||||
use App\Domain\Identity\Party;
|
||||
use App\Mail\OrderConfirmed;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -20,13 +22,15 @@ class Checkout
|
||||
public function __construct(
|
||||
private readonly GrantIssuer $grants,
|
||||
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
|
||||
{
|
||||
if ($user->status !== AccountStatus::Aktiv || $user->party_id === null) {
|
||||
throw new DomainRuleException('Nur ein aktives Mitglied kann kaufen.');
|
||||
}
|
||||
$this->assertActive($user);
|
||||
|
||||
$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.');
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($user, $offer, $version): Order {
|
||||
$order = Order::query()->create([
|
||||
'user_id' => $user->id,
|
||||
'party_id' => $user->party_id,
|
||||
'status' => 'offen',
|
||||
'holder_kind' => 'person',
|
||||
]);
|
||||
$holder = $this->holders->resolve($user, null);
|
||||
|
||||
return DB::transaction(fn (): Order => $this->createOrder($user, $holder, [[$offer, $version]]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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([
|
||||
'offer_version_id' => $version->id,
|
||||
'offer_name' => $offer->name,
|
||||
'price_cents' => $version->price_cents,
|
||||
'currency' => 'EUR',
|
||||
'term_rule' => $version->term_rule,
|
||||
'update_promise' => $version->update_promise,
|
||||
'holder_kind' => $version->holder_kind,
|
||||
'tax_class' => $version->tax_class,
|
||||
'grant_kind' => $version->grant_kind,
|
||||
'holder_party_id' => $holder->id,
|
||||
]);
|
||||
$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
|
||||
{
|
||||
$this->assertTestDriver();
|
||||
@@ -100,14 +166,12 @@ public function confirmTestPayment(Order $order, string $reference): Order
|
||||
$order->status = 'bezahlt';
|
||||
$order->save();
|
||||
$paidNow = true;
|
||||
$line = $order->lines()->firstOrFail();
|
||||
$this->grants->issue(
|
||||
$order->user,
|
||||
$line->offerVersion,
|
||||
AcquisitionType::Bestellposition,
|
||||
'order_line',
|
||||
$line->id,
|
||||
);
|
||||
$actor = User::query()->findOrFail($order->user_id);
|
||||
|
||||
foreach ($order->lines()->orderBy('id')->get() as $line) {
|
||||
$holder = Party::query()->findOrFail($line->holder_party_id ?? $order->party_id);
|
||||
$this->grants->issueFromOrderLine($line, $holder, $actor);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
$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.');
|
||||
}
|
||||
|
||||
$line = $order->lines()->firstOrFail();
|
||||
$acquisition = Acquisition::query()->where([
|
||||
'type' => AcquisitionType::Bestellposition,
|
||||
'reference_type' => 'order_line',
|
||||
'reference_id' => $line->id,
|
||||
])->first();
|
||||
foreach ($order->lines()->orderBy('id')->get() as $line) {
|
||||
$acquisition = Acquisition::query()->where([
|
||||
'type' => AcquisitionType::Bestellposition,
|
||||
'reference_type' => 'order_line',
|
||||
'reference_id' => $line->id,
|
||||
])->first();
|
||||
|
||||
if ($acquisition !== null) {
|
||||
foreach ($acquisition->grants as $grant) {
|
||||
foreach ($acquisition?->grants ?? [] as $grant) {
|
||||
if ($grant->status === GrantStatus::Aktiv) {
|
||||
$grant->status = GrantStatus::Widerrufen;
|
||||
$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
|
||||
{
|
||||
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',
|
||||
'status',
|
||||
'holder_kind',
|
||||
'total_cents',
|
||||
'currency',
|
||||
];
|
||||
|
||||
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;
|
||||
|
||||
use App\Domain\Catalog\OfferVersion;
|
||||
use App\Domain\Identity\Party;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
@@ -17,6 +18,10 @@ class OrderLine extends Model
|
||||
'term_rule',
|
||||
'update_promise',
|
||||
'holder_kind',
|
||||
'currency',
|
||||
'tax_class',
|
||||
'grant_kind',
|
||||
'holder_party_id',
|
||||
];
|
||||
|
||||
public function order(): BelongsTo
|
||||
@@ -24,6 +29,11 @@ public function order(): BelongsTo
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
|
||||
public function holder(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Party::class, 'holder_party_id');
|
||||
}
|
||||
|
||||
public function offerVersion(): BelongsTo
|
||||
{
|
||||
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_id',
|
||||
'conditions',
|
||||
'acting_user_id',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
|
||||
@@ -47,7 +47,7 @@ public function __invoke(
|
||||
$candidates = Grant::query()
|
||||
->where('license_article_id', $article->id)
|
||||
->where('status', GrantStatus::Aktiv)
|
||||
->whereHas('acquisition', fn ($query) => $query->where('party_id', $user->party_id))
|
||||
->usableBy($user)
|
||||
->get()
|
||||
->filter(function (Grant $grant) use ($now): bool {
|
||||
if ($grant->valid_from !== null && $grant->valid_from->greaterThan($now)) {
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
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\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
|
||||
{
|
||||
return $this->belongsTo(Acquisition::class);
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Catalog\OfferStatus;
|
||||
use App\Domain\Catalog\OfferVersion;
|
||||
use App\Domain\Commerce\OrderLine;
|
||||
use App\Domain\Identity\Party;
|
||||
use App\Models\User;
|
||||
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(
|
||||
User $user,
|
||||
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,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Jobs\StorePresentationFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Legt die technische Ableitung eines Präsentationsmediums (Website-Datei) an der Medienidentität ab.
|
||||
* Es entsteht keine Inhaltsfassung, keine Freigabe und keine Berechtigung. Eine vorhandene Inhaltsfassung bleibt
|
||||
* unverändert und geschützt; die Website-Datei ist eine eigene, bewusst gewählte Datei daneben.
|
||||
*
|
||||
* Der Web-Prozess hat `derived/` nur lesend. Er prüft deshalb nur und gibt das Kopieren an die Warteschlange
|
||||
* (`StorePresentationFile`, ruft `place()` auf).
|
||||
*/
|
||||
class PresentationFile
|
||||
{
|
||||
/**
|
||||
* Dateiendungen, die ein Browser auf der Website abspielen kann.
|
||||
*
|
||||
* @var array<string, list<string>>
|
||||
*/
|
||||
public const EXTENSIONS = [
|
||||
'bild' => ['jpg', 'jpeg', 'png', 'webp', 'gif'],
|
||||
'audio' => ['mp3', 'm4a', 'ogg'],
|
||||
'film' => ['mp4', 'webm'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Prüft die Datei im Eingang, ohne etwas zu verändern. Wirft eine verständliche Regelverletzung.
|
||||
*/
|
||||
public function validate(string $outputClass, string $incoming): void
|
||||
{
|
||||
if (! isset(self::EXTENSIONS[$outputClass])) {
|
||||
throw new DomainRuleException('Eine Präsentationsdatei ist ein Bild, ein Film oder ein Hörstück.');
|
||||
}
|
||||
|
||||
$extension = strtolower(pathinfo($incoming, PATHINFO_EXTENSION));
|
||||
|
||||
if (! in_array($extension, self::EXTENSIONS[$outputClass], true)) {
|
||||
throw new DomainRuleException(sprintf(
|
||||
'Für die Website geht nur %s. Eine %s-Datei kann der Browser nicht direkt abspielen; wandle sie vorher um oder lade sie ohne „Eigenständiges Präsentationsmedium“ hoch.',
|
||||
$this->formats($outputClass),
|
||||
$extension === '' ? 'Datei ohne Endung' : '.'.$extension,
|
||||
));
|
||||
}
|
||||
|
||||
if (! $this->readable($incoming)) {
|
||||
throw new DomainRuleException('Die Datei liegt nicht im Eingang.');
|
||||
}
|
||||
}
|
||||
|
||||
public function store(ContentElement $element, string $incoming): void
|
||||
{
|
||||
$this->validate((string) $element->output_class, $incoming);
|
||||
|
||||
$element->thumbnail_error = null;
|
||||
$element->save();
|
||||
|
||||
StorePresentationFile::dispatch($element->id, $incoming);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kopiert die Datei nach `derived/`. Läuft nur in der Warteschlange, die dort schreiben darf.
|
||||
*/
|
||||
public function place(ContentElement $element, string $incoming): void
|
||||
{
|
||||
$this->validate((string) $element->output_class, $incoming);
|
||||
|
||||
$extension = strtolower(pathinfo($incoming, PATHINFO_EXTENSION));
|
||||
$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 {
|
||||
$written = Storage::disk('media_derived')->writeStream($target, $stream);
|
||||
} finally {
|
||||
fclose($stream);
|
||||
}
|
||||
|
||||
if ($written === false) {
|
||||
throw new DomainRuleException('Die Datei ließ sich nicht ablegen.');
|
||||
}
|
||||
|
||||
if ($element->output_class === 'bild') {
|
||||
$element->thumbnail_path = $target;
|
||||
$element->thumbnail_source = 'eigen';
|
||||
} else {
|
||||
$element->preview_path = $target;
|
||||
}
|
||||
|
||||
$element->thumbnail_error = null;
|
||||
$element->save();
|
||||
Storage::disk('cms_incoming')->delete($incoming);
|
||||
}
|
||||
|
||||
public function formats(string $outputClass): string
|
||||
{
|
||||
return match ($outputClass) {
|
||||
'bild' => 'JPG, PNG, WebP oder GIF',
|
||||
'audio' => 'MP3, M4A oder OGG',
|
||||
default => 'MP4 (H.264) oder WebM',
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -138,8 +138,20 @@ public function forCompositionFrame(Composition $composition, ContentElementVers
|
||||
$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()
|
||||
->where('content_element_version_id', $version->id)
|
||||
->where('role', 'variant')
|
||||
@@ -155,13 +167,25 @@ public function frameInput(ContentElementVersion $version): ?string
|
||||
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
|
||||
{
|
||||
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) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$file = $this->frameInput($version);
|
||||
$file = $this->frameInput($version, $original);
|
||||
|
||||
if ($file === null) {
|
||||
return null;
|
||||
@@ -186,7 +210,7 @@ public function jpegAtVersion(ContentElementVersion $version, float $seconds): ?
|
||||
'-frames:v',
|
||||
'1',
|
||||
'-vf',
|
||||
'scale=640:-2',
|
||||
$width === 640 ? 'scale=640:-2' : 'scale=min('.max(160, min(2400, $width)).'\,iw):-2',
|
||||
'-f',
|
||||
'image2pipe',
|
||||
'-vcodec',
|
||||
|
||||
@@ -40,7 +40,11 @@ public function present(ContentElement|int $element): ?WebsitePresentation
|
||||
title: $title,
|
||||
alt: $alt !== '' ? $alt : $title,
|
||||
credit: filled($element->website_credit) ? trim((string) $element->website_credit) : null,
|
||||
kind: $element->output_class === 'film' ? 'film' : 'bild',
|
||||
kind: match ($element->output_class) {
|
||||
'film' => 'film',
|
||||
'audio' => 'audio',
|
||||
default => 'bild',
|
||||
},
|
||||
url: route('website.media', $element),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,16 @@ public static function effectiveFor(mixed $path): ?self
|
||||
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;
|
||||
|
||||
@@ -44,7 +44,7 @@ public function refusal(ContentElement $element): ?string
|
||||
}
|
||||
|
||||
if ($this->derivedPath($element) === null) {
|
||||
return 'Für die Website fehlt eine freigebbare Ableitung. Beim Bild ist das das Vorschaubild, beim Film eine Teaserfassung unter teaser/. Die Originaldatei bleibt geschützt.';
|
||||
return 'Für die Website fehlt eine freigebbare Datei. Beim Bild ist das das Vorschaubild. Bei Film und Hörstück lädst du unter „Website-Freigabe“ eine Website-Datei hoch (Film als MP4 oder WebM); die geschützte Originaldatei bleibt unberührt.';
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -57,7 +57,18 @@ public function derivedPath(ContentElement $element): ?string
|
||||
}
|
||||
|
||||
if ($element->output_class === 'bild') {
|
||||
return $this->allowedDerivedPath($element->thumbnail_path, 'vorschau/');
|
||||
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') {
|
||||
@@ -79,7 +90,7 @@ public function derivedPath(ContentElement $element): ?string
|
||||
->orderByDesc('id')
|
||||
->value('path');
|
||||
|
||||
return $this->allowedDerivedPath($path, 'teaser/');
|
||||
return $this->allowedDerivedPath($path, 'teaser/', ['mp4', 'webm']);
|
||||
}
|
||||
|
||||
public function publicPath(ContentElement $element, string $derivedPath): string
|
||||
@@ -100,7 +111,10 @@ private function isConfidential(ContentElement $element): bool
|
||||
return in_array($slug, PublicMaterialReader::CONFIDENTIAL_KINDS, true);
|
||||
}
|
||||
|
||||
private function allowedDerivedPath(mixed $path, string $prefix): ?string
|
||||
/**
|
||||
* @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;
|
||||
@@ -108,7 +122,7 @@ private function allowedDerivedPath(mixed $path, string $prefix): ?string
|
||||
|
||||
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||
|
||||
if (! in_array($extension, ['jpg', 'jpeg', 'png', 'webp', 'gif', 'mp4', 'webm'], true)) {
|
||||
if (! in_array($extension, $extensions, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,20 +2,21 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
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\Support\EditorialCatalog;
|
||||
use App\Filament\Support\ListsCompositions;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Support\Enums\Width;
|
||||
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
|
||||
{
|
||||
use ListsCompositions;
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||
|
||||
protected static ?string $navigationLabel = 'Arbeitsplatz';
|
||||
@@ -28,24 +29,6 @@ class EditorialDesk extends 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
|
||||
{
|
||||
return 'Programme und Module';
|
||||
@@ -53,7 +36,7 @@ public function getHeading(): 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
|
||||
@@ -66,185 +49,11 @@ public static function canAccess(): bool
|
||||
return ContentElementResource::editor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{label: string, values: list<array{id: int, label: string}>}>
|
||||
*/
|
||||
public function dimensionFilters(): array
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
$groups = [];
|
||||
|
||||
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
|
||||
$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);
|
||||
return [
|
||||
$this->createCompositionAction(CompositionKind::Uebung),
|
||||
$this->createCompositionAction(CompositionKind::Kurs),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
use App\Domain\Catalog\Bundle;
|
||||
use App\Domain\Catalog\BundleService;
|
||||
use App\Domain\Catalog\BundleStatus;
|
||||
use App\Domain\Catalog\StatusValue;
|
||||
use App\Filament\Resources\Bundles\BundleResource;
|
||||
use App\Filament\Support\ListsCatalog;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
@@ -12,6 +16,7 @@
|
||||
|
||||
class ListBundles extends ListRecords
|
||||
{
|
||||
use ListsCatalog;
|
||||
use ReportsDomainRules;
|
||||
|
||||
protected static string $resource = BundleResource::class;
|
||||
@@ -24,13 +29,83 @@ public function getSubheading(): string|Htmlable|null
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('create')->label('Paket anlegen')->schema([
|
||||
TextInput::make('name')->label('Name')->required(),
|
||||
])->action(function (array $data): void {
|
||||
$this->report(function () use ($data): void {
|
||||
app(BundleService::class)->create($data['name']);
|
||||
}, 'Das Paket ist angelegt.');
|
||||
}),
|
||||
Action::make('create')->label('Paket anlegen')
|
||||
->modalHeading('Neues Paket')
|
||||
->modalDescription('Der Name genügt. Bestandteile stellst du danach am Paket zusammen.')
|
||||
->modalSubmitActionLabel('Paket anlegen')
|
||||
->schema([
|
||||
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\BundleService;
|
||||
use App\Domain\Catalog\BundleStatus;
|
||||
use App\Domain\Catalog\BundleVersion;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Catalog\StatusValue;
|
||||
use App\Filament\Resources\Bundles\BundleResource;
|
||||
use App\Filament\Support\CatalogOptions;
|
||||
use App\Filament\Support\CatalogReading;
|
||||
use App\Filament\Support\PublicationReadiness;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
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
|
||||
{
|
||||
use ReportsDomainRules;
|
||||
|
||||
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
|
||||
{
|
||||
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 [
|
||||
Action::make('publish')
|
||||
->label('Fassung veröffentlichen')
|
||||
->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()]);
|
||||
'articles' => $published?->items->pluck('license_article_id')->filter()->values()->all() ?? [],
|
||||
'bundles' => $published?->items->pluck('nested_bundle_id')->filter()->values()->all() ?? [],
|
||||
];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$this->report(function () use ($data): void {
|
||||
/** @var Bundle $bundle */
|
||||
$bundle = $this->getRecord();
|
||||
$items = [];
|
||||
private function nextNumber(): int
|
||||
{
|
||||
return ((int) $this->getRecord()->versions()->max('number')) + 1;
|
||||
}
|
||||
|
||||
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) {
|
||||
$items[] = Bundle::query()->findOrFail($id);
|
||||
}
|
||||
|
||||
app(BundleService::class)->publish($bundle, $items);
|
||||
}, 'Die Paketfassung ist veröffentlicht.');
|
||||
$this->getRecord()->unsetRelations();
|
||||
$this->getRecord()->refresh();
|
||||
}),
|
||||
return [
|
||||
'kopf' => [
|
||||
'brot' => [['label' => 'Pakete', 'href' => BundleResource::getUrl('index')], $bundle->name],
|
||||
'titel' => $bundle->name,
|
||||
'typ' => 'Paket',
|
||||
'status' => $published !== null
|
||||
? ['text' => 'Fassung '.$published->number.' veröffentlicht', 'ton' => 'gut']
|
||||
: ['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\ContentService;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Support\ListsCompositions;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Schemas\Components\View;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\Width;
|
||||
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
|
||||
{
|
||||
use ListsCompositions;
|
||||
use ReportsDomainRules;
|
||||
|
||||
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
|
||||
{
|
||||
$desk = in_array($this->kind(), [CompositionKind::Kurs, CompositionKind::Uebung], true)
|
||||
? ' Programme und Module liegen gemeinsam auf dem Arbeitsplatz.'
|
||||
: '';
|
||||
$desk = $this->onDesk() ? ' Programme und Module stehen gemeinsam auch auf dem Arbeitsplatz.' : '';
|
||||
|
||||
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
|
||||
{
|
||||
if ($this->onDesk()) {
|
||||
return [$this->createCompositionAction($this->kind())];
|
||||
}
|
||||
|
||||
return [
|
||||
Action::make('create')
|
||||
->label(match ($this->kind()) {
|
||||
CompositionKind::Kurs => 'Programm anlegen',
|
||||
CompositionKind::Uebung => 'Modul anlegen',
|
||||
default => $this->kind()->createLabel(),
|
||||
})
|
||||
->label($this->kind()->createLabel())
|
||||
->modalHeading('Neue '.lcfirst($this->kind()->label()))
|
||||
->modalSubmitActionLabel($this->kind()->createLabel())
|
||||
->visible(fn (): bool => ContentElementResource::editor())
|
||||
->schema([
|
||||
TextInput::make('designation')->label('Bezeichnung')->required(),
|
||||
@@ -44,16 +72,6 @@ protected function getHeaderActions(): array
|
||||
$composition = null;
|
||||
$this->report(function () use ($data, &$composition): void {
|
||||
$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.');
|
||||
|
||||
if ($composition !== null) {
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\EditorialDimensionValue;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
@@ -37,12 +35,23 @@
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
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
|
||||
{
|
||||
use ReportsDomainRules;
|
||||
|
||||
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
|
||||
{
|
||||
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.'),
|
||||
Textarea::make('summary')->label('Kurzbeschreibung')->rows(3),
|
||||
Select::make('editorial_content_kind_id')
|
||||
->label('Inhaltsart')
|
||||
->options(fn (): array => EditorialContentKind::selectOptions())
|
||||
->label('Fachliche Materialart')
|
||||
->options(fn (): array => app(EditorialVocabulary::class)->kindOptions('medium', $this->getRecord()->editorial_content_kind_id !== null ? (int) $this->getRecord()->editorial_content_kind_id : null))
|
||||
->nullable()
|
||||
->helperText('Optional für Bibliothek und Website. Ändert weder die Ausgabeart noch eine Fassung.'),
|
||||
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')
|
||||
->options(function (): array {
|
||||
$options = [];
|
||||
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
|
||||
foreach ($dimension->values as $value) {
|
||||
$options[$value->id] = $dimension->label.': '.$value->label;
|
||||
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) {
|
||||
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']);
|
||||
}
|
||||
if (array_key_exists('dimension_ids', $data)) {
|
||||
$ids = 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(IdentityDimension::class)->replaceOffered($record, array_map(intval(...), $data['dimension_ids'] ?? []));
|
||||
}
|
||||
app(PillarService::class)->assign($record, array_map(intval(...), $data['pillars'] ?? []));
|
||||
} catch (DomainRuleException $exception) {
|
||||
|
||||
@@ -2,10 +2,14 @@
|
||||
|
||||
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\Support\Bestand;
|
||||
use App\Filament\Support\MediaLibrary;
|
||||
use App\Filament\Support\MediumForm;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use App\Filament\Support\ShowsBestand;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Schemas\Components\RenderHook;
|
||||
@@ -19,14 +23,16 @@
|
||||
class ListContentElements extends ListRecords
|
||||
{
|
||||
use ReportsDomainRules;
|
||||
use ShowsBestand;
|
||||
|
||||
protected static string $resource = ContentElementResource::class;
|
||||
|
||||
#[Url(as: 'suche', except: '')]
|
||||
public string $suche = '';
|
||||
|
||||
#[Url(as: 'ansicht', except: 'kacheln')]
|
||||
public string $ansicht = 'kacheln';
|
||||
/** 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 = '';
|
||||
@@ -46,6 +52,9 @@ class ListContentElements extends ListRecords
|
||||
#[Url(as: 'saeule', except: '')]
|
||||
public string $saeule = '';
|
||||
|
||||
#[Url(as: 'inhaltsart', except: '')]
|
||||
public string $inhaltsart = '';
|
||||
|
||||
#[Url(as: 'einordnung', except: '')]
|
||||
public string $einordnung = '';
|
||||
|
||||
@@ -68,13 +77,17 @@ public function getMaxContentWidth(): Width|string|null
|
||||
public function content(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
$this->getTabsContentComponent(),
|
||||
RenderHook::make(PanelsRenderHook::RESOURCE_PAGES_LIST_RECORDS_TABLE_BEFORE),
|
||||
View::make('filament.media.library'),
|
||||
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';
|
||||
@@ -109,7 +122,15 @@ public function pillarOptions(): array
|
||||
*/
|
||||
public function classificationOptions(): array
|
||||
{
|
||||
return app(MediaLibrary::class)->classifications();
|
||||
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
|
||||
@@ -122,6 +143,7 @@ public function filtersActive(): bool
|
||||
|| $this->nutzung !== ''
|
||||
|| $this->saeule !== ''
|
||||
|| $this->einordnung !== ''
|
||||
|| $this->inhaltsart !== ''
|
||||
|| $this->verarbeitung !== ''
|
||||
|| $this->archiv !== 'aktiv';
|
||||
}
|
||||
@@ -136,8 +158,109 @@ public function resetFilters(): void
|
||||
$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,
|
||||
])),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,6 +277,7 @@ private function libraryFilters(): array
|
||||
'nutzung' => $this->nutzung,
|
||||
'saeule' => $this->saeule,
|
||||
'einordnung' => $this->einordnung,
|
||||
'inhaltsart' => $this->inhaltsart,
|
||||
'verarbeitung' => $this->verarbeitung,
|
||||
'archiv' => $this->archiv,
|
||||
];
|
||||
@@ -164,6 +288,7 @@ protected function getHeaderActions(): array
|
||||
return [
|
||||
Action::make('create')
|
||||
->label('Medium anlegen')
|
||||
->modalSubmitActionLabel('Medium anlegen')
|
||||
->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.')
|
||||
->schema(fn (): array => MediumForm::fields(creating: true))
|
||||
|
||||
@@ -6,15 +6,18 @@
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EditorialDimensionValue;
|
||||
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\Pillar;
|
||||
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\PresentationFile;
|
||||
use App\Domain\Media\ThumbnailRef;
|
||||
use App\Domain\Media\WebsiteMedia;
|
||||
use App\Domain\Media\WebsiteRelease;
|
||||
@@ -22,6 +25,7 @@
|
||||
use App\Filament\Support\CatalogReading;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Filament\Support\ElementRevision;
|
||||
use App\Filament\Support\ManagesEditorialSurface;
|
||||
use App\Filament\Support\MediaLibrary;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use App\Http\Controllers\ContentPreviewController;
|
||||
@@ -39,6 +43,7 @@
|
||||
|
||||
class ViewContentElement extends ViewRecord
|
||||
{
|
||||
use ManagesEditorialSurface;
|
||||
use ReportsDomainRules;
|
||||
use WithFileUploads;
|
||||
|
||||
@@ -54,6 +59,14 @@ class ViewContentElement extends ViewRecord
|
||||
|
||||
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 string $bereich = 'inhalt';
|
||||
@@ -62,8 +75,12 @@ class ViewContentElement extends ViewRecord
|
||||
|
||||
public string $displayTitle = '';
|
||||
|
||||
public string $teaser = '';
|
||||
|
||||
public string $summary = '';
|
||||
|
||||
public string $searchTerms = '';
|
||||
|
||||
public string $descriptionText = '';
|
||||
|
||||
public string $usageNote = '';
|
||||
@@ -76,6 +93,9 @@ class ViewContentElement extends ViewRecord
|
||||
|
||||
public string $websiteFeedback = '';
|
||||
|
||||
/** Gewählte Website-Datei für Film oder Hörstück (ungeschützt, getrennt von der Inhaltsfassung). */
|
||||
public mixed $websiteUpload = null;
|
||||
|
||||
public int|string|null $kindId = null;
|
||||
|
||||
/** @var list<int|string> */
|
||||
@@ -86,18 +106,16 @@ class ViewContentElement extends ViewRecord
|
||||
|
||||
public string $editorialFeedback = '';
|
||||
|
||||
public int $versionsBeforeSave = 0;
|
||||
|
||||
public string $previewWidth = '640';
|
||||
|
||||
public string $previewSurface = 'website';
|
||||
|
||||
public string $pickerQuery = '';
|
||||
|
||||
public string $pickerContext = 'modul';
|
||||
|
||||
public string $pickerLayout = 'kacheln';
|
||||
|
||||
public string $pickerSelected = '';
|
||||
|
||||
public function mount(int|string $record): void
|
||||
{
|
||||
parent::mount($record);
|
||||
@@ -108,25 +126,47 @@ public function mount(int|string $record): void
|
||||
$this->fassung = $requested;
|
||||
}
|
||||
|
||||
$bereich = (string) request()->query('bereich', 'beschreibung');
|
||||
$this->bereich = in_array($bereich, ['beschreibung', 'inhalt', 'fassungen', 'verwendung', 'vorschau'], true)
|
||||
? $bereich
|
||||
: 'beschreibung';
|
||||
$bereich = (string) request()->query('bereich', 'inhalt');
|
||||
$this->bereich = $this->normalBereich($bereich);
|
||||
$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();
|
||||
|
||||
if (in_array($bereich, ['praesentation', 'redaktion'], true) && $this->canEditEditorial()) {
|
||||
$this->openRedaktion($bereich === 'praesentation' ? 'medien' : 'texte');
|
||||
}
|
||||
}
|
||||
|
||||
public function getHeading(): string|Htmlable
|
||||
public function updatedBereich(string $value): void
|
||||
{
|
||||
$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 getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return 'Texte und Vorschaubild ändern keine Fassung. Eine neue Datei oder ein geänderter Lehrtext braucht eine neue Fassung.';
|
||||
}
|
||||
|
||||
public function getMaxContentWidth(): Width|string|null
|
||||
{
|
||||
return Width::Full;
|
||||
@@ -135,14 +175,54 @@ public function getMaxContentWidth(): Width|string|null
|
||||
public function infolist(Schema $schema): Schema
|
||||
{
|
||||
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
|
||||
{
|
||||
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->fassungFeedback = '';
|
||||
$this->syncBodyDraft();
|
||||
}
|
||||
|
||||
@@ -154,12 +234,28 @@ public function saveShownText(): void
|
||||
return;
|
||||
}
|
||||
|
||||
$created = app(ContentService::class)->isCommitted($shown);
|
||||
$this->report(function () use ($shown): void {
|
||||
app(ContentService::class)->reviseElementContent($shown, $this->bodyDraft);
|
||||
}, $created
|
||||
? 'Die neue Fassung ist angelegt. Die bisherige bleibt erhalten.'
|
||||
: 'Der Text ist in derselben Fassung gespeichert.');
|
||||
if (! $this->textUnsaved()) {
|
||||
$this->fassungFeedback = 'Der Text ist unverändert. Es gibt nichts zu speichern.';
|
||||
$this->fassungFeedbackError = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
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->syncBodyDraft();
|
||||
}
|
||||
@@ -287,7 +383,7 @@ public function deactivateAction(): Action
|
||||
{
|
||||
return Action::make('deactivate')
|
||||
->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.')
|
||||
->modalSubmitActionLabel('Deaktivieren')
|
||||
->visible(fn (): bool => ContentElementResource::editor())
|
||||
@@ -307,49 +403,141 @@ public function deactivateAction(): Action
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('releaseVersion')
|
||||
->label('Fassung freigeben')
|
||||
->modalHeading('Fassung freigeben')
|
||||
->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.')
|
||||
->modalSubmitActionLabel('Freigeben')
|
||||
->visible(function (): bool {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function releaseVersionAction(): Action
|
||||
{
|
||||
return Action::make('releaseVersion')
|
||||
->label('Fassung freigeben')
|
||||
->modalHeading(function (array $arguments): string {
|
||||
$versionId = (int) ($arguments['version'] ?? 0);
|
||||
$version = $versionId > 0
|
||||
? $this->ownedVersion($versionId)
|
||||
: $this->getRecord()->versions()->where('status', ContentVersionStatus::Entwurf)->orderByDesc('number')->first();
|
||||
|
||||
return $version instanceof ContentElementVersion ? 'Fassung '.$version->number.' freigeben' : 'Fassung freigeben';
|
||||
})
|
||||
->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.')
|
||||
->modalSubmitActionLabel('Freigeben')
|
||||
->visible(function (): bool {
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
|
||||
return ContentElementResource::editor()
|
||||
&& $element->versions()->where('status', ContentVersionStatus::Entwurf)->exists();
|
||||
})
|
||||
->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 Fassung ist freigegeben.');
|
||||
$this->getRecord()->unsetRelation('versions');
|
||||
});
|
||||
}
|
||||
|
||||
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 */
|
||||
$element = $this->getRecord();
|
||||
|
||||
return ContentElementResource::editor()
|
||||
&& $element->versions()->where('status', ContentVersionStatus::Entwurf)->exists();
|
||||
})
|
||||
->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 ElementRevision::publish($element, $data);
|
||||
}, 'Die neue Fassung ist angelegt.');
|
||||
$this->getRecord()->unsetRelation('versions');
|
||||
|
||||
return 'Fassung '.$released->number.' ist freigegeben.';
|
||||
}, 'Die Fassung ist freigegeben.');
|
||||
$this->getRecord()->unsetRelation('versions');
|
||||
}),
|
||||
Action::make('revise')
|
||||
->label('Neue Fassung anlegen')
|
||||
->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();
|
||||
// Die neue Fassung wird gezeigt, sofern dabei kein offener Text verloren geht.
|
||||
if (! $textOffen) {
|
||||
$neueste = $this->getRecord()->versions()->orderByDesc('number')->value('id');
|
||||
$this->fassung = $neueste !== null ? (int) $neueste : $this->fassung;
|
||||
$this->fassungFeedback = '';
|
||||
$this->syncBodyDraft();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return ElementRevision::publish($element, $data);
|
||||
}, 'Die neue Fassung ist angelegt.');
|
||||
$this->getRecord()->unsetRelation('versions');
|
||||
}),
|
||||
];
|
||||
/**
|
||||
* Löschen bleibt Medien ohne Fassung vorbehalten. Bisher nur im separaten Formular, jetzt unter „Weitere Aktionen“.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -440,7 +628,15 @@ private function ownedVersion(int $id): ?ContentElementVersion
|
||||
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);
|
||||
|
||||
@@ -449,58 +645,262 @@ public function saveEditorial(): void
|
||||
$title = trim($this->workingTitle);
|
||||
|
||||
if ($title === '') {
|
||||
$this->editorialFeedback = 'Der Arbeitstitel fehlt.';
|
||||
$this->deskFeedback = 'Der Arbeitstitel fehlt. Er bezeichnet das Medium in der Verwaltung.';
|
||||
$this->redaktionFehlerFeld = 'workingTitle';
|
||||
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$versions = $element->versions()->count();
|
||||
$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,
|
||||
'thumbnail_alt' => $this->thumbnailAlt,
|
||||
'editorial_content_kind_id' => filled($this->kindId) ? (int) $this->kindId : null,
|
||||
], auth()->user());
|
||||
app(PillarService::class)->assign($element, array_map(intval(...), $this->pillarIds));
|
||||
$ids = array_map(intval(...), $this->dimensionIds);
|
||||
IdentityDimensionValue::query()
|
||||
->where('subject_type', $element->getMorphClass())
|
||||
->where('subject_id', $element->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($element, $value, 'direkt');
|
||||
}
|
||||
app(IdentityDimension::class)->replaceOffered($element, array_map(intval(...), $this->dimensionIds));
|
||||
|
||||
$element->refresh();
|
||||
$this->fillEditorial();
|
||||
$this->editorialFeedback = $element->versions()->count() === $versions
|
||||
? 'Gespeichert. Es gibt keine neue Fassung.'
|
||||
: 'Gespeichert. Prüfe die Fassungen, ihre Zahl hat sich geändert.';
|
||||
|
||||
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();
|
||||
app(IdentityProfile::class)->fill($element, [
|
||||
'website_credit' => $this->websiteCredit,
|
||||
'website_alt' => $this->websiteAlt,
|
||||
], auth()->user());
|
||||
$element->refresh();
|
||||
$this->websiteFeedback = app(WebsiteRelease::class)->release($element, auth()->user());
|
||||
$element->refresh();
|
||||
$this->fillEditorial();
|
||||
}
|
||||
|
||||
/**
|
||||
* Legt die Datei ab, die auf der Website laufen soll (zum Beispiel ein Trailer). Die geschützte Inhaltsfassung
|
||||
* bleibt unberührt; öffentlich wird die Datei erst mit der Website-Freigabe.
|
||||
*/
|
||||
public function storeWebsiteFile(): void
|
||||
{
|
||||
abort_unless(ContentElementResource::editor(), 403);
|
||||
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
|
||||
if (! in_array($element->output_class, ['film', 'audio'], true)) {
|
||||
$this->websiteFeedback = 'Eine Website-Datei gibt es nur für Filme und Hörstücke.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->websiteUpload instanceof TemporaryUploadedFile) {
|
||||
$this->websiteFeedback = 'Wähle zuerst eine Datei.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$files = app(PresentationFile::class);
|
||||
$extension = strtolower($this->websiteUpload->getClientOriginalExtension());
|
||||
|
||||
if (! in_array($extension, PresentationFile::EXTENSIONS[$element->output_class], true)) {
|
||||
$this->websiteFeedback = 'Für die Website geht nur '.$files->formats($element->output_class).'. Eine .'.$extension.'-Datei kann der Browser nicht direkt abspielen.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$path = $this->websiteUpload->storeAs('inhalte', 'web-'.bin2hex(random_bytes(6)).'.'.$extension, 'cms_incoming');
|
||||
$this->websiteUpload = null;
|
||||
|
||||
if (! is_string($path)) {
|
||||
$this->websiteFeedback = 'Die Datei wurde nicht übernommen.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$files->store($element, $path);
|
||||
} catch (DomainRuleException $e) {
|
||||
$this->websiteFeedback = $e->getMessage();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$element->refresh();
|
||||
$this->websiteFeedback = filled($element->thumbnail_error)
|
||||
? (string) $element->thumbnail_error
|
||||
: 'Die Website-Datei ist übernommen. Sie ist erst nach „Für die Website freigeben“ öffentlich. Ein bereits freigegebenes Medium zeigt danach die neue Datei.';
|
||||
}
|
||||
|
||||
public function withdrawWebsite(): void
|
||||
@@ -511,7 +911,18 @@ public function withdrawWebsite(): void
|
||||
$element = $this->getRecord();
|
||||
$this->websiteFeedback = app(WebsiteRelease::class)->withdraw($element, auth()->user());
|
||||
$element->refresh();
|
||||
$this->fillEditorial();
|
||||
}
|
||||
|
||||
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.';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -665,8 +1076,10 @@ public function editorialHistory(): array
|
||||
$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',
|
||||
@@ -675,7 +1088,7 @@ public function editorialHistory(): array
|
||||
'thumbnail_alt' => 'Alternativtext',
|
||||
'thumbnail_path' => 'Vorschaubild',
|
||||
'thumbnail_source' => 'Herkunft des Vorschaubilds',
|
||||
'editorial_content_kind_id' => 'Inhaltsart',
|
||||
'editorial_content_kind_id' => 'Fachliche Materialart',
|
||||
];
|
||||
|
||||
return IdentityChange::query()
|
||||
@@ -709,7 +1122,9 @@ private function fillEditorial(): void
|
||||
$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 ?? '');
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
use App\Filament\Resources\LicenseArticles\Pages\ListLicenseArticles;
|
||||
use App\Filament\Resources\LicenseArticles\Pages\ViewLicenseArticle;
|
||||
use App\Filament\Support\CatalogReading;
|
||||
use App\Filament\Support\PublicationReadiness;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\View;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
@@ -53,15 +53,14 @@ public static function getViewAuthorizationResponse(Model $record): Response
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Section::make('Aktueller Stand')->schema([
|
||||
TextEntry::make('stand')->hiddenLabel()->listWithLineBreaks()
|
||||
->state(fn (LicenseArticle $record): array => app(CatalogReading::class)->articleStand($record)),
|
||||
]),
|
||||
Section::make('Pakete und Angebote')->description('Wo dieser Artikel lizenziert wird.')->schema([
|
||||
TextEntry::make('context')->hiddenLabel()->listWithLineBreaks()
|
||||
->state(fn (LicenseArticle $record): array => app(CatalogReading::class)->articleContext($record)),
|
||||
]),
|
||||
return $schema->columns(1)->components([
|
||||
View::make('filament.editorial.license-desk')
|
||||
->viewData(fn (LicenseArticle $record): array => [
|
||||
'stand' => app(CatalogReading::class)->articleStand($record),
|
||||
'kontext' => app(CatalogReading::class)->articleContext($record),
|
||||
'voraussetzungen' => app(PublicationReadiness::class)->forArticle($record),
|
||||
])
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,24 @@
|
||||
namespace App\Filament\Resources\LicenseArticles\Pages;
|
||||
|
||||
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\Support\ListsCatalog;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ListLicenseArticles extends ListRecords
|
||||
{
|
||||
use ListsCatalog;
|
||||
use ReportsDomainRules;
|
||||
|
||||
protected static string $resource = LicenseArticleResource::class;
|
||||
@@ -26,15 +35,118 @@ protected function getHeaderActions(): array
|
||||
return [
|
||||
Action::make('create')
|
||||
->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([
|
||||
TextInput::make('code')->label('Kennung')->required(),
|
||||
TextInput::make('product_line')->label('Produktlinie'),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$this->report(function () use ($data): void {
|
||||
app(ArticleService::class)->create($data['code'], $data['product_line'] ?? null);
|
||||
$article = null;
|
||||
$this->report(function () use ($data, &$article): void {
|
||||
$article = app(ArticleService::class)->create($data['code'], $data['product_line'] ?? null);
|
||||
}, '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;
|
||||
|
||||
use App\Domain\Catalog\ArticleService;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
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\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
|
||||
use App\Filament\Support\AssignsPillars;
|
||||
use App\Filament\Support\CatalogOptions;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Filament\Support\ManagesEditorialSurface;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ViewLicenseArticle extends ViewRecord
|
||||
{
|
||||
use AssignsPillars;
|
||||
use ManagesEditorialSurface;
|
||||
use ReportsDomainRules;
|
||||
|
||||
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 [
|
||||
Action::make('release')
|
||||
->label('Stand veröffentlichen')
|
||||
->schema([
|
||||
Select::make('root')->label('Wurzel')->options(fn (): array => CatalogOptions::readyTargets())->required(),
|
||||
Textarea::make('classification')->label('Einordnung')->required()
|
||||
->helperText('Warum dies derselbe Lizenzartikel bleibt und kein neues Produkt ist.'),
|
||||
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();
|
||||
}),
|
||||
'art' => 'Lizenzartikel',
|
||||
'fuer' => 'den Lizenzartikel',
|
||||
'liste' => 'Lizenzartikel',
|
||||
'zurueck' => 'Zurück zum Lizenzartikel',
|
||||
'typ' => null,
|
||||
'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.',
|
||||
];
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
$this->getRecord()->unsetRelations();
|
||||
|
||||
@@ -28,6 +28,9 @@ class NavigationItemResource extends Resource
|
||||
|
||||
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 $pluralModelLabel = 'Navigation';
|
||||
|
||||
@@ -2,18 +2,22 @@
|
||||
|
||||
namespace App\Filament\Resources\NavigationItems\Pages;
|
||||
|
||||
use App\Filament\Pages\Webpraesenz;
|
||||
use App\Filament\Resources\NavigationItems\NavigationItemResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
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
|
||||
{
|
||||
protected static string $resource = NavigationItemResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
public function mount(): void
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
parent::mount();
|
||||
|
||||
$this->redirect(Webpraesenz::getUrl(['bereich' => 'menues']));
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,13 @@
|
||||
|
||||
namespace App\Filament\Resources\Offers\Pages;
|
||||
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Catalog\OfferStatus;
|
||||
use App\Domain\Catalog\StatusValue;
|
||||
use App\Filament\Resources\Offers\OfferResource;
|
||||
use App\Filament\Support\CatalogLabels;
|
||||
use App\Filament\Support\ListsCatalog;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
@@ -12,6 +17,7 @@
|
||||
|
||||
class ListOffers extends ListRecords
|
||||
{
|
||||
use ListsCatalog;
|
||||
use ReportsDomainRules;
|
||||
|
||||
protected static string $resource = OfferResource::class;
|
||||
@@ -24,13 +30,83 @@ public function getSubheading(): string|Htmlable|null
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('create')->label('Angebot anlegen')->schema([
|
||||
TextInput::make('name')->label('Name')->required(),
|
||||
])->action(function (array $data): void {
|
||||
$this->report(function () use ($data): void {
|
||||
app(OfferService::class)->create($data['name']);
|
||||
}, 'Das Angebot ist angelegt.');
|
||||
}),
|
||||
Action::make('create')->label('Angebot anlegen')
|
||||
->modalHeading('Neues Angebot')
|
||||
->modalDescription('Der Name genügt. Positionen, Vergabe und Preis legst du danach am Angebot fest.')
|
||||
->modalSubmitActionLabel('Angebot anlegen')
|
||||
->schema([
|
||||
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;
|
||||
|
||||
use App\Domain\Catalog\BundleService;
|
||||
use App\Domain\Catalog\BundleVersion;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Catalog\OfferStatus;
|
||||
use App\Domain\Catalog\OfferVersion;
|
||||
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\Support\CatalogLabels;
|
||||
use App\Filament\Support\CatalogOptions;
|
||||
use App\Filament\Support\PublicationReadiness;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
@@ -17,24 +28,105 @@
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
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
|
||||
{
|
||||
use ReportsDomainRules;
|
||||
|
||||
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
|
||||
{
|
||||
return [
|
||||
Action::make('activate')->label('Fassung aktivieren')->schema([
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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([
|
||||
'kauf' => 'Kauf',
|
||||
'auf_abruf' => 'Auf Abruf',
|
||||
'bei_registrierung' => 'Bei Registrierung',
|
||||
])->required(),
|
||||
TextInput::make('price_cents')->label('Preis in Cent')->numeric()
|
||||
->helperText('Nur bei einem Kauf. 500 bedeutet 5,00 €.'),
|
||||
TextInput::make('price_euro')->label('Preis in Euro')->suffix('€')
|
||||
->helperText('Nur bei einem Kauf, zum Beispiel 49,00.'),
|
||||
Select::make('composition_version_id')->label('Programmfassung, die abgedeckt sein muss')
|
||||
->options(function (): array {
|
||||
return CompositionVersion::query()
|
||||
@@ -52,14 +144,18 @@ protected function getHeaderActions(): array
|
||||
'article' => 'Lizenzartikel',
|
||||
'bundle' => 'Paketfassung',
|
||||
])->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'),
|
||||
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'),
|
||||
Select::make('rights_id')->label('Rechte')->options(fn (): array => CatalogOptions::rights())->required(),
|
||||
])->minItems(1),
|
||||
])->action(function (array $data): void {
|
||||
$this->report(function () use ($data): void {
|
||||
])->minItems(1)->addActionLabel('Position hinzufügen'),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$this->report(function () use ($data): string {
|
||||
/** @var Offer $offer */
|
||||
$offer = $this->getRecord();
|
||||
$lines = [];
|
||||
@@ -74,16 +170,270 @@ protected function getHeaderActions(): array
|
||||
];
|
||||
}
|
||||
|
||||
app(OfferService::class)->activate($offer, $lines, [
|
||||
'grant_kind' => $data['grant_kind'],
|
||||
'price_cents' => $data['price_cents'] === null || $data['price_cents'] === '' ? null : (int) $data['price_cents'],
|
||||
'holder_kind' => 'person',
|
||||
'composition_version_id' => filled($data['composition_version_id'] ?? null) ? (int) $data['composition_version_id'] : null,
|
||||
]);
|
||||
// Voraussetzung: Jeder Artikel der Positionen hat einen veröffentlichten Stand, sonst erhielten Käufer nichts.
|
||||
$articleIds = [];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$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.');
|
||||
$this->getRecord()->unsetRelations();
|
||||
$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';
|
||||
|
||||
/** 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 $pluralModelLabel = 'Seiten';
|
||||
@@ -38,11 +41,9 @@ public static function form(Schema $schema): Schema
|
||||
return $schema->components([
|
||||
Section::make('Seite und Suchmaschinen')
|
||||
->description('Adresse, Titel für Suchmaschinen und Zuordnung zu Themenbereichen.')
|
||||
->collapsible()
|
||||
->collapsed(fn (string $operation): bool => $operation === 'edit')
|
||||
->persistCollapsed()
|
||||
->columns(2)
|
||||
->columnSpanFull()
|
||||
->extraAttributes(fn ($livewire): array => ['class' => self::registerClass($livewire, 'einstellungen')])
|
||||
->schema([
|
||||
TextInput::make('path')
|
||||
->label('Pfad')
|
||||
@@ -63,15 +64,26 @@ public static function form(Schema $schema): Schema
|
||||
->columns(['default' => 1, 'lg' => 2]),
|
||||
]),
|
||||
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()
|
||||
->extraAttributes(['class' => 'luf-page-content'])
|
||||
->extraAttributes(fn ($livewire): array => ['class' => 'luf-page-content '.self::registerClass($livewire, 'inhalt')])
|
||||
->schema([
|
||||
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
|
||||
{
|
||||
return $table
|
||||
|
||||
@@ -6,16 +6,19 @@
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Filament\Resources\Pages\PageResource;
|
||||
use App\Filament\Support\ChoosesWebsiteImages;
|
||||
use App\Filament\Support\ReportsSectionErrors;
|
||||
use App\Filament\Support\SectionEditor;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class CreatePage extends CreateRecord
|
||||
{
|
||||
use ChoosesWebsiteImages;
|
||||
use ReportsSectionErrors;
|
||||
|
||||
protected static string $resource = PageResource::class;
|
||||
@@ -28,6 +31,12 @@ class CreatePage extends CreateRecord
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -6,17 +6,23 @@
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Filament\Resources\Pages\PageResource;
|
||||
use App\Filament\Support\ChoosesWebsiteImages;
|
||||
use App\Filament\Support\ReportsSectionErrors;
|
||||
use App\Filament\Support\SectionEditor;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Filament\Schemas\Components\Group;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Attributes\Url;
|
||||
|
||||
class EditPage extends EditRecord
|
||||
{
|
||||
use ChoosesWebsiteImages;
|
||||
use ReportsSectionErrors;
|
||||
|
||||
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. */
|
||||
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
|
||||
{
|
||||
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 [];
|
||||
}
|
||||
|
||||
return $revision === null
|
||||
? '#'
|
||||
: route('pages.preview.devices', $revision);
|
||||
})
|
||||
->openUrlInNewTab(),
|
||||
Action::make('publish')
|
||||
->label('Veröffentlichen')
|
||||
->icon('heroicon-o-globe-alt')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Seite veröffentlichen?')
|
||||
->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.')
|
||||
->modalSubmitActionLabel('Speichern und veröffentlichen')
|
||||
->visible(fn (): bool => auth()->user()?->can('publish', $this->record) ?? 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);
|
||||
public function publishAction(): Action
|
||||
{
|
||||
return Action::make('publish')
|
||||
->label('Veröffentlichen')
|
||||
->icon('heroicon-o-globe-alt')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Seite veröffentlichen?')
|
||||
->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.')
|
||||
->modalSubmitActionLabel('Speichern und veröffentlichen')
|
||||
->visible(fn (): bool => auth()->user()?->can('publish', $this->record) ?? 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');
|
||||
$revision = $this->record->latestRevision;
|
||||
abort_if($revision === null, 404);
|
||||
$service->publish($this->record, $revision);
|
||||
$this->record->refresh();
|
||||
$this->record->unsetRelation('latestRevision');
|
||||
$revision = $this->record->latestRevision;
|
||||
abort_if($revision === null, 404);
|
||||
$service->publish($this->record, $revision);
|
||||
$this->record->refresh();
|
||||
|
||||
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(),
|
||||
];
|
||||
Notification::make()->title('Seite veröffentlicht')->success()->send();
|
||||
});
|
||||
}
|
||||
|
||||
protected function getSaveFormAction(): Action
|
||||
|
||||
@@ -2,18 +2,22 @@
|
||||
|
||||
namespace App\Filament\Resources\Pages\Pages;
|
||||
|
||||
use App\Filament\Pages\Webpraesenz;
|
||||
use App\Filament\Resources\Pages\PageResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
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
|
||||
{
|
||||
protected static string $resource = PageResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
public function mount(): void
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
parent::mount();
|
||||
|
||||
$this->redirect(Webpraesenz::getUrl());
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,9 @@ class RevisionsRelationManager extends RelationManager
|
||||
|
||||
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
|
||||
{
|
||||
return $table
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Filament\Resources\Pillars\Pages;
|
||||
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Catalog\PillarService;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Resources\Pillars\PillarResource;
|
||||
use App\Filament\Support\ListsCatalog;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
@@ -13,13 +15,14 @@
|
||||
|
||||
class ListPillars extends ListRecords
|
||||
{
|
||||
use ListsCatalog;
|
||||
use ReportsDomainRules;
|
||||
|
||||
protected static string $resource = PillarResource::class;
|
||||
|
||||
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
|
||||
@@ -27,6 +30,9 @@ protected function getHeaderActions(): array
|
||||
return [
|
||||
Action::make('create')
|
||||
->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())
|
||||
->schema([
|
||||
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;
|
||||
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Catalog\RightsProfile;
|
||||
use App\Filament\Resources\RightsProfiles\RightsProfileResource;
|
||||
use App\Filament\Support\CatalogLabels;
|
||||
use App\Filament\Support\ListsCatalog;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
@@ -14,6 +17,7 @@
|
||||
|
||||
class ListRightsProfiles extends ListRecords
|
||||
{
|
||||
use ListsCatalog;
|
||||
use ReportsDomainRules;
|
||||
|
||||
protected static string $resource = RightsProfileResource::class;
|
||||
@@ -26,36 +30,78 @@ public function getSubheading(): string|Htmlable|null
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('create')->label('Rechteprofil anlegen')->schema([
|
||||
TextInput::make('name')->label('Name')->required(),
|
||||
Select::make('purpose')->label('Zweck')->options([
|
||||
'ehrenamtlich' => 'Ehrenamtlich',
|
||||
'kommerziell' => 'Kommerziell',
|
||||
'institutionell' => 'Institutionell',
|
||||
])->required(),
|
||||
CheckboxList::make('capabilities')->label('Fähigkeiten')->options([
|
||||
'film:streamen' => 'Film ansehen',
|
||||
'film:laden' => 'Film herunterladen',
|
||||
'audio:streamen' => 'Hörstück ansehen',
|
||||
'document:ansehen' => 'Dokument ansehen',
|
||||
'document:laden' => 'Dokument herunterladen',
|
||||
'pdf:ansehen' => 'PDF ansehen',
|
||||
'pdf:laden' => 'PDF herunterladen',
|
||||
'text:ansehen' => 'Text ansehen',
|
||||
'bild:ansehen' => 'Bild ansehen',
|
||||
])->required(),
|
||||
])->action(function (array $data): void {
|
||||
$this->report(function () use ($data): void {
|
||||
$capabilities = [];
|
||||
Action::make('create')->label('Rechteprofil anlegen')
|
||||
->modalHeading('Neues Rechteprofil')
|
||||
->modalDescription('Zweck und erlaubte Handlungen. Ein Angebot verbindet das Profil später mit Artikeln.')
|
||||
->modalSubmitActionLabel('Rechteprofil anlegen')
|
||||
->schema([
|
||||
TextInput::make('name')->label('Name')->required(),
|
||||
Select::make('purpose')->label('Zweck')->options([
|
||||
'ehrenamtlich' => 'Ehrenamtlich',
|
||||
'kommerziell' => 'Kommerziell',
|
||||
'institutionell' => 'Institutionell',
|
||||
])->required(),
|
||||
CheckboxList::make('capabilities')->label('Fähigkeiten')->options(CatalogLabels::FAEHIGKEITEN)->required(),
|
||||
])->action(function (array $data): void {
|
||||
$this->report(function () use ($data): void {
|
||||
$capabilities = [];
|
||||
|
||||
foreach ($data['capabilities'] as $entry) {
|
||||
[$class, $action] = explode(':', $entry, 2);
|
||||
$capabilities[$class][] = $action;
|
||||
}
|
||||
foreach ($data['capabilities'] as $entry) {
|
||||
[$class, $action] = explode(':', $entry, 2);
|
||||
$capabilities[$class][] = $action;
|
||||
}
|
||||
|
||||
app(OfferService::class)->createRightsProfile($data['name'], $data['purpose'], $capabilities);
|
||||
}, 'Das Rechteprofil ist angelegt.');
|
||||
}),
|
||||
app(OfferService::class)->createRightsProfile($data['name'], $data['purpose'], $capabilities);
|
||||
}, '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;
|
||||
|
||||
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\Support\CatalogLabels;
|
||||
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
|
||||
{
|
||||
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;
|
||||
|
||||
use App\Domain\Identity\AccountStatus;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Filament\Resources\Users\UserResource;
|
||||
use App\Filament\Support\ListsCatalog;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListUsers extends ListRecords
|
||||
{
|
||||
use ListsCatalog;
|
||||
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
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';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Catalog\PillarService;
|
||||
|
||||
/**
|
||||
* Fachliche Säulen im Redaktionsmanager von Modul, Programm und Lizenzartikel (wie bei Medien): Die Auswahl kommt aus
|
||||
* der zentralen Säulenverwaltung, die Zuordnung ersetzt die bisherige vollständig und bleibt beim Speichern anderer
|
||||
* Angaben erhalten, weil der gespeicherte Stand geladen und mitgeschrieben wird.
|
||||
*
|
||||
* Eine Zuordnung veröffentlicht nichts: Ob eine Säule eine Themenseite hat, entscheidet allein die Säulenverwaltung.
|
||||
*/
|
||||
trait AssignsPillars
|
||||
{
|
||||
/** @var list<int|string> */
|
||||
public array $pillarIds = [];
|
||||
|
||||
/**
|
||||
* @return array{legend: string, model: string, values: list<array{id: int, label: string}>}|null
|
||||
*/
|
||||
public function pillarGroup(): ?array
|
||||
{
|
||||
$values = Pillar::query()->orderBy('sort_order')->orderBy('name')->get(['id', 'name'])
|
||||
->map(fn (Pillar $pillar): array => ['id' => (int) $pillar->id, 'label' => (string) $pillar->name])
|
||||
->all();
|
||||
|
||||
return $values === [] ? null : ['legend' => 'Fachliche Säulen', 'model' => 'pillarIds', 'values' => $values];
|
||||
}
|
||||
|
||||
protected function loadPillarIds(Composition|LicenseArticle $subject): void
|
||||
{
|
||||
$this->pillarIds = $subject->pillars()->pluck('pillars.id')->map(fn (mixed $id): string => (string) (int) $id)->all();
|
||||
}
|
||||
|
||||
protected function persistPillarIds(Composition|LicenseArticle $subject): void
|
||||
{
|
||||
app(PillarService::class)->assign($subject, array_map(intval(...), $this->pillarIds));
|
||||
}
|
||||
|
||||
protected function pillarsUnsaved(Composition|LicenseArticle $subject): bool
|
||||
{
|
||||
$stored = $subject->pillars()->pluck('pillars.id')->map(fn (mixed $id): int => (int) $id)->all();
|
||||
$current = array_map(intval(...), $this->pillarIds);
|
||||
sort($stored);
|
||||
sort($current);
|
||||
|
||||
return $stored !== $current;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
/**
|
||||
* Werte der gemeinsamen Bestandsliste (ShowsBestand, Ansicht filament.verwaltung.bestand).
|
||||
*/
|
||||
final class Bestand
|
||||
{
|
||||
/** So viele Einträge zeigt eine Liste zunächst und je „Weitere anzeigen“. */
|
||||
public const SCHRITT = 50;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Catalog\OfferVersion;
|
||||
|
||||
/**
|
||||
* Lesbare Bezeichnungen für Katalogangaben, gemeinsam für Listen und Objektseiten (Rechteprofil, Angebot).
|
||||
*/
|
||||
final class CatalogLabels
|
||||
{
|
||||
/** Fähigkeiten eines Rechteprofils; dieselben Werte wie im Anlegedialog. */
|
||||
public const FAEHIGKEITEN = [
|
||||
'film:streamen' => 'Film ansehen',
|
||||
'film:laden' => 'Film herunterladen',
|
||||
'audio:streamen' => 'Hörstück ansehen',
|
||||
'document:ansehen' => 'Dokument ansehen',
|
||||
'document:laden' => 'Dokument herunterladen',
|
||||
'pdf:ansehen' => 'PDF ansehen',
|
||||
'pdf:laden' => 'PDF herunterladen',
|
||||
'text:ansehen' => 'Text ansehen',
|
||||
'bild:ansehen' => 'Bild ansehen',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param array<string, mixed>|null $capabilities ['film' => ['streamen'], …]
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function faehigkeiten(?array $capabilities): array
|
||||
{
|
||||
$labels = [];
|
||||
|
||||
foreach ($capabilities ?? [] as $class => $actions) {
|
||||
foreach ((array) $actions as $action) {
|
||||
$labels[] = self::FAEHIGKEITEN[$class.':'.$action] ?? $class.': '.$action;
|
||||
}
|
||||
}
|
||||
|
||||
return $labels;
|
||||
}
|
||||
|
||||
public static function zweck(?string $purpose): string
|
||||
{
|
||||
return match ((string) $purpose) {
|
||||
'ehrenamtlich' => 'Ehrenamtlich',
|
||||
'kommerziell' => 'Kommerziell',
|
||||
'institutionell' => 'Institutionell',
|
||||
default => (string) $purpose,
|
||||
};
|
||||
}
|
||||
|
||||
public static function vergabe(OfferVersion $version): string
|
||||
{
|
||||
$kind = match ($version->grant_kind) {
|
||||
'kauf' => 'Kauf',
|
||||
'auf_abruf' => 'Auf Abruf',
|
||||
'bei_registrierung' => 'Bei Registrierung',
|
||||
default => (string) $version->grant_kind,
|
||||
};
|
||||
|
||||
return $version->price_cents === null ? $kind : $kind.' · '.number_format($version->price_cents / 100, 2, ',', '.').' €';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Cms\Catalog\PublicMaterialReader;
|
||||
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||
use App\Http\Controllers\ContentPreviewController;
|
||||
|
||||
/**
|
||||
* Gemeinsamer visueller Picker (Dokument 14 §9): Zustand, Suche, Treffer, Betrachten, Markieren und Detail. Die
|
||||
* Ansicht ist filament.verwaltung.picker. Die Seite bestimmt Zweck, Titel, Typen, Mehrfachauswahl und was
|
||||
* „Übernehmen“ bewirkt (pickerAllowsMany, pickerKinds, pickerTitle, pickerConfirmLabel, pickerKontext, confirmPicker,
|
||||
* closePicker). Genutzt von der Redaktion (ManagesEditorialSurface) und vom CMS (ChoosesWebsiteImages).
|
||||
*/
|
||||
trait ChoosesMedia
|
||||
{
|
||||
public bool $pickerOpen = false;
|
||||
|
||||
public string $pickerPurpose = 'praesentation';
|
||||
|
||||
public string $pickerQuery = '';
|
||||
|
||||
public string $pickerKind = 'alle';
|
||||
|
||||
public string $pickerDimension = '';
|
||||
|
||||
/** Filter „Fachliche Säule“ (Kennung der Säule aus der zentralen Säulenverwaltung). */
|
||||
public string $pickerSaeule = '';
|
||||
|
||||
/** Filter „Fachliche Materialart“ (Kennung), gleiche Regel wie Medieneditor und Medienfilter. */
|
||||
public string $pickerMaterialart = '';
|
||||
|
||||
public string $pickerInspected = '';
|
||||
|
||||
public string $pickerSelected = '';
|
||||
|
||||
/** @var array<string, string> Ziel => Titel; bleibt bei Suche und Filter erhalten */
|
||||
public array $pickerMarked = [];
|
||||
|
||||
public string $presentationRole = 'titelbild';
|
||||
|
||||
public bool $bindToVersion = false;
|
||||
|
||||
public ?string $replacingKey = null;
|
||||
|
||||
abstract public function pickerAllowsMany(): bool;
|
||||
|
||||
abstract public function closePicker(): void;
|
||||
|
||||
abstract public function confirmPicker(): void;
|
||||
|
||||
public function inspectPicker(string $target, bool $mark = false): void
|
||||
{
|
||||
$this->pickerInspected = $target;
|
||||
|
||||
if ($mark) {
|
||||
$this->markPicker($target, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function togglePick(string $target): void
|
||||
{
|
||||
$this->markPicker($target, ! isset($this->pickerMarked[$target]));
|
||||
}
|
||||
|
||||
public function markPicker(string $target, bool $on): void
|
||||
{
|
||||
if (! $on) {
|
||||
unset($this->pickerMarked[$target]);
|
||||
|
||||
if ($this->pickerSelected === $target) {
|
||||
$this->pickerSelected = '';
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$row = app(EditorialCatalog::class)->rowForTarget($target, $this->pickerExceptId(), allowDraft: true);
|
||||
|
||||
if ($row === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->pickerAllowsMany()) {
|
||||
$this->pickerMarked = [];
|
||||
$this->pickerSelected = $target;
|
||||
}
|
||||
|
||||
$this->pickerMarked[$target] = (string) $row['title'];
|
||||
|
||||
if ($this->pickerInspected === '') {
|
||||
$this->pickerInspected = $target;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{items: list<array<string, mixed>>, more: bool}
|
||||
*/
|
||||
public function pickerResult(): array
|
||||
{
|
||||
if (! $this->pickerOpen) {
|
||||
return ['items' => [], 'more' => false];
|
||||
}
|
||||
|
||||
if ($this->pickerPurpose === 'aufbau') {
|
||||
return $this->filterByMaterialart(app(EditorialCatalog::class)->browse(
|
||||
$this->pickerQuery,
|
||||
$this->pickerKind,
|
||||
$this->pickerDimension,
|
||||
$this->pickerExceptId(),
|
||||
false,
|
||||
ctype_digit($this->pickerSaeule) ? (int) $this->pickerSaeule : 0,
|
||||
));
|
||||
}
|
||||
|
||||
$result = app(EditorialCatalog::class)->presentationBrowse($this->pickerQuery, $this->pickerKind);
|
||||
$result = $this->filterByMaterialart($result);
|
||||
|
||||
// CMS: nur Bilder, die als Website-Bild wählbar sind (keine vertraulichen Arten, nicht archiviert).
|
||||
if ($this->pickerPurpose === 'website-bild') {
|
||||
$ids = array_values(array_filter(array_map(fn (array $item): int => (int) ($item['element_id'] ?? 0), $result['items'])));
|
||||
$elements = ContentElement::query()->with('editorialContentKind')->whereKey($ids)->get()->keyBy('id');
|
||||
$result['items'] = array_values(array_filter($result['items'], function (array $item) use ($elements): bool {
|
||||
$element = $elements->get((int) ($item['element_id'] ?? 0));
|
||||
|
||||
return $element !== null && WebsiteImage::isSelectable($element);
|
||||
}));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function pickerDetail(): ?array
|
||||
{
|
||||
$target = $this->pickerInspected !== '' ? $this->pickerInspected : $this->pickerSelected;
|
||||
|
||||
if ($target === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$row = app(EditorialCatalog::class)->rowForTarget($target, $this->pickerExceptId(), allowDraft: true);
|
||||
|
||||
if ($row === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$row['playback'] = null;
|
||||
$row['file_url'] = null;
|
||||
$elementId = isset($row['element_id']) ? (int) $row['element_id'] : 0;
|
||||
|
||||
if (preg_match('/^element:(\d+)$/', (string) $row['target'], $match) === 1) {
|
||||
$version = ContentElementVersion::query()->with('element.editorialContentKind')->find($match[1]);
|
||||
|
||||
if ($version instanceof ContentElementVersion) {
|
||||
$row['playback'] = app(ContentPreviewController::class)->playback($version);
|
||||
}
|
||||
}
|
||||
|
||||
$element = $elementId > 0 ? ContentElement::query()->with(['editorialContentKind', 'pillars'])->find($elementId) : null;
|
||||
|
||||
if ($element instanceof ContentElement) {
|
||||
$row['visibility'] = app(PublicMaterialReader::class)->visibilityNote($element);
|
||||
$row['released'] = $element->website_released_at !== null;
|
||||
$row['output_label'] = PublicMaterialReader::outputLabel((string) $element->output_class);
|
||||
$row['pillars'] = $element->pillars->pluck('name')->all();
|
||||
$row['material'] = $element->editorialContentKind?->label;
|
||||
$row['usage'] = app(CatalogReading::class)->elementUsage($element);
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{target: string, label: string, current: bool}>
|
||||
*/
|
||||
public function pickerVersions(): array
|
||||
{
|
||||
$detail = $this->pickerDetail();
|
||||
|
||||
if ($detail === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$options = app(EditorialCatalog::class)->alternatives((string) ($detail['identity'] ?? ''), $this->pickerExceptId());
|
||||
|
||||
if ($options === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$current = $options[array_key_last($options)]['target'];
|
||||
|
||||
return array_map(fn (array $option): array => $option + ['current' => $option['target'] === $current], $options);
|
||||
}
|
||||
|
||||
protected function pickerExceptId(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function resetPicker(string $purpose): void
|
||||
{
|
||||
$this->pickerPurpose = $purpose;
|
||||
$this->pickerOpen = true;
|
||||
$this->pickerQuery = '';
|
||||
$this->pickerDimension = '';
|
||||
$this->pickerSaeule = '';
|
||||
$this->pickerMaterialart = '';
|
||||
$this->pickerInspected = '';
|
||||
$this->pickerSelected = '';
|
||||
$this->pickerMarked = [];
|
||||
$this->replacingKey = null;
|
||||
$this->bindToVersion = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fachliche Materialarten, nach denen der Picker Medien eingrenzen kann (Kontext Medium).
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function pickerMaterialarten(): array
|
||||
{
|
||||
return app(EditorialVocabulary::class)->kindFilterOptions('medium', $this->pickerMaterialart);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{items: list<array<string, mixed>>, more: bool} $result
|
||||
* @return array{items: list<array<string, mixed>>, more: bool}
|
||||
*/
|
||||
private function filterByMaterialart(array $result): array
|
||||
{
|
||||
if (! ctype_digit($this->pickerMaterialart)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$ids = array_values(array_filter(array_map(fn (array $item): int => (int) ($item['element_id'] ?? 0), $result['items'])));
|
||||
$passend = ContentElement::query()->whereKey($ids)->where('editorial_content_kind_id', (int) $this->pickerMaterialart)->pluck('id')->map(fn ($id): int => (int) $id)->all();
|
||||
$result['items'] = array_values(array_filter($result['items'], fn (array $item): bool => in_array((int) ($item['element_id'] ?? 0), $passend, true)));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Säulen für den Picker-Filter, in der Reihenfolge der Säulenverwaltung.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function pickerSaeulen(): array
|
||||
{
|
||||
return Pillar::query()->orderBy('sort_order')->orderBy('name')->pluck('name', 'id')
|
||||
->mapWithKeys(fn (string $name, int|string $id): array => [(string) $id => $name])->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Einordnungsfilter des Pickers: dieselbe Filterregel wie Medien- und Kompositionslisten (verwendete inaktive Werte
|
||||
* bleiben auffindbar, ein gewählter Filter bleibt sichtbar).
|
||||
*
|
||||
* @return list<array{label: string, values: list<array{id: int, label: string}>}>
|
||||
*/
|
||||
public function pickerDimensionGroups(): array
|
||||
{
|
||||
return app(EditorialVocabulary::class)->dimensionFilterGroups(ctype_digit($this->pickerDimension) ? [(int) $this->pickerDimension] : []);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||
use App\Domain\Media\CompositionStill;
|
||||
use App\Domain\Media\FilmStill;
|
||||
use App\Domain\Media\WebsiteMedia;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
/**
|
||||
* Bildauswahl im CMS über den gemeinsamen visuellen Picker (Dokument 14 §9) statt einer eigenen Auswahlliste.
|
||||
* Ein Bildfeld (filament.cms.bild-feld) öffnet den Picker mit seinem Formularpfad; „Bild übernehmen“ schreibt die
|
||||
* Kennung des Mediums in genau dieses Feld, auch im geöffneten Bausteindialog. Gespeichert wird weiterhin nur mit dem
|
||||
* Seitenentwurf. Die Auswahl gibt kein Bild für die Website frei.
|
||||
*/
|
||||
trait ChoosesWebsiteImages
|
||||
{
|
||||
use ChoosesMedia;
|
||||
|
||||
/** Formularpfad des Bildfelds, in das die Auswahl übernommen wird. */
|
||||
public ?string $bildZiel = null;
|
||||
|
||||
public function openWebsiteImagePicker(string $pfad): void
|
||||
{
|
||||
if (preg_match('/^(data|mountedActions\.\d+\.data)(\.[A-Za-z0-9_-]+)+$/', $pfad) !== 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->resetPicker('website-bild');
|
||||
$this->pickerKind = 'bild';
|
||||
$this->bildZiel = $pfad;
|
||||
$this->forceRenderForPicker();
|
||||
}
|
||||
|
||||
/**
|
||||
* Medien- und Materialkarte: das Vorschaubild des Films als Bild für die Website übernehmen. Es entsteht ein Bild
|
||||
* im Medienmanager (einmal gespeichert), das im Bildfeld ausgewählt wird. Die Datei des Films bleibt geschützt.
|
||||
*/
|
||||
public function adoptFilmThumbnail(string $pfad, int $elementId): void
|
||||
{
|
||||
$this->adoptFilmStill($pfad, $elementId, fn (FilmStill $stills, ContentElement $film): ContentElement => $stills->fromThumbnail($film, auth('staff')->user()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Medien- und Materialkarte: eine Stelle des Films wählen und als Bild für die Website übernehmen.
|
||||
*/
|
||||
public function adoptFilmFrame(string $pfad, int $elementId, string $sekunde): void
|
||||
{
|
||||
if (! is_numeric($sekunde)) {
|
||||
Notification::make()->danger()->title('Bitte eine Zeitposition in Sekunden angeben.')->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->adoptFilmStill($pfad, $elementId, fn (FilmStill $stills, ContentElement $film): ContentElement => $stills->fromSecond($film, (float) $sekunde, auth('staff')->user()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Programm- und Modulkarte: das Vorschaubild des Programms oder Moduls als Bild für die Website übernehmen
|
||||
* (Bild-Medium im Medienmanager, einmal kopiert).
|
||||
*/
|
||||
public function adoptCompositionThumbnail(string $pfad, int $compositionId): void
|
||||
{
|
||||
abort_unless(ContentElementResource::editor(), 403);
|
||||
|
||||
if ($this->imageTargetIsInvalid($pfad)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$composition = Composition::query()->find($compositionId);
|
||||
|
||||
if (! $composition instanceof Composition) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stills = app(CompositionStill::class);
|
||||
|
||||
try {
|
||||
$still = $stills->fromThumbnail($composition, auth('staff')->user());
|
||||
} catch (DomainRuleException $exception) {
|
||||
Notification::make()->danger()->title($exception->getMessage())->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
data_set($this, $pfad, $still->id);
|
||||
$this->announceAdoptedStill($still, $stills->reused, 'Dieses Vorschaubild war schon übernommen.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable(FilmStill, ContentElement): ContentElement $make
|
||||
*/
|
||||
private function adoptFilmStill(string $pfad, int $elementId, callable $make): void
|
||||
{
|
||||
abort_unless(ContentElementResource::editor(), 403);
|
||||
|
||||
if ($this->imageTargetIsInvalid($pfad)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$film = ContentElement::query()->with('editorialContentKind')->find($elementId);
|
||||
|
||||
if (! $film instanceof ContentElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stills = app(FilmStill::class);
|
||||
|
||||
try {
|
||||
$still = $make($stills, $film);
|
||||
} catch (DomainRuleException $exception) {
|
||||
Notification::make()->danger()->title($exception->getMessage())->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
data_set($this, $pfad, $still->id);
|
||||
$this->announceAdoptedStill($still, $stills->reused, 'Diese Stelle war schon übernommen.');
|
||||
}
|
||||
|
||||
/** Nur das Bildfeld eines Widgets oder Abschnitts ist ein zulässiges Ziel (…image). */
|
||||
private function imageTargetIsInvalid(string $pfad): bool
|
||||
{
|
||||
return preg_match('/^(data|mountedActions\.\d+\.data)(\.[A-Za-z0-9_-]+)+\.image$/', $pfad) !== 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Meldung nach dem tatsächlichen Stand des Bildes: neu angelegt, schon vorhanden und freigegeben, wird verarbeitet
|
||||
* oder Website-Freigabe zurückgenommen (bleibt zurückgenommen).
|
||||
*/
|
||||
private function announceAdoptedStill(ContentElement $still, bool $reused, string $reusedText): void
|
||||
{
|
||||
$title = ($still->display_title ?: $still->working_title);
|
||||
|
||||
if (! $reused) {
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Im Medienmanager angelegt: „'.$title.'“')
|
||||
->body('Das Bild ist als Kartenbild ausgewählt. Nach der Verarbeitung wird es für die Website freigegeben; dort lässt sich die Freigabe auch zurücknehmen.')
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (app(WebsiteMedia::class)->present($still) !== null) {
|
||||
Notification::make()->success()->title('Bereits im Medienmanager: „'.$title.'“')->body($reusedText.' Das Bild ist als Kartenbild ausgewählt.')->send();
|
||||
} elseif (blank($still->thumbnail_path) && blank($still->thumbnail_error)) {
|
||||
Notification::make()->success()->title('Bereits im Medienmanager: „'.$title.'“')->body('Das Bild wird noch verarbeitet und danach für die Website freigegeben.')->send();
|
||||
} else {
|
||||
Notification::make()->warning()->title('Bild ausgewählt, aber nicht für die Website freigegeben: „'.$title.'“')
|
||||
->body($reusedText.' Die Website-Freigabe wurde zurückgenommen. Das Bild erscheint öffentlich erst wieder, wenn sie im Medienmanager (Reiter „Website“) erneut gegeben wird.')
|
||||
->persistent()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filament rendert bei offenen Aktionsdialogen nur den Dialogteil neu; der Picker liegt darüber und braucht die
|
||||
* ganze Seite.
|
||||
*/
|
||||
public function hydrateChoosesWebsiteImages(): void
|
||||
{
|
||||
if ($this->pickerOpen) {
|
||||
$this->forceRenderForPicker();
|
||||
}
|
||||
}
|
||||
|
||||
public function pickerAllowsMany(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function closePicker(): void
|
||||
{
|
||||
$this->pickerOpen = false;
|
||||
$this->pickerSelected = '';
|
||||
$this->pickerInspected = '';
|
||||
$this->pickerMarked = [];
|
||||
$this->bildZiel = null;
|
||||
$this->forceRenderForPicker();
|
||||
}
|
||||
|
||||
public function confirmPicker(): void
|
||||
{
|
||||
$target = array_key_first($this->pickerMarked);
|
||||
$ziel = $this->bildZiel;
|
||||
|
||||
if ($target === null || $ziel === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$row = app(EditorialCatalog::class)->rowForTarget((string) $target, 0, allowDraft: true);
|
||||
$element = isset($row['element_id']) ? ContentElement::query()->find((int) $row['element_id']) : null;
|
||||
|
||||
if (! $element instanceof ContentElement || ! WebsiteImage::isSelectable($element)) {
|
||||
Notification::make()->danger()->title('Dieses Medium kann nicht als Website-Bild gewählt werden.')->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
data_set($this, $ziel, $element->id);
|
||||
$this->closePicker();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function pickerKinds(): array
|
||||
{
|
||||
return ['bild' => 'Bilder'];
|
||||
}
|
||||
|
||||
public function pickerTitle(): string
|
||||
{
|
||||
return 'Bild aus dem Medienmanager';
|
||||
}
|
||||
|
||||
public function pickerConfirmLabel(): string
|
||||
{
|
||||
return 'Bild übernehmen';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{art: string, titel: string}
|
||||
*/
|
||||
public function pickerKontext(): array
|
||||
{
|
||||
$pfad = property_exists($this, 'record') && is_object($this->record ?? null) ? (string) ($this->record->path ?? '') : '';
|
||||
|
||||
return ['art' => 'die Seite', 'titel' => $pfad !== '' ? $pfad : 'neue Seite'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function presentationRoleOptions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function pickerReplacing(): ?array
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
private function forceRenderForPicker(): void
|
||||
{
|
||||
if (method_exists($this, 'forceRender')) {
|
||||
$this->forceRender();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,10 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
|
||||
return $this->draftCompositionRow((int) $draftMatch[1], $exceptCompositionId, $allowSelf);
|
||||
}
|
||||
|
||||
if (preg_match('/^medium:(\d+)$/', $target, $mediumMatch) === 1) {
|
||||
return $this->rowForPresentationMedium((int) $mediumMatch[1]);
|
||||
}
|
||||
|
||||
if (preg_match('/^(element|composition):(\d+)$/', $target, $match) !== 1) {
|
||||
return null;
|
||||
}
|
||||
@@ -210,6 +214,8 @@ public function search(string $query, string $scope, int $exceptCompositionId):
|
||||
|
||||
$builder->where('working_title', 'like', $like)
|
||||
->orWhere('display_title', 'like', $like)
|
||||
->orWhere('teaser', 'like', $like)
|
||||
->orWhere('search_terms', 'like', $like)
|
||||
->orWhere('summary', 'like', $like);
|
||||
})
|
||||
->orderByDesc('id')
|
||||
@@ -242,6 +248,8 @@ public function search(string $query, string $scope, int $exceptCompositionId):
|
||||
$builder->where(function ($inner) use ($like): void {
|
||||
$inner->where('designation', 'like', $like)
|
||||
->orWhere('display_title', 'like', $like)
|
||||
->orWhere('teaser', 'like', $like)
|
||||
->orWhere('search_terms', 'like', $like)
|
||||
->orWhere('summary', 'like', $like);
|
||||
});
|
||||
})
|
||||
@@ -264,7 +272,7 @@ public function search(string $query, string $scope, int $exceptCompositionId):
|
||||
/**
|
||||
* @return array{items: list<array<string, string|null>>, more: bool}
|
||||
*/
|
||||
public function browse(string $query, string $kind, string $dimension, int $exceptCompositionId, bool $elementsOnly = false): array
|
||||
public function browse(string $query, string $kind, string $dimension, int $exceptCompositionId, bool $elementsOnly = false, int $pillarId = 0): array
|
||||
{
|
||||
$query = trim($query);
|
||||
$like = '%'.str_replace(['%', '_'], ['', ''], $query).'%';
|
||||
@@ -276,8 +284,8 @@ public function browse(string $query, string $kind, string $dimension, int $exce
|
||||
$latestElements = ContentElementVersion::query()
|
||||
->selectRaw('MAX(id)')
|
||||
->whereIn('status', [ContentVersionStatus::Bereit, ContentVersionStatus::Entwurf])
|
||||
->whereHas('element', function ($builder) use ($query, $like, $kind, $dimensionId): void {
|
||||
$this->constrainElement($builder, $query, $like, $kind, $dimensionId);
|
||||
->whereHas('element', function ($builder) use ($query, $like, $kind, $dimensionId, $pillarId): void {
|
||||
$this->constrainElement($builder, $query, $like, $kind, $dimensionId, $pillarId);
|
||||
})
|
||||
->groupBy('content_element_id');
|
||||
$elements = ContentElementVersion::query()
|
||||
@@ -301,7 +309,7 @@ public function browse(string $query, string $kind, string $dimension, int $exce
|
||||
->selectRaw('MAX(id)')
|
||||
->where('status', ContentVersionStatus::Bereit)
|
||||
->where('composition_id', '!=', $exceptCompositionId)
|
||||
->whereHas('composition', function ($builder) use ($query, $like, $kind, $dimensionId): void {
|
||||
->whereHas('composition', function ($builder) use ($query, $like, $kind, $dimensionId, $pillarId): void {
|
||||
if ($kind === 'modul') {
|
||||
$builder->where('kind', CompositionKind::Uebung);
|
||||
}
|
||||
@@ -310,6 +318,10 @@ public function browse(string $query, string $kind, string $dimension, int $exce
|
||||
$builder->whereIn('id', $this->dimensionSubjectIds(Composition::class, $dimensionId));
|
||||
}
|
||||
|
||||
if ($pillarId > 0) {
|
||||
$builder->whereIn('id', $this->pillarSubjectIds(Composition::class, $pillarId));
|
||||
}
|
||||
|
||||
if ($query === '') {
|
||||
return;
|
||||
}
|
||||
@@ -317,6 +329,8 @@ public function browse(string $query, string $kind, string $dimension, int $exce
|
||||
$builder->where(function ($inner) use ($like): void {
|
||||
$inner->where('designation', 'like', $like)
|
||||
->orWhere('display_title', 'like', $like)
|
||||
->orWhere('teaser', 'like', $like)
|
||||
->orWhere('search_terms', 'like', $like)
|
||||
->orWhere('summary', 'like', $like);
|
||||
});
|
||||
})
|
||||
@@ -360,6 +374,10 @@ public function browse(string $query, string $kind, string $dimension, int $exce
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($pillarId > 0 && ! in_array($composition->id, $this->pillarSubjectIds(Composition::class, $pillarId), true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$title = $this->compositionTitle($composition);
|
||||
|
||||
if ($query !== '' && ! str_contains(mb_strtolower($title.' '.(string) ($composition->summary ?? '')), mb_strtolower($query))) {
|
||||
@@ -382,6 +400,117 @@ public function browse(string $query, string $kind, string $dimension, int $exce
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Bestandssuche für Präsentationsmedien.
|
||||
* Fassungen bleiben im didaktischen Aufbau. Bilder, Filme und Hörstücke ohne Inhaltsfassung kommen dazu.
|
||||
*
|
||||
* @return array{items: list<array<string, string|null>>, more: bool}
|
||||
*/
|
||||
public function presentationBrowse(string $query, string $kind = 'alle'): array
|
||||
{
|
||||
$catalog = $this->browse($query, $kind, '', 0, elementsOnly: true);
|
||||
$outputs = match ($kind) {
|
||||
'bild' => ['bild'],
|
||||
'film' => ['film'],
|
||||
'audio' => ['audio'],
|
||||
'dokument' => [],
|
||||
default => ['bild', 'film', 'audio'],
|
||||
};
|
||||
// Reine Texte sind Lehrinhalt oder Beschreibung, keine Präsentationsmedien.
|
||||
$catalog['items'] = array_values(array_filter(
|
||||
$catalog['items'],
|
||||
fn (array $item): bool => ($item['output'] ?? '') !== 'text',
|
||||
));
|
||||
$seen = [];
|
||||
|
||||
foreach ($catalog['items'] as $item) {
|
||||
if (isset($item['element_id'])) {
|
||||
$seen[(int) $item['element_id']] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$query = trim($query);
|
||||
$like = '%'.str_replace(['%', '_'], ['', ''], $query).'%';
|
||||
$elements = ContentElement::query()
|
||||
->with('editorialContentKind')
|
||||
->whereIn('output_class', $outputs)
|
||||
->whereNull('archived_at')
|
||||
->whereDoesntHave('versions')
|
||||
->where(function ($builder): void {
|
||||
$builder->whereNull('editorial_content_kind_id')
|
||||
->orWhereDoesntHave('editorialContentKind', function ($kind): void {
|
||||
$kind->where('slug', 'traineranleitung');
|
||||
});
|
||||
})
|
||||
->when($query !== '', function ($builder) use ($like): void {
|
||||
$builder->where(function ($inner) use ($like): void {
|
||||
$inner->where('working_title', 'like', $like)
|
||||
->orWhere('display_title', 'like', $like)
|
||||
->orWhere('teaser', 'like', $like)
|
||||
->orWhere('search_terms', 'like', $like)
|
||||
->orWhere('summary', 'like', $like);
|
||||
});
|
||||
})
|
||||
->orderBy('working_title')
|
||||
->limit(48)
|
||||
->get();
|
||||
|
||||
foreach ($elements as $element) {
|
||||
if (isset($seen[$element->id])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row = $this->rowForPresentationMedium($element->id);
|
||||
|
||||
if ($row !== null) {
|
||||
$catalog['items'][] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $catalog;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string|null>|null
|
||||
*/
|
||||
private function rowForPresentationMedium(int $id): ?array
|
||||
{
|
||||
$element = ContentElement::query()->with('editorialContentKind')->find($id);
|
||||
|
||||
if (! $element instanceof ContentElement
|
||||
|| $element->archived_at !== null
|
||||
|| ! in_array($element->output_class, ['bild', 'film', 'audio'], true)
|
||||
|| $element->editorialContentKind?->slug === 'traineranleitung') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$kind = $element->editorialContentKind?->label ?: $this->outputLabel((string) $element->output_class);
|
||||
$title = filled($element->display_title) ? $element->display_title : $element->working_title;
|
||||
|
||||
return [
|
||||
'target' => 'medium:'.$element->id,
|
||||
'element_id' => (string) $element->id,
|
||||
'title' => $title,
|
||||
'kind' => $kind,
|
||||
'output' => (string) $element->output_class,
|
||||
'body' => '',
|
||||
'summary' => (string) ($element->summary ?: $element->description ?: ''),
|
||||
'medium_description' => (string) ($element->description ?? ''),
|
||||
'usage_note' => (string) ($element->usage_note ?? ''),
|
||||
'license_note' => (string) ($element->license_note ?? ''),
|
||||
'tone' => $this->tone((string) $element->output_class, $kind),
|
||||
'image' => $element->output_class === 'bild'
|
||||
? $this->cardUrl('element', $element->id, $element->thumbnail_path)
|
||||
: null,
|
||||
'version_label' => 'Ohne Inhaltsfassung',
|
||||
'committed' => false,
|
||||
'identity' => 'medium:'.$element->id,
|
||||
'open_url' => ContentElementResource::getUrl('view', ['record' => $element]),
|
||||
'open_label' => 'Medium ansehen',
|
||||
'edit_url' => ContentElementResource::getUrl('view', ['record' => $element]),
|
||||
];
|
||||
}
|
||||
|
||||
public function tone(string $outputClass, string $kindLabel): string
|
||||
{
|
||||
$value = mb_strtolower($outputClass.' '.$kindLabel);
|
||||
@@ -443,12 +572,13 @@ private function withVisibility(array $rows): array
|
||||
/**
|
||||
* @param Builder<ContentElement> $builder
|
||||
*/
|
||||
private function constrainElement($builder, string $query, string $like, string $kind, int $dimensionId): void
|
||||
private function constrainElement($builder, string $query, string $like, string $kind, int $dimensionId, int $pillarId = 0): void
|
||||
{
|
||||
$outputs = match ($kind) {
|
||||
'film' => ['film'],
|
||||
'text' => ['text'],
|
||||
'bild' => ['bild'],
|
||||
'audio' => ['audio'],
|
||||
'dokument' => ['pdf', 'document'],
|
||||
default => null,
|
||||
};
|
||||
@@ -461,6 +591,10 @@ private function constrainElement($builder, string $query, string $like, string
|
||||
$builder->whereIn('id', $this->dimensionSubjectIds(ContentElement::class, $dimensionId));
|
||||
}
|
||||
|
||||
if ($pillarId > 0) {
|
||||
$builder->whereIn('id', $this->pillarSubjectIds(ContentElement::class, $pillarId));
|
||||
}
|
||||
|
||||
if ($query === '') {
|
||||
return;
|
||||
}
|
||||
@@ -468,11 +602,29 @@ private function constrainElement($builder, string $query, string $like, string
|
||||
$builder->where(function ($inner) use ($like): void {
|
||||
$inner->where('working_title', 'like', $like)
|
||||
->orWhere('display_title', 'like', $like)
|
||||
->orWhere('teaser', 'like', $like)
|
||||
->orWhere('search_terms', 'like', $like)
|
||||
->orWhere('summary', 'like', $like)
|
||||
->orWhere('description', 'like', $like);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Direkt einer Säule zugeordnete Medien oder Module und Programme (zentrale Säulenverwaltung).
|
||||
*
|
||||
* @param class-string<Model> $class
|
||||
* @return list<int>
|
||||
*/
|
||||
private function pillarSubjectIds(string $class, int $pillarId): array
|
||||
{
|
||||
[$table, $column] = $class === Composition::class
|
||||
? ['composition_pillar', 'composition_id']
|
||||
: ['content_element_pillar', 'content_element_id'];
|
||||
|
||||
return DB::table($table)->where('pillar_id', $pillarId)->pluck($column)
|
||||
->map(fn (mixed $id): int => (int) $id)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<Model> $class
|
||||
* @return list<int>
|
||||
@@ -637,13 +789,13 @@ public function statusChips(Composition $composition, bool $offered): array
|
||||
$chips[] = ['label' => 'Entwurf offen', 'tone' => 'yellow'];
|
||||
}
|
||||
|
||||
$chips[] = $stand['released_number'] !== null
|
||||
? ['label' => 'In der Mitgliederbibliothek', 'tone' => 'pine']
|
||||
: ['label' => 'Nicht in der Mitgliederbibliothek', 'tone' => 'quiet'];
|
||||
|
||||
if ($stand['released_number'] !== null && $stand['released_number'] !== $stand['number']) {
|
||||
$chips[] = ['label' => 'Bibliothek zeigt Fassung '.$stand['released_number'], 'tone' => 'pine'];
|
||||
}
|
||||
// Zeigt die Bibliothek eine ältere Fassung, nennt der Chip sie; „In der Mitgliederbibliothek“ neben
|
||||
// „Fassung 2“ läse sich sonst, als wäre Fassung 2 sichtbar.
|
||||
$chips[] = match (true) {
|
||||
$stand['released_number'] === null => ['label' => 'Nicht in der Mitgliederbibliothek', 'tone' => 'quiet'],
|
||||
$stand['released_number'] === $stand['number'] => ['label' => 'In der Mitgliederbibliothek', 'tone' => 'pine'],
|
||||
default => ['label' => 'Bibliothek zeigt Fassung '.$stand['released_number'], 'tone' => 'pine'],
|
||||
};
|
||||
}
|
||||
|
||||
$chips[] = ['label' => 'Nicht auf der Website', 'tone' => 'quiet'];
|
||||
@@ -749,6 +901,8 @@ public function mediaPictures(string $query): array
|
||||
->where(function ($builder) use ($like): void {
|
||||
$builder->where('working_title', 'like', $like)
|
||||
->orWhere('display_title', 'like', $like)
|
||||
->orWhere('teaser', 'like', $like)
|
||||
->orWhere('search_terms', 'like', $like)
|
||||
->orWhere('summary', 'like', $like);
|
||||
})
|
||||
->orderBy('working_title')
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use Filament\Schemas\Components\View;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Livewire\Attributes\Url;
|
||||
|
||||
/**
|
||||
* Kataloglisten (Lizenzartikel, Pakete, Rechteprofile, Angebote) in der gemeinsamen Bestandsliste. Die Seite liefert
|
||||
* Zeilen mit 'suchtext' und 'zustand' (Liste von Zustandsschlüsseln) sowie die Zustandsoptionen.
|
||||
*/
|
||||
trait ListsCatalog
|
||||
{
|
||||
use ShowsBestand;
|
||||
|
||||
#[Url(as: 'suche', except: '')]
|
||||
public string $suche = '';
|
||||
|
||||
#[Url(as: 'zustand', except: 'alle')]
|
||||
public string $zustand = 'alle';
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
abstract protected function catalogRows(): array;
|
||||
|
||||
/**
|
||||
* @return array<string, string> Zustandsschlüssel => Bezeichnung, beginnend mit 'alle'
|
||||
*/
|
||||
abstract protected function zustandOptionen(): array;
|
||||
|
||||
/**
|
||||
* @return array{0: string, 1: string}
|
||||
*/
|
||||
abstract protected function einheit(): array;
|
||||
|
||||
/**
|
||||
* @return array{titel: string, text: string}
|
||||
*/
|
||||
abstract protected function leer(): array;
|
||||
|
||||
protected function bestandFilterEigenschaften(): array
|
||||
{
|
||||
return ['suche', 'zustand'];
|
||||
}
|
||||
|
||||
protected function suchPlatzhalter(): string
|
||||
{
|
||||
return 'Name oder Beschreibung';
|
||||
}
|
||||
|
||||
public function getMaxContentWidth(): Width|string|null
|
||||
{
|
||||
return Width::Full;
|
||||
}
|
||||
|
||||
public function content(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([View::make('filament.verwaltung.bestand')]);
|
||||
}
|
||||
|
||||
public function resetFilters(): void
|
||||
{
|
||||
$this->suche = '';
|
||||
$this->zustand = 'alle';
|
||||
$this->bestandGrenze = Bestand::SCHRITT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function bestand(): array
|
||||
{
|
||||
$needle = mb_strtolower(trim($this->suche));
|
||||
$rows = array_values(array_filter($this->catalogRows(), function (array $row) use ($needle): bool {
|
||||
if ($this->zustand !== 'alle' && ! in_array($this->zustand, $row['zustand'] ?? [], true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $needle === '' || str_contains(mb_strtolower(implode(' ', array_filter([
|
||||
$row['titel'], $row['meta'] ?? '', $row['text'] ?? '', $row['suchtext'] ?? '',
|
||||
]))), $needle);
|
||||
}));
|
||||
|
||||
return [
|
||||
'suche' => ['eigenschaft' => 'suche', 'label' => 'Suche', 'platzhalter' => $this->suchPlatzhalter()],
|
||||
'filter' => [['eigenschaft' => 'zustand', 'label' => 'Zustand', 'vorgabe' => 'alle', 'optionen' => $this->zustandOptionen()]],
|
||||
'zeilen' => $rows,
|
||||
'einheit' => $this->einheit(),
|
||||
'leer' => $this->leer(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,327 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Catalog\PillarFilterCompat;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Attributes\Url;
|
||||
|
||||
/**
|
||||
* Eine Liste für Programme und Module (Arbeitsplatz, „Module“, „Programme“): dieselben Zeilen, Filter und derselbe
|
||||
* Anlegedialog. Seiten mit festem Typ setzen fixedKind(); der Arbeitsplatz zeigt beide Arten mit Umschalter.
|
||||
*/
|
||||
trait ListsCompositions
|
||||
{
|
||||
use ShowsBestand;
|
||||
|
||||
#[Url]
|
||||
public string $query = '';
|
||||
|
||||
#[Url]
|
||||
public string $kindFilter = 'alle';
|
||||
|
||||
#[Url]
|
||||
public string $pillar = '';
|
||||
|
||||
/** Fachliche Säule (zentrale Säulenverwaltung), direkt zugeordnet. */
|
||||
#[Url(as: 'saeule', except: '')]
|
||||
public string $saeule = '';
|
||||
|
||||
#[Url]
|
||||
public string $visibility = 'alle';
|
||||
|
||||
protected function fixedKind(): ?CompositionKind
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function bestandFilterEigenschaften(): array
|
||||
{
|
||||
return ['query', 'kindFilter', 'pillar', 'saeule', 'visibility'];
|
||||
}
|
||||
|
||||
public function resetFilters(): void
|
||||
{
|
||||
$this->query = '';
|
||||
$this->kindFilter = 'alle';
|
||||
$this->pillar = '';
|
||||
$this->saeule = '';
|
||||
$this->visibility = 'alle';
|
||||
$this->bestandGrenze = Bestand::SCHRITT;
|
||||
}
|
||||
|
||||
public function hasActiveFilters(): bool
|
||||
{
|
||||
return trim($this->query) !== '' || $this->kindFilter !== 'alle' || $this->pillar !== '' || $this->saeule !== '' || $this->visibility !== 'alle';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function bestand(): array
|
||||
{
|
||||
$this->normalizeLegacyPillarFilter();
|
||||
$fixed = $this->fixedKind();
|
||||
$einheit = match ($fixed) {
|
||||
CompositionKind::Kurs => ['Programm', 'Programme'],
|
||||
CompositionKind::Uebung => ['Modul', 'Module'],
|
||||
CompositionKind::Kombination => ['Fachliche Kombination', 'Fachliche Kombinationen'],
|
||||
default => ['Programm oder Modul', 'Programme und Module'],
|
||||
};
|
||||
$gruppen = [];
|
||||
|
||||
foreach ($this->dimensionFilters() as $gruppe) {
|
||||
$optionen = [];
|
||||
|
||||
foreach ($gruppe['values'] as $value) {
|
||||
$optionen[(string) $value['id']] = $value['label'];
|
||||
}
|
||||
|
||||
$gruppen[] = ['label' => $gruppe['label'], 'optionen' => $optionen];
|
||||
}
|
||||
|
||||
return [
|
||||
'suche' => ['eigenschaft' => 'query', 'label' => 'Suche', 'platzhalter' => 'Titel oder Kurzbeschreibung'],
|
||||
'segmente' => $fixed === null ? [[
|
||||
'eigenschaft' => 'kindFilter', 'label' => 'Art', 'vorgabe' => 'alle',
|
||||
'optionen' => ['alle' => 'Alle', 'programm' => 'Programme', 'modul' => 'Module'],
|
||||
]] : [],
|
||||
'filter' => [[
|
||||
'eigenschaft' => 'visibility', 'label' => 'Stand', 'vorgabe' => 'alle',
|
||||
'optionen' => ['alle' => 'Jeder Stand', 'bibliothek' => 'In der Mitgliederbibliothek', 'verborgen' => 'Nicht in der Mitgliederbibliothek', 'entwurf' => 'Noch ohne Fassung'],
|
||||
]],
|
||||
'weitere' => [
|
||||
...($this->pillarOptions() === [] ? [] : [[
|
||||
'eigenschaft' => 'saeule', 'label' => 'Fachliche Säule', 'vorgabe' => '', 'alle' => 'Alle Säulen', 'optionen' => $this->pillarOptions(),
|
||||
]]),
|
||||
...($gruppen === [] ? [] : [[
|
||||
'eigenschaft' => 'pillar', 'label' => 'Fachliche Einordnung', 'vorgabe' => '', 'alle' => 'Alle Einordnungen', 'gruppen' => $gruppen,
|
||||
]]),
|
||||
],
|
||||
'zeilen' => $this->entries(),
|
||||
'einheit' => $einheit,
|
||||
'leer' => [
|
||||
'titel' => $fixed === CompositionKind::Kombination ? 'Noch keine fachlichen Kombinationen' : 'Noch keine '.$einheit[1],
|
||||
'text' => 'Mit „'.match ($fixed) {
|
||||
CompositionKind::Kurs => 'Programm anlegen',
|
||||
CompositionKind::Kombination => CompositionKind::Kombination->createLabel(),
|
||||
default => 'Modul anlegen',
|
||||
}.'“ oben entsteht der erste Eintrag. Der Name genügt.',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{label: string, values: list<array{id: int, label: string}>}>
|
||||
*/
|
||||
public function dimensionFilters(): array
|
||||
{
|
||||
return app(EditorialVocabulary::class)->dimensionFilterGroups(ctype_digit($this->pillar) ? [(int) $this->pillar] : []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeilen der gemeinsamen Bestandsliste.
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function entries(): array
|
||||
{
|
||||
$needle = mb_strtolower(trim($this->query));
|
||||
$catalog = app(EditorialCatalog::class);
|
||||
$offered = $catalog->offeredCompositionIds();
|
||||
$this->normalizeLegacyPillarFilter();
|
||||
$pillarIds = $this->pillar === '' ? null : $this->pillarSubjects((int) $this->pillar);
|
||||
$saeuleIds = ctype_digit($this->saeule) && $this->saeule !== '' ? $this->saeuleSubjects((int) $this->saeule) : null;
|
||||
$fixed = $this->fixedKind();
|
||||
$kinds = $fixed !== null ? [$fixed] : match ($this->kindFilter) {
|
||||
'programm' => [CompositionKind::Kurs],
|
||||
'modul' => [CompositionKind::Uebung],
|
||||
default => [CompositionKind::Kurs, CompositionKind::Uebung],
|
||||
};
|
||||
$canEdit = ContentElementResource::editor();
|
||||
$rows = [];
|
||||
|
||||
$compositions = Composition::query()
|
||||
->whereIn('kind', $kinds)
|
||||
->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 ($pillarIds !== null && ! in_array($composition->id, $pillarIds, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($saeuleIds !== null && ! in_array($composition->id, $saeuleIds, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$stand = $catalog->stand($composition);
|
||||
|
||||
if (! $this->matchesVisibility($stand)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$title = $catalog->compositionTitle($composition);
|
||||
$summary = trim((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));
|
||||
$url = EditorialCatalog::editUrl($composition);
|
||||
$rows[] = [
|
||||
'schluessel' => 'c'.$composition->id,
|
||||
'titel' => $title,
|
||||
'meta' => $kind->deskLabel().($title !== $composition->designation ? ' · '.$composition->designation : ''),
|
||||
'text' => $summary,
|
||||
'bild' => $cover['url'],
|
||||
'bildFehlt' => 'Kein Titelbild',
|
||||
'hinweise' => filled($cover['note']) ? ['Bild: '.$cover['note']] : [],
|
||||
'symbol' => 'modul',
|
||||
'url' => $url,
|
||||
'chips' => array_map(fn (array $chip): array => [
|
||||
'label' => $chip['label'],
|
||||
'ton' => match ($chip['tone']) {
|
||||
'pine' => 'gut',
|
||||
'yellow' => 'offen',
|
||||
'quiet' => 'leise',
|
||||
default => 'neutral',
|
||||
},
|
||||
], $catalog->statusChips($composition, in_array($composition->id, $offered, true))),
|
||||
'aktionen' => array_values(array_filter([
|
||||
['label' => 'Aufbau', 'href' => $url, 'icon' => 'modul'],
|
||||
$canEdit ? ['label' => 'Redaktion', 'href' => $url.'?redaktion=1', 'icon' => 'stift'] : null,
|
||||
])),
|
||||
];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Anlegedialog für Module und Programme; derselbe auf dem Arbeitsplatz und in den Listen.
|
||||
*/
|
||||
protected function createCompositionAction(CompositionKind $kind): Action
|
||||
{
|
||||
$label = $kind === CompositionKind::Kurs ? 'Programm' : 'Modul';
|
||||
|
||||
return Action::make($kind === CompositionKind::Kurs ? 'createProgram' : 'createModule')
|
||||
->label($label.' anlegen')
|
||||
->modalHeading('Neues '.$label)
|
||||
->modalDescription('Der Name genügt. Danach öffnet sich der Aufbau; Texte, Bilder und Einordnung folgen dort und in der Redaktion.')
|
||||
->modalSubmitActionLabel($label.' anlegen')
|
||||
->modalWidth('lg')
|
||||
->visible(fn (): bool => ContentElementResource::editor())
|
||||
->schema([
|
||||
TextInput::make('designation')->label('Name')->required()->maxLength(255),
|
||||
])
|
||||
->action(function (array $data) use ($kind): void {
|
||||
abort_unless(ContentElementResource::editor(), 403);
|
||||
$composition = app(EditorialCatalog::class)->create(trim((string) $data['designation']), $kind);
|
||||
$this->redirect(EditorialCatalog::editUrl($composition), navigate: false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
$members[] = ['target' => $member->content_element_version_id
|
||||
? 'element:'.$member->content_element_version_id
|
||||
: 'composition:'.$member->nested_composition_version_id];
|
||||
}
|
||||
|
||||
return $members;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alte Adressen mit einem Säulenwert der Einordnung (`?pillar=…`) gelten für die zentrale Säule.
|
||||
*/
|
||||
private function normalizeLegacyPillarFilter(): void
|
||||
{
|
||||
if (ctype_digit($this->pillar) && $this->pillar !== '' && $this->saeule === '' && is_int($pillar = PillarFilterCompat::pillarOfLegacyValue((int) $this->pillar))) {
|
||||
[$this->saeule, $this->pillar] = [(string) $pillar, ''];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function pillarOptions(): array
|
||||
{
|
||||
return Pillar::query()->orderBy('sort_order')->orderBy('name')->pluck('name', 'id')
|
||||
->mapWithKeys(fn (string $name, int|string $id): array => [(string) $id => $name])->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Direkt zugeordnete Module und Programme einer Säule. Die Säulen der enthaltenen Medien zählen hier nicht.
|
||||
*
|
||||
* @return list<int>
|
||||
*/
|
||||
private function saeuleSubjects(int $pillarId): array
|
||||
{
|
||||
return DB::table('composition_pillar')->where('pillar_id', $pillarId)->pluck('composition_id')
|
||||
->map(fn (mixed $id): int => (int) $id)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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,
|
||||
};
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -8,9 +8,10 @@
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\EditorialVocabulary;
|
||||
use App\Domain\Catalog\IdentityDimensionValue;
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Catalog\PillarFilterCompat;
|
||||
use App\Domain\Catalog\ReleaseContent;
|
||||
use App\Domain\Media\ThumbnailRef;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
@@ -50,15 +51,16 @@ public function pillars(): array
|
||||
/**
|
||||
* @return list<array{id: int, label: string}>
|
||||
*/
|
||||
public function classifications(): array
|
||||
public function classifications(array $selectedIds = []): array
|
||||
{
|
||||
$options = [];
|
||||
|
||||
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
|
||||
foreach ($dimension->values->sortBy('label') as $value) {
|
||||
// Gleiche Regel wie Editor und Picker; verwendete inaktive Werte und gewählte Filter bleiben auffindbar.
|
||||
foreach (app(EditorialVocabulary::class)->dimensionFilterGroups($selectedIds) as $dimension) {
|
||||
foreach ($dimension['values'] as $value) {
|
||||
$options[] = [
|
||||
'id' => $value->id,
|
||||
'label' => $dimension->label.': '.$value->label,
|
||||
'id' => $value['id'],
|
||||
'label' => $dimension['label'].': '.$value['label'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -75,7 +77,7 @@ public function classifications(): array
|
||||
*/
|
||||
public function cardFor(ContentElement $element, bool $canEdit): array
|
||||
{
|
||||
$element->loadMissing(['versions', 'pillars']);
|
||||
$element->loadMissing(['versions', 'pillars', 'editorialContentKind']);
|
||||
$versionIds = $element->versions->pluck('id')->all();
|
||||
|
||||
return $this->card(
|
||||
@@ -95,7 +97,7 @@ public function cards(array $filters, bool $canEdit): array
|
||||
{
|
||||
$filters = $this->normalize($filters);
|
||||
$elements = ContentElement::query()
|
||||
->with(['versions', 'pillars'])
|
||||
->with(['versions', 'pillars', 'editorialContentKind'])
|
||||
->orderBy('working_title')
|
||||
->get();
|
||||
$versionIds = $elements->flatMap(fn (ContentElement $element) => $element->versions->pluck('id'))->all();
|
||||
@@ -131,6 +133,13 @@ public function cards(array $filters, bool $canEdit): array
|
||||
*/
|
||||
private function normalize(array $filters): array
|
||||
{
|
||||
$saeule = ctype_digit($filters['saeule'] ?? '') ? $filters['saeule'] : '';
|
||||
$einordnung = ctype_digit($filters['einordnung'] ?? '') ? $filters['einordnung'] : '';
|
||||
|
||||
if ($einordnung !== '' && $saeule === '' && is_int($pillar = PillarFilterCompat::pillarOfLegacyValue((int) $einordnung))) {
|
||||
[$saeule, $einordnung] = [(string) $pillar, ''];
|
||||
}
|
||||
|
||||
return [
|
||||
'suche' => trim($filters['suche'] ?? ''),
|
||||
'art' => $this->choice($filters['art'] ?? '', ['film', 'text', 'document', 'bild', 'audio']),
|
||||
@@ -138,8 +147,9 @@ private function normalize(array $filters): array
|
||||
'entwurf' => $this->choice($filters['entwurf'] ?? '', ['offen', 'keiner']),
|
||||
'fassung' => $this->choice($filters['fassung'] ?? '', ['mit', 'nur']),
|
||||
'nutzung' => $this->choice($filters['nutzung'] ?? '', ['verwendet', 'unbenutzt']),
|
||||
'saeule' => ctype_digit($filters['saeule'] ?? '') ? $filters['saeule'] : '',
|
||||
'einordnung' => ctype_digit($filters['einordnung'] ?? '') ? $filters['einordnung'] : '',
|
||||
'saeule' => $saeule,
|
||||
'einordnung' => $einordnung,
|
||||
'inhaltsart' => ctype_digit($filters['inhaltsart'] ?? '') ? $filters['inhaltsart'] : '',
|
||||
'verarbeitung' => $this->choice($filters['verarbeitung'] ?? '', ['fehler', 'uebernahme']),
|
||||
'archiv' => $this->choice($filters['archiv'] ?? '', ['aktiv', 'archiviert', 'alle'], 'aktiv'),
|
||||
];
|
||||
@@ -189,6 +199,7 @@ private function placements(array $versionIds): array
|
||||
'name' => $this->catalog->compositionTitle($composition),
|
||||
'type' => $this->kindLabel($composition),
|
||||
'mediumVersion' => $this->versionLabel($version),
|
||||
'mediumVersionId' => $version->id,
|
||||
'hostVersion' => 'Fassung '.$compositionVersion->number,
|
||||
'url' => EditorialCatalog::editUrl($composition),
|
||||
'roles' => [],
|
||||
@@ -418,6 +429,10 @@ private function matches(ContentElement $element, array $portrait, array $uses,
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($filters['inhaltsart'] !== '' && (int) $element->editorial_content_kind_id !== (int) $filters['inhaltsart']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($filters['verarbeitung'] === 'fehler' && $portrait['processing'] !== 'Verarbeitungsfehler') {
|
||||
return false;
|
||||
}
|
||||
@@ -451,6 +466,8 @@ private function haystack(ContentElement $element): string
|
||||
$element->display_title,
|
||||
$element->description,
|
||||
$element->summary,
|
||||
$element->teaser,
|
||||
$element->search_terms,
|
||||
$element->usage_note,
|
||||
], fn (mixed $value): bool => is_string($value) && trim($value) !== '')));
|
||||
}
|
||||
@@ -473,6 +490,7 @@ private function card(ContentElement $element, array $portrait, array $uses, arr
|
||||
'id' => $element->id,
|
||||
'title' => $element->working_title,
|
||||
'type' => $this->catalog->outputLabel((string) $element->output_class),
|
||||
'editorialKind' => $element->editorialContentKind?->label,
|
||||
'typeKey' => $typeKey,
|
||||
'description' => $description === '' ? null : $description,
|
||||
'usageNote' => $usageNote === '' ? null : $usageNote,
|
||||
@@ -495,7 +513,7 @@ private function card(ContentElement $element, array $portrait, array $uses, arr
|
||||
'usages' => $uses,
|
||||
'licenseText' => $this->licenseText($codes),
|
||||
'url' => ContentElementResource::getUrl('view', ['record' => $element]),
|
||||
'editUrl' => $canEdit ? ContentElementResource::getUrl('edit', ['record' => $element]) : null,
|
||||
'editUrl' => $canEdit ? ContentElementResource::getUrl('view', ['record' => $element, 'redaktion' => 1]) : null,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
use App\Domain\Media\PresentationFile;
|
||||
use App\Jobs\DeriveThumbnail;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
@@ -39,6 +41,10 @@ public static function fields(bool $creating, ?ContentElement $element = null):
|
||||
$fields[] = self::fileField()
|
||||
->visible(fn ($get): bool => filled($get('shape')) && $get('shape') !== 'text')
|
||||
->required(fn ($get): bool => filled($get('shape')) && $get('shape') !== 'text');
|
||||
$fields[] = Checkbox::make('without_version')
|
||||
->label('Eigenständiges Präsentationsmedium')
|
||||
->helperText('Bild, Film oder Hörstück ohne fachliche Inhaltsfassung, zum Beispiel ein Trailer, der ungeschützt auf der Website laufen soll. Der Film muss dafür MP4 (H.264) oder WebM sein. Er wird nicht lizenziert und erst nach „Für die Website freigeben“ öffentlich.')
|
||||
->visible(fn ($get): bool => in_array($get('shape'), ['film', 'audio', 'bild'], true));
|
||||
} elseif ($element?->output_class === 'text') {
|
||||
$fields[] = Textarea::make('body')->label('Text')->rows(8)->required();
|
||||
}
|
||||
@@ -88,20 +94,10 @@ public static function create(array $data, bool $hold): ContentElement
|
||||
{
|
||||
$service = app(ContentService::class);
|
||||
[$kind, $output] = self::shape($data['shape'] ?? null);
|
||||
$element = $service->createElement($kind, $output, (string) $data['working_title']);
|
||||
self::remember($element, $data);
|
||||
$incoming = null;
|
||||
|
||||
if ($output === 'text') {
|
||||
$body = trim((string) ($data['body'] ?? ''));
|
||||
|
||||
if ($body === '') {
|
||||
throw new DomainRuleException('Der Text braucht einen Inhalt.');
|
||||
}
|
||||
|
||||
$hold
|
||||
? $service->draftElementVersion($element, $body)
|
||||
: $service->publishElementVersion($element, $body);
|
||||
} else {
|
||||
if ($output !== 'text') {
|
||||
// Alles prüfen, bevor etwas angelegt wird: Eine abgelehnte Datei darf kein leeres Medium hinterlassen.
|
||||
$incoming = IncomingFile::store($data['incoming'] ?? null);
|
||||
|
||||
if ($incoming === null) {
|
||||
@@ -120,13 +116,36 @@ public static function create(array $data, bool $hold): ContentElement
|
||||
throw new DomainRuleException('Diese Datei passt nicht zur gewählten Art.');
|
||||
}
|
||||
|
||||
$metadata = ['incoming' => $incoming];
|
||||
if (! empty($data['without_version']) && in_array($output, ['bild', 'film', 'audio'], true)) {
|
||||
app(PresentationFile::class)->validate($output, $incoming);
|
||||
}
|
||||
}
|
||||
|
||||
if ($hold) {
|
||||
$metadata['hold'] = true;
|
||||
$service->draftElementVersion($element, null, $metadata);
|
||||
$element = $service->createElement($kind, $output, (string) $data['working_title']);
|
||||
self::remember($element, $data);
|
||||
|
||||
if ($output === 'text') {
|
||||
$body = trim((string) ($data['body'] ?? ''));
|
||||
|
||||
if ($body === '') {
|
||||
throw new DomainRuleException('Der Text braucht einen Inhalt.');
|
||||
}
|
||||
|
||||
$hold
|
||||
? $service->draftElementVersion($element, $body)
|
||||
: $service->publishElementVersion($element, $body);
|
||||
} else {
|
||||
if (! empty($data['without_version']) && in_array($output, ['bild', 'film', 'audio'], true)) {
|
||||
app(PresentationFile::class)->store($element, $incoming);
|
||||
} else {
|
||||
$service->publishElementVersion($element, null, $metadata);
|
||||
$metadata = ['incoming' => $incoming];
|
||||
|
||||
if ($hold) {
|
||||
$metadata['hold'] = true;
|
||||
$service->draftElementVersion($element, null, $metadata);
|
||||
} else {
|
||||
$service->publishElementVersion($element, null, $metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\Bundle;
|
||||
use App\Domain\Catalog\BundleService;
|
||||
use App\Domain\Catalog\BundleStatus;
|
||||
use App\Domain\Catalog\BundleVersion;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Catalog\OfferVersion;
|
||||
use App\Domain\Catalog\ReleaseStatus;
|
||||
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\LicenseArticles\LicenseArticleResource;
|
||||
use App\Filament\Resources\Offers\OfferResource;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Voraussetzungen bis zur Veröffentlichung für Lizenzartikel, Paket und Angebot in einer gemeinsamen Form
|
||||
* (Verwaltungsstandard 14, Abschnitt 9: eine Komponente für gleiche Aufgaben). Die Klasse liest nur; sie ändert keine
|
||||
* fachliche Regel. Jeder Schritt nennt, was fehlt, und bietet den Weg dorthin an.
|
||||
*
|
||||
* Schritt: ['titel', 'text', 'stand' => erledigt|offen|optional, 'aktion' => ['label', 'wire'|'href']|null]
|
||||
* Ergebnis: ['schritte', 'bereit' (alle Pflichtschritte erledigt), 'naechster' (Text des ersten offenen Pflichtschritts)].
|
||||
*/
|
||||
class PublicationReadiness
|
||||
{
|
||||
public function __construct(
|
||||
private readonly BundleService $bundles,
|
||||
private readonly OfferService $offers,
|
||||
private readonly PublicCatalogReader $catalog,
|
||||
) {}
|
||||
|
||||
/** Ein Artikel ist verwendbar, wenn sein aktueller Stand veröffentlicht ist. */
|
||||
public function articleUsable(LicenseArticle $article): bool
|
||||
{
|
||||
$release = $article->currentRelease;
|
||||
|
||||
return $release instanceof ArticleRelease && StatusValue::of($release->status) === ReleaseStatus::Veroeffentlicht->value;
|
||||
}
|
||||
|
||||
/** Anzeige in Auswahllisten: Name, Kennung und Stand statt der bloßen Kennung. */
|
||||
public function articleLabel(LicenseArticle $article): string
|
||||
{
|
||||
$title = $this->articleName($article);
|
||||
$name = $title !== '' ? $title.' ('.$article->code.')' : (string) $article->code;
|
||||
$release = $article->currentRelease;
|
||||
|
||||
if ($this->articleUsable($article)) {
|
||||
return $name.' · Stand '.$release->number;
|
||||
}
|
||||
|
||||
return $name.' · '.($release === null ? 'noch ohne Stand, nicht verwendbar' : 'Stand gesperrt, nicht verwendbar');
|
||||
}
|
||||
|
||||
/** Name wie in der Redaktion: eigener Name oder Name des Inhalts, sonst der Arbeitstitel; leer ohne beides. */
|
||||
public function articleName(LicenseArticle $article): string
|
||||
{
|
||||
return app(ProductOptions::class)->articleName($article);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function articleOptions(): array
|
||||
{
|
||||
$options = [];
|
||||
|
||||
foreach (LicenseArticle::query()->with('currentRelease')->orderBy('code')->get() as $article) {
|
||||
$options[$article->id] = $this->articleLabel($article);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Veröffentlichte Paketfassungen mit ihren Artikeln, damit die Auswahl zeigt, was verkauft wird.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function bundleVersionOptions(): array
|
||||
{
|
||||
$options = [];
|
||||
|
||||
foreach (BundleVersion::query()->where('status', BundleStatus::Veroeffentlicht)->with('bundle')->orderBy('id')->get() as $version) {
|
||||
try {
|
||||
$codes = LicenseArticle::query()->whereIn('id', $this->bundles->articleIds($version))->orderBy('code')->pluck('code')->all();
|
||||
} catch (DomainRuleException) {
|
||||
$codes = [];
|
||||
}
|
||||
|
||||
$options[$version->id] = $version->bundle->name.' · Fassung '.$version->number.' ('.($codes === [] ? 'ohne Artikel' : implode(', ', $codes)).')';
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Artikel einer Auswahl, die keinen verwendbaren Stand haben.
|
||||
*
|
||||
* @param list<int> $articleIds
|
||||
* @return list<LicenseArticle>
|
||||
*/
|
||||
public function unusableArticles(array $articleIds): array
|
||||
{
|
||||
return LicenseArticle::query()->with('currentRelease')->whereIn('id', array_unique($articleIds))->orderBy('code')->get()
|
||||
->reject(fn (LicenseArticle $article): bool => $this->articleUsable($article))
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<LicenseArticle> $articles
|
||||
*/
|
||||
public function unusableMessage(array $articles, string $zweck): string
|
||||
{
|
||||
$namen = implode(', ', array_map(fn (LicenseArticle $article): string => '„'.($this->articleName($article) ?: $article->code).'“ ('.$article->code.')', $articles));
|
||||
|
||||
return (count($articles) === 1 ? 'Der Lizenzartikel ' : 'Die Lizenzartikel ').$namen
|
||||
.(count($articles) === 1 ? ' hat' : ' haben')
|
||||
.' noch keinen veröffentlichten Stand und vergibt'.(count($articles) === 1 ? '' : ' keine').' keine Inhalte. '
|
||||
.'Lege zuerst am Artikel mit „Inhalt festlegen“ den Inhalt fest, bevor du '.$zweck.'.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function forArticle(LicenseArticle $article): array
|
||||
{
|
||||
$article->loadMissing('currentRelease');
|
||||
$usable = $this->articleUsable($article);
|
||||
$release = $article->currentRelease;
|
||||
$inUse = $this->articleInUse($article);
|
||||
|
||||
return $this->result([
|
||||
[
|
||||
'titel' => 'Inhalt festlegen',
|
||||
'text' => $usable
|
||||
? 'Stand '.$release->number.' ist veröffentlicht und bestimmt, welche Inhalte der Artikel lizenziert.'
|
||||
: 'Der Artikel lizenziert noch nichts. Wähle den freigegebenen Inhalt (Medium, Modul oder Programm), den er umfassen soll.',
|
||||
'stand' => $usable ? 'erledigt' : 'offen',
|
||||
'aktion' => $usable ? null : ['label' => 'Inhalt festlegen', 'wire' => "mountAction('release')"],
|
||||
],
|
||||
[
|
||||
'titel' => 'Name und Beschreibung',
|
||||
'text' => $this->articleName($article) !== ''
|
||||
? 'Der Name „'.$this->articleName($article).'“ erscheint in Paketen, Angeboten, im Shop und in der Bibliothek.'
|
||||
: 'Ohne Name erscheint die Kennung „'.$article->code.'“. Name, Teaser und Beschreibung pflegst du in der Redaktion.',
|
||||
'stand' => $this->articleName($article) !== '' ? 'erledigt' : 'optional',
|
||||
'aktion' => $this->articleName($article) !== '' ? null : ['label' => 'Redaktion bearbeiten', 'wire' => "openRedaktion('texte')"],
|
||||
],
|
||||
[
|
||||
'titel' => 'In einem Paket oder Angebot verwenden',
|
||||
'text' => $inUse
|
||||
? 'Der Artikel ist in einem Paket oder Angebot enthalten.'
|
||||
: 'Verkauft wird der Artikel erst über ein Angebot, allein oder in einem Paket.',
|
||||
'stand' => $inUse ? 'erledigt' : 'offen',
|
||||
'aktion' => $inUse ? null : ['label' => 'Angebote öffnen', 'href' => OfferResource::getUrl('index')],
|
||||
'pflicht' => false,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function forBundle(Bundle $bundle): array
|
||||
{
|
||||
$published = $bundle->versions()->where('status', BundleStatus::Veroeffentlicht)->orderByDesc('number')->first();
|
||||
$missing = [];
|
||||
|
||||
if ($published instanceof BundleVersion) {
|
||||
try {
|
||||
$missing = $this->unusableArticles($this->bundles->articleIds($published));
|
||||
} catch (DomainRuleException) {
|
||||
$missing = [];
|
||||
}
|
||||
}
|
||||
|
||||
$offered = $published instanceof BundleVersion && $this->bundleOffered($bundle);
|
||||
|
||||
return $this->result([
|
||||
[
|
||||
'titel' => 'Bestandteile festlegen',
|
||||
'text' => $published instanceof BundleVersion
|
||||
? 'Fassung '.$published->number.' ist veröffentlicht und unveränderlich.'
|
||||
: 'Wähle die Lizenzartikel und Pakete, die zusammen verkauft werden, und veröffentliche die Fassung.',
|
||||
'stand' => $published instanceof BundleVersion ? 'erledigt' : 'offen',
|
||||
'aktion' => $published instanceof BundleVersion ? null : ['label' => 'Bestandteile festlegen', 'wire' => "mountAction('publish')"],
|
||||
],
|
||||
[
|
||||
'titel' => 'Jeder enthaltene Artikel hat einen Inhalt',
|
||||
'text' => ! $published instanceof BundleVersion
|
||||
? 'Wird geprüft, sobald die Bestandteile feststehen.'
|
||||
: ($missing === []
|
||||
? 'Alle enthaltenen Artikel haben einen veröffentlichten Stand.'
|
||||
: 'Ohne Stand und damit ohne Inhalt: '.implode(', ', array_map(fn (LicenseArticle $article): string => (string) $article->code, $missing)).'. Ein Angebot lässt sich erst aktivieren, wenn jeder Artikel einen Stand hat.'),
|
||||
'stand' => $published instanceof BundleVersion && $missing === [] ? 'erledigt' : 'offen',
|
||||
'aktion' => $missing === [] ? null : ['label' => 'Artikel „'.$missing[0]->code.'“ öffnen', 'href' => LicenseArticleResource::getUrl('view', ['record' => $missing[0]])],
|
||||
],
|
||||
[
|
||||
'titel' => 'Angebot mit Preis und Rechten',
|
||||
'text' => $offered
|
||||
? 'Ein aktives Angebot verkauft dieses Paket.'
|
||||
: 'Verkauft wird das Paket erst über ein Angebot. Dort wählst du die Paketfassung, die Rechte und den Preis.',
|
||||
'stand' => $offered ? 'erledigt' : 'offen',
|
||||
'aktion' => $offered ? null : ['label' => 'Angebote öffnen', 'href' => OfferResource::getUrl('index')],
|
||||
'pflicht' => false,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function forOffer(Offer $offer): array
|
||||
{
|
||||
$active = $offer->versions()->where('status', 'aktiv')->orderByDesc('number')->first();
|
||||
$hasActive = $active instanceof OfferVersion;
|
||||
$articleIds = $hasActive ? $active->resolvedScopes()->pluck('license_article_id')->map(fn ($id): int => (int) $id)->all() : [];
|
||||
$missing = $this->unusableArticles($articleIds);
|
||||
$buyable = $hasActive && $this->offers->purchasableVersion($offer) !== null;
|
||||
$page = $offer->composition;
|
||||
$shown = $page !== null && $this->catalog->shownVersion($page) !== null;
|
||||
$pageName = $page !== null ? (string) ($page->display_title ?: $page->designation) : '';
|
||||
$activate = ['label' => $hasActive ? 'Geänderte Fassung aktivieren' : 'Angebot konfigurieren', 'wire' => "mountAction('activate')"];
|
||||
|
||||
return $this->result([
|
||||
[
|
||||
'titel' => 'Artikel oder Paket, Rechte, Preis und Vergabe festlegen',
|
||||
'text' => $hasActive
|
||||
? 'Fassung '.$active->number.' ist aktiv.'
|
||||
: 'Wähle, was verkauft wird (Lizenzartikel oder Paketfassung), welche Nutzungsrechte dazugehören, für wen es gilt und was es kostet. Erst „Fassung aktivieren“ macht das Angebot gültig.',
|
||||
'stand' => $hasActive ? 'erledigt' : 'offen',
|
||||
'aktion' => $hasActive ? null : $activate,
|
||||
],
|
||||
[
|
||||
'titel' => 'Inhalt vorhanden',
|
||||
'text' => ! $hasActive
|
||||
? 'Wird geprüft, sobald die Fassung aktiv ist.'
|
||||
: ($missing === []
|
||||
? 'Jeder enthaltene Lizenzartikel hat einen veröffentlichten Stand.'
|
||||
: 'Ohne Stand und damit ohne Inhalt: '.implode(', ', array_map(fn (LicenseArticle $article): string => (string) $article->code, $missing)).'. Käufer würden nichts erhalten.'),
|
||||
'stand' => $hasActive && $missing === [] ? 'erledigt' : 'offen',
|
||||
'aktion' => $missing === [] ? null : ['label' => 'Artikel „'.$missing[0]->code.'“ öffnen', 'href' => LicenseArticleResource::getUrl('view', ['record' => $missing[0]])],
|
||||
],
|
||||
[
|
||||
'titel' => 'Als Kauf mit Preis angeboten',
|
||||
'text' => $buyable
|
||||
? 'Die aktive Fassung ist ein Kauf zu '.Money::format((int) $active->price_cents).'.'
|
||||
: ($hasActive ? 'Die aktive Fassung ist kein Kauf mit Preis (Vergabe: '.CatalogLabels::vergabe($active).'). Im Shop erscheinen nur Käufe.' : 'Wird mit der Fassung festgelegt.'),
|
||||
'stand' => $buyable ? 'erledigt' : 'offen',
|
||||
'aktion' => $buyable ? null : ($hasActive ? $activate : null),
|
||||
],
|
||||
[
|
||||
'titel' => 'Produktseite zuordnen',
|
||||
'text' => $page !== null
|
||||
? 'Zugeordnet: „'.$pageName.'“. Optionen derselben Produktseite sind Alternativen im Warenkorb.'
|
||||
: 'Der Shop zeigt ein Angebot auf der Seite eines Programms. Wähle in der Maske die Produktseite. Ein Paket braucht eine eigene Produktseite, sonst ist es Alternative zu den Einzelangeboten dieser Seite.',
|
||||
'stand' => $page !== null ? 'erledigt' : 'offen',
|
||||
'aktion' => $page !== null ? null : $activate,
|
||||
],
|
||||
[
|
||||
'titel' => 'Produktseite öffentlich',
|
||||
'text' => $page === null
|
||||
? 'Wird geprüft, sobald eine Produktseite zugeordnet ist.'
|
||||
: ($shown
|
||||
? 'Das Programm ist zur Anzeige freigegeben. Das Angebot erscheint in der Shop-Suche und auf der Produktseite.'
|
||||
: 'Das Programm „'.$pageName.'“ ist nicht zur Anzeige freigegeben oder kein Programm. Das Angebot ist dort nicht auffindbar.'),
|
||||
'stand' => $shown ? 'erledigt' : 'offen',
|
||||
'aktion' => $page === null || $shown ? null : ['label' => 'Programm öffnen', 'href' => EditorialCatalog::editUrl($page)],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $schritte
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function result(array $schritte): array
|
||||
{
|
||||
$schritte = array_map(fn (array $schritt): array => ['pflicht' => true, 'aktion' => null, ...$schritt], $schritte);
|
||||
$naechster = null;
|
||||
|
||||
foreach ($schritte as $schritt) {
|
||||
if ($schritt['pflicht'] && $schritt['stand'] === 'offen') {
|
||||
$naechster = $schritt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'schritte' => $schritte,
|
||||
'bereit' => $naechster === null,
|
||||
'naechster' => $naechster,
|
||||
];
|
||||
}
|
||||
|
||||
private function articleInUse(LicenseArticle $article): bool
|
||||
{
|
||||
return DB::table('offer_lines')->where('license_article_id', $article->id)->exists()
|
||||
|| DB::table('bundle_items')->where('license_article_id', $article->id)->exists();
|
||||
}
|
||||
|
||||
private function bundleOffered(Bundle $bundle): bool
|
||||
{
|
||||
return DB::table('offer_lines')
|
||||
->join('offer_versions', 'offer_versions.id', '=', 'offer_lines.offer_version_id')
|
||||
->join('bundle_versions', 'bundle_versions.id', '=', 'offer_lines.bundle_version_id')
|
||||
->where('bundle_versions.bundle_id', $bundle->id)
|
||||
->where('offer_versions.status', 'aktiv')
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,8 @@ public static function repeater(string $name = 'sections'): Repeater
|
||||
->label('Abschnitte')
|
||||
->hiddenLabel()
|
||||
->schema(self::sectionSchema())
|
||||
->itemLabel(fn (array $state, ?int $index): string => self::sectionLabel($state, $index))
|
||||
->columns(['default' => 1, 'xl' => 2])
|
||||
->itemLabel(fn (array $state, ?int $index): HtmlString => self::sectionLabel($state, $index))
|
||||
->addActionLabel('Abschnitt hinzufügen')
|
||||
->addBetweenActionLabel('Abschnitt hier einfügen')
|
||||
->defaultItems(0)
|
||||
@@ -48,6 +49,7 @@ public static function repeater(string $name = 'sections'): Repeater
|
||||
->deletable()
|
||||
->maxItems(PageSections::MAX_SECTIONS)
|
||||
->cloneAction(fn (Action $action): Action => $action
|
||||
->label('Abschnitt duplizieren')
|
||||
->tooltip('Abschnitt duplizieren')
|
||||
->action(function (array $arguments, Repeater $component): void {
|
||||
// Die Kopie steht direkt hinter dem Original (Filament hängt sie sonst ans Seitenende).
|
||||
@@ -56,16 +58,28 @@ public static function repeater(string $name = 'sections'): Repeater
|
||||
$component->shouldPartiallyRenderAfterActionsCalled() ? $component->partiallyRender() : null;
|
||||
}))
|
||||
->deleteAction(fn (Action $action): Action => $action
|
||||
->label('Abschnitt löschen')
|
||||
->tooltip('Abschnitt löschen')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Abschnitt löschen?')
|
||||
->modalDescription('Der Abschnitt und die Widgets darin werden aus dem Entwurf entfernt. Bereits gespeicherte Revisionen bleiben erhalten.')
|
||||
->modalSubmitActionLabel('Löschen'))
|
||||
->moveUpAction(fn (Action $action): Action => $action->tooltip('Abschnitt nach oben'))
|
||||
->moveDownAction(fn (Action $action): Action => $action->tooltip('Abschnitt nach unten'))
|
||||
->reorderAction(fn (Action $action): Action => $action->tooltip('Abschnitt ziehen'))
|
||||
->collapseAction(fn (Action $action): Action => $action->tooltip('Abschnitt einklappen'))
|
||||
->expandAction(fn (Action $action): Action => $action->tooltip('Abschnitt aufklappen'))
|
||||
->moveUpAction(fn (Action $action): Action => $action->label('Abschnitt nach oben')->tooltip('Abschnitt nach oben'))
|
||||
->moveDownAction(fn (Action $action): Action => $action->label('Abschnitt nach unten')->tooltip('Abschnitt nach unten'))
|
||||
->reorderAction(fn (Action $action): Action => $action->label('Abschnitt ziehen')->tooltip('Abschnitt ziehen'))
|
||||
->extraItemActions([
|
||||
// Seiten-Arbeitsplatz (EditPage): Raster und Gestaltung im eigenen Kontext statt an jedem Abschnitt.
|
||||
Action::make('gestalten')
|
||||
->label('Abschnitt gestalten')
|
||||
->icon('heroicon-o-swatch')
|
||||
->button()
|
||||
->size('sm')
|
||||
->color('gray')
|
||||
->visible(fn ($livewire): bool => is_object($livewire) && method_exists($livewire, 'openAbschnitt'))
|
||||
->action(fn (array $arguments, Repeater $component) => $component->getLivewire()->openAbschnitt((string) $arguments['item'])),
|
||||
])
|
||||
->collapseAction(fn (Action $action): Action => $action->label('Abschnitt einklappen')->tooltip('Abschnitt einklappen'))
|
||||
->expandAction(fn (Action $action): Action => $action->label('Abschnitt aufklappen')->tooltip('Abschnitt aufklappen'))
|
||||
->extraAttributes(['class' => 'luf-sections'])
|
||||
->columnSpanFull();
|
||||
}
|
||||
@@ -77,33 +91,50 @@ private static function sectionSchema(): array
|
||||
{
|
||||
return [
|
||||
Hidden::make('id'),
|
||||
ToggleButtons::make('layout')
|
||||
->label('Raster')
|
||||
->options(self::layoutOptions())
|
||||
->default(SectionLayouts::DEFAULT)
|
||||
->required()
|
||||
->inline()
|
||||
->live()
|
||||
->disableOptionWhen(fn (string $value, Get $get): bool => self::filledCount($get('slots')) > SectionLayouts::slotCount($value))
|
||||
->helperText(fn (Get $get): ?string => self::filledCount($get('slots')) > 1
|
||||
? 'Raster mit weniger Plätzen als eingesetzten Widgets sind gesperrt. Entfernen oder verschieben Sie zuerst ein Widget; beim Wechsel geht kein Widget verloren.'
|
||||
: null)
|
||||
->afterStateUpdated(function (?string $state, Get $get, Set $set): void {
|
||||
$set('slots', self::arrangeSlots($get('slots'), $state ?? SectionLayouts::DEFAULT));
|
||||
})
|
||||
->extraAttributes(['class' => 'luf-layout-picker']),
|
||||
Section::make('Gestaltung des Abschnitts')
|
||||
->description(fn (Get $get): string => SectionStyle::summary(is_array($get('style')) ? $get('style') : []))
|
||||
->icon('heroicon-o-swatch')
|
||||
->collapsible()
|
||||
->collapsed()
|
||||
// Abschnittsgestaltung in drei Gruppen. Im Seiten-Arbeitsplatz nur im Kontext „Abschnitt gestalten“
|
||||
// sichtbar und dort offen; beim Anlegen einer Seite an jedem Abschnitt, eingeklappt.
|
||||
Section::make('Raster und Breite')
|
||||
->columnSpanFull()
|
||||
->extraAttributes(['class' => 'luf-nur-gestalten luf-gestaltung'])
|
||||
->collapsible(fn ($livewire): bool => ! self::onWorkplace($livewire))
|
||||
->collapsed(fn ($livewire): bool => ! self::onWorkplace($livewire))
|
||||
->compact()
|
||||
->schema([
|
||||
Group::make(self::styleFields())
|
||||
->statePath('style')
|
||||
->columns(['default' => 1, 'md' => 2, 'xl' => 4]),
|
||||
ToggleButtons::make('layout')
|
||||
->label('Raster')
|
||||
->options(self::layoutOptions())
|
||||
->default(SectionLayouts::DEFAULT)
|
||||
->required()
|
||||
->inline()
|
||||
->live()
|
||||
->disableOptionWhen(fn (string $value, Get $get): bool => self::filledCount($get('slots')) > SectionLayouts::slotCount($value))
|
||||
->helperText(fn (Get $get): ?string => self::filledCount($get('slots')) > 1
|
||||
? 'Raster mit weniger Plätzen als eingesetzten Widgets sind gesperrt. Entfernen oder verschieben Sie zuerst ein Widget; beim Wechsel geht kein Widget verloren.'
|
||||
: null)
|
||||
->afterStateUpdated(function (?string $state, Get $get, Set $set): void {
|
||||
$set('slots', self::arrangeSlots($get('slots'), $state ?? SectionLayouts::DEFAULT));
|
||||
})
|
||||
->extraAttributes(['class' => 'luf-layout-picker']),
|
||||
Group::make([self::widthField()])->statePath('style')->columns(['default' => 1, 'md' => 2]),
|
||||
]),
|
||||
Section::make('Hintergrund')
|
||||
->extraAttributes(['class' => 'luf-nur-gestalten luf-gestaltung'])
|
||||
->collapsible(fn ($livewire): bool => ! self::onWorkplace($livewire))
|
||||
->collapsed(fn ($livewire): bool => ! self::onWorkplace($livewire))
|
||||
->compact()
|
||||
->schema([
|
||||
Group::make(self::backgroundFields())->statePath('style')->columns(['default' => 1, 'md' => 2]),
|
||||
]),
|
||||
Section::make('Abstände und Trenner')
|
||||
->extraAttributes(['class' => 'luf-nur-gestalten luf-gestaltung'])
|
||||
->collapsible(fn ($livewire): bool => ! self::onWorkplace($livewire))
|
||||
->collapsed(fn ($livewire): bool => ! self::onWorkplace($livewire))
|
||||
->compact()
|
||||
->schema([
|
||||
Group::make(self::spacingFields())->statePath('style')->columns(['default' => 1, 'md' => 2]),
|
||||
]),
|
||||
Repeater::make('slots')
|
||||
->columnSpanFull()
|
||||
->label('Plätze im Raster')
|
||||
->hiddenLabel()
|
||||
->schema([
|
||||
@@ -113,8 +144,8 @@ private static function sectionSchema(): array
|
||||
->deletable(false)
|
||||
->reorderableWithDragAndDrop()
|
||||
->reorderableWithButtons(false)
|
||||
->reorderAction(fn (Action $action): Action => $action->tooltip('Widget auf einen anderen Platz ziehen'))
|
||||
->itemLabel(fn (array $state, ?int $index, Get $get): string => self::slotLabel($state, $index, $get('layout')))
|
||||
->reorderAction(fn (Action $action): Action => $action->label('Baustein auf einen anderen Platz ziehen')->tooltip('Baustein auf einen anderen Platz ziehen'))
|
||||
->itemLabel(fn (array $state, ?int $index, Get $get): HtmlString => self::slotLabel($state, $index, $get('layout')))
|
||||
->default(fn (): array => self::arrangeSlots([], SectionLayouts::DEFAULT))
|
||||
->extraAttributes(fn (Get $get): array => [
|
||||
'class' => 'luf-slots',
|
||||
@@ -123,10 +154,27 @@ private static function sectionSchema(): array
|
||||
];
|
||||
}
|
||||
|
||||
private static function onWorkplace(mixed $livewire): bool
|
||||
{
|
||||
return is_object($livewire) && method_exists($livewire, 'openAbschnitt');
|
||||
}
|
||||
|
||||
private static function widthField(): Select
|
||||
{
|
||||
return Select::make('width')
|
||||
->label('Inhaltsbreite')
|
||||
->options(SectionStyle::WIDTHS)
|
||||
->default('standard')
|
||||
->selectablePlaceholder(false)
|
||||
->hintIcon('heroicon-o-question-mark-circle', 'Ein Hintergrund reicht immer über die ganze Bildschirmbreite.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Hintergrund; Bild, Ausschnitt und Überlagerung nur beim Hintergrund „Bild“.
|
||||
*
|
||||
* @return list<mixed>
|
||||
*/
|
||||
private static function styleFields(): array
|
||||
private static function backgroundFields(): array
|
||||
{
|
||||
return [
|
||||
Select::make('background')
|
||||
@@ -135,35 +183,6 @@ private static function styleFields(): array
|
||||
->default('default')
|
||||
->selectablePlaceholder(false)
|
||||
->live(),
|
||||
Select::make('width')
|
||||
->label('Breite')
|
||||
->options(SectionStyle::WIDTHS)
|
||||
->default('standard')
|
||||
->selectablePlaceholder(false)
|
||||
->helperText('Ein Hintergrund reicht immer über die ganze Bildschirmbreite.'),
|
||||
Select::make('spacing_top')
|
||||
->label('Abstand oben')
|
||||
->options(SectionStyle::SPACINGS)
|
||||
->default(SectionStyle::DEFAULTS['spacing_top'])
|
||||
->selectablePlaceholder(false)
|
||||
->helperText('Vor dem Inhalt. Zwischen zwei Abschnitten addieren sich „unten“ und „oben“; „Kein Abstand“ lässt einen Einstieg direkt unter der Kopfzeile beginnen.'),
|
||||
Select::make('spacing_bottom')
|
||||
->label('Abstand unten')
|
||||
->options(SectionStyle::SPACINGS)
|
||||
->default(SectionStyle::DEFAULTS['spacing_bottom'])
|
||||
->selectablePlaceholder(false)
|
||||
->helperText('Nach dem Inhalt. Bei eigener Fläche liegen beide Abstände innerhalb der Fläche.'),
|
||||
Select::make('gap')
|
||||
->label('Widget-Abstand')
|
||||
->options(SectionStyle::SPACINGS)
|
||||
->default(SectionStyle::DEFAULTS['gap'])
|
||||
->selectablePlaceholder(false)
|
||||
->helperText('Zwischen den Plätzen dieses Abschnitts, nebeneinander und gestapelt. Abstände innerhalb eines Widgets bleiben Sache des Widgets.'),
|
||||
Select::make('divider')
|
||||
->label('Trenner zum nächsten Abschnitt')
|
||||
->options(SectionStyle::DIVIDERS)
|
||||
->default('none')
|
||||
->selectablePlaceholder(false),
|
||||
...array_map(
|
||||
fn ($field) => $field->visible(fn (Get $get): bool => $get('background') === 'image')->columnSpan(['default' => 1, 'md' => 2]),
|
||||
ImageRefFields::fields('Hintergrundbild'),
|
||||
@@ -173,18 +192,50 @@ private static function styleFields(): array
|
||||
->options(SectionStyle::FOCUS)
|
||||
->default('center')
|
||||
->selectablePlaceholder(false)
|
||||
->helperText('Dieser Bereich bleibt auf schmalen Bildschirmen sichtbar.')
|
||||
->hintIcon('heroicon-o-question-mark-circle', 'Dieser Bereich bleibt auf schmalen Bildschirmen sichtbar.')
|
||||
->visible(fn (Get $get): bool => $get('background') === 'image'),
|
||||
Select::make('overlay')
|
||||
->label('Überlagerung')
|
||||
->options(SectionStyle::OVERLAYS)
|
||||
->default('light')
|
||||
->selectablePlaceholder(false)
|
||||
->helperText('Sorgt für lesbaren Text auf dem Bild.')
|
||||
->hintIcon('heroicon-o-question-mark-circle', 'Sorgt für lesbaren Text auf dem Bild.')
|
||||
->visible(fn (Get $get): bool => $get('background') === 'image'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<mixed>
|
||||
*/
|
||||
private static function spacingFields(): array
|
||||
{
|
||||
return [
|
||||
Select::make('spacing_top')
|
||||
->label('Abstand oben')
|
||||
->options(SectionStyle::SPACINGS)
|
||||
->default(SectionStyle::DEFAULTS['spacing_top'])
|
||||
->selectablePlaceholder(false)
|
||||
->hintIcon('heroicon-o-question-mark-circle', 'Vor dem Inhalt. Zwischen zwei Abschnitten addieren sich „unten“ und „oben“; „Kein Abstand“ lässt einen Einstieg direkt unter der Kopfzeile beginnen.'),
|
||||
Select::make('spacing_bottom')
|
||||
->label('Abstand unten')
|
||||
->options(SectionStyle::SPACINGS)
|
||||
->default(SectionStyle::DEFAULTS['spacing_bottom'])
|
||||
->selectablePlaceholder(false)
|
||||
->hintIcon('heroicon-o-question-mark-circle', 'Nach dem Inhalt. Bei eigener Fläche liegen beide Abstände innerhalb der Fläche.'),
|
||||
Select::make('gap')
|
||||
->label('Widget-Abstand')
|
||||
->options(SectionStyle::SPACINGS)
|
||||
->default(SectionStyle::DEFAULTS['gap'])
|
||||
->selectablePlaceholder(false)
|
||||
->hintIcon('heroicon-o-question-mark-circle', 'Zwischen den Plätzen dieses Abschnitts, nebeneinander und gestapelt. Abstände innerhalb eines Widgets bleiben Sache des Widgets.'),
|
||||
Select::make('divider')
|
||||
->label('Trenner zum nächsten Abschnitt')
|
||||
->options(SectionStyle::DIVIDERS)
|
||||
->default('none')
|
||||
->selectablePlaceholder(false),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gespeicherte Abschnitte (PageSections::read) als Formularzustand.
|
||||
*
|
||||
@@ -481,7 +532,7 @@ private static function editorColumns(mixed $layout): string
|
||||
/**
|
||||
* @param array<string, mixed> $state
|
||||
*/
|
||||
private static function sectionLabel(array $state, ?int $index): string
|
||||
private static function sectionLabel(array $state, ?int $index): HtmlString
|
||||
{
|
||||
$layout = SectionLayouts::has($state['layout'] ?? null) ? $state['layout'] : SectionLayouts::DEFAULT;
|
||||
$registry = app(WidgetRegistry::class);
|
||||
@@ -495,16 +546,48 @@ private static function sectionLabel(array $state, ?int $index): string
|
||||
}
|
||||
}
|
||||
|
||||
$label = 'Abschnitt '.(($index ?? 0) + 1).' · Raster '.SectionLayouts::short($layout)
|
||||
.' · '.SectionStyle::summary(is_array($state['style'] ?? null) ? $state['style'] : []);
|
||||
// Kurz sichtbar: Nummer, Raster und nur abweichende Gestaltung. Vollständig im Titel und für Screenreader.
|
||||
$style = SectionStyle::fromStored(is_array($state['style'] ?? null) ? $state['style'] : []);
|
||||
$meta = ['Raster '.SectionLayouts::short($layout)];
|
||||
if ($style['background'] !== 'default') {
|
||||
$meta[] = SectionStyle::BACKGROUNDS[$style['background']] ?? $style['background'];
|
||||
}
|
||||
if ($style['width'] !== 'standard') {
|
||||
$meta[] = SectionStyle::WIDTHS[$style['width']] ?? $style['width'];
|
||||
}
|
||||
if ($style['divider'] !== 'none') {
|
||||
$meta[] = 'Trenner';
|
||||
}
|
||||
if ($names === []) {
|
||||
$meta[] = 'noch leer';
|
||||
}
|
||||
|
||||
return $names === [] ? $label.' · noch leer' : $label.' · '.implode(', ', $names);
|
||||
$name = 'Abschnitt '.(($index ?? 0) + 1);
|
||||
$full = 'Raster '.SectionLayouts::short($layout).' · '.SectionStyle::summary($style)
|
||||
.($names === [] ? ' · noch leer' : ' · '.implode(', ', $names));
|
||||
|
||||
return new HtmlString('<span class="luf-abschnitt" title="'.e($full).'"><span class="luf-abschnitt-nr">'.e($name).'</span>'
|
||||
.'<span class="luf-abschnitt-meta" aria-hidden="true">'.e(implode(' · ', $meta)).'</span>'
|
||||
.'<span class="vw-sr">: '.e($full).'</span></span>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $state
|
||||
*/
|
||||
private static function slotLabel(array $state, ?int $index, mixed $layout): string
|
||||
private static function slotLabel(array $state, ?int $index, mixed $layout): HtmlString
|
||||
{
|
||||
$text = self::slotText($state, $index, $layout);
|
||||
|
||||
// Plätze zeigen sich über Lage und Breite; benannt werden sie nur für Screenreader oder bei einem Problem.
|
||||
return str_contains($text, 'passt nicht') || str_contains($text, 'außerhalb')
|
||||
? new HtmlString('<span class="luf-platz-warnung">'.e($text).'</span>')
|
||||
: new HtmlString('<span class="vw-sr">'.e($text).'</span>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $state
|
||||
*/
|
||||
private static function slotText(array $state, ?int $index, mixed $layout): string
|
||||
{
|
||||
$layout = SectionLayouts::has($layout) ? $layout : SectionLayouts::DEFAULT;
|
||||
$units = SectionLayouts::units($layout);
|
||||
|
||||
Loaded 100 of 685 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user