You are here

function _hs_taxonomy_term_within_allowed_depth in Hierarchical Select 7.3

Helper function to check if taxonomy term is within allowed depth.

Parameters

int $tid: The term id.

int $vid: The vocabulary id.

int $root_tid: The term id of th4e parent taxonomy term.

int $allowed_depth: The number of maxium taxonomy depth allowed.

1 call to _hs_taxonomy_term_within_allowed_depth()
hs_taxonomy_hierarchical_select_valid_item in modules/hs_taxonomy.module
Implements hook_hierarchical_select_valid_item().

File

modules/hs_taxonomy.module, line 1323
Implementation of the Hierarchical Select API for the Taxonomy module.

Code

function _hs_taxonomy_term_within_allowed_depth($tid, $vid, $root_tid, $allowed_depth) {

  // If the allowed depth is zero, then every term is allowed!
  if ($allowed_depth == 0) {
    return TRUE;
  }

  // Otherwise, only allow terms that are within the allowed depth.
  static $valid_tids;
  if (!isset($valid_tids[$vid][$root_tid][$allowed_depth])) {
    $valid_tids[$vid][$root_tid][$allowed_depth] = array();
    $tree = _hs_taxonomy_hierarchical_select_get_tree($vid, $root_tid);
    foreach ($tree as $term) {
      if ($term->depth < $allowed_depth) {
        $valid_tids[$vid][$root_tid][$allowed_depth][] = $term->tid;
      }
    }
  }
  return in_array($tid, $valid_tids[$vid][$root_tid][$allowed_depth]);
}