function calendar_week in Calendar 5
Handle a lot of messy week calculations all in one place to make maintenance easier
3 calls to calendar_week()
- calendar_build_filter in ./
calendar.module - Compile the filter query for this view.
- calendar_filter_week in ./
calendar.module - Callback for week filter. Build year, month, day, min, and max into query object.
- theme_calendar_nav_title in ./
calendar.theme - Theme the navigation bar title
3 string references to 'calendar_week'
- calendar_args in ./
calendar.module - Valid calendar arguments.
- calendar_views_query_alter in ./
calendar.module - Implementation of hook_views_query() Insert filters into the query based on the current calendar view and the selected fields Used when the actual view arguments don't provide enough info to construct the query. i.e. on a view with no arguments…
- _calendar_views_validate in ./
calendar_admin.inc - Validate a view.
File
- ./
calendar.module, line 1034 - Adds calendar filtering and displays to Views.
Code
function calendar_week($op, $view, $week = 0) {
calendar_load_date_api();
if ($week == 0) {
$day = !empty($view->day) && $view->day != CALENDAR_EMPTY_ARG ? $view->day : calendar_user_date('day');
$month = !empty($view->month) && $view->month != CALENDAR_EMPTY_ARG ? $view->month : calendar_user_date('month');
$isodate = $view->year . '-' . sprintf('%02d', $month) . '-' . sprintf('%02d', $day) . 'T00:00:00';
$week_year = calendar_week_year(date_iso2unix($isodate));
if ($op == 'week') {
return $week_year[0];
}
}
$range = calendar_week_range($view->year, $week);
$week_start = $range[0];
$week_end = $range[1];
switch ($op) {
case 'start_year':
return date_format_date('Y', $week_start);
case 'end_year':
return date_format_date('Y', $week_end);
case 'start_month':
return date_format_date('n', $week_start);
case 'end_month':
return date_format_date('n', $week_end);
case 'start_day':
return date_format_date('d', $week_start);
case 'end_day':
return date_format_date('d', $week_end);
default:
return $week_start;
}
}