public function getPlacesClosest($place) { $data = array(); $data[] = $this->conn->cleanData($place->getLatitude()); $data[] = $this->conn->cleanData($place->getLongitude()); $data[] = $this->conn->cleanData($place->getDistance()); $query = <<<SQL \t\t\t\t\tSELECT \t\t\t\t\t\tid, \t\t\t\t\t\tname, \t\t\t\t\t\tcategory, \t\t\t\t\t\tdescription, \t\t\t\t\t\tlatitude, \t\t\t\t\t\tlongitude \t\t\t\t\t\tFROM \t\t\t\t\t\t\tlaa_place \t\t\t\t\t\tWHERE \t\t\t\t\t\t\tstatus = 1 \t\t\t\t\t\t\tAND \t\t\t\t\t\t\t6371 * ACOS( \t\t\t\t\t\t\t\t\t\tCOS( RADIANS( {$data['0']} ) ) \t\t\t\t\t\t\t\t\t\t* \t\t\t\t\t\t\t\t\t\tCOS( RADIANS(latitude) ) \t\t\t\t\t\t\t\t\t\t* \t\t\t\t\t\t\t\t\t\tCOS( \t\t\t\t\t\t\t\t\t\t\tRADIANS( {$data['1']} ) \t\t\t\t\t\t\t\t\t\t\t- \t\t\t\t\t\t\t\t\t\t\tRADIANS(longitude) \t\t\t\t\t\t\t\t\t\t) \t\t\t\t\t\t\t\t\t\t+ \t\t\t\t\t\t\t\t\t\tSIN( RADIANS( {$data['0']} ) ) \t\t\t\t\t\t\t\t\t\t* \t\t\t\t\t\t\t\t\t\tSIN( RADIANS(latitude) ) \t\t\t\t\t\t\t\t\t) <= {$data['2']} SQL; //exit($query); $query = $this->conn->removeBreakLine($query); $result = $this->conn->getConn()->query($query); $arrayPlaces = array(); while ($data = $result->fetch_object()) { $place = new Place($data->id); $place->setName($data->name); $place->setCategory(new Category($data->category)); $place->setDescription($data->description); $place->setLatitude($data->latitude); $place->setLongitude($data->longitude); $arrayPlaces[] = $place; } $result->free(); return $arrayPlaces; }
$place = new Place($_POST['id-place']); $place->post($_POST); $return = $apl->updatePlace($place); echo json_encode(array('feedback' => $return)); } else { if (preg_match('/^(get-place-data){1}$/', $_POST['method'])) { $apl = new AplMap(); $place = new Place($_POST['id-place']); $place->post($_POST); $place = $apl->getPlace($place); echo json_encode(array('place' => $place->getDataJSON())); } else { if (preg_match('/^(get-places-closest){1}$/', $_POST['method'])) { $apl = new AplMap(); $place = new Place(); $place->setLatitude($_POST['latitude']); $place->setLongitude($_POST['longitude']); $place->setDistance($_POST['distance']); $arrayPlaces = $apl->getPlacesClosest($place); // SEND TO CLIENT $tam = count($arrayPlaces); $arrayJson = array(); for ($i = 0; $i < $tam; $i++) { $arrayJson[] = $arrayPlaces[$i]->getDataJSON(); } $arrayJson = array('places' => $arrayJson); echo json_encode($arrayJson); } } } }
function test_setLatitude() { //Arrange $place_name = "Director Park"; $address = "SW Park Ave"; $latitude = 45.518672; $longitude = -122.681211; $id = 1; $test_place = new Place($place_name, $address, $latitude, $longitude, $id); //Act $test_place->setLatitude($latitude); $result = $test_place->getLatitude(); //Assert $this->assertEquals("45.518672", $result); }