|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
abstract class CalendarAbstractTimeView extends CalendarAbstractView |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
|
|
6
|
|
|
// Attributes |
|
7
|
|
|
|
|
8
|
|
|
private $timePeriod; |
|
9
|
|
|
private $subPeriodsLength; |
|
10
|
|
|
private $subPeriodsRemoved = array(); |
|
11
|
|
|
|
|
12
|
|
|
protected $timeTitle; |
|
13
|
|
|
protected $dayTitleClass; |
|
14
|
|
|
protected $dayTitle; |
|
15
|
|
|
protected $timeClass; |
|
16
|
|
|
protected $time; |
|
17
|
|
|
protected $dayClass; |
|
18
|
|
|
|
|
19
|
|
|
// Abstract Functions Implemented |
|
20
|
|
|
|
|
21
|
|
|
public function init() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->timePeriod = new CalendarTimePeriod(new CalendarTime(), new CalendarTime(23, 59, 59)); |
|
24
|
|
|
$this->subPeriodsLength = new CalendarTime(1); |
|
25
|
|
|
|
|
26
|
|
|
$this->dayTitleClass = 'return strtolower(date(\'l\', $date));'; |
|
27
|
|
|
$this->dayTitle = 'return date(\'l jS F Y\', $date);'; |
|
28
|
|
|
$this->timeClass = 'return \'hour\' . date(\'H\', $subPeriodStartDateTime) . \' minute\' . date(\'i\', $subPeriodStartDateTime) . \' second\' . date(\'s\', $subPeriodStartDateTime);'; |
|
29
|
|
|
$this->time = 'return date(\'H:i\', $subPeriodStartDateTime);'; |
|
30
|
|
|
$this->dayClass = 'return strtolower(date(\'l\', $subPeriodStart));'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function needsMonth() |
|
34
|
|
|
{ |
|
35
|
|
|
return true; |
|
36
|
|
|
} |
|
37
|
|
|
public function needsDay() |
|
38
|
|
|
{ |
|
39
|
|
|
return true; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function Calendars(Calendar $calendar) |
|
43
|
|
|
{ |
|
44
|
|
|
$datesGroups = $this->Dates($calendar); |
|
45
|
|
|
|
|
46
|
|
|
foreach ($datesGroups as $datesGroup) { |
|
47
|
|
|
$calendars[] = $this->Calendar($datesGroup, $calendar); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return new ArrayList($calendars); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function viewLinkParamsAndTitle(Calendar $calendar) |
|
54
|
|
|
{ |
|
55
|
|
|
$day = $calendar->getDay(); |
|
56
|
|
|
if (! $day) { |
|
57
|
|
|
$day = 1; |
|
58
|
|
|
} |
|
59
|
|
|
$month = $calendar->getMonth(); |
|
60
|
|
|
if (! $month) { |
|
61
|
|
|
$month = 1; |
|
62
|
|
|
} |
|
63
|
|
|
$year = $calendar->getYear(); |
|
64
|
|
|
$date = mktime(0, 0, 0, $month, $day, $year); |
|
65
|
|
|
$params = $this->getLinkParams($date); |
|
66
|
|
|
$title = $this->getCustomisedTitle($day, $month, $year); |
|
67
|
|
|
return array($params, $title); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getLinkParams($date) |
|
71
|
|
|
{ |
|
72
|
|
|
return array( |
|
73
|
|
|
'year' => date('Y', $date), |
|
74
|
|
|
'month' => date('n', $date), |
|
75
|
|
|
'day' => date('j', $date) |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function DateTitle(Calendar $calendar) |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
return $this->getCustomisedTitle($calendar->getDay(), $calendar->getMonth(), $calendar->getYear()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
// Functions |
|
85
|
|
|
|
|
86
|
|
|
public function setTimePeriod(CalendarTimePeriod $timePeriod) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->timePeriod = $timePeriod; |
|
89
|
|
|
} |
|
90
|
|
|
public function setSubPeriodsLength(CalendarTime $subPeriodsLength) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->subPeriodsLength = $subPeriodsLength; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function removeSubPeriods($subPeriods) |
|
96
|
|
|
{ |
|
97
|
|
|
if (! is_array($subPeriods)) { |
|
98
|
|
|
$subPeriods = array($subPeriods); |
|
99
|
|
|
} |
|
100
|
|
|
foreach ($subPeriods as $subPeriod) { |
|
101
|
|
|
if (is_a($subPeriod, 'CalendarTimePeriod')) { |
|
102
|
|
|
$this->subPeriodsRemoved[] = $subPeriod; |
|
103
|
|
|
} else { |
|
104
|
|
|
user_error('CalendarAbstractTimeView::removeSubPeriods() : you cannot remove a period which class is not \'CalendarTimePeriod\'', E_USER_ERROR); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getSubPeriods() |
|
110
|
|
|
{ |
|
111
|
|
|
$startSubPeriodTime = $this->timePeriod->getStartTime(); |
|
112
|
|
|
$endTime = $this->timePeriod->getEndTime(); |
|
113
|
|
|
|
|
114
|
|
|
while ($startSubPeriodTime < $endTime) { |
|
115
|
|
|
$endSubPeriodTime = $this->getEndSubPeriodTime($startSubPeriodTime); |
|
116
|
|
|
$subPeriods[] = new CalendarTimePeriod($startSubPeriodTime, $endSubPeriodTime); |
|
|
|
|
|
|
117
|
|
|
$startSubPeriodTime = $endSubPeriodTime; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $subPeriods; |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function setTimeTitle($timeTitle) |
|
124
|
|
|
{ |
|
125
|
|
|
$this->timeTitle = $timeTitle; |
|
126
|
|
|
} |
|
127
|
|
|
public function setDayTitleClass($dayTitleClass) |
|
128
|
|
|
{ |
|
129
|
|
|
$this->dayTitleClass = $dayTitleClass; |
|
130
|
|
|
} |
|
131
|
|
|
public function setDayTitle($dayTitle) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->dayTitle = $dayTitle; |
|
134
|
|
|
} |
|
135
|
|
|
public function setTimeClass($timeClass) |
|
136
|
|
|
{ |
|
137
|
|
|
$this->timeClass = $timeClass; |
|
138
|
|
|
} |
|
139
|
|
|
public function setTime($time) |
|
140
|
|
|
{ |
|
141
|
|
|
$this->time = $time; |
|
142
|
|
|
} |
|
143
|
|
|
public function setDayClass($dayClass) |
|
144
|
|
|
{ |
|
145
|
|
|
$this->dayClass = $dayClass; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
// Private Functions |
|
149
|
|
|
|
|
150
|
|
|
private function getEndSubPeriodTime(CalendarTime $startSubPeriodTime) |
|
151
|
|
|
{ |
|
152
|
|
|
$endSubPeriodTime = $startSubPeriodTime->add($this->subPeriodsLength); |
|
153
|
|
|
|
|
154
|
|
|
if ($endSubPeriodTime < $startSubPeriodTime) { |
|
155
|
|
|
$endSubPeriodTime = clone $this->timePeriod->getEndTime(); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
return $endSubPeriodTime; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
// Abstract Functions |
|
162
|
|
|
|
|
163
|
|
|
abstract public function Dates(Calendar $calendar); |
|
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
abstract public function getCustomisedTitle($day, $month, $year); |
|
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
// Template Functions |
|
168
|
|
|
|
|
169
|
|
|
private function Calendar($dates, Calendar $currentCalendar) |
|
170
|
|
|
{ |
|
171
|
|
|
|
|
172
|
|
|
// 1) Single Values |
|
173
|
|
|
|
|
174
|
|
|
$calendar['InnerClass'] = $this->innerClass; |
|
|
|
|
|
|
175
|
|
|
$calendar['TimeTitle'] = $this->timeTitle; |
|
176
|
|
|
|
|
177
|
|
|
// 2) Days Values |
|
178
|
|
|
|
|
179
|
|
View Code Duplication |
foreach ($dates as $date) { |
|
|
|
|
|
|
180
|
|
|
$dayTitleClass = eval($this->dayTitleClass); |
|
|
|
|
|
|
181
|
|
|
$dayTitle = eval($this->dayTitle); |
|
|
|
|
|
|
182
|
|
|
$days[] = new ArrayData(array('DayTitleClass' => $dayTitleClass, 'DayTitle' => $dayTitle)); |
|
|
|
|
|
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
$calendar['Days'] = new ArrayList($days); |
|
|
|
|
|
|
186
|
|
|
|
|
187
|
|
|
// 3) Periods Values |
|
188
|
|
|
|
|
189
|
|
|
$subPeriods = $this->getSubPeriods(); |
|
190
|
|
|
|
|
191
|
|
|
$todayNow = mktime(); |
|
192
|
|
|
|
|
193
|
|
|
foreach ($subPeriods as $subPeriod) { |
|
194
|
|
|
$period = array(); |
|
195
|
|
|
|
|
196
|
|
|
$subPeriodStartTime = $subPeriod->getStartTime(); |
|
197
|
|
|
$subPeriodEndTime = $subPeriod->getEndTime(); |
|
198
|
|
|
|
|
199
|
|
|
$subPeriodStartTimeHours = $subPeriodStartTime->getHours(); |
|
200
|
|
|
$subPeriodEndTimeHours = $subPeriodEndTime->getHours(); |
|
201
|
|
|
|
|
202
|
|
|
$subPeriodStartTimeMinutes = $subPeriodStartTime->getMinutes(); |
|
203
|
|
|
$subPeriodEndTimeMinutes = $subPeriodEndTime->getMinutes(); |
|
204
|
|
|
|
|
205
|
|
|
$subPeriodStartTimeSeconds = $subPeriodStartTime->getSeconds(); |
|
206
|
|
|
$subPeriodEndTimeSeconds = $subPeriodEndTime->getSeconds(); |
|
207
|
|
|
|
|
208
|
|
|
$subPeriodStartDateTime = mktime($subPeriodStartTimeHours, $subPeriodStartTimeMinutes, $subPeriodStartTimeSeconds, 0, 0, 0); |
|
|
|
|
|
|
209
|
|
|
$subPeriodEndDateTime = mktime($subPeriodEndTimeHours, $subPeriodEndTimeMinutes, $subPeriodEndTimeSeconds, 0, 0, 0); |
|
|
|
|
|
|
210
|
|
|
|
|
211
|
|
|
// 1) Single Values |
|
212
|
|
|
|
|
213
|
|
|
$period['TimeClass'] = eval($this->timeClass); |
|
|
|
|
|
|
214
|
|
|
$period['Time'] = eval($this->time); |
|
|
|
|
|
|
215
|
|
|
|
|
216
|
|
|
// 2) Days Values |
|
217
|
|
|
|
|
218
|
|
|
$days = array(); |
|
219
|
|
|
|
|
220
|
|
|
foreach ($dates as $date) { |
|
221
|
|
|
$day = date('j', $date); |
|
222
|
|
|
$month = date('n', $date); |
|
223
|
|
|
$year = date('Y', $date); |
|
224
|
|
|
|
|
225
|
|
|
$subPeriodStart = mktime($subPeriodStartTimeHours, $subPeriodStartTimeMinutes, $subPeriodStartTimeSeconds, $month, $day, $year); |
|
226
|
|
|
$subPeriodEnd = mktime($subPeriodEndTimeHours, $subPeriodEndTimeMinutes, $subPeriodEndTimeSeconds, $month, $day, $year); |
|
227
|
|
|
|
|
228
|
|
|
$subPeriodParams = array(); |
|
229
|
|
|
|
|
230
|
|
|
$subPeriodParams['IsTodayNow'] = $subPeriodStart <= $todayNow && $todayNow <= $subPeriodEnd; |
|
231
|
|
|
$subPeriodParams['IsToday'] = $day == date('j') && $month == date('n') && $year == date('Y'); |
|
232
|
|
|
$subPeriodParams['IsPast'] = $subPeriodStart < $todayNow; |
|
233
|
|
|
$subPeriodParams['DayClass'] = eval($this->dayClass); |
|
|
|
|
|
|
234
|
|
|
|
|
235
|
|
|
$this->extend('updateSubPeriodParams', $subPeriodStart, $subPeriodEnd, $subPeriodParams, $currentCalendar); |
|
236
|
|
|
|
|
237
|
|
|
$days[] = new ArrayData($subPeriodParams); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
$period['Days'] = new ArrayList($days); |
|
241
|
|
|
|
|
242
|
|
|
$periods[] = new ArrayData($period); |
|
|
|
|
|
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
$calendar['Periods'] = new ArrayList($periods); |
|
|
|
|
|
|
246
|
|
|
|
|
247
|
|
|
return new ArrayData($calendar); |
|
248
|
|
|
} |
|
249
|
|
|
} |
|
250
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.