Exemplo n.º 1
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Zipcode $value A Zipcode object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Zipcode $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Exemplo n.º 2
0
 /**
  * Zwraca liste wspisow pasujacych do zadanych parametrow
  *
  * @param string $hash
  * @param integer $tercRegion
  * @param string $district
  * @param string $town
  * @param string $zipcode
  * @param integer $limit
  * @throws SoapFault
  * @return object
  */
 public function searchByParamsStrict($hash, $tercRegion, $district, $town, $zipcode, $limit = 100)
 {
     try {
         // usluga: Kody pocztowe; id: 4
         $this->_init($hash, 'Kes)9sW%', 'searchByParamsStrict', array('tercRegion' => $tercRegion, 'district' => $district, 'town' => $town, 'zipcode' => $zipcode, 'limit' => $limit), $this->_revision);
         $model = new Zipcode();
         $results = $model->getDataTownDistrict($town, $district, $tercRegion, $zipcode, $limit);
         $object = new stdClass();
         if (!empty($results)) {
             $object->resultsList = $results;
         } else {
             $object->resultsList = array();
         }
         return $this->_responseHandler($object);
     } catch (Logic_WebService_Exception $e) {
         return $this->_faultHandler($e);
     }
 }
Exemplo n.º 3
0
 /**
  * Overwrite Address2 Setter 
  * to geocode the locatable model
  * 
  */
 function setAddress2Attribute($address2)
 {
     $this->attributes['address2'] = $address2;
     $parts = explode(" ", $address2);
     if (count($parts) > 0 && is_numeric($parts[0])) {
         $zipcode = Zipcode::where('zipcode', '=', $parts[0])->first();
         if ($zipcode instanceof Zipcode) {
             // connect to  Zipcode
             $this->zipcode_id = $zipcode->id;
             // Try to geocode
             if (!$this->geocode()) {
                 $geocoded = $this->geocodeKey();
                 // use district lat lng if available
                 if ($zipcode->district) {
                     $this->lat = $zipcode->district->lat;
                     $this->lng = $zipcode->district->lng;
                     $this->geosource = 'ZIPD';
                     $this->geocoded = $geocoded;
                 } else {
                     if ($zipcode->city) {
                         $this->lat = $zipcode->city->lat;
                         $this->lng = $zipcode->city->lng;
                         $this->geosource = 'ZIPC';
                         $this->geocoded = $geocoded;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
        $zipcode = new Zipcode();
        $zipcode->createBlock($argv[3], $argv[2]);
        break;
    case '--restaurant-num-by-block':
        $zipcode = new Zipcode();
        $zipcode->mintcraftBlocks($argv[3], $argv[2]);
        break;
    case '--restaurant-unique-value':
        $zipcode = new Zipcode();
        $zipcode->mintcraftUniqueValues($argv[2]);
        break;
    case '--diff':
        $zipcode = new Zipcode();
        $zipcode->zipcodesUniqueValues();
        $zipcode->locationUnique($argv[2]);
        //$zipcode->diffZipcodes($argv[2]);
        $zipcode->diffFileLocation('/usr/share/nginx/cli/SDInvoicesFileCheck/app/cli/test/diff.txt');
        break;
    case '--more-information':
        $zipcode = new Zipcode();
        $zipcode->needMoreInformation('/usr/share/nginx/cli/SDInvoicesFileCheck/app/cli/test/zipcode_unique.txt');
        break;
    case '--count-restaurants':
        $zipcode = new Zipcode();
        $zipcode->readfileLocation($argv[2]);
        break;
    case '--help':
    default:
        echo " Usage:\n command [options] [arguments]\n\n Options:\n   --help                                Display this help message\n   --more-information                    Takes all zip codes and the divided in blocks with the location.\n   --count-restaurants  < filepath >     Display the number of the restaurants per zip code and save in a file text.\n   --all                                 Force ANSI output\n";
        break;
}
Exemplo n.º 5
0
 public function executeCalculateDistance(sfWebRequest $request)
 {
     $origin_ = $request->getParameter('origin');
     $destination_ = $request->getParameter('destination');
     $origin = array();
     $destination = array();
     if (empty($origin_)) {
         $origin[0] = '*';
     } else {
         if (strstr($origin_, ',')) {
             $origin = explode(',', $origin_);
         } else {
             $origin[0] = $origin_;
         }
     }
     if (empty($destination_)) {
         $destination[0] = '*';
     } else {
         if (strstr($destination_, ',')) {
             $destination = explode(',', $destination_);
         } else {
             $destination[0] = $destination_;
         }
     }
     // find airports
     # origin
     //    $c = new Criteria();
     //    if (is_array($origin)) {
     //      if (count($origin) != 3) return $this->renderText('please format: city, state, zipcode');
     //      $c->add(AirportPeer::CITY, trim($origin[0]));
     //      $c->add(AirportPeer::STATE, trim($origin[1]));
     //      $c->add(AirportPeer::ZIPCODE, trim($origin[2]));
     //    }else{
     //      if (empty($origin)) return $this->renderText('please enter origin');
     //      $c->add(AirportPeer::IDENT, $origin);
     //    }
     //    $origin_airport = AirportPeer::doSelectOne($c);
     //    if (!($origin_airport instanceof Airport)) return $this->renderText('origin airport not found');
     //
     //    # destination
     //    $c = new Criteria();
     //    if (is_array($destination)) {
     //      if (count($destination) != 3) return $this->renderText('please format: city, state, zipcode');
     //      $c->add(AirportPeer::CITY, trim($destination[0]));
     //      $c->add(AirportPeer::STATE, trim($destination[1]));
     //      $c->add(AirportPeer::ZIPCODE, trim($destination[2]));
     //    }else{
     //      if (empty($destination)) return $this->renderText('please enter destination');
     //      $c->add(AirportPeer::IDENT, $destination);
     //    }
     //    $destination_airport = AirportPeer::doSelectOne($c);
     //    if (!($destination_airport instanceof Airport)) return $this->renderText('origin airport not found');
     /* Edited By Masum , LAST EDITED BY ZIYED*/
     $flag = 0;
     $c = new Criteria();
     if (is_array($origin)) {
         switch (count($origin)) {
             case 3:
                 $city_name = trim($origin[0]);
                 $state_name = trim($origin[1]);
                 $zip_code = trim($origin[2]);
                 $sql = "SELECT * FROM afids.zipcode WHERE zipcode.city ='" . $city_name . "' AND zipcode.state ='" . $state_name . "' AND zipcode.zipcode ='" . $zip_code . "' limit 1";
                 $ident = 0;
                 break;
             case 2:
                 $city_name = trim($origin[0]);
                 $state_name = trim($origin[1]);
                 $sql = "SELECT * FROM afids.zipcode WHERE zipcode.city ='" . $city_name . "' AND zipcode.state ='" . $state_name . "' limit 1";
                 $ident = 0;
                 break;
             case 1:
                 //trace city
                 $cityname = trim($origin[0]);
                 $query = "select * from afids.zipcode where zipcode.city ='" . $cityname . "'";
                 $conn = Propel::getConnection();
                 $statement = $conn->prepare($query);
                 $statement->execute();
                 $row = $statement->fetch();
                 if (!empty($row)) {
                     $city = 1;
                 } else {
                     $city = 0;
                 }
                 //trace state
                 $statename = trim($origin[0]);
                 $query = "select * from afids.zipcode where zipcode.state ='" . $statename . "'";
                 $conn = Propel::getConnection();
                 $statement = $conn->prepare($query);
                 $statement->execute();
                 $row = $statement->fetch();
                 if (!empty($row)) {
                     $state = 1;
                 } else {
                     $state = 0;
                 }
                 //trace zip
                 $zipcode = trim($origin[0]);
                 $query = "select * from afids.zipcode where zipcode.zipcode ='" . $zipcode . "'";
                 $conn = Propel::getConnection();
                 $statement = $conn->prepare($query);
                 $statement->execute();
                 $row = $statement->fetch();
                 if (!empty($row)) {
                     $zip = 1;
                 } else {
                     $zip = 0;
                 }
                 //trace airport
                 $airportident = trim($origin[0]);
                 $query = "select * from afids.airport where airport.ident ='" . $airportident . "'";
                 $conn = Propel::getConnection();
                 $statement = $conn->prepare($query);
                 $statement->execute();
                 $row = $statement->fetch();
                 if (!empty($row)) {
                     $ident = 1;
                 } else {
                     $ident = 0;
                 }
                 if ($city == 1) {
                     $sql = "SELECT * FROM afids.zipcode WHERE zipcode.city ='" . $cityname . "' limit 1 ";
                 } else {
                     if ($state == 1) {
                         $sql = "SELECT * FROM afids.zipcode WHERE zipcode.state ='" . $statename . "' limit 1";
                     } else {
                         if ($zip == 1) {
                             $sql = "SELECT * FROM afids.zipcode WHERE zipcode.zipcode ='" . $zipcode . "' limit 1";
                         } else {
                             if ($ident == 1) {
                                 $sql = "SELECT * FROM afids.airport WHERE airport.ident ='" . $airportident . "'";
                             } else {
                                 $flag = 1;
                             }
                         }
                     }
                 }
                 break;
             default:
                 return $this->renderText('please format: city, state, zipcode');
                 break;
         }
         //$origin_airport = AirportPeer::doSelectOne($c);
     } else {
         if (empty($origin)) {
             return $this->renderText('please enter origin');
         }
         $flag = 1;
     }
     if ($ident == 1) {
         $conn = Propel::getConnection();
         $statement = $conn->prepare($sql);
         $statement->execute();
         $row = $statement->fetch();
         if (empty($row)) {
             return $this->renderText('origin airport not found');
         }
         $origin_airport = new Airport();
         $origin_airport->setCity($row['city']);
         $origin_airport->setIdent($row['ident']);
         $origin_airport->setState($row['state']);
         $origin_airport->setLatitude($row['latitude']);
         $origin_airport->setLongitude($row['longitude']);
     } else {
         if ($flag != 1) {
             $conn = Propel::getConnection();
             $statement = $conn->prepare($sql);
             $statement->execute();
             $row = $statement->fetch();
             if (empty($row)) {
                 return $this->renderText('origin airport not found');
             }
             $origin_airport = new Zipcode();
             $origin_airport->setCity($row['city']);
             $origin_airport->setState($row['state']);
             $origin_airport->setLatitude($row['latitude']);
             $origin_airport->setLongitude($row['longitude']);
         } else {
             return $this->renderText('origin airport not found');
         }
     }
     //if (!($origin_airport instanceof Airport)) return $this->renderText('origin airport not found');
     $flag = 0;
     # destination
     $c = new Criteria();
     if (is_array($destination)) {
         switch (count($destination)) {
             case 3:
                 $city_name_ = trim($destination[0]);
                 $state_name_ = trim($destination[1]);
                 $zip_code_ = trim($destination[2]);
                 $sql = "SELECT * FROM afids.zipcode WHERE zipcode.city ='" . $city_name_ . "' AND zipcode.state ='" . $state_name_ . "' AND zipcode.zipcode ='" . $zip_code_ . "' limit 1";
                 $identt = 0;
                 break;
             case 2:
                 $city_name_ = trim($destination[0]);
                 $state_name_ = trim($destination[1]);
                 $sql = "SELECT * FROM afids.zipcode WHERE zipcode.city ='" . $city_name_ . "' AND zipcode.state ='" . $state_name_ . "' limit 1";
                 $identt = 0;
                 break;
             case 1:
                 //trace city
                 $dest_city = trim($destination[0]);
                 $query = "select * from afids.zipcode where zipcode.city ='" . $dest_city . "'";
                 $conn = Propel::getConnection();
                 $statement = $conn->prepare($query);
                 $statement->execute();
                 $row = $statement->fetch();
                 if (!empty($row)) {
                     $city = 1;
                 } else {
                     $city = 0;
                 }
                 //trace state
                 $dest_state = trim($destination[0]);
                 $query = "select * from afids.zipcode where zipcode.state ='" . $dest_state . "'";
                 $conn = Propel::getConnection();
                 $statement = $conn->prepare($query);
                 $statement->execute();
                 $row = $statement->fetch();
                 if (!empty($row)) {
                     $state = 1;
                 } else {
                     $state = 0;
                 }
                 //trace zip
                 $dest_zip = trim($destination[0]);
                 $query = "select * from afids.zipcode where zipcode.zipcode ='" . $dest_zip . "'";
                 $conn = Propel::getConnection();
                 $statement = $conn->prepare($query);
                 $statement->execute();
                 $row = $statement->fetch();
                 if (!empty($row)) {
                     $zip = 1;
                 } else {
                     $zip = 0;
                 }
                 //trace airport
                 $dest_airport = trim($destination[0]);
                 $query = "select * from afids.airport where airport.ident ='" . $dest_airport . "'";
                 $conn = Propel::getConnection();
                 $statement = $conn->prepare($query);
                 $statement->execute();
                 $row = $statement->fetch();
                 if (!empty($row)) {
                     $identt = 1;
                 } else {
                     $identt = 0;
                 }
                 if ($city == 1) {
                     $sql = "SELECT * FROM afids.zipcode WHERE zipcode.city ='" . $dest_city . "' limit 1";
                 } else {
                     if ($state == 1) {
                         $sql = "SELECT * FROM afids.zipcode WHERE zipcode.state ='" . $dest_state . "' limit 1";
                     } else {
                         if ($zip == 1) {
                             $sql = "SELECT * FROM afids.zipcode WHERE zipcode.zipcode ='" . $dest_zip . "' limit 1";
                         } else {
                             if ($identt == 1) {
                                 $sql = "SELECT * FROM afids.airport WHERE airport.ident ='" . $dest_airport . "'";
                             } else {
                                 $flag = 1;
                             }
                         }
                     }
                 }
                 break;
             default:
                 return $this->renderText('please format: city, state, zipcode');
                 break;
         }
     } else {
         if (empty($destination)) {
             return $this->renderText('please enter destination');
         }
         $flag = 1;
     }
     if ($identt == 1) {
         $conn = Propel::getConnection();
         $statement = $conn->prepare($sql);
         $statement->execute();
         $row = $statement->fetch();
         if (empty($row)) {
             return $this->renderText('destination airport not found');
         }
         $destination_airport = new Airport();
         $destination_airport->setCity($row['city']);
         $destination_airport->setIdent($row['ident']);
         $destination_airport->setState($row['state']);
         $destination_airport->setLatitude($row['latitude']);
         $destination_airport->setLongitude($row['longitude']);
     } else {
         if ($flag != 1) {
             $conn = Propel::getConnection();
             $statement = $conn->prepare($sql);
             $statement->execute();
             $row = $statement->fetch();
             if (empty($row)) {
                 return $this->renderText('destination airport not found');
             }
             $destination_airport = new Zipcode();
             $destination_airport->setCity($row['city']);
             $destination_airport->setState($row['state']);
             $destination_airport->setLatitude($row['latitude']);
             $destination_airport->setLongitude($row['longitude']);
         } else {
             return $this->renderText('destination airport not found');
         }
     }
     //if (!($destination_airport instanceof Airport)) return $this->renderText('destination airport not found');
     /* End Edited By Masum , LAST EDITED BY ZIYED*/
     $distance = round(acos(sin(deg2rad($origin_airport->getLatitude())) * sin(deg2rad($destination_airport->getLatitude())) + cos(deg2rad($origin_airport->getLatitude())) * cos(deg2rad($destination_airport->getLatitude())) * cos(deg2rad($origin_airport->getLongitude()) - deg2rad($destination_airport->getLongitude()))) * (180 * 60) / pi());
     if ($ident == 1) {
         $html = 'Origin: ' . $origin_airport->getIdent() . ' (' . $origin_airport->getCity() . ', ' . $origin_airport->getState() . ')';
     } else {
         $html = 'Origin: (' . $origin_airport->getCity() . ', ' . $origin_airport->getState() . ')';
     }
     $html .= '<br/>';
     if ($identt == 1) {
         $html .= 'Destination: ' . $destination_airport->getIdent() . ' (' . $destination_airport->getCity() . ', ' . $destination_airport->getState() . ')';
     } else {
         $html .= 'Destination: (' . $destination_airport->getCity() . ', ' . $destination_airport->getState() . ')';
     }
     $html .= '<br/>';
     $html .= 'Distance: ' . $distance . ' nautical miles';
     return $this->renderText($html);
 }
Exemplo n.º 6
0
<?php

require 'classes/zipcode.php';
require_once 'common/header.php';
if (isset($_POST['submit'])) {
    // $address = 'Kothapet, Anantapur, Andhra Pradesh, India';
    $res = '';
    $zc = new Zipcode();
    $res = $zc->getPincode(trim($_POST['address']));
}
?>
<h1> Find Pincode</h1>
<div class="row" style="margin-bottom: 10px;">
    <form id="pin-form" role="form" method="post" action="<?php 
echo $_SERVER['PHP_SELF'];
?>
">
      <div class="form-group">
            <div class="col-sm-4">
                <input type="text" class="form-control" id="address" name="address" placeholder="Enter Address" value="<?php 
if (isset($_POST['address'])) {
    echo $_POST['address'];
}
?>
">
            </div>
      </div>
       <div class="form-group">
           <div class="col-md-4">
               <button type="submit" class="btn btn-default" name="submit">Get Pincode</button>
           </div>