Forráskód Böngészése

fix bug of analysis strings are not parsed in validation

Jiu9Shen 5 éve
szülő
commit
9a2dc41c65

+ 14 - 0
tripal_jbrowse_mgmt/includes/tripal_jbrowse_mgmt.api.inc

@@ -141,6 +141,20 @@ function tripal_jbrowse_mgmt_get_instance($instance_id) {
   return reset($instance);
 }
 
+/**
+ * Get analysis_id from string(autocomplete analysis)
+ *
+ * @param $analysis_string (in format: ******** (###))
+ *
+ * @return int
+ */
+function tripal_jbrowse_mgmt_get_analysis_id_from_string($analysis_string){
+  preg_match_all('!\d+!', $analysis_string, $match_analysis);
+  $analysis_id =  array_pop($match_analysis[0]);
+  return $analysis_id;
+}
+
+
 /**
  * Update an instance.
  *

+ 6 - 2
tripal_jbrowse_mgmt/includes/tripal_jbrowse_mgmt_add.form.inc

@@ -226,10 +226,11 @@ function tripal_jbrowse_mgmt_add_form_validate($form, &$form_state) {
     }
   }
   else{
+    $values_analysis_id = tripal_jbrowse_mgmt_get_analysis_id_from_string($values['analysis']);
     foreach ($instances as $instance){
-      if ($values['analysis'] == $instance->analysis_id){
+      if ($values_analysis_id == $instance->analysis_id){
         form_set_error(
-          ['organism', 'analysis'],
+          'analysis',
           'The analysis for selected organism is taken. Please choose another analysis/organism for this instance.'
         );
       }
@@ -257,6 +258,9 @@ function tripal_jbrowse_mgmt_add_form_submit($form, &$form_state) {
   global $user;
   $values = $form_state['values'];
   $organism_id = $values['organism'];
+  if ($values['analysis']){
+    $analysis_id = tripal_jbrowse_mgmt_get_analysis_id_from_string($values['analysis']);
+  }
   preg_match_all('!\d+!', $values['analysis'], $match_analysis);
   $analysis_id = array_pop($match_analysis[0]);
   $description = isset($values['description']) ? $values['description'] : '';