function chado_featuremap_update

2.x tripal_featuremap.chado_node.inc chado_featuremap_update($node)
3.x tripal_featuremap.chado_node.inc chado_featuremap_update($node)
1.x tripal_featuremap.module chado_featuremap_update($node)

Implements hook_update(). Update nodes

Related topics

File

legacy/tripal_featuremap/includes/tripal_featuremap.chado_node.inc, line 349
Hooks implementing the feature map node content type

Code

function chado_featuremap_update($node) {

  $node->fmapname = trim($node->fmapname);
  $node->description = trim($node->description['value']);

  $featuremap_id = chado_get_id_from_nid('featuremap', $node->nid);

  // update the map record
  $match = array(
    'featuremap_id' => $featuremap_id,
  );
  $values = array(
    'name' => $node->fmapname,
    'description' => $node->description,
    'unittype_id' => $node->unittype_id
  );
  $status = chado_update_record('featuremap', $match, $values);
  if (!$status) {
    drupal_set_message("Error updating map", "error");
    tripal_report_error('t_featuremap', TRIPAL_ERROR, "Error updating map", array());
    return;
  }

  // Update 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);

}