/** * * @param PlanDeVols $entity */ public function syncVolsPlanified(PlanDeVols $entity) { $em = $this->em; $daylist = array('Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'); $days = $entity->getDaysArray(); //Calcul period $period = array(); foreach ($entity->getIntervalleValidite() as $intervalle) { $begin = clone $intervalle->getBeginDate(); $end = clone $intervalle->getEndDate(); $end = $end->modify('+1 day'); while ($begin < $end) { $period[] = \DateTime::createFromFormat('d/m/Y H:i:s', $begin->format('d/m/Y H:i:s')); $begin->modify('+1 day'); } //echo"<pre>"; //var_dump($period); //exit(); foreach ($entity->getVols() as $singleVols) { //Delete all unsed VP $volsPlanifiedListToUpdate = $em->getRepository('AppCoreBundle:VolsPlanified')->findByOptions(array('numeroVols' => $singleVols->getNumeroVols())); foreach ($volsPlanifiedListToUpdate as $vp) { //TODO check if below to the period //Check if vp is deletable $pnr_list = $this->em->getRepository('AppCoreBundle:Pnr')->findByOptions(array('Vols' => $vp->getVols())); if (!count($pnr_list)) { $em->remove($vp); $em->flush(); } } foreach ($period as $daytime) { $dayOfTheWeek = $this->DayToNum($daytime->format("D")); if (in_array($daylist[$dayOfTheWeek], $days)) { $flightAt = $daytime->setTime($singleVols->getEscaleDepart()->getAeroportAt()->format('H'), $singleVols->getEscaleDepart()->getAeroportAt()->format('i'), 0); $volsPlanifiedList = $em->getRepository('AppCoreBundle:VolsPlanified')->findByOptions(array('numeroVols' => $singleVols->getNumeroVols(), 'date' => $flightAt)); if (!count($volsPlanifiedList)) { $volsPlanified = new VolsPlanified(); $volsPlanified->setFlightAt($flightAt); $volsPlanified->setStatus($em->getRepository('AppCoreBundle:StatutVols')->findOneBy(array('code' => 'vols-pret'))); $singleVols->addVolsPlanified($volsPlanified); $em->persist($singleVols); $em->flush(); } } } } } }