1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace POData\ObjectModel; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class ODataEntry. |
7
|
|
|
*/ |
8
|
|
|
class ODataEntry |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Entry id. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
public $id; |
16
|
|
|
/** |
17
|
|
|
* Entry Self Link. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
public $selfLink; |
22
|
|
|
/** |
23
|
|
|
* Entry title. |
24
|
|
|
* |
25
|
|
|
* @var ODataTitle |
26
|
|
|
*/ |
27
|
|
|
public $title; |
28
|
|
|
/** |
29
|
|
|
* Entry Edit Link. |
30
|
|
|
* |
31
|
|
|
* @var ODataLink |
32
|
|
|
*/ |
33
|
|
|
public $editLink; |
34
|
|
|
/** |
35
|
|
|
* Entry Type. This become the value of term attribute of Category element. |
36
|
|
|
* |
37
|
|
|
* @var ODataCategory |
38
|
|
|
*/ |
39
|
|
|
public $type; |
40
|
|
|
/** |
41
|
|
|
* Instance to hold entity properties. |
42
|
|
|
* Properties corresponding to "m:properties" under content element |
43
|
|
|
* in the case of Non-MLE. For MLE "m:properties" is direct child of entry. |
44
|
|
|
* |
45
|
|
|
* @var ODataPropertyContent |
46
|
|
|
*/ |
47
|
|
|
public $propertyContent; |
48
|
|
|
/** |
49
|
|
|
* Collection of entry media links (Named Stream Links). |
50
|
|
|
* |
51
|
|
|
* @var array<ODataMediaLink> |
52
|
|
|
*/ |
53
|
|
|
public $mediaLinks = []; |
54
|
|
|
/** |
55
|
|
|
* media link entry (MLE Link). |
56
|
|
|
* |
57
|
|
|
* @var ODataMediaLink |
58
|
|
|
*/ |
59
|
|
|
public $mediaLink; |
60
|
|
|
/** |
61
|
|
|
* Collection of navigation links (can be expanded). |
62
|
|
|
* |
63
|
|
|
* @var array<ODataLink> |
64
|
|
|
*/ |
65
|
|
|
public $links = []; |
66
|
|
|
/** |
67
|
|
|
* Entry ETag. |
68
|
|
|
* |
69
|
|
|
* @var string |
70
|
|
|
*/ |
71
|
|
|
public $eTag; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* True if this is a media link entry. |
75
|
|
|
* |
76
|
|
|
* @var bool |
77
|
|
|
*/ |
78
|
|
|
public $isMediaLinkEntry; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* The name of the resource set this entry belongs to, use in metadata output. |
82
|
|
|
* |
83
|
|
|
* @var string |
84
|
|
|
*/ |
85
|
|
|
public $resourceSetName; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Last updated timestamp. |
89
|
|
|
* |
90
|
|
|
* @var string |
91
|
|
|
*/ |
92
|
|
|
public $updated; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Service Base URI. |
96
|
|
|
* |
97
|
|
|
* @var string |
98
|
|
|
*/ |
99
|
|
|
public $baseURI; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var AtomObjectModel\AtomContent |
103
|
|
|
*/ |
104
|
|
|
public $atomContent; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return \POData\ObjectModel\AtomObjectModel\AtomContent |
108
|
|
|
*/ |
109
|
|
|
public function getAtomContent() |
110
|
|
|
{ |
111
|
|
|
if (!$this->isMediaLinkEntry) { |
112
|
|
|
return new AtomObjectModel\AtomContent( |
113
|
|
|
\POData\Common\MimeTypes::MIME_APPLICATION_XML, |
114
|
|
|
null, $this->propertyContent |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
return new AtomObjectModel\AtomContent($this->mediaLink->contentType, $this->mediaLink->srcLink); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param \POData\ObjectModel\AtomObjectModel\AtomContent $atomContent |
122
|
|
|
*/ |
123
|
|
|
public function setAtomContent(AtomObjectModel\AtomContent $atomContent) |
124
|
|
|
{ |
125
|
|
|
$this->setPropertyContent($atomContent->properties); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @var AtomObjectModel\AtomAuthor |
130
|
|
|
*/ |
131
|
|
|
public $atomAuthor; |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return \POData\ObjectModel\AtomObjectModel\AtomAuthor |
135
|
|
|
*/ |
136
|
|
|
public function getAtomAuthor() |
137
|
|
|
{ |
138
|
|
|
return new AtomObjectModel\AtomAuthor(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return null|\POData\ObjectModel\ODataPropertyContent |
143
|
|
|
*/ |
144
|
|
|
public function getPropertyContent() |
145
|
|
|
{ |
146
|
|
|
if (!$this->isMediaLinkEntry) { |
147
|
|
|
return null; |
148
|
|
|
} |
149
|
|
|
return $this->propertyContent; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param \POData\ObjectModel\ODataPropertyContent|null $oDataPropertyContent |
154
|
|
|
*/ |
155
|
|
|
public function setPropertyContent(ODataPropertyContent $oDataPropertyContent = null) |
156
|
|
|
{ |
157
|
|
|
$this->propertyContent = $oDataPropertyContent; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return \POData\ObjectModel\ODataLink |
162
|
|
|
*/ |
163
|
|
|
public function getEditLink() |
164
|
|
|
{ |
165
|
|
|
return $this->editLink; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return \POData\ObjectModel\ODataLink[] |
170
|
|
|
*/ |
171
|
|
|
public function getLinks() |
172
|
|
|
{ |
173
|
|
|
return $this->links; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param $links \POData\ObjectModel\ODataLink[] |
178
|
|
|
*/ |
179
|
|
|
public function setLinks(array $links) |
180
|
|
|
{ |
181
|
|
|
$this->links = []; |
182
|
|
|
foreach ($links as $link) { |
183
|
|
|
if ('edit' == $link->name) { |
184
|
|
|
$this->editLink = $link; |
185
|
|
|
$this->resourceSetName = explode('(', $link->url)[0]; |
186
|
|
|
continue; |
187
|
|
|
} |
188
|
|
|
if ('http://schemas.microsoft.com/ado/2007/08/dataservices/related' == substr($link->name, 0, 61) |
189
|
|
|
) { |
190
|
|
|
$this->links[] = $link; |
191
|
|
|
continue; |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @return ODataMediaLink[] |
198
|
|
|
*/ |
199
|
|
|
public function getMediaLinks() |
200
|
|
|
{ |
201
|
|
|
return $this->mediaLinks; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @param ODataMediaLink[] $mediaLinks |
206
|
|
|
*/ |
207
|
|
|
public function setMediaLinks(array $mediaLinks) |
208
|
|
|
{ |
209
|
|
|
$this->mediaLinks = []; |
210
|
|
|
$editLink = null; |
211
|
|
|
foreach ($mediaLinks as $mediaLink) { |
212
|
|
|
$this->handleMediaLinkEntry($mediaLink, $editLink); |
213
|
|
|
} |
214
|
|
|
$this->correctMediaLinkSrc($editLink); |
215
|
|
|
if (null === $this->mediaLink) { |
216
|
|
|
$this->isMediaLinkEntry = false; |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @param \POData\ObjectModel\ODataMediaLink $mediaLink |
222
|
|
|
* @param \POData\ObjectModel\ODataMediaLink|null $editLink |
223
|
|
|
*/ |
224
|
|
|
private function handleMediaLinkEntry(ODataMediaLink $mediaLink, ODataMediaLink &$editLink = null) |
225
|
|
|
{ |
226
|
|
|
if ('edit-media' == $mediaLink->rel) { |
227
|
|
|
$this->isMediaLinkEntry = true; |
228
|
|
|
$this->mediaLink = $mediaLink; |
229
|
|
|
} |
230
|
|
|
if (ODataMediaLink::MEDIARESOURCE_BASE == substr($mediaLink->rel, 0, 68)) { |
231
|
|
|
$this->mediaLinks[] = $mediaLink; |
232
|
|
|
} |
233
|
|
|
if ('edit' == $mediaLink->rel) { |
234
|
|
|
$editLink = $mediaLink; |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param \POData\ObjectModel\ODataMediaLink|null $editLink |
240
|
|
|
*/ |
241
|
|
|
private function correctMediaLinkSrc(ODataMediaLink $editLink = null) |
242
|
|
|
{ |
243
|
|
|
if (null !== $this->mediaLink && null !== $editLink) { |
244
|
|
|
$this->mediaLink->srcLink = $editLink->editLink . $this->mediaLink->editLink; |
245
|
|
|
foreach ($this->mediaLinks as $mediaLink) { |
246
|
|
|
$mediaLink->srcLink = $editLink->editLink . '/' . $mediaLink->name; |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @return \POData\ObjectModel\ODataMediaLink |
253
|
|
|
*/ |
254
|
|
|
public function getMediaLink() |
255
|
|
|
{ |
256
|
|
|
return $this->mediaLink; |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
|