function chado_project_insert
2.x tripal_project.chado_node.inc | chado_project_insert($node) |
3.x tripal_project.chado_node.inc | chado_project_insert($node) |
1.x tripal_project.module | chado_project_insert($node) |
Implementation of hook_insert().
@parm $node Then node that has the information stored within, accessed given the nid
Related topics
File
- tripal_project/
includes/ tripal_project.chado_node.inc, line 240 - Implement the project node content type
Code
function chado_project_insert($node) {
$project_id = '';
// if there is an project_id in the $node object then this must be a sync so
// we can skip adding the project as it is already there, although
// we do need to proceed with insertion into the chado/drupal linking table.
if (!property_exists($node, 'project_id')) {
$node->title = trim($node->title);
$node->description = trim($node->description['value']);
$values = array(
'name' => $node->title,
'description' => '',
);
$project = chado_insert_record('project', $values);
if (!$project) {
drupal_set_message(t('Unable to add project.', 'warning'));
watchdog('tripal_project', 'Insert project: Unable to create project where values:%values',
array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
return;
}
$project_id = $project['project_id'];
// * Properties Form *
// Add the description property
$properties = chado_retrieve_node_form_properties($node);
$descrip_id = tripal_get_cvterm(array(
'name' => 'Project Description',
'cv_id' => array('name' => 'project_property')
));
$properties[$descrip_id->cvterm_id][0] = $node->description;
$details = array(
'property_table' => 'projectprop',
'base_table' => 'project',
'foreignkey_name' => 'project_id',
'foreignkey_value' => $project_id
);
chado_update_node_form_properties($node, $details, $properties);
// * Relationships Form *
$details = array(
'relationship_table' => 'project_relationship', // name of the _relationship table
'foreignkey_value' => $project_id // value of the example_id key
);
chado_update_node_form_relationships($node, $details);
}
else {
$project_id = $node->project_id;
}
// Make sure the entry for this project doesn't already exist in the
// chado_project table if it doesn't exist then we want to add it.
$check_org_id = chado_get_id_from_nid('project', $node->nid);
if (!$check_org_id) {
$record = new stdClass();
$record->nid = $node->nid;
$record->vid = $node->vid;
$record->project_id = $project_id;
drupal_write_record('chado_project', $record);
}
}