Example #1
0
 /**
  * @param ImportedTransport $source
  * @param Transport $destination
  * @return mixed
  */
 public function map($source, $destination)
 {
     $destination->setDistance($source->getDistance());
     $destination->setComments($source->getComment());
     $destination->setLabel($source->getLabel());
     $destination->setPublish($source->getPublish());
     return $destination;
 }
Example #2
0
 /**
  * Importe les données d'un hôtel en particulier.
  * Utilise le webservice Artsys flux/hotel
  *
  * @param string $codeAdherent Code adhérent SEH de l'hôtel à importer
  *
  * @Route("/{codeAdherent}", name="importArtsysHotel")
  * @Template()
  */
 public function importAction($codeAdherent, $log = false)
 {
     $timeStep1 = microtime(true);
     $xmlMapper = $this->getXmlMapper();
     $detailsClient = $this->getArtsysClient();
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     /** @var $translationRepository */
     $translationRepository = $em->getRepository('Gedmo\\Translatable\\Entity\\Translation');
     $entity = $em->getRepository('BigfootImportBundle:DataSource')->findOneby(array('slug' => $this->container->getParameter('artsys_bundle.datasource_slug')));
     // Initialisation du client
     $detailsClient = new Client();
     $detailsClient->init($entity->getProtocol(), $entity->getDomain(), $entity->getPort());
     $detailsClient->setAuth($entity->getUsername(), $entity->getPassword());
     // Récupération de l'hotel
     if ($log) {
         $time = microtime(true);
     }
     $artsysInfos = $detailsClient->get('flux/hotel?codeAdherent=' . $codeAdherent, false);
     if ($log) {
         $time = microtime(true) - $time;
     }
     if ($log) {
         $this->logger->info(sprintf('Artsys Webservice call : %s seconds', $time));
     }
     try {
         // Création de l'objet XML
         $artsysHotelXml = simplexml_load_string($artsysInfos);
         // print_r(json_encode($artsysHotelXml)); die();
         if ($artsysHotelXml) {
             $artsysHotel = $xmlMapper->map($artsysHotelXml);
             if ($artsysHotel != null && $artsysHotel instanceof Hotel) {
                 foreach ($artsysHotel->getTransports() as $transport) {
                     $em->remove($transport);
                 }
                 $transportsXml = $artsysHotelXml->xpath('transports/transport');
                 $labels = array('fr' => 'labelFR', 'en' => 'labelEN', 'de' => 'labelDE', 'es' => 'labelES', 'it' => 'labelIT', 'nl' => 'labelNL');
                 /** @var \SimpleXMLElement $transportXml */
                 foreach ($transportsXml as $transportXml) {
                     /** @var \SimpleXMLElement $transportCategoryXml */
                     $transportCategoryXml = $transportXml->xpath('categorie')[0];
                     $transportCategoryId = $transportCategoryXml->xpath('@id');
                     $transportCategoryId = (string) $transportCategoryId[0];
                     if (!($transportCategory = $em->getRepository('SehBundle:HotelTransportCategory')->findOneBy(array('artsysId' => $transportCategoryId)))) {
                         $transportCategory = new HotelTransportCategory();
                         $transportCategory->setArtsysId($transportCategoryId);
                         foreach ($labels as $locale => $label) {
                             $translationRepository->translate($transportCategory, 'label', $locale, (string) $transportCategoryXml->xpath($label)[0]);
                         }
                     }
                     $transport = new HotelTransport();
                     if ($distance = $transportXml->xpath('distance')) {
                         $transport->setDistance((string) $distance[0]);
                     }
                     if ($comments = $transportXml->xpath('commentaires')) {
                         $transport->setComments((string) $comments[0]);
                     }
                     if ($label = $transportXml->xpath('libelle')) {
                         $transport->setLabel((string) $label[0]);
                     }
                     $transport->setPublish($transportXml->xpath('publiable')[0] == 'true');
                     $transport->setCategory($transportCategory);
                     $transport->setHotel($artsysHotel);
                     $transportCategory->addTransport($transport);
                     $artsysHotel->addTransport($transport);
                     $em->persist($transportCategory);
                     $em->persist($transport);
                     $em->flush();
                 }
                 $hotelPois = array();
                 /** @var HotelPoi $poi */
                 foreach ($artsysHotel->getHotelPois() as $poi) {
                     if (in_array($poi->getPoi()->getArtsysID(), $hotelPois)) {
                         $em->remove($poi);
                     } else {
                         $hotelPois[] = $poi->getPoi()->getArtsysID();
                     }
                 }
                 $poisXml = $artsysHotelXml->xpath('pois/poi');
                 /** @var \SimpleXMLElement $poiXml */
                 foreach ($poisXml as $poiXml) {
                     /** @var \SimpleXMLElement $poiCategoryXml */
                     $poiCategoryXml = $poiXml->xpath('categoriePOI')[0];
                     $poiCategoryId = $poiCategoryXml->xpath('@id');
                     $poiCategoryId = (string) $poiCategoryId[0];
                     if (!($poiCategory = $em->getRepository('SehBundle:PoiCategory')->findOneBy(array('artsysID' => $poiCategoryId)))) {
                         $poiCategory = new PoiCategory();
                         $poiCategory->setArtsysID($poiCategoryId);
                         foreach ($labels as $locale => $label) {
                             $translationRepository->translate($poiCategory, 'name', $locale, (string) $poiCategoryXml->xpath($label)[0]);
                         }
                     }
                     $poiId = $poiXml->xpath('id');
                     $poiId = (string) $poiId[0];
                     if (!($poi = $em->getRepository('SehBundle:Poi')->findOneBy(array('artsysID' => $poiId)))) {
                         $poi = new Poi();
                         $poi->setArtsysID($poiId);
                         $poi->setName((string) $poiXml->xpath('precisions')[0]);
                     }
                     if (!($hotelPoi = $em->getRepository('SehBundle:HotelPoi')->findOneBy(array('hotel' => $artsysHotel, 'poi' => $poi)))) {
                         $hotelPoi = new HotelPoi();
                         if ($distance = $poiXml->xpath('distance')) {
                             $hotelPoi->setDistance((string) $distance[0]);
                         }
                     }
                     $poi->setPoiCategory($poiCategory);
                     $hotelPoi->setHotel($artsysHotel);
                     $hotelPoi->setPoi($poi);
                     $artsysHotel->addHotelPoi($hotelPoi);
                     $em->persist($poiCategory);
                     $em->persist($poi);
                     $em->persist($hotelPoi);
                     $em->flush();
                 }
                 $city = $artsysHotel->getCity();
                 if (strpos($city->getName(), "aix") !== false || strpos($city->getName(), "agde") !== false) {
                     $this->printMessage(sprintf("Nom ville : %s.\n", $city->getName()));
                 }
                 if ($city instanceof City) {
                     if ($city->getLatitude() == null || $city->getLongitude() == null) {
                         $tabCoord = $this->container->get('artsys_google.client')->getGoogleXmlCoords($city->getName(), 'fr');
                         if (isset($tabCoord[0]) && !empty($tabCoord[0]) && isset($tabCoord[1]) && !empty($tabCoord[1])) {
                             $city->setLatitude($tabCoord[0]);
                             $city->setLongitude($tabCoord[1]);
                             $em->persist($city);
                         }
                     }
                     unset($city);
                 }
                 $cities = $artsysHotel->getLinkedCities();
                 foreach ($cities as $city) {
                     if ($city instanceof City) {
                         if ($city->getLatitude() == null || $city->getLongitude() == null) {
                             $tabCoord = $this->container->get('artsys_google.client')->getGoogleXmlCoords($city->getName(), 'fr');
                             if (isset($tabCoord[0]) && !empty($tabCoord[0]) && isset($tabCoord[1]) && !empty($tabCoord[1])) {
                                 $city->setLatitude($tabCoord[0]);
                                 $city->setLongitude($tabCoord[1]);
                                 $em->persist($city);
                             }
                         }
                         unset($city);
                     }
                 }
                 if ($log) {
                     $time = microtime(true);
                 }
                 $em->flush();
                 $em->clear();
                 if ($log) {
                     $time = microtime(true) - $time;
                     $this->logger->info(sprintf('Doctrine flush : %s seconds', $time));
                 }
                 $execTime = round(microtime(true) - $timeStep1);
                 echo sprintf("Import réussi pour l'hotel %s en %s s.\n\n", $artsysHotel->getName(), $execTime);
                 $artsysHotel = null;
                 $artsysHotelXml = null;
                 unset($artsysHotel);
                 unset($artsysHotelXml);
             }
         }
     } catch (\Exception $e) {
         if ($log) {
             $this->logger->error(sprintf('Error while importing hotel %s (Webservice XML error : %s)', $codeAdherent, $e->getMessage(), $e->getMessage()));
         } else {
             echo $e->getMessage();
         }
     }
 }
Example #3
0
 /**
  * @param $codeAdherent
  */
 public function import($codeAdherent)
 {
     set_time_limit(0);
     $detailsClient = $this->getArtsysClient();
     $xmlMapper = $this->getXmlMapper();
     $em = $this->em;
     /** @var TranslationRepository $translationRepository */
     $translationRepository = $em->getRepository('Gedmo\\Translatable\\Entity\\Translation');
     $artsysInfos = $detailsClient->get('flux/hotel?codeAdherent=' . $codeAdherent, false);
     $serializer = SerializerBuilder::create()->build();
     $hotel = $serializer->deserialize($artsysInfos, 'Seh\\Bundle\\ArtsysBundle\\Model\\Hotel', 'xml');
     $artsysHotelXml = simplexml_load_string($artsysInfos);
     if ($artsysHotelXml) {
         $artsysHotel = $xmlMapper->map($artsysHotelXml);
         if ($artsysHotel != null && $artsysHotel instanceof Hotel) {
             foreach ($artsysHotel->getTransports() as $transport) {
                 $em->remove($transport);
             }
             $transportsXml = $artsysHotelXml->xpath('transports/transport');
             $labels = array('fr' => 'labelFR', 'en' => 'labelEN', 'de' => 'labelDE', 'es' => 'labelES', 'it' => 'labelIT', 'nl' => 'labelNL');
             /** @var \SimpleXMLElement $transportXml */
             foreach ($transportsXml as $transportXml) {
                 /** @var \SimpleXMLElement $transportCategoryXml */
                 $transportCategoryXml = $transportXml->xpath('categorie')[0];
                 $transportCategoryId = $transportCategoryXml->xpath('@id');
                 $transportCategoryId = (string) $transportCategoryId[0];
                 if (!($transportCategory = $em->getRepository('SehBundle:HotelTransportCategory')->findOneBy(array('artsysId' => $transportCategoryId)))) {
                     $transportCategory = new HotelTransportCategory();
                     $transportCategory->setArtsysId($transportCategoryId);
                     foreach ($labels as $locale => $label) {
                         $translationRepository->translate($transportCategory, 'label', $locale, (string) $transportCategoryXml->xpath($label)[0]);
                     }
                 }
                 $transport = new HotelTransport();
                 if ($distance = $transportXml->xpath('distance')) {
                     $transport->setDistance((string) $distance[0]);
                 }
                 if ($comments = $transportXml->xpath('commentaires')) {
                     $transport->setComments((string) $comments[0]);
                 }
                 if ($label = $transportXml->xpath('libelle')) {
                     $transport->setLabel((string) $label[0]);
                 }
                 $transport->setPublish($transportXml->xpath('publiable')[0] == 'true');
                 $transport->setCategory($transportCategory);
                 $transport->setHotel($artsysHotel);
                 $transportCategory->addTransport($transport);
                 $artsysHotel->addTransport($transport);
                 $em->persist($transportCategory);
                 $em->persist($transport);
                 $em->flush();
             }
             $hotelPois = array();
             /** @var HotelPoi $poi */
             foreach ($artsysHotel->getHotelPois() as $poi) {
                 if (in_array($poi->getPoi()->getArtsysID(), $hotelPois)) {
                     $em->remove($poi);
                 } else {
                     $hotelPois[] = $poi->getPoi()->getArtsysID();
                 }
             }
             $poisXml = $artsysHotelXml->xpath('pois/poi');
             /** @var \SimpleXMLElement $poiXml */
             foreach ($poisXml as $poiXml) {
                 /** @var \SimpleXMLElement $poiCategoryXml */
                 $poiCategoryXml = $poiXml->xpath('categoriePOI')[0];
                 $poiCategoryId = $poiCategoryXml->xpath('@id');
                 $poiCategoryId = (string) $poiCategoryId[0];
                 if (!($poiCategory = $em->getRepository('SehBundle:PoiCategory')->findOneBy(array('artsysID' => $poiCategoryId)))) {
                     $poiCategory = new PoiCategory();
                     $poiCategory->setArtsysID($poiCategoryId);
                     foreach ($labels as $locale => $label) {
                         $translationRepository->translate($poiCategory, 'name', $locale, (string) $poiCategoryXml->xpath($label)[0]);
                     }
                 }
                 $poiId = $poiXml->xpath('id');
                 $poiId = (string) $poiId[0];
                 /** @var Poi $poi */
                 if (!($poi = $em->getRepository('SehBundle:Poi')->findOneBy(array('artsysID' => $poiId)))) {
                     $poi = new Poi();
                     $poi->setArtsysID($poiId);
                     $poi->setName((string) $poiXml->xpath('precisions')[0]);
                 }
                 if (!($hotelPoi = $em->getRepository('SehBundle:HotelPoi')->findOneBy(array('hotel' => $artsysHotel, 'poi' => $poi)))) {
                     $hotelPoi = new HotelPoi();
                     if ($distance = $poiXml->xpath('distance')) {
                         $hotelPoi->setDistance((string) $distance[0]);
                     }
                 }
                 $poi->setPoiCategory($poiCategory);
                 $hotelPoi->setHotel($artsysHotel);
                 $hotelPoi->setPoi($poi);
                 $artsysHotel->addHotelPoi($hotelPoi);
                 $em->persist($poiCategory);
                 $em->persist($poi);
                 $em->persist($hotelPoi);
                 $em->flush();
             }
             $city = $artsysHotel->getCity();
             if ($city instanceof City) {
                 if ($city->getLatitude() == null || $city->getLongitude() == null) {
                     $tabCoord = $this->google->getGoogleXmlCoords($city->getName(), 'fr');
                     if (isset($tabCoord[0]) && !empty($tabCoord[0]) && isset($tabCoord[1]) && !empty($tabCoord[1])) {
                         $city->setLatitude($tabCoord[0]);
                         $city->setLongitude($tabCoord[1]);
                         $em->persist($city);
                     }
                 }
                 unset($city);
             }
             $cities = $artsysHotel->getLinkedCities();
             foreach ($cities as $city) {
                 if ($city instanceof City) {
                     if ($city->getLatitude() == null || $city->getLongitude() == null) {
                         $tabCoord = $this->google->getGoogleXmlCoords($city->getName(), 'fr');
                         if (isset($tabCoord[0]) && !empty($tabCoord[0]) && isset($tabCoord[1]) && !empty($tabCoord[1])) {
                             $city->setLatitude($tabCoord[0]);
                             $city->setLongitude($tabCoord[1]);
                             $em->persist($city);
                         }
                     }
                     unset($city);
                 }
             }
             $em->flush();
             $em->clear();
             $artsysHotel = null;
             $artsysHotelXml = null;
             unset($artsysHotel);
             unset($artsysHotelXml);
         }
     }
 }