From d12c8d6aebe3fe814a9d2bb186b653b4fe5b387a Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Tue, 8 Jul 2014 12:59:34 +0200 Subject: [PATCH] Show only events which are in the future. --- .../CalciferBundle/Controller/EventController.php | 10 +++++++++- .../Controller/LocationController.php | 13 +++++++++++-- .../CalciferBundle/Controller/TagController.php | 5 ++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php index a9a88f1..af7e576 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php @@ -3,6 +3,7 @@ namespace Hackspace\Bundle\CalciferBundle\Controller; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\QueryBuilder; use Hackspace\Bundle\CalciferBundle\Entity\Location; use Hackspace\Bundle\CalciferBundle\Entity\Tag; use Symfony\Component\HttpFoundation\Request; @@ -32,7 +33,14 @@ class EventController extends Controller { $em = $this->getDoctrine()->getManager(); - $entities = $em->getRepository('CalciferBundle:Event')->findBy([],['startdate' => 'ASC']); + /** @var QueryBuilder $qb */ + $qb = $em->createQueryBuilder(); + $qb ->select(array('e')) + ->from('CalciferBundle:Event', 'e') + ->where('e.startdate >= :startdate') + ->orderBy('e.startdate') + ->setParameter('startdate',new \DateTime()); + $entities = $qb->getQuery()->execute(); return array( 'entities' => $entities, diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php index 1ae9a95..0b13bbb 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php @@ -2,7 +2,7 @@ namespace Hackspace\Bundle\CalciferBundle\Controller; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\QueryBuilder; use Hackspace\Bundle\CalciferBundle\Entity\Location; use Hackspace\Bundle\CalciferBundle\Entity\Tag; use Symfony\Component\HttpFoundation\Request; @@ -50,7 +50,16 @@ class LocationController extends Controller $em = $this->getDoctrine()->getManager(); - $entities = $em->getRepository('CalciferBundle:Event')->findBy(['locations_id' => $location->getId()],['startdate' => 'ASC']); + /** @var QueryBuilder $qb */ + $qb = $em->createQueryBuilder(); + $qb ->select(array('e')) + ->from('CalciferBundle:Event', 'e') + ->where('e.startdate >= :startdate') + ->andWhere('e.locations_id = :location') + ->orderBy('e.startdate') + ->setParameter('startdate',new \DateTime()) + ->setParameter('location',$location->getId()); + $entities = $qb->getQuery()->execute(); return array( 'entities' => $entities, diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/TagController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/TagController.php index 3c85f91..c0013d7 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/TagController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/TagController.php @@ -22,6 +22,7 @@ use Jsvrcek\ICS\Model\Relationship\Organizer; use Jsvrcek\ICS\Utility\Formatter; use Jsvrcek\ICS\CalendarStream; use Jsvrcek\ICS\CalendarExport; +use Symfony\Component\Validator\Constraints\DateTime; /** * Tag controller. @@ -53,7 +54,9 @@ class TagController extends Controller $qb ->select(array('e')) ->from('CalciferBundle:Event', 'e') ->join('e.tags', 't', 'WITH', $qb->expr()->in('t.id', $tag->getId())) - ->orderBy('e.startdate'); + ->where('e.startdate >= :startdate') + ->orderBy('e.startdate') + ->setParameter('startdate',new \DateTime()); $entities = $qb->getQuery()->execute(); return array(