private function deleteBetween(\DateTime $start, \Club\TeamBundle\Entity\Schedule $schedule, \DateTime $end = null)
 {
     $parent = $schedule->getSchedule() ? $schedule->getSchedule() : $schedule;
     $qb = $this->em->createQueryBuilder()->delete('ClubTeamBundle:Schedule', 's')->where('s.schedule = :id')->andWhere('s.first_date > :first')->setParameter('first', $start->format('Y-m-d H:i:s'))->setParameter('id', $parent->getId());
     if (isset($end)) {
         $qb->andWhere('s.first_date < :end')->setParameter('end', $end->format('Y-m-d H:i:s'));
     }
     $qb->getQuery()->getResult();
     return true;
 }
 protected function deleteAll(\Club\TeamBundle\Entity\Schedule $schedule)
 {
     $em = $this->getDoctrine()->getManager();
     $parent = $schedule->getSchedule() ? $schedule->getSchedule() : $schedule;
     $repetition = $parent->getRepetition();
     $repetition->setSchedule(null);
     $em->persist($repetition);
     $em->flush();
     $em->createQueryBuilder()->delete('ClubTeamBundle:Schedule', 's')->where('(s.id = :id OR s.schedule = :id)')->setParameter('id', $parent->getId())->getQuery()->execute();
     $em->remove($repetition);
     $em->flush();
     return true;
 }
 public function getPrevSchedule(\Club\TeamBundle\Entity\Schedule $schedule)
 {
     $parent = $schedule->getSchedule() ? $schedule->getSchedule() : $schedule;
     return $this->_em->createQueryBuilder()->select('s')->from('ClubTeamBundle:Schedule', 's')->where('s.first_date <= :date')->andWhere('(s.id = :id OR s.schedule = :id)')->setMaxResults(1)->orderBy('s.first_date', 'DESC')->setParameter('date', date('Y-m-d H:i:s'))->setParameter('id', $parent->getId())->getQuery()->getSingleResult();
 }