You are here

function facetapi_callback_taxonomy_hierarchy in Facet API 6

Gets parent information for taxonomy terms.

Parameters

&$tids: An array containing the term ids.

Return value

An associative array keyed by term ID to parent ID.

1 string reference to 'facetapi_callback_taxonomy_hierarchy'
facetapi_facetapi_facet_info in ./facetapi.module
Implementation of hook_facetapi_facet_info().

File

./facetapi.callbacks.inc, line 120
Various callbacks referenced in facet definitions.

Code

function facetapi_callback_taxonomy_hierarchy(array $tids) {
  $placeholders = db_placeholders($tids);
  $sql = "\n    SELECT tid, parent\n    FROM {term_hierarchy}\n    WHERE parent > 0 AND (tid IN ({$placeholders}) OR parent IN ({$placeholders}))\n  ";

  // Executes query to get parents, relates the terms to one another.
  $parents = array();
  if ($result = db_query($sql, array_merge($tids, $tids))) {
    while ($record = db_fetch_object($result)) {
      $parents[$record->tid][] = $record->parent;
    }
  }
  return $parents;
}