Permalink
Browse files

Merge pull request #16 from jonseg/EventRepositoryOptimize

Optimize EventRepository queries
  • Loading branch information...
2 parents 87398de + e2d40b3 commit a72e8949559e2dd086d2954fa2f77be4f650305d @aramirez-es aramirez-es committed Feb 16, 2012
Showing with 7 additions and 3 deletions.
  1. +7 −3 src/SFBCN/WebsiteBundle/Entity/EventRepository.php
@@ -12,16 +12,18 @@
*/
class EventRepository extends EntityRepository
{
+
/**
* Gets past events
* @param integer $max
* @return array
*/
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();
}
}

0 comments on commit a72e894

Please sign in to comment.