|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Calendar; |
|
4
|
|
|
|
|
5
|
|
|
use Broadway\Serializer\SerializableInterface; |
|
6
|
|
|
use CultuurNet\UDB3\Model\ValueObject\Calendar\OpeningHours\OpeningHour as Udb3ModelOpeningHour; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @todo Replace by CultuurNet\UDB3\Model\ValueObject\Calendar\OpeningHours\OpeningHour. |
|
10
|
|
|
*/ |
|
11
|
|
|
final class OpeningHour implements SerializableInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var OpeningTime |
|
15
|
|
|
*/ |
|
16
|
|
|
private $opens; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var OpeningTime |
|
20
|
|
|
*/ |
|
21
|
|
|
private $closes; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var DayOfWeekCollection |
|
25
|
|
|
*/ |
|
26
|
|
|
private $dayOfWeekCollection; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct( |
|
29
|
|
|
OpeningTime $opens, |
|
30
|
|
|
OpeningTime $closes, |
|
31
|
|
|
DayOfWeekCollection $dayOfWeekCollection |
|
32
|
|
|
) { |
|
33
|
|
|
$this->dayOfWeekCollection = $dayOfWeekCollection; |
|
34
|
|
|
$this->opens = $opens; |
|
35
|
|
|
$this->closes = $closes; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getOpens(): OpeningTime |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->opens; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getCloses(): OpeningTime |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->closes; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getDayOfWeekCollection(): DayOfWeekCollection |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->dayOfWeekCollection; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function addDayOfWeekCollection(DayOfWeekCollection $dayOfWeekCollection): void |
|
54
|
|
|
{ |
|
55
|
|
|
foreach ($dayOfWeekCollection->getDaysOfWeek() as $dayOfWeek) { |
|
56
|
|
|
$this->dayOfWeekCollection->addDayOfWeek($dayOfWeek); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function hasEqualHours(OpeningHour $otherOpeningHour): bool |
|
61
|
|
|
{ |
|
62
|
|
|
return $otherOpeningHour->getOpens()->sameValueAs($this->getOpens()) && |
|
63
|
|
|
$otherOpeningHour->getCloses()->sameValueAs($this->getCloses()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public static function deserialize(array $data): OpeningHour |
|
67
|
|
|
{ |
|
68
|
|
|
return new static( |
|
69
|
|
|
OpeningTime::fromNativeString($data['opens']), |
|
70
|
|
|
OpeningTime::fromNativeString($data['closes']), |
|
71
|
|
|
DayOfWeekCollection::deserialize($data['dayOfWeek']) |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function serialize(): array |
|
76
|
|
|
{ |
|
77
|
|
|
return [ |
|
78
|
|
|
'opens' => $this->opens->toNativeString(), |
|
79
|
|
|
'closes' => $this->closes->toNativeString(), |
|
80
|
|
|
'dayOfWeek' => $this->dayOfWeekCollection->serialize(), |
|
81
|
|
|
]; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public static function fromUdb3ModelOpeningHour(Udb3ModelOpeningHour $openingHour): OpeningHour |
|
85
|
|
|
{ |
|
86
|
|
|
return new self( |
|
87
|
|
|
OpeningTime::fromUdb3ModelTime($openingHour->getOpeningTime()), |
|
88
|
|
|
OpeningTime::fromUdb3ModelTime($openingHour->getClosingTime()), |
|
89
|
|
|
DayOfWeekCollection::fromUdb3ModelDays($openingHour->getDays()) |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|