/** * 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); }