CI Feature / test (push) Successful in 5m40s
Die Marken eines Films liegen als metadata['markers'] an der Fassung. Bis eine
Fassung entsteht, gibt es einen Arbeitsstand in content_elements.marker_draft
(neue, leere Spalte, rückwärtskompatibel): { base_version, markers, saved_at }.
Mitglieder sehen ihn nie, und er wird nicht gesondert protokolliert.
- FilmMarkers prüft und vereinheitlicht (Zeit auf 0,1 s, Titel, Mindestabstand
1 s, höchstens 100) und liest gespeicherte Daten reparierend. Der Altwert
decision_seconds gilt nur, solange der Schlüssel markers fehlt; eine
gelöschte Liste bringt ihn nicht zurück.
- MarkerDraft speichert den Arbeitsstand gegen gleichzeitiges Speichern
(saved_at als Marke) und räumt nur den Stand ab, der gelesen wurde.
- ContentService übernimmt die Marken der bisherigen Fassung, wenn eine Fassung
mit Datei ohne Marken angelegt wird. Vorher ging jede Fassung aus anderem
Anlass (Text, Notiz, neue Datei) ohne Marken hervor, weil die Aufrufer die
Metadaten selbst zusammenstellen.
- ElementRevision wendet den Arbeitsstand an. Eine Änderung nur an den Marken
zählt als Änderung, ohne Datei entsteht keine Fassung nur aus Marken.
Das Formularfeld decision_seconds entfällt.
Bewusste Änderung eines Tests: test_an_uploaded_file_becomes_a_ready_version
setzte decision_seconds über das Formular; der Wert kommt jetzt als Marke aus
dem Arbeitsstand.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
491 lines
16 KiB
PHP
491 lines
16 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Support;
|
||
|
||
use App\Domain\Catalog\Bundle;
|
||
use App\Domain\Catalog\BundleService;
|
||
use App\Domain\Catalog\BundleStatus;
|
||
use App\Domain\Catalog\BundleVersion;
|
||
use App\Domain\Catalog\Composition;
|
||
use App\Domain\Catalog\CompositionKind;
|
||
use App\Domain\Catalog\CompositionMember;
|
||
use App\Domain\Catalog\ContentElement;
|
||
use App\Domain\Catalog\ContentElementVersion;
|
||
use App\Domain\Catalog\ContentResolver;
|
||
use App\Domain\Catalog\ContentVersionStatus;
|
||
use App\Domain\Catalog\DomainRuleException;
|
||
use App\Domain\Catalog\LicenseArticle;
|
||
use App\Domain\Catalog\Offer;
|
||
use App\Domain\Catalog\OfferStatus;
|
||
use App\Domain\Catalog\OfferVersion;
|
||
use App\Domain\Catalog\ReleaseContent;
|
||
use App\Domain\Catalog\ResolvedScope;
|
||
use App\Domain\Catalog\RightsProfile;
|
||
use App\Domain\Catalog\RightsProfileVersion;
|
||
use App\Domain\Catalog\StatusValue;
|
||
use App\Domain\Media\FilmMarkers;
|
||
|
||
class CatalogReading
|
||
{
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function articleStand(LicenseArticle $article): array
|
||
{
|
||
$release = $article->currentRelease()->with(['contents.elementVersion.element'])->first();
|
||
|
||
if ($release === null) {
|
||
return ['Noch kein Stand veröffentlicht. Ein Lizenzartikel ohne Stand vergibt keine Inhalte.'];
|
||
}
|
||
|
||
$lines = [
|
||
'Stand '.$release->number.' · '.$this->status($release->status).' · '.$release->classification_note,
|
||
];
|
||
|
||
foreach ($release->contents as $content) {
|
||
$title = $content->elementVersion?->element?->working_title ?? 'Inhalt fehlt';
|
||
$lines[] = $content->path.' — '.$title;
|
||
}
|
||
|
||
if ($release->contents->isEmpty()) {
|
||
$lines[] = 'Dieser Stand hat keine festgeschriebenen Inhalte.';
|
||
}
|
||
|
||
return $lines;
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function articleContext(LicenseArticle $article): array
|
||
{
|
||
$lines = [];
|
||
|
||
foreach (BundleVersion::query()->where('status', BundleStatus::Veroeffentlicht)->with('bundle')->orderBy('id')->get() as $version) {
|
||
try {
|
||
$ids = app(BundleService::class)->articleIds($version);
|
||
} catch (DomainRuleException $exception) {
|
||
continue;
|
||
}
|
||
|
||
if (in_array($article->id, $ids, true)) {
|
||
$lines[] = 'Paket '.$version->bundle->name.' · Fassung '.$version->number;
|
||
}
|
||
}
|
||
|
||
$scopes = ResolvedScope::query()
|
||
->where('license_article_id', $article->id)
|
||
->with(['offerVersion.offer', 'rights.profile'])
|
||
->orderBy('id')
|
||
->get();
|
||
|
||
foreach ($scopes as $scope) {
|
||
$version = $scope->offerVersion;
|
||
$lines[] = 'Angebot '.$version->offer->name
|
||
.' · Fassung '.$version->number
|
||
.' · '.$this->status($version->status)
|
||
.' · '.$this->grant($version)
|
||
.' · '.$scope->rights->profile->name
|
||
.' ('.$this->capabilities($scope->rights).')';
|
||
}
|
||
|
||
return $lines === []
|
||
? ['Dieser Artikel ist noch in keinem veröffentlichten Paket und in keiner Angebotsfassung aufgelöst.']
|
||
: $lines;
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function bundleParts(Bundle $bundle): array
|
||
{
|
||
$version = $this->publishedBundle($bundle);
|
||
|
||
if ($version === null) {
|
||
return ['Noch keine veröffentlichte Fassung. Bestandteile werden mit der Fassung festgeschrieben.'];
|
||
}
|
||
|
||
$lines = ['Fassung '.$version->number];
|
||
|
||
foreach ($version->items as $item) {
|
||
if ($item->article !== null) {
|
||
$lines[] = 'Lizenzartikel '.$item->article->code;
|
||
|
||
continue;
|
||
}
|
||
|
||
$lines[] = 'Paket '.($item->nestedBundle->name ?? 'fehlt');
|
||
}
|
||
|
||
$older = $bundle->versions()->where('status', BundleStatus::Veroeffentlicht)->count() - 1;
|
||
|
||
if ($older > 0) {
|
||
$lines[] = $older.' ältere Fassung'.($older === 1 ? '' : 'en').' bleibt unverändert.';
|
||
}
|
||
|
||
return $lines;
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function bundleArticles(Bundle $bundle): array
|
||
{
|
||
$version = $this->publishedBundle($bundle);
|
||
|
||
if ($version === null) {
|
||
return ['Ohne Fassung gibt es nichts aufzulösen.'];
|
||
}
|
||
|
||
try {
|
||
$ids = app(BundleService::class)->articleIds($version);
|
||
} catch (DomainRuleException $exception) {
|
||
return [$exception->getMessage()];
|
||
}
|
||
|
||
$codes = LicenseArticle::query()->whereIn('id', $ids)->orderBy('code')->pluck('code')->all();
|
||
|
||
return $codes === []
|
||
? ['Die Fassung löst keinen Lizenzartikel auf.']
|
||
: $codes;
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function offerPositions(Offer $offer): array
|
||
{
|
||
$version = $this->activeOffer($offer);
|
||
|
||
if ($version === null) {
|
||
return ['Noch keine aktive Fassung. Ein Angebot ohne Fassung kann niemand erwerben.'];
|
||
}
|
||
|
||
$lines = [
|
||
'Fassung '.$version->number.' · '.$this->status($version->status).' · '.$this->grant($version),
|
||
];
|
||
|
||
foreach ($version->lines as $line) {
|
||
$target = $line->article !== null
|
||
? 'Lizenzartikel '.$line->article->code
|
||
: 'Paket '.($line->bundleVersion->bundle->name ?? 'fehlt').' · Fassung '.($line->bundleVersion->number ?? '–');
|
||
$lines[] = $target.' · Rechte '.$line->rights->profile->name;
|
||
}
|
||
|
||
return $lines;
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function offerGrants(Offer $offer): array
|
||
{
|
||
$version = $this->activeOffer($offer);
|
||
|
||
if ($version === null) {
|
||
return ['Der Leistungsumfang wird erst beim Aktivieren aufgelöst.'];
|
||
}
|
||
|
||
$lines = [];
|
||
|
||
foreach ($version->resolvedScopes as $scope) {
|
||
$lines[] = $scope->article->code.' · '.$scope->rights->profile->name.' · '.$this->capabilities($scope->rights);
|
||
}
|
||
|
||
return $lines === []
|
||
? ['Diese Fassung hat keinen aufgelösten Leistungsumfang.']
|
||
: $lines;
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function rights(RightsProfile $profile): array
|
||
{
|
||
$version = $profile->versions()->orderByDesc('number')->first();
|
||
|
||
if ($version === null) {
|
||
return ['Noch keine Fassung.'];
|
||
}
|
||
|
||
return [
|
||
'Fassung '.$version->number.' · '.$this->purpose($version->purpose),
|
||
$this->capabilities($version),
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function elementVersions(ContentElement $element): array
|
||
{
|
||
$versions = $element->versions()->orderByDesc('number')->get();
|
||
|
||
if ($versions->isEmpty()) {
|
||
return ['Noch keine Fassung.'];
|
||
}
|
||
|
||
return $versions->flatMap(function ($version): array {
|
||
$note = filled($version->change_note) ? ' · '.$version->change_note : '';
|
||
$lines = ['Fassung '.$version->number.' · '.$this->status($version->status).$note];
|
||
$metadata = is_array($version->metadata) ? $version->metadata : [];
|
||
|
||
if (filled($version->body)) {
|
||
$lines[] = $version->body;
|
||
}
|
||
|
||
if (is_string($metadata['file'] ?? null) && $metadata['file'] !== '') {
|
||
$lines[] = 'Datei: '.basename($metadata['file']);
|
||
} elseif (is_string($metadata['incoming'] ?? null) || is_array($metadata['incoming'] ?? null)) {
|
||
$lines[] = 'Die Datei wird noch übernommen.';
|
||
}
|
||
|
||
$markers = FilmMarkers::ofVersion($version);
|
||
|
||
if ($markers !== []) {
|
||
$stops = count(array_filter($markers, fn (array $marker): bool => $marker['stop']));
|
||
$lines[] = count($markers).(count($markers) === 1 ? ' Marke' : ' Marken')
|
||
.($stops > 0 ? ', davon '.$stops.' mit Stopp' : '').': '
|
||
.implode(', ', array_map(fn (array $marker): string => FilmMarkers::format($marker['t']).' s '.$marker['label'], $markers));
|
||
}
|
||
|
||
if (is_string($metadata['error'] ?? null) && $metadata['error'] !== '') {
|
||
$lines[] = $metadata['error'];
|
||
}
|
||
|
||
return $lines;
|
||
})->all();
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function elementUsage(ContentElement $element): array
|
||
{
|
||
$versionIds = $element->versions()->pluck('id');
|
||
$lines = [];
|
||
|
||
$members = CompositionMember::query()
|
||
->whereIn('content_element_version_id', $versionIds)
|
||
->with(['compositionVersion.composition', 'contentElementVersion'])
|
||
->orderBy('id')
|
||
->get();
|
||
|
||
foreach ($members as $member) {
|
||
$lines[] = self::compositionLabelOf($member->compositionVersion->composition)
|
||
.' · Fassung '.$member->compositionVersion->number
|
||
.' · Rolle '.$member->role;
|
||
}
|
||
|
||
$contents = ReleaseContent::query()
|
||
->whereIn('content_element_version_id', $versionIds)
|
||
->with(['release.article', 'elementVersion'])
|
||
->orderBy('id')
|
||
->get();
|
||
|
||
foreach ($contents as $content) {
|
||
$lines[] = 'Lizenzartikel '.$content->release->article->code
|
||
.' · Stand '.$content->release->number
|
||
.' · '.$content->path
|
||
.($content->variant_key !== null ? ' · Variante '.$content->variant_key : '')
|
||
.($content->requirement === CompositionMember::SUPPLEMENTARY ? ' · ergänzend' : '');
|
||
}
|
||
|
||
return $lines === []
|
||
? ['Noch in keiner Komposition und in keinem Artikel-Stand verwendet.']
|
||
: $lines;
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function compositionMembers(Composition $composition): array
|
||
{
|
||
$version = $composition->versions()
|
||
->where('status', ContentVersionStatus::Bereit)
|
||
->orderByDesc('number')
|
||
->with(['members.contentElementVersion.element', 'members.nestedCompositionVersion.composition'])
|
||
->first();
|
||
|
||
if ($version === null) {
|
||
return ['Noch keine bestätigte Fassung.'];
|
||
}
|
||
|
||
$lines = ['Fassung '.$version->number];
|
||
|
||
foreach ($version->members as $member) {
|
||
if ($member->contentElementVersion !== null) {
|
||
$lines[] = $member->role.' — '.$member->contentElementVersion->element->working_title;
|
||
|
||
continue;
|
||
}
|
||
|
||
$nested = $member->nestedCompositionVersion;
|
||
$lines[] = $member->role.' — '.($nested === null ? 'fehlt' : self::compositionLabelOf($nested->composition));
|
||
}
|
||
|
||
return $lines;
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function memberPillars(Composition $composition): array
|
||
{
|
||
$version = $composition->versions()
|
||
->where('status', ContentVersionStatus::Bereit)
|
||
->orderByDesc('number')
|
||
->first();
|
||
|
||
if ($version === null) {
|
||
return ['Noch keine Fassung, deshalb keine Säulen.'];
|
||
}
|
||
|
||
$rows = app(ContentResolver::class)->expand($version);
|
||
$versions = ContentElementVersion::query()
|
||
->whereIn('id', array_column($rows, 'version_id'))
|
||
->with('element.pillars')
|
||
->get()
|
||
->keyBy('id');
|
||
$lines = [];
|
||
|
||
foreach ($rows as $row) {
|
||
$element = $versions[$row['version_id']]->element;
|
||
$names = $element->pillars->pluck('name');
|
||
$lines[] = $element->working_title.' — '.($names->isEmpty() ? 'keiner Säule zugeordnet' : $names->join(', '));
|
||
}
|
||
|
||
return $lines === [] ? ['Diese Fassung enthält keine Medien.'] : $lines;
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function compositionUsage(Composition $composition): array
|
||
{
|
||
$versionIds = $composition->versions()->pluck('id');
|
||
$lines = [];
|
||
|
||
$parents = CompositionMember::query()
|
||
->whereIn('nested_composition_version_id', $versionIds)
|
||
->with('compositionVersion.composition')
|
||
->orderBy('id')
|
||
->get();
|
||
|
||
foreach ($parents as $member) {
|
||
$lines[] = self::compositionLabelOf($member->compositionVersion->composition)
|
||
.' · Fassung '.$member->compositionVersion->number
|
||
.' · Rolle '.$member->role;
|
||
}
|
||
|
||
$articles = LicenseArticle::query()
|
||
->whereHas('releases', function ($query) use ($versionIds): void {
|
||
$query->whereIn('root_composition_version_id', $versionIds);
|
||
})
|
||
->orderBy('code')
|
||
->pluck('code');
|
||
|
||
foreach ($articles as $code) {
|
||
$lines[] = 'Wurzel des Lizenzartikels '.$code;
|
||
}
|
||
|
||
return $lines === []
|
||
? ['Noch nicht in einer anderen Komposition und nicht als Wurzel eines Artikels verwendet.']
|
||
: $lines;
|
||
}
|
||
|
||
private function publishedBundle(Bundle $bundle): ?BundleVersion
|
||
{
|
||
return $bundle->versions()
|
||
->where('status', BundleStatus::Veroeffentlicht)
|
||
->orderByDesc('number')
|
||
->with(['items.article', 'items.nestedBundle'])
|
||
->first();
|
||
}
|
||
|
||
private function activeOffer(Offer $offer): ?OfferVersion
|
||
{
|
||
return $offer->versions()
|
||
->where('status', OfferStatus::Aktiv)
|
||
->orderByDesc('number')
|
||
->with([
|
||
'lines.article',
|
||
'lines.bundleVersion.bundle',
|
||
'lines.rights.profile',
|
||
'resolvedScopes.article',
|
||
'resolvedScopes.rights.profile',
|
||
])
|
||
->first();
|
||
}
|
||
|
||
private function grant(OfferVersion $version): string
|
||
{
|
||
$kind = match ($version->grant_kind) {
|
||
'kauf' => 'Kauf',
|
||
'auf_abruf' => 'Auf Abruf',
|
||
'bei_registrierung' => 'Bei Registrierung',
|
||
default => (string) $version->grant_kind,
|
||
};
|
||
|
||
if ($version->price_cents === null) {
|
||
return $kind;
|
||
}
|
||
|
||
return $kind.' · '.number_format($version->price_cents / 100, 2, ',', '.').' €';
|
||
}
|
||
|
||
private function capabilities(RightsProfileVersion $version): string
|
||
{
|
||
$parts = [];
|
||
|
||
foreach ($version->capabilities ?? [] as $class => $actions) {
|
||
$actions = is_array($actions) ? implode(', ', $actions) : (string) $actions;
|
||
$parts[] = $class.': '.$actions;
|
||
}
|
||
|
||
return $parts === [] ? 'keine Fähigkeiten' : implode('; ', $parts);
|
||
}
|
||
|
||
private function purpose(string $purpose): string
|
||
{
|
||
return match ($purpose) {
|
||
'ehrenamtlich' => 'Ehrenamtlich',
|
||
'kommerziell' => 'Kommerziell',
|
||
'institutionell' => 'Institutionell',
|
||
default => $purpose,
|
||
};
|
||
}
|
||
|
||
/**
|
||
* Eine Zusammenstellung, die dieser Programmstand nicht kennt, erscheint nur als Hinweis ohne Namen und Inhalt.
|
||
*/
|
||
private static function compositionLabelOf(?Composition $composition): string
|
||
{
|
||
return $composition === null
|
||
? 'Zusammenstellung einer neueren Programmversion'
|
||
: self::compositionLabel($composition);
|
||
}
|
||
|
||
private static function compositionLabel(Composition $composition): string
|
||
{
|
||
$kind = $composition->kind;
|
||
$label = $kind instanceof CompositionKind ? $kind->label() : 'Zusammenstellung';
|
||
|
||
return $label.': '.$composition->designation;
|
||
}
|
||
|
||
private function status(mixed $status): string
|
||
{
|
||
return match (StatusValue::of($status)) {
|
||
'veroeffentlicht' => 'veröffentlicht',
|
||
'abgeloest_verfuegbar' => 'abgelöst, weiterhin verfügbar',
|
||
'gesperrt' => 'gesperrt',
|
||
'bereit' => 'bereit',
|
||
'entwurf' => 'Entwurf',
|
||
'aktiv' => 'aktiv',
|
||
'beendet' => 'beendet',
|
||
default => StatusValue::of($status) ?? 'unbekannt',
|
||
};
|
||
}
|
||
}
|