You are here

function tft_get_parent_tid in Taxonomy File Tree 7

Same name and namespace in other branches
  1. 7.2 tft.module \tft_get_parent_tid()

Get the parent tid based on a tid.

Parameters

int $tid: The taxonomy term tid

Return value

int The parent tid or 0 if there's no parent. Will return -1 if the tid is null or 0.

2 calls to tft_get_parent_tid()
tft_ajax_get_folder in ./tft.ajax.inc
Menu function callback for getting the forlder content via AJAX. Returns a JSON object with a 'data' key for the HTML table and a 'parent' key for the parent taxonomy term tid. A 'ops_links' key stores the folder menu.
tft_get_folder_operation_links in ./tft.module
Return an <ul> with links for the current folder. Links include:

File

./tft.module, line 1187
Module hooks.

Code

function tft_get_parent_tid($tid, $gid = NULL) {
  static $cache = array();
  if (!(int) $tid) {
    return -1;
  }
  if (isset($cache[$tid])) {
    return $cache[$tid];
  }
  $result = db_query("SELECT `parent` FROM {taxonomy_term_hierarchy} WHERE tid = :tid", array(
    ':tid' => $tid,
  ))
    ->fetchField();
  $cache[$tid] = is_null($result) ? -1 : $result;
  return (int) $cache[$tid];
}