コード例 #1
0
ファイル: city.php プロジェクト: nemein/openpsa
 static function get_by_name($name)
 {
     if (empty($name)) {
         return false;
     }
     // Seek by strict city name first
     $qb = org_routamc_positioning_city_dba::new_query_builder();
     $qb->add_constraint('city', 'LIKE', $name);
     $qb->set_limit(1);
     $matches = $qb->execute_unchecked();
     if (count($matches) > 0) {
         return $matches[0];
     }
     // Strict name didn't match, seek by alternate names
     $qb = org_routamc_positioning_city_dba::new_query_builder();
     $qb->add_constraint('alternatenames', 'LIKE', "%{$name}%");
     // Most likely we're interested in the biggest city that matches
     $qb->add_order('population', 'DESC');
     $qb->set_limit(1);
     $matches = $qb->execute_unchecked();
     if (count($matches) > 0) {
         return $matches[0];
     }
     return false;
 }
コード例 #2
0
ファイル: city.php プロジェクト: nemein/openpsa
 /**
  * Empty default implementation, this calls won't do much.
  *
  * @param Array $location Parameters to geocode with, conforms to XEP-0080
  * @return Array containing geocoded information
  */
 function geocode($location, $options = array())
 {
     $results = array();
     $parameters = array('maxRows' => 1);
     if (!empty($options)) {
         foreach ($options as $key => $value) {
             if (isset($parameters[$key])) {
                 $parameters[$key] = $value;
             }
         }
     }
     if ($parameters['maxRows'] < 1) {
         $parameters['maxRows'] = 1;
     }
     if (!isset($location['city'])) {
         $this->error = 'POSITIONING_MISSING_ATTRIBUTES';
         return null;
     }
     $city_entry = null;
     $qb = org_routamc_positioning_city_dba::new_query_builder();
     $qb->add_constraint('city', '=', $location['city']);
     if (isset($location['country'])) {
         $qb->add_constraint('country', '=', $location['country']);
     }
     $qb->add_order('population', 'DESC');
     $qb->set_limit($parameters['maxRows']);
     $matches = $qb->execute();
     if (count($matches) < 1) {
         // Seek the city entry by alternate names via a LIKE query
         $qb = org_routamc_positioning_city_dba::new_query_builder();
         $qb->add_constraint('alternatenames', 'LIKE', "%|{$location['city']}|%");
         if (isset($location['country'])) {
             $qb->add_constraint('country', '=', $location['country']);
         }
         $qb->set_limit($parameters['maxRows']);
         $matches = $qb->execute();
         if (count($matches) < 1) {
             $this->error = 'POSITIONING_CITY_NOT_FOUND';
             return null;
         }
     }
     foreach ($matches as $city_entry) {
         $city_coordinates = array('latitude' => $city_entry->latitude, 'longitude' => $city_entry->longitude);
         $position = array();
         $position['latitude'] = $city_entry->latitude;
         $position['longitude'] = $city_entry->longitude;
         $position['distance'] = array('meters' => 0, 'bearing' => null);
         $position['city'] = $city_entry->city;
         $position['region'] = $city_entry->region;
         $position['country'] = $city_entry->country;
         $position['postalcode'] = null;
         $position['alternate_names'] = $city_entry->alternatenames;
         $position['accuracy'] = ORG_ROUTAMC_POSITIONING_ACCURACY_CITY;
         $results[] = $position;
     }
     return $results;
 }