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
|
|
|
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
|
|
|
/** |
29
|
|
|
* OpeningHour constructor. |
30
|
|
|
* @param OpeningTime $opens |
31
|
|
|
* @param OpeningTime $closes |
32
|
|
|
* @param DayOfWeekCollection $dayOfWeekCollection |
33
|
|
|
*/ |
34
|
|
|
public function __construct( |
35
|
|
|
OpeningTime $opens, |
36
|
|
|
OpeningTime $closes, |
37
|
|
|
DayOfWeekCollection $dayOfWeekCollection |
38
|
|
|
) { |
39
|
|
|
$this->dayOfWeekCollection = $dayOfWeekCollection; |
40
|
|
|
$this->opens = $opens; |
41
|
|
|
$this->closes = $closes; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return OpeningTime |
46
|
|
|
*/ |
47
|
|
|
public function getOpens() |
48
|
|
|
{ |
49
|
|
|
return $this->opens; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return OpeningTime |
54
|
|
|
*/ |
55
|
|
|
public function getCloses() |
56
|
|
|
{ |
57
|
|
|
return $this->closes; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return DayOfWeekCollection |
62
|
|
|
*/ |
63
|
|
|
public function getDayOfWeekCollection() |
64
|
|
|
{ |
65
|
|
|
return $this->dayOfWeekCollection; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param DayOfWeekCollection $dayOfWeekCollection |
70
|
|
|
*/ |
71
|
|
|
public function addDayOfWeekCollection(DayOfWeekCollection $dayOfWeekCollection) |
72
|
|
|
{ |
73
|
|
|
foreach ($dayOfWeekCollection->getDaysOfWeek() as $dayOfWeek) { |
74
|
|
|
$this->dayOfWeekCollection->addDayOfWeek($dayOfWeek); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param OpeningHour $otherOpeningHour |
80
|
|
|
* @return bool |
81
|
|
|
*/ |
82
|
|
|
public function hasEqualHours(OpeningHour $otherOpeningHour) |
83
|
|
|
{ |
84
|
|
|
return $otherOpeningHour->getOpens()->sameValueAs($this->getOpens()) && |
85
|
|
|
$otherOpeningHour->getCloses()->sameValueAs($this->getCloses()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @inheritdoc |
90
|
|
|
*/ |
91
|
|
|
public static function deserialize(array $data) |
92
|
|
|
{ |
93
|
|
|
return new static( |
94
|
|
|
OpeningTime::fromNativeString($data['opens']), |
95
|
|
|
OpeningTime::fromNativeString($data['closes']), |
96
|
|
|
DayOfWeekCollection::deserialize($data['dayOfWeek']) |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @inheritdoc |
102
|
|
|
*/ |
103
|
|
|
public function serialize() |
104
|
|
|
{ |
105
|
|
|
return [ |
106
|
|
|
'opens' => $this->opens->toNativeString(), |
107
|
|
|
'closes' => $this->closes->toNativeString(), |
108
|
|
|
'dayOfWeek' => $this->dayOfWeekCollection->serialize(), |
109
|
|
|
]; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param Udb3ModelOpeningHour $openingHour |
114
|
|
|
* @return self |
115
|
|
|
*/ |
116
|
|
|
public static function fromUdb3ModelOpeningHour(Udb3ModelOpeningHour $openingHour) |
117
|
|
|
{ |
118
|
|
|
return new OpeningHour( |
119
|
|
|
OpeningTime::fromUdb3ModelTime($openingHour->getOpeningTime()), |
120
|
|
|
OpeningTime::fromUdb3ModelTime($openingHour->getClosingTime()), |
121
|
|
|
DayOfWeekCollection::fromUdb3ModelDays($openingHour->getDays()) |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|