> */ 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 */ 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 */ 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 '–'; } // Wie in der Redaktion: eigener Name, sonst der Name des Inhalts, zuletzt die Kennung. $name = app(EditorialProfileReader::class)->read($article, 'detail')->value('display_title'); return (string) (filled($name) ? $name : ($article->working_title ?: $article->code)); } }