function chado_contact_update

2.x tripal_contact.chado_node.inc chado_contact_update($node)
3.x tripal_contact.chado_node.inc chado_contact_update($node)
1.x tripal_contact.module chado_contact_update($node)

Implements hook_update

The purpose of the function is to allow the module to take action when an edited node is being updated. It updates any name changes to the database tables that were created upon registering a contact. As well, the database will be changed, so the user changed information will be saved to the database.

Parameters

$node: The node being updated

Related topics

File

tripal_contact/includes/tripal_contact.chado_node.inc, line 450
Implements drupal node hooks.

Code

function chado_contact_update($node) {
  // remove surrounding white-space on submitted values
  $node->contactname = trim($node->contactname);
  $node->description = trim($node->description['value']);

  $contact_id = chado_get_id_from_nid('contact', $node->nid);

  // update the contact record
  $match = array(
    'contact_id' => $contact_id,
  );
  $values = array(
    'name' => $node->contactname,
    'description' => '',
    'type_id' => $node->type_id
  );
  $status = chado_update_record('contact', $match, $values);
  if (!$status) {
    drupal_set_message("Error updating contact", "error");
    tripal_report_error('tripal_contact', TRIPAL_ERROR, 
    "Error updating contact", array());
    return;
  }

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

  // now add in the properties by first removing any the contact
  // already has and adding the ones we have
  $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);
}