00001 <?php
00002
00016 class SMGeoCoordsValue extends SMWDataValue {
00017
00018 protected $wikiValue;
00019
00029 protected function loadDataItem( SMWDataItem $dataItem ) {
00030 if ( $dataItem->getDIType() == SMWDataItem::TYPE_GEO ) {
00031 $this->m_dataitem = $dataItem;
00032
00033 global $smgQPCoodFormat, $smgQPCoodDirectional;
00034 $this->wikiValue = MapsCoordinateParser::formatCoordinates(
00035 $dataItem->getCoordinateSet(),
00036 $smgQPCoodFormat,
00037 $smgQPCoodDirectional
00038 );
00039 return true;
00040 } else {
00041 return false;
00042 }
00043 }
00044
00050 protected function parseUserValue( $value ) {
00051 $this->parseUserValueOrQuery( $value );
00052 }
00053
00064 public function getQueryDescription( $value ) {
00065 return $this->parseUserValueOrQuery( $value, true );
00066 }
00067
00078 protected function parseUserValueOrQuery( $value, $asQuery = false ) {
00079 $this->wikiValue = $value;
00080
00081 $comparator = SMW_CMP_EQ;
00082
00083 if ( $value === '' ) {
00084 $this->addError( wfMsg( 'smw_novalues' ) );
00085 } else {
00086 SMWDataValue::prepareValue( $value, $comparator );
00087
00088 $parts = explode( '(', $value );
00089
00090 $coordinates = trim( array_shift( $parts ) );
00091 $distance = count( $parts ) > 0 ? trim( array_shift( $parts ) ) : false;
00092
00093 if ( $distance !== false ) {
00094 $distance = substr( trim( $distance ), 0, -1 );
00095
00096 if ( !MapsDistanceParser::isDistance( $distance ) ) {
00097 $this->addError( wfMsgExt( 'semanticmaps-unrecognizeddistance', array( 'parsemag' ), $distance ) );
00098 $distance = false;
00099 }
00100 }
00101
00102 $parsedCoords = MapsCoordinateParser::parseCoordinates( $coordinates );
00103 if ( $parsedCoords ) {
00104 $this->m_dataitem = new SMWDIGeoCoord( $parsedCoords );
00105 } else {
00106 $this->addError( wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $coordinates, 1 ) );
00107
00108
00109
00110 $this->m_dataitem = new SMWDIGeoCoord( array( 'lat' => 0, 'lon' => 0 ) );
00111 }
00112 }
00113
00114 if ( $asQuery ) {
00115 $this->setUserValue( $value );
00116
00117 switch ( true ) {
00118 case !$this->isValid() :
00119 return new SMWThingDescription();
00120 case $distance !== false :
00121 return new SMAreaValueDescription( $this->getDataItem(), $comparator, $distance );
00122 default :
00123 return new SMGeoCoordsValueDescription( $this->getDataItem(), $comparator );
00124 }
00125 }
00126 }
00127
00133 public function getShortWikiText( $linked = null ) {
00134 if ( $this->isValid() ) {
00135 if ( $this->m_caption === false ) {
00136 global $smgQPCoodFormat, $smgQPCoodDirectional;
00137 return MapsCoordinateParser::formatCoordinates( $this->m_dataitem->getCoordinateSet(), $smgQPCoodFormat, $smgQPCoodDirectional );
00138 }
00139 else {
00140 return $this->m_caption;
00141 }
00142 }
00143 else {
00144 return $this->getErrorText();
00145 }
00146 }
00147
00153 public function getShortHTMLText( $linker = null ) {
00154 return $this->getShortWikiText( $linker );
00155 }
00156
00162 public function getLongWikiText( $linked = null ) {
00163 if ( $this->isValid() ) {
00164 SMWOutputs::requireHeadItem( SMW_HEADER_TOOLTIP );
00165
00166
00167 $coordinateSet = $this->m_dataitem->getCoordinateSet();
00168
00169 global $smgQPCoodFormat, $smgQPCoodDirectional;
00170 $text = MapsCoordinateParser::formatCoordinates( $coordinateSet, $smgQPCoodFormat, $smgQPCoodDirectional );
00171
00172 $lines = array(
00173 htmlspecialchars( wfMsgExt( 'semanticmaps-latitude', 'content', $coordinateSet['lat'] ) ),
00174 htmlspecialchars( wfMsgExt( 'semanticmaps-longitude', 'content', $coordinateSet['lon'] ) ),
00175 );
00176
00177 if ( array_key_exists( 'alt', $coordinateSet ) ) {
00178 $lines[] = htmlspecialchars ( wfMsgForContent( 'semanticmaps-altitude', 'content', $coordinateSet['alt'] ) );
00179 }
00180
00181 return '<span class="smwttinline">' . htmlspecialchars( $text ) . '<span class="smwttcontent">' .
00182 implode( '<br />', $lines ) .
00183 '</span></span>';
00184 } else {
00185 return $this->getErrorText();
00186 }
00187 }
00188
00194 public function getLongHTMLText( $linker = null ) {
00195 return $this->getLongWikiText( $linker );
00196 }
00197
00203 public function getWikiValue() {
00204 return $this->wikiValue;
00205 }
00206
00212 public function getExportData() {
00213 if ( $this->isValid() ) {
00214 global $smgQPCoodFormat, $smgQPCoodDirectional;
00215 $lit = new SMWExpLiteral(
00216 MapsCoordinateParser::formatCoordinates( $this->m_dataitem->getCoordinateSet(), $smgQPCoodFormat, $smgQPCoodDirectional ),
00217 $this,
00218 'http://www.w3.org/2001/XMLSchema#string'
00219 );
00220 return new SMWExpData( $lit );
00221 } else {
00222 return null;
00223 }
00224 }
00225
00239 protected function getServiceLinkParams() {
00240 $coordinateSet = $this->m_dataitem->getCoordinateSet();
00241 return array(
00242 MapsCoordinateParser::formatCoordinates( $coordinateSet, 'float', false ),
00243 MapsCoordinateParser::formatCoordinates( $coordinateSet, 'dms', true ),
00244 $coordinateSet['lat'],
00245 $coordinateSet['lon']
00246 );
00247 }
00248
00249 }