|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SEQL\ByHttpRequest; |
|
4
|
|
|
|
|
5
|
|
|
use SEQL\DataValueDeserializer; |
|
6
|
|
|
use SMW\DIProperty; |
|
7
|
|
|
use SMW\DIWikiPage; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @license GNU GPL v2+ |
|
11
|
|
|
* @since 1.0 |
|
12
|
|
|
* |
|
13
|
|
|
* @author mwjames |
|
14
|
|
|
*/ |
|
15
|
|
|
class ResponsePropertyList { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
private $querySource = ''; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
private $propertyList = array(); |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
private $internalLabelToKeyMap = array(); |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @since 1.0 |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $querySource |
|
36
|
|
|
*/ |
|
37
|
11 |
|
public function __construct( $querySource ) { |
|
38
|
11 |
|
$this->querySource = $querySource; |
|
39
|
11 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @since 1.0 |
|
43
|
|
|
* |
|
44
|
|
|
* @return DIProperty[] |
|
45
|
|
|
*/ |
|
46
|
9 |
|
public function getPropertyList() { |
|
47
|
9 |
|
return $this->propertyList; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @since 1.0 |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $key |
|
54
|
|
|
* |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
10 |
|
public function findPropertyKey( $key ) { |
|
58
|
|
|
|
|
59
|
10 |
|
if ( isset( $this->internalLabelToKeyMap[$key] ) ) { |
|
60
|
3 |
|
return $this->internalLabelToKeyMap[$key]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
9 |
|
return $key; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @since 1.0 |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $key |
|
70
|
|
|
* |
|
71
|
|
|
* @return boolean |
|
72
|
|
|
*/ |
|
73
|
8 |
|
public function hasProperty( $key ) { |
|
74
|
8 |
|
return isset( $this->propertyList[$this->findPropertyKey( $key )] ); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @since 1.0 |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $key |
|
81
|
|
|
* |
|
82
|
|
|
* @return DIProperty|null |
|
83
|
|
|
*/ |
|
84
|
10 |
|
public function getProperty( $key ) { |
|
85
|
|
|
|
|
86
|
10 |
|
$key = $this->findPropertyKey( $key ); |
|
87
|
|
|
|
|
88
|
10 |
|
if ( isset( $this->propertyList[$key] ) ) { |
|
89
|
10 |
|
return $this->propertyList[$key]; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return null; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @since 1.0 |
|
97
|
|
|
* |
|
98
|
|
|
* @param array $value |
|
99
|
|
|
*/ |
|
100
|
10 |
|
public function addToPropertyList( array $value ) { |
|
101
|
|
|
|
|
102
|
10 |
|
if ( $value['label'] === '' ) { |
|
103
|
6 |
|
return; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
10 |
|
if ( $value['mode'] == 0 ) { |
|
107
|
2 |
|
$property = new DIProperty( '_INST' ); |
|
108
|
2 |
|
$this->internalLabelToKeyMap[$value['label']] = $property->getKey(); |
|
109
|
2 |
|
} else { |
|
110
|
8 |
|
$property = DIProperty::newFromUserLabel( $value['label'] ); |
|
111
|
8 |
|
$property->setPropertyTypeId( $value['typeid'] ); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
10 |
|
if ( isset( $value['redi'] ) ) { |
|
115
|
2 |
|
$this->internalLabelToKeyMap[$value['redi']] = $property->getKey(); |
|
116
|
2 |
|
} |
|
117
|
|
|
|
|
118
|
10 |
|
$property->setInterwiki( $this->querySource ); |
|
119
|
10 |
|
$this->propertyList[$property->getKey()] = $property; |
|
120
|
10 |
|
} |
|
121
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|