You are here

function tft_get_depth in Taxonomy File Tree 7.2

Same name and namespace in other branches
  1. 7 tft.module \tft_get_depth()

Get the depth of the term

Parameters

int $tid: The taxonomy term tid

Return value

int The depth of the term, or 0 if no valid term tid was given

Related topics

6 calls to tft_get_depth()
tft_get_og_nid in ./tft.module
tft_is_archive_folder in ./tft.module
tft_is_term_archived in ./tft.module
tft_manage_folders_form in includes/tft.pages.inc
Form: reorganize folder items.
tft_og_get_og_nid in modules/tft_og/tft_og.module
Check if the current term is part of a OG term and return the OG nid.

... See full list

File

./tft.module, line 900
Hook implementations and module logic for TFT.

Code

function tft_get_depth($tid) {
  static $cache = array();
  if (!$tid || !db_query("SELECT COUNT(tid) FROM {taxonomy_term_data} WHERE tid = :tid", array(
    ':tid' => $tid,
  ))
    ->fetchField()) {
    return 0;
  }
  if (isset($cache[$tid])) {
    return $cache[$tid];
  }
  $depth = 0;
  $pid = $tid;
  while ($pid = db_query("SELECT parent FROM {taxonomy_term_hierarchy} WHERE tid = :tid", array(
    ':tid' => $pid,
  ))
    ->fetchField()) {
    $depth++;
  }
  $cache[$tid] = $depth;
  return $depth;
}