function _taxonomy_edge_taxonomy_term_insert in Taxonomy Edge 6
Same name and namespace in other branches
- 8 taxonomy_edge.module \_taxonomy_edge_taxonomy_term_insert()
- 7.2 taxonomy_edge.module \_taxonomy_edge_taxonomy_term_insert()
- 7 taxonomy_edge.module \_taxonomy_edge_taxonomy_term_insert()
Insert a term into the edge tree.
Parameters
type $term:
2 calls to _taxonomy_edge_taxonomy_term_insert()
- taxonomy_edge_process_queue_item in ./
taxonomy_edge.module - Cron queue worker Process edge for a queued term.
- taxonomy_edge_taxonomy_term_insert in ./
taxonomy_edge.module - Implements hook_taxonomy_term_insert().
File
- ./
taxonomy_edge.module, line 444 - 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_taxonomy_term_insert($term) {
$vocabulary = taxonomy_vocabulary_load($term->vid);
// Derive proper parents.
$parents = _taxonomy_edge_unify_parents($term->parent);
if ($term->tid > 0) {
$tx = _taxonomy_edge_db_transaction();
db_query("INSERT INTO {term_edge} (vid, tid, parent) VALUES(%d, %d, %d)", $term->vid, $term->tid, $term->tid);
$args = $parents;
array_unshift($args, $term->tid);
array_unshift($args, $term->vid);
$args[] = $term->vid;
$placeholders = db_placeholders($parents);
db_query("INSERT INTO {term_edge} (vid, tid, parent, distance)\n SELECT %d AS vid, %d AS tid, e.parent, e.distance + 1 AS distance\n FROM {term_edge} e\n WHERE e.tid IN ({$placeholders})\n AND e.vid = %d\n ", $args);
taxonomy_edge_invalidate_order($term->vid);
}
else {
watchdog('taxonomy_edge', 'Invalid term-id (%tid) received', array(
'%tid' => $term->tid,
), WATCHDOG_ERROR);
}
}