You are here

function tft_get_depth in Taxonomy File Tree 7

Same name and namespace in other branches
  1. 7.2 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

5 calls to tft_get_depth()
tft_get_og_nid in ./tft.module
Check if the current term is part of a OG term and return the OG nid. If no nid is found, return FALSE.
tft_is_archive_folder in ./tft.module
Checks if the term is an "Archive" term. These cannot be edited or deleted.
tft_is_term_archived in ./tft.module
Checks if the term is already archived.
tft_manage_folders_form in ./tft.admin.inc
Reorganise terms under the given term tid.
_tft_manage_folders_form in ./tft.admin.inc
Form helper. Flattens the terms tree and creates the form elements.

File

./tft.module, line 1214
Module hooks.

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;
}