1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @ingroup SMWDataItemsHandlers |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* This class implements Store access to Boolean data items. |
8
|
|
|
* |
9
|
|
|
* @since 1.8 |
10
|
|
|
* |
11
|
|
|
* @author Nischay Nahata |
12
|
|
|
* @ingroup SMWDataItemsHandlers |
13
|
|
|
*/ |
14
|
|
|
class SMWDIHandlerBoolean extends SMWDataItemHandler { |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Method to return array of fields for a DI type |
18
|
|
|
* |
19
|
|
|
* @return array |
20
|
|
|
*/ |
21
|
26 |
|
public function getTableFields() { |
22
|
26 |
|
return array( 'o_value' => 'b' ); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @see SMWDataItemHandler::getFetchFields() |
27
|
|
|
* |
28
|
|
|
* @since 1.8 |
29
|
|
|
* @return array |
30
|
|
|
*/ |
31
|
5 |
|
public function getFetchFields() { |
32
|
5 |
|
return array( 'o_value' => 'b' ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Method to return an array of fields=>values for a DataItem |
37
|
|
|
* |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
public function getWhereConds( SMWDataItem $dataItem ) { |
41
|
|
|
return array( |
42
|
|
|
'o_value' => $dataItem->getBoolean() ? 1 : 0, |
|
|
|
|
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Method to return an array of fields=>values for a DataItem |
48
|
|
|
* This array is used to perform all insert operations into the DB |
49
|
|
|
* To optimize return minimum fields having indexes |
50
|
|
|
* |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
12 |
|
public function getInsertValues( SMWDataItem $dataItem ) { |
54
|
|
|
return array( |
55
|
12 |
|
'o_value' => $dataItem->getBoolean() ? 1 : 0, |
|
|
|
|
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Method to return the field used to select this type of DataItem |
61
|
|
|
* @since 1.8 |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
7 |
|
public function getIndexField() { |
65
|
7 |
|
return 'o_value'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Method to return the field used to select this type of DataItem |
70
|
|
|
* using the label |
71
|
|
|
* @since 1.8 |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
5 |
|
public function getLabelField() { |
75
|
5 |
|
return 'o_value'; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Method to create a dataitem from an array of DB keys. |
80
|
|
|
* |
81
|
|
|
* @since 1.8 |
82
|
|
|
* @param array|string $dbkeys should be a string here |
83
|
|
|
* |
84
|
|
|
* @return SMWDataItem |
85
|
|
|
*/ |
86
|
3 |
|
public function dataItemFromDBKeys( $dbkeys ) { |
87
|
3 |
|
global $wgDBtype; |
|
|
|
|
88
|
|
|
|
89
|
|
|
//PgSQL returns as t and f and need special handling http://archives.postgresql.org/pgsql-php/2010-02/msg00005.php |
90
|
3 |
|
if ( $wgDBtype == 'postgres' ) { |
91
|
|
|
$value = ( $dbkeys == 't' ); |
92
|
|
|
} else { |
93
|
3 |
|
$value = ( $dbkeys == '1' ); |
94
|
|
|
} |
95
|
|
|
|
96
|
3 |
|
return new SMWDIBoolean( $value ); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.