|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
abstract class CalendarAbstractWeekView extends CalendarAbstractView |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
|
|
6
|
|
|
// Attributes |
|
7
|
|
|
|
|
8
|
|
|
private $dayStart = 1; |
|
9
|
|
|
private $daysRemoved = array(); |
|
10
|
|
|
|
|
11
|
|
|
protected $showWeekLeft; |
|
12
|
|
|
protected $weekLeftTitle; |
|
13
|
|
|
protected $weekLeft; |
|
14
|
|
|
protected $showWeekRight; |
|
15
|
|
|
protected $weekRightTitle; |
|
16
|
|
|
protected $weekRight; |
|
17
|
|
|
protected $dayTitleClass; |
|
18
|
|
|
protected $dayTitle; |
|
19
|
|
|
protected $weekClass; |
|
20
|
|
|
protected $dayClass; |
|
21
|
|
|
|
|
22
|
|
|
private $weekLinkView; |
|
23
|
|
|
private $weekLinkCalendar; |
|
24
|
|
|
private $weekLinkController; |
|
25
|
|
|
|
|
26
|
|
|
private $dayLinkView; |
|
27
|
|
|
private $dayLinkCalendar; |
|
28
|
|
|
private $dayLinkController; |
|
29
|
|
|
|
|
30
|
|
|
// Abstract Functions Implemented |
|
31
|
|
|
|
|
32
|
|
|
public function init() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->weekLeft = $this->weekRight = 'return $week[\'week\'];'; |
|
35
|
|
|
$this->dayTitleClass = 'return strtolower(date(\'l\', $day));'; |
|
36
|
|
|
$this->dayTitle = 'return date(\'l\', $day);'; |
|
37
|
|
|
$this->weekClass = 'return \'week\' . $week[\'week\'] . \' year\' . $week[\'yearOfWeek\'];'; |
|
38
|
|
|
$this->dayClass = 'return strtolower(date(\'l\', $date));'; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function Calendars(Calendar $calendar) |
|
42
|
|
|
{ |
|
43
|
|
|
$weeksGroups = $this->Weeks($calendar); |
|
44
|
|
|
|
|
45
|
|
|
foreach ($weeksGroups as $weeksGroup) { |
|
46
|
|
|
list($weeksGroup, $values) = $weeksGroup; |
|
47
|
|
|
$calendars[] = $this->Calendar($weeksGroup, $values, $calendar); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return new ArrayList($calendars); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// Functions |
|
54
|
|
|
|
|
55
|
|
|
public function startByMonday() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->dayStart = 1; |
|
58
|
|
|
} |
|
59
|
|
|
public function startByTuesday() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->dayStart = 2; |
|
62
|
|
|
} |
|
63
|
|
|
public function startByWednesday() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->dayStart = 3; |
|
66
|
|
|
} |
|
67
|
|
|
public function startByThursday() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->dayStart = 4; |
|
70
|
|
|
} |
|
71
|
|
|
public function startByFriday() |
|
72
|
|
|
{ |
|
73
|
|
|
$this->dayStart = 5; |
|
74
|
|
|
} |
|
75
|
|
|
public function startBySaturday() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->dayStart = 6; |
|
78
|
|
|
} |
|
79
|
|
|
public function startBySunday() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->dayStart = 7; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function removeMonday() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->removeDay(1); |
|
87
|
|
|
} |
|
88
|
|
|
public function removeTuesday() |
|
89
|
|
|
{ |
|
90
|
|
|
$this->removeDay(2); |
|
91
|
|
|
} |
|
92
|
|
|
public function removeWednesday() |
|
93
|
|
|
{ |
|
94
|
|
|
$this->removeDay(3); |
|
95
|
|
|
} |
|
96
|
|
|
public function removeThursday() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->removeDay(4); |
|
99
|
|
|
} |
|
100
|
|
|
public function removeFriday() |
|
101
|
|
|
{ |
|
102
|
|
|
$this->removeDay(5); |
|
103
|
|
|
} |
|
104
|
|
|
public function removeSaturday() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->removeDay(6); |
|
107
|
|
|
} |
|
108
|
|
|
public function removeSunday() |
|
109
|
|
|
{ |
|
110
|
|
|
$this->removeDay(7); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function showWeekLeft() |
|
114
|
|
|
{ |
|
115
|
|
|
$this->showWeekLeft = true; |
|
116
|
|
|
} |
|
117
|
|
|
public function hideWeekLeft() |
|
118
|
|
|
{ |
|
119
|
|
|
$this->showWeekLeft = false; |
|
120
|
|
|
} |
|
121
|
|
|
public function setWeekLeftTitle($weekLeftTitle) |
|
122
|
|
|
{ |
|
123
|
|
|
$this->weekLeftTitle = $weekLeftTitle; |
|
124
|
|
|
} |
|
125
|
|
|
public function setWeekLeft($weekLeft) |
|
126
|
|
|
{ |
|
127
|
|
|
$this->weekLeft = $weekLeft; |
|
128
|
|
|
} |
|
129
|
|
|
public function showWeekRight() |
|
130
|
|
|
{ |
|
131
|
|
|
$this->showWeekRight = true; |
|
132
|
|
|
} |
|
133
|
|
|
public function hideWeekRight() |
|
134
|
|
|
{ |
|
135
|
|
|
$this->showWeekRight = false; |
|
136
|
|
|
} |
|
137
|
|
|
public function setWeekRightTitle($weekRightTitle) |
|
138
|
|
|
{ |
|
139
|
|
|
$this->weekRightTitle = $weekRightTitle; |
|
140
|
|
|
} |
|
141
|
|
|
public function setWeekRight($weekRight) |
|
142
|
|
|
{ |
|
143
|
|
|
$this->weekRight = $weekRight; |
|
144
|
|
|
} |
|
145
|
|
|
public function setDayTitleClass($dayTitleClass) |
|
146
|
|
|
{ |
|
147
|
|
|
$this->dayTitleClass = $dayTitleClass; |
|
148
|
|
|
} |
|
149
|
|
|
public function setDayTitle($dayTitle) |
|
150
|
|
|
{ |
|
151
|
|
|
$this->dayTitle = $dayTitle; |
|
152
|
|
|
} |
|
153
|
|
|
public function setWeekClass($weekClass) |
|
154
|
|
|
{ |
|
155
|
|
|
$this->weekClass = $weekClass; |
|
156
|
|
|
} |
|
157
|
|
|
public function setDayClass($dayClass) |
|
158
|
|
|
{ |
|
159
|
|
|
$this->dayClass = $dayClass; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
// Private Functions |
|
163
|
|
|
|
|
164
|
|
|
private function removeDay($day) |
|
165
|
|
|
{ |
|
166
|
|
|
if (! in_array($day, $this->daysRemoved)) { |
|
167
|
|
|
$this->daysRemoved[] = $day; |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
// Abstract Functions |
|
172
|
|
|
|
|
173
|
|
|
abstract public function Weeks(Calendar $calendar); |
|
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
// Template Functions |
|
176
|
|
|
|
|
177
|
|
|
protected function Calendar($weeks, $values, Calendar $currentCalendar) |
|
178
|
|
|
{ |
|
179
|
|
|
// 1) Single Values |
|
180
|
|
|
|
|
181
|
|
|
$calendar = $values; |
|
182
|
|
|
$calendar['InnerClass'] = $this->innerClass; |
|
183
|
|
|
$calendar['ShowWeekLeft'] = $this->showWeekLeft; |
|
184
|
|
|
$calendar['WeekLeftTitle'] = $this->weekLeftTitle; |
|
185
|
|
|
$calendar['ShowWeekRight'] = $this->showWeekRight; |
|
186
|
|
|
$calendar['WeekRightTitle'] = $this->weekRightTitle; |
|
187
|
|
|
//Hack |
|
188
|
|
|
$week = $weeks[1]['week']; |
|
189
|
|
|
$year = $weeks[1]['yearOfWeek']; |
|
190
|
|
|
$monthTitleDate = $this->getWeekStartDay($week, $year); |
|
191
|
|
|
$calendar['MonthTitle'] = date('F Y', $monthTitleDate); |
|
192
|
|
|
|
|
193
|
|
|
// 2) Days Values |
|
194
|
|
|
|
|
195
|
|
|
$daysByDateFormat = $this->DaysByDateFormat(); |
|
196
|
|
|
|
|
197
|
|
|
if (count($daysByDateFormat) == 0) { |
|
198
|
|
|
return new ArrayData($calendar); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
View Code Duplication |
foreach ($daysByDateFormat as $day) { |
|
|
|
|
|
|
202
|
|
|
$dayTitleClass = eval($this->dayTitleClass); |
|
|
|
|
|
|
203
|
|
|
$dayTitle = eval($this->dayTitle); |
|
|
|
|
|
|
204
|
|
|
$days[] = new ArrayData(array('DayTitleClass' => $dayTitleClass, 'DayTitle' => $dayTitle)); |
|
|
|
|
|
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
$calendar['Days'] = new ArrayList($days); |
|
|
|
|
|
|
208
|
|
|
|
|
209
|
|
|
// 3) Weeks Values |
|
210
|
|
|
|
|
211
|
|
|
$today = mktime(0, 0, 0, date('n'), date('j'), date('Y')); |
|
212
|
|
|
|
|
213
|
|
|
foreach ($weeks as $week) { |
|
214
|
|
|
$period = array(); |
|
215
|
|
|
|
|
216
|
|
|
// 1) Single Values |
|
217
|
|
|
|
|
218
|
|
|
$period['WeekClass'] = eval($this->weekClass); |
|
|
|
|
|
|
219
|
|
|
$period['ShowWeekLeft'] = $this->showWeekLeft; |
|
220
|
|
|
$period['WeekLeft'] = eval($this->weekLeft); |
|
|
|
|
|
|
221
|
|
|
$period['ShowWeekRight'] = $this->showWeekRight; |
|
222
|
|
|
$period['WeekRight'] = eval($this->weekRight); |
|
|
|
|
|
|
223
|
|
|
|
|
224
|
|
|
if ($this->weekLinkView) { |
|
225
|
|
|
$date = $this->getWeekStartDay($week['week'], $week['yearOfWeek']); |
|
226
|
|
|
$linkController = $currentCalendar->getController(); |
|
227
|
|
|
if ($this->weekLinkController) { |
|
228
|
|
|
$linkController = $this->weekLinkController; |
|
229
|
|
|
} |
|
230
|
|
|
$linkCalendar = $currentCalendar; |
|
231
|
|
|
if ($this->weekLinkCalendar) { |
|
232
|
|
|
$linkCalendar = $this->weekLinkCalendar; |
|
233
|
|
|
} |
|
234
|
|
|
$params = $this->weekLinkView->getLinkParams($date); |
|
235
|
|
|
$period['WeekLink'] = $linkCalendar->Link($linkController, $this->weekLinkView, $params); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
// 2) Days Values |
|
239
|
|
|
|
|
240
|
|
|
$days = array(); |
|
241
|
|
|
|
|
242
|
|
|
$dates = $this->WeekDates($daysByDateFormat, $week['week'], $week['yearOfWeek']); |
|
243
|
|
|
|
|
244
|
|
|
foreach ($dates as $date) { |
|
245
|
|
|
$day = date('j', $date); |
|
246
|
|
|
$month = date('n', $date); |
|
247
|
|
|
$year = date('Y', $date); |
|
248
|
|
|
|
|
249
|
|
|
$dateParams = array(); |
|
250
|
|
|
|
|
251
|
|
|
$dateParams['IsToday'] = $date == $today; |
|
252
|
|
|
$dateParams['IsPast'] = $date < $today; |
|
253
|
|
|
if ($month == $week['month']) { |
|
254
|
|
|
$dateParams['CurrentMonth'] = true; |
|
255
|
|
|
} elseif (($year == $week['yearOfMonth'] && $month < $week['month']) || ($year == $week['yearOfMonth'] - 1 && $month == 12)) { |
|
256
|
|
|
$dateParams['PrevMonth'] = true; |
|
257
|
|
|
if ($year == $week['yearOfMonth'] - 1) { |
|
258
|
|
|
$dateParams['PrevYear'] = true; |
|
259
|
|
|
} |
|
260
|
|
|
} else { |
|
261
|
|
|
$dateParams['NextMonth'] = true; |
|
262
|
|
|
if ($year == $week['yearOfMonth'] + 1) { |
|
263
|
|
|
$dateParams['NextYear'] = true; |
|
264
|
|
|
} |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
$dateParams['DayClass'] = eval($this->dayClass); |
|
|
|
|
|
|
268
|
|
|
$dateParams['Day'] = $day; |
|
269
|
|
|
|
|
270
|
|
|
if ($this->dayLinkView) { |
|
271
|
|
|
$linkController = $currentCalendar->getController(); |
|
272
|
|
|
if ($this->dayLinkController) { |
|
273
|
|
|
$linkController = $this->dayLinkController; |
|
274
|
|
|
} |
|
275
|
|
|
$linkCalendar = $currentCalendar; |
|
276
|
|
|
if ($this->dayLinkCalendar) { |
|
277
|
|
|
$linkCalendar = $this->dayLinkCalendar; |
|
278
|
|
|
} |
|
279
|
|
|
$params = $this->dayLinkView->getLinkParams($date); |
|
280
|
|
|
$dateParams['Link'] = $linkCalendar->Link($linkController, $this->dayLinkView, $params); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
|
|
284
|
|
|
|
|
285
|
|
|
$this->extend('updateDateParams', $date, $dateParams, $currentCalendar); |
|
286
|
|
|
|
|
287
|
|
|
$days[] = new ArrayData($dateParams); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
$period['Days'] = new ArrayList($days); |
|
291
|
|
|
|
|
292
|
|
|
$periods[] = new ArrayData($period); |
|
|
|
|
|
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
$calendar['Weeks'] = new ArrayList($periods); |
|
|
|
|
|
|
296
|
|
|
|
|
297
|
|
|
return new ArrayData($calendar); |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
public function WeekDates($days, $week, $year) |
|
301
|
|
|
{ |
|
302
|
|
|
$firstDate = $this->getWeekStartDay($week, $year); |
|
303
|
|
|
|
|
304
|
|
|
$beforeMonday = true; |
|
305
|
|
|
|
|
306
|
|
|
foreach ($days as $day) { |
|
307
|
|
|
$date = $firstDate; |
|
308
|
|
|
|
|
309
|
|
|
if (date('N', $day) == 1) { |
|
310
|
|
|
$beforeMonday = false; |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
while (date('N', $date) != date('N', $day)) { |
|
314
|
|
|
$date = mktime(0, 0, 0, date('n', $date), date('j', $date) + ($beforeMonday ? -1 : 1), date('Y', $date)); |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
$dates[] = $date; |
|
|
|
|
|
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
return $dates; |
|
|
|
|
|
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
private function DaysByDateFormat() |
|
324
|
|
|
{ |
|
325
|
|
|
$day = $this->dayStart; |
|
326
|
|
|
|
|
327
|
|
|
$days = array(); |
|
328
|
|
|
for ($i = 1; $i <= 7; $i++) { |
|
329
|
|
|
if (! in_array($day, $this->daysRemoved)) { |
|
330
|
|
|
$days[] = mktime(0, 0, 0, 1, $day, 1); |
|
331
|
|
|
} |
|
332
|
|
|
$day = $day < 7 ? $day + 1 : 1; |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
return $days; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
protected function getWeekStartDay($week, $year, $fromStartDay = false) |
|
339
|
|
|
{ |
|
340
|
|
|
|
|
341
|
|
|
// 1) Research of the week |
|
342
|
|
|
|
|
343
|
|
|
$firstDate = mktime(0, 0, 0, 1, 1, $year); |
|
344
|
|
View Code Duplication |
while (date('W', $firstDate) != 1) { |
|
|
|
|
|
|
345
|
|
|
$firstDate = mktime(0, 0, 0, date('n', $firstDate), date('j', $firstDate) + 1, date('Y', $firstDate)); |
|
346
|
|
|
} |
|
347
|
|
View Code Duplication |
while (date('W', $firstDate) < $week) { |
|
|
|
|
|
|
348
|
|
|
$firstDate = mktime(0, 0, 0, date('n', $firstDate), date('j', $firstDate) + 7, date('Y', $firstDate)); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
// 2) Research of the first day of the week |
|
352
|
|
|
|
|
353
|
|
|
$diff = date('N', $firstDate) - 1; |
|
354
|
|
|
if ($fromStartDay && $this->dayStart != 1) { |
|
355
|
|
|
$diff += 8 - $this->dayStart; |
|
356
|
|
|
} |
|
357
|
|
|
$firstDate = mktime(0, 0, 0, date('n', $firstDate), date('j', $firstDate) - $diff, date('Y', $firstDate)); |
|
358
|
|
|
|
|
359
|
|
|
return $firstDate; |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
// Link Functions |
|
363
|
|
|
|
|
364
|
|
|
public function linkWeekTo(CalendarWeekView $view, Calendar $calendar = null, $controller = null) |
|
365
|
|
|
{ |
|
366
|
|
|
$this->weekLinkView = $view; |
|
367
|
|
|
$this->weekLinkCalendar = $calendar; |
|
368
|
|
|
$this->weekLinkController = $controller; |
|
369
|
|
|
} |
|
370
|
|
|
|
|
371
|
|
|
public function linkDayTo(CalendarDayView $view, Calendar $calendar = null, $controller = null) |
|
372
|
|
|
{ |
|
373
|
|
|
$this->dayLinkView = $view; |
|
374
|
|
|
$this->dayLinkCalendar = $calendar; |
|
375
|
|
|
$this->dayLinkController = $controller; |
|
376
|
|
|
} |
|
377
|
|
|
} |
|
378
|
|
|
|
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.