Is there any way to make menus based on the arguments of a view?

Let me explain. I have a views.module view that I use to sort through posts by date, i.e. journal/yyyy/mm/dd/post_title, and I'd like to have a block at the side that can be used to navigate through the various dates, like the following diagram:

2007 (14)
-- May (2)
-- -- Weds 2 (1)
-- -- Fri 18 (1) <---selected page is /journal/2007/05/18
-- April (6)
-- February (5)
-- January (1)
2006 (31)
2005 (27)

The thing is, at each level this is *extremely* similar to the "summary" that views can creat, so I was hoping there' is an easy way to use views to do this without resorting to my own PHP and SQL custom block.

Comments

Morris Singer’s picture

I've tried to do some similar things. The best I could come up with was to determine what the arguments of the view are (you can do this by loading the view), and then figuring out non-views-native ways of culling a list of argument values. For example, if I were using the Taxonomy: Term ID (taxid) argument, I could then get the taxonomy tree using API functions in the taxonomy module and use that to build a menu.

mhutch’s picture

If anyone is interested:

if (arg(0)=="journal") {
  $sql_years = "SELECT COUNT(*) as node_count, YEAR(FROM_UNIXTIME(created)) as node_year FROM {node} WHERE type='journal' GROUP BY node_year ORDER BY node_year DESC";
  $sql_months = "SELECT COUNT(*) as node_count, MONTH(FROM_UNIXTIME(created)) as node_month FROM {node} WHERE type='journal' and (YEAR(FROM_UNIXTIME(created))=%d) GROUP BY node_month ORDER BY node_month DESC";
  $sql_days = "SELECT COUNT(*) as node_count, DAY(FROM_UNIXTIME(created)) as node_day FROM {node} WHERE type='journal' and (YEAR(FROM_UNIXTIME(created))=%d) and (MONTH(FROM_UNIXTIME(created))=%d) GROUP BY node_day ORDER BY node_day DESC";
  
  if (is_numeric(arg(1))) {
    $year = intval(arg(1));
  }
  if (is_numeric(arg(2))) {
    $month = intval(arg(2));
  }
  if (is_numeric(arg(3))) {
    $day = intval(arg(3));
  }
  
  
  $output = '<ul class="menu">';
  $result_years = db_query_range($sql_years, 0, 20);
  while ($res_years = db_fetch_object($result_years)) {
    if ($res_years->node_year != $year) {
      $output .= '<li class="collapsed">' . l("{$res_years->node_year} ({$res_years->node_count})", "journal/{$res_years->node_year}") . '</li>';
    } else {
      $output .= '<li class="expanded">' . l("{$res_years->node_year} ({$res_years->node_count})", "journal/{$res_years->node_year}") ;
      $output .= '<ul class="menu">';
      $result_months = db_query_range($sql_months, $year, 0, 12);
      while ($res_months = db_fetch_object($result_months)) {
        $node_month = str_pad($res_months->node_month, 2, '0', STR_PAD_LEFT);
        $node_month_name = format_date(strtotime("2005{$node_month}15"), 'custom', 'F', 0);
        if ($res_months->node_month != $month) {
          $output .= '<li class="collapsed">' . l("{$node_month_name} ({$res_months->node_count})", "journal/{$res_years->node_year}/{$node_month}") . '</li>';
        } else {
          $output .= '<li class="expanded">' . l("{$node_month_name} ({$res_months->node_count})", "journal/{$res_years->node_year}/{$node_month}");
          $output .= '<ul class="menu">';
          $result_days = db_query_range($sql_days, $year, $month, 0, 31);
          while ($res_days = db_fetch_object($result_days)) {
            $node_day = str_pad($res_days->node_day, 2, '0', STR_PAD_LEFT);
            $node_day_name = format_date(strtotime("{$year}{$node_month}{$node_day}"), 'custom', 'l j', 0);
            $output .= '<li class="leaf">' . l("{$node_day_name} ({$res_days->node_count})", "journal/{$res_years->node_year}/{$node_month}/{$node_day}") . '</li>';
          }
          $output .= '</ul></li>';
        }  
      }
      $output .= '</ul></li>';
    }
  }
  $output .= '</ul>';
  print $output;
}