<?php
// $Id: summary_combo.inc,v 1.1.2.1 2006/11/14 02:12:42 merlinofchaos Exp $
// $Name: DRUPAL-4-7--1-1 $

function views_bonus_summary_combo_info() {
  $items['summary_combo'] = array(
    'name' => t('Summary + full view'),
    'description' => t('View type puts a summary on top and an argument below.'),
    'requires' => array(), // must be here, even if empty.
  );
  return $items;
}

function views_bonus_summary_combo_style_plugins() {
  $items['summary_combo'] = array(
    'name' => t('Bonus: Summary + full view'),
    'theme' => 'views_bonus_summary_combo',
    'summary_theme' => 'views_bonus_summary_combo_summary',
  );
  return $items;
}

// Merlin comment: This plugin should provide validation, since it requires
// an argument to work.

// --------------------------------------------------------------------------
// Combo theme with summary on top and full view below
/**
 *  Combo full page theme
 *  $level, $args, and $summary are only available if called by summary view
 */
function theme_views_bonus_summary_combo($view, $nodes, $type, $level = NULL, $args = NULL, $summary = FALSE) {
  
  $teasers = true;
  $links = true;
  
  // keep the title from displaying both in the summary and full view
  drupal_set_title($title);
  unset($view->page_title);
  // create page bottom first -- may be either a full view or a summary view
  // it is possible to have several levels of summary views if multiple arguments set to summary are used
  if ($summary && $level == 0 && isset($view->argument[0])) {
    // don't display bottom if it will be same top level summary view displayed on top
    $bottom = '';
  }
  elseif ($summary) {
    // a summary view on the bottom of the page should be the regular summary view
    $bottom = theme('views_summary', $view, $type, $level, $nodes, $args);
  }
  else {
    // otherwise display the full view
    $bottom = theme('views_view_nodes', $view, $nodes, $view->page_type, $teasers, $links);
  } 
  // the summary view on the top of the page should always be the top level summary view
  // create this only after bottom view has been generated to avoid wiping out values from the original view
  
  if (isset($view->argument[0])) {
    $summary = views_build_view('items', $view, array(), false, $view->nodes_per_page);
    $top = theme('views_bonus_summary_combo_top', $view, $summary['items']);
  }
  return $top . $bottom;
}
/**
 *  The combo summary theme, a wrapper function to send summary page theme through the full page theme
 *  passing along $level, $args, and setting $summary = TRUE
 */
function theme_views_bonus_summary_combo_summary($view, $type, $level, $nodes, $args) {
  return theme_views_bonus_summary_combo($view, $nodes, $type, $level, $args, TRUE);
}
/**
 *  Style the summary list to be wide (side by side) instead of long when used above the full view
 *  @return item list adapted with | separator and css to display list inline
 */
function theme_views_bonus_summary_combo_top($view, $nodes) {
  
  theme_add_style(drupal_get_path('module', 'views_bonus') .'/views_bonus.css');
  foreach ($nodes as $node) {
    $items[] = views_get_summary_link($view->argument[0]['type'], $node, $view->url)  . "&nbsp;(" . $node->num_nodes . ")&nbsp;| ";
  }
  if ($items) {
    return '<div id="views_bonus_summary_top">'. theme('item_list', $items) .'</div>';
  }
}
