You are here

function theme_taxonomy_list_table in Taxonomy List 7

Same name and namespace in other branches
  1. 5.2 taxonomy_list.module \theme_taxonomy_list_table()
  2. 6.2 taxonomy_list.module \theme_taxonomy_list_table()

Theme a table of the term tree.

Parameters

$terms: the enhanced term tree.

$cells_per_row: the number of cells per row to display.

$list_mode: indicates how to show the hierarchy.

Return value

the themed list to be displayed.

File

./taxonomy_list.module, line 467
List all terms in a vocabulary.

Code

function theme_taxonomy_list_table($variables) {
  $terms = $variables['terms'];
  $cells_per_row = $variables['cells'];
  $list_mode = $variables['title'];
  $cells = array();
  $table = array(
    'rows' => array(),
    'header' => array(),
  );
  $curr_col = -1;
  $curr_depth = 0;
  foreach ($terms as $tid => $term) {
    if (!isset($vid)) {

      // If recursive, watch out for this.
      $vid = $term->vid;
    }
    $class = 'taxonomy-list-depth-' . $term->depth;
    $table['attributes'] = array(
      'id' => 'taxonomy-list-table-' . $vid,
    );

    // List_mode = 0 is hierarchical; = 1 is flat.
    if ($curr_depth != $term->depth && $list_mode == 0) {
      $table['rows'][] = $cells;
      $cells = array();
      $curr_col = -1;
      $curr_depth = $term->depth;
    }
    if ($term->children) {
      $class .= ' taxonomy-list-parent';
      $colspan = $cells_per_row;
    }
    else {
      $colspan = 1;
    }
    $cells[] = array(
      'data' => '<div class="' . $class . '">' . theme('taxonomy_list_term', array(
        'term' => $term,
      )) . '</div>',
      'colspan' => $colspan,
    );
    $curr_col = ($curr_col + 1) % $cells_per_row;
    if ($curr_col == $cells_per_row - 1) {
      $table['rows'][] = $cells;
      $cells = array();
    }
  }
  if ($cells) {
    $table['rows'][] = $cells;
  }
  return theme('table', $table);
}