Example #1
0
 public function weekendAction(Saison $saison)
 {
     $em = $this->getDoctrine()->getManager();
     $session = $this->getRequest()->getSession();
     if ($saison->getSaisonWeekend() == NULL) {
         $saisonWeekend = new SaisonWeekend();
     } else {
         $saisonWeekend = $saison->getSaisonWeekend();
     }
     foreach ($saison->getHotel()->getChambres() as $chambre) {
         $verif = $em->getRepository("BackHotelTunisieBundle:SaisonWeekendLigne")->findBy(array('saisonWeekend' => $saisonWeekend, 'chambre' => $chambre));
         if (count($verif) == 0) {
             $saisonWeekendLigne = new SaisonWeekendLigne();
             $saisonWeekendLigne->setChambre($chambre);
             $saisonWeekend->addLigne($saisonWeekendLigne);
         }
     }
     $form = $this->createForm(new SaisonWeekendType(), $saisonWeekend);
     $form->add('lignes', 'collection', array('type' => new SaisonWeekendLigneType($saison->getHotel()->getId())));
     $request = $this->getRequest();
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             $saisonWeekend = $form->getData();
             $em->persist($saisonWeekend);
             foreach ($saisonWeekend->getLignes() as $ligne) {
                 $em->persist($ligne->setSaisonWeekend($saisonWeekend));
             }
             $em->persist($saison->setSaisonWeekend($saisonWeekend));
             $em->flush();
             $session->getFlashBag()->add('success', " Votre saison de base a été modifié avec succées ");
             return $this->redirect($this->generateUrl("WeekendSaison", array('id' => $saison->getId())));
         }
     }
     return $this->render("BackHotelTunisieBundle:Saisons:weekend.html.twig", array('saison' => $saison, 'hotel' => $saison->getHotel(), 'form' => $form->createView()));
 }