|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class CalendarWeekView extends CalendarAbstractTimeView |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
|
|
6
|
|
|
// Attributes |
|
7
|
|
|
|
|
8
|
|
|
private $dayStart = 1; |
|
9
|
|
|
private $daysRemoved = array(); |
|
10
|
|
|
|
|
11
|
|
|
// Abstract Functions Implemented |
|
12
|
|
|
|
|
13
|
|
|
public function init() |
|
14
|
|
|
{ |
|
15
|
|
|
parent::init(); |
|
16
|
|
|
$this->containerClass = 'weekView'; |
|
17
|
|
|
$this->innerClass = 'week'; |
|
18
|
|
|
$this->viewTitle = 'return \'Week Of \' . date(\'l jS F Y\', $date);'; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
View Code Duplication |
public function prevLinkParams(Calendar $calendar) |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
|
|
$date = $this->getWeekStartDay($calendar->getDay(), $calendar->getMonth(), $calendar->getYear()); |
|
24
|
|
|
$dayValue = date('j', $date) - ($this->number * 7); |
|
25
|
|
|
$monthValue = date('n', $date); |
|
26
|
|
|
$yearValue = date('Y', $date); |
|
27
|
|
|
$date = mktime(0, 0, 0, $monthValue, $dayValue, $yearValue); |
|
28
|
|
|
return $this->getLinkParams($date); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
View Code Duplication |
public function nextLinkParams(Calendar $calendar) |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
$date = $this->getWeekStartDay($calendar->getDay(), $calendar->getMonth(), $calendar->getYear()); |
|
34
|
|
|
$dayValue = date('j', $date) + ($this->number * 7); |
|
35
|
|
|
$monthValue = date('n', $date); |
|
36
|
|
|
$yearValue = date('Y', $date); |
|
37
|
|
|
$date = mktime(0, 0, 0, $monthValue, $dayValue, $yearValue); |
|
38
|
|
|
return $this->getLinkParams($date); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function title() |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
|
|
return $this->number == 1 ? 'week' : "$this->number weeks"; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function Dates(Calendar $calendar) |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
|
|
$year = $calendar->getYear(); |
|
49
|
|
|
$month = $calendar->getMonth(); |
|
50
|
|
|
$day = $calendar->getDay(); |
|
51
|
|
|
|
|
52
|
|
|
if (count($this->daysRemoved) == 7) { |
|
53
|
|
|
return $datesGroups; |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$lastDate = $this->getWeekStartDay($day, $month, $year); |
|
57
|
|
|
|
|
58
|
|
View Code Duplication |
while (date('N', $lastDate) != $this->dayStart) { |
|
|
|
|
|
|
59
|
|
|
$lastDate = mktime(0, 0, 0, date('n', $lastDate), date('j', $lastDate) - 1, date('Y', $lastDate)); |
|
60
|
|
|
} |
|
61
|
|
View Code Duplication |
while (in_array(date('N', $lastDate), $this->daysRemoved)) { |
|
|
|
|
|
|
62
|
|
|
$lastDate = mktime(0, 0, 0, date('n', $lastDate), date('j', $lastDate) + 1, date('Y', $lastDate)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
for ($i = 0; $i < $this->number; $i++) { |
|
66
|
|
|
$datesGroup = array(); |
|
67
|
|
|
for ($j = 0; $j < 7; $j++) { |
|
68
|
|
|
if (! in_array(date('N', $lastDate), $this->daysRemoved)) { |
|
69
|
|
|
$datesGroup[] = $lastDate; |
|
70
|
|
|
} |
|
71
|
|
|
$lastDate = mktime(0, 0, 0, date('n', $lastDate), date('j', $lastDate) + 1, date('Y', $lastDate)); |
|
72
|
|
|
} |
|
73
|
|
|
$datesGroups[] = $datesGroup; |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $datesGroups; |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getCustomisedTitle($day, $month, $year) |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
$date = $this->getWeekStartDay($day, $month, $year); |
|
82
|
|
|
$result = eval($this->viewTitle); |
|
|
|
|
|
|
83
|
|
|
if ($this->number > 1) { |
|
84
|
|
|
$dayValue = date('j', $date) + (($this->number - 1) * 7); |
|
85
|
|
|
$monthValue = date('n', $date); |
|
86
|
|
|
$yearValue = date('Y', $date); |
|
87
|
|
|
$date = mktime(0, 0, 0, $monthValue, $dayValue, $yearValue); |
|
|
|
|
|
|
88
|
|
|
$result .= $this->viewTitleDelimiter . eval($this->viewTitle); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
return $result; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
// Functions |
|
94
|
|
|
|
|
95
|
|
|
public function startByMonday() |
|
96
|
|
|
{ |
|
97
|
|
|
$this->dayStart = 1; |
|
98
|
|
|
} |
|
99
|
|
|
public function startByTuesday() |
|
100
|
|
|
{ |
|
101
|
|
|
$this->dayStart = 2; |
|
102
|
|
|
} |
|
103
|
|
|
public function startByWednesday() |
|
104
|
|
|
{ |
|
105
|
|
|
$this->dayStart = 3; |
|
106
|
|
|
} |
|
107
|
|
|
public function startByThursday() |
|
108
|
|
|
{ |
|
109
|
|
|
$this->dayStart = 4; |
|
110
|
|
|
} |
|
111
|
|
|
public function startByFriday() |
|
112
|
|
|
{ |
|
113
|
|
|
$this->dayStart = 5; |
|
114
|
|
|
} |
|
115
|
|
|
public function startBySaturday() |
|
116
|
|
|
{ |
|
117
|
|
|
$this->dayStart = 6; |
|
118
|
|
|
} |
|
119
|
|
|
public function startBySunday() |
|
120
|
|
|
{ |
|
121
|
|
|
$this->dayStart = 7; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function removeMonday() |
|
125
|
|
|
{ |
|
126
|
|
|
$this->removeDay(1); |
|
127
|
|
|
} |
|
128
|
|
|
public function removeTuesday() |
|
129
|
|
|
{ |
|
130
|
|
|
$this->removeDay(2); |
|
131
|
|
|
} |
|
132
|
|
|
public function removeWednesday() |
|
133
|
|
|
{ |
|
134
|
|
|
$this->removeDay(3); |
|
135
|
|
|
} |
|
136
|
|
|
public function removeThursday() |
|
137
|
|
|
{ |
|
138
|
|
|
$this->removeDay(4); |
|
139
|
|
|
} |
|
140
|
|
|
public function removeFriday() |
|
141
|
|
|
{ |
|
142
|
|
|
$this->removeDay(5); |
|
143
|
|
|
} |
|
144
|
|
|
public function removeSaturday() |
|
145
|
|
|
{ |
|
146
|
|
|
$this->removeDay(6); |
|
147
|
|
|
} |
|
148
|
|
|
public function removeSunday() |
|
149
|
|
|
{ |
|
150
|
|
|
$this->removeDay(7); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
// Private Functions |
|
154
|
|
|
|
|
155
|
|
|
private function getWeekStartDay($day, $month, $year) |
|
156
|
|
|
{ |
|
157
|
|
|
$date = mktime(0, 0, 0, $month, $day, $year); |
|
158
|
|
|
|
|
159
|
|
View Code Duplication |
while (date('N', $date) > 1) { // It means that the 1st day of this week is not Monday |
|
|
|
|
|
|
160
|
|
|
$date = mktime(0, 0, 0, date('n', $date), date('j', $date) - 1, date('Y', $date)); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
return $date; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
private function getWeekEndDay($day, $month, $year) |
|
167
|
|
|
{ |
|
168
|
|
|
$date = $this->getWeekStartDay($day, $month, $year); |
|
169
|
|
|
$date = mktime(0, 0, 0, date('n', $date), date('j', $date) + 6, date('Y', $date)); |
|
170
|
|
|
return $date; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
private function removeDay($day) |
|
174
|
|
|
{ |
|
175
|
|
|
if (! in_array($day, $this->daysRemoved)) { |
|
176
|
|
|
$this->daysRemoved[] = $day; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|
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.