function calendar_get_paths in Calendar 5.2
Same name and namespace in other branches
- 5 calendar.module \calendar_get_paths()
1 call to calendar_get_paths()
- theme_calendar_nav in ./
calendar.theme - Function to construct back and next navigation from views arguments
File
- ./
calendar.inc, line 782 - All the code used while processing a calendar is stored in this file and is included only when needed.
Code
function calendar_get_paths($view) {
$path = array();
$prev_date = drupal_clone($view->min_date);
date_modify($prev_date, '-1 ' . $view->calendar_type);
$next_date = drupal_clone($view->min_date);
date_modify($next_date, '+1 ' . $view->calendar_type);
$path = calendar_get_url($view, $view->args, TRUE);
// reverse through the path, creating a $nextpath and $prevpath arrays
$formats = array(
'day' => 'j',
'month' => 'm',
'year' => 'Y',
'week' => 'W',
);
for ($x = count($path); $x >= 0; $x--) {
$type = $path[$x]['type'];
if (in_array($type, array_keys($formats)) && $path[$x]['path'] != CALENDAR_EMPTY_ARG) {
if ($type != 'week') {
$nextpath[$x] = $type == 'year' && isset($next_year) ? $next_year : date_format($next_date, $formats[$type]);
$prevpath[$x] = $type == 'year' && isset($prev_year) ? $prev_year : date_format($prev_date, $formats[$type]);
}
else {
if (date_format($prev_date, 'Y') < $view->year) {
$prev_week = calendar_max_weeks(date_format($prev_date, 'Y'));
}
else {
$prev_week = $view->week - 1;
}
if (date_format($next_date, 'Y') > $view->year) {
$next_week = 1;
}
else {
$next_week = $view->week + 1;
}
$nextpath[$x] = 'W' . $next_week;
$prevpath[$x] = 'W' . $prev_week;
}
}
elseif (!empty($path[$x]['path'])) {
$nextpath[$x] = $path[$x]['path'];
$prevpath[$x] = $path[$x]['path'];
}
}
// See if back/next navigation will take us outside
// the allowed date range for our argument.
$view_dates = calendar_year_range($view);
$view_min_year = $view_dates[0];
$view_max_year = $view_dates[1];
if (date_format($prev_date, 'Y') < $view_min_year) {
$prevpath = array();
}
if (date_format($next_date, 'Y') > $view_max_year) {
$nextpath = array();
}
return array(
$prevpath,
$nextpath,
);
}