You are here

function taxonomy_manager_autocomplete_search_terms in Taxonomy Manager 6.2

Same name and namespace in other branches
  1. 7 taxonomy_manager.admin.inc \taxonomy_manager_autocomplete_search_terms()

similar to taxonomy_manager_autocomplete_tags_get_tids, but used for searching terms takes synonyms and selected subtrees into account

Parameters

$typed_input input string of form field:

$vid vocabulary id: @param $include_synonyms TRUE if search should include synonyms

$parents array of parents:

Return value

array of term ids

1 call to taxonomy_manager_autocomplete_search_terms()
taxonomy_manager_form_submit in ./taxonomy_manager.admin.inc
submits the taxonomy manager form (only search button)

File

./taxonomy_manager.admin.inc, line 2308
Taxonomy Manager Admin

Code

function taxonomy_manager_autocomplete_search_terms($typed_input, $vid, $include_synonyms = FALSE, $parents = array(), $language = NULL) {
  $tids = array();
  if ($language != NULL && $language == "no language") {
    $language = "";
  }
  $regexp = '%(?:^|,\\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
  preg_match_all($regexp, $typed_input, $matches);
  $typed_terms = array_unique($matches[1]);
  foreach ($typed_terms as $typed_term) {
    $typed_term = str_replace('""', '"', preg_replace('/^"(.*)"$/', '\\1', $typed_term));
    $typed_term = trim($typed_term);
    if ($typed_term == "") {
      continue;
    }
    if ($include_synonyms) {
      if ($language != NULL) {
        $search_sql = db_query("SELECT td.tid FROM {term_data} td LEFT JOIN {term_synonym} ts ON td.tid = ts.tid WHERE td.vid = %d AND (td.name = '%s' OR ts.name = '%s') AND td.language = '%s'", $vid, $typed_term, $typed_term, $language);
      }
      else {
        $search_sql = db_query("SELECT td.tid FROM {term_data} td LEFT JOIN {term_synonym} ts ON td.tid = ts.tid WHERE td.vid = %d AND (td.name = '%s' OR ts.name = '%s')", $vid, $typed_term, $typed_term);
      }
    }
    else {
      if ($language != NULL) {
        $search_sql = db_query("SELECT td.tid FROM {term_data} td WHERE td.vid = %d AND td.name = '%s' AND td.language = '%s'", $vid, $typed_term, $language);
      }
      else {
        $search_sql = db_query("SELECT td.tid FROM {term_data} td WHERE td.vid = %d AND td.name = '%s'", $vid, $typed_term);
      }
    }
    while ($obj = db_fetch_object($search_sql)) {
      $tids[] = $obj->tid;
    }
    if (count($parents)) {
      $filtered_tids = array();
      foreach ($tids as $tid) {
        $parents_all = taxonomy_get_parents_all($tid);
        foreach ($parents_all as $key => $parent) {
          if (in_array($parent->tid, $parents)) {
            $filtered_tids[] = $tid;
            break;
          }
        }
      }
      $tids = $filtered_tids;
    }
  }
  return $tids;
}