function tripal_autocomplete_contact

2.x tripal_contact.api.inc tripal_autocomplete_contact($text)
3.x tripal_chado.module.DEPRECATED.api.inc tripal_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 string reference to 'tripal_autocomplete_contact'
tripal_contact_menu in tripal_contact/tripal_contact.module
Implemets hook_menu(). Adds menu items for the tripal_contact module menu. This section gives the outline for the main menu of the Tripal-contact module

File

tripal_contact/api/tripal_contact.api.inc, line 126
Functions to interact with contacts.

Code

function tripal_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);
}