Biete in der Shopliste Auswahl, Reihenfolge, Listenansicht und Seiten
CI Feature / test (push) Successful in 6m4s

- ShopCatalog::listing mit Auswahl nach Thema, Materialart, Eignung und Nutzerkreis, Reihenfolge, Ansicht und Seiten
- Listenansicht shop/zeile, gemeinsame Liste fuer Shopseite und Widget (Variante Liste, Einstellung Auswahl fuer Besucher)
- Werte aus dem Abfragetext werden gegen vorhandene Werte geprueft, Felder als Liste und Zahlen ausserhalb des Bereichs sind harmlos
- Suchfeld heisst nach dem Umbau Zurücksetzen statt Suche zuruecksetzen (Test bewusst angepasst)
- ADR-57

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-26 08:35:33 +01:00
1 parent 95a888d1ca
commit f0ffb47210
15 files changed
+651 -73

No files matched your search

+140 -11
View File
@@ -6,6 +6,7 @@
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\EditorialProfileReader;
use App\Domain\Catalog\FormattedText;
use App\Domain\Catalog\LicenceScope;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\Pillar;
use App\Domain\Catalog\PresentationMedia;
@@ -37,11 +38,21 @@ public function __construct(
public const SORTS = ['name' => 'Alphabetisch', 'neu' => 'Neueste zuerst', 'preis' => 'Preis aufsteigend'];
/**
* @param array{pillar?: int|null, kind?: int|null, sort?: string|null, limit?: int|null} $options Filter nach Säule
* und Materialart, Sortierung (name, neu, preis) und Höchstzahl
* @param array{pillar?: int|null, kind?: int|null, holder?: string|null, scope?: string|null, sort?: string|null, limit?: int|null} $options Filter
* nach Säule, Materialart, Eignung und Nutzerkreis, Sortierung (name, neu, preis) und Höchstzahl
* @return list<array<string, mixed>>
*/
public function cards(string $term = '', array $options = []): array
{
return $this->arrange($this->all($term), $options);
}
/**
* Alle Kacheln zu einem Suchbegriff, ungefiltert und in der Reihenfolge der Quellen.
*
* @return list<array<string, mixed>>
*/
public function all(string $term = ''): array
{
$term = mb_strtolower(mb_substr(trim($term), 0, 100));
$cards = [];
@@ -56,10 +67,13 @@ public function cards(string $term = '', array $options = []): array
$title = (string) ($composition->display_title ?: $composition->designation);
$teaser = (string) ($composition->teaser ?: FormattedText::plain($composition->summary));
$pillars = $this->pillarNames($composition->pillars);
$pillarMap = $this->publishedPillars($composition->pillars);
$pillars = array_values($pillarMap);
$card = $this->card('c:'.$composition->id, 'programm', route('public.program', $composition), $title, $teaser, $summaries[$composition->id], 'Programm', null, $pillars, [], $this->image($composition));
$card['pillar_ids'] = $composition->pillars->pluck('id')->map(fn ($id): int => (int) $id)->all();
$card['pillar_ids'] = array_keys($pillarMap);
$card['kind_id'] = $composition->editorial_content_kind_id !== null ? (int) $composition->editorial_content_kind_id : null;
$card['holders'] = $summaries[$composition->id]['holders'] ?? [];
$card['scopes'] = $summaries[$composition->id]['scopes'] ?? [];
if ($this->matches($term, $title.' '.$teaser.' '.FormattedText::plain($composition->summary).' '.$composition->search_terms.' '.implode(' ', $pillars))) {
$cards[] = $card;
@@ -74,15 +88,18 @@ public function cards(string $term = '', array $options = []): array
$title = $this->products->articleTitle($article);
$teaser = (string) ($profile->value('teaser') ?: $profile->value('summary'));
$kind = $article->editorialContentKind;
$pillars = $this->pillarNames($article->pillars);
$pillarMap = $this->publishedPillars($article->pillars);
$pillars = array_values($pillarMap);
$offerIds = array_map(fn ($offer): int => (int) $offer->id, $this->products->offersOfArticle($article));
$card = $this->card(
'a:'.$article->id, 'artikel', route('shop.article', $article), $title, $teaser, $articleSummaries[$article->id],
(string) ($kind?->label ?? ''), $this->symbol($kind?->symbol), $pillars, $this->markers->visible($article, $offerIds), $this->image($article),
);
$card['pillar_ids'] = $article->pillars->pluck('id')->map(fn ($id): int => (int) $id)->all();
$card['pillar_ids'] = array_keys($pillarMap);
$card['kind_id'] = $kind !== null ? (int) $kind->id : null;
$card['since'] = $this->markers->firstOffered($offerIds)?->getTimestamp() ?? 0;
$card['holders'] = $articleSummaries[$article->id]['holders'] ?? [];
$card['scopes'] = $articleSummaries[$article->id]['scopes'] ?? [];
if ($this->matches($term, $title.' '.$teaser.' '.$profile->value('summary').' '.$profile->searchTerms.' '.($kind?->label ?? '').' '.implode(' ', $pillars))) {
$cards[] = $card;
@@ -97,13 +114,15 @@ public function cards(string $term = '', array $options = []): array
$names = implode(', ', array_column($contents, 'title'));
$teaser = 'Paket mit '.count($contents).' '.(count($contents) === 1 ? 'Inhalt' : 'Inhalten').($names !== '' ? ': '.$names : '');
$card = $this->card('b:'.$bundle->id, 'paket', route('public.package', $bundle), (string) $bundle->name, $teaser, $bundleSummaries[$bundle->id], 'Paket', null, [], [], $this->image($bundle));
$card['holders'] = $bundleSummaries[$bundle->id]['holders'] ?? [];
$card['scopes'] = $bundleSummaries[$bundle->id]['scopes'] ?? [];
if ($this->matches($term, $bundle->name.' '.$names)) {
$cards[] = $card;
}
}
return $this->arrange($cards, $options);
return $cards;
}
/**
@@ -114,7 +133,7 @@ public function cards(string $term = '', array $options = []): array
* @param array<string, mixed> $options
* @return list<array<string, mixed>>
*/
private function arrange(array $cards, array $options): array
public function arrange(array $cards, array $options): array
{
$pillar = isset($options['pillar']) ? (int) $options['pillar'] : 0;
$kind = isset($options['kind']) ? (int) $options['kind'] : 0;
@@ -127,6 +146,17 @@ private function arrange(array $cards, array $options): array
$cards = array_filter($cards, fn (array $card): bool => ($card['kind_id'] ?? null) === $kind);
}
$holder = (string) ($options['holder'] ?? '');
$scope = (string) ($options['scope'] ?? '');
if ($holder !== '') {
$cards = array_filter($cards, fn (array $card): bool => in_array($holder, $card['holders'] ?? [], true));
}
if ($scope !== '') {
$cards = array_filter($cards, fn (array $card): bool => in_array($scope, $card['scopes'] ?? [], true));
}
$cards = array_values($cards);
match ($options['sort'] ?? null) {
@@ -141,6 +171,103 @@ private function arrange(array $cards, array $options): array
return $limit > 0 ? array_slice($cards, 0, $limit) : $cards;
}
public const HOLDERS = ['person' => 'Privatpersonen', 'organisation' => 'Organisationen und Vereine'];
public const SCOPES = [LicenceScope::SINGLE => 'Einzellizenz', LicenceScope::MULTI => 'Mehrfachlizenz'];
/**
* Die Auswahl, die ein Besucher bei diesen Kacheln hat: nur Werte, die es gibt, und nur Auswahlfelder mit mindestens
* zwei Werten (sonst filtert nichts).
*
* @param list<array<string, mixed>> $cards
* @return array{pillar: array<int, string>, kind: array<int, string>, holder: array<string, string>, scope: array<string, string>}
*/
public function facets(array $cards): array
{
$pillars = [];
$kinds = [];
$holders = [];
$scopes = [];
foreach ($cards as $card) {
foreach (array_values($card['pillar_ids'] ?? []) as $index => $id) {
$pillars[(int) $id] = (string) ($card['pillars'][$index] ?? '');
}
if (($card['kind_id'] ?? null) !== null && ($card['kind_label'] ?? '') !== '') {
$kinds[(int) $card['kind_id']] = (string) $card['kind_label'];
}
foreach ($card['holders'] ?? [] as $holder) {
if (isset(self::HOLDERS[$holder])) {
$holders[$holder] = self::HOLDERS[$holder];
}
}
foreach ($card['scopes'] ?? [] as $scope) {
if (isset(self::SCOPES[$scope])) {
$scopes[$scope] = self::SCOPES[$scope];
}
}
}
asort($pillars);
asort($kinds);
$facets = ['pillar' => $pillars, 'kind' => $kinds, 'holder' => $holders, 'scope' => $scopes];
return array_map(fn (array $values): array => count($values) >= 2 ? $values : [], $facets);
}
/**
* Die Produktliste für Shopseite und Widget: Suche, Auswahl des Besuchers (Säule, Materialart, Eignung,
* Nutzerkreis), Reihenfolge, Ansicht und Seiten. Alles kommt aus dem Abfragetext und wird gegen feste Werte
* geprüft; unbekannte Werte entfallen.
*
* @param array<string, mixed> $query Abfrage des Besuchers (suche, saeule, art, eignung, kreis, sort, ansicht, seite)
* @param array<string, mixed> $fixed Vorgaben der Seite (pillar, kind, sort, limit, view, filters)
* @return array<string, mixed>
*/
public function listing(array $query, array $fixed = []): array
{
$text = fn (string $key): string => isset($query[$key]) && (is_string($query[$key]) || is_int($query[$key])) ? trim((string) $query[$key]) : '';
$filters = (bool) ($fixed['filters'] ?? true);
$term = mb_substr($text('suche'), 0, 100);
$base = $this->arrange($this->all($term), array_intersect_key($fixed, ['pillar' => 1, 'kind' => 1]));
$facets = $filters ? $this->facets($base) : ['pillar' => [], 'kind' => [], 'holder' => [], 'scope' => []];
$pick = function (string $key, string $facet) use ($text, $facets, $filters): int|string|null {
$value = $text($key);
return $filters && $value !== '' && array_key_exists($value, $facets[$facet]) ? (ctype_digit($value) ? (int) $value : $value) : null;
};
$chosen = [
'pillar' => $pick('saeule', 'pillar'),
'kind' => $pick('art', 'kind'),
'holder' => $pick('eignung', 'holder'),
'scope' => $pick('kreis', 'scope'),
];
$sort = $filters && isset(self::SORTS[$text('sort')]) ? $text('sort') : ($fixed['sort'] ?? null);
$view = $filters && in_array($text('ansicht'), ['kacheln', 'liste'], true) ? $text('ansicht') : (string) ($fixed['view'] ?? 'kacheln');
$cards = $this->arrange($base, $chosen + ['sort' => $sort, 'limit' => $fixed['limit'] ?? null]);
$perPage = max(1, (int) config('shop.per_page', 12));
$pages = max(1, (int) ceil(count($cards) / $perPage));
$page = $filters ? min($pages, max(1, (int) $text('seite'))) : 1;
$shown = $filters ? array_slice($cards, ($page - 1) * $perPage, $perPage) : $cards;
return [
'cards' => $shown,
'total' => count($cards),
'page' => $page,
'pages' => $filters ? $pages : 1,
'facets' => $facets,
'chosen' => $chosen,
'sort' => $sort,
'view' => $view,
'term' => $term,
'filters' => $filters,
];
}
/**
* @param array{from_cents: int, count: int} $summary
* @param list<string> $pillars
@@ -167,6 +294,8 @@ private function card(string $key, string $kind, string $url, string $title, str
'pillar_ids' => [],
'kind_id' => null,
'since' => 0,
'holders' => [],
'scopes' => [],
];
}
@@ -179,11 +308,11 @@ private function matches(string $term, string $haystack): bool
* Nur veröffentlichte Säulen sind öffentlich (Säulenverwaltung).
*
* @param Collection<int, Pillar> $pillars
* @return list<string>
* @return array<int, string> Kennung => Name
*/
private function pillarNames(Collection $pillars): array
private function publishedPillars(Collection $pillars): array
{
return $pillars->filter(fn (Pillar $pillar): bool => $pillar->published_at !== null)->map(fn (Pillar $pillar): string => (string) $pillar->name)->values()->all();
return $pillars->filter(fn (Pillar $pillar): bool => $pillar->published_at !== null)->mapWithKeys(fn (Pillar $pillar): array => [(int) $pillar->id => (string) $pillar->name])->all();
}
/** Ein Symbol zeigt nur, was die Symbolbibliothek kennt (die Auswahl wird an der Materialart geprüft, hier noch einmal). */