You are here

function _taxonomy_edge_attach_subtree in Taxonomy Edge 6

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

Attach path and children to new parents

Parameters

$vid: Vocabulary ID

$tid: Term ID

$parents: Term ID of new parents

1 call to _taxonomy_edge_attach_subtree()
_taxonomy_edge_move_subtree in ./taxonomy_edge.module
Detach path and children from current parent and attach to new parents

File

./taxonomy_edge.module, line 407
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_attach_subtree($vid, $tid, $parents) {

  // Build new parents
  $args = $parents;
  array_unshift($args, $vid);
  $args[] = $tid;
  $args[] = $vid;
  $args[] = $vid;
  $placeholders = db_placeholders($parents);
  db_query("INSERT INTO {term_edge} (vid, tid, parent, distance)\n  SELECT %d, e2.tid, e.parent, e.distance + e2.distance + 1 AS distance\n  FROM {term_edge} e\n  INNER JOIN {term_edge} e2 ON e.tid IN ({$placeholders}) AND e2.parent = %d\n  WHERE e.vid = %d AND e2.vid = %d\n  ", $args);
  taxonomy_edge_invalidate_order($vid);
}