|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PODEntender\Infrastructure\Domain\Model\Participant; |
|
4
|
|
|
|
|
5
|
|
|
use PODEntender\Domain\Model\Participant\Participant; |
|
6
|
|
|
use PODEntender\Domain\Model\Participant\ParticipantCollection; |
|
7
|
|
|
use PODEntender\Domain\Model\Participant\ParticipantRepository; |
|
8
|
|
|
use TightenCo\Jigsaw\Jigsaw; |
|
9
|
|
|
use TightenCo\Jigsaw\PageVariable; |
|
10
|
|
|
|
|
11
|
|
|
class JigsawParticipantRepository implements ParticipantRepository |
|
12
|
|
|
{ |
|
13
|
|
|
private $jigsaw; |
|
14
|
|
|
|
|
15
|
2 |
|
public function __construct(Jigsaw $jigsaw) |
|
16
|
|
|
{ |
|
17
|
2 |
|
$this->jigsaw = $jigsaw; |
|
18
|
2 |
|
} |
|
19
|
|
|
|
|
20
|
1 |
|
public function all(): ParticipantCollection |
|
21
|
|
|
{ |
|
22
|
1 |
|
return new ParticipantCollection( |
|
23
|
1 |
|
$this->jigsaw |
|
24
|
1 |
|
->getCollection('episodes') |
|
25
|
|
|
->filter(function (PageVariable $page) { |
|
26
|
1 |
|
return count($page->participants ?? []) > 0; |
|
|
|
|
|
|
27
|
1 |
|
}) |
|
28
|
|
|
->map(function (PageVariable $page) { |
|
29
|
1 |
|
return $page->participants; |
|
30
|
1 |
|
}) |
|
31
|
1 |
|
->flatten(1) |
|
32
|
|
|
->map(function (array $participantMap) { |
|
33
|
1 |
|
return new Participant( |
|
34
|
1 |
|
$participantMap['name'], |
|
35
|
1 |
|
$participantMap['picture'], |
|
36
|
1 |
|
$participantMap['description'] |
|
37
|
|
|
); |
|
38
|
1 |
|
}) |
|
39
|
|
|
->unique(function (Participant $participant) { |
|
40
|
1 |
|
return $participant->name(); |
|
41
|
1 |
|
}) |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
1 |
|
public function byEpisode(string $number): ParticipantCollection |
|
46
|
|
|
{ |
|
47
|
1 |
|
return new ParticipantCollection( |
|
48
|
1 |
|
$this->jigsaw |
|
49
|
1 |
|
->getCollection('episodes') |
|
50
|
|
|
->filter(function (PageVariable $page) use ($number) { |
|
51
|
1 |
|
return $page->episode['number'] === $number && count($page->participants ?? []) > 0; |
|
|
|
|
|
|
52
|
1 |
|
}) |
|
53
|
|
|
->map(function (PageVariable $page) { |
|
54
|
1 |
|
return $page->participants; |
|
55
|
1 |
|
}) |
|
56
|
1 |
|
->flatten(1) |
|
57
|
|
|
->map(function (array $participantMap) { |
|
58
|
1 |
|
return new Participant( |
|
59
|
1 |
|
$participantMap['name'], |
|
60
|
1 |
|
$participantMap['picture'], |
|
61
|
1 |
|
$participantMap['description'] |
|
62
|
|
|
); |
|
63
|
1 |
|
}) |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|