function get_chado_organisms
1.x tripal_organism.module | get_chado_organisms() |
This function uses organism_id's of all drupal organism nodes as input and pull the organism information (genus, species, common_name, comment) from chado database. The return type is an object array that stores $organism objects sorted by common_name
Related topics
File
- tripal_organism/
tripal_organism.module, line 592 - tripal_organism Organism Module
Code
function get_chado_organisms() {
$sql_drupal = "SELECT COUNT (organism_id) FROM {chado_organism}";
$no_orgs = db_result(db_query($sql_drupal));
if ($no_orgs != 0) {
$sql = "SELECT organism_id, nid FROM {chado_organism}";
$result = chado_query($sql);
$sql = "SELECT genus, species, common_name, comment " .
"FROM {Organism} " .
"WHERE organism_id=%d";
$organisms = array();
$count = 0;
while ($data = db_fetch_object($result)) {
$organism = db_fetch_object(chado_query($sql, $data->organism_id));
$organism->node_id = $data->nid;
// Use common_name plus $count as the key so we can sort by common
// name later. Since common_name is not unique, we need to add $count
// to the key
$key = drupal_strtolower($organism->common_name) . $count;
$organisms[$key] = $organism;
$count++;
}
//Sort organisms by common name
ksort($organisms, SORT_STRING);
return $organisms;
}
}