function _taxonomy_list_get_table in Taxonomy List 5
Generate cascaded tables with terms and sub terms inside
1 call to _taxonomy_list_get_table()
- taxonomy_list_show in ./
taxonomy_list.module - Show the category list
File
- ./
taxonomy_list.module, line 188 - List the category specified in the URL
Code
function _taxonomy_list_get_table($terms, $vocabulary, $controls, $depth) {
// list of terms those already rendered
static $done = array();
$cells = array();
$rows = array();
foreach ($terms as $term) {
// Have we already seen this term?
if (isset($done[$term->tid])) {
continue;
}
// Indicate that we've already done this term and save its name.
$done[$term->tid] = $term->name;
// Taxonomy_get_children does not provide depth or parents.
if (!isset($term->depth)) {
$term->depth = $depth;
}
if ($depth < $controls['max_depth']) {
$children = taxonomy_get_children($term->tid, $vocabulary->vid);
}
else {
$children = NULL;
}
// List_mode 0 = 'hierarchical'.
$has_children = $children && $controls['list_mode'] == 0;
if ($has_children) {
// Pad the row so the parent term will start at the begining of the next row.
_taxonomy_list_pad_row($cells, $rows, $controls['cells_per_row']);
}
// TODO: consider a depth attribute for parents.
$cell = $has_children ? '<div class="taxonomy-list-cascade"><div class="taxonomy-list-parent">' : NULL;
$stuff = theme('taxonomy_list_term', $term, $vocabulary, $controls);
// Was there something in the cell?
if (!$stuff) {
continue;
}
$cell .= $stuff;
if ($has_children) {
$cell .= '</div>';
// class="taxonomy-list-parent"
$cell .= '<div class="taxonomy-list-children">';
$cell .= _taxonomy_list_get_table($children, $vocabulary, $controls, $depth + 1);
$cell .= '</div>';
// class="taxonomy-list-children"
$cell .= '</div>';
// class="taxonomy-list-cascade"
}
if ($has_children) {
// Span the cell to cover the whole row, and then the
// next term will start at the begining of the next row
$cells[] = array(
'data' => $cell,
'class' => 'cells-1',
'colspan' => $controls['cells_per_row'],
);
$rows[] = array(
'data' => $cells,
);
$cells = array();
}
else {
$cells[] = array(
'data' => $cell,
'class' => 'cells-' . $controls['cells_per_row'],
);
// add cell into the row, advance row if it reach the end of row
if (count($cells) % $controls['cells_per_row'] == 0) {
$rows[] = array(
'data' => $cells,
);
$cells = array();
}
}
}
// Ensure that the table will be in good shape
// by padding the last row of the table.
_taxonomy_list_pad_row($cells, $rows, $controls['cells_per_row']);
$table_attrs = array(
'class' => 'taxonomy-list-table',
);
if ($depth == 1) {
$table_attrs['id'] = 'taxonomy-list-table-' . $vocabulary->vid;
}
return theme('table', array(), $rows, $table_attrs);
}