1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\DataValues; |
4
|
|
|
|
5
|
|
|
use SMWDataValue as DataValue; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @private |
9
|
|
|
* |
10
|
|
|
* @license GNU GPL v2+ |
11
|
|
|
* @since 2.5 |
12
|
|
|
* |
13
|
|
|
* @author mwjames |
14
|
|
|
*/ |
15
|
|
|
abstract class AbstractMultiValue extends DataValue { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @since 2.5 |
19
|
|
|
* |
20
|
|
|
* @param string $userValue |
21
|
|
|
* |
22
|
|
|
* @return array |
23
|
|
|
*/ |
24
|
|
|
abstract public function getValuesFromString( $userValue ); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @since 2.5 |
28
|
|
|
* |
29
|
|
|
* @param DIProperty[] $properties |
30
|
|
|
* |
31
|
|
|
* @return DIProperty[]|null |
32
|
|
|
*/ |
33
|
|
|
abstract public function setFieldProperties( array $properties ); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @since 2.5 |
37
|
|
|
* |
38
|
|
|
* @return DIProperty[]|null |
39
|
|
|
*/ |
40
|
|
|
abstract public function getProperties(); |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Create a list (array with numeric keys) containing the datavalue |
44
|
|
|
* objects that this SMWRecordValue object holds. Values that are not |
45
|
|
|
* present are set to null. Note that the first index in the array is |
46
|
|
|
* 0, not 1. |
47
|
|
|
* |
48
|
|
|
* @since 2.5 |
49
|
|
|
* |
50
|
|
|
* @return DataItem[]|null |
51
|
|
|
*/ |
52
|
|
|
abstract public function getDataItems(); |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Return the array (list) of properties that the individual entries of |
56
|
|
|
* this datatype consist of. |
57
|
|
|
* |
58
|
|
|
* @since 2.5 |
59
|
|
|
* |
60
|
|
|
* @return DIProperty[]|null |
61
|
|
|
*/ |
62
|
|
|
abstract public function getPropertyDataItems(); |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @note called by SMWResultArray::loadContent for matching an index as denoted |
66
|
|
|
* in |?Foo=Bar|+index=1 OR |?Foo=Bar|+index=Bar |
67
|
|
|
* |
68
|
|
|
* @see https://www.semantic-mediawiki.org/wiki/Help:Type_Record#Semantic_search |
69
|
|
|
* |
70
|
|
|
* @since 2.5 |
71
|
|
|
* |
72
|
|
|
* @param string|integer $index |
73
|
|
|
* |
74
|
|
|
* @return DataItem[]|null |
75
|
|
|
*/ |
76
|
4 |
|
public function getDataItemByIndex( $index ) { |
77
|
|
|
|
78
|
4 |
|
if ( is_numeric( $index ) ) { |
79
|
3 |
|
$pos = $index - 1; |
80
|
3 |
|
$dataItems = $this->getDataItems(); |
81
|
3 |
|
return isset( $dataItems[$pos] ) ? $dataItems[$pos] : null; |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
if ( ( $property = $this->getPropertyDataItemByIndex( $index ) ) !== null ) { |
85
|
1 |
|
$values = $this->getDataItem()->getSemanticData()->getPropertyValues( $property ); |
|
|
|
|
86
|
1 |
|
return reset( $values ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return null; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @note called by SMWResultArray::getNextDataValue to match an index |
94
|
|
|
* that has been denoted using |?Foo=Bar|+index=1 OR |?Foo=Bar|+index=Bar |
95
|
|
|
* |
96
|
|
|
* @since 2.5 |
97
|
|
|
* |
98
|
|
|
* @param string|integer $index |
99
|
|
|
* |
100
|
|
|
* @return DIProperty|null |
101
|
|
|
*/ |
102
|
4 |
|
public function getPropertyDataItemByIndex( $index ) { |
103
|
|
|
|
104
|
4 |
|
$properties = $this->getPropertyDataItems(); |
105
|
|
|
|
106
|
4 |
|
if ( is_numeric( $index ) ) { |
107
|
3 |
|
$pos = $index - 1; |
108
|
3 |
|
return isset( $properties[$pos] ) ? $properties[$pos] : null; |
109
|
|
|
} |
110
|
|
|
|
111
|
1 |
|
foreach ( $properties as $property ) { |
|
|
|
|
112
|
1 |
|
if ( $property->getLabel() === $index ) { |
113
|
1 |
|
return $property; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return null; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|