Completed
Push — master ( 484b1a...998a69 )
by Jeroen De
03:30
created

GeoPolygonValue::getExportData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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 ) {
0 ignored issues
show
Bug introduced by
The class SMWDIBlob does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
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