Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezdateoperatorcollection.php
Go to the documentation of this file.
1 <?php
11 class eZDateOperatorCollection
12 {
13 public $MonthOverviewName;
19 public function __construct( $monthName = 'month_overview' )
20 {
21 $this->MonthOverviewName = $monthName;
22 $this->Operators = array( $monthName );
23 }
24
28 function operatorList()
29 {
30 return $this->Operators;
31 }
32
36 function namedParameterPerOperator()
37 {
38 return true;
39 }
40
44 function namedParameterList()
45 {
46 return array( 'month_overview' => array( 'field' => array( 'type' => 'string',
47 'required' => true,
48 'default' => false ),
49 'date' => array( 'type' => 'integer',
50 'required' => true,
51 'default' => false ),
52 'optional' => array( 'type' => 'array',
53 'required' => false,
54 'default' => false ) ) );
55 }
56
57 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
58 {
59 $locale = eZLocale::instance();
60 if ( $operatorName == $this->MonthOverviewName )
61 {
62 $field = $namedParameters['field'];
63 $date = $namedParameters['date'];
64 if ( !$field )
65 return $tpl->missingParameter( $operatorName, 'field' );
66 if ( !$date )
67 return $tpl->missingParameter( $operatorName, 'date' );
68 $optional = $namedParameters['optional'];
69 $dateInfo = getdate( $date );
70 if ( is_array( $operatorValue ) )
71 {
72 $month = array();
73 $month['year'] = $dateInfo['year'];
74 $month['month'] = $locale->longMonthName( $dateInfo['mon'] );
75 $weekDays = $locale->weekDays();
76 $weekDaysMap = array();
77 $i = 0;
78 $dayNames = array( 0 => 'sun', 1 => 'mon', 2 => 'tue',
79 3 => 'wed', 4 => 'thu', 5 => 'fri', 6 => 'sat' );
80 foreach ( $weekDays as $weekDay )
81 {
82 $weekDaysMap[$weekDay] = $i;
83 $weekDayName = $locale->shortDayName( $weekDay );
84 $weekDayIdentifier = $dayNames[$weekDay];
85 $month['weekdays'][] = array( 'day' => $weekDayName,
86 'class' => $weekDayIdentifier );
87 ++$i;
88 }
89 $days = array();
90 $lastDay = getdate( mktime( 0, 0, 0, $dateInfo['mon']+1, 0, $dateInfo['year'] ) );
91 $lastDay = $lastDay['mday'];
92 for ( $day = 1; $day <= $lastDay; ++$day )
93 {
94 $days[$day] = false;
95 }
96 foreach ( $operatorValue as $item )
97 {
98 $value = null;
99 if ( is_object( $item ) and
100 method_exists( $item, 'hasAttribute' ) and
101 method_exists( $item, 'attribute' ) )
102 {
103 if ( $item->hasAttribute( $field ) )
104 $value = $item->attribute( $field );
105 }
106 else if ( is_array( $item ) )
107 {
108 if ( array_key_exists( $field, $item ) )
109 $value = $item[$field];
110 }
111 if ( $value !== null )
112 {
113 $info = getdate( $value );
114 if ( $info['year'] == $dateInfo['year'] and
115 $info['mon'] == $dateInfo['mon'] )
116 {
117 $days[$info['mday']] = true;
118 }
119 }
120 }
121 $currentDay = false;
122 if ( isset( $optional['current'] ) and $optional['current'] !== false )
123 {
124 $info = getdate( $optional['current'] );
125 $currentDay = $info['yday'];
126 }
127 $today = time();
128 $todayInfo = getdate( $today );
129 $todayClass = false;
130 if ( isset( $optional['today_class'] ) )
131 $todayClass = $optional['today_class'];
132 $dayClass = false;
133 if ( isset( $optional['day_class'] ) )
134 $dayClass = $optional['day_class'];
135 $link = false;
136 if ( isset( $optional['link'] ) )
137 $link = $optional['link'];
138 $yearLinkParameter = false;
139 $monthLinkParameter = false;
140 $dayLinkParameter = false;
141 if ( isset( $optional['year_link'] ) )
142 $yearLinkParameter = $optional['year_link'];
143 if ( isset( $optional['month_link'] ) )
144 $monthLinkParameter = $optional['month_link'];
145 if ( isset( $optional['day_link'] ) )
146 $dayLinkParameter = $optional['day_link'];
147 $weeks = array();
148 $lastWeek = 0;
149 for ( $day = 1; $day <= $lastDay; ++$day )
150 {
151 $timestamp = mktime( 0, 0, 0, $dateInfo['mon'], $day, $dateInfo['year'] );
152 $info = getdate( $timestamp );
153 $weekDay = $weekDaysMap[$info['wday']];
154
155 /*
156 * Attention: date('W') returns the week number according to
157 * ISO, which states that the week with the first Thursday
158 * in the new year is week 1.
159 */
160 $week = date( 'W', $timestamp );
161
162 if ( $weekDay == 0 && $weekDaysMap[0] == 0 )
163 {
164 ++$week;
165 }
166
167 /*
168 * This checks for a year switch within a week. Routine
169 * takes care that first days in January might still belong
170 * to the last week of the old year (according to ISO week
171 * number), thus be part of week 52 or 53.
172 */
173 if ($week >= 52 || $week == 1)
174 {
175 // See if it's a new year by comparing the year of the previous week with the
176 // current one.
177 $timestampPrevWeek = mktime( 0, 0, 0, $dateInfo['mon'], $day-7, $dateInfo['year'] );
178 $isNewYear = date('Y', $timestampPrevWeek) < date('Y', $timestamp);
179 if ($isNewYear && $week != 1)
180 {
181 // A new year with the first week having last year's final week number (52 or 53),
182 // because the week's Thursday lies in the old year.
183 $week = $lastWeek;
184 }
185 else
186 {
187 // The last week of December having the week number 1, because
188 // the week's Thursday lies in the new year.
189 $week = $lastWeek;
190 }
191 if ($weekDay == 0)
192 {
193 ++$week;
194 }
195 }
196
197 $lastWeek = $week;
198
199 if ( !isset( $weeks[$week] ) )
200 {
201 for ( $i = 0; $i < 7; ++$i )
202 {
203 $weeks[$week][] = false;
204 }
205 }
206 $dayData = array( 'day' => $day,
207 'link' => false,
208 'class' => $dayClass,
209 'highlight' => false );
210 if ( $currentDay == $info['yday'] )
211 {
212 if ( isset( $optional['current_class'] ) )
213 $dayData['class'] = $optional['current_class'];
214 $dayData['highlight'] = true;
215 }
216 if ( $dateInfo['year'] == $todayInfo['year'] and
217 $dateInfo['mon'] == $todayInfo['mon'] and
218 $day == $todayInfo['mday'] )
219 {
220 if ( $dayData['class'] )
221 $dayData['class'] .= '-' . $todayClass;
222 else
223 $dayData['class'] = $todayClass;
224 }
225 if ( $days[$day] )
226 {
227 $dayLink = $link;
228 if ( $dayLink )
229 {
230 $dayLink .= '/(year)/' . $info['year'];
231 $dayLink .= '/(month)/' . $info['mon'];
232 $dayLink .= '/(day)/' . $info['mday'];
233 }
234 $dayData['link'] = $dayLink;
235 }
236 $weeks[$week][$weekDay] = $dayData;
237 }
238
239 $next = false;
240 if ( isset( $optional['next'] ) )
241 $next = $optional['next'];
242 if ( $next )
243 {
244 $nextTimestamp = mktime( 0, 0, 0, $dateInfo['mon'] + 1, 1, $dateInfo['year'] );
245 $nextInfo = getdate( $nextTimestamp );
246 $month['next'] = array( 'month' => $locale->longMonthName( $nextInfo['mon'] ),
247 'year' => $nextInfo['year'] );
248 $nextLink = $next['link'];
249 $nextLink .= '/(year)/' . $nextInfo['year'];
250 $nextLink .= '/(month)/' . $nextInfo['mon'];
251 $month['next']['link'] = $nextLink;
252 }
253 else
254 $month['next'] = false;
255
256 $month['current'] = array( 'month' => $locale->longMonthName( $info['mon'] ),
257 'year' => $info['year'] );
258 $currentLink = $next['link'];
259 $currentLink .= '/(year)/' . $info['year'];
260 $currentLink .= '/(month)/' . $info['mon'];
261 $month['current']['link'] = $currentLink;
262
263 $previous = false;
264 if ( isset( $optional['previous'] ) )
265 {
266 $previous = $optional['previous'];
267 }
268 if ( $previous )
269 {
270 $previousTimestamp = mktime( 0, 0, 0, $dateInfo['mon'] - 1, 1, $dateInfo['year'] );
271 $previousInfo = getdate( $previousTimestamp );
272 $month['previous'] = array( 'month' => $locale->longMonthName( $previousInfo['mon'] ),
273 'year' => $previousInfo['year'] );
274 $previousLink = $previous['link'];
275 $previousLink .= '/(year)/' . $previousInfo['year'];
276 $previousLink .= '/(month)/' . $previousInfo['mon'];
277 $month['previous']['link'] = $previousLink;
278 }
279 else
280 {
281 $month['previous'] = false;
282 }
283 $month['weeks'] = $weeks;
284 $operatorValue = $month;
285 }
286 }
287 }
288
290 public $Operators;
291 }
292
293 ?>
eZDateOperatorCollection
Definition: ezdateoperatorcollection.php:12
eZDateOperatorCollection\namedParameterList
namedParameterList()
Definition: ezdateoperatorcollection.php:44
eZDateOperatorCollection\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: ezdateoperatorcollection.php:57
eZDateOperatorCollection\$MonthOverviewName
$MonthOverviewName
Definition: ezdateoperatorcollection.php:13
eZDateOperatorCollection\__construct
__construct( $monthName='month_overview')
Definition: ezdateoperatorcollection.php:19
eZDateOperatorCollection\operatorList
operatorList()
Definition: ezdateoperatorcollection.php:28
eZDateOperatorCollection\$Operators
$Operators
Definition: ezdateoperatorcollection.php:290
eZDateOperatorCollection\namedParameterPerOperator
namedParameterPerOperator()
Definition: ezdateoperatorcollection.php:36
eZLocale\instance
static instance( $localeString=false)
Definition: ezlocale.php:1536
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.