Completed
Push — master ( 14d2bd...06e609 )
by mw
81:37 queued 59:24
created

storage/SQLStore/SMW_DIHandler_GeoCoord.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @ingroup SMWDataItemsHandlers
4
 */
5
6
/**
7
 * This class implements store access to SMWDIGeoCoord data items.
8
 *
9
 * @since 1.8
10
 *
11
 * @author Nischay Nahata
12
 * @ingroup SMWDataItemsHandlers
13
 */
14
class SMWDIHandlerGeoCoord extends SMWDataItemHandler {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
15
16
	/**
17
	 * Coordinates have three fields: a string version to keep the
18
	 * serialized value (exact), and two floating point columns for
19
	 * latitude and longitude (inexact, useful for bounding box selects).
20
	 * Altitude is not stored in an extra column since no operation uses
21
	 * this for anything so far.
22
	 *
23
	 * @see SMWDataItemHandler::getTableFields()
24
	 * @return array
25
	 */
26 26
	public function getTableFields() {
27 26
		return array( 'o_serialized' => 't', 'o_lat' => 'f', 'o_lon' => 'f' );
28
	}
29
30
	/**
31
	 * @see SMWDataItemHandler::getFetchFields()
32
	 *
33
	 * @since 1.8
34
	 * @return array
35
	 */
36
	public function getFetchFields() {
37
		return array( 'o_serialized' => 't' );
38
	}
39
40
	/**
41
	 * @see SMWDataItemHandler::getTableIndexes()
42
	 * @return array
43
	 */
44 3
	public function getTableIndexes() {
45 3
		return array( 'o_lat,o_lon' );
46
	}
47
48
	/**
49
	 * @see SMWDataItemHandler::getWhereConds()
50
	 * @return array
51
	 */
52
	public function getWhereConds( SMWDataItem $dataItem ) {
53
		return array(
54
			'o_serialized' => $dataItem->getSerialization()
55
		);
56
	}
57
58
	/**
59
	 * @see SMWDataItemHandler::getInsertValues()
60
	 * @return array
61
	 */
62
	public function getInsertValues( SMWDataItem $dataItem ) {
63
		return array(
64
			'o_serialized' => $dataItem->getSerialization(),
65
			'o_lat' => (string)$dataItem->getLatitude(),
66
			'o_lon' => (string)$dataItem->getLongitude()
67
		);
68
	}
69
70
	/**
71
	 * @see SMWDataItemHandler::getIndexField()
72
	 * @return string
73
	 */
74 3
	public function getIndexField() {
75 3
		return 'o_serialized';
76
	}
77
78
	/**
79
	 * Coordinates do not have a general string version that
80
	 * could be used for string search, so this method returns
81
	 * no label column (empty string).
82
	 *
83
	 * @see SMWDataItemHandler::getLabelField()
84
	 * @since 1.8
85
	 * @return string
86
	 */
87
	public function getLabelField() {
88
		return '';
89
	}
90
91
	/**
92
	 * @see SMWDataItemHandler::dataItemFromDBKeys()
93
	 * @since 1.8
94
	 * @param array|string $dbkeys expecting string here
95
	 *
96
	 * @return SMWDataItem
97
	 */
98
	public function dataItemFromDBKeys( $dbkeys ) {
99
		if ( is_string( $dbkeys ) ) {
100
			return SMWDIGeoCoord::doUnserialize( $dbkeys );
101
		} else {
102
			throw new SMWDataItemException( 'Failed to create data item from DB keys.' );
103
		}
104
	}
105
}
106