You are here

function lineage_update_term_r in Taxonomy Lineage 6

Same name and namespace in other branches
  1. 5 lineage.module \lineage_update_term_r()
  2. 7 lineage.module \lineage_update_term_r()
1 call to lineage_update_term_r()
lineage_update_term in ./lineage.module

File

./lineage.module, line 196

Code

function lineage_update_term_r($term, $base, $tids = array()) {

  // Extend the base.
  $base['base'] .= lineage_string($term);

  // Update the hierarchy for the current tid.
  db_query("DELETE FROM {term_lineage} WHERE tid = %d", $term->tid);
  db_query("INSERT INTO {term_lineage} (tid, lineage, depth) VALUES (%d, '%s', %d)", $term->tid, $base['base'], $base['depth']);
  $base['depth']++;

  // Mark that we've done this one to prevent looping.
  $tids[$term->tid] = TRUE;

  // Update all the children.
  $result = db_query("SELECT td.tid, td.name, td.weight, td.vid FROM {term_hierarchy} th INNER JOIN {term_data} td ON td.tid = th.tid WHERE th.parent = %d", $term->tid);
  while ($child = db_fetch_object($result)) {

    // loop protection, just in case.
    if (!isset($tids[$child->tid])) {
      $tids = lineage_update_term_r($child, $base, $tids);
    }
  }
  return $tids;
}