1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JDecool\JsonFeed; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use InvalidArgumentException; |
7
|
|
|
|
8
|
|
|
class Item |
9
|
|
|
{ |
10
|
|
|
/** @var string */ |
11
|
|
|
private $id; |
12
|
|
|
|
13
|
|
|
/** @var string */ |
14
|
|
|
private $url; |
15
|
|
|
|
16
|
|
|
/** @var string */ |
17
|
|
|
private $externalUrl; |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
private $title; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
private $contentHtml; |
24
|
|
|
|
25
|
|
|
/** @var string */ |
26
|
|
|
private $contentText; |
27
|
|
|
|
28
|
|
|
/** @var string */ |
29
|
|
|
private $summary; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
private $image; |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
private $bannerImage; |
36
|
|
|
|
37
|
|
|
/** @var DateTime */ |
38
|
|
|
private $datePublished; |
39
|
|
|
|
40
|
|
|
/** @var DateTime */ |
41
|
|
|
private $dateModified; |
42
|
|
|
|
43
|
|
|
/** @var Author */ |
44
|
|
|
private $author; |
45
|
|
|
|
46
|
|
|
/** @var string[] */ |
47
|
|
|
private $tags; |
48
|
|
|
|
49
|
|
|
/** @var Attachment[] */ |
50
|
|
|
private $attachments; |
51
|
|
|
|
52
|
|
|
/** @var array */ |
53
|
|
|
private $extensions; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Constructor |
57
|
|
|
* |
58
|
|
|
* @param string $id |
59
|
|
|
*/ |
60
|
|
|
public function __construct($id) |
61
|
|
|
{ |
62
|
|
|
$this->id = $id; |
63
|
|
|
|
64
|
|
|
$this->tags = []; |
65
|
|
|
$this->attachments = []; |
66
|
|
|
$this->extensions = []; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get unique identifer for that item for that feed over time |
71
|
|
|
* |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
public function getId() |
75
|
|
|
{ |
76
|
|
|
return $this->id; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the URL of the resource described by the item |
81
|
|
|
* |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
public function getUrl() |
85
|
|
|
{ |
86
|
|
|
return $this->url; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Set the URL of the resource described by the item |
91
|
|
|
* |
92
|
|
|
* @param string $url |
93
|
|
|
* @return Item |
94
|
|
|
*/ |
95
|
|
|
public function setUrl($url) |
96
|
|
|
{ |
97
|
|
|
$this->url = $url; |
98
|
|
|
|
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get the URL of a page elsewhere |
104
|
|
|
* |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
|
|
public function getExternalUrl() |
108
|
|
|
{ |
109
|
|
|
return $this->externalUrl; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Set the URL of a page elsewhere |
114
|
|
|
* |
115
|
|
|
* @param string $externalUrl |
116
|
|
|
* @return Item |
117
|
|
|
*/ |
118
|
|
|
public function setExternalUrl($externalUrl) |
119
|
|
|
{ |
120
|
|
|
$this->externalUrl = $externalUrl; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Get plaintext title |
127
|
|
|
* |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
|
|
public function getTitle() |
131
|
|
|
{ |
132
|
|
|
return $this->title; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Set plaintext title |
137
|
|
|
* |
138
|
|
|
* @param string $title |
139
|
|
|
* @return Item |
140
|
|
|
*/ |
141
|
|
|
public function setTitle($title) |
142
|
|
|
{ |
143
|
|
|
$this->title = $title; |
144
|
|
|
|
145
|
|
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Get the HTML content for the item |
150
|
|
|
* |
151
|
|
|
* @return string |
152
|
|
|
*/ |
153
|
|
|
public function getContentHtml() |
154
|
|
|
{ |
155
|
|
|
return $this->contentHtml; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Set the HTML content for the item |
160
|
|
|
* |
161
|
|
|
* @param string $contentHtml |
162
|
|
|
* @return Item |
163
|
|
|
*/ |
164
|
|
|
public function setContentHtml($contentHtml) |
165
|
|
|
{ |
166
|
|
|
$this->contentHtml = $contentHtml; |
167
|
|
|
|
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Get plain text content for the item |
173
|
|
|
* |
174
|
|
|
* @return string |
175
|
|
|
*/ |
176
|
|
|
public function getContentText() |
177
|
|
|
{ |
178
|
|
|
return $this->contentText; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Set plain text content for the item |
183
|
|
|
* |
184
|
|
|
* @param string $contentText |
185
|
|
|
* @return Item |
186
|
|
|
*/ |
187
|
|
|
public function setContentText($contentText) |
188
|
|
|
{ |
189
|
|
|
$this->contentText = $contentText; |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Get a plain text sentence or two describing the item |
196
|
|
|
* |
197
|
|
|
* @return string |
198
|
|
|
*/ |
199
|
|
|
public function getSummary() |
200
|
|
|
{ |
201
|
|
|
return $this->summary; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Set a plain text sentence or two describing the item |
206
|
|
|
* |
207
|
|
|
* @param string $summary |
208
|
|
|
* @return Item |
209
|
|
|
*/ |
210
|
|
|
public function setSummary($summary) |
211
|
|
|
{ |
212
|
|
|
$this->summary = $summary; |
213
|
|
|
|
214
|
|
|
return $this; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Get the URL of the main image for the item |
219
|
|
|
* |
220
|
|
|
* @return string |
221
|
|
|
*/ |
222
|
|
|
public function getImage() |
223
|
|
|
{ |
224
|
|
|
return $this->image; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Set the URL of the main image for the item |
229
|
|
|
* |
230
|
|
|
* @param string $image |
231
|
|
|
* @return Item |
232
|
|
|
*/ |
233
|
|
|
public function setImage($image) |
234
|
|
|
{ |
235
|
|
|
$this->image = $image; |
236
|
|
|
|
237
|
|
|
return $this; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Get the URL of an image to use as a banner |
242
|
|
|
* |
243
|
|
|
* @return string |
244
|
|
|
*/ |
245
|
|
|
public function getBannerImage() |
246
|
|
|
{ |
247
|
|
|
return $this->bannerImage; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Set the URL of an image to use as a banner |
252
|
|
|
* |
253
|
|
|
* @param string $bannerImage |
254
|
|
|
* @return Item |
255
|
|
|
*/ |
256
|
|
|
public function setBannerImage($bannerImage) |
257
|
|
|
{ |
258
|
|
|
$this->bannerImage = $bannerImage; |
259
|
|
|
|
260
|
|
|
return $this; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Get the item published date |
265
|
|
|
* |
266
|
|
|
* @return DateTime |
267
|
|
|
*/ |
268
|
|
|
public function getDatePublished() |
269
|
|
|
{ |
270
|
|
|
return $this->datePublished; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Set the item published date |
275
|
|
|
* |
276
|
|
|
* @param DateTime $datePublished |
277
|
|
|
* @return Item |
278
|
|
|
*/ |
279
|
|
|
public function setDatePublished(DateTime $datePublished) |
280
|
|
|
{ |
281
|
|
|
$this->datePublished = $datePublished; |
282
|
|
|
|
283
|
|
|
return $this; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Get the item modified date |
288
|
|
|
* |
289
|
|
|
* @return DateTime |
290
|
|
|
*/ |
291
|
|
|
public function getDateModified() |
292
|
|
|
{ |
293
|
|
|
return $this->dateModified; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* Set the item modified date |
298
|
|
|
* |
299
|
|
|
* @param DateTime $dateModified |
300
|
|
|
* @return Item |
301
|
|
|
*/ |
302
|
|
|
public function setDateModified(DateTime $dateModified) |
303
|
|
|
{ |
304
|
|
|
$this->dateModified = $dateModified; |
305
|
|
|
|
306
|
|
|
return $this; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Get item author |
311
|
|
|
* |
312
|
|
|
* @return Author |
313
|
|
|
*/ |
314
|
|
|
public function getAuthor() |
315
|
|
|
{ |
316
|
|
|
return $this->author; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* Set item author |
321
|
|
|
* |
322
|
|
|
* @param Author $author |
323
|
|
|
* @return Item |
324
|
|
|
*/ |
325
|
|
|
public function setAuthor(Author $author) |
326
|
|
|
{ |
327
|
|
|
$this->author = $author; |
328
|
|
|
|
329
|
|
|
return $this; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* Get item tags |
334
|
|
|
* |
335
|
|
|
* @return string[] |
336
|
|
|
*/ |
337
|
|
|
public function getTags() |
338
|
|
|
{ |
339
|
|
|
return $this->tags; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* Add item tag |
344
|
|
|
* @param string $tag |
345
|
|
|
* @return Item |
346
|
|
|
*/ |
347
|
|
|
public function addTag($tag) |
348
|
|
|
{ |
349
|
|
|
if (!in_array($tag, $this->tags, true)) { |
350
|
|
|
$this->tags[] = $tag; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
return $this; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* Set item tags |
358
|
|
|
* |
359
|
|
|
* @param string[] $tags |
360
|
|
|
* @return Item |
361
|
|
|
*/ |
362
|
|
|
public function setTags(array $tags) |
363
|
|
|
{ |
364
|
|
|
$this->tags = $tags; |
365
|
|
|
|
366
|
|
|
return $this; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Get item attachments |
371
|
|
|
* |
372
|
|
|
* @return Attachment[] |
373
|
|
|
*/ |
374
|
|
|
public function getAttachments() |
375
|
|
|
{ |
376
|
|
|
return $this->attachments; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* Add item attachment |
381
|
|
|
* |
382
|
|
|
* @param Attachment $attachment |
383
|
|
|
* @return Item |
384
|
|
|
*/ |
385
|
|
|
public function addAttachment(Attachment $attachment) |
386
|
|
|
{ |
387
|
|
|
if (!in_array($attachment, $this->attachments, true)) { |
388
|
|
|
$this->attachments[] = $attachment; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
return $this; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* Set item attachments |
396
|
|
|
* |
397
|
|
|
* @param Attachment[] $attachments |
398
|
|
|
* @return Item |
399
|
|
|
*/ |
400
|
|
|
public function setAttachments(array $attachments) |
401
|
|
|
{ |
402
|
|
|
$this->attachments = $attachments; |
403
|
|
|
|
404
|
|
|
return $this; |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* Add an extension to the item |
409
|
|
|
* |
410
|
|
|
* @param string $key |
411
|
|
|
* @param array $value |
412
|
|
|
* @return Item |
413
|
|
|
*/ |
414
|
|
|
public function addExtension($key, array $value) |
415
|
|
|
{ |
416
|
|
|
if (!is_string($key)) { |
417
|
|
|
throw new InvalidArgumentException('Extension key must be a string'); |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
$this->extensions[$key] = $value; |
421
|
|
|
|
422
|
|
|
return $this; |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* Get all extensions |
427
|
|
|
* |
428
|
|
|
* @return array |
429
|
|
|
*/ |
430
|
|
|
public function getExtensions() |
431
|
|
|
{ |
432
|
|
|
return $this->extensions; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* Get an extension |
437
|
|
|
* |
438
|
|
|
* @param string $key |
439
|
|
|
* @return array|null |
440
|
|
|
*/ |
441
|
|
|
public function getExtension($key) |
442
|
|
|
{ |
443
|
|
|
if (!isset($this->extensions[$key])) { |
444
|
|
|
return null; |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
return $this->extensions[$key]; |
448
|
|
|
} |
449
|
|
|
} |
450
|
|
|
|