Procházet zdrojové kódy

when a new tripal content type is created. it'll insert, or update if not exsit, a new tripal_cvterm_mapping record. Added local:biomaterial and initial population of tripal_cvterm_mapping to the prepare chado function.

Chun-Huai Cheng před 8 roky
rodič
revize
bbdd00ebbc

+ 13 - 3
tripal_chado/includes/tripal_chado.mapping.inc

@@ -58,11 +58,8 @@ function tripal_chado_add_cvterm_mapping($cvterm_id, $tablename, $chado_field) {
   $record = db_select('tripal_cvterm_mapping', 'tcm')
   ->fields('tcm', array('mapping_id'))
   ->condition('cvterm_id', $cvterm_id)
-  ->condition('chado_table', $tablename)
-  ->condition('chado_field', $chado_field)
   ->execute()
   ->fetchField();
-
   // insert records into the tripal_cvterm_mapping table.
   if (!$record) {
     db_insert('tripal_cvterm_mapping')
@@ -75,4 +72,17 @@ function tripal_chado_add_cvterm_mapping($cvterm_id, $tablename, $chado_field) {
         )
         ->execute();
   }
+  // if the record exists, update the term mapping
+  else {
+    db_update('tripal_cvterm_mapping')
+    ->fields(
+        array(
+          'chado_table' => $tablename,
+          'chado_field' => $chado_field
+        )
+      )
+    ->condition('cvterm_id', $cvterm_id)
+    ->execute()
+    ;
+  }
 }

+ 13 - 0
tripal_chado/includes/tripal_chado.setup.inc

@@ -366,6 +366,16 @@ function tripal_chado_prepare_chado() {
       'definition' => 'The way in which two things are connected.',
       'cv_name' => 'local',
     ));
+    
+    tripal_insert_cvterm(array(
+      'id' => 'local:biomaterial',
+      'name' => 'biomaterial',
+      'definition' => 'A biomaterial represents the MAGE concept of BioSource, BioSample, ' . 
+        'and LabeledExtract. It is essentially some biological material (tissue, cells, serum) that ' .
+        'may have been processed. Processed biomaterials should be traceable back to raw ' .
+        'biomaterials via the biomaterialrelationship table.',
+      'cv_name' => 'local',
+    ));
 
     // For the TripalBundle entities we will want to associate the cvterm_id,
     // and the chado table and field that it maps to.  We will use a few
@@ -414,6 +424,9 @@ function tripal_chado_prepare_chado() {
     if (!tripal_create_bundle('local', 'project', 'project', $error)) {
       throw new Exception($error);
     }
+    
+    // Initialize the population of the tripal_cvterm_mapping table.
+    tripal_chado_map_cvterms();
 
     // Set a variable to indicate the site is prepared.
     variable_set('tripal_chado_is_prepared', TRUE);

+ 2 - 1
tripal_chado/includes/tripal_chado.vocab_storage.inc

@@ -229,12 +229,13 @@ function tripal_chado_vocab_select_term_form_validate($form, &$form_state) {
         form_set_error('default_table-' . $cvterm_id, 'Please select a default table.');
       }
       else {
+        $chado_field = NULL;
         $schema = chado_get_schema($default_table);
         if (isset($schema['foreign keys']['cvterm']['columns'])) {
           $fkey = array_keys($schema['foreign keys']['cvterm']['columns']);
           $chado_field = $fkey[0];
-          tripal_chado_add_cvterm_mapping($cvterm_id, $default_table, $chado_field);
         }
+        tripal_chado_add_cvterm_mapping($cvterm_id, $default_table, $chado_field);
       }
     }
   }