function chado_update_node_form_dbxrefs

2.x tripal_core.chado_nodes.dbxrefs.api.inc chado_update_node_form_dbxrefs($node, $details, $retrieved_dbxrefs = FALSE)

This function is used in hook_insert or hook_update and handles inserting of any new dbxrefs and creation of links between those dbxrefs and node content

Parameters

$node: The node passed into hook_insert & hook_update

$details:

  • linking_table: the name of the _dbxref linking table (ie: feature_dbxref)
  • foreignkey_name: the name of the foreign key used to link to the node content (ie: feature_id)
  • foreignkey_value: the value of the foreign key (ie: 445, if there exists a feature where feature_id=445)

$retrieved_dbxrefs: An array of databa references from chado_retrieve_node_form_dbxrefs($node). This can be used if you need special handling for some of the database references

Related topics

15 calls to chado_update_node_form_dbxrefs()
chado_example_insert in tripal_example/includes/tripal_example.chado_node.inc
Implementation of hook_insert(). This function is called after the node is inserted into the database. We need it so that we can insert appropriate fields as provided by the user into the database. And so that we can link the new Drupal node to the…
chado_example_update in tripal_example/includes/tripal_example.chado_node.inc
Implementation of hook_update(). This function runs after the node has been inserted into the Drupal schema and allows us to update the record in Chado.
chado_featuremap_insert in tripal_featuremap/includes/tripal_featuremap.chado_node.inc
Implements hook_insert().
chado_featuremap_update in tripal_featuremap/includes/tripal_featuremap.chado_node.inc
Implements hook_update(). Update nodes
chado_feature_insert in tripal_feature/includes/tripal_feature.chado_node.inc
Implements hook_insert().

... See full list

1 string reference to 'chado_update_node_form_dbxrefs'

File

tripal_core/api/tripal_core.chado_nodes.dbxrefs.api.inc, line 668
API to manage the chado _dbxref table for various Tripal Node Types

Code

function chado_update_node_form_dbxrefs($node, $details, $retrieved_dbxrefs = FALSE) {

  $linking_table = $details['linking_table'];
  $foreignkey_name = $details['foreignkey_name'];
  $foreignkey_value = $details['foreignkey_value'];

  if (isset($node->dbxref_table) AND ($foreignkey_value > 0)) {
    // First remove existing dbxref links
    chado_delete_record($linking_table, array($foreignkey_name => $foreignkey_value));

    // Add back in dbxref links and insert dbxrefs as needed
    if ($retrieved_dbxrefs) {
      $dbxrefs = $retrieved_dbxrefs;
    }
    else {
      $dbxrefs = chado_retrieve_node_form_dbxrefs($node);
    }
    foreach ($dbxrefs as $db_id => $versions) {
      foreach ($versions as $version => $elements) {
        foreach ($elements as $dbxref_id => $accession) {
          // If there is no dbxref then we have to create that first
          if (preg_match('/^TEMP/', $dbxref_id)) {
            $version = ($version == 'NONE') ? '' : $version;
            $success = tripal_insert_dbxref(array(
              'db_id' => $db_id,
              'accession' => $accession,
              'version' => $version,
              'description' => NULL
            ));
            if ($success) {
              $dbxref_id = $success->dbxref_id;
            }
            else {
              $dbxref_id = FALSE;
            }
          }

          // add _dbxref linker
          if ($dbxref_id) {
            if (preg_match('/(\w+)_dbxref/', $linking_table, $matches)) {
              $base_table = $matches[1];

              $success_link = tripal_associate_dbxref(
              $base_table, 
              $foreignkey_value, 
              array('dbxref_id' => $dbxref_id)
              );
            }
          }
        }
      }
    }
  }
}