|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PODEntender\Domain\Model\Feed; |
|
4
|
|
|
|
|
5
|
|
|
class ItemBuilder |
|
6
|
|
|
{ |
|
7
|
|
|
const DATE_FORMAT = 'D, d M Y H:i:s O'; |
|
8
|
|
|
|
|
9
|
|
|
private $channelBuilder; |
|
10
|
|
|
|
|
11
|
|
|
private $guid; |
|
12
|
|
|
|
|
13
|
|
|
private $title; |
|
14
|
|
|
|
|
15
|
|
|
private $subtitle; |
|
16
|
|
|
|
|
17
|
|
|
private $link; |
|
18
|
|
|
|
|
19
|
|
|
private $image; |
|
20
|
|
|
|
|
21
|
|
|
private $comments; |
|
22
|
|
|
|
|
23
|
|
|
private $pubDate; |
|
24
|
|
|
|
|
25
|
|
|
private $description; |
|
26
|
|
|
|
|
27
|
|
|
private $author; |
|
28
|
|
|
|
|
29
|
|
|
private $explicit; |
|
30
|
|
|
|
|
31
|
|
|
private $duration; |
|
32
|
|
|
|
|
33
|
|
|
private $categories = []; |
|
34
|
|
|
|
|
35
|
|
|
private $enclosures = []; |
|
36
|
|
|
|
|
37
|
1 |
|
public function __construct(ChannelBuilder $channelBuilder) |
|
38
|
|
|
{ |
|
39
|
1 |
|
$this->channelBuilder = $channelBuilder; |
|
40
|
1 |
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
public function guid(string $guid): self |
|
43
|
|
|
{ |
|
44
|
1 |
|
$this->guid = $guid; |
|
45
|
1 |
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
1 |
|
public function title(string $title): self |
|
49
|
|
|
{ |
|
50
|
1 |
|
$this->title = $title; |
|
51
|
1 |
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
public function subtitle(string $subtitle): self |
|
55
|
|
|
{ |
|
56
|
1 |
|
$this->subtitle = $subtitle; |
|
57
|
1 |
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
public function link(string $link): self |
|
61
|
|
|
{ |
|
62
|
1 |
|
$this->link = $link; |
|
63
|
1 |
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
public function image(string $image): self |
|
67
|
|
|
{ |
|
68
|
1 |
|
$this->image = $image; |
|
69
|
1 |
|
return $this; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
1 |
|
public function comments(string $comments): self |
|
73
|
|
|
{ |
|
74
|
1 |
|
$this->comments = $comments; |
|
75
|
1 |
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
1 |
|
public function pubDate(string $pubDate): self |
|
79
|
|
|
{ |
|
80
|
1 |
|
$this->pubDate = $pubDate; |
|
81
|
1 |
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
1 |
|
public function description(string $description): self |
|
85
|
|
|
{ |
|
86
|
1 |
|
$this->description = $description; |
|
87
|
1 |
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
1 |
|
public function author(string $author): self |
|
91
|
|
|
{ |
|
92
|
1 |
|
$this->author = $author; |
|
93
|
1 |
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
1 |
|
public function explicit(string $explicit): self |
|
97
|
|
|
{ |
|
98
|
1 |
|
$this->explicit = $explicit; |
|
99
|
1 |
|
return $this; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
1 |
|
public function duration(string $duration): self |
|
103
|
|
|
{ |
|
104
|
1 |
|
$this->duration = $duration; |
|
105
|
1 |
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
1 |
|
public function addCategory(string $category): self { |
|
109
|
1 |
|
$this->categories[] = $category; |
|
110
|
1 |
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
1 |
|
public function addEnclosure(): EnclosureBuilder |
|
114
|
|
|
{ |
|
115
|
1 |
|
$enclosureBuilder = new EnclosureBuilder($this); |
|
116
|
1 |
|
$this->enclosures[] = $enclosureBuilder; |
|
117
|
|
|
|
|
118
|
1 |
|
return $enclosureBuilder; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
1 |
|
public function toDOMElement(\DOMDocument $dom): \DOMElement |
|
122
|
|
|
{ |
|
123
|
1 |
|
$element = $dom->createElement('item'); |
|
124
|
1 |
|
$element->appendChild($dom->createElement('title', $this->title)); |
|
125
|
1 |
|
$element->appendChild($dom->createElement('link', $this->link)); |
|
126
|
1 |
|
$element->appendChild($dom->createElement('comments', $this->comments)); |
|
127
|
1 |
|
$element->appendChild($dom->createElement('pubDate', $this->pubDate)); |
|
128
|
1 |
|
$guid = $dom->createElement('guid', $this->guid); |
|
129
|
1 |
|
$guid->setAttribute('isPermaLink', 'false'); |
|
130
|
1 |
|
$element->appendChild($guid); |
|
131
|
|
|
|
|
132
|
1 |
|
foreach ($this->categories as $category) { |
|
133
|
1 |
|
$categoryElement = $dom->createElement('category'); |
|
134
|
1 |
|
$categoryElement->appendChild( |
|
135
|
1 |
|
$dom->createCDATASection($category) |
|
136
|
|
|
); |
|
137
|
1 |
|
$element->appendChild($categoryElement); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
1 |
|
foreach ($this->enclosures as $enclosure) { |
|
141
|
1 |
|
$element->appendChild($enclosure->toDOMElement($dom)); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
1 |
|
$element->appendChild($dom->createElement('itunes:subtitle', $this->subtitle)); |
|
145
|
1 |
|
$element->appendChild($dom->createElement('itunes:summary', $this->description)); |
|
146
|
1 |
|
$element->appendChild($dom->createElement('itunes:author', $this->author)); |
|
147
|
1 |
|
$element->appendChild($dom->createElement('itunes:explicit', $this->explicit)); |
|
148
|
1 |
|
$element->appendChild($dom->createElement('itunes:duration', $this->duration)); |
|
149
|
|
|
|
|
150
|
1 |
|
if ($this->image) { |
|
151
|
1 |
|
$coverImage = $dom->createElement('itunes:image'); |
|
152
|
1 |
|
$coverImage->setAttribute('href', $this->image); |
|
153
|
|
|
|
|
154
|
1 |
|
$element->appendChild($coverImage); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
1 |
|
return $element; |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|