Browse Source

Added some error messages if the cv could not be found using the values in the array

Stephen Ficklin 11 years ago
parent
commit
40a22f19d1

+ 30 - 9
tripal_core/api/tripal_core.chado_nodes.properties.api.inc

@@ -131,8 +131,23 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
   if (isset($details['select_options'])) {
     $property_options = $details['select_options'];
   }
+  // if the select options are not provided then try to get them on our own
   else {
+    
+    // if the vocabulary name is provided in the details then use that to
+    // get the terms 
     if (isset($details['cv_name'])) {
+      // make sure the cv_name is real
+      $result = chado_select_record('cv',array('cv_id'),array('name' => $details['cv_name']));
+      if (count($result) == 0) {
+        drupal_set_message("Cannot add property elements to the form. The CV name, '" . $details['cv_name'] . "', does not exists", "error");
+        tripal_report_error('tcprops_form', TRIPAL_ERROR, "Cannot add property elements to the form. The CV named, '%name',
+          cannot be found.", array('%name' => $details['cv_name']));
+        return;
+      }
+      // add the cv_id option to the details array
+      $details['cv_id'] = $result[0]->cv_id;
+      
       $property_options = array();
       $property_options[] = 'Select a Property';
       $sql = "
@@ -149,11 +164,20 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
         $property_options[$prop->cvterm_id] = $prop->name;
         $details['cv_id'] = $prop->cv_id;
       }
-      if (!isset($details['cv_id'])) {
-        $result = chado_select_record('cv',array('cv_id'),array('name' => $details['cv_name']));
-        $details['cv_id'] = $result[0]->cv_id;
+    } 
+    // if the cv_id is set in the $details array then use that to get the terms
+    elseif (isset($details['cv_id'])) {
+      // make sure the cv_id is real
+      $result = chado_select_record('cv', array('name'), array('cv_id' => $details['cv_id']));
+      if (count($result) == 0) {
+        drupal_set_message("Cannot add property elements to the form. The CV ID, '" . $details['cv_id'] . "', does not exist", "error");
+        tripal_report_error('tcprops_form', TRIPAL_ERROR, "Cannot add property elements to the form. The CV ID, '%id',
+          cannot be found.", array('%id' => $details['cv_id']));
+        return;
       }
-    } elseif (isset($details['cv_id'])) {
+      // add the cv_name option to the details array
+      $details['cv_name'] = $result[0]->name;
+      
       $property_options = array();
       $property_options[] = 'Select a Property';
       $sql = "
@@ -168,12 +192,9 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
       $prop_types = chado_query($sql, array(':cv_id' => $details['cv_id']));
       while ($prop = $prop_types->fetchObject()) {
         $property_options[$prop->cvterm_id] = $prop->name;
-        $details['cv_name'] = $prop->cv_name;
-      }
-      if (!isset($details['cv_name'])) {
-        $result = chado_select_record('cv',array('name'),array('cv_id' => $details['cv_id']));
-        $details['cv_name'] = $result[0]->name;
       }
+      
+
     }
   }
 

+ 23 - 8
tripal_core/api/tripal_core.chado_nodes.relationships.api.inc

@@ -147,6 +147,17 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
   }
   else {
     if (isset($details['cv_name'])) {
+      // make sure the cv_name is real
+      $result = chado_select_record('cv',array('cv_id'),array('name' => $details['cv_name']));
+      if (count($result) == 0) {
+        drupal_set_message("Cannot add relationship elements to the form. The CV name, '" . $details['cv_name'] . "', does not exists", "error");
+        tripal_report_error('tcrels_form', TRIPAL_ERROR, "Cannot add relationship elements to the form. The CV named, '%name',
+          cannot be found.", array('%name' => $details['cv_name']));
+        return;
+      }
+      // add the cv_id option to the details array
+      $details['cv_id'] = $result[0]->cv_id;
+      
       $type_options = array();
       $type_options[] = 'Select a Property';
       $sql = "
@@ -163,11 +174,19 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
         $type_options[$prop->cvterm_id] = $prop->name;
         $details['cv_id'] = $prop->cv_id;
       }
-      if (!isset($details['cv_id'])) {
-        $result = chado_select_record('cv',array('cv_id'),array('name' => $details['cv_name']));
-        $details['cv_id'] = $result[0]->cv_id;
+    } 
+    elseif (isset($details['cv_id'])) {
+      // make sure the cv_id is real
+      $result = chado_select_record('cv', array('name'), array('cv_id' => $details['cv_id']));
+      if (count($result) == 0) {
+        drupal_set_message("Cannot add relationships elements to the form. The CV ID, '" . $details['cv_id'] . "', does not exist", "error");
+        tripal_report_error('tcprops_form', TRIPAL_ERROR, "Cannot add relationship elements to the form. The CV ID, '%id',
+          cannot be found.", array('%id' => $details['cv_id']));
+        return;
       }
-    } elseif (isset($details['cv_id'])) {
+      // add the cv_name option to the details array
+      $details['cv_name'] = $result[0]->name;
+      
       $type_options = array();
       $type_options[] = 'Select a Property';
       $sql = "
@@ -184,10 +203,6 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
         $type_options[$prop->cvterm_id] = $prop->name;
         $details['cv_name'] = $prop->cv_name;
       }
-      if (!isset($details['cv_name'])) {
-        $result = chado_select_record('cv',array('name'),array('cv_id' => $details['cv_id']));
-        $details['cv_name'] = $result[0]->name;
-      }
     }
   }