|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class CalendarYearView extends CalendarMonthView |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
|
|
6
|
|
|
// Attributes |
|
7
|
|
|
|
|
8
|
|
|
private $monthStart = 1; |
|
9
|
|
|
private $monthsRemoved = array(); |
|
10
|
|
|
|
|
11
|
|
|
protected $monthInnerClass; |
|
12
|
|
|
protected $monthTitle; |
|
13
|
|
|
|
|
14
|
|
|
private $monthLinkView; |
|
15
|
|
|
private $monthLinkCalendar; |
|
16
|
|
|
private $monthLinkController; |
|
17
|
|
|
|
|
18
|
|
|
// Abstract Functions Implemented |
|
19
|
|
|
|
|
20
|
|
|
public function init() |
|
21
|
|
|
{ |
|
22
|
|
|
parent::init(); |
|
23
|
|
|
$this->containerClass = 'yearView'; |
|
24
|
|
|
$this->monthInnerClass = $this->innerClass; |
|
25
|
|
|
$this->viewTitle = 'return date(\'Y\', $date);'; |
|
26
|
|
|
$this->innerClass = 'year'; |
|
27
|
|
|
$this->monthTitle = 'return date(\'F Y\', $monthDate);'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function needsMonth() |
|
31
|
|
|
{ |
|
32
|
|
|
return false; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function Calendars(Calendar $calendar) |
|
36
|
|
|
{ |
|
37
|
|
|
$years = $this->Years($calendar); |
|
38
|
|
|
|
|
39
|
|
|
foreach ($years as $year) { |
|
40
|
|
|
$calendars[] = $this->YearCalendar($year, $calendar); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return new ArrayList($calendars); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function prevLinkParams(Calendar $calendar) |
|
47
|
|
|
{ |
|
48
|
|
|
$date = mktime(0, 0, 0, 1, 1, $calendar->getYear() - $this->number); |
|
49
|
|
|
return $this->getLinkParams($date); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function nextLinkParams(Calendar $calendar) |
|
53
|
|
|
{ |
|
54
|
|
|
$date = mktime(0, 0, 0, 1, 1, $calendar->getYear() + $this->number); |
|
55
|
|
|
return $this->getLinkParams($date); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function viewLinkParamsAndTitle(Calendar $calendar) |
|
59
|
|
|
{ |
|
60
|
|
|
$year = $calendar->getYear(); |
|
61
|
|
|
$date = mktime(0, 0, 0, 1, 1, $year); |
|
62
|
|
|
$params = $this->getLinkParams($date); |
|
63
|
|
|
$title = $this->getCustomisedTitle($year); |
|
64
|
|
|
return array($params, $title); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getLinkParams($date) |
|
68
|
|
|
{ |
|
69
|
|
|
return array( |
|
70
|
|
|
'year' => date('Y', $date) |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function title() |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
return $this->number == 1 ? 'year' : "$this->number years"; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function DateTitle(Calendar $calendar) |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
return $this->getCustomisedTitle($calendar->getYear()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function Years(Calendar $calendar) |
|
85
|
|
|
{ |
|
86
|
|
|
$year = $calendar->getYear(); |
|
87
|
|
|
|
|
88
|
|
|
for ($i = 0; $i < $this->number; $i++) { |
|
89
|
|
|
$years[] = $year + $i; |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return $years; |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
// Functions |
|
96
|
|
|
|
|
97
|
|
|
public function startByJanuary() |
|
98
|
|
|
{ |
|
99
|
|
|
$this->monthStart = 1; |
|
100
|
|
|
} |
|
101
|
|
|
public function startByFebruary() |
|
102
|
|
|
{ |
|
103
|
|
|
$this->monthStart = 2; |
|
104
|
|
|
} |
|
105
|
|
|
public function startByMarch() |
|
106
|
|
|
{ |
|
107
|
|
|
$this->monthStart = 3; |
|
108
|
|
|
} |
|
109
|
|
|
public function startByApril() |
|
110
|
|
|
{ |
|
111
|
|
|
$this->monthStart = 4; |
|
112
|
|
|
} |
|
113
|
|
|
public function startByMay() |
|
114
|
|
|
{ |
|
115
|
|
|
$this->monthStart = 5; |
|
116
|
|
|
} |
|
117
|
|
|
public function startByJune() |
|
118
|
|
|
{ |
|
119
|
|
|
$this->monthStart = 6; |
|
120
|
|
|
} |
|
121
|
|
|
public function startByJuly() |
|
122
|
|
|
{ |
|
123
|
|
|
$this->monthStart = 7; |
|
124
|
|
|
} |
|
125
|
|
|
public function startByAugust() |
|
126
|
|
|
{ |
|
127
|
|
|
$this->monthStart = 8; |
|
128
|
|
|
} |
|
129
|
|
|
public function startBySeptember() |
|
130
|
|
|
{ |
|
131
|
|
|
$this->monthStart = 9; |
|
132
|
|
|
} |
|
133
|
|
|
public function startByOctober() |
|
134
|
|
|
{ |
|
135
|
|
|
$this->monthStart = 10; |
|
136
|
|
|
} |
|
137
|
|
|
public function startByNovember() |
|
138
|
|
|
{ |
|
139
|
|
|
$this->monthStart = 11; |
|
140
|
|
|
} |
|
141
|
|
|
public function startByDecember() |
|
142
|
|
|
{ |
|
143
|
|
|
$this->monthStart = 12; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function removeJanuary() |
|
147
|
|
|
{ |
|
148
|
|
|
$this->removeMonth(1); |
|
149
|
|
|
} |
|
150
|
|
|
public function removeFebruary() |
|
151
|
|
|
{ |
|
152
|
|
|
$this->removeMonth(2); |
|
153
|
|
|
} |
|
154
|
|
|
public function removeMarch() |
|
155
|
|
|
{ |
|
156
|
|
|
$this->removeMonth(3); |
|
157
|
|
|
} |
|
158
|
|
|
public function removeApril() |
|
159
|
|
|
{ |
|
160
|
|
|
$this->removeMonth(4); |
|
161
|
|
|
} |
|
162
|
|
|
public function removeMay() |
|
163
|
|
|
{ |
|
164
|
|
|
$this->removeMonth(5); |
|
165
|
|
|
} |
|
166
|
|
|
public function removeJune() |
|
167
|
|
|
{ |
|
168
|
|
|
$this->removeMonth(6); |
|
169
|
|
|
} |
|
170
|
|
|
public function removeJuly() |
|
171
|
|
|
{ |
|
172
|
|
|
$this->removeMonth(7); |
|
173
|
|
|
} |
|
174
|
|
|
public function removeAugust() |
|
175
|
|
|
{ |
|
176
|
|
|
$this->removeMonth(8); |
|
177
|
|
|
} |
|
178
|
|
|
public function removeSeptember() |
|
179
|
|
|
{ |
|
180
|
|
|
$this->removeMonth(9); |
|
181
|
|
|
} |
|
182
|
|
|
public function removeOctober() |
|
183
|
|
|
{ |
|
184
|
|
|
$this->removeMonth(10); |
|
185
|
|
|
} |
|
186
|
|
|
public function removeNovember() |
|
187
|
|
|
{ |
|
188
|
|
|
$this->removeMonth(11); |
|
189
|
|
|
} |
|
190
|
|
|
public function removeDecember() |
|
191
|
|
|
{ |
|
192
|
|
|
$this->removeMonth(12); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
// Private Functions |
|
196
|
|
|
|
|
197
|
|
|
private function removeMonth($month) |
|
198
|
|
|
{ |
|
199
|
|
|
if (! in_array($month, $this->monthsRemoved)) { |
|
200
|
|
|
$this->monthsRemoved[] = $month; |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
private function YearCalendar($year, Calendar $currentCalendar) |
|
205
|
|
|
{ |
|
206
|
|
|
|
|
207
|
|
|
// 1) Single Values |
|
208
|
|
|
|
|
209
|
|
|
$nowYear = date('Y'); |
|
210
|
|
|
$nowMonth = date('n'); |
|
211
|
|
|
|
|
212
|
|
|
$calendar['InnerClass'] = $this->innerClass; |
|
|
|
|
|
|
213
|
|
|
$calendar['ExtraInnerClass'] = "$this->innerClass$year"; |
|
214
|
|
|
$calendar['IsNow'] = $year == $nowYear; |
|
215
|
|
|
$calendar['IsPast'] = $year < $nowYear; |
|
216
|
|
|
|
|
217
|
|
|
// 2) Months Values |
|
218
|
|
|
|
|
219
|
|
|
$months = $this->Months(); |
|
220
|
|
|
|
|
221
|
|
|
if (count($months) == 0) { |
|
222
|
|
|
return new ArrayData($calendar); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
foreach ($months as $month) { |
|
226
|
|
|
$weeksGroups = $this->MonthWeeks($month, $year); |
|
227
|
|
|
|
|
228
|
|
|
// 1) Single Values |
|
229
|
|
|
|
|
230
|
|
|
$monthDate = mktime(0, 0, 0, $month, 1, $year); |
|
231
|
|
|
$values['IsNow'] = $calendar['IsNow'] && $month == $nowMonth; |
|
|
|
|
|
|
232
|
|
|
$values['IsPast'] = $calendar['IsPast'] || ($calendar['IsNow'] && $month < $nowMonth); |
|
|
|
|
|
|
233
|
|
|
$values['MonthClass'] = eval($this->monthClass); |
|
|
|
|
|
|
234
|
|
|
$values['MonthTitle'] = eval($this->monthTitle); |
|
|
|
|
|
|
235
|
|
|
|
|
236
|
|
|
$period = $this->Calendar($weeksGroups, $values, $currentCalendar); |
|
237
|
|
|
$period->setField('InnerClass', $this->monthInnerClass); |
|
238
|
|
|
|
|
239
|
|
|
if ($this->monthLinkView) { |
|
240
|
|
|
$linkController = $currentCalendar->getController(); |
|
241
|
|
|
if ($this->monthLinkController) { |
|
242
|
|
|
$linkController = $this->monthLinkController; |
|
243
|
|
|
} |
|
244
|
|
|
$linkCalendar = $currentCalendar; |
|
245
|
|
|
if ($this->monthLinkCalendar) { |
|
246
|
|
|
$linkCalendar = $this->monthLinkCalendar; |
|
247
|
|
|
} |
|
248
|
|
|
$params = $this->monthLinkView->getLinkParams($monthDate); |
|
249
|
|
|
$period->setField('Link', $linkCalendar->Link($linkController, $this->monthLinkView, $params)); |
|
250
|
|
|
} |
|
251
|
|
|
$periods[] = $period; |
|
|
|
|
|
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
$calendar['Months'] = new ArrayList($periods); |
|
|
|
|
|
|
255
|
|
|
|
|
256
|
|
|
return new ArrayData($calendar); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
private function Months() |
|
260
|
|
|
{ |
|
261
|
|
|
$month = $this->monthStart; |
|
262
|
|
|
|
|
263
|
|
|
$months = array(); |
|
264
|
|
|
while ($month <= 12) { |
|
265
|
|
|
if (! in_array($month, $this->monthsRemoved)) { |
|
266
|
|
|
$months[] = $month; |
|
267
|
|
|
} |
|
268
|
|
|
$month++; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
return $months; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
// Link Functions |
|
275
|
|
|
|
|
276
|
|
|
public function linkMonthTo(CalendarMonthView $view, Calendar $calendar = null, $controller = null) |
|
277
|
|
|
{ |
|
278
|
|
|
$this->monthLinkView = $view; |
|
279
|
|
|
$this->monthLinkCalendar = $calendar; |
|
280
|
|
|
$this->monthLinkController = $controller; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
// Other Functions |
|
284
|
|
|
|
|
285
|
|
View Code Duplication |
public function getCustomisedTitle($year) |
|
|
|
|
|
|
286
|
|
|
{ |
|
287
|
|
|
$date = mktime(0, 0, 0, 1, 1, $year); |
|
|
|
|
|
|
288
|
|
|
$result = eval($this->viewTitle); |
|
|
|
|
|
|
289
|
|
|
if ($this->number > 1) { |
|
290
|
|
|
$date = mktime(0, 0, 0, 1, 1, $year + $this->number - 1); |
|
|
|
|
|
|
291
|
|
|
$result .= $this->viewTitleDelimiter . eval($this->viewTitle); |
|
|
|
|
|
|
292
|
|
|
} |
|
293
|
|
|
return $result; |
|
294
|
|
|
} |
|
295
|
|
|
} |
|
296
|
|
|
|
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.