diff options
author | Dries Buytaert <dries@buytaert.net> | 2002-12-12 18:54:17 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2002-12-12 18:54:17 +0000 |
commit | c760223682513cab1b504f4ad601619103dd1607 (patch) | |
tree | d3f6501ed1b42b33c6b9fc007f92fafb288a1e54 /modules/taxonomy/taxonomy.module | |
parent | b6b24c28e046bbd0bddb9b2b65ca9d4bddff24c8 (diff) | |
download | brdo-c760223682513cab1b504f4ad601619103dd1607.tar.gz brdo-c760223682513cab1b504f4ad601619103dd1607.tar.bz2 |
Patch by Marco:
- consistency in return order
(http://list.drupal.org/drupal-devel/2002-December/009522.html)
- new functions: taxonomy_get_term_by_name() and
taxonomy_get_vocabulary_by_name()
- caches are flushed after vocabulary and term edit/delete; this should
avoid problems like forums not up to date
Diffstat (limited to 'modules/taxonomy/taxonomy.module')
-rw-r--r-- | modules/taxonomy/taxonomy.module | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 150acf060..bdc39bf01 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -94,6 +94,8 @@ function taxonomy_save_vocabulary($edit) { db_query("INSERT INTO vocabulary ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2)); return t("created new vocabulary '%name'.", array("%name" => $edit["name"])); } + + cache_clear_all(); } function taxonomy_del_vocabulary($vid) { @@ -105,6 +107,8 @@ function taxonomy_del_vocabulary($vid) { taxonomy_del_term($term->tid); } + cache_clear_all(); + return t("deleted vocabulary '%name'.", array("%name" => $vocabulary->name)); } @@ -213,6 +217,8 @@ function taxonomy_save_term($edit) { } } + cache_clear_all(); + return $message; } @@ -225,6 +231,8 @@ function taxonomy_del_term($tid) { db_query("DELETE FROM term_synonym WHERE tid = '%d'", $tid); db_query("DELETE FROM term_node WHERE tid = '%d'", $tid); + cache_clear_all(); + return t("deleted term '%name'.", array("%name" => $term->name)); } @@ -354,7 +362,7 @@ 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", $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); $terms[$nid] = array(); while ($term = db_fetch_object($result)) { $terms[$nid][$term->$key] = $term; @@ -382,7 +390,7 @@ function taxonomy_node_delete($nid) { // relations: return array of related terms function taxonomy_get_related($tid, $key = "tid") { if ($tid) { - $result = db_query("SELECT t.*, tid1, tid2 FROM term_relation, term_data t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = '%d' OR tid2 = '%d') AND t.tid != '%d' ORDER BY weight", $tid, $tid, $tid); + $result = db_query("SELECT t.*, tid1, tid2 FROM term_relation, term_data t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = '%d' OR tid2 = '%d') AND t.tid != '%d' ORDER BY weight, name", $tid, $tid, $tid); $related = array(); while ($term = db_fetch_object($result)) { $related[$term->$key] = $term; @@ -514,6 +522,44 @@ function _taxonomy_term_children($tid) { return $children[$tid] ? $children[$tid] : array(); } +/** + * Try to map a string to existing vocabularies + * Provide case insensitive and trimmed map so as to + * maximize likelihood of successful mapping. + * + * @param string $name Name of the vocabulary to search + * @return array array of matching vocabularies, as objects + */ +function taxonomy_get_vocabulary_by_name($name) { + // LOWER is ANSI SQL-92 + $db_result = db_query("SELECT * FROM vocabulary WHERE LOWER('%s') LIKE LOWER(name)", trim($name)); + $result = array(); + while ($vocabulary = db_fetch_object($db_result)) { + $result[] = $vocabulary; + } + + return $result; +} + +/** + * Try to map a string to existing terms + * Provide case insensitive and trimmed map so as to + * maximize likelihood of successful mapping. + * + * @param string $name Name of the term to search + * @return array array of matching terms, as objects + */ +function taxonomy_get_term_by_name($name) { + // LOWER is ANSI SQL-92 + $db_result = db_query("SELECT * FROM term_data WHERE LOWER('%s') LIKE LOWER(name)", trim($name)); + $result = array(); + while ($term = db_fetch_object($db_result)) { + $result[] = $term; + } + + return $result; +} + function taxonomy_get_vocabulary($vid) { // simple cache using a static var? return db_fetch_object(db_query("SELECT * FROM vocabulary WHERE vid = '%d'", $vid)); |