|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class CalendarMonthView extends CalendarAbstractWeekView |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
|
|
6
|
|
|
// Attributes |
|
7
|
|
|
|
|
8
|
|
|
private $monthClass; |
|
9
|
|
|
|
|
10
|
|
|
// Abstract Functions Implemented |
|
11
|
|
|
|
|
12
|
|
|
public function init() |
|
13
|
|
|
{ |
|
14
|
|
|
parent::init(); |
|
15
|
|
|
$this->containerClass = 'monthView'; |
|
16
|
|
|
$this->innerClass = 'month'; |
|
17
|
|
|
$this->viewTitle = 'return date(\'F Y\', $date);'; |
|
18
|
|
|
$this->monthClass = 'return strtolower(date(\'F\', $monthDate));'; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function needsMonth() |
|
22
|
|
|
{ |
|
23
|
|
|
return true; |
|
24
|
|
|
} |
|
25
|
|
|
public function needsDay() |
|
26
|
|
|
{ |
|
27
|
|
|
return false; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function prevLinkParams(Calendar $calendar) |
|
31
|
|
|
{ |
|
32
|
|
|
$date = mktime(0, 0, 0, $calendar->getMonth() - $this->number, 1, $calendar->getYear()); |
|
33
|
|
|
return $this->getLinkParams($date); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function nextLinkParams(Calendar $calendar) |
|
37
|
|
|
{ |
|
38
|
|
|
$date = mktime(0, 0, 0, $calendar->getMonth() + $this->number, 1, $calendar->getYear()); |
|
39
|
|
|
return $this->getLinkParams($date); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function viewLinkParamsAndTitle(Calendar $calendar) |
|
43
|
|
|
{ |
|
44
|
|
|
$month = $calendar->getMonth(); |
|
45
|
|
|
if (! $month) { |
|
46
|
|
|
$month = 1; |
|
47
|
|
|
} |
|
48
|
|
|
$year = $calendar->getYear(); |
|
49
|
|
|
$date = mktime(0, 0, 0, $month, 1, $year); |
|
50
|
|
|
$params = $this->getLinkParams($date); |
|
51
|
|
|
$title = $this->getCustomisedTitle($month, $year); |
|
52
|
|
|
return array($params, $title); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getLinkParams($date) |
|
56
|
|
|
{ |
|
57
|
|
|
return array( |
|
58
|
|
|
'year' => date('Y', $date), |
|
59
|
|
|
'month' => date('n', $date) |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function title() |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
|
|
return $this->number == 1 ? 'month' : "$this->number months"; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function DateTitle(Calendar $calendar) |
|
|
|
|
|
|
69
|
|
|
{ |
|
70
|
|
|
return $this->getCustomisedTitle($calendar->getMonth(), $calendar->getYear()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function Weeks(Calendar $calendar) |
|
74
|
|
|
{ |
|
75
|
|
|
$year = $calendar->getYear(); |
|
76
|
|
|
$month = $calendar->getMonth(); |
|
77
|
|
|
|
|
78
|
|
|
$nowYear = date('Y'); |
|
79
|
|
|
$nowMonth = date('n'); |
|
80
|
|
|
|
|
81
|
|
|
for ($i = 0; $i < $this->number; $i++) { |
|
82
|
|
|
$weeksGroup = $this->MonthWeeks($month, $year); |
|
83
|
|
|
|
|
84
|
|
|
// 1) Single Values |
|
85
|
|
|
|
|
86
|
|
|
$monthDate = mktime(0, 0, 0, $month, 1, $year); |
|
|
|
|
|
|
87
|
|
|
$values['ExtraInnerClass'] = eval($this->monthClass) . " year$year"; |
|
|
|
|
|
|
88
|
|
|
$values['IsNowYear'] = $year == $nowYear; |
|
|
|
|
|
|
89
|
|
|
$values['IsPastYear'] = $year < $nowYear; |
|
90
|
|
|
$values['IsNow'] = $values['IsNowYear'] && $month == $nowMonth; |
|
91
|
|
|
$values['IsPast'] = $values['IsPastYear'] || ($values['IsNowYear'] && $month < $nowMonth); |
|
92
|
|
|
|
|
93
|
|
|
$weeksGroups[] = array($weeksGroup, $values); |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
if (++$month > 12) { |
|
96
|
|
|
$month = 1; |
|
97
|
|
|
$year++; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $weeksGroups; |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
// Private Functions |
|
105
|
|
|
|
|
106
|
|
|
protected function MonthWeeks($month, $year) |
|
107
|
|
|
{ |
|
108
|
|
|
$firstDate = mktime(0, 0, 0, $month, 1, $year); |
|
109
|
|
|
$firstDateWeek = date('W', $firstDate); |
|
110
|
|
|
$firstDateWeekYear = $year; |
|
111
|
|
|
|
|
112
|
|
|
if ($month == 1 && $firstDateWeek >= 52) { |
|
113
|
|
|
$firstDateWeekYear--; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$weekFirstDate = $this->getWeekStartDay($firstDateWeek, $firstDateWeekYear, true); |
|
117
|
|
|
$nextWeekFirstDate = mktime(0, 0, 0, date('n', $weekFirstDate), date('j', $weekFirstDate) + 7, date('Y', $weekFirstDate)); |
|
118
|
|
|
|
|
119
|
|
|
if (date('j', $nextWeekFirstDate) == 1) { |
|
120
|
|
|
$weekFirstDate = $nextWeekFirstDate; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
while (date('Y', $weekFirstDate) < $year || (date('Y', $weekFirstDate) == $year && date('n', $weekFirstDate) <= $month)) { |
|
124
|
|
|
$weekMonday = $weekFirstDate; |
|
125
|
|
View Code Duplication |
while (date('N', $weekMonday) != 1) { |
|
|
|
|
|
|
126
|
|
|
$weekMonday = mktime(0, 0, 0, date('n', $weekMonday), date('j', $weekMonday) + 1, date('Y', $weekMonday)); |
|
127
|
|
|
} |
|
128
|
|
|
$week = date('W', $weekMonday); |
|
129
|
|
|
$yearOfWeek = date('Y', $weekMonday); |
|
130
|
|
|
if ($month == 1) { |
|
131
|
|
|
if ($week == 1 && $yearOfWeek == $year - 1) { |
|
132
|
|
|
$yearOfWeek++; |
|
133
|
|
|
} elseif ($week >= 52 && $yearOfWeek == $year) { |
|
134
|
|
|
$yearOfWeek--; |
|
135
|
|
|
} |
|
136
|
|
|
} elseif ($month == 12 && $week == 1) { |
|
137
|
|
|
$yearOfWeek++; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
$weeks[] = array('week' => $week, 'yearOfWeek' => $yearOfWeek, 'month' => $month, 'yearOfMonth' => $year); |
|
|
|
|
|
|
141
|
|
|
$weekFirstDate = mktime(0, 0, 0, date('n', $weekFirstDate), date('j', $weekFirstDate) + 7, date('Y', $weekFirstDate)); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
return $weeks; |
|
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
// Other Functions |
|
148
|
|
|
|
|
149
|
|
View Code Duplication |
public function getCustomisedTitle($month, $year) |
|
|
|
|
|
|
150
|
|
|
{ |
|
151
|
|
|
$date = mktime(0, 0, 0, $month, 1, $year); |
|
|
|
|
|
|
152
|
|
|
$result = eval($this->viewTitle); |
|
|
|
|
|
|
153
|
|
|
if ($this->number > 1) { |
|
154
|
|
|
$date = mktime(0, 0, 0, $month + $this->number - 1, 1, $year); |
|
|
|
|
|
|
155
|
|
|
$result .= $this->viewTitleDelimiter . eval($this->viewTitle); |
|
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
return $result; |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
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.