public function getAllBetween(\DateTime $start, \DateTime $end, \Club\UserBundle\Entity\User $user = null, \Club\UserBundle\Entity\Location $location = null, \Club\BookingBundle\Entity\Field $field = null)
 {
     $qb = $this->_em->createQueryBuilder()->select('s')->from('ClubTeamBundle:Schedule', 's')->where('(s.first_date <= :start and s.end_date >= :end)')->orWhere('(s.first_date <= :start and s.end_date <= :end and s.end_date >= :start)')->orWhere('(s.first_date >= :start and s.end_date >= :end and s.first_date < :end)')->orWhere('(s.first_date >= :start and s.end_date <= :end and s.end_date >= :start)')->orderBy('s.first_date')->setParameter('start', $start->format('Y-m-d H:i:s'))->setParameter('end', $end->format('Y-m-d H:i:s'));
     if (isset($user)) {
         $qb->leftJoin('s.users', 'u')->andWhere('u.user = :user')->setParameter('user', $user->getId());
     }
     if (isset($location)) {
         $qb->leftJoin('s.location', 'l')->andWhere('l.id = :location')->setParameter('location', $location->getId());
     }
     if (isset($field)) {
         $qb->leftJoin('s.fields', 'f')->andWhere('f.id = :field')->setParameter('field', $field->getId());
     }
     return $qb->getQuery()->getResult();
 }
 public function getAll(\DateTime $start, \DateTime $end, \Club\BookingBundle\Entity\Field $field)
 {
     return $this->_em->createQueryBuilder()->select('i')->from('ClubBookingBundle:Interval', 'i')->where('((i.start_time <= :start and i.stop_time > :start) or (i.start_time >= :start and i.start_time < :stop))')->andWhere('i.field = :field')->andWhere('i.day = :day')->setParameter('start', $start->format('H:i:s'))->setParameter('stop', $end->format('H:i:s'))->setParameter('field', $field->getId())->setParameter('day', $start->format('N'))->getQuery()->getResult();
 }
 public function getAllBetween(\DateTime $start, \DateTime $end, \Club\BookingBundle\Entity\Field $field)
 {
     return $this->_em->createQueryBuilder()->select('b')->from('ClubBookingBundle:Booking', 'b')->where('(b.status >= :status) AND ((b.first_date <= :start AND b.end_date >= :end) OR (b.first_date <= :start AND b.end_date <= :end AND b.end_date >= :start) OR (b.first_date >= :start AND b.end_date >= :end AND b.first_date < :end) OR b.first_date >= :start AND b.end_date <= :end AND b.end_date >= :start)')->orderBy('b.first_date')->setParameter('status', \Club\BookingBundle\Entity\Booking::CONFIRMED)->setParameter('start', $start->format('Y-m-d H:i:s'))->setParameter('end', $end->format('Y-m-d H:i:s'))->leftJoin('b.field', 'f')->andWhere('f.id = :field')->setParameter('field', $field->getId())->getQuery()->getResult();
 }
 public function getICSByField(\Club\BookingBundle\Entity\Field $field, \DateTime $date)
 {
     $plans = $this->getQuery($date)->andWhere('f.id = :field')->setParameter('field', $field->getId())->getQuery()->getResult();
     return $this->getIcsFromPlans($plans);
 }
 protected function post(\Club\BookingBundle\Entity\Field $field, $fl)
 {
     $em = $this->getDoctrine()->getManager();
     $field->setFieldLayout($fl);
     $em->persist($field);
     $intervals = $em->getRepository('ClubBookingBundle:Interval')->findBy(array('valid_to' => null, 'field' => $field->getId()));
     foreach ($intervals as $interval) {
         $interval->setValidTo(new \DateTime());
         $em->persist($interval);
     }
 }