1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PODEntender\Infrastructure\Domain\Factory; |
4
|
|
|
|
5
|
|
|
use PODEntender\Domain\Model\FileProcessing\RssFeedConfiguration; |
6
|
|
|
use PODEntender\Domain\Model\Post\AudioEpisode; |
7
|
|
|
use PODEntender\Domain\Model\Post\Post; |
8
|
|
|
use PODEntender\Domain\Model\Post\PostImage; |
9
|
|
|
use PODEntender\Domain\Model\Post\PostImageCollection; |
10
|
|
|
use TightenCo\Jigsaw\PageVariable; |
11
|
|
|
|
12
|
|
|
class JigsawPostFactory |
13
|
|
|
{ |
14
|
|
|
private $feedConfiguration; |
15
|
|
|
|
16
|
4 |
|
public function __construct(RssFeedConfiguration $feedConfiguration) |
17
|
|
|
{ |
18
|
4 |
|
$this->feedConfiguration = $feedConfiguration; |
19
|
4 |
|
} |
20
|
|
|
|
21
|
3 |
|
public function newPostFromPageVariable(PageVariable $page): Post |
22
|
|
|
{ |
23
|
3 |
|
$date = new \DateTime(); |
24
|
|
|
|
25
|
3 |
|
$episode = $page->episode; |
26
|
|
|
|
27
|
3 |
|
return new Post( |
28
|
3 |
|
$page->episode['guid'] ?? $page->getUrl(), |
29
|
3 |
|
$page->getUrl(), |
30
|
3 |
|
$episode['title'], |
31
|
3 |
|
$episode['description'], |
32
|
3 |
|
$episode['author'], |
33
|
3 |
|
$page->getContent(), |
34
|
3 |
|
$page->category, |
|
|
|
|
35
|
3 |
|
$this->createImageCollectionFromPageVariable($page), |
36
|
3 |
|
$page->tags ?? [], |
|
|
|
|
37
|
3 |
|
\DateTimeImmutable::createFromMutable($date->setTimestamp($page->date)), |
|
|
|
|
38
|
3 |
|
\DateTimeImmutable::createFromMutable($date->setTimestamp($episode['date'])) |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
public function newAudioEpisodeFromPageVariable(PageVariable $page): AudioEpisode |
43
|
|
|
{ |
44
|
1 |
|
$date = new \DateTime(); |
45
|
|
|
|
46
|
1 |
|
$episode = $page->episode; |
47
|
|
|
|
48
|
1 |
|
return new AudioEpisode( |
49
|
1 |
|
$page->episode['guid'] ?? $page->getUrl(), |
50
|
1 |
|
$page->getUrl(), |
51
|
1 |
|
$episode['title'], |
52
|
1 |
|
$episode['description'], |
53
|
1 |
|
$episode['author'] ?? '', |
54
|
1 |
|
$page->getContent(), |
55
|
1 |
|
$page->get('category'), |
56
|
1 |
|
$this->createImageCollectionFromPageVariable($page), |
57
|
1 |
|
$page->tags ?? [], |
|
|
|
|
58
|
1 |
|
\DateTimeImmutable::createFromMutable($date->setTimestamp($page->date)), |
|
|
|
|
59
|
1 |
|
\DateTimeImmutable::createFromMutable($date->setTimestamp($episode['date'])), |
60
|
1 |
|
$this->feedConfiguration->explicit(), |
61
|
1 |
|
$episode['audioDuration'] ?? '00:00:00', |
62
|
1 |
|
$episode['audioUrl'], |
63
|
1 |
|
$page->getBaseUrl() . $episode['cover']['url'] ?? '' |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
4 |
|
private function createImageCollectionFromPageVariable(PageVariable $page): PostImageCollection |
68
|
|
|
{ |
69
|
4 |
|
$episode = $page->episode; |
70
|
|
|
|
71
|
4 |
|
$cover = new PostImage( |
72
|
4 |
|
$page->getBaseUrl() . $episode['cover']['url'], |
73
|
4 |
|
$episode['cover']['title'] ?? '', |
74
|
4 |
|
$episode['cover']['alt'] ?? '', |
75
|
4 |
|
true |
76
|
|
|
); |
77
|
|
|
|
78
|
4 |
|
return new PostImageCollection([$cover]); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|