Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php |
— | — | @@ -54,14 +54,38 @@ |
55 | 55 | * @see SMWDataValue::parseUserValue |
56 | 56 | */ |
57 | 57 | protected function parseUserValue( $value ) { |
| 58 | + $this->parseUserValueOrQuery( $value ); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Overwrite SMWDataValue::getQueryDescription() to be able to process |
| 63 | + * comparators between all values. |
| 64 | + * |
| 65 | + * @param string $value |
| 66 | + * |
| 67 | + * @return SMWDescription |
| 68 | + */ |
| 69 | + public function getQueryDescription( $value ) { |
| 70 | + return $this->parseUserValueOrQuery( $value, true ); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Parses the value into the coordinates and any meta data provided, such as distance. |
| 75 | + */ |
| 76 | + protected function parseUserValueOrQuery( $value, $asQuery = false ) { |
58 | 77 | if ( $value == '' ) { |
59 | 78 | $this->addError( wfMsg( 'smw_novalues' ) ); |
60 | 79 | } else { |
| 80 | + // TODO: parse the parts here |
| 81 | + //$parts = preg_split( '', $value ); |
| 82 | + $distance = 5; |
| 83 | + $hasDistance = false; |
| 84 | + |
61 | 85 | $coordinates = MapsCoordinateParser::parseCoordinates( $value ); |
62 | 86 | if ( $coordinates ) { |
63 | 87 | $this->mCoordinateSet = $coordinates; |
64 | 88 | |
65 | | - if ( $this->m_caption === false ) { |
| 89 | + if ( $this->m_caption === false && !$asQuery ) { |
66 | 90 | global $smgQPCoodFormat, $smgQPCoodDirectional; |
67 | 91 | $this->m_caption = MapsCoordinateParser::formatCoordinates( $coordinates, $smgQPCoodFormat, $smgQPCoodDirectional ); |
68 | 92 | } |
— | — | @@ -69,16 +93,22 @@ |
70 | 94 | $this->addError( wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $value, 1 ) ); |
71 | 95 | } |
72 | 96 | } |
73 | | - } |
74 | 97 | |
75 | | - /** |
76 | | - * Overwrite SMWDataValue::getQueryDescription() to be able to process |
77 | | - * comparators between all values. |
78 | | - * |
79 | | - * @return SMWDescription |
80 | | - */ |
81 | | - public function getQueryDescription( $value ) { |
82 | | - return parent::getQueryDescription( $value ); |
| 98 | + if ( $asQuery ) { |
| 99 | + $this->setUserValue( $value ); |
| 100 | + |
| 101 | + switch ( true ) { |
| 102 | + case !$this->isValid() : |
| 103 | + return new SMWThingDescription(); |
| 104 | + break; |
| 105 | + case $hasDistance : |
| 106 | + return new SMAreaValueDescription( $this, $distance ); |
| 107 | + break; |
| 108 | + default : |
| 109 | + return new SMGeoCoordsValueDescription( $this ); |
| 110 | + break; |
| 111 | + } |
| 112 | + } |
83 | 113 | } |
84 | 114 | |
85 | 115 | /** |
— | — | @@ -95,6 +125,7 @@ |
96 | 126 | $smgQPCoodFormat, |
97 | 127 | $smgQPCoodDirectional |
98 | 128 | ); |
| 129 | + |
99 | 130 | $this->mWikivalue = $this->m_caption; |
100 | 131 | } |
101 | 132 | |
— | — | @@ -136,7 +167,6 @@ |
137 | 168 | * @see SMWDataValue::getShortHTMLText |
138 | 169 | */ |
139 | 170 | public function getShortHTMLText( $linker = null ) { |
140 | | - // TODO: parse to HTML? |
141 | 171 | return $this->getShortWikiText( $linker ); |
142 | 172 | } |
143 | 173 | |
— | — | @@ -156,7 +186,6 @@ |
157 | 187 | * @see SMWDataValue::getLongHTMLText |
158 | 188 | */ |
159 | 189 | public function getLongHTMLText( $linker = null ) { |
160 | | - // TODO: parse to HTML? |
161 | 190 | return $this->getLongWikiText( $linker ); |
162 | 191 | } |
163 | 192 | |
— | — | @@ -194,5 +223,12 @@ |
195 | 224 | protected function getServiceLinkParams() { |
196 | 225 | return array( ); // TODO |
197 | 226 | } |
| 227 | + |
| 228 | + /** |
| 229 | + * @return array |
| 230 | + */ |
| 231 | + public function getCoordinateSet() { |
| 232 | + return $this->mCoordinateSet; |
| 233 | + } |
198 | 234 | |
199 | 235 | } |
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php |
— | — | @@ -8,7 +8,6 @@ |
9 | 9 | * @ingroup SemanticMaps |
10 | 10 | * |
11 | 11 | * @author Jeroen De Dauw |
12 | | - * @author Markus Krötzsch |
13 | 12 | */ |
14 | 13 | |
15 | 14 | // Registration of the GoeCoords class. |
— | — | @@ -18,56 +17,21 @@ |
19 | 18 | $wgAutoloadClasses['SMGeoCoordsValue'] = dirname( __FILE__ ) . '/SM_GeoCoordsValue.php'; |
20 | 19 | |
21 | 20 | // Registration of the Geographical Coordinate value description class. |
| 21 | +$wgAutoloadClasses['SMGeoCoordsValueDescription'] = dirname( __FILE__ ) . '/SM_GeoCoordsValueDescription.php'; |
| 22 | + |
| 23 | +// Registration of the Geographical Coordinate are description class. |
22 | 24 | $wgAutoloadClasses['SMAreaValueDescription'] = dirname( __FILE__ ) . '/SM_AreaValueDescription.php'; |
23 | 25 | |
24 | 26 | // Hook for initializing the Geographical Coordinate type. |
25 | 27 | $wgHooks['smwInitDatatypes'][] = 'SMGeoCoordsValue::initGeoCoordsType'; |
26 | 28 | |
| 29 | +// Hook for defining a table to store geographical coordinates in. |
27 | 30 | $wgHooks['SMWPropertyTables'][] = 'SMGeoCoordsValue::initGeoCoordsTable'; |
28 | 31 | |
29 | 32 | // Hook for initializing the Geographical Proximity query support. |
30 | | -$wgHooks['smwGetSQLConditionForValue'][] = 'SMGeoCoords::getGeoProximitySQLCondition'; |
| 33 | +$wgHooks['smwGetSQLConditionForValue'][] = 'SMAreaValueDescription::getSQLCondition'; |
31 | 34 | |
32 | | -define( 'SM_CMP_NEAR', 101 ); // Define the near comparator for proximity queries. |
| 35 | +// Hook for initializing the Geographical Proximity query support. |
| 36 | +$wgHooks['smwGetSQLConditionForValue'][] = 'SMGeoCoordsValueDescription::getSQLCondition'; |
33 | 37 | |
34 | | -final class SMGeoCoords { |
35 | | - |
36 | | - /** |
37 | | - * Custom SQL query extension for matching geographic coordinates. |
38 | | - * |
39 | | - * @param string $whereSQL The SQL where condition to expand. |
40 | | - * @param SMAreaValueDescription $description The description of center coordinate. |
41 | | - * @param string $tablename |
42 | | - * @param string $fieldname |
43 | | - * @param DatabaseBase $dbs |
44 | | - * |
45 | | - * @return true |
46 | | - */ |
47 | | - public static function getGeoProximitySQLCondition( &$whereSQL, SMAreaValueDescription $description, $tablename, $fieldname, DatabaseBase $dbs ) { |
48 | | - $dataValue = $description->getDatavalue(); |
49 | | - |
50 | | - // Only execute the query when the description's type is geographical coordinates, |
51 | | - // the description is valid, and the near comparator is used. |
52 | | - if ( ( $dataValue->getTypeID() != '_geo' ) |
53 | | - || ( !$dataValue->isValid() ) |
54 | | - || ( $description->getComparator() != SM_CMP_NEAR ) |
55 | | - ) return true; |
56 | | - |
57 | | - $boundingBox = $description->getBounds(); |
58 | | - |
59 | | - $north = $dbs->addQuotes( $boundingBox['north'] ); |
60 | | - $east = $dbs->addQuotes( $boundingBox['east'] ); |
61 | | - $south = $dbs->addQuotes( $boundingBox['south'] ); |
62 | | - $west = $dbs->addQuotes( $boundingBox['west'] ); |
63 | | - |
64 | | - // TODO: The field names are hardcoded in, since SMW offers no support for selection based on multiple fields. |
65 | | - // Ideally SMW's setup should be changed to allow for this. Now the query can break when other extensions |
66 | | - // add their own semantic tables with similar signatures. |
67 | | - $whereSQL .= "{$tablename}.lat < $north && {$tablename}.lat > $south && {$tablename}.lon < $east && {$tablename}.lon > $west"; |
68 | | - |
69 | | - return true; |
70 | | - } |
71 | | - |
72 | | - |
73 | | -} |
74 | | - |
| 38 | +// define( 'SM_CMP_NEAR', 101 ); // Define the near comparator for proximity queries. |
\ No newline at end of file |
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValueDescription.php |
— | — | @@ -0,0 +1,79 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File holding the SMGeoCoordsValueDescription class. |
| 6 | + * |
| 7 | + * @file SM_GeoCoordsValueDescription.php |
| 8 | + * @ingroup SemanticMaps |
| 9 | + * |
| 10 | + * @author Jeroen De Dauw |
| 11 | + */ |
| 12 | + |
| 13 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 14 | + die( 'Not an entry point.' ); |
| 15 | +} |
| 16 | + |
| 17 | +/** |
| 18 | + * Description of one data value of type Goegraphical Coordinates. |
| 19 | + * |
| 20 | + * @author Jeroen De Dauw |
| 21 | + * |
| 22 | + * @ingroup SemanticMaps |
| 23 | + */ |
| 24 | +class SMGeoCoordsValueDescription extends SMWValueDescription { |
| 25 | + |
| 26 | + /** |
| 27 | + * TODO: re-add the coparator parameter once support for this is implemented in the query hook. |
| 28 | + * |
| 29 | + * @param SMGeoCoordsValue $dataValue |
| 30 | + */ |
| 31 | + public function __construct( SMGeoCoordsValue $dataValue ) { |
| 32 | + parent::__construct( $dataValue ); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @see SMWDescription:getQueryString |
| 37 | + * |
| 38 | + * @param Boolean $asvalue |
| 39 | + */ |
| 40 | + public function getQueryString( $asValue = false ) { |
| 41 | + if ( $this->m_datavalue !== null ) { |
| 42 | + $queryString = $this->m_datavalue->getWikiValue(); |
| 43 | + return $asValue ? $queryString : "[[$queryString]]"; |
| 44 | + } else { |
| 45 | + return $asValue ? '+' : ''; |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Custom SQL query extension for matching geographic coordinates. |
| 51 | + * |
| 52 | + * @param string $whereSQL The SQL where condition to expand. |
| 53 | + * @param SMWDescription $description |
| 54 | + * @param string $tablename |
| 55 | + * @param string $fieldname |
| 56 | + * @param DatabaseBase $dbs |
| 57 | + * |
| 58 | + * @return true |
| 59 | + */ |
| 60 | + public static function getSQLCondition( &$whereSQL, SMWDescription $description, $tablename, $fieldname, DatabaseBase $dbs ) { |
| 61 | + $dataValue = $description->getDatavalue(); |
| 62 | + |
| 63 | + // Only execute the query when the description's type is geographical coordinates, |
| 64 | + // the description is valid, and the near comparator is used. |
| 65 | + if ( $dataValue->getTypeID() != '_geo' |
| 66 | + || !$dataValue->isValid() |
| 67 | + || !$description instanceof SMGeoCoordsValueDescription |
| 68 | + ) return true; |
| 69 | + |
| 70 | + $coordinates = $dataValue->getCoordinateSet(); |
| 71 | + |
| 72 | + // TODO: The field names are hardcoded in, since SMW offers no support for selection based on multiple fields. |
| 73 | + // Ideally SMW's setup should be changed to allow for this. Now the query can break when other extensions |
| 74 | + // add their own semantic tables with similar signatures. |
| 75 | + $whereSQL .= "{$tablename}.lat = {$coordinates['lat']} && {$tablename}.lon = {$coordinates['lon']}"; |
| 76 | + |
| 77 | + return true; |
| 78 | + } |
| 79 | + |
| 80 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValueDescription.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 81 | + native |
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php |
— | — | @@ -14,7 +14,9 @@ |
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
18 | | - * Description of one data value of type Goegraphical Areas. |
| 18 | + * Description of a geographical area defined by a coordinates set and a distance to the bounds. |
| 19 | + * The bounds are a 'rectangle' (but bend due to the earhs curvature), as the resulting query |
| 20 | + * would otherwise be to resource intensive. |
19 | 21 | * |
20 | 22 | * @author Jeroen De Dauw |
21 | 23 | * |
— | — | @@ -23,8 +25,8 @@ |
24 | 26 | class SMAreaValueDescription extends SMWValueDescription { |
25 | 27 | protected $mBounds = false; |
26 | 28 | |
27 | | - public function __construct( SMGeoCoordsValue $dataValue, $radius, $comparator = SMW_CMP_EQ ) { |
28 | | - parent::__construct( $dataValue, $comparator ); |
| 29 | + public function __construct( SMGeoCoordsValue $dataValue, $radius ) { |
| 30 | + parent::__construct( $dataValue ); |
29 | 31 | |
30 | 32 | // If the MapsGeoFunctions class is not loaded, we can not create the bounding box, so don't add any conditions. |
31 | 33 | if ( self::geoFunctionsAreAvailable() ) { |
— | — | @@ -39,7 +41,7 @@ |
40 | 42 | ); |
41 | 43 | } |
42 | 44 | } |
43 | | - |
| 45 | + |
44 | 46 | /** |
45 | 47 | * @see SMWDescription:getQueryString |
46 | 48 | * |
— | — | @@ -75,7 +77,7 @@ |
76 | 78 | */ |
77 | 79 | public function getBounds() { |
78 | 80 | return $this->mBounds; |
79 | | - } |
| 81 | + } |
80 | 82 | |
81 | 83 | /** |
82 | 84 | * Returns the lat and lon limits of a bounding box around a circle defined by the provided parameters. |
— | — | @@ -106,4 +108,40 @@ |
107 | 109 | global $wgAutoloadClasses; |
108 | 110 | return array_key_exists( 'MapsGeoFunctions', $wgAutoloadClasses ); |
109 | 111 | } |
| 112 | + |
| 113 | + /** |
| 114 | + * Custom SQL query extension for matching geographic coordinates in an area. |
| 115 | + * |
| 116 | + * @param string $whereSQL The SQL where condition to expand. |
| 117 | + * @param SMWDescription $description |
| 118 | + * @param string $tablename |
| 119 | + * @param string $fieldname |
| 120 | + * @param DatabaseBase $dbs |
| 121 | + * |
| 122 | + * @return true |
| 123 | + */ |
| 124 | + public static function getSQLCondition( &$whereSQL, SMWDescription $description, $tablename, $fieldname, DatabaseBase $dbs ) { |
| 125 | + $dataValue = $description->getDatavalue(); |
| 126 | + |
| 127 | + // Only execute the query when the description's type is geographical coordinates, |
| 128 | + // the description is valid, and the near comparator is used. |
| 129 | + if ( $dataValue->getTypeID() != '_geo' |
| 130 | + || !$dataValue->isValid() |
| 131 | + || !$description instanceof SMAreaValueDescription |
| 132 | + ) return true; |
| 133 | + |
| 134 | + $boundingBox = $description->getBounds(); |
| 135 | + |
| 136 | + $north = $dbs->addQuotes( $boundingBox['north'] ); |
| 137 | + $east = $dbs->addQuotes( $boundingBox['east'] ); |
| 138 | + $south = $dbs->addQuotes( $boundingBox['south'] ); |
| 139 | + $west = $dbs->addQuotes( $boundingBox['west'] ); |
| 140 | + |
| 141 | + // TODO: The field names are hardcoded in, since SMW offers no support for selection based on multiple fields. |
| 142 | + // Ideally SMW's setup should be changed to allow for this. Now the query can break when other extensions |
| 143 | + // add their own semantic tables with similar signatures. |
| 144 | + $whereSQL .= "{$tablename}.lat < $north && {$tablename}.lat > $south && {$tablename}.lon < $east && {$tablename}.lon > $west"; |
| 145 | + |
| 146 | + return true; |
| 147 | + } |
110 | 148 | } |
\ No newline at end of file |