From 438004a5a9ed57f8149f3c471b08e25706684ee6 Mon Sep 17 00:00:00 2001 From: Silvio Date: Fri, 16 Oct 2009 11:22:57 -0300 Subject: Sorting code --- taxonomy_node_tree.module | 188 +++++++++++++++++++++++----------------------- 1 file changed, 94 insertions(+), 94 deletions(-) diff --git a/taxonomy_node_tree.module b/taxonomy_node_tree.module index 088c02a..8244b00 100644 --- a/taxonomy_node_tree.module +++ b/taxonomy_node_tree.module @@ -21,71 +21,6 @@ function taxonomy_node_tree_parents($vid) { return $menu; } -/** - * Implementation of hook_theme(); - * - * @TODO: update - */ -function taxonomy_node_tree_theme() { - return array( - 'taxonomy_node_tree_menu_parents' => array( - 'arguments' => array( - 'menu' => NULL, - 'parent' => NULL, - ), - ), - 'taxonomy_node_tree_link' => array( - 'arguments' => array(), - ), - ); -} - -/** - * Render the parent items of a menu. - * - * @ingroup themeable - */ -function theme_taxonomy_node_tree_menu_parents($menu, $class = 'menu', $id = NULL, $base = NULL) { - - if ($id != NULL) { - $id = ' id="'. $id .'"'; - } - - $output = ''; - $output .= '
'; - $output .= '
'; - return $output; - -} - -/** - * Link theme function. - * - * @ingroup themeable - */ -function theme_taxonomy_node_tree_link($link) { - if (empty($link['localized_options'])) { - $link['localized_options'] = array(); - } - - $link['attributes']['rel'] = 'drw'; - - $output = '
  • '; - $output .= l($link['title'], $link['href'], array('attributes' => array('rel' => 'drw'))); - $output .= '
  • '; - - return $output; -} - /** * Setup an index of terms associated with it's children nodes. * @@ -158,6 +93,49 @@ function taxonomy_node_tree_build($nodes, $terms) { return $tree; } +/** + * Version of taxonomy_get_tree() without caching. + */ +function taxonomy_node_tree_taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL, $cache = FALSE) { + static $children, $parents, $terms; + + $depth++; + + // We can cache trees, so it's not CPU-intensive to call get_tree() on a term + // and its children, too. + if (!$cache && !isset($children[$vid])) { + $children[$vid] = array(); + + $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid); + while ($term = db_fetch_object($result)) { + $children[$vid][$term->parent][] = $term->tid; + $parents[$vid][$term->tid][] = $term->parent; + $terms[$vid][$term->tid] = $term; + } + } + + $max_depth = (is_null($max_depth)) ? count($children[$vid]) : $max_depth; + $tree = array(); + if ($max_depth > $depth && !empty($children[$vid][$parent])) { + foreach ($children[$vid][$parent] as $child) { + $term = drupal_clone($terms[$vid][$child]); + $term->depth = $depth; + // The "parent" attribute is not useful, as it would show one parent only. + unset($term->parent); + $term->parents = $parents[$vid][$child]; + $tree[] = $term; + if (!empty($children[$vid][$child])) { + $tree = array_merge($tree, taxonomy_get_tree($vid, $child, $depth, $max_depth)); + } + } + } + + return $tree; + +} + +// TODO: cleanup from here + /** * Menu callback. * @@ -259,43 +237,65 @@ function taxonomy_node_tree_menu_build($term) { return $output; } +/** + * Implementation of hook_theme(); + * + * @TODO: update + */ +function taxonomy_node_tree_theme() { + return array( + 'taxonomy_node_tree_menu_parents' => array( + 'arguments' => array( + 'menu' => NULL, + 'parent' => NULL, + ), + ), + 'taxonomy_node_tree_link' => array( + 'arguments' => array(), + ), + ); +} /** - * Version of taxonomy_get_tree() without caching. + * Render the parent items of a menu. + * + * @ingroup themeable */ -function taxonomy_node_tree_taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL, $cache = FALSE) { - static $children, $parents, $terms; +function theme_taxonomy_node_tree_menu_parents($menu, $class = 'menu', $id = NULL, $base = NULL) { - $depth++; + if ($id != NULL) { + $id = ' id="'. $id .'"'; + } - // We can cache trees, so it's not CPU-intensive to call get_tree() on a term - // and its children, too. - if (!$cache && !isset($children[$vid])) { - $children[$vid] = array(); + $output = ''; + return $output; + +} + +/** + * Link theme function. + * + * @ingroup themeable + */ +function theme_taxonomy_node_tree_link($link, $class = 'tree') { + if (empty($link['localized_options'])) { + $link['localized_options'] = array(); } - return $tree; + $link['attributes']['rel'] = 'drw'; + + $output = '
  • '; + $output .= l($link['title'], $link['href'], array('attributes' => array('rel' => 'drw'))); + $output .= '
  • '; + + return $output; } -- cgit v1.2.3