function tripal_autocomplete_cvterm

2.x tripal_cv.api.inc tripal_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 tripal_autocomplete_cvterm()
2 string references to 'tripal_autocomplete_cvterm'
tripal_cv_cvterm_name_autocomplete in tripal_cv/api/tripal_cv.DEPRECATED.inc
tripal_cv_menu in tripal_cv/tripal_cv.module
Implements hook_menu(). Registers all menu items associated with this module

File

tripal_cv/api/tripal_cv.api.inc, line 898
This module provides a set of functions to simplify working with controlled vocabularies.

Code

function tripal_autocomplete_cvterm($cv_id, $string = '') {
  $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;
  }
  drupal_json_output($items);
}