private function addSchedule(\DateTime $start, \DateInterval $diff, \Club\TeamBundle\Entity\Schedule $schedule) { // only count when we are in the future to get the following if ($start->getTimestamp() > time()) { $this->future_occur++; } $this->occur++; $parent = $schedule->getSchedule() ? $schedule->getSchedule() : $schedule; $res = $this->em->createQueryBuilder()->select('s')->from('ClubTeamBundle:Schedule', 's')->where('s.first_date = :date')->andWhere('(s.schedule = :id OR s.id = :id)')->setParameter('date', $start->format('Y-m-d H:i:s'))->setParameter('id', $parent->getId())->getQuery()->getResult(); if (count($res)) { return; } // find new times $new_format = $start->format('Y-m-d') . ' ' . $schedule->getFirstDate()->format('H:i:s'); if ($new_format == $schedule->getFirstDate()->format('Y-m-d H:i:s')) { return; } $new_first = new \DateTime($new_format); $new_end = new \DateTime($new_format); $new_end->add($diff); // make new schedule $new = new \Club\TeamBundle\Entity\Schedule(); $new->setDescription($schedule->getDescription()); $new->setMaxAttend($schedule->getMaxAttend()); $new->setPenalty($schedule->getPenalty()); $new->setFirstDate($new_first); $new->setEndDate($new_end); $new->setTeamCategory($schedule->getTeamCategory()); $new->setLevel($schedule->getLevel()); $new->setLocation($schedule->getLocation()); $new->setSchedule($parent); foreach ($schedule->getInstructors() as $instructor) { $new->addInstructor($instructor); } foreach ($schedule->getFields() as $field) { $new->addField($field); } $this->em->persist($new); return $new; }