1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use SMW\DataValueFactory; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Description of one data value of type Geographical Coordinates. |
7
|
|
|
* |
8
|
|
|
* @since 0.6 |
9
|
|
|
* @ingroup SemanticMaps |
10
|
|
|
* |
11
|
|
|
* @author Jeroen De Dauw |
12
|
|
|
*/ |
13
|
|
|
class SMGeoCoordsValueDescription extends SMWValueDescription { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @see SMWDescription::getQueryString |
17
|
|
|
* |
18
|
|
|
* @since 0.6 |
19
|
|
|
* |
20
|
|
|
* @param boolean $asValue |
21
|
|
|
* @return string |
22
|
|
|
*/ |
23
|
|
|
public function getQueryString( $asValue = false ) { |
24
|
|
|
if ( $this->getDataItem() !== null ) { |
25
|
|
|
$queryString = DataValueFactory::newDataItemValue( $this->getDataItem(), $this->getPropertyCompat() )->getWikiValue(); |
|
|
|
|
26
|
|
|
return $asValue ? $queryString : "[[$queryString]]"; |
27
|
|
|
} else { |
28
|
|
|
return $asValue ? '+' : ''; |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
private function getPropertyCompat() { |
33
|
|
|
return method_exists( $this, 'getProperty' ) ? $this->getProperty() : $this->m_property; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @see SMWDescription::getSQLCondition |
38
|
|
|
* |
39
|
|
|
* FIXME: store specific code should be in the store component |
40
|
|
|
* |
41
|
|
|
* @since 0.6 |
42
|
|
|
* |
43
|
|
|
* @param string $tableName |
44
|
|
|
* @param array $fieldNames |
45
|
|
|
* @param DatabaseBase $dbs |
46
|
|
|
* |
47
|
|
|
* @return boolean |
48
|
|
|
*/ |
49
|
|
|
public function getSQLCondition( $tableName, array $fieldNames, DatabaseBase $dbs ) { |
50
|
|
|
$dataItem = $this->getDataItem(); |
51
|
|
|
|
52
|
|
|
// Only execute the query when the description's type is geographical coordinates, |
53
|
|
|
// the description is valid, and the near comparator is used. |
54
|
|
|
if ( $dataItem instanceof SMWDIGeoCoord ) { |
55
|
|
|
switch ( $this->getComparator() ) { |
56
|
|
|
case SMW_CMP_EQ: $comparator = '='; break; |
57
|
|
|
case SMW_CMP_LEQ: $comparator = '<='; break; |
58
|
|
|
case SMW_CMP_GEQ: $comparator = '>='; break; |
59
|
|
|
case SMW_CMP_NEQ: $comparator = '!='; break; |
60
|
|
|
default: return false; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$lat = $dbs->addQuotes( $dataItem->getLatitude() ); |
64
|
|
|
$lon = $dbs->addQuotes( $dataItem->getLongitude() ); |
65
|
|
|
|
66
|
|
|
$conditions = []; |
67
|
|
|
|
68
|
|
|
$conditions[] = "{$tableName}.$fieldNames[1] $comparator $lat"; |
69
|
|
|
$conditions[] = "{$tableName}.$fieldNames[2] $comparator $lon"; |
70
|
|
|
|
71
|
|
|
return implode( ' AND ', $conditions ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return false; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
} |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.