Пример #1
0
 /**
  * Returns true if the parameter value contains atleast 1 comma
  * meaning that there are atleast two enpoints on which to draw a line.
  *
  * @param string $value
  * @param Parameter $parameter
  * @param array $parameters
  *
  * @since 0.4
  *
  * @return boolean
  */
 protected function doValidation($value, Parameter $parameter, array $parameters)
 {
     //fetch locations
     $value = explode($this->metaDataSeparator, $value);
     $value = $value[0];
     //need atleast two points to create a line
     $valid = strpos($value, ':') != false;
     if (!$valid) {
         return $valid;
     }
     //setup geocode deps
     $canGeoCode = MapsGeocoders::canGeocode();
     if ($canGeoCode) {
         $geoService = $parameter->hasDependency('geoservice') ? $parameters['geoservice']->getValue() : '';
         $mappingService = $parameter->hasDependency('mappingservice') ? $parameters['mappingservice']->getValue() : false;
     }
     //strip away line parameters and check for valid locations
     $parts = explode(':', $value);
     foreach ($parts as $part) {
         $toIndex = strpos($part, $this->metaDataSeparator);
         if ($toIndex != false) {
             $part = substr($part, 0, $toIndex);
         }
         if ($canGeoCode) {
             $valid = MapsGeocoders::isLocation($part, $geoService, $mappingService);
         } else {
             $valid = MapsCoordinateParser::areCoordinates($part);
         }
         if (!$valid) {
             break;
         }
     }
     return $valid;
 }
 /**
  * Tests MapsCoordinateParser::areCoordinates()
  */
 public function testAreCoordinates()
 {
     foreach (self::$coordinates as $coordsOfType) {
         foreach ($coordsOfType as $coord) {
             $this->assertTrue(MapsCoordinateParser::areCoordinates($coord), "{$coord} not recognized as coordinate.");
         }
     }
     foreach (self::$fakeCoordinates as $coord) {
         $this->assertFalse(MapsCoordinateParser::areCoordinates($coord), "{$coord} was recognized as coordinate.");
     }
 }
Пример #3
0
 /**
  *
  * @param string $value
  *
  * @since 2.0
  *
  * @return boolean
  */
 public function doValidation($value)
 {
     //fetch locations
     $value = explode($this->metaDataSeparator, $value);
     $value = $value[0];
     //strip away line parameters and check for valid locations
     $parts = explode(':', $value);
     if (count($parts) != 2) {
         return false;
     }
     return $parts[1] > 0 ? MapsCoordinateParser::areCoordinates($parts[0]) : false;
 }
Пример #4
0
 /**
  * @see GeoValidator::doValidation
  */
 protected function doValidation($value)
 {
     //Empty string. e.g no coordinates given
     if (empty($value)) {
         return true;
     }
     if ($this->metaDataSeparator !== false) {
         $parts = explode($this->metaDataSeparator, $value);
         $value = $parts[0];
     }
     return MapsCoordinateParser::areCoordinates($value);
 }
 /**
  * @see ItemParameterCriterion::validate
  */
 protected function doValidation($value, Parameter $parameter, array $parameters)
 {
     if ($this->metaDataSeparator !== false) {
         $parts = explode($this->metaDataSeparator, $value);
         $value = $parts[0];
     }
     if (MapsGeocoders::canGeocode()) {
         $geoService = $parameter->hasDependency('geoservice') ? $parameters['geoservice']->getValue() : '';
         $mappingService = $parameter->hasDependency('mappingservice') ? $parameters['mappingservice']->getValue() : false;
         return MapsGeocoders::isLocation($value, $geoService, $mappingService);
     } else {
         return MapsCoordinateParser::areCoordinates($value);
     }
 }
Пример #6
0
 /**
  * @see GeoValidator::doValidation
  */
 public function doValidation($value)
 {
     //fetch locations
     $value = explode($this->metaDataSeparator, $value);
     $value = $value[0];
     $parts = explode(':', $value);
     if (count($parts) != 2) {
         return false;
     }
     foreach ($parts as $part) {
         $valid = MapsCoordinateParser::areCoordinates($part);
         if (!$valid) {
             break;
         }
     }
     return $valid;
 }
Пример #7
0
 /**
  * @see GeoValidator::doValidation
  */
 public function doValidation($value)
 {
     //fetch locations
     $value = explode($this->metaDataSeparator, $value);
     $value = $value[0];
     //need atleast two points to create a line
     $valid = strpos($value, ':') != false;
     if (!$valid) {
         return $valid;
     }
     //strip away line parameters and check for valid locations
     $parts = explode(':', $value);
     foreach ($parts as $part) {
         $toIndex = strpos($part, $this->metaDataSeparator);
         if ($toIndex != false) {
             $part = substr($part, 0, $toIndex);
         }
         $valid = MapsCoordinateParser::areCoordinates($part);
         if (!$valid) {
             break;
         }
     }
     return $valid;
 }
 /**
  * This function first determines wether the provided string is a pair or coordinates
  * or an address. If it's the later, an attempt to geocode will be made. The function will
  * return the coordinates or false, in case a geocoding attempt was made but failed. 
  * 
  * @since 0.7
  * 
  * @param string $coordsOrAddress
  * @param string $geoservice
  * @param string|false $mappingService
  * @param boolean $checkForCoords
  *
  * @return array or false
  */
 public static function attemptToGeocode($coordsOrAddress, $geoservice = '', $mappingService = false, $checkForCoords = true)
 {
     if ($checkForCoords) {
         if (MapsCoordinateParser::areCoordinates($coordsOrAddress)) {
             return MapsCoordinateParser::parseCoordinates($coordsOrAddress);
         } else {
             return self::geocode($coordsOrAddress, $geoservice, $mappingService);
         }
     } else {
         return self::geocode($coordsOrAddress, $geoservice, $mappingService);
     }
 }
Пример #9
0
 /**
  * Constructor.
  * 
  * @param mixed $coordsOrAddress string or array with lat and lon
  * @param integer $format
  * @param boolean $directional
  * @param string $separator
  * 
  * @since 0.7.1
  */
 public function __construct($coordsOrAddress = null, $format = Maps_COORDS_FLOAT, $directional = false, $separator = ',')
 {
     $this->format = $format;
     $this->directional = $directional;
     $this->separator = $separator;
     if (!is_null($coordsOrAddress)) {
         if (MapsCoordinateParser::areCoordinates($coordsOrAddress)) {
             $this->setCoordinates($coordsOrAddress);
         } else {
             $this->setAddress($coordsOrAddress);
         }
     }
 }