You are here

function tft_get_parent_tid in Taxonomy File Tree 7.2

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

Get the parent tid based on a tid.

Parameters

int $tid:

Return value

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

Related topics

4 calls to tft_get_parent_tid()
tft_ajax_get_folder in includes/tft.ajax.inc
Page callback: get folder content via AJAX.
tft_archive_get_closest_parent_archive_tid in modules/tft_archive/tft_archive.module
Helper function to get the closest archive folder.
tft_archive_term_form_submit in modules/tft_archive/includes/tft_archive.pages.inc
Submission callback for tft_archive_term_form().
tft_get_folder_menu_links in ./tft.module
Return a list of links for the folder menu.

File

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

Code

function tft_get_parent_tid($tid) {
  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];
}