Files
laraundfelix/app/Domain/Commerce/ProductOptions.php
T
LarsandClaude Sonnet 5.5 2e6260acca Gestalte den Mitgliederbereich nach Brand-UI-Kit 14 neu
Eine Navigation (Meine Bibliothek, Programme, Meine Lizenzen, Konto-Menü) mit der freigegebenen Wortmarke,
Startseite ohne erfundene Inhalte, Bibliothek mit Inhaltsart-Filter und einer Karte je Medienidentität
(„Verwendet in“), Programm-/Moduldetail, Film und Material im Zusammenhang mit Begleitmaterial und Weg zurück,
Lizenzübersicht mit Detailseite je Berechtigung. Alle Größen aus der Größenskala (ADR-44, neues Token --card-min).

Tests bewusst angepasst: Der Film spielt auf der Kontextseite statt eingebettet im Programm, Download-Links tragen
ein Symbol, der Platzhalter ist ein dekoratives Element, die Wortmarke ist das freigegebene Logo. Die Vorschau der
Bibliothekskarte in der Verwaltung nutzt dieselbe Komponente.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 17:56:16 +01:00

146 lines
4.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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 self::termRuleLabel($version->term_rule);
}
/** Laufzeitregel aus der Angebotsfassung oder aus den Bedingungen eines Erwerbs (gleiche Schlüssel). */
public static function termRuleLabel(?string $rule): string
{
return match ((string) $rule) {
'dauerhaft' => 'Dauerhaft nutzbar',
'befristet' => 'Befristet',
'solange_angebot_aktiv' => 'Solange das Angebot aktiv ist',
'periodisch' => 'Laufend, periodisch',
default => (string) $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 '';
}
}