Ejemplo n.º 1
0
 public function addAddress(Address $address)
 {
     try {
         if ($address != null) {
             $latLong = [];
             if ($address->getLatitude() == null && $address->getLongitude() == null || $address->getLatitude() == 0.0 && $address->getLongitude() == 0.0) {
                 $latLong = $this->googleMapService->getLatLong($address);
                 if (sizeof($latLong) == 2) {
                     $address->setLatitude($latLong[0]);
                     $address->setLongitude($latLong[1]);
                 }
             }
             if (!parent::getBdd()->inTransaction()) {
                 parent::getBdd()->beginTransaction();
             }
             $query = "INSERT INTO ADDRESS VALUES (NULL,:line1, :line2, :zipcode, :city, :lat, :long)";
             $request = parent::getBdd()->prepare($query);
             $request->bindParam(':line1', $address->getLine1());
             $request->bindParam(':line2', $address->getLine2());
             $request->bindParam(':zipcode', $address->getZipCode());
             $request->bindParam(':city', $address->getCity());
             $request->bindParam(':lat', $address->getLatitude());
             $request->bindParam(':long', $address->getLongitude());
             $request->execute();
             $id = parent::getBdd()->lastInsertId();
             $request->closeCursor();
             parent::getBdd()->commit();
             return $id;
         }
     } catch (Exception $e) {
         error_log($e->getMessage());
     }
     return -1;
 }
Ejemplo n.º 2
0
 public function testAddressLatitudeAndLongitude()
 {
     $address = new Address();
     $address->latitude = 123.145638;
     $this->assertEquals('123.145638', $address->getLatitude());
     $address->longitude = 121.176129;
     $this->assertEquals('121.176129', $address->getLongitude());
 }
 /**
  * Tests Address->getLatitude()
  */
 public function testGetLatitude()
 {
     $this->assertEquals('LATITUDE', $this->Address->getLatitude());
 }
Ejemplo n.º 4
0
 /**
  * @param Address $addressB
  * @return float the distance in km
  */
 public function distanceToAddress(Address $addressB)
 {
     $longitudeA = $this->getLongitude();
     $latitudeA = $this->getLatitude();
     $longitudeB = $addressB->getLongitude();
     $latitudeB = $addressB->getLatitude();
     return $this->calculateDistanceInKm($longitudeA, $latitudeA, $longitudeB, $latitudeB);
 }
Ejemplo n.º 5
0
 /**
  * Tests Address->setLatitude()
  */
 public function testSetLatitude()
 {
     $this->Address->setLatitude('latitude');
     $this->assertEquals('latitude', $this->Address->getLatitude());
 }