/**
  * @param Event $event
  *
  * @return Unregistration[]
  */
 public function getUnprocessedUnregistrations(Event $event)
 {
     $rsm = new ResultSetMappingBuilder($this->_em);
     $rsm->addRootEntityFromClassMetadata('BCRM\\BackendBundle\\Entity\\Event\\Unregistration', 'u');
     $eventId = $event->getId();
     $unregistrations = "SELECT MAX(id) FROM unregistration WHERE confirmed = 1 AND event_id = {$eventId} AND processed = 0 GROUP BY event_id, email ORDER BY created ASC, id ASC";
     $sql = "SELECT * FROM unregistration WHERE id IN ({$unregistrations})";
     $query = $this->_em->createNativeQuery($sql, $rsm);
     return $query->getResult();
 }
 /**
  * {@inheritDocs}
  */
 public function getNextVipRegistrations(Event $event, $day)
 {
     $rsm = new ResultSetMappingBuilder($this->_em);
     $rsm->addRootEntityFromClassMetadata('BCRM\\BackendBundle\\Entity\\Event\\Registration', 'r');
     $types = join(',', array(Registration::TYPE_SPONSOR, Registration::TYPE_VIP));
     $eventId = $event->getId();
     $dayName = $day == Ticket::DAY_SATURDAY ? 'saturday' : 'sunday';
     $registrations = "SELECT MAX(id) FROM registration WHERE confirmed = 1 AND type IN ({$types}) AND event_id = {$eventId} GROUP BY event_id, email ORDER BY created ASC, id ASC";
     $sql = "SELECT * FROM registration WHERE id IN ({$registrations}) AND email NOT IN (SELECT email FROM ticket WHERE day = {$day} AND event_id = {$eventId}) AND {$dayName} = 1";
     $query = $this->_em->createNativeQuery($sql, $rsm);
     return $query->getResult();
 }
 /**
  * @param Event $event
  * @param       $day
  *
  * @return integer
  */
 public function getCapacity(Event $event, $day)
 {
     return $this->createQueryBuilder('e')->select('e.capacity - COUNT(t.id) as capacity')->leftJoin('e.tickets', 't')->andWhere('t.day = :day')->setParameter('day', $day)->andWhere('t.type = :type')->setParameter('type', Registration::TYPE_NORMAL)->andWhere('e.id = :event')->setParameter('event', $event->getId())->getQuery()->getSingleScalarResult();
 }