You are here

function _taxonomy_edge_attach_subtree in Taxonomy Edge 8

Same name and namespace in other branches
  1. 6 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 498
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
  db_query("INSERT INTO {taxonomy_term_edge} (vid, tid, parent, distance)\n  SELECT e.vid, e2.tid, e.parent, e.distance + e2.distance + 1 AS distance\n  FROM {taxonomy_term_edge} e\n  INNER JOIN {taxonomy_term_edge} e2 ON e.tid IN (:parents) AND e2.parent = :tid AND e2.vid = e.vid\n  WHERE e.vid = :vid\n  ", array(
    ':tid' => $tid,
    ':parents' => $parents,
    ':vid' => $vid,
  ));
  taxonomy_edge_invalidate_order($vid);
}