Exemple #1
0
 protected function compareCity(Address $a, Address $b, $query)
 {
     if (!$a->getLocality() && !$b->getLocality()) {
         return 0;
     } elseif ($a->getLocality() && !$b->getLocality()) {
         return -1;
     } elseif ($b->getLocality() && !$a->getLocality()) {
         return 1;
     }
     if (stripos($query, $a->getLocality()) !== FALSE && stripos($query, $b->getLocality()) === FALSE) {
         return -1;
     } elseif (stripos($query, $b->getLocality()) !== FALSE && stripos($query, $a->getLocality()) === FALSE) {
         return 1;
     }
     return 0;
 }
 public static function format(Address $address, $options)
 {
     $data = array_filter(['country' => $address->getCountry()->getName(), 'city' => $address->getLocality(), 'district' => $address->getSubLocality(), 'postalCode' => $address->getPostalCode(), 'streetName' => $address->getStreetName(), 'streetNumber' => $address->getStreetNumber()]);
     if ($options['format'] === self::FORMAT_REVERSED) {
         $data = array_reverse($data);
     }
     if ($options['type'] === self::TYPE_SHORT) {
         unset($data['country']);
     }
     return implode(', ', $data);
 }
 /**
  * Transform an `Address` instance into a string representation.
  *
  * @param Address $address
  * @param string  $format
  *
  * @return string
  */
 public function format(Address $address, $format)
 {
     $replace = [self::STREET_NUMBER => $address->getStreetNumber(), self::STREET_NAME => $address->getStreetName(), self::LOCALITY => $address->getLocality(), self::POSTAL_CODE => $address->getPostalCode(), self::SUB_LOCALITY => $address->getSubLocality(), self::COUNTRY => $address->getCountry()->getName(), self::COUNTRY_CODE => $address->getCountry()->getCode(), self::TIMEZONE => $address->getTimezone()];
     for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; $level++) {
         $replace[self::ADMIN_LEVEL . $level] = null;
         $replace[self::ADMIN_LEVEL_CODE . $level] = null;
     }
     foreach ($address->getAdminLevels() as $level => $adminLevel) {
         $replace[self::ADMIN_LEVEL . $level] = $adminLevel->getName();
         $replace[self::ADMIN_LEVEL_CODE . $level] = $adminLevel->getCode();
     }
     return strtr($format, $replace);
 }
Exemple #4
0
 public function insertUserInformation($ipAddress, $userAgentString, $sapiName, GeocoderResult $geocoderResult = null)
 {
     $userAgent = new UserAgent();
     $userAgent->setUserAgent($userAgentString);
     $browser = $userAgent->browser();
     $platform = $userAgent->platform();
     $data = ['ip_address' => $ipAddress, 'sapi_name' => substr($sapiName, 0, 32), 'user_agent' => substr($userAgentString, 0, 255), 'user_agent_browser' => substr($browser, 0, 32), 'user_agent_device' => substr($userAgent->device(), 0, 32), 'user_agent_browser_version' => substr($userAgent->version($browser), 0, 32), 'user_agent_platform_version' => substr($userAgent->version($platform), 0, 32), 'user_agent_platform' => substr($platform, 0, 32), 'user_agent_robot' => substr($userAgent->robot(), 0, 32)];
     if ($geocoderResult) {
         $region = $geocoderResult->getAdminLevels()->first();
         $data['geo_city'] = substr($geocoderResult->getLocality(), 0, 32);
         $data['geo_region'] = $region ? substr($region->getCode(), 0, 32) : null;
         $data['geo_country'] = substr($geocoderResult->getCountry(), 0, 32);
         $data['geo_country_code'] = substr($geocoderResult->getCountryCode(), 0, 6);
         $data['geo_latitude'] = substr($geocoderResult->getLatitude(), 0, 32);
         $data['geo_longitude'] = substr($geocoderResult->getLongitude(), 0, 32);
     }
     $this->getAdapter()->insert('dewdrop_activity_log_user_information', $data);
     return $this->getAdapter()->lastInsertId();
 }
Exemple #5
0
 /**
  * @param Address $address
  * @param string $geocoderQuery
  * @return boolean
  */
 private function queryContainsCity(Address $address, $geocoderQuery)
 {
     return Strings::match($geocoderQuery, '~(\\s|-|,|^)' . preg_quote($address->getLocality()) . '(\\s|-|,|\\z)~');
 }
Exemple #6
0
 /**
  * Set locality
  *
  * @param \Geocoder\Model\Address $address
  * @return Geo
  */
 private function setLocality($address)
 {
     $this->locality = $address->getLocality();
     return $this;
 }
Exemple #7
0
 /**
  * Expects certain address types to be present in the given address.
  *
  * @param \Geocoder\Model\Address $address
  * @return bool
  */
 public function isExpectedType(Address $address)
 {
     $expected = $this->_config['expect'];
     if (!$expected) {
         return true;
     }
     $adminLevels = $address->getAdminLevels();
     $map = [static::TYPE_AAL1 => 1, static::TYPE_AAL2 => 2, static::TYPE_AAL3 => 3, static::TYPE_AAL4 => 4, static::TYPE_AAL5 => 5];
     foreach ($expected as $expect) {
         switch ($expect) {
             case static::TYPE_COUNTRY:
                 if ($address->getCountry() !== null) {
                     return true;
                 }
                 break;
             case static::TYPE_AAL1:
             case static::TYPE_AAL2:
             case static::TYPE_AAL3:
             case static::TYPE_AAL4:
             case static::TYPE_AAL5:
                 if ($adminLevels->has($map[$expect])) {
                     return true;
                 }
                 break;
             case static::TYPE_LOC:
                 if ($address->getLocality() !== null) {
                     return true;
                 }
                 break;
             case static::TYPE_SUBLOC:
                 if ($address->getSubLocality() !== null) {
                     return true;
                 }
                 break;
             case static::TYPE_POSTAL:
                 if ($address->getPostalCode() !== null) {
                     return true;
                 }
                 break;
             case static::TYPE_ADDRESS:
                 if ($address->getStreetName() !== null) {
                     return true;
                 }
                 break;
             case static::TYPE_NUMBER:
                 if ($address->getStreetNumber() !== null) {
                     return true;
                 }
                 break;
         }
     }
     return false;
 }