improved maps and browse events, removed search

This commit is contained in:
Hendrik Behme committed 2026-08-17 18:00:44 +02:00
1 parent 55e28fd0af
commit 75d5d0bb0f
11 files changed
+387 -392

No files matched your search

+44 -41
View File
@@ -33,26 +33,6 @@ class EventRepository extends ServiceEntityRepository
->getResult();
}
/** @return Event[] */
public function findPage(int $limit, int $offset, ?string $category = null): array
{
$qb = $this->orderByStartDate($this->notDeleted())
->setMaxResults($limit)
->setFirstResult($offset);
$this->filterByCategory($qb, $category);
return $qb->getQuery()->getResult();
}
public function countPage(?string $category = null): int
{
$qb = $this->notDeleted()->select('COUNT(DISTINCT e.id)');
$this->filterByCategory($qb, $category);
return (int) $qb->getQuery()->getSingleScalarResult();
}
/** @return Event[] */
public function findWithCoordinates(int $limit = 500): array
{
@@ -127,40 +107,63 @@ class EventRepository extends ServiceEntityRepository
* a sortable DB column, so paging has to slice that ordered id list
* *after* intersecting it with the text/category matches — pushing
* LIMIT/OFFSET into SQL here would paginate an arbitrary DB-ordered
* subset instead of the correct "25th-50th nearest" slice.
* subset instead of the correct "25th-50th nearest" slice. That trick
* only applies to $sort === 'nearest' though; the other sorts are real
* DB columns, so they go through a normal ORDER BY + LIMIT/OFFSET
* query instead, restricted to $locationIds the same way but without
* needing to preserve that array's own order.
*
* @param int[]|null $locationIds
*
* @return Event[]
*/
public function search(?string $q, ?string $category, string $when, int $limit, int $offset, ?array $locationIds = null): array
public function search(?string $q, ?string $category, string $when, int $limit, int $offset, ?array $locationIds = null, string $sort = 'soonest'): array
{
if (null === $locationIds) {
return $this->orderByStartDate($this->baseSearchQb($q, $category, $when))
->setMaxResults($limit)
->setFirstResult($offset)
->getQuery()
->getResult();
// "Nearest" only means anything once a location narrowed the pool.
if ('nearest' === $sort && null === $locationIds) {
$sort = 'soonest';
}
if (!$locationIds) {
if ('nearest' === $sort) {
if (!$locationIds) {
return [];
}
$matchingIds = array_map('intval', array_column(
$this->baseSearchQb($q, $category, $when)
->select('e.id')
->andWhere('e.id IN (:locationIds)')
->setParameter('locationIds', $locationIds)
->getQuery()
->getScalarResult(),
'id'
));
$matchingIdSet = array_flip($matchingIds);
$orderedIds = array_values(array_filter($locationIds, static fn ($id) => isset($matchingIdSet[$id])));
return $this->hydrateInOrder(array_slice($orderedIds, $offset, $limit));
}
if (null !== $locationIds && !$locationIds) {
return [];
}
$matchingIds = array_map('intval', array_column(
$this->baseSearchQb($q, $category, $when)
->select('e.id')
->andWhere('e.id IN (:locationIds)')
->setParameter('locationIds', $locationIds)
->getQuery()
->getScalarResult(),
'id'
));
$qb = $this->baseSearchQb($q, $category, $when);
if (null !== $locationIds) {
$qb->andWhere('e.id IN (:locationIds)')->setParameter('locationIds', $locationIds);
}
$matchingIdSet = array_flip($matchingIds);
$orderedIds = array_values(array_filter($locationIds, static fn ($id) => isset($matchingIdSet[$id])));
match ($sort) {
'az' => $qb->orderBy('e.title', 'ASC'),
'za' => $qb->orderBy('e.title', 'DESC'),
default => $this->orderByStartDate($qb),
};
return $this->hydrateInOrder(array_slice($orderedIds, $offset, $limit));
return $qb->setMaxResults($limit)
->setFirstResult($offset)
->getQuery()
->getResult();
}
/**