You are here

function taxonomy_edge_locate_paths in Taxonomy Edge 7.2

Locate path IDs for a term (unique term = term + parent)

Parameters

integer $tid: Term ID

array $parents: List of parent term IDs

Return value

array List of path IDs

1 call to taxonomy_edge_locate_paths()
_taxonomy_edge_taxonomy_term_update in ./taxonomy_edge.module
Update a term in the edge tree.

File

./taxonomy_edge.module, line 741
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_locate_paths($tid, $parents) {
  $pids = db_query("\n    SELECT p2.tid AS parent, p.pid\n    FROM {taxonomy_term_edge_path} p\n    INNER JOIN {taxonomy_term_edge} e ON e.pid = p.pid AND e.distance = 1\n    INNER JOIN {taxonomy_term_edge_path} p2 ON p2.pid = e.parent\n    WHERE p.tid = :tid AND p2.tid IN (:parents)\n  ", array(
    ':tid' => $tid,
    ':parents' => $parents,
  ))
    ->fetchAllAssoc('parent', PDO::FETCH_ASSOC);

  // @fixme Using _taxonomy_edge_unify_parents() for flattening the array.
  foreach ($pids as &$pid) {
    $pid = $pid['pid'];
  }
  return $pids;
}