1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WITR\Schedule; |
4
|
|
|
|
5
|
|
|
use WITR\Show; |
6
|
|
|
use WITR\User; |
7
|
|
|
use Carbon\Carbon; |
8
|
|
|
|
9
|
|
|
class ScheduledShow |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
protected $show; |
13
|
|
|
protected $dj; |
14
|
|
|
protected $startingHour; |
15
|
|
|
protected $endingHour; |
16
|
|
|
protected $id; |
17
|
|
|
protected $dayOfWeek; |
18
|
|
|
|
19
|
|
|
public static function fromShowAndDJ($show, $dj) |
20
|
|
|
{ |
21
|
|
|
$scheduledShow = new ScheduledShow(); |
22
|
|
|
|
23
|
|
|
$scheduledShow->show = $show; |
24
|
|
|
$scheduledShow->dj = $dj; |
25
|
|
|
|
26
|
|
|
return $scheduledShow; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function dj() |
30
|
|
|
{ |
31
|
|
|
return $this->dj->name; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function djId() |
35
|
|
|
{ |
36
|
|
|
return $this->dj->id; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function show() |
40
|
|
|
{ |
41
|
|
|
return $this->show->name; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function showId() |
45
|
|
|
{ |
46
|
|
|
return $this->show->id; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function djPicture() |
50
|
|
|
{ |
51
|
|
|
return $this->dj->picture; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function showPicture() |
55
|
|
|
{ |
56
|
|
|
return $this->show->show_picture; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function sliderPicture() |
60
|
|
|
{ |
61
|
|
|
return $this->show->slider_picture; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function sliderStyle() |
65
|
|
|
{ |
66
|
|
|
return $this->show->style; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function startsAt($startingHour) |
70
|
|
|
{ |
71
|
|
|
$this->startingHour = $startingHour; |
72
|
|
|
$this->endingHour = $startingHour; |
73
|
|
|
$this->extendShowByHour(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function start() |
77
|
|
|
{ |
78
|
|
|
return $this->startingHour; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function end() |
82
|
|
|
{ |
83
|
|
|
return $this->endingHour; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function extendShowByHour() |
87
|
|
|
{ |
88
|
|
|
$this->endingHour++; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function timespan() |
92
|
|
|
{ |
93
|
|
|
$suffix = $this->endingHour < 12 || $this->endingHour > 24 ? 'AM' : 'PM'; |
94
|
|
|
$endingHour = $this->hourAdjusted($this->endingHour); |
95
|
|
|
$startingHour = $this->hourAdjusted($this->startingHour); |
96
|
|
|
return $startingHour . ' - ' . $endingHour . ' ' . $suffix; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
private function hourAdjusted($hour) |
100
|
|
|
{ |
101
|
|
|
while ($hour > 12) { |
102
|
|
|
$hour -= 12; |
103
|
|
|
} |
104
|
|
|
return $hour; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function airsDayOfWeek($airsDayOfWeek) |
108
|
|
|
{ |
109
|
|
|
$this->dayOfWeek = $airsDayOfWeek; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getAirDate() |
113
|
|
|
{ |
114
|
|
|
return Weekday::display($this->dayOfWeek); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function getRelativeAirDate() |
118
|
|
|
{ |
119
|
|
|
$now = ScheduleTime::now(); |
120
|
|
|
if ($this->dayOfWeek == $now->dayOfWeek) |
|
|
|
|
121
|
|
|
{ |
122
|
|
|
return 'Today'; |
123
|
|
|
} |
124
|
|
|
else if ($this->dayOfWeek == $now->addDay()->dayOfWeek) |
|
|
|
|
125
|
|
|
{ |
126
|
|
|
return 'Tomorrow'; |
127
|
|
|
} |
128
|
|
|
else |
129
|
|
|
{ |
130
|
|
|
return $this->getAirDate(); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
public function airDayOfWeek() |
136
|
|
|
{ |
137
|
|
|
return $this->dayOfWeek; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function showDescription() |
141
|
|
|
{ |
142
|
|
|
return $this->show->description; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function setId($id) |
146
|
|
|
{ |
147
|
|
|
$this->id = $id; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function id() |
151
|
|
|
{ |
152
|
|
|
return $this->id; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function nowPlaying() |
156
|
|
|
{ |
157
|
|
|
$today = ScheduleTime::now(); |
158
|
|
|
|
159
|
|
|
if ($this->airDayOfWeek() != $today->dayOfWeek()) |
160
|
|
|
{ |
161
|
|
|
return false; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
if ($this->startingHour > $today->hour() || $this->endingHour <= $today->hour()) |
165
|
|
|
{ |
166
|
|
|
return false; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return true; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.