/**
  * Tests MapsDistanceParser::isDistance()
  */
 public function testIsDistance()
 {
     foreach (self::$fakeDistances as $fakeDistance) {
         $this->assertFalse(MapsDistanceParser::isDistance($fakeDistance), "'{$fakeDistance}' should not be recognized:");
     }
     foreach (self::$distances as $distance) {
         $this->assertTrue(MapsDistanceParser::isDistance($distance), "'{$distance}' was not be recognized:");
     }
 }
예제 #2
0
 /**
  * Parses the value into the coordinates and any meta data provided, such as distance.
  * 
  * @since 0.6
  * 
  * @param $value String
  * @param $asQuery Boolean
  */
 protected function parseUserValueOrQuery($value, $asQuery = false)
 {
     $this->wikiValue = $value;
     $comparator = SMW_CMP_EQ;
     if ($value === '') {
         $this->addError(wfMsg('smw_novalues'));
     } else {
         SMWDataValue::prepareValue($value, $comparator);
         $parts = explode('(', $value);
         $coordinates = trim(array_shift($parts));
         $distance = count($parts) > 0 ? trim(array_shift($parts)) : false;
         if ($distance !== false) {
             $distance = substr(trim($distance), 0, -1);
             if (!MapsDistanceParser::isDistance($distance)) {
                 $this->addError(wfMsgExt('semanticmaps-unrecognizeddistance', array('parsemag'), $distance));
                 $distance = false;
             }
         }
         $parsedCoords = MapsCoordinateParser::parseCoordinates($coordinates);
         if ($parsedCoords) {
             $this->m_dataitem = new SMWDIGeoCoord($parsedCoords);
         } else {
             $this->addError(wfMsgExt('maps_unrecognized_coords', array('parsemag'), $coordinates, 1));
             // Make sure this is always set
             // TODO: Why is this needed?!
             $this->m_dataitem = new SMWDIGeoCoord(array('lat' => 0, 'lon' => 0));
         }
     }
     if ($asQuery) {
         $this->setUserValue($value);
         switch (true) {
             case !$this->isValid():
                 return new SMWThingDescription();
             case $distance !== false:
                 return new SMAreaValueDescription($this->getDataItem(), $comparator, $distance);
             default:
                 return new SMGeoCoordsValueDescription($this->getDataItem(), $comparator);
         }
     }
 }
예제 #3
0
 protected function parserDistance($distance)
 {
     if ($distance !== false) {
         $distance = substr(trim($distance), 0, -1);
         if (!MapsDistanceParser::isDistance($distance)) {
             $this->addError(wfMessage('semanticmaps-unrecognizeddistance', $distance)->text());
             $distance = false;
         }
     }
     return $distance;
 }
예제 #4
0
 /**
  * @see ItemParameterCriterion::validate
  */
 protected function doValidation($value, Parameter $parameter, array $parameters)
 {
     return MapsDistanceParser::isDistance($value);
 }