function chado_autocomplete_cvterm

3.x tripal_chado.cv.api.inc chado_autocomplete_cvterm($cv_id, $string = '')

This function is intended to be used in autocomplete forms for searching for CV terms that begin with the provided string.

Parameters

$cv_id: The CV ID in which to search for the term.

$string: The string to search for.

Return value

A json array of terms that begin with the provided string.

Related topics

1 call to chado_autocomplete_cvterm()
tripal_autocomplete_cvterm in tripal_chado/api/modules/tripal_chado.module.DEPRECATED.api.inc
This function is intended to be used in autocomplete forms for searching for CV terms that begin with the provided string.
1 string reference to 'chado_autocomplete_cvterm'
tripal_chado_menu in tripal_chado/tripal_chado.module
Implements hook_menu().

File

tripal_chado/api/modules/tripal_chado.cv.api.inc, line 1463
Provides API functions specificially for managing controlled vocabulary records in Chado.

Code

function chado_autocomplete_cvterm($cv_id, $string = '') {
  if ($cv_id) {
    $sql = "
      SELECT CVT.cvterm_id, CVT.name
      FROM {cvterm} CVT
      WHERE CVT.cv_id = :cv_id and lower(CVT.name) like lower(:name)
      UNION
      SELECT CVT2.cvterm_id, CVTS.synonym as name
      FROM {cvterm} CVT2
        INNER JOIN {cvtermsynonym} CVTS ON CVTS.cvterm_id = CVT2.cvterm_id
      WHERE CVT2.cv_id = :cv_id and lower(CVTS.synonym) like lower(:name)
      ORDER by name
      LIMIT 25 OFFSET 0
    ";
    $results = chado_query($sql, array(':cv_id' => $cv_id, ':name' => $string . '%'));
    $items = array();
    foreach ($results as $term) {
      $items[$term->name] = $term->name;
    }
  }
  // If a CV wasn't provided then search all of them, and include the cv
  // in the results.
  else {
    $sql = "
      SELECT CVT.cvterm_id, CVT.name, CV.name as cvname, CVT.cv_id
      FROM {cvterm} CVT
        INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
      WHERE lower(CVT.name) like lower(:name)
      UNION
      SELECT CVT2.cvterm_id, CVTS.synonym as name, CV2.name as cvname, CVT2.cv_id
      FROM {cvterm} CVT2
        INNER JOIN {cv} CV2 on CVT2.cv_id = CV2.cv_id
        INNER JOIN {cvtermsynonym} CVTS ON CVTS.cvterm_id = CVT2.cvterm_id
      WHERE lower(CVTS.synonym) like lower(:name)
      ORDER by name
      LIMIT 25 OFFSET 0
    ";
    $results = chado_query($sql, array(':name' => $string . '%'));
    $items = array();
    foreach ($results as $term) {
      $items[$term->name] = $term->name;
    }
  }

  drupal_json_output($items);
}