function chado_contact_insert
2.x tripal_contact.chado_node.inc | chado_contact_insert($node) |
3.x tripal_contact.chado_node.inc | chado_contact_insert($node) |
1.x tripal_contact.module | chado_contact_insert($node) |
Implements of hook_insert().
This function inserts user entered information pertaining to the contact instance into the 'contactauthor', 'contactprop', 'chado_contact', 'contact' talble of the database.
@parm $node Then node which contains the information stored within the node-ID
Related topics
File
- tripal_contact/
includes/ tripal_contact.chado_node.inc, line 367 - Implements drupal node hooks.
Code
function chado_contact_insert($node) {
$contact_id = '';
// if there is a contact_id in the $node object then this must be a sync so
// we can skip adding the contact as it is already there, although
// we do need to proceed with insertion into the chado/drupal linking table.
if (!property_exists($node, 'contact_id')) {
// remove surrounding white-space on submitted values
$node->contactname = trim($node->contactname);
$node->description = trim($node->description['value']);
// insert and then get the newly inserted contact record
$values = array(
'name' => $node->contactname,
'description' => '',
'type_id' => $node->type_id,
);
$contact = chado_insert_record('contact', $values);
if (!$contact) {
drupal_set_message(t('Unable to add contact.', 'warning'));
tripal_report_error('tripal_contact', TRIPAL_ERROR,
'Insert contact: Unable to create contact where values: %values',
array('%values' => print_r($values, TRUE)));
return;
}
$contact_id = $contact['contact_id'];
// Add the description property
$properties = chado_retrieve_node_form_properties($node);
$contact_descrip_id = tripal_get_cvterm(array(
'name' => 'contact_description',
'cv_id' => array('name' => 'tripal_contact')
));
$properties[$contact_descrip_id->cvterm_id][0] = $node->description;
// * Properties Form *
$details = array(
'property_table' => 'contactprop',
'base_table' => 'contact',
'foreignkey_name' => 'contact_id',
'foreignkey_value' => $contact_id
);
chado_update_node_form_properties($node, $details, $properties);
// * Relationships Form *
$details = array(
'relationship_table' => 'contact_relationship', // name of the _relationship table
'foreignkey_value' => $contact_id // value of the contact_id key
);
chado_update_node_form_relationships($node, $details);
}
else {
$contact_id = $node->contact_id;
}
// Make sure the entry for this contact doesn't already exist in the
// chado_contact table if it doesn't exist then we want to add it.
$check_org_id = chado_get_id_from_nid('contact', $node->nid);
if (!$check_org_id) {
$record = new stdClass();
$record->nid = $node->nid;
$record->vid = $node->vid;
$record->contact_id = $contact_id;
drupal_write_record('chado_contact', $record);
}
return TRUE;
}