/** * Parses the value into the coordinates and any meta data provided, such as distance. * * @since 0.6 * * @param $value String * @param $asQuery Boolean * * @return SMWDescription */ 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 ); } } }
/** * @see SMWDataValue::parseUserValue * * @since 0.6 */ protected function parseUserValue($value) { if (!is_string($value)) { throw new InvalidArgumentException('$value needs to be a string'); } $this->wikiValue = $value; $comparator = SMW_CMP_EQ; $distance = false; if ($value === '') { $this->addError(wfMessage('smw_novalues')->text()); } else { SMWDataValue::prepareValue($value, $comparator); list($coordinates, $distance) = $this->findValueParts($value); $this->tryParseAndSetDataItem($coordinates); } return array($distance, $comparator); }
protected function parseUserValueOrQuery($value, $queryMode) { if ($value === '') { $this->addError(wfMessage('smw_novalues')->text()); if ($queryMode) { return new SMWThingDescription(); } else { return; } } if ($queryMode) { $subdescriptions = array(); } elseif (is_null($this->m_contextPage)) { $semanticData = SMWContainerSemanticData::makeAnonymousContainer(); } else { $subobjectName = '_' . hash('md4', $value, false); // md4 is probably fastest of PHP's hashes $subject = new SMWDIWikiPage($this->m_contextPage->getDBkey(), $this->m_contextPage->getNamespace(), $this->m_contextPage->getInterwiki(), $subobjectName); $semanticData = new SMWContainerSemanticData($subject); } $values = preg_split('/[\\s]*;[\\s]*/u', trim($value)); $valueIndex = 0; // index in value array $propertyIndex = 0; // index in property list $empty = true; foreach ($this->getPropertyDataItems() as $diProperty) { if (!array_key_exists($valueIndex, $values)) { break; // stop if there are no values left } if ($queryMode) { // special handling for supporting query parsing $comparator = SMW_CMP_EQ; SMWDataValue::prepareValue($values[$valueIndex], $comparator); } // generating the DVs: if ($values[$valueIndex] === '' || $values[$valueIndex] == '?') { // explicit omission $valueIndex++; } else { $dataValue = SMWDataValueFactory::newPropertyObjectValue($diProperty, $values[$valueIndex]); if ($dataValue->isValid()) { // valid DV: keep if ($queryMode) { $subdescriptions[] = new SMWSomeProperty($diProperty, new SMWValueDescription($dataValue->getDataItem(), $dataValue->getProperty(), $comparator)); } else { $semanticData->addPropertyObjectValue($diProperty, $dataValue->getDataItem()); } $valueIndex++; $empty = false; } elseif (count($values) - $valueIndex == count($this->m_diProperties) - $propertyIndex) { // too many errors: keep this one to have enough slots left if (!$queryMode) { $semanticData->addPropertyObjectValue($diProperty, $dataValue->getDataItem()); } $this->addError($dataValue->getErrors()); ++$valueIndex; } } ++$propertyIndex; } if ($empty) { $this->addError(wfMessage('smw_novalues')->text()); } if ($queryMode) { switch (count($subdescriptions)) { case 0: return new SMWThingDescription(); case 1: return reset($subdescriptions); default: return new SMWConjunction($subdescriptions); } } else { $this->m_dataitem = new SMWDIContainer($semanticData); } }