/** * This first parameter is to be updated be parameter two */ protected function updateSchedule(\Club\TeamBundle\Entity\Schedule $schedule, \Club\TeamBundle\Entity\Schedule $original) { if ($schedule == $original) { return; } $t1_first = clone $original->getFirstDate(); $t1_first->setDate(1970, 1, 1); $t2_first = clone $schedule->getFirstDate(); $t2_first->setDate(1970, 1, 1); $t1_end = clone $original->getEndDate(); $t1_end->setDate(1970, 1, 1); $t2_end = clone $schedule->getEndDate(); $t2_end->setDate(1970, 1, 1); $diff_first = $t1_first->diff($t2_first); $diff_end = $t1_end->diff($t2_end); $em = $this->getDoctrine()->getManager(); $schedule->resetInstructors(); $schedule->resetFields(); $schedule->setDescription($original->getDescription()); $schedule->setFirstDate(new \DateTime($schedule->getFirstDate()->sub($diff_first)->format('Y-m-d H:i:s'))); $schedule->setEndDate(new \DateTime($schedule->getEndDate()->sub($diff_end)->format('Y-m-d H:i:s'))); $schedule->setLevel($original->getLevel()); $schedule->setLocation($original->getLocation()); $schedule->setMaxAttend($original->getMaxAttend()); $schedule->setPenalty($original->getPenalty()); foreach ($original->getInstructors() as $instructor) { $schedule->addInstructor($instructor); } foreach ($original->getFields() as $field) { $schedule->addField($field); } $em->persist($schedule); }
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; }