function _hs_taxonomy_hierarchical_select_get_tree in Hierarchical Select 6.3
Same name and namespace in other branches
- 5.3 modules/hs_taxonomy.module \_hs_taxonomy_hierarchical_select_get_tree()
- 7.3 modules/hs_taxonomy.module \_hs_taxonomy_hierarchical_select_get_tree()
Drupal core's taxonomy_get_tree() doesn't allow us to reset the cached trees, which obviously causes problems when you create new items between two calls to it.
8 calls to _hs_taxonomy_hierarchical_select_get_tree()
- hs_content_taxonomy_hierarchical_select_children in modules/
hs_content_taxonomy.module - Implementation of hook_hierarchical_select_children().
- hs_content_taxonomy_hierarchical_select_root_level in modules/
hs_content_taxonomy.module - Implementation of hook_hierarchical_select_root_level().
- hs_taxonomy_hierarchical_select_create_item in modules/
hs_taxonomy.module - Implementation of hook_hierarchical_select_create_item().
- hs_taxonomy_hierarchical_select_root_level in modules/
hs_taxonomy.module - Implementation of hook_hierarchical_select_root_level().
- hs_taxonomy_term_count_nodes in modules/
hs_taxonomy.module - Drupal core's taxonomy_term_count_nodes() is buggy. See http://drupal.org/node/144969#comment-843000.
File
- modules/
hs_taxonomy.module, line 788 - Implementation of the Hierarchical Select API for the Taxonomy module.
Code
function _hs_taxonomy_hierarchical_select_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL, $reset = FALSE) {
static $children, $parents, $terms;
if ($reset) {
$children = $parents = $terms = array();
}
$depth++;
// We cache trees, so it's not CPU-intensive to call get_tree() on a term
// and its children, too.
if (!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;
if (isset($children[$vid][$parent])) {
foreach ($children[$vid][$parent] as $child) {
if ($max_depth > $depth) {
$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 (isset($children[$vid][$child])) {
$tree = array_merge($tree, _hs_taxonomy_hierarchical_select_get_tree($vid, $child, $depth, $max_depth));
}
}
}
}
return isset($tree) ? $tree : array();
}