added filtering and cronjob soft delete for old events
This commit is contained in:
1 parent
75d5d0bb0f
commit
1701eb5070
4 files changed
+76
-5
No files matched your search
@@ -27,7 +27,7 @@ class EventRepository extends ServiceEntityRepository
|
||||
/** @return Event[] */
|
||||
public function findRecent(int $limit): array
|
||||
{
|
||||
return $this->orderByStartDate($this->notDeleted())
|
||||
return $this->orderByStartDate($this->notEnded($this->notDeleted()))
|
||||
->setMaxResults($limit)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
@@ -36,7 +36,7 @@ class EventRepository extends ServiceEntityRepository
|
||||
/** @return Event[] */
|
||||
public function findWithCoordinates(int $limit = 500): array
|
||||
{
|
||||
return $this->notDeleted()
|
||||
return $this->notEnded($this->notDeleted())
|
||||
->andWhere('e.latitude IS NOT NULL AND e.longitude IS NOT NULL')
|
||||
->andWhere('e.latitude <> 0 OR e.longitude <> 0')
|
||||
->setMaxResults($limit)
|
||||
@@ -56,6 +56,12 @@ class EventRepository extends ServiceEntityRepository
|
||||
*/
|
||||
public function distancesWithinRadius(float $lat, float $lon, float $radiusKm, int $limit = 500): array
|
||||
{
|
||||
// end_date comparison mirrors notEnded()/filterByWhen(): day-level
|
||||
// lexicographic comparison against the raw ISO-ish string column,
|
||||
// in Europe/Berlin — this is raw SQL (DBAL, not the QueryBuilder),
|
||||
// so it can't just call that helper directly.
|
||||
$today = (new \DateTimeImmutable('today', new \DateTimeZone('Europe/Berlin')))->format('Y-m-d');
|
||||
|
||||
$sql = 'SELECT id, distance_km FROM (
|
||||
SELECT e.id,
|
||||
(6371 * acos(least(1, greatest(-1,
|
||||
@@ -66,6 +72,7 @@ class EventRepository extends ServiceEntityRepository
|
||||
WHERE e.deleted_at IS NULL
|
||||
AND e.latitude IS NOT NULL AND e.longitude IS NOT NULL
|
||||
AND (e.latitude <> 0 OR e.longitude <> 0)
|
||||
AND (e.end_date >= :today OR e.end_date = \'\')
|
||||
) sub
|
||||
WHERE distance_km <= :radius
|
||||
ORDER BY distance_km ASC
|
||||
@@ -73,8 +80,8 @@ class EventRepository extends ServiceEntityRepository
|
||||
|
||||
$rows = $this->getEntityManager()->getConnection()->executeQuery(
|
||||
$sql,
|
||||
['lat' => $lat, 'lon' => $lon, 'radius' => $radiusKm, 'limit' => $limit],
|
||||
['lat' => ParameterType::STRING, 'lon' => ParameterType::STRING, 'radius' => ParameterType::STRING, 'limit' => ParameterType::INTEGER]
|
||||
['lat' => $lat, 'lon' => $lon, 'radius' => $radiusKm, 'limit' => $limit, 'today' => $today],
|
||||
['lat' => ParameterType::STRING, 'lon' => ParameterType::STRING, 'radius' => ParameterType::STRING, 'limit' => ParameterType::INTEGER, 'today' => ParameterType::STRING]
|
||||
)->fetchAllAssociative();
|
||||
|
||||
$distances = [];
|
||||
@@ -188,7 +195,7 @@ class EventRepository extends ServiceEntityRepository
|
||||
|
||||
private function baseSearchQb(?string $q, ?string $category, string $when): QueryBuilder
|
||||
{
|
||||
$qb = $this->notDeleted();
|
||||
$qb = $this->notEnded($this->notDeleted());
|
||||
|
||||
if ($q) {
|
||||
$qb->andWhere('LOWER(e.title) LIKE :q OR LOWER(e.city) LIKE :q OR LOWER(e.street) LIKE :q')
|
||||
@@ -280,6 +287,26 @@ class EventRepository extends ServiceEntityRepository
|
||||
->andWhere('e.deletedAt IS NULL');
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides events that have already ended — compared by calendar day
|
||||
* (Europe/Berlin), the same precision filterByWhen() uses for
|
||||
* "today"/"week", not exact time (end_date is a raw ISO-ish string,
|
||||
* not a real date/time column). Blank end_date is treated as "still
|
||||
* current" rather than excluded, matching orderByStartDate()'s
|
||||
* defensive handling of blank date strings.
|
||||
*
|
||||
* Deliberately NOT applied to findOneNotDeleted() — a bookmarked or
|
||||
* shared link to a single past event should still resolve, only the
|
||||
* listing/discovery queries should hide it.
|
||||
*/
|
||||
private function notEnded(QueryBuilder $qb): QueryBuilder
|
||||
{
|
||||
$today = new \DateTimeImmutable('today', new \DateTimeZone('Europe/Berlin'));
|
||||
|
||||
return $qb->andWhere("e.endDate >= :notEndedBoundary OR e.endDate = ''")
|
||||
->setParameter('notEndedBoundary', $today->format('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* startDate is a raw ISO-ish string column (may be empty when the
|
||||
* source had no time interval); push undated events to the end
|
||||
|
||||
Reference in new issue
Block a user