diff options
Diffstat (limited to 'taxonomy_node_tree.module')
-rw-r--r-- | taxonomy_node_tree.module | 63 |
1 files changed, 28 insertions, 35 deletions
diff --git a/taxonomy_node_tree.module b/taxonomy_node_tree.module index 31e0f44..ebb9e3c 100644 --- a/taxonomy_node_tree.module +++ b/taxonomy_node_tree.module @@ -5,15 +5,14 @@ * @file * Taxonomy Node Tree. * - * This module implements functions to build hierarchical - * term trees including children nodes. + * This module implements functions to build hierarchical term trees including + * children nodes. */ /** * Return the parent terms of a given vocabulary. * - * This function takes a vocabulary id and returns a - * list of it's parent terms. + * This function takes a vocabulary id and returns a list of it's parent terms. * * @param $vid * Taxonomy id. @@ -38,24 +37,22 @@ function taxonomy_node_tree_parents($vid) { /** * Setup an index of terms associated with it's children nodes. * - * This function accept a list of nodes and terms and build a - * tree with the corresponding association between terms and - * nodes. + * This function accept a list of nodes and terms and build a tree with the + * corresponding association between terms and nodes. * * @param $nodes * Array with node objects. - * - * @param $terms + * @param $terms * Array with term objects. * * @return * Term tree with nodes at their parent terms. * - * @TODO: It is assumed that nodes are just associated with - * a single term. This could be changed to support - * multiple relationships. + * @todo + * It is assumed that nodes are just associated with a single term. + * This could be changed to support multiple relationships. */ -function taxonomy_node_tree_index($nodes, $terms) { +function taxonomy_node_tree_index($nodes, $terms) { while ($node = db_fetch_object($nodes)) { foreach ($terms as $term) { // add nodes into the term @@ -79,9 +76,11 @@ function taxonomy_node_tree_index($nodes, $terms) { * Term tree with parent/children relation. */ function taxonomy_node_tree_relation($tree) { - foreach ($tree as $term) { - if ($term->parents[0] != 0 && isset($tree[$term->parents[0]])) { - $tree[$term->parents[0]]->children[] = $term->tid; + if (is_array($tree) && $tree != NULL) { + foreach ($tree as $term) { + if ($term->parents[0] != 0 && isset($tree[$term->parents[0]])) { + $tree[$term->parents[0]]->children[] = $term->tid; + } } } return $tree; @@ -94,7 +93,6 @@ function taxonomy_node_tree_relation($tree) { * * @param $tree * Tree with term objects to be changed (by reference). - * * @param $term * Term object. */ @@ -122,8 +120,10 @@ function taxonomy_node_tree_sort(&$tree, $term) { * Hierarchical term tree. */ function taxonomy_node_tree_hierarchy($tree) { - foreach ($tree as $term) { - taxonomy_node_tree_sort($tree, $term); + if (is_array($tree) && $tree != NULL) { + foreach ($tree as $term) { + taxonomy_node_tree_sort($tree, $term); + } } return $tree; } @@ -131,12 +131,11 @@ function taxonomy_node_tree_hierarchy($tree) { /** * Setup a full taxonomy node hierarchical tree. * - * Build a tree with taxonomy terms with full dept - * and add child node information at each level. + * Build a tree with taxonomy terms with full dept and add child node + * information at each level. * * @param $nodes * Array with node objects. - * * @param $terms * Array with term objects. * @@ -157,17 +156,13 @@ function taxonomy_node_tree_build($nodes, $terms) { * * @param $vid * Which vocabulary to generate the tree for. - * * @param $parent * The term ID under which to generate the tree. If 0, generate the tree * for the entire vocabulary. - * * @param $depth * Internal use only. - * * @param $max_depth * The number of levels of the tree to return. Leave NULL to return all levels. - * * @param $cache * Whether to use cache results. * @@ -175,7 +170,7 @@ function taxonomy_node_tree_build($nodes, $terms) { * An array of all term objects in the tree. Each term object is extended * to have "depth" and "parents" attributes in addition to its normal ones. * Results are statically cached. - */ + */ function taxonomy_node_tree_taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL, $cache = FALSE) { static $children, $parents, $terms; @@ -211,14 +206,13 @@ function taxonomy_node_tree_taxonomy_get_tree($vid, $parent = 0, $depth = -1, $m } return $tree; - } /** * Recursively build an HTML taxonomy node tree. * * @ingroup themeable - * @TODO: usage with hook_theme(); + * @todo Usage with hook_theme(). */ function taxonomy_node_tree_list($term, $id, $class, $baselink = NULL, &$level = NULL) { @@ -232,24 +226,23 @@ function taxonomy_node_tree_list($term, $id, $class, $baselink = NULL, &$level = $output .= '<li>'; $output .= $term->name; if (isset($term->below)) { - $output .= '<ul id="' . $id .'[ul]["'. $level .']" class="'. $class .'">'; + $output .= '<ul id="' . $id .'-ul-'. $level .'" class="'. $class .'">'; foreach ($term->below as $child) { $output .= taxonomy_node_tree_list($child, $id, $class, $baselink, $level); } $output .= '</ul>'; } - else if (isset($term->nodes)) { - $output .= '<ul id="' . $id .'[ul]["'. $level .']" class="'. $class .'">'; + elseif (isset($term->nodes)) { + $output .= '<ul id="' . $id .'-ul-'. $level .'" class="'. $class .'">'; foreach ($term->nodes as $node) { $output .= '<li>'; - $output .= '<a href="'. $GLOBALS['base_url'] .'/'. $baselink .'/'. $node->nid .'">'. $node->title .'</a>'; + $output .= l($node->title, "$baselink/$node->nid"); + $output .= '</li>'; } $output .= '</ul>'; - $output .= '</li>'; } $output .= '</li>'; } return $output; - } |