Example #1
0
 public function refreshAction()
 {
     $em = $this->getDoctrine()->getManager();
     $session = $this->getRequest()->getSession();
     $config = $em->find('BackResaBookingBundle:Configuration', 1);
     if (!$config) {
         $session->getFlashBag()->add('info', " Vos paramétres de configuration sont vides ");
         return $this->redirect($this->generateUrl('back_resabooking_hotels_liste'));
     }
     $xmlProducts = simplexml_load_file($config->getLienProduit(), "SimpleXMLELement", LIBXML_NOCDATA);
     $json = json_encode($xmlProducts);
     $produits = json_decode($json, TRUE);
     $xmlPrix = simplexml_load_file($config->getLienPrix(), "SimpleXMLELement", LIBXML_NOCDATA);
     $json = json_encode($xmlPrix);
     $prix = json_decode($json, TRUE);
     foreach ($produits['produit'] as $produit) {
         $hotel = $em->find('BackResaBookingBundle:Hotel', $produit['id_hotel']);
         if (!$hotel) {
             $hotel = new Hotel();
             $hotel->setId($produit['id_hotel']);
         }
         $hotel->setLibelle($produit['libelle_hotel']);
         $hotel->setProduit($produit);
         $arrayPrix = array();
         foreach ($prix['produit'] as $p) {
             if ($p['id_hotel'] == $produit['id_hotel']) {
                 $arrayPrix[] = $p;
             }
         }
         $hotel->setPrix($arrayPrix);
         $em->persist($hotel);
         $em->flush();
     }
     $session->getFlashBag()->add('success', " les hôtels sont à jour ");
     return $this->redirect($this->generateUrl('back_resabooking_hotels_liste'));
 }