Browse Source

The validate function now handles three schenarios:
-Update a node that exists in both drupal and chado
-Synchronizing a node from chado to drupal
-Inserting a new node that exists in niether drupal nor chado

mestato 14 years ago
parent
commit
14dde24292
1 changed files with 65 additions and 47 deletions
  1. 65 47
      tripal_analysis_blast/tripal_analysis_blast.module

+ 65 - 47
tripal_analysis_blast/tripal_analysis_blast.module

@@ -1218,66 +1218,84 @@ function chado_analysis_blast_form ($node){
 }
 
 function chado_analysis_blast_validate($node, &$form){
-    //dprint_r($node);
+    ##dprint_r($node);
+
+    // This validation is being used for three activities:
+    // CASE A: Update a node that exists in both drupal and chado
+    // CASE B: Synchronizing a node from chado to drupal
+    // CASE C: Inserting a new node that exists in niether drupal nor chado
 
     // Only nodes being updated will have an nid already
     if($node->nid){
         //---------------------------------------------------
-        // We are validating a form for updating an existing node
+        // CASE A: We are validating a form for updating an existing node
         //---------------------------------------------------
 
         // TO DO: check that the new fields don't yield a non-unique primary key in chado
     }
     else{
-        //---------------------------------------------------
-        // We are validating a form for inserting a new node
-        //---------------------------------------------------
-        // The primary key for the chado analysis table is 
-        // program, programversion, sourcename
-        // Check to see if this analysis really is new -ie, it doesn't have the same
-        // primary key as any other analysis 
-	    $sql = "SELECT analysis_id ".
-            "FROM {analysis} ".
-            "WHERE program='%s'".
-            "AND programversion='%s'".
-            "AND sourcename='%s'";
-	    $previous_db = db_set_active('chado');
-	    $analysis_id = db_result(db_query($sql, $node->program, $node->programversion, $node->sourcename));
-        db_set_active($previous_db);
-    
-        if($analysis_id){
+        // To differentiate if we are syncing or creating a new analysis altogther, see if an
+        // analysis_id already exists
+
+        if($node->analysis_id){
+
             //---------------------------------------------------
-            // this primary key already exists in chado analysis table!
+            // CASE B: Synchronizing a node from chado to drupal
             //---------------------------------------------------
-    
-            // check to see if it has also been synced with drupal
-	        $sql = "SELECT nid FROM {chado_analysis} ".
-                            "WHERE analysis_id = %d";
-	        $node_id = db_result(db_query($sql, $analysis_id));
-	        if($node_id){
-                //---------------------------------------------------
-                // the analysis has already been synced with drupal, redirect the user
-                // to modify that node or start over
-                //---------------------------------------------------
-                $error = 'This analysis already exists in the chado database (analysis id ';
-                $error .= $analysis_id.') and has been synchronized ';
-                    $error .= 'with drupal. See node '.$node_id.' if you wish to update that analysis.  ';
-                $error .= ' For a new analysis, please select a unique primary key ';
-                $error .= '(primary key consists of sourcename, program and programversion).';
-                form_set_error('sourcename', t($error));
-            }
-    
-            else{
+
+        }
+        else{
+
+            //---------------------------------------------------
+            // CASE C: We are validating a form for inserting a new node
+            //---------------------------------------------------
+            // The primary key for the chado analysis table is 
+            // program, programversion, sourcename
+            // Check to see if this analysis really is new -ie, it doesn't have the same
+            // primary key as any other analysis 
+	        $sql = "SELECT analysis_id ".
+                "FROM {analysis} ".
+                "WHERE program='%s'".
+                "AND programversion='%s'".
+                "AND sourcename='%s'";
+	        $previous_db = db_set_active('chado');
+	        $analysis_id = db_result(db_query($sql, $node->program, $node->programversion, $node->sourcename));
+            db_set_active($previous_db);
+        
+            if($analysis_id){
                 //---------------------------------------------------
-                // the analysis does not exist in drupal - tell the user 
-                // to sync from chado or create a new unique primary key
+                // this primary key already exists in chado analysis table!
                 //---------------------------------------------------
-                $error = 'This analysis already exists in the chado database (analysis id ';
-                $error .= $analysis_id.') but has not been synchronized ';
-                $error .= 'with drupal. See the tripal admin pages to synchronize. ';
-                $error .= ' For a new analysis, please select a unique primary key ';
-                $error .= '(primary key consists of sourcename, program and programversion).';
-                form_set_error('sourcename', t($error));
+        
+                // check to see if it has also been synced with drupal
+	            $sql = "SELECT nid FROM {chado_analysis} ".
+                                "WHERE analysis_id = %d";
+	            $node_id = db_result(db_query($sql, $analysis_id));
+	            if($node_id){
+                    //---------------------------------------------------
+                    // the analysis has already been synced with drupal, redirect the user
+                    // to modify that node or start over
+                    //---------------------------------------------------
+                    $error = 'This analysis already exists in the chado database (analysis id ';
+                    $error .= $analysis_id.') and has been synchronized ';
+                        $error .= 'with drupal. See node '.$node_id.' if you wish to update that analysis.  ';
+                    $error .= ' For a new analysis, please select a unique primary key ';
+                    $error .= '(primary key consists of sourcename, program and programversion).';
+                    form_set_error('sourcename', t($error));
+                }
+        
+                else{
+                    //---------------------------------------------------
+                    // the analysis does not exist in drupal - tell the user 
+                    // to sync from chado or create a new unique primary key
+                    //---------------------------------------------------
+                    $error = 'This analysis already exists in the chado database (analysis id ';
+                    $error .= $analysis_id.') but has not been synchronized ';
+                    $error .= 'with drupal. See the tripal admin pages to synchronize. ';
+                    $error .= ' For a new analysis, please select a unique primary key ';
+                    $error .= '(primary key consists of sourcename, program and programversion).';
+                    form_set_error('sourcename', t($error));
+                }
             }
         }
     }