function chado_autocomplete_contact

3.x tripal_chado.contact.api.inc chado_autocomplete_contact($text)

This function is intended to be used in autocomplete forms for contacts.

Parameters

$text: 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_contact()
tripal_autocomplete_contact in tripal_chado/api/modules/tripal_chado.module.DEPRECATED.api.inc
This function is intended to be used in autocomplete forms for contacts.

File

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

Code

function chado_autocomplete_contact($text) {
  $matches = array();

  $sql = "SELECT * FROM {contact} WHERE lower(name) like lower(:name) ";
  $args = array();
  $args[':name'] = $text . '%';
  $sql .= "ORDER BY name ";
  $sql .= "LIMIT 25 OFFSET 0 ";
  $results = chado_query($sql, $args);
  $items = array();
  foreach ($results as $contact) {
    // Don't include the null contact
    if ($contact->name == 'null') {
      continue;
    }
    $items[$contact->name] = $contact->name;
  }
  drupal_json_output($items);
}