Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #16 from jonseg/EventRepositoryOptimize

Optimize EventRepository queries
  • Loading branch information...
commit a72e8949559e2dd086d2954fa2f77be4f650305d 2 parents 87398de + e2d40b3
@aramirez-es aramirez-es authored
Showing with 7 additions and 3 deletions.
  1. +7 −3 src/SFBCN/WebsiteBundle/Entity/EventRepository.php
View
10 src/SFBCN/WebsiteBundle/Entity/EventRepository.php
@@ -12,6 +12,7 @@
*/
class EventRepository extends EntityRepository
{
+
/**
* Gets past events
* @param integer $max
@@ -19,9 +20,10 @@ class EventRepository extends EntityRepository
*/
public function getPastEvents($max = 15)
{
+ $today = new \DateTime();
return $this->_em->createQuery('SELECT e from SFBCNWebsiteBundle:Event e WHERE e.datetime < :datetime ORDER BY e.datetime DESC')
->setMaxResults($max)
- ->setParameter('datetime', new \DateTime())
+ ->setParameter('datetime', $today->format('Y-m-d 00:00:00'))
->getResult();
}
@@ -31,9 +33,10 @@ public function getPastEvents($max = 15)
*/
public function getNextEvent()
{
+ $today = new \DateTime();
return $this->_em->createQuery('SELECT e from SFBCNWebsiteBundle:Event e WHERE e.datetime > :datetime ORDER BY e.datetime ASC')
->setMaxResults(1)
- ->setParameter('datetime', new \DateTime())
+ ->setParameter('datetime',$today->format('Y-m-d 00:00:00'))
->getOneOrNullResult();
}
@@ -44,10 +47,11 @@ public function getNextEvent()
*/
public function getFutureEvents($max = 15)
{
+ $today = new \DateTime();
return $this->_em->createQuery('SELECT e from SFBCNWebsiteBundle:Event e WHERE e.datetime > :datetime ORDER BY e.datetime ASC')
->setFirstResult(1)
->setMaxResults($max)
- ->setParameter('datetime', new \DateTime())
+ ->setParameter('datetime', $today->format('Y-m-d 00:00:00'))
->getResult();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.