/** * * @param unknown $entity * @param EntityManager $em */ public function syncVolsPlanified(EPlanDeVols $entity, EntityManager $em) { $daylist = array('Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'); $days = $entity->getDaysArray(); //Calcul period $begin = $entity->getStartAt(); $end = $entity->getEndAt(); $end = $end->modify('+1 day'); $period = array(); while ($begin < $end) { $period[] = \DateTime::createFromFormat('d/m/Y H:i:s', $begin->format('d/m/Y H:i:s')); $begin->modify('+1 day'); } foreach ($entity->getVols() as $singleVols) { //$singleVols = new Vols(); //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 $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); //var_dump($daytime->format("D, d/m"),$singleVols->getNumeroVols()); $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(); } } } } }
public function isVolsPlanifiedAvailable(VolsPlanified $vols, $options = array()) { $avion = $vols->getVols()->getPlanDeVols()->getAvion(); $restrictions = $avion->getRestrictionPassager(); $volsTarifaires = $vols->getVolsTarifaire(); //echo "<pre>"; //$seats = 0; foreach ($volsTarifaires as $vt) { $seatsPerCabine = 0; foreach ($restrictions as $restriction) { //Count all available seats //$seats += $vt->getPnr()->getNbPassagersAssis(); //Count all available seats per cabine if ($vt->getPnr()->getStatus()->getOrder() <= 3 && $restriction->getCabine() == $vt->getTarifaire()->getCabine()) { $seatsPerCabine += $vt->getNbPassagersByTypePassager($restriction->getTypePassager()); } if ($seatsPerCabine >= $restriction->getNbSieges()) { return false; } } } $nombrePassagerNeeded = 0; if (isset($options["typePassager"])) { foreach ($options["typePassager"] as $key => $typePassager) { if ($key != 'bebe') { $nombrePassagerNeeded += $typePassager; } } } if ($nombrePassagerNeeded > $vols->getNbAvailableSeating()) { return false; } if ($vols->getNbAvailableSeating() <= 0) { return false; } return true; }