public function contingentAction(VoyageOrganise $voyage)
 {
     $em = $this->getDoctrine()->getManager();
     $session = $this->getRequest()->getSession();
     foreach ($voyage->getPeriodes() as $periode) {
         foreach ($periode->getPacks() as $pack) {
             if (count($pack->getHotels()) > 0) {
                 $verif = $em->getRepository('BackVoyageOrganiseBundle:Contingent')->findOneBy(array('voyage' => $voyage, 'hotel' => $pack->getHotels()->first()));
                 if (!$verif) {
                     $contingent = new Contingent();
                     $voyage->addContingent($contingent->setHotel($pack->getHotels()->first())->setPack($pack));
                 }
             }
         }
     }
     $form = $this->createForm(new VoyageOrganiseContingentType(), $voyage);
     $request = $this->getRequest();
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             $voyage = $form->getData();
             foreach ($voyage->getContingents() as $contingent) {
                 $em->persist($contingent->setVoyage($voyage));
                 $this->container->get('chambreVO')->update($contingent);
             }
             $em->flush();
             return $this->redirect($this->generateUrl('back_vo_contingent', array('voyage' => $voyage->getId())));
         }
     }
     return $this->render('BackVoyageOrganiseBundle:voyageOrganise:contingents.html.twig', array('form' => $form->createView(), 'voyage' => $voyage));
 }
예제 #2
0
 public function update(Contingent $contingent)
 {
     $nameHotel = $contingent->getHotel()->getLibelle();
     $nbrSingle = count($this->em->getRepository('BackVoyageOrganiseBundle:Chambre')->findBy(array('contingent' => $contingent, 'type' => 1)));
     $nbrDouble = count($this->em->getRepository('BackVoyageOrganiseBundle:Chambre')->findBy(array('contingent' => $contingent, 'type' => 2)));
     $nbrTriple = count($this->em->getRepository('BackVoyageOrganiseBundle:Chambre')->findBy(array('contingent' => $contingent, 'type' => 3)));
     $nbrQuadruple = count($this->em->getRepository('BackVoyageOrganiseBundle:Chambre')->findBy(array('contingent' => $contingent, 'type' => 4)));
     if ($contingent->getChambreSingle() > $nbrSingle) {
         for ($i = 1; $i <= $contingent->getChambreSingle() - $nbrSingle; $i++) {
             $chambre = new Chambre();
             $this->em->persist($chambre->setContingent($contingent)->setType(1));
             $this->session->getFlashBag()->add('info', "<strong>{$nameHotel}: </strong> Une chambre single a été crée ");
         }
     }
     if ($nbrSingle > $contingent->getChambreSingle()) {
         $i = $nbrSingle - $contingent->getChambreSingle();
         foreach ($contingent->getChambres() as $chambre) {
             if ($chambre->getType() == 1 and $i > 0) {
                 $this->em->remove($chambre);
                 $this->session->getFlashBag()->add('warning', "<strong>{$nameHotel}: </strong>  Une chambre single a été supprimée ");
                 $i--;
             }
         }
     }
     if ($contingent->getChambreDouble() > $nbrDouble) {
         for ($i = 1; $i <= $contingent->getChambreDouble() - $nbrDouble; $i++) {
             $chambre = new Chambre();
             $this->em->persist($chambre->setContingent($contingent)->setType(2));
             $this->session->getFlashBag()->add('info', "<strong>{$nameHotel}: </strong>  Une chambre double a été crée ");
         }
     }
     if ($nbrDouble > $contingent->getChambreDouble()) {
         $i = $nbrDouble - $contingent->getChambreDouble();
         foreach ($contingent->getChambres() as $chambre) {
             if ($chambre->getType() == 2 and $i > 0) {
                 $this->em->remove($chambre);
                 $this->session->getFlashBag()->add('warning', "<strong>{$nameHotel}: </strong>  Une chambre double a été supprimée ");
                 $i--;
             }
         }
     }
     if ($contingent->getChambreTriple() > $nbrTriple) {
         for ($i = 1; $i <= $contingent->getChambreTriple() - $nbrTriple; $i++) {
             $chambre = new Chambre();
             $this->em->persist($chambre->setContingent($contingent)->setType(3));
             $this->session->getFlashBag()->add('info', "<strong>{$nameHotel}: </strong>  Une chambre triple a été crée ");
         }
     }
     if ($nbrTriple > $contingent->getChambreTriple()) {
         $i = $nbrTriple - $contingent->getChambreTriple();
         foreach ($contingent->getChambres() as $chambre) {
             if ($chambre->getType() == 3 and $i > 0) {
                 $this->em->remove($chambre);
                 $this->session->getFlashBag()->add('warning', "<strong>{$nameHotel}: </strong>  Une chambre triple a été supprimée ");
                 $i--;
             }
         }
     }
     if ($contingent->getChambreQuadruple() > $nbrQuadruple) {
         for ($i = 1; $i <= $contingent->getChambreQuadruple() - $nbrQuadruple; $i++) {
             $chambre = new Chambre();
             $this->em->persist($chambre->setContingent($contingent)->setType(4));
             $this->session->getFlashBag()->add('info', "<strong>{$nameHotel}: </strong>  Une chambre quadruple a été crée ");
         }
     }
     if ($nbrQuadruple > $contingent->getChambreQuadruple()) {
         $i = $nbrQuadruple - $contingent->getChambreQuadruple();
         foreach ($contingent->getChambres() as $chambre) {
             if ($chambre->getType() == 4 and $i > 0) {
                 $this->em->remove($chambre);
                 $this->session->getFlashBag()->add('warning', "<strong>{$nameHotel}: </strong>  Une chambre quadruple a été supprimée ");
                 $i--;
             }
         }
     }
 }