Browse Source

Chado Node API: updated dbxref/relationship api to handle pre-retrieved records in the update functions and changed the update function params to match the details arry form used elsewhere

Lacey Sanderson 11 năm trước cách đây
mục cha
commit
9787eedc1f

+ 18 - 8
tripal_core/api/tripal_core.chado_nodes.dbxrefs.api.inc

@@ -581,23 +581,33 @@ function chado_node_additional_dbxrefs_form_retreive($node) {
  *
  * @param $node
  *    The node passed into hook_insert & hook_update
- * @param $linking_table
- *    The name of the _dbxref linking table (ie: feature_dbxref)
- * @param $foreignkey_name
- *    The name of the foreign key used to link to the node content (ie: feature_id)
- * @param $foreignkey_value
- *    The value of the foreign key (ie: 445, if there exists a feature where feature_id=445)
+ * @param $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)
+ * @param $retrieved_dbxrefs
+ *   An array of databa references from chado_node_additional_dbxrefs_form_retreive($node).
+ *   This can be used if you need special handling for some of the database references
  *
  * @ingroup tripal_chado_node_api
  */
-function chado_node_additional_dbxrefs_form_update_dbxrefs($node, $linking_table, $foreignkey_name, $foreignkey_value) {
+function chado_node_additional_dbxrefs_form_update_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
     tripal_core_chado_delete($linking_table, array($foreignkey_name => $foreignkey_value));
 
     // Add back in dbxref links and insert dbxrefs as needed
-    $dbxrefs = chado_node_additional_dbxrefs_form_retreive($node);
+    if ($retrieved_dbxrefs) {
+      $dbxrefs = $retrieved_dbxrefs;
+    }
+    else {
+      $dbxrefs = chado_node_additional_dbxrefs_form_retreive($node);
+    }
     foreach ($dbxrefs as $db_id => $versions) {
       foreach ($versions as $version => $elements) {
         foreach ($elements as $dbxref_id => $accession) {

+ 16 - 6
tripal_core/api/tripal_core.chado_nodes.relationships.api.inc

@@ -726,14 +726,19 @@ function chado_node_relationships_form_retreive($node) {
  *
  * @param $node
  *    The node passed into hook_insert & hook_update
- * @param $relationship_table
- *    The name of the _relationship linking table (ie: feature_relationship)
- * @param $current_id
- *    The value of the foreign key (ie: 445, if there exists a feature where feature_id=445)
+ * @param $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)
+ * @param $retrieved_relationships
+ *   An array of relationships from chado_node_relationships_form_retreive($node). This
+ *   can be used if you need special handling for some of the relationships.
  *
  * @ingroup tripal_chado_node_api
  */
-function chado_node_relationships_form_update_relationships($node, $relationship_table, $current_id) {
+function chado_node_relationships_form_update_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)) {
     // First remove existing relationships links
@@ -741,7 +746,12 @@ function chado_node_relationships_form_update_relationships($node, $relationship
     tripal_core_chado_delete($relationship_table, array('object_id' => $current_id));
 
     // Add back in relationships as needed
-    $relationships = chado_node_relationships_form_retreive($node);
+    if ($retrieved_relationships) {
+      $relationships = $retrieved_relationships;
+    }
+    else {
+      $relationships = chado_node_relationships_form_retreive($node);
+    }
     foreach ($relationships as $type_id => $ranks) {
       foreach ($ranks as $rank => $element) {
 

+ 19 - 18
tripal_stock/includes/tripal_stock.chado_node.inc

@@ -545,18 +545,19 @@ function chado_stock_insert($node) {
       chado_node_properties_form_update_properties($node, $details);
 
       // Now add the additional references
-      chado_node_additional_dbxrefs_form_update_dbxrefs(
-        $node,
-        'stock_dbxref',
-        'stock_id',
-        $stock_id
+      $details = array(
+        'linking_table' => 'stock_dbxref',
+        'foreignkey_name' => 'stock_id',
+        'foreignkey_value' => $stock_id
       );
+      chado_node_additional_dbxrefs_form_update_dbxrefs($node, $details);
+
       // Now add in relationships
-      chado_node_relationships_form_update_relationships(
-        $node,
-        'stock_relationship',
-        $stock_id
+      $details = array(
+        'relationship_table' => 'stock_relationship',
+        'foreignkey_value' => $node->stock_id
       );
+      chado_node_relationships_form_update_relationships($node, $details);
     }
   } //end of adding stock to chado
   else {
@@ -722,21 +723,21 @@ function chado_stock_update($node) {
 
   // now update the additional dbxrefs
   if ($node->stock_id > 0) {
-    chado_node_additional_dbxrefs_form_update_dbxrefs(
-      $node,
-      'stock_dbxref',
-      'stock_id',
-      $node->stock_id
+    $details = array(
+      'linking_table' => 'stock_dbxref',
+      'foreignkey_name' => 'stock_id',
+      'foreignkey_value' => $node->stock_id
     );
+    chado_node_additional_dbxrefs_form_update_dbxrefs($node, $details);
   }
 
   // now update relationships
   if ($node->stock_id > 0) {
-    chado_node_relationships_form_update_relationships(
-      $node,
-      'stock_relationship',
-      $node->stock_id
+    $details = array(
+      'relationship_table' => 'stock_relationship',
+      'foreignkey_value' => $node->stock_id
     );
+    chado_node_relationships_form_update_relationships($node, $details);
   }
 }