Biete in der Shopliste Auswahl, Reihenfolge, Listenansicht und Seiten
CI Feature / test (push) Successful in 6m4s
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:
1 parent
95a888d1ca
commit
f0ffb47210
15 files changed
+651
-73
No files matched your search
@@ -79,6 +79,7 @@ public function variants(): array
|
||||
{
|
||||
return [
|
||||
'kacheln' => 'Kacheln mit Bild',
|
||||
'liste' => 'Liste mit kleinem Bild',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -88,6 +89,7 @@ public function settings(): array
|
||||
'sort' => ['name' => 'Alphabetisch', 'neu' => 'Neueste zuerst', 'preis' => 'Preis aufsteigend'],
|
||||
'limit' => ['alle' => 'Alle Produkte', 'n3' => '3 Produkte', 'n6' => '6 Produkte', 'n9' => '9 Produkte', 'n12' => '12 Produkte', 'n24' => '24 Produkte'],
|
||||
'search' => ['aus' => 'Ohne Suchfeld', 'an' => 'Mit Suchfeld'],
|
||||
'filter' => ['aus' => 'Ohne Auswahl', 'an' => 'Mit Suche, Auswahl, Ansicht und Seiten'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -96,13 +98,14 @@ public function settingLabels(): array
|
||||
return [
|
||||
'sort' => ['Reihenfolge', 'Ohne Wahl gilt die Reihenfolge der Shopseite: Altbestand, Artikel, Pakete.'],
|
||||
'limit' => ['Anzahl', 'Wie viele Produkte höchstens erscheinen. Ohne Wahl erscheinen alle.'],
|
||||
'search' => ['Suchfeld', 'Ein Suchfeld über den Kacheln. Es wirkt auf der Shopseite; auf anderen Seiten führt die Suche in den Shop.'],
|
||||
'search' => ['Suchfeld', 'Ein einfaches Suchfeld über den Kacheln. Es sendet an die Seite, auf der das Widget steht.'],
|
||||
'filter' => ['Auswahl für Besucher', 'Suche, Auswahl nach Thema, Materialart, Eignung und Nutzerkreis, Reihenfolge, Umschalter Kacheln und Liste und Seiten. Sinnvoll auf der Shopseite mit vielen Produkten. Ersetzt das einfache Suchfeld und die Einstellung „Anzahl“.'],
|
||||
];
|
||||
}
|
||||
|
||||
public function settingGroups(): array
|
||||
{
|
||||
return ['Auswahl' => ['sort', 'limit', 'search']];
|
||||
return ['Auswahl' => ['sort', 'limit', 'search', 'filter']];
|
||||
}
|
||||
|
||||
public function dataRules(): array
|
||||
@@ -165,21 +168,28 @@ public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||
public function resolve(array $widget, RenderContext $context): array
|
||||
{
|
||||
if (! Shop::visible()) {
|
||||
return ['cards' => [], 'term' => '', 'shopVisible' => false];
|
||||
return ['listing' => null, 'cards' => [], 'term' => '', 'shopVisible' => false];
|
||||
}
|
||||
|
||||
$settings = is_array($widget['settings'] ?? null) ? $widget['settings'] : [];
|
||||
$filters = ($settings['filter'] ?? 'aus') === 'an';
|
||||
$search = ($settings['search'] ?? 'aus') === 'an';
|
||||
$term = $search && ! $context->preview ? trim((string) request()->query('suche', '')) : '';
|
||||
$limit = preg_match('/^n(\d+)$/', (string) ($settings['limit'] ?? ''), $match) === 1 ? (int) $match[1] : null;
|
||||
$limit = preg_match('/^n(\\d+)$/', (string) ($settings['limit'] ?? ''), $match) === 1 ? (int) $match[1] : null;
|
||||
$query = $context->preview ? [] : request()->query();
|
||||
$term = ($search || $filters) && isset($query['suche']) && is_string($query['suche']) ? mb_substr(trim($query['suche']), 0, 100) : '';
|
||||
$fixed = [
|
||||
'pillar' => $widget['data']['pillar'] ?? null,
|
||||
'kind' => $widget['data']['kind'] ?? null,
|
||||
'sort' => $settings['sort'] ?? null,
|
||||
'limit' => $filters ? null : $limit,
|
||||
'view' => ($widget['variant'] ?? 'kacheln') === 'liste' ? 'liste' : 'kacheln',
|
||||
'filters' => $filters,
|
||||
];
|
||||
$listing = app(ShopCatalog::class)->listing($filters ? $query : ['suche' => $term], $fixed);
|
||||
|
||||
return [
|
||||
'cards' => app(ShopCatalog::class)->cards($term, [
|
||||
'pillar' => $widget['data']['pillar'] ?? null,
|
||||
'kind' => $widget['data']['kind'] ?? null,
|
||||
'sort' => $settings['sort'] ?? null,
|
||||
'limit' => $limit,
|
||||
]),
|
||||
'listing' => $listing,
|
||||
'cards' => $listing['cards'],
|
||||
'term' => $term,
|
||||
'shopVisible' => true,
|
||||
];
|
||||
|
||||
@@ -210,7 +210,7 @@ private function optionsFor(string $key): array
|
||||
/**
|
||||
* Günstigster Preis und Zahl der Optionen je Seite einer Art ('a', 'b' oder 'c'): Kennung => Zusammenfassung.
|
||||
*
|
||||
* @return array<int, array{from_cents: int, count: int}>
|
||||
* @return array<int, array{from_cents: int, count: int, holders: list<string>, scopes: list<string>}>
|
||||
*/
|
||||
private function summariesOf(string $kind): array
|
||||
{
|
||||
@@ -224,6 +224,8 @@ private function summariesOf(string $kind): array
|
||||
$summary[(int) substr($key, 2)] = [
|
||||
'from_cents' => min(array_map(fn (array $row): int => (int) $row['version']->price_cents, $rows)),
|
||||
'count' => count($rows),
|
||||
'holders' => array_values(array_unique(array_map(fn (array $row): string => (string) $row['version']->holder_kind, $rows))),
|
||||
'scopes' => array_values(array_unique(array_filter(array_map(fn (array $row): ?string => $row['version']->licence_scope, $rows)))),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -233,7 +235,7 @@ private function summariesOf(string $kind): array
|
||||
/**
|
||||
* Artikel mit kaufbarer Option: Artikelkennung => günstigster Preis und Zahl der Optionen.
|
||||
*
|
||||
* @return array<int, array{from_cents: int, count: int}>
|
||||
* @return array<int, array{from_cents: int, count: int, holders: list<string>, scopes: list<string>}>
|
||||
*/
|
||||
public function articleSummaries(): array
|
||||
{
|
||||
@@ -243,7 +245,7 @@ public function articleSummaries(): array
|
||||
/**
|
||||
* Pakete mit kaufbarer Option: Paketkennung => günstigster Preis und Zahl der Optionen.
|
||||
*
|
||||
* @return array<int, array{from_cents: int, count: int}>
|
||||
* @return array<int, array{from_cents: int, count: int, holders: list<string>, scopes: list<string>}>
|
||||
*/
|
||||
public function bundleSummaries(): array
|
||||
{
|
||||
@@ -253,7 +255,7 @@ public function bundleSummaries(): array
|
||||
/**
|
||||
* Altbestand: Programmseiten mit kaufbaren Optionen (Angebote mit mehreren Positionen).
|
||||
*
|
||||
* @return array<int, array{from_cents: int, count: int}>
|
||||
* @return array<int, array{from_cents: int, count: int, holders: list<string>, scopes: list<string>}>
|
||||
*/
|
||||
public function summaries(): array
|
||||
{
|
||||
|
||||
@@ -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). */
|
||||
|
||||
@@ -35,8 +35,6 @@ public function index(Request $request, ShopCatalog $catalog, PageController $pa
|
||||
return $pages->showPage($page);
|
||||
}
|
||||
|
||||
$term = trim((string) $request->query('suche', ''));
|
||||
|
||||
return view('shop.index', ['cards' => $catalog->cards($term), 'term' => $term]);
|
||||
return view('shop.index', ['listing' => $catalog->listing($request->query())]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user