function chado_featuremap_insert
2.x tripal_featuremap.chado_node.inc | chado_featuremap_insert($node) |
3.x tripal_featuremap.chado_node.inc | chado_featuremap_insert($node) |
1.x tripal_featuremap.module | chado_featuremap_insert($node) |
Implements hook_insert().
When a new chado_featuremap node is created we also need to add information to our chado_featuremap table. This function is called on insert of a new node of type 'chado_featuremap' and inserts the necessary information.
Related topics
File
- legacy/
tripal_featuremap/ includes/ tripal_featuremap.chado_node.inc, line 265 - Hooks implementing the feature map node content type
Code
function chado_featuremap_insert($node) {
$featuremap_id = '';
// if there is an featuremap_id in the $node object then this must be a sync so
// we can skip adding the featuremap as it is already there, although
// we do need to proceed with insertion into the chado/drupal linking table.
if (!property_exists($node, 'featuremap_id')) {
$node->fmapname = trim($node->fmapname);
$node->description = trim($node->description['value']);
$values = array(
'name' => $node->fmapname,
'description' => $node->description,
'unittype_id' => $node->unittype_id
);
$featuremap = chado_insert_record('featuremap', $values);
if (!$featuremap) {
drupal_set_message(t('Unable to add featuremap.', 'warning'));
tripal_report_error('tripal_featuremap', TRIPAL_WARNING, 'Unable to create feature map where values: %values',
array('%values' => print_r($values, TRUE)));
return;
}
$featuremap_id = $featuremap['featuremap_id'];
// now add in the properties
$properties = chado_retrieve_node_form_properties($node);
// We need to deal with the 'Map Dbxref' property specially
$cvterm = chado_select_record(
'cvterm',
array('cvterm_id'),
array('name' => 'Map Dbxref', 'cv_id' => array('name' => 'featuremap_property'))
);
$map_dbxref_cvterm_id = $cvterm[0]->cvterm_id;
if (isset($properties[$map_dbxref_cvterm_id])) {
foreach ($properties[$map_dbxref_cvterm_id] as $rank => $value) {
$featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap_id, $value);
if (!$featuremap_dbxref) {
drupal_set_message("Error cannot add featuremap cross reference: $value", "error");
tripal_report_error('t_featuremap', TRIPAL_ERROR, "Error cannot add featuremap cross reference: %ref",
array('%ref' => $value));
}
}
unset($properties[$map_dbxref_cvterm_id]);
}
$details = array(
'property_table' => 'featuremapprop',
'base_table' => 'featuremap',
'foreignkey_name' => 'featuremap_id',
'foreignkey_value' => $featuremap_id
);
chado_update_node_form_properties($node, $details, $properties);
// * Additional DBxrefs Form *
$details = array(
'linking_table' => 'featuremap_dbxref', // the name of your _dbxref table
'foreignkey_name' => 'featuremap_id', // the name of the key in your base table
'foreignkey_value' => $featuremap_id // the value of the featuremap_id key
);
chado_update_node_form_dbxrefs($node, $details);
}
else {
$featuremap_id = $node->featuremap_id;
}
// Make sure the entry for this featuremap doesn't already exist in the
// chado_featuremap table if it doesn't exist then we want to add it.
$check_org_id = chado_get_id_from_nid('featuremap', $node->nid);
if (!$check_org_id) {
$record = new stdClass();
$record->nid = $node->nid;
$record->vid = $node->vid;
$record->featuremap_id = $featuremap_id;
drupal_write_record('chado_featuremap', $record);
}
}