1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maps\Semantic\DataValues; |
4
|
|
|
|
5
|
|
|
use PolygonHandler; |
6
|
|
|
use SMWDataItem; |
7
|
|
|
use SMWDataValue; |
8
|
|
|
use SMWDIBlob; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Implementation of datavalues that are geographic shapes. |
12
|
|
|
* |
13
|
|
|
* @author Nischay Nahata |
14
|
|
|
*/ |
15
|
|
|
class GeoPolygonValue extends SMWDataValue { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @see SMWDataValue::setDataItem() |
19
|
|
|
* |
20
|
|
|
* @param $dataitem SMWDataItem |
21
|
|
|
* |
22
|
|
|
* @return boolean |
23
|
|
|
*/ |
24
|
|
|
protected function loadDataItem( SMWDataItem $dataItem ) { |
25
|
|
|
if ( $dataItem instanceof SMWDIBlob ) { |
|
|
|
|
26
|
|
|
$this->m_dataitem = $dataItem; |
27
|
|
|
return true; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return false; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* NOTE: Do param validation. |
35
|
|
|
* TODO: Stores as a Blob, use better data structure |
36
|
|
|
* @see SMWDataValue::parseUserValue |
37
|
|
|
* |
38
|
|
|
* @since 2.0 |
39
|
|
|
*/ |
40
|
|
|
protected function parseUserValue( $value ) { |
41
|
|
|
if ( $value === '' ) { |
42
|
|
|
$this->addError( wfMessage( 'smw_emptystring' )->inContentLanguage()->text() ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
foreach( ( new PolygonHandler( $value ) )->getValidationErrors() as $errMsg ) { |
46
|
|
|
$this->addError( $errMsg ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$this->m_dataitem = new SMWDIBlob( $value, $this->m_typeid ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @see SMWDataValue::getShortWikiText |
54
|
|
|
* |
55
|
|
|
* @since 2.0 |
56
|
|
|
*/ |
57
|
|
|
public function getShortWikiText( $linked = null ) { |
58
|
|
|
if ( $this->isValid() ) { |
59
|
|
|
return $this->m_dataitem->getString(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $this->getErrorText(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @see SMWDataValue::getShortHTMLText |
67
|
|
|
* |
68
|
|
|
* @since 2.0 |
69
|
|
|
*/ |
70
|
|
|
public function getShortHTMLText( $linker = null ) { |
71
|
|
|
return $this->getShortWikiText( $linker ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @see SMWDataValue::getLongWikiText |
76
|
|
|
* |
77
|
|
|
* @since 2.0 |
78
|
|
|
*/ |
79
|
|
|
public function getLongWikiText( $linker = null ) { |
80
|
|
|
return $this->getShortWikiText( $linker ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @see SMWDataValue::getLongHTMLText |
85
|
|
|
* |
86
|
|
|
* @since 2.0 |
87
|
|
|
*/ |
88
|
|
|
public function getLongHTMLText( $linker = null ) { |
89
|
|
|
return $this->getLongWikiText( $linker ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @see SMWDataValue::getWikiValue |
94
|
|
|
* |
95
|
|
|
* @since 2.0 |
96
|
|
|
*/ |
97
|
|
|
public function getWikiValue() { |
98
|
|
|
return $this->m_dataitem->getString(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @see SMWDataValue::getExportData |
103
|
|
|
* |
104
|
|
|
* @since 2.0 |
105
|
|
|
*/ |
106
|
|
|
public function getExportData() { |
107
|
|
|
return null; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|