function calendar_views_pre_view in Calendar 5.2
Same name and namespace in other branches
- 5 calendar.module \calendar_views_pre_view()
- 6.2 includes/calendar.views.inc \calendar_views_pre_view()
- 7 includes/calendar.views.inc \calendar_views_pre_view()
- 7.2 includes/calendar.views.inc \calendar_views_pre_view()
Implementation of hook_views_pre_view()
File
- ./
calendar.module, line 315 - Adds calendar filtering and displays to Views.
Code
function calendar_views_pre_view(&$view, &$items) {
require_once './' . drupal_get_path('module', 'calendar') . '/calendar.theme';
// Construct a formatted title for the view from the last calendar
// argument encountered.
$view->subtitle = theme('calendar_nav_title', $view->calendar_type, $view);
// If this is a view with calendar arguments but not a calendar view,
// add navigation to the top of the view and return.
if (!calendar_is_calendar($view) && calendar_has_calendar_args($view)) {
return theme('calendar_nav', $view, $view->build_type != 'block');
}
elseif (!calendar_is_calendar($view) || !calendar_has_calendar_args($view)) {
return;
}
if ($view->build_type == 'block' || $view->calendar_type == 'year') {
$view->mini = TRUE;
}
// Don't do anything in summary views.
if ($summary = !empty($items) && array_key_exists('num_nodes', $items[0])) {
return;
}
// Don't do anything if this isn't a calendar component.
if (!calendar_has_calendar_args($view) || empty($view->args) && !calendar_is_calendar_arg($view) && $view->argument[0]['argdefault'] != 2) {
return;
}
require_once './' . drupal_get_path('module', 'calendar') . '/calendar.inc';
$display_formats = variable_get('calendar_display_format_' . $view->name, array(
'year' => 'calendar',
'month' => 'calendar',
'week' => 'calendar',
'day' => 'calendar',
'block' => 'calendar',
));
// Massage the resulting items into formatted calendar items.
$items = calendar_build_nodes($view, $items, $display_formats[$view->calendar_type]);
// Merge in items from other sources.
foreach (module_implements('calendar_add_items') as $module) {
$function = $module . '_calendar_add_items';
if (function_exists($function)) {
if ($feeds = $function($view)) {
foreach ($feeds as $feed) {
$items[$feed->calendar_start][] = $feed;
}
}
}
}
// Sort the results -- sort needed if they are to be displayed
// in a list or other non-calendar format, since sorting was
// clobbered by adding in feeds and breaking items up into
// individual days.
$sort = '';
$fields = array_keys(calendar_fields());
foreach ($view->field as $field) {
if (in_array($field['field'], $fields)) {
foreach ($view->sort as $sort) {
if ($sort['field'] = $field['field']) {
$sort = $sort['sortorder'];
break;
}
}
}
}
if (!empty($sort)) {
if ($sort == 'DESC') {
krsort($items);
}
else {
ksort($items);
}
}
$nodes = array();
foreach ($items as $date => $values) {
foreach ($values as $node) {
$nodes[] = $node;
}
}
$items = $nodes;
// If this is a calendar plugin theme view, make sure empty results
// will produce blank calendar page
if (array_key_exists($view->page_type, calendar_view_types())) {
if (!$items && $view->build_type == 'page' && $view->year && $display_formats[$view->calendar_type] == 'calendar') {
$view->page_empty = check_markup($view->page_header, $view->page_header_format, FALSE) . check_markup($view->page_empty, $view->page_empty_format, FALSE);
}
}
if (array_key_exists($view->block_type, calendar_view_types())) {
if (!$items && $view->build_type == 'block' && $view->year && $display_formats[$view->calendar_type] == 'calendar') {
$view->block_empty = check_markup($view->block_header, $view->block_header_format, FALSE) . check_markup($view->block_empty, $view->block_empty_format, FALSE);
}
}
}