You are here

function tft_get_og_nid in Taxonomy File Tree 7.2

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

Parameters

int $tid: The tid (and its ancestor tree) to check against

Return value

int|boolean The OG nid if found, else FALSE

Deprecated

move this to tft_og

Check if the current term is part of a OG term and return the OG nid. If no nid is found, return FALSE.

1 call to tft_get_og_nid()
tft_is_term_archived in ./tft.module

File

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

Code

function tft_get_og_nid($tid) {
  static $cache = array();
  if (is_array($tid)) {
    $tid = $tid[0];
  }
  $tid = (int) $tid;
  if (!$tid) {
    return FALSE;
  }
  if (isset($cache[$tid])) {
    return $cache[$tid];
  }
  $param_tid = $tid;
  $depth = tft_get_depth($tid);
  $og_nid = db_query("SELECT og_nid FROM {tft_tid_og_nid} WHERE tid = :tid", array(
    ':tid' => $tid,
  ))
    ->fetchField();
  while ($depth && $tid && !$og_nid) {
    $tid = db_query("SELECT parent FROM {taxonomy_term_hierarchy} WHERE tid = :tid", array(
      ':tid' => $tid,
    ))
      ->fetchField();
    $depth--;
    $og_nid = db_query("SELECT og_nid FROM {tft_tid_og_nid} WHERE tid = :tid", array(
      ':tid' => $tid,
    ))
      ->fetchField();
  }
  if ($og_nid) {
    $cache[$param_tid] = (int) $og_nid;
  }
  else {
    $cache[$param_tid] = FALSE;
  }
  return $cache[$param_tid];
}