1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maps\SemanticMW\ValueDescriptions; |
4
|
|
|
|
5
|
|
|
use DatabaseBase; |
6
|
|
|
use SMW\DataValueFactory; |
7
|
|
|
use SMW\Query\Language\ValueDescription; |
8
|
|
|
use SMWDIGeoCoord; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Description of one data value of type Geographical Coordinates. |
12
|
|
|
* |
13
|
|
|
* @author Jeroen De Dauw |
14
|
|
|
*/ |
15
|
|
|
class CoordinateDescription extends ValueDescription { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @see SMWDescription::getQueryString |
19
|
|
|
* |
20
|
|
|
* @since 0.6 |
21
|
|
|
* |
22
|
|
|
* @param boolean $asValue |
23
|
|
|
* |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
public function getQueryString( $asValue = false ) { |
27
|
|
|
$queryString = DataValueFactory::newDataItemValue( $this->getDataItem(), $this->getProperty() )->getWikiValue(); |
28
|
|
|
return $asValue ? $queryString : "[[$queryString]]"; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @see SMWDescription::getSQLCondition |
33
|
|
|
* |
34
|
|
|
* FIXME: store specific code should be in the store component |
35
|
|
|
* |
36
|
|
|
* @since 0.6 |
37
|
|
|
* |
38
|
|
|
* @param string $tableName |
39
|
|
|
* @param array $fieldNames |
40
|
|
|
* @param DatabaseBase $dbs |
41
|
|
|
* |
42
|
|
|
* @return string|false |
43
|
|
|
*/ |
44
|
|
|
public function getSQLCondition( $tableName, array $fieldNames, DatabaseBase $dbs ) { |
45
|
|
|
$dataItem = $this->getDataItem(); |
46
|
|
|
|
47
|
|
|
// Only execute the query when the description's type is geographical coordinates, |
48
|
|
|
// the description is valid, and the near comparator is used. |
49
|
|
|
if ( $dataItem instanceof SMWDIGeoCoord ) { |
|
|
|
|
50
|
|
|
switch ( $this->getComparator() ) { |
51
|
|
|
case SMW_CMP_EQ: |
52
|
|
|
$comparator = '='; |
53
|
|
|
break; |
54
|
|
|
case SMW_CMP_LEQ: |
55
|
|
|
$comparator = '<='; |
56
|
|
|
break; |
57
|
|
|
case SMW_CMP_GEQ: |
58
|
|
|
$comparator = '>='; |
59
|
|
|
break; |
60
|
|
|
case SMW_CMP_NEQ: |
61
|
|
|
$comparator = '!='; |
62
|
|
|
break; |
63
|
|
|
default: |
64
|
|
|
return false; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$lat = $dbs->addQuotes( $dataItem->getLatitude() ); |
68
|
|
|
$lon = $dbs->addQuotes( $dataItem->getLongitude() ); |
69
|
|
|
|
70
|
|
|
$conditions = []; |
71
|
|
|
|
72
|
|
|
$conditions[] = "{$tableName}.$fieldNames[1] $comparator $lat"; |
73
|
|
|
$conditions[] = "{$tableName}.$fieldNames[2] $comparator $lon"; |
74
|
|
|
|
75
|
|
|
return implode( ' AND ', $conditions ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return false; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
} |