Esempio n. 1
0
 public function location()
 {
     $hideWhereAmI = true;
     $location = new Location();
     $location->load();
     if (!empty($_GET)) {
         $location = new Location();
         if (!empty($_GET['lat']) and !empty($_GET['lng'])) {
             $location->getPoint()->setLat($_GET['lat']);
             $location->getPoint()->setLng($_GET['lng']);
             $location->save();
         } elseif (!empty($_GET['cep'])) {
             $address = new Address();
             $address->setZipcode($_GET['cep']);
             $geocode = $this->api->geocode($address);
             if (!empty($geocode)) {
                 $location->getPoint()->setLat($geocode->getLat());
                 $location->getPoint()->setLng($geocode->getLng());
                 $revgeocode = $this->api->revgeocode($geocode->getLat(), $geocode->getLng());
                 $location->setAddress($revgeocode);
                 $location->save();
             } else {
                 $this->redirect("profile/location");
             }
         } elseif (!empty($_GET['cityState'])) {
             if (!strstr($_GET['cityState'], ',')) {
                 $this->redirect("profile/location");
             }
             $cityStateToUpper = strtoupper($_GET['cityState']);
             list($cityField, $stateField) = \explode(',', $cityStateToUpper);
             $city = new City();
             $city->setName(trim($cityField));
             $city->setState(trim($stateField));
             $address = new Address();
             $address->setCity(new City($city));
             $geocode = $this->api->geocode($address);
             if (!empty($geocode)) {
                 $location->getPoint()->setLat($geocode->getLat());
                 $location->getPoint()->setLng($geocode->getLng());
                 $location->getAddress()->setCity($city);
                 $location->save();
             } else {
                 $this->redirect("profile/location");
             }
         }
         $this->redirect("/");
     }
     $title = 'Onde estou';
     return compact('title', 'geocode', 'hideWhereAmI', 'location');
 }
Esempio n. 2
0
    public function testGetRequestByCreatePlace()
    {
        $placeJson = <<<JSON
{"place": {
    "id":"NOVOID",
    "name":"Bar Tolomeu",
    "description": "Um bom restaurante",
    "review_count":"52",
    "average_rating":"4",
    "thumbs":{
        "total":"779",
        "up":"606"
    },
    "category":{
        "id":"67",
        "name":"RESTAURANTES",
        "subcategory":{
            "id":"95267",
            "name":"A Quilo "
        }
    },
    "address":{
        "street":"R Min. Jesuino Cardoso",
        "number":"473",
        "district":"Vila Olimpia",
        "zipcode":"00000000",
        "complement":"",
        "city":{
            "country":"BR",
            "state":"SP",
            "name":"Sorocaba"
        }
    },
    "phone":{
        "country":"55",
        "area":"11",
        "number":"25793044"
    },
    "created":{
        "timestamp":"2007-08-01T00:00:00",
        "user":{
            "id":"1997653480",
            "name":"Uziel Restaurante",
            "photo_large_url":"http://aptuser.s3.amazonaws.com/1997653480_b.jpg",
            "photo_url":"http://aptuser.s3.amazonaws.com/1997653480_b.jpg",
            "photo_medium_url":"http://aptuser.s3.amazonaws.com/1997653480_m.jpg",
            "photo_small_url":"http://aptuser.s3.amazonaws.com/1997653480_s.jpg"
        }
    },
    "point":{
        "lat":"-23.59260829",
        "lng":"-46.68183288"
    },
    "main_url":"http://www.apontador.com.br/local/sp/sao_paulo/restaurantes/UCV34B2P/uziel_restaurante___sao_paulo.html",
    "icon_url":"http://img218.imageshack.us/img218/5889/logov2pv.jpg",
    "other_url":""
    }
}
JSON;
        $city = new City();
        $city->setName("Sorocaba");
        $city->setState("SP");
        $city->setCountry("BR");
        $address = new Address();
        $address->setStreet("Rua Aclimação");
        $address->setNumber(620);
        $address->setComplement("Esquina");
        $address->setDistrict("Jardim Paulistano");
        $address->setZipcode("18040690");
        $address->setCity($city);
        $place = new Place();
        $place->setName("Bar Tolomeu");
        $place->setAddress($address);
        $placeRepository = new PlaceRepository($this->getConfigMock($placeJson));
        $savedPlace = $placeRepository->save($place);
        $this->assertEquals("NOVOID", $savedPlace->getId());
        $this->assertEquals("Bar Tolomeu", $savedPlace->getName());
    }