function chado_analysis_update

2.x tripal_analysis.chado_node.inc chado_analysis_update($node)
3.x tripal_analysis.chado_node.inc chado_analysis_update($node)
1.x tripal_analysis.module chado_analysis_update($node)

Implements hook_update(). Update analyses

File

legacy/tripal_analysis/includes/tripal_analysis.chado_node.inc, line 514
Implements Drupal Node hooks to create the chado_analysis node content type.

Code

function chado_analysis_update($node) {
  $node->analysisname = trim($node->analysisname);
  $node->program = trim($node->program);
  $node->programversion = trim($node->programversion);
  $node->algorithm = trim($node->algorithm);
  $node->sourcename = trim($node->sourcename);
  $node->sourceversion = trim($node->sourceversion);
  $node->sourceuri = trim($node->sourceuri);
  $node->description = trim($node->description['value']);

  // Create a timestamp so we can insert it into the chado database
  $time = $node->timeexecuted;
  $month = $time['month'];
  $day = $time['day'];
  $year = $time['year'];
  $timestamp = $month . '/' . $day . '/' . $year;

  // update the record in Chado
  $analysis_id = chado_get_id_from_nid('analysis', $node->nid);
  $match = array(
    'analysis_id' => $node->analysis_id,
  );
  $values = array(
    'name' => $node->analysisname,
    'description' => $node->description,
    'program' => $node->program,
    'programversion' => $node->programversion,
    'algorithm' => $node->algorithm,
    'sourcename' => $node->sourcename,
    'sourceversion' => $node->sourceversion,
    'sourceuri' => $node->sourceuri,
    'timeexecuted' => $timestamp,
    'analysis_id' => $analysis_id
  );
  $status = chado_update_record('analysis', $match, $values);
  if (!$status) {
    drupal_set_message(t('Unable to update analysis.', 'warning'));
    tripal_report_error('tripal_analysis', TRIPAL_ERROR, 'Update analysis: Unable to update analysis where values: %values', 
    array('%values' => print_r($values, TRUE)));
  }

  // now add in the properties by first removing any the analysis
  // already has and adding the ones we have
  $details = array(
    'property_table' => 'analysisprop',
    'base_table' => 'analysis',
    'foreignkey_name' => 'analysis_id',
    'foreignkey_value' => $analysis_id
  );
  chado_update_node_form_properties($node, $details);
}