1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\QueryEngine\SQLStore\DVHandler; |
4
|
|
|
|
5
|
|
|
use DataValues\BooleanValue; |
6
|
|
|
use DataValues\DataValue; |
7
|
|
|
use Doctrine\DBAL\Schema\Table; |
8
|
|
|
use Doctrine\DBAL\Types\Type; |
9
|
|
|
use InvalidArgumentException; |
10
|
|
|
use Wikibase\QueryEngine\SQLStore\DataValueHandler; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Represents the mapping between BooleanValue and |
14
|
|
|
* the corresponding table in the store. |
15
|
|
|
* |
16
|
|
|
* @since 0.1 |
17
|
|
|
* |
18
|
|
|
* @licence GNU GPL v2+ |
19
|
|
|
* @author Jeroen De Dauw < [email protected] > |
20
|
|
|
*/ |
21
|
|
|
class BooleanHandler extends DataValueHandler { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @see DataValueHandler::getBaseTableName |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
protected function getBaseTableName() { |
29
|
|
|
return 'boolean'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @see DataValueHandler::completeTable |
34
|
|
|
*/ |
35
|
|
|
protected function completeTable( Table $table ) { |
36
|
|
|
$table->addColumn( 'value', Type::BOOLEAN ); |
37
|
|
|
|
38
|
|
|
$table->addIndex( array( 'value' ) ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @see DataValueHandler::getEqualityFieldName |
43
|
|
|
* |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
|
|
public function getEqualityFieldName() { |
47
|
|
|
return 'value'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @see DataValueHandler::getInsertValues |
52
|
|
|
* |
53
|
|
|
* @param DataValue $value |
54
|
|
|
* |
55
|
|
|
* @throws InvalidArgumentException |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
|
|
public function getInsertValues( DataValue $value ) { |
59
|
|
|
if ( !( $value instanceof BooleanValue ) ) { |
60
|
|
|
throw new InvalidArgumentException( 'Value is not a BooleanValue.' ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$values = array( |
64
|
|
|
'value' => $value->getValue() ? 1 : 0, |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
return $values; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @see DataValueHandler::getEqualityFieldValue |
72
|
|
|
* |
73
|
|
|
* @param DataValue $value |
74
|
|
|
* |
75
|
|
|
* @throws InvalidArgumentException |
76
|
|
|
* @return int |
77
|
|
|
*/ |
78
|
|
|
public function getEqualityFieldValue( DataValue $value ) { |
79
|
|
|
if ( !( $value instanceof BooleanValue ) ) { |
80
|
|
|
throw new InvalidArgumentException( 'Value is not a BooleanValue.' ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $value->getValue() ? 1 : 0; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|