You are here

public static function AbtUtils::taxonomyGetChildrenAll in Access By Term 7

Method for fetching all of the children for a taxonomy term or an array of taxonomy terms.

Parameters

string $terms: Array of terms. Each term must be an object containing properties tid, vid & name.

Return value

Array On success returns array of terms with all their children. On failure returns an empty array.

1 call to AbtUtils::taxonomyGetChildrenAll()
abt_node_grants in ./abt.module
Implements hook_node_grants().

File

./abtutils.inc, line 26
abtutils.inc File containing AbtUtils class.

Class

AbtUtils
Static class containing utility methods for the ABT module.

Code

public static function taxonomyGetChildrenAll($terms) {
  $out = array();
  if (empty($terms) || !is_array($terms)) {
    return $out;
  }
  $first_term_data = taxonomy_term_load($terms[0]['tid']);
  if (property_exists($first_term_data, 'vid')) {
    $vid = intval($first_term_data->vid);
  }
  else {
    return $out;
  }
  unset($first_term_data);
  foreach ($terms as $tkey => $term) {
    $out[$term['tid']] = $term['tid'];
    $children = taxonomy_get_tree($vid, $term['tid']);
    foreach ($children as $ckey => $child) {
      $out[$child->tid] = $child->tid;
    }
  }
  return $out;
}