You are here

function taxonomy_edge_get_top_tids in Taxonomy Edge 6

Same name and namespace in other branches
  1. 8 taxonomy_edge.module \taxonomy_edge_get_top_tids()
  2. 7 taxonomy_edge.module \taxonomy_edge_get_top_tids()

Get top term ids.

Parameters

$tid: Term ID to get top term ID from.

Return value

array Top term IDs.

2 calls to taxonomy_edge_get_top_tids()
TaxonomyEdgeTreeTestCase::testParents in tests/tree.test
taxonomy_edge_get_top_tid in ./taxonomy_edge.module
Get top term id.

File

./taxonomy_edge.module, line 766
Selecting all children of a given taxonomy term can be a pain. This module makes it easier to do this, by maintaining a complete list of edges for each term using the adjecency matrix graph theory.

Code

function taxonomy_edge_get_top_tids($tid) {
  $result = db_query("SELECT DISTINCT e2.parent\n    FROM {term_edge} e\n    JOIN {term_edge} e2 ON e2.tid = e.tid AND e2.distance = e.distance - 1 AND e2.parent <> e.parent\n    WHERE e.tid = %d\n    AND e.parent = 0\n    AND e.vid = e2.vid\n  ", $tid);
  $toptids = array();
  while ($row = db_fetch_object($result)) {
    $toptids[$row->parent] = $row->parent;
  }
  return $toptids;
}