--- taxonomy.module.original 2004-12-24 17:49:46.000000000 +1100 +++ taxonomy.module 2005-02-13 19:38:20.000000000 +1100 @@ -450,13 +450,15 @@ } /** - * Find all terms associated to the given node. + * Find all terms associated to the given node. + * SQL patch made by x on xxxx-xx-xx, to sort taxonomies by vocab weight rather than by term weight */ function taxonomy_node_get_terms($nid, $key = 'tid') { static $terms; if (!isset($terms[$nid])) { - $result = db_query('SELECT t.* FROM {term_data} t, {term_node} r WHERE r.tid = t.tid AND r.nid = %d ORDER BY weight, name', $nid); + $result = db_query('SELECT t.* FROM {term_data} t, {term_node} r, {vocabulary} v '. + 'WHERE r.tid = t.tid AND t.vid = v.vid AND r.nid = %d ORDER BY v.weight, v.name', $nid); $terms[$nid] = array(); while ($term = db_fetch_object($result)) { $terms[$nid][$term->$key] = $term; @@ -505,11 +507,21 @@ } /** - * Find all parents of a given term ID. + * Find all parents of a given term ID. + * Patched to allow cross-vocabulary relationships. + * Patch done by x on xxxx-xx-xx. */ -function taxonomy_get_parents($tid, $key = 'tid') { +function taxonomy_get_parents($tid, $key = 'tid', $distantparent = FALSE) { if ($tid) { - $result = db_query('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.parent = t.tid AND h.tid = %d ORDER BY weight, name', $tid); + if ($distantparent) { + // Cross-vocabulary-aware SQL query + $sql_distantparent = 'SELECT t.* FROM {term_data} t, {term_hierarchy} h LEFT JOIN {term_distantparent} d ON h.tid = d.tid '. + 'WHERE h.tid = %d AND (d.parent = t.tid OR h.parent = t.tid)'; + $result = db_query($sql_distantparent, $tid); + } else { + //Original drupal query + $result = db_query('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.parent = t.tid AND h.tid = %d ORDER BY weight, name', $tid); + } $parents = array(); while ($parent = db_fetch_object($result)) { $parents[$parent->$key] = $parent; @@ -522,14 +534,16 @@ } /** - * Find all ancestors of a given term ID. + * Find all ancestors of a given term ID. + * Patched to call helper functions using the optional "distantparent" argument, so that cross-vocabulary-aware queries are activated. + * Patch done by x on xxxx-xx-xx. */ -function taxonomy_get_parents_all($tid) { +function taxonomy_get_parents_all($tid, $distantparent = FALSE) { $parents = array(); if ($tid) { $parents[] = taxonomy_get_term($tid); $n = 0; - while ($parent = taxonomy_get_parents($parents[$n]->tid)) { + while ($parent = taxonomy_get_parents($parents[$n]->tid, 'tid', $distantparent)) { $parents = array_merge($parents, $parent); $n++; }