View source
<?php
function views_tree_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'views_tree'),
);
}
function views_tree_theme($existing, $type, $theme, $path) {
return array(
'views_tree_inner' => array(
'arguments' => array(
'view' => NULL,
'options' => array(),
'rows' => array(),
'title' => NULL,
'result' => array(),
'parent' => NULL,
),
),
);
}
function theme_views_tree($view, $options, $rows, $title) {
$result = $view->result;
$fields =& $view->field;
$options['main_field_property'] = $fields[$options['main_field']]->field_alias;
$options['parent_field_property'] = $fields[$options['parent_field']]->field_alias;
$parents = array();
foreach ($result as $record) {
$parents[] = $record->{$options}['main_field_property'];
}
foreach ($result as $record) {
if (!in_array($record->{$options}['parent_field_property'], $parents)) {
$record->{$options}['parent_field_property'] = 0;
}
}
return $title . theme('views_tree_inner', $view, $options, $rows, $title, $result, 0);
}
function theme_views_tree_inner($view, $options, $rows, $title, $result, $parent = NULL) {
$items = array();
foreach ($result as $i => $record) {
if ($record->{$options}['parent_field_property'] == $parent) {
$items[] = $rows[$i] . call_user_func(__FUNCTION__, $view, $options, $rows, $title, $result, $record->{$options}['main_field_property']);
}
}
return count($items) ? theme('item_list', $items, NULL, $options['type']) : '';
}