aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio <s1lv10@uol.com.br>2009-10-16 11:22:57 -0300
committerSilvio <s1lv10@uol.com.br>2009-10-16 11:22:57 -0300
commit438004a5a9ed57f8149f3c471b08e25706684ee6 (patch)
treeda494e72c189b1d6f26f92b455e6060f72d03dfb
parent163cca42f0d572f080ba7d31407053587f60f0f0 (diff)
downloadtaxonomy_node_tree-438004a5a9ed57f8149f3c471b08e25706684ee6.tar.gz
taxonomy_node_tree-438004a5a9ed57f8149f3c471b08e25706684ee6.tar.bz2
Sorting code
-rw-r--r--taxonomy_node_tree.module188
1 files 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
@@ -22,71 +22,6 @@ function taxonomy_node_tree_parents($vid) {
}
/**
- * 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 = '<ul class="'. $class .'"'. $id .'>';
- $output .= implode((array) module_invoke_all('taxonomy_node_tree_menu_parents'));
-
- foreach ($menu as $item) {
- $link['title'] = $item->name;
- $link['href'] = $base . $item->tid;
- $output .= theme('taxonomy_node_tree_link', $link);
- }
-
- $output .= '</ul>';
- $output .= '<div id="drw">';
- $output .= '</div>';
- 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 = '<li class="drw_li">';
- $output .= l($link['title'], $link['href'], array('attributes' => array('rel' => 'drw')));
- $output .= '</li>';
-
- return $output;
-}
-
-/**
* Setup an index of terms associated with it's children nodes.
*
* This function accept a list of nodes and terms and build a
@@ -159,6 +94,49 @@ function taxonomy_node_tree_build($nodes, $terms) {
}
/**
+ * 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.
*
* @TODO: revamp
@@ -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 = '<ul class="'. $class .'"'. $id .'>';
+ $output .= implode((array) module_invoke_all('taxonomy_node_tree_menu_parents'));
- $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;
- }
+ foreach ($menu as $item) {
+ $link['title'] = $item->name;
+ $link['href'] = $base . $item->tid;
+ $output .= theme('taxonomy_node_tree_link', $link);
}
- $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));
- }
- }
+ $output .= '</ul>';
+ 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 = '<li class="drw_li">';
+ $output .= l($link['title'], $link['href'], array('attributes' => array('rel' => 'drw')));
+ $output .= '</li>';
+
+ return $output;
}