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