function chado_autocomplete_organism
3.x tripal_chado.organism.api.inc | chado_autocomplete_organism($text) |
This function is intended to be used in autocomplete forms for searching for organisms that begin with the provided string.
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_organism()
- tripal_autocomplete_organism in tripal_chado/
api/ modules/ tripal_chado.module.DEPRECATED.api.inc - This function is intended to be used in autocomplete forms for searching for organisms that begin with the provided string.
1 string reference to 'chado_autocomplete_organism'
- tripal_chado_menu in tripal_chado/
tripal_chado.module - Implements hook_menu().
File
- tripal_chado/
api/ modules/ tripal_chado.organism.api.inc, line 293 - Provides API functions specificially for managing feature records in Chado.
Code
function chado_autocomplete_organism($text) {
$matches = array();
$genus = $text;
$species = '';
if (preg_match('/^(.*?)\s+(.*)$/', $text, $matches)) {
$genus = $matches[1];
$species = $matches[2];
}
$sql = "SELECT * FROM {organism} WHERE lower(genus) like lower(:genus) ";
$args = array();
$args[':genus'] = $genus . '%';
if ($species) {
$sql .= "AND lower(species) like lower(:species) ";
$args[':species'] = $species . '%';
}
$sql .= "ORDER BY genus, species ";
$sql .= "LIMIT 25 OFFSET 0 ";
$results = chado_query($sql, $args);
$items = array(['args'[$sql $args]]);
foreach ($results as $organism) {
$name = chado_get_organism_scientific_name($organism);
$items["$name [id: $organism->organism_id]"] = $name;
}
drupal_json_output($items);
}