You are here

function taxonomy_dupecheck_is_dupe_term in Taxonomy dupecheck 6

Same name and namespace in other branches
  1. 7 taxonomy_dupecheck.module \taxonomy_dupecheck_is_dupe_term()

Checks whether a term is a duplicate, based on the module preferences.

Parameters

$term: Name of the new term to check

int $vid: ID of the vocabulary the new term belongs to

int $tid: Term ID of the new term (used when updating an existing term name)

Return value

TRUE if the term is a duplicate, FALSE if not

1 call to taxonomy_dupecheck_is_dupe_term()
taxonomy_dupecheck_term_validate in ./taxonomy_dupecheck.module
Implements _form_validate() for taxonomy_form_term().

File

./taxonomy_dupecheck.module, line 142
Module file for the Taxonomy dupecheck module.

Code

function taxonomy_dupecheck_is_dupe_term($term, $vid, $tid = 0) {

  // Get case-sensitivity preference
  $case_sensitive = variable_get('taxonomy_dupecheck_case_sensitive', 0);

  // Get the terms via SQL instead of taxonomy_get_tree, which helps with large vocabs
  $sql = "SELECT TRIM(name) AS trimmed_name FROM {term_data} WHERE vid = %d AND name = TRIM('%s') AND tid <> '%d'";
  $result = db_query($sql, $vid, $term, $tid);
  while ($found_term = db_fetch_object($result)) {

    // Do case (in)sensitive comparison
    if ($case_sensitive && !strcmp($found_term->trimmed_name, $term) || !$case_sensitive && !strcasecmp($found_term->trimmed_name, $term)) {
      return TRUE;
    }
  }
  return FALSE;
}