mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-17 15:59:56 +03:00
Add date range filter to short url repository
This commit is contained in:
parent
1183d65184
commit
5928f28699
1 changed files with 15 additions and 1 deletions
|
@ -7,6 +7,7 @@ namespace Shlinkio\Shlink\Core\Repository;
|
|||
use Cake\Chronos\Chronos;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
|
||||
use function array_column;
|
||||
|
@ -27,7 +28,8 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI
|
|||
?int $offset = null,
|
||||
?string $searchTerm = null,
|
||||
array $tags = [],
|
||||
$orderBy = null
|
||||
$orderBy = null,
|
||||
?DateRange $dateRange = null
|
||||
): array {
|
||||
$qb = $this->createListQueryBuilder($searchTerm, $tags);
|
||||
$qb->select('DISTINCT s');
|
||||
|
@ -40,6 +42,18 @@ class ShortUrlRepository extends EntityRepository implements ShortUrlRepositoryI
|
|||
$qb->setFirstResult($offset);
|
||||
}
|
||||
|
||||
// Date filters
|
||||
if ($dateRange !== null) {
|
||||
if ($dateRange->getStartDate() !== null) {
|
||||
$qb->andWhere($qb->expr()->gte('s.dateCreated', ':startDate'));
|
||||
$qb->setParameter('startDate', $dateRange->getStartDate());
|
||||
}
|
||||
if ($dateRange->getEndDate() !== null) {
|
||||
$qb->andWhere($qb->expr()->lte('s.dateCreated', ':endDate'));
|
||||
$qb->setParameter('endDate', $dateRange->getEndDate());
|
||||
}
|
||||
}
|
||||
|
||||
// In case the ordering has been specified, the query could be more complex. Process it
|
||||
if ($orderBy !== null) {
|
||||
return $this->processOrderByForList($qb, $orderBy);
|
||||
|
|
Loading…
Add table
Reference in a new issue