function chado_autocomplete_feature

3.x tripal_chado.feature.api.inc chado_autocomplete_feature($string = '')

Used for autocomplete in forms for identifying for publications.

Parameters

$field: The field in the publication to search on.

$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_feature()
tripal_autocomplete_feature in tripal_chado/api/modules/tripal_chado.module.DEPRECATED.api.inc
Used for autocomplete in forms for identifying for publications.
1 string reference to 'chado_autocomplete_feature'
tripal_chado_menu in tripal_chado/tripal_chado.module
Implements hook_menu().

File

tripal_chado/api/modules/tripal_chado.feature.api.inc, line 30
Provides API functions specificially for managing feature records in Chado.

Code

function chado_autocomplete_feature($string = '') {
  $items = array();
  $sql = "
    SELECT
      F.feature_id, F.uniquename, F.name,
      O.genus, O,species,
      CVT.name as type
    FROM {feature} F
      INNER JOIN {organism} O ON O.organism_id = F.organism_id
      INNER JOIN {cvterm} CVT ON CVT.cvterm_id = F.type_id
    WHERE lower(F.uniquename) like lower(:str)
    ORDER by F.uniquename
    LIMIT 25 OFFSET 0
  ";
  $features = chado_query($sql, array(':str' => $string . '%'));
  while ($feature = $features->fetchObject()) {
    $key = "$feature->uniquename [id: $feature->feature_id]";
    $items[$key] = "$feature->uniquename ($feature->name, $feature->type, $feature->genus $feature->species)";
  }

  drupal_json_output($items);
}