Beispiel #1
0
 /**
  * @test
  */
 public function providedDatesAreSet()
 {
     $startDate = new \DateTime();
     $endDate = new \DateTime();
     $range = new DateRange($startDate, $endDate);
     $this->assertSame($startDate, $range->getStartDate());
     $this->assertSame($endDate, $range->getEndDate());
     $this->assertFalse($range->isEmpty());
 }
Beispiel #2
0
 /**
  * @param ShortUrl|int $shortUrl
  * @param DateRange|null $dateRange
  * @return Visit[]
  */
 public function findVisitsByShortUrl($shortUrl, DateRange $dateRange = null)
 {
     $shortUrl = $shortUrl instanceof ShortUrl ? $shortUrl : $this->getEntityManager()->find(ShortUrl::class, $shortUrl);
     $qb = $this->createQueryBuilder('v');
     $qb->where($qb->expr()->eq('v.shortUrl', ':shortUrl'))->setParameter('shortUrl', $shortUrl)->orderBy('v.date', 'DESC');
     // Apply date range filtering
     if (!empty($dateRange->getStartDate())) {
         $qb->andWhere($qb->expr()->gte('v.date', ':startDate'))->setParameter('startDate', $dateRange->getStartDate());
     }
     if (!empty($dateRange->getEndDate())) {
         $qb->andWhere($qb->expr()->lte('v.date', ':endDate'))->setParameter('endDate', $dateRange->getEndDate());
     }
     return $qb->getQuery()->getResult();
 }