function chado_organism_insert
2.x tripal_organism.chado_node.inc | chado_organism_insert($node) |
3.x tripal_organism.chado_node.inc | chado_organism_insert($node) |
1.x tripal_organism.module | chado_organism_insert($node) |
When a new chado_organism node is created we also need to add information to our chado_organism table. This function is called on insert of a new node of type 'chado_organism' and inserts the necessary information.
Related topics
File
- tripal_organism/
tripal_organism.module, line 289 - tripal_organism Organism Module
Code
function chado_organism_insert($node) {
$values = array(
'genus' => $node->genus,
'species' => $node->species,
'abbreviation' => $node->abbreviation,
'common_name' => $node->common_name,
'comment' => $node->description
);
// if there is an organism_id in the $node object then this must be a sync so
// we can skip adding the organism as it is already there, although
// we do need to proceed with the rest of the insert
if (!$node->organism_id) {
$organism = tripal_core_chado_insert('organism', $values);
if (!$organism) {
drupal_set_message(t('Unable to add organism.', 'warning'));
watchdog('tripal_organism', 'Insert Organism: Unable to create organism where values:%values',
array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
return;
}
$organism_id = $organism['organism_id'];
}
else {
$organism_id = $node->organism_id;
}
// Make sure the entry for this organism doesn't already exist in the
// chado_organism table if it doesn't exist then we want to add it.
if (!chado_get_id_for_node('organism', $node)) {
// next add the item to the drupal table
$sql = "INSERT INTO {chado_organism} (nid, vid, organism_id) " .
"VALUES (%d, %d, %d)";
db_query($sql, $node->nid, $node->vid, $organism_id);
}
// set the title for the node
$record = new stdClass();
$record->title = "$node->genus $node->species";
$record->nid = $node->nid;
drupal_write_record('node', $record, 'nid');
drupal_write_record('node_revisions', $record, 'nid');
// add the image
chado_organism_add_image($node);
}