Created methods to get orphan visits lists

This commit is contained in:
Alejandro Celaya
2021-02-09 21:22:36 +01:00
parent 1fbcb44136
commit 85dd023c0e
7 changed files with 173 additions and 30 deletions

View File

@@ -168,6 +168,29 @@ class VisitRepository extends EntitySpecificationRepository implements VisitRepo
return $qb;
}
public function findOrphanVisits(?DateRange $dateRange = null, ?int $limit = null, ?int $offset = null): array
{
// Parameters in this query need to be inlined, not bound, as we need to use it as sub-query later
// Since they are not strictly provided by the caller, it's reasonably safe
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->from(Visit::class, 'v')
->where($qb->expr()->isNull('v.shortUrl'));
$this->applyDatesInline($qb, $dateRange);
return $this->resolveVisitsWithNativeQuery($qb, $limit, $offset);
}
public function countOrphanVisits(?DateRange $dateRange = null): int
{
return (int) $this->matchSingleScalarResult(new CountOfOrphanVisits($dateRange));
}
public function countVisits(?ApiKey $apiKey = null): int
{
return (int) $this->matchSingleScalarResult(new CountOfShortUrlVisits($apiKey));
}
private function applyDatesInline(QueryBuilder $qb, ?DateRange $dateRange): void
{
if ($dateRange !== null && $dateRange->getStartDate() !== null) {
@@ -208,14 +231,4 @@ class VisitRepository extends EntitySpecificationRepository implements VisitRepo
return $query->getResult();
}
public function countVisits(?ApiKey $apiKey = null): int
{
return (int) $this->matchSingleScalarResult(new CountOfShortUrlVisits($apiKey));
}
public function countOrphanVisits(): int
{
return (int) $this->matchSingleScalarResult(new CountOfOrphanVisits());
}
}

View File

@@ -62,7 +62,12 @@ interface VisitRepositoryInterface extends ObjectRepository, EntitySpecification
public function countVisitsByTag(string $tag, ?DateRange $dateRange = null, ?Specification $spec = null): int;
public function countVisits(?ApiKey $apiKey = null): int;
/**
* @return Visit[]
*/
public function findOrphanVisits(?DateRange $dateRange = null, ?int $limit = null, ?int $offset = null): array;
public function countOrphanVisits(): int;
public function countOrphanVisits(?DateRange $dateRange = null): int;
public function countVisits(?ApiKey $apiKey = null): int;
}