You are here

function _term_reference_tree_get_children in Taxonomy Term Reference Tree Widget 7.2

Same name and namespace in other branches
  1. 8 term_reference_tree.module \_term_reference_tree_get_children()

This function is like taxonomy_get_children, except it doesn't load the entire term.

Parameters

$tid: The ID of the term whose children you want to get.

$vid: The vocabulary ID.

Return value

An array of taxonomy terms, each in the form array('tid' => $tid, 'name' => $name)

1 call to _term_reference_tree_get_children()
_term_reference_tree_get_term_hierarchy in ./term_reference_tree.module
This function returns a taxonomy term hierarchy in a nested array.

File

./term_reference_tree.module, line 133

Code

function _term_reference_tree_get_children($tid, $vid) {

  // DO NOT LOAD TAXONOMY TERMS HERE
  // Taxonomy terms take a lot of time and memory to load, and this can be
  // very bad on large vocabularies.  Instead, we load the term as necessary
  // in cases where it's needed (such as using tokens or when the locale
  // module is enabled).
  $select = db_select('taxonomy_term_data', 'd');
  $select
    ->join('taxonomy_term_hierarchy', 'h', 'd.tid = h.tid');
  $result = $select
    ->fields('d', array(
    'tid',
    'name',
  ))
    ->condition('d.vid', $vid, '=')
    ->condition('h.parent', $tid, '=')
    ->orderBy('weight')
    ->orderBy('name')
    ->orderBy('tid')
    ->execute();
  $terms = array();
  while ($term = $result
    ->fetchAssoc()) {
    $terms[$term['tid']] = (object) $term;
  }
  return $terms;
}