1
|
|
|
<?php |
2
|
|
|
namespace Dkd\PhpCmis; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* This file is part of php-cmis-lib. |
6
|
|
|
* |
7
|
|
|
* (c) Dimitri Ebert <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
use Dkd\PhpCmis\Data\AllowableActionsInterface; |
14
|
|
|
use Dkd\PhpCmis\Data\ObjectDataInterface; |
15
|
|
|
use Dkd\PhpCmis\Data\PropertyDataInterface; |
16
|
|
|
use Dkd\PhpCmis\Data\RelationshipInterface; |
17
|
|
|
use Dkd\PhpCmis\Data\RenditionInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Query Result. |
21
|
|
|
*/ |
22
|
|
|
class QueryResult implements QueryResultInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var PropertyDataInterface[] |
26
|
|
|
*/ |
27
|
|
|
protected $propertiesById = array(); |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var PropertyDataInterface[] |
31
|
|
|
*/ |
32
|
|
|
protected $propertiesByQueryName = array(); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var AllowableActionsInterface|null |
36
|
|
|
*/ |
37
|
|
|
protected $allowableActions = null; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var RelationshipInterface[] |
41
|
|
|
*/ |
42
|
|
|
protected $relationships = array(); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var RenditionInterface[] |
46
|
|
|
*/ |
47
|
|
|
protected $renditions = array(); |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param SessionInterface $session |
51
|
|
|
* @param ObjectDataInterface $objectData |
52
|
|
|
*/ |
53
|
16 |
|
public function __construct(SessionInterface $session, ObjectDataInterface $objectData) |
54
|
|
|
{ |
55
|
16 |
|
$objectFactory = $session->getObjectFactory(); |
56
|
16 |
|
$properties = $objectData->getProperties(); |
57
|
|
|
|
58
|
|
|
// handle properties |
59
|
16 |
|
if (!empty($properties)) { |
60
|
9 |
|
$queryProperties = $objectFactory->convertQueryProperties($properties); |
61
|
9 |
|
foreach ($queryProperties as $queryProperty) { |
62
|
9 |
|
if ($queryProperty->getId() !== null) { |
63
|
9 |
|
$this->propertiesById[$queryProperty->getId()] = $queryProperty; |
64
|
9 |
|
} |
65
|
|
|
|
66
|
9 |
|
if ($queryProperty->getQueryName() !== null) { |
67
|
9 |
|
$this->propertiesByQueryName[$queryProperty->getQueryName()] = $queryProperty; |
68
|
9 |
|
} |
69
|
9 |
|
} |
70
|
9 |
|
} |
71
|
|
|
|
72
|
|
|
// handle allowable actions |
73
|
16 |
|
$allowableActions = $objectData->getAllowableActions(); |
74
|
16 |
|
if ($allowableActions !== null) { |
75
|
2 |
|
$this->allowableActions = $allowableActions; |
76
|
2 |
|
} |
77
|
|
|
|
78
|
|
|
// handle relationships |
79
|
16 |
|
$relationshipsObjectData = $objectData->getRelationships(); |
80
|
16 |
|
foreach ($relationshipsObjectData as $relationshipObjectData) { |
81
|
2 |
|
$relationship = $objectFactory->convertObject($relationshipObjectData, $session->getDefaultContext()); |
82
|
2 |
|
if ($relationship instanceof RelationshipInterface) { |
83
|
2 |
|
$this->relationships[] = $relationship; |
84
|
2 |
|
} |
85
|
16 |
|
} |
86
|
|
|
|
87
|
|
|
// handle renditions |
88
|
16 |
|
$renditionsData = $objectData->getRenditions(); |
89
|
16 |
|
foreach ($renditionsData as $renditionData) { |
90
|
2 |
|
$rendition = $objectFactory->convertRendition($objectData->getId(), $renditionData); |
91
|
2 |
|
if ($rendition instanceof RenditionInterface) { |
92
|
2 |
|
$this->renditions[] = $rendition; |
93
|
2 |
|
} |
94
|
16 |
|
} |
95
|
16 |
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Returns the allowable actions if they have been requested. |
99
|
|
|
* |
100
|
|
|
* @return AllowableActionsInterface|null the allowable actions if they have been requested, <code>null</code> |
101
|
|
|
* otherwise |
102
|
|
|
*/ |
103
|
1 |
|
public function getAllowableActions() |
104
|
|
|
{ |
105
|
1 |
|
return $this->allowableActions; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Returns the list of all properties in this query result. |
110
|
|
|
* |
111
|
|
|
* @return PropertyDataInterface[] all properties, not <code>null</code> |
112
|
|
|
*/ |
113
|
1 |
|
public function getProperties() |
114
|
|
|
{ |
115
|
1 |
|
return array_values($this->propertiesById); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Returns a property by ID. |
120
|
|
|
* |
121
|
|
|
* Because repositories are not obligated to add property IDs to their query result properties, |
122
|
|
|
* this method might not always work as expected with some repositories. Use getPropertyByQueryName(String) instead. |
123
|
|
|
* |
124
|
|
|
* @param string $id |
125
|
|
|
* @return PropertyDataInterface|null the property or <code>null</code> if the property doesn't |
126
|
|
|
* exist or hasn't been requested |
127
|
|
|
*/ |
128
|
3 |
|
public function getPropertyById($id) |
129
|
|
|
{ |
130
|
3 |
|
return isset($this->propertiesById[$id]) ? $this->propertiesById[$id] : null; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Returns a property by query name or alias. |
135
|
|
|
* |
136
|
|
|
* @param string $queryName the property query name or alias |
137
|
|
|
* @return PropertyDataInterface|null the property or <code>null</code> if the property doesn't exist |
138
|
|
|
* or hasn't been requested |
139
|
|
|
*/ |
140
|
3 |
|
public function getPropertyByQueryName($queryName) |
141
|
|
|
{ |
142
|
3 |
|
return isset($this->propertiesByQueryName[$queryName]) ? $this->propertiesByQueryName[$queryName] : null; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Returns a property multi-value by ID. |
147
|
|
|
* |
148
|
|
|
* @param string $id the property ID |
149
|
|
|
* @return array|null the property value or <code>null</code> if the property doesn't exist, hasn't been requested, |
150
|
|
|
* or the property value isn't set |
151
|
|
|
*/ |
152
|
1 |
|
public function getPropertyMultivalueById($id) |
153
|
|
|
{ |
154
|
1 |
|
$property = $this->getPropertyById($id); |
155
|
|
|
|
156
|
1 |
|
return $property !== null ? $property->getValues() : null; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Returns a property multi-value by query name or alias. |
161
|
|
|
* |
162
|
|
|
* @param string $queryName the property query name or alias |
163
|
|
|
* @return array|null the property value or <code>null</code> if the property doesn't exist, hasn't been requested, |
164
|
|
|
* or the property value isn't set |
165
|
|
|
*/ |
166
|
1 |
|
public function getPropertyMultivalueByQueryName($queryName) |
167
|
|
|
{ |
168
|
1 |
|
$property = $this->getPropertyByQueryName($queryName); |
169
|
|
|
|
170
|
1 |
|
return $property !== null ? $property->getValues() : null; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Returns a property (single) value by ID. |
175
|
|
|
* |
176
|
|
|
* @param string $id the property ID |
177
|
|
|
* @return mixed |
178
|
|
|
*/ |
179
|
1 |
|
public function getPropertyValueById($id) |
180
|
|
|
{ |
181
|
1 |
|
$property = $this->getPropertyById($id); |
182
|
|
|
|
183
|
1 |
|
return $property !== null ? $property->getFirstValue() : null; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Returns a property (single) value by query name or alias. |
188
|
|
|
* |
189
|
|
|
* @param string $queryName the property query name or alias |
190
|
|
|
* @return mixed the property value or <code>null</code> if the property doesn't exist, hasn't been requested, |
191
|
|
|
* or the property value isn't set |
192
|
|
|
*/ |
193
|
1 |
|
public function getPropertyValueByQueryName($queryName) |
194
|
|
|
{ |
195
|
1 |
|
$property = $this->getPropertyByQueryName($queryName); |
196
|
|
|
|
197
|
1 |
|
return $property !== null ? $property->getFirstValue() : null; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Returns the relationships if they have been requested. |
202
|
|
|
* |
203
|
|
|
* @return RelationshipInterface[] |
204
|
|
|
*/ |
205
|
1 |
|
public function getRelationships() |
206
|
|
|
{ |
207
|
1 |
|
return $this->relationships; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Returns the renditions if they have been requested. |
212
|
|
|
* |
213
|
|
|
* @return RenditionInterface[] |
214
|
|
|
*/ |
215
|
1 |
|
public function getRenditions() |
216
|
|
|
{ |
217
|
1 |
|
return $this->renditions; |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
|