function chado_library_insert
2.x tripal_library.chado_node.inc | chado_library_insert($node) |
3.x tripal_library.chado_node.inc | chado_library_insert($node) |
1.x tripal_library.module | chado_library_insert($node) |
When a new chado_library node is created we also need to add information to our chado_library table. This function is called on insert of a new node of type 'chado_library' and inserts the necessary information.
Related topics
File
- tripal_library/
tripal_library.module, line 566
Code
function chado_library_insert($node) {
if ($node->library_id) {
$library['library_id'] = $node->library_id;
}
else {
$values = array(
'name' => $node->title,
'uniquename' => $node->uniquename,
'organism_id' => $node->organism_id,
'type_id' => $node->library_type,
);
$library = tripal_core_chado_insert('library', $values);
}
if ($library) {
// add the description property
tripal_library_insert_property($library['library_id'], 'library_description',
$node->library_description);
// make sure the entry for this feature doesn't already exist in the chado_library table
// if it doesn't exist then we want to add it.
$library_id = chado_get_id_for_node('library', $node);
if (!$library_id) {
// next add the item to the drupal table
$sql = "INSERT INTO {chado_library} (nid, vid, library_id) " .
"VALUES (%d, %d, %d)";
db_query($sql, $node->nid, $node->vid, $library['library_id']);
}
}
else {
drupal_set_message(t('Unable to add library.', 'warning'));
watchdog('tripal_library',
'Insert feature: Unable to create library where values: %values',
array('%values' => print_r($values, TRUE)),
WATCHDOG_WARNING
);
}
}