Example #1
0
 public function regionsAction()
 {
     die('nope');
     //        http://ws.geonames.org/search?q=&country=HR&fclass=A&username=nebs&fcode=ADM1
     $em = $this->getDoctrine()->getManager();
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, 'http://ws.geonames.org/searchJSON?q=&country=HR&fclass=A&username=nebs&fcode=ADM1&maxRows=1000');
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
     // Assuming you're requesting JSON
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $response = curl_exec($ch);
     // If using JSON...
     $data = json_decode($response);
     foreach ($data->geonames as $region) {
         $country = $em->getRepository('AppBundle:Country')->findOneByName($region->countryName);
         $name = $region->name;
         $geonameId = $region->geonameId;
         $regionObj = new Region();
         $regionObj->setName($name);
         $regionObj->setGeonameId($geonameId);
         $regionObj->setCountry($country);
         $em->persist($regionObj);
         $em->flush();
     }
     return $this->render('AdminBundle::parse.html.twig', array('data' => $data->geonames));
 }