function chado_update_node_form_relationships

2.x tripal_core.chado_nodes.relationships.api.inc chado_update_node_form_relationships($node, $details, $retrieved_relationships = FALSE)
3.x tripal_core.chado_nodes.relationships.api.inc chado_update_node_form_relationships($node, $details, $retrieved_relationships = FALSE)

This function is used in hook_insert or hook_update and handles inserting of relationships between the current nodetype and other memebers of the same nodetype

Parameters

$node: The node passed into hook_insert & hook_update

$details:

  • relationship_table: the name of the _relationship linking table (ie: feature_relationship)
  • foreignkey_value: the value of the foreign key (ie: 445, if there exists a feature where feature_id=445)

$retrieved_relationships: An array of relationships from chado_retrieve_node_form_relationships($node). This can be used if you need special handling for some of the relationships.

Related topics

11 calls to chado_update_node_form_relationships()
chado_contact_insert in legacy/tripal_contact/includes/tripal_contact.chado_node.inc
Implements of hook_insert().
chado_contact_update in legacy/tripal_contact/includes/tripal_contact.chado_node.inc
Implements hook_update
chado_feature_insert in legacy/tripal_feature/includes/tripal_feature.chado_node.inc
Implements hook_insert().
chado_feature_update in legacy/tripal_feature/includes/tripal_feature.chado_node.inc
Implements hook_update().
chado_node_relationships_form_update_relationships in legacy/tripal_core/api/tripal_core.DEPRECATED.inc

... See full list

1 string reference to 'chado_update_node_form_relationships'

File

legacy/tripal_core/api/tripal_core.chado_nodes.relationships.api.inc, line 960
API to manage the chado _relationship table for various Tripal Node Types

Code

function chado_update_node_form_relationships($node, $details, $retrieved_relationships = FALSE) {

  $relationship_table = $details['relationship_table'];
  $current_id = $details['foreignkey_value'];

  if (isset($node->relationship_table) AND ($current_id > 0)) {

    // determine whether there is a rank in this relationship table
    $form_details = unserialize($node->relationship_table['details']);
    $has_rank = $form_details['table_has_rank'];

    // First remove existing relationships links
    chado_delete_record(
    $relationship_table, 
    array($form_details['subject_field_name'] => $current_id)
    );
    chado_delete_record(
    $relationship_table, 
    array($form_details['object_field_name'] => $current_id)
    );

    // Add back in relationships as needed
    if ($retrieved_relationships) {
      $relationships = $retrieved_relationships;
    }
    else {
      $relationships = chado_retrieve_node_form_relationships($node);
    }
    foreach ($relationships as $type_id => $ranks) {
      foreach ($ranks as $rank => $element) {

        $values = array(
          $form_details['subject_field_name'] => $element['subject_id'],
          'type_id' => $type_id,
          $form_details['object_field_name'] => $element['object_id']
        );

        // Set the current id if not already
        // this is usually only necessary in an insert
        if (empty($values[$form_details['subject_field_name']])) {
          $values[$form_details['subject_field_name']] = $current_id;
        }
        if (empty($values[$form_details['object_field_name']])) {
          $values[$form_details['object_field_name']] = $current_id;
        }

        if ($has_rank) {
          // Ensure that the rank is Set & Current
          $rank_select = chado_get_table_max_rank(
          $relationship_table, 
          array(
            $form_details['subject_field_name'] => $values['subject_id'],
            'type_id' => $values['type_id'],
            $form_details['object_field_name'] => $values['object_id'],
          )
          );
          $values['rank'] = $rank_select + 1;
        }

        // add relationship
        $success_link = chado_insert_record(
        $relationship_table, 
        $values
        );

      }
    }
  }
}