Ver Fonte

Fixes to these fields: sep__protocol, schema__additional_type, local__contact.

Stephen Ficklin há 6 anos atrás
pai
commit
5d06f20ac2

+ 68 - 15
tripal/api/tripal.terms.api.inc

@@ -585,6 +585,11 @@ function tripal_get_vocabularies() {
 function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
     $title = 'Vocabulary Term', $description = '', $is_required,
     $field_name = '', $delta = 0 ) {
+  
+  $ajax_wrapper_id = 'tripal-vocab-select-form-' . $delta;
+  if ($field_name) {
+    $ajax_wrapper_id = $field_name . '-' . $delta;
+  }
 
   $term_name = $default_name;
   if (array_key_exists('values', $form_state)) {
@@ -600,15 +605,15 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
       'the controlled vocabulary should already be loaded into this site.');
   }
 
-  $form_state['storage']['term_match_field'] = $field_name;
-  $form_state['storage']['term_match_delta'] = $delta;
+  $form_state['storage'][$ajax_wrapper_id]['term_match_field'] = $field_name;
+  $form_state['storage'][$ajax_wrapper_id]['term_match_delta'] = $delta;
 
   $form['term_match'] = array(
     '#type' => 'fieldset',
     '#collapsible' => FALSE,
     '#collapsed' => FALSE,
     '#title' => t($title),
-    '#prefix' => '<div id = "tripal-vocab-select-form">',
+    '#prefix' => '<div id = "' . $ajax_wrapper_id . '">',
     '#suffix' => '</div>',
   );
   $form['term_match']['term_name'] = array(
@@ -622,12 +627,12 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
   $form['term_match']['select_button'] = array(
     '#type' => 'button',
     '#value' => t('Lookup Term'),
-    '#name' => 'select_cvterm',
+    '#name' => 'select_cvterm_' . $ajax_wrapper_id,
     '#validate' => array(),
     '#limit_validation_errors' => array(),
     '#ajax' => array(
       'callback' => "tripal_get_term_lookup_form_ajax_callback",
-      'wrapper' => "tripal-vocab-select-form",
+      'wrapper' => $ajax_wrapper_id,
       'effect' => 'fade',
       'method' => 'replace'
     ),
@@ -652,7 +657,7 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
     $terms = chado_generate_var('cvterm', $match, array('return_array' => TRUE));
     $terms = chado_expand_var($terms, 'field', 'cvterm.definition');
     $num_terms = 0;
-    $selected_term = '';
+    $selected_term = '';  
 
     // Let the user select from any matching terms. Sometimes there may be
     // more than one that match.
@@ -676,7 +681,7 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
         '<br><b>Definition:</b>  ' . $term->definition,
         '#ajax' => array(
           'callback' => "tripal_get_term_lookup_form_ajax_callback",
-          'wrapper' => "tripal-vocab-select-form",
+          'wrapper' => $ajax_wrapper_id,
           'effect' => 'fade',
           'method' => 'replace'
         ),
@@ -688,6 +693,50 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
       }
       $num_terms++;
     }
+    
+    // Next find terms that are synonyms
+    $match = array(
+      'synonym' => $term_name,
+    );
+    $termsyn = chado_generate_var('cvtermsynonym', $match, array('return_array' => TRUE));
+    // Let the user select from any matching terms. Sometimes there may be
+    // more than one that match.
+    foreach ($termsyn as $synonym) {
+      $term = $synonym->cvterm_id;
+      // Save the user a click by setting the default value as 1 if there's
+      // only one matching term.
+      $default = FALSE;
+      $attrs = array();
+      if ($num_terms == 0 and count($terms) == 1) {
+        $default = TRUE;
+        $attrs = array('checked' => 'checked');
+      }
+      $term_element_name = 'term-' . $term->cvterm_id;
+      $form['term_match']['terms_list'][$term_element_name] = array(
+        '#type' => 'checkbox',
+        '#title' =>  $term->name,
+        '#default_value' => $default,
+        '#attributes' => $attrs,
+        '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name . ' (' . $term->dbxref_id->db_id->name . ') ' . $term->cv_id->definition .
+        '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '.  ' .
+        '<br><b>Definition:</b>  ' . $term->definition . 
+        '<br><b>Synonym:</b> ' . $synonym->synonym,
+        '#ajax' => array(
+          'callback' => "tripal_get_term_lookup_form_ajax_callback",
+          'wrapper' => $ajax_wrapper_id,
+          'effect' => 'fade',
+          'method' => 'replace'
+        ),
+      );
+      
+      if (array_key_exists('values', $form_state) and array_key_exists($term_element_name, $form_state['values']) and
+        $form_state['values'][$term_element_name] == 1) {
+          $selected_term = $term;
+        }
+        $num_terms++;
+    }
+    
+    
     if ($num_terms == 0) {
       $form['term_match']['terms_list']['none'] = array(
         '#type' => 'item',
@@ -727,11 +776,13 @@ function tripal_get_term_lookup_form_result($form, $form_state, $field_name = ''
     $values = $form_state['values'];
   }
 
-  foreach ($values as $key => $value) {
-    $matches = array();
-    if (preg_match("/^term-(\d+)$/", $key, $matches) and $values['term-' . $matches[1]]) {
-      $cvterm_id = $matches[1];
-      $selected[] = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
+  if (is_array($values)) {
+    foreach ($values as $key => $value) {
+      $matches = array();
+      if (preg_match("/^term-(\d+)$/", $key, $matches) and $values['term-' . $matches[1]]) {
+        $cvterm_id = $matches[1];
+        $selected[] = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
+      }
     }
   }
   return $selected;
@@ -743,9 +794,11 @@ function tripal_get_term_lookup_form_result($form, $form_state, $field_name = ''
  * @ingroup tripal_terms_api
  */
 function tripal_get_term_lookup_form_ajax_callback($form, $form_state) {
-  $field_name = $form_state['storage']['term_match_field'];
-  $delta = $form_state['storage']['term_match_delta'];
-
+  $ajax_wrapper_id = $form_state['triggering_element']['#ajax']['wrapper'];
+  
+  $field_name = $form_state['storage'][$ajax_wrapper_id]['term_match_field'];
+  $delta = $form_state['storage'][$ajax_wrapper_id]['term_match_delta'];
+  
   // If this form is in a field then we need to dig a bit deeper to return
   // the form elements.
   if ($field_name) {

+ 44 - 1
tripal/includes/TripalBundleUIController.inc

@@ -554,7 +554,7 @@ function tripal_admin_add_type_form($form, &$form_state) {
     // more than one that match.
     foreach ($terms as $term) {
       // Save the user a click by setting the default value as 1 if there's
-      // only one matching term.
+      // only one matching term. 
       $default = FALSE;
       $attrs = array();
       if ($num_terms == 0 and count($terms) == 1) {
@@ -584,6 +584,49 @@ function tripal_admin_add_type_form($form, &$form_state) {
       }
       $num_terms++;
     }
+    
+    
+    // Next find terms that are synonyms
+    $match = array(
+      'synonym' => $term_name,
+    );
+    $termsyn = chado_generate_var('cvtermsynonym', $match, array('return_array' => TRUE));
+    // Let the user select from any matching terms. Sometimes there may be
+    // more than one that match.
+    foreach ($termsyn as $synonym) {
+      $term = $synonym->cvterm_id;
+      // Save the user a click by setting the default value as 1 if there's
+      // only one matching term.
+      $default = FALSE;
+      $attrs = array();
+      if ($num_terms == 0 and count($terms) == 1) {
+        $default = TRUE;
+        $attrs = array('checked' => 'checked');
+      }
+      $term_element_name = 'term-' . $term->cvterm_id;
+      $form['term_match']['terms_list'][$term_element_name] = array(
+        '#type' => 'checkbox',
+        '#title' =>  $term->name,
+        '#default_value' => $default,
+        '#attributes' => $attrs,
+        '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name . ' (' . $term->dbxref_id->db_id->name . ') ' . $term->cv_id->definition .
+        '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '.  ' .
+        '<br><b>Definition:</b>  ' . $term->definition .
+        '<br><b>Synonym:</b> ' . $synonym->synonym,
+        '#ajax' => array(
+          'callback' => "tripal_admin_add_type_form_ajax_callback",
+          'wrapper' => "tripal-vocab-select-form",
+          'effect' => 'fade',
+          'method' => 'replace'
+        ),
+      );
+      
+      if (array_key_exists('values', $form_state) and array_key_exists($term_element_name, $form_state['values']) and
+        $form_state['values'][$term_element_name] == 1) {
+          $selected_term = $term;
+        }
+        $num_terms++;
+    }
     if ($num_terms == 0) {
       $form['terms_list']['none'] = array(
         '#type' => 'item',

+ 26 - 17
tripal_chado/includes/TripalFields/local__contact/local__contact.inc

@@ -134,25 +134,34 @@ class local__contact extends ChadoField {
     );
 
     // Handle the biomaterial table.
+    if (!$record) {
+      return;
+    }
+      
+    $linker_field = 'chado-' . $field_table . '__' . $field_column;
     if ($field_table == 'biomaterial') {
-      if ($record) {
-        $contact = $record->biosourceprovider_id;
-        if ($contact) {
-          $entity->{$field_name}['und'][0] = array(
-            'value' => array(
-              $type_term => $contact->type_id ? $contact->type_id->name : '',
-              $name_term => $contact->name,
-              $description_term => $contact->description,
-            ),
-            $entity->{$field_name}['und'][0]['chado-biomaterial__biosourceprovider_id'] = $contact->contact_id,
-          );
-          if (property_exists($contact, 'entity_id')) {
-            $entity->{$field_name}['und'][0]['value']['entity'] = 'TripalEntity:' . $contact->entity_id;
-          }
-        }
+      $contact = $record->biosourceprovider_id;      
+    }
+    elseif ($field_table == 'arraydesign') {
+      $contact = $record->manufacturer_id;
+    }
+    else {
+      $contact = $record->contact_id;
+    }
+  
+    if ($contact) {
+      $entity->{$field_name}['und'][0] = array(
+        'value' => array(
+          $type_term => $contact->type_id ? $contact->type_id->name : '',
+          $name_term => $contact->name,
+          $description_term => $contact->description,
+        ),
+        $entity->{$field_name}['und'][0][$linker_field] = $contact->contact_id,
+        );
+      if (property_exists($contact, 'entity_id')) {
+        $entity->{$field_name}['und'][0]['value']['entity'] = 'TripalEntity:' . $contact->entity_id;
       }
-    };
-    // Here place other non-linker tables that have a FK to the contact table.
+    }
   }
 
   /**

+ 4 - 14
tripal_chado/includes/TripalFields/local__contact/local__contact_widget.inc

@@ -32,12 +32,7 @@ class local__contact_widget extends ChadoFieldWidget {
     $name_term = chado_get_semweb_term('contact', 'name');
 
     // Set the linker field appropriately.
-    if ($field_table == 'biomaterial') {
-      $linker_field = 'chado-biomaterial__biosourceprovider_id';
-    }
-    else {
-      $linker_field = 'chado-' . $field_table . '__contact_id';
-    }
+    $linker_field = 'chado-' . $field_table . '__' . $chado_column;
 
     // If the field already has a value then it will come through the $items
     // array.  This happens when editing an existing record.
@@ -70,11 +65,11 @@ class local__contact_widget extends ChadoFieldWidget {
       '#type' => 'value',
       '#default_value' => $contact_id,
     );
-
     $widget['name'] = array(
       '#type' => 'textfield',
-      '#title' => t('Contact'),
+      '#title' => $element['#title'],
       '#default_value' => $name,
+      '#required' => $element['#required'],
       '#autocomplete_path' => 'admin/tripal/storage/chado/auto_name/contact',
       '#maxlength' => 100000,
     );
@@ -102,12 +97,7 @@ class local__contact_widget extends ChadoFieldWidget {
     $name = $form_state['values'][$field_name]['und'][$delta]['name'];
 
     // Set the linker field appropriately.
-    if ($field_table == 'biomaterial') {
-      $linker_field = 'chado-biomaterial__biosourceprovider_id';
-    }
-    else {
-      $linker_field = 'chado-' . $field_table . '__contact_id';
-    }
+    $linker_field = 'chado-' . $field_table . '__' . $chado_column;
 
     // If the user provided a name then we want to set the foreign key
     // value to be the chado_record_id

+ 7 - 5
tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type.inc

@@ -94,17 +94,19 @@ class schema__additional_type extends ChadoField {
     $field_type = $this->field['type'];
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
-
+    
+    $linker_field = 'chado-' . $field_table . '__' . $field_column;
+    
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = array(
       'value' => '',
-      'chado-' . $field_table . '__type_id' => '',
+      $linker_field => '',
     );
 
-    if ($record->type_id) {
+    if ($record->{$field_column}) {
       $entity->{$field_name}['und'][0] = array(
-        'value' => $record->type_id->name,
-        'chado-' . $field_table . '__type_id' => $record->type_id->cvterm_id,
+        'value' => $record->{$field_column}->name,
+        $linker_field => $record->{$field_column}->cvterm_id,
       );
     }
   }

+ 7 - 4
tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type_widget.inc

@@ -21,12 +21,14 @@ class schema__additional_type_widget extends ChadoFieldWidget {
     $field_column = $this->instance['settings']['chado_column'];
     $vocabulary = $this->instance['settings']['vocabulary'];
     $parent_term = $this->instance['settings']['parent_term'];
+    
+    $linker_field = 'chado-' . $field_table . '__' . $field_column;
 
     $value = '';
     $type_id = '';
 
     if (count($items) > 0) {
-      $type_id = $items[0]['chado-' . $field_table . '__type_id'];
+      $type_id = $items[0][$linker_field];
       $value = $items[0]['value'];
     }
 
@@ -85,7 +87,7 @@ class schema__additional_type_widget extends ChadoFieldWidget {
           $field_name, $delta);
     }
     if ($vocabulary) {
-      $widget['chado-' . $field_table . '__type_id'] = array(
+      $widget[$linker_field] = array(
         '#type' => 'select',
         '#options' => $options,
         '#title' => $element['#title'],
@@ -111,11 +113,12 @@ class schema__additional_type_widget extends ChadoFieldWidget {
     $field_column = $this->instance['settings']['chado_column'];
     $vocabulary = $this->instance['settings']['vocabulary'];
     $parent_term = $this->instance['settings']['parent_term'];
+    $linker_field = 'chado-' . $field_table . '__' . $field_column;
 
     // Get the vocabulary term.
     $type_id = '';
     if ($vocabulary) {
-      $type_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__type_id'];
+      $type_id = $form_state['values'][$field_name]['und'][$delta][$linker_field];
     }
     else {
       $selected = tripal_get_term_lookup_form_result($form, $form_state, $field_name, $delta);
@@ -128,7 +131,7 @@ class schema__additional_type_widget extends ChadoFieldWidget {
     }
 
     if (!$type_id) {
-      $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__type_id'] = '__NULL__';
+      $form_state['values'][$field_name]['und'][$delta][$linker_field] = '__NULL__';
     }
     else {
       $form_state['values'][$field_name]['und'][$delta]['value'] = $type_id;

+ 73 - 30
tripal_chado/includes/TripalFields/schema__publication/schema__publication.inc

@@ -83,42 +83,85 @@ class schema__publication extends ChadoField {
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
     $base_table = $this->instance['settings']['base_table'];
+    
+    // These fields are used when the publications come through a linker table.
+    $pkey = '';
+    $fkey_lcolumn = '';
+    $fkey_rcolumn = '';
+    $linker_table = '';
+       
+    
+    // If the field table and the base table are not the same thing then
+    // we are going through a linker table.
+    if ($field_table != $base_table) {
+
+      // Get the FK that links to the base record.
+      $schema = chado_get_schema($field_table);
+      $pkey = $schema['primary key'][0];
+      $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
+      $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
+      $linker_table = $base_table . '_pub';
+
+      // Set some defaults for the empty record.
+      $entity->{$field_name}['und'][0] = array(
+        'value' => array(),
+        'chado-' . $field_table . '__' . $pkey => '',
+        'chado-' . $field_table . '__' . $fkey_lcolumn => '',
+        'chado-' . $field_table . '__' . 'pub_id' => '',
+      );
+    }
+    // Otherwise, the base table has a pub_id field.
+    else {
+      $entity->{$field_name}['und'][0] = array(
+        'value' => array(),
+        'chado-' . $field_table . '__' . $field_column => '',
+      );
+    }
+    
+    if (!$record) {
+      return;
+    }
 
-    // Get the FK that links to the base record.
-    $schema = chado_get_schema($field_table);
-    $pkey = $schema['primary key'][0];
-    $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
-    $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
-
-    // Set some defaults for the empty record.
-    $entity->{$field_name}['und'][0] = array(
-      'value' => array(),
-      'chado-' . $field_table . '__' . $pkey => '',
-      'chado-' . $field_table . '__' . $fkey_lcolumn => '',
-      'chado-' . $field_table . '__' . 'pub_id' => '',
-    );
+    // Get the list of publications
+    $pubs = array();
+    if ($linker_table) {
+      $options = array(
+        'return_array' => 1,
+      );
+      $record = chado_expand_var($record, 'table', $linker_table, $options);
+      if (property_exists($record, $linker_table) and is_array($record->$linker_table) and count($record->$linker_table) > 0) {
+        $i = 0;
+        foreach ($record->$linker_table as $index => $linker) {
+          $pub = $linker->pub_id;
+          $pubs[$pub->pub_id] = $pub;          
+        }
+      }
+    }
+    else {
+      $pub = $record->{$field_column};
+      if ($pub) {
+        $pubs[$pub->pub_id] = $pub;
+      }
+    }
+    
+    $i = 0;
+    foreach ($pubs as $pub_id => $pub) {
+      $pub_details = chado_get_minimal_pub_info($pub);
 
-    $linker_table = $base_table . '_pub';
-    $options = array(
-      'return_array' => 1,
-    );
-    $record = chado_expand_var($record, 'table', $linker_table, $options);
-    if (property_exists($record, $linker_table) and is_array($record->$linker_table) and count($record->$linker_table) > 0) {
-      $i = 0;
-      foreach ($record->$linker_table as $index => $linker) {
-        $pub = $linker->pub_id;
-        $pub_details = chado_get_minimal_pub_info($pub);
-
-        $entity->{$field_name}['und'][$i]['value'] = $pub_details;
+      $entity->{$field_name}['und'][$i]['value'] = $pub_details;
+      if ($linker_table) {
         $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $pkey] = $linker->$pkey;
         $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $fkey_lcolumn] = $linker->$fkey_lcolumn->$fkey_lcolumn;
-        $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . 'pub_id'] = $pub->pub_id;
+        $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . 'pub_id'] = $pub_id;
+      }
+      else {
+        $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $field_column] = $pub_id;
+      }
 
-        if (property_exists($pub, 'entity_id')) {
-          $entity->{$field_name}['und'][$i]['value']['entity'] = 'TripalEntity:' . $pub->entity_id;
-        }
-        $i++;
+      if (property_exists($pub, 'entity_id')) {
+        $entity->{$field_name}['und'][$i]['value']['entity'] = 'TripalEntity:' . $pub->entity_id;
       }
+      $i++;
     }
   }
 }

+ 68 - 39
tripal_chado/includes/TripalFields/schema__publication/schema__publication_widget.inc

@@ -15,27 +15,46 @@ class schema__publication_widget extends ChadoFieldWidget {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
     $field_name = $this->field['field_name'];
-
-    // Get the FK column that links to the base table.
-    $table_name = $this->instance['settings']['chado_table'];
+    $field_type = $this->field['type'];
+    $field_table = $this->instance['settings']['chado_table'];
+    $field_column = $this->instance['settings']['chado_column'];
     $base_table = $this->instance['settings']['base_table'];
-    $schema = chado_get_schema($table_name);
-    $pkey = $schema['primary key'][0];
-    $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
-    $fkey = $fkeys[0];
-
-    // Get the field defaults.
+    
+    // These fields are used when the publications come through a linker table.
+    $pkey = '';
+    $fkeys = '';
+    $fkey = '';
     $pkey_val = '';
     $fkey_value = '';
+    $linker_table = '';
+    
+    // If the field table and the base table are not the same thing then
+    // we are going through a linker table.
+    $pub_item_id = '';
+    if ($field_table != $base_table) {
+      $schema = chado_get_schema($field_table);
+      $pkey = $schema['primary key'][0];
+      $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
+      $fkey = $fkeys[0];
+      $linker_table = $base_table . '_pub';
+      $pub_item_id = 'chado-' . $field_table . '__pub_id';
+    }
+    else {
+      $pub_item_id = 'chado-' . $field_table . '__' . $field_column;
+    }
+
+    // Get the field defaults.
     $pub_id = '';
     $title = '';
 
     // If the field already has a value then it will come through the $items
     // array.  This happens when editing an existing record.
     if (count($items) > 0 and array_key_exists($delta, $items)) {
-      $pkey_val =  tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__' . $pkey, $pkey_val);
-      $fkey_value = tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__' . $fkey, $fkey_value);
-      $pub_id = tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__pub_id', $pub_id);
+      if ($linker_table) {
+        $pkey_val =  tripal_get_field_item_keyval($items, $delta, 'chado-' . $field_table . '__' . $pkey, $pkey_val);
+        $fkey_value = tripal_get_field_item_keyval($items, $delta, 'chado-' . $field_table . '__' . $fkey, $fkey_value);
+      }
+      $pub_id = tripal_get_field_item_keyval($items, $delta, $pub_item_id, $pub_id);
       if ($pub_id) {
         $pub = chado_get_publication(array('pub_id' => $pub_id));
         $title =  $pub->title . ' [id:' . $pub->pub_id . ']';
@@ -49,11 +68,9 @@ class schema__publication_widget extends ChadoFieldWidget {
       $pub_id = $form_state['values'][$field_name]['und'][$delta]['accession'];
     }
 
-    $schema = chado_get_schema('pub');
-
-    $widget['#table_name'] = $table_name;
+    $widget['#table_name'] = $field_table;
     $widget['#fkey_field'] = $fkey;
-    $widget['#prefix'] =  "<span id='$table_name-$delta'>";
+    $widget['#prefix'] =  "<span id='" . $field_table . "-" . $delta . "'>";
     $widget['#suffix'] =  "</span>";
 
     $widget['value'] = array(
@@ -61,15 +78,17 @@ class schema__publication_widget extends ChadoFieldWidget {
       '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
     );
 
-    $widget['chado-' . $table_name . '__' . $pkey] = array(
-      '#type' => 'value',
-      '#default_value' => $pkey_val,
-    );
-    $widget['chado-' . $table_name . '__' . $fkey] = array(
-      '#type' => 'value',
-      '#default_value' => $fkey_value,
-    );
-    $widget['chado-' . $table_name . '__pub_id'] = array(
+    if ($linker_table) {
+      $widget['chado-' . $field_table . '__' . $pkey] = array(
+        '#type' => 'value',
+        '#default_value' => $pkey_val,
+      );
+      $widget['chado-' . $field_table . '__' . $fkey] = array(
+        '#type' => 'value',
+        '#default_value' => $fkey_value,
+      );
+    }
+    $widget[$pub_item_id] = array(
       '#type' => 'value',
       '#default_value' => $pub_id,
     );
@@ -91,17 +110,27 @@ class schema__publication_widget extends ChadoFieldWidget {
   public function validate($element, $form, &$form_state, $langcode, $delta) {
 
     // Get the FK column that links to the base table.
-    $table_name = $this->instance['settings']['chado_table'];
-    $base_table = $this->instance['settings']['base_table'];
-    $schema = chado_get_schema($table_name);
-    $pkey = $schema['primary key'][0];
-    $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
-    $fkey = $fkeys[0];
     $field_name = $this->field['field_name'];
-
-    // Get the field values.
-    $fkey_value = $form_state['values'][$field_name]['und'][$delta]['value'];
-    $pub_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'];
+    $field_type = $this->field['type'];
+    $field_table = $this->instance['settings']['chado_table'];
+    $field_column = $this->instance['settings']['chado_column'];
+    $base_table = $this->instance['settings']['base_table'];
+    
+    if ($field_table != $base_table) {
+      $schema = chado_get_schema($field_table);
+      $pkey = $schema['primary key'][0];
+      $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
+      $fkey = $fkeys[0];
+      $pub_item_id = 'chado-' . $field_table . '__pub_id';
+
+      // Get the field values.
+      $fkey_value = $form_state['values'][$field_name]['und'][$delta]['value'];
+    }
+    else {
+      $pub_item_id = 'chado-' . $field_table . '__' . $field_column;
+    }
+    
+    $pub_id = $form_state['values'][$field_name]['und'][$delta][$pub_item_id];
     $title = $form_state['values'][$field_name]['und'][$delta]['pub_title'];
 
     // If the user provided a pub_title then we want to set the foreign key
@@ -111,7 +140,7 @@ class schema__publication_widget extends ChadoFieldWidget {
       if (preg_match('/^.*\[id:(\d+)]$/', $title, $matches)) {
         $pub_id = $matches[1];
         $pub = chado_generate_var('pub', array('pub_id' => $pub_id));
-        $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'] = $pub->pub_id;
+        $form_state['values'][$field_name]['und'][$delta][$pub_item_id] = $pub->pub_id;
         $form_state['values'][$field_name]['und'][$delta]['value'] = $pub->pub_id;
       }
     }
@@ -121,9 +150,9 @@ class schema__publication_widget extends ChadoFieldWidget {
     // it out so that the Chado field_storage infrastructure won't try to
     // write a record.
     if (!$title) {
-      $form_state['values'][$field_name]['und'][$delta]['value'] = 'delete_me';
-      $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__' . $fkey] = '';
-      $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'] = '';
+      $form_state['values'][$field_name]['und'][$delta]['value'] = '';
+      $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $fkey] = '';
+      $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__pub_id'] = '';
     }
   }
 

+ 16 - 11
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol.inc

@@ -114,29 +114,31 @@ class sep__protocol extends ChadoField {
     $field_type = $this->field['type'];
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
-    $linker_field = 'chado-' . $field_table . '__protocol_id';
+    $base_table = $this->instance['settings']['base_table'];
+    $linker_field = 'chado-' . $field_table . '__' . $field_column;
 
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = [
       'value' => [],
     ];
 
-    if (!$record->protocol_id->protocol_id) {
+    if (!$record) {
       return;
     }
-
-    $protocol_id = $record->protocol_id->protocol_id;
-    $protocol_name = $record->protocol_id->name;
-    $protocol_type_id = $record->protocol_id->type_id;
-
+    
+    $protocol = $record->{$field_column};
     $entity_id = $record->entity_id;
 
+    // Get the Protocol controlled vocabulary terms.
+    $protocol_name_term = chado_get_semweb_term('protocol', 'name');
+    $protocol_type_term = chado_get_semweb_term('protocol', 'type_id');       
+    
     $entity->{$field_name}['und'][0]['value'] = [
-      "protocol_name" => $protocol_name,
-      'type_id' => $protocol_type_id
+      $protocol_name_term => $protocol->name,
+      $protocol_type_term => $protocol->type_id->name,
     ];
-    $entity->{$field_name}['und'][0]['protocol_chado_id'] =  $protocol_id;
-//    $entity->{$field_name}['und'][0]['protocol_entity_id'] =  $entity_id;
+    
+    $entity->{$field_name}['und'][0][$linker_field] =  $protocol->protocol_id;
 
     // Is there a published entity for this protocol?
     if (property_exists($record->{$field_column}, 'entity_id')) {
@@ -144,6 +146,9 @@ class sep__protocol extends ChadoField {
     }
   }
 
+  /**
+   * @see TripalField::elementInfo()
+   */
   function elementInfo() {
     $field_term = $this->getFieldTermID();
     $type_id_term = tripal_get_chado_semweb_term('protocol', 'type_id');

+ 9 - 81
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol_formatter.inc

@@ -21,73 +21,25 @@ class sep__protocol_formatter extends ChadoFieldFormatter {
   ];
 
   /**
-   * Provides the field's setting form.
-   *
-   * This function corresponds to the hook_field_formatter_settings_form()
-   * function of the Drupal Field API.
-   *
-   * The settings form appears on the 'Manage Display' page of the content
-   * type administration page. This function provides the form that will
-   * appear on that page.
-   *
-   * To add a validate function, please create a static function in the
-   * implementing class, and indicate that this function should be used
-   * in the form array that is returned by this function.
-   *
-   * This form will not be displayed if the formatter_settings_summary()
-   * function does not return anything.
-   *
-   * param $field
-   *   The field structure being configured.
-   * param $instance
-   *   The instance structure being configured.
-   * param $view_mode
-   *   The view mode being configured.
-   * param $form
-   *   The (entire) configuration form array, which will usually have no use
-   *   here.  Typically for reference only.
-   * param $form_state
-   *   The form state of the (entire) configuration form.
-   *
-   * @return
-   *   A Drupal Form array containing the settings form for this field.
+   * @see TripalFieldFormatter::settingsForm()
    */
   public function settingsForm($view_mode, $form, &$form_state) {
 
   }
 
   /**
-   *  Provides the display for a field
-   *
-   * This function corresponds to the hook_field_formatter_view()
-   * function of the Drupal Field API.
-   *
-   *  This function provides the display for a field when it is viewed on
-   *  the web page.  The content returned by the formatter should only include
-   *  what is present in the $items[$delta]['values] array. This way, the
-   *  contents that are displayed on the page, via webservices and downloaded
-   *  into a CSV file will always be identical.  The view need not show all
-   *  of the data in the 'values' array.
-   *
-   * @param $element
-   * @param $entity_type
-   * @param $entity
-   * @param $langcode
-   * @param $items
-   * @param $display
-   *
-   * @return
-   *    An element array compatible with that returned by the
-   *    hook_field_formatter_view() function.
+   * @see TripalFieldFormatter::view()
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
+
     if (count($items) > 0) {
-      $protocol_id = $items[0]["protocol_chado_id"];
-      $protocol_name = $items[0]['value']["protocol_name"];
-      $entity_id =  $items[0]['value']['entity_id'];
+      
+      $protocol_name_term = chado_get_semweb_term('protocol', 'name');
+      $protocol_type_term = chado_get_semweb_term('protocol', 'type_id');    
 
+      $protocol_name =  $items[0]['value'][$protocol_name_term];
       $content = $protocol_name;
-       list($entity_type, $entity_id) = explode(':', $items[0]['value']['entity_id']);
+      list($entity_type, $entity_id) = explode(':', $items[0]['value']['entity_id']);
       if ($entity_id) {
         $content = l($protocol_name, 'bio_data/' . $entity_id);
       }
@@ -102,31 +54,7 @@ class sep__protocol_formatter extends ChadoFieldFormatter {
 
 
   /**
-   * Provides a summary of the formatter settings.
-   *
-   * This function corresponds to the hook_field_formatter_settings_summary()
-   * function of the Drupal Field API.
-   *
-   * On the 'Manage Display' page of the content type administration page,
-   * fields are allowed to provide a settings form.  This settings form can
-   * be used to allow the site admin to define how the field should be
-   * formatted.  The settings are then available for the formatter()
-   * function of this class.  This function provides a text-based description
-   * of the settings for the site developer to see.  It appears on the manage
-   * display page inline with the field.  A field must always return a
-   * value in this function if the settings form gear button is to appear.
-   *
-   * See the hook_field_formatter_settings_summary() function for more
-   * information.
-   *
-   * @param $field
-   * @param $instance
-   * @param $view_mode
-   *
-   * @return string
-   *   A string that provides a very brief summary of the field settings
-   *   to the user.
-   *
+   * @see TripalFieldFormatter::settingsSummary()
    */
   public function settingsSummary($view_mode) {
     return '';

+ 38 - 42
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol_widget.inc

@@ -79,19 +79,40 @@ class sep__protocol_widget extends ChadoFieldWidget {
     $field_type = $this->field['type'];
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
-    $linker_field = 'chado-' . $field_table . '__protocol_id';
+    $base_table = $this->instance['settings']['base_table'];
+    $linker_field = 'chado-' . $field_table . '__' . $field_column;
 
-    $protocols = [];
-    //options are all protocols
-    //It could be argued that options should only be protocols where protocol_type matches the bundle base table.
+    $protocol_term = chado_get_semweb_term($field_column, $field_table);
+    $protocol_name_term = chado_get_semweb_term('protocol', 'name');
+    $protocol_type_term = chado_get_semweb_term('protocol', 'type_id');    
 
+    // Set defaults for the form elements.
+    $protocol_name = '';
+    $protocol_id = '';
+    
+    // If the field already has a value then it will come through the $items
+    // array.  This happens when editing an existing record.
+    if (count($items) > 0 and array_key_exists($delta, $items)) {
+      $protocol_name = array_key_exists($protocol_name_term, $items[$delta]['value']) ? $items[$delta]['value'][$protocol_name_term] : $protocol_name;
+    }
+    
+    // Get the list of protocols
+    $protocols = [];
     $sql = "SELECT * FROM {protocol}";
     $results = chado_query($sql);
     foreach ($results as $protocol) {
       $protocols[$protocol->protocol_id] = $protocol->name;
+      if ($protocol->name == $protocol_name) {
+        $protocol_id = $protocol->protocol_id;
+      }
     }
+    
+    $widget['value'] = array(
+      '#type' => 'value',
+      '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
+    );
 
-    $widget['value'] = [
+    $widget[$linker_field] = [
       '#type' => 'select',
       '#title' => $element['#title'],
       '#description' => $element['#description'],
@@ -100,52 +121,27 @@ class sep__protocol_widget extends ChadoFieldWidget {
       '#required' => $element['#required'],
       '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
       '#delta' => $delta,
+      '#default_value' => $protocol_id,
     ];
-
   }
 
   /**
-   * Performs validation of the widgetForm.
-   *
-   * Use this validate to ensure that form values are entered correctly.
-   * The 'value' key of this field must be set in the $form_state['values']
-   * array anytime data is entered by the user.  It may be the case that there
-   * are other fields for helping select a value. In the end those helper
-   * fields must be used to set the 'value' field.
+   * @see TripalFieldWidget::validate()
    */
   public function validate($element, $form, &$form_state, $langcode, $delta) {
-
+    $field_name = $this->field['field_name'];
+    $field_table = $this->instance['settings']['chado_table'];
+    $field_column = $this->instance['settings']['chado_column'];
+    
+    $linker_field = 'chado-' . $field_table . '__' . $field_column;    
+    
+    // Make sure the value is set to the organism_id
+    $protocol_id = $form_state['values'][$field_name]['und'][0][$linker_field];
+    $form_state['values'][$field_name]['und'][0]['value'] = $protocol_id;
   }
 
   /**
-   * Performs extra commands when the entity form is submitted.
-   *
-   * Drupal typically does not provide a submit hook for fields.  The
-   * TripalField provides one to allow for behind-the-scenes actions to
-   * occur.   This function should never be used for updates, deletes or
-   * inserts for the Chado table associated with the field.  Rather, the
-   * storage backend should be allowed to handle inserts, updates deletes.
-   * However, it is permissible to perform inserts, updates or deletions within
-   * Chado using this function.  Those operations can be performed if needed but
-   * on other tables not directly associated with the field.
-   *
-   * An example is the chado.feature_synonym table.  The chado_linker__synonym
-   * field allows the user to provide a brand new synonynm and it must add it
-   * to the chado.synonym table prior to the record in the
-   * chado.feature_synonym table.  This insert occurs in the widgetFormSubmit
-   * function.
-   *
-   * @param $form
-   *    The submitted form array.
-   * @param $form_state .
-   *    The form state array.
-   * @param $entity_type
-   *    The type of $entity.
-   * @param $entity
-   *    The entity for the operation.
-   * @param $langcode
-   *    The language associated with $items.
-   * @param $delta
+   * @see TripalFieldWidget::submit()
    */
   public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
   }

+ 6 - 0
tripal_chado/includes/tripal_chado.entity.inc

@@ -157,6 +157,12 @@ function tripal_chado_tripal_default_title_format($bundle, $available_tokens) {
       );
     }
   }
+  if ($table == 'arraydesign') {
+    $format[] = array(
+      'format' => '[schema__name]',
+      'weight' => -5
+    );
+  }
   if ($table == 'biomaterial') {
     $format[] = array(
       'format' => '[schema__name]',

+ 220 - 3
tripal_chado/includes/tripal_chado.fields.inc

@@ -237,6 +237,33 @@ function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type,
       ),
     );
   }
+  
+  // BASE ARRAYDESIGN TABLE
+  if ($table_name == 'arraydesign') {
+    $field_name = 'ncit__technology_platform';
+    $field_type = 'schema__additional_type';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'type' => $field_type,
+      'cardinality' => 1,
+      'locked' => FALSE,
+      'storage' => array(
+        'type' => 'field_chado_storage',
+      ),
+    );
+    
+    $field_name = 'efo__substrate_type';
+    $field_type = 'schema__additional_type';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'type' => $field_type,
+      'cardinality' => 1,
+      'locked' => FALSE,
+      'storage' => array(
+        'type' => 'field_chado_storage',
+      ),
+    );
+  }
 
   // BASE ORGANISM_ID
   if ($table_name != 'organism' and
@@ -268,6 +295,19 @@ function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type,
       ),
     );
   }
+  if ($table_name == 'arraydesign') {
+    $field_name = 'efo__array_manufacturer';
+    $field_type = 'local__contact';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'type' => $field_type,
+      'cardinality' => 1,
+      'locked' => FALSE,
+      'storage' => array(
+        'type' => 'field_chado_storage',
+      ),
+    );
+  }
 
   // BASE ORGANISM_ID
   if ($table_name == 'cvterm') {
@@ -477,6 +517,27 @@ function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type,
         'type' => 'field_chado_storage',
       ),
     );
+  }
+  
+  // For the pub_id field in the base table.
+  $schema = chado_get_schema($table_name);
+  if (array_key_exists('pub_id', $schema['fields'])) {
+    
+    // Remove the schema__publication added by the
+    // tripal_chado_bunde_instnaces_info_base function.
+    unset($info['schema__publication']);
+    
+    $field_name = 'schema__publication_single';
+    $field_type = 'schema__publication';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'type' => $field_type,
+      'cardinality' => 1,
+      'locked' => FALSE,
+      'storage' => array(
+        'type' => 'field_chado_storage',
+      ),
+    );
   } 
 
 }
@@ -1135,6 +1196,16 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
         $base_info['widget']['type'] = 'text_textfield';
         $base_info['settings']['text_processing'] = '0';
       }
+      if ($column_name == 'platformtype_id') {
+        $base_info['label'] = 'Platform type';
+      }
+      if ($column_name == 'substratetype_id') {
+        $base_info['label'] = 'Substrate Type';
+      }
+      if ($column_name == 'manufacturer_id') {
+        $base_info['label'] = 'Manufacturer';
+      }
+      
     }
 
     $info[$field_name] = $base_info;
@@ -1217,6 +1288,82 @@ function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle
       ),
     );
   }
+  
+  if ($table_name == 'arraydesign') {
+    $field_name = 'ncit__technology_platform';
+    $default_vocab = '';
+    $parent_term = '';
+    $description = 'Select the platform type.';
+    $info[$field_name] =  array(
+      'field_name' => $field_name,
+      'entity_type' => $entity_type,
+      'bundle' => $bundle->name,
+      'label' => 'Platform Type',
+      'description' => $description,
+      'required' => TRUE,
+      'settings' => array(
+        'auto_attach' => TRUE,
+        'chado_table' => $table_name,
+        'chado_column' => 'platformtype_id',
+        'base_table' => $table_name,
+        'vocabulary' => $default_vocab,
+        'parent_term' => $parent_term,
+        'term_vocabulary' => 'NCIT',
+        'term_name' => 'Technology Platform',
+        'term_accession' => 'C45378',
+      ),
+      'widget' => array(
+        'type' => 'schema__additional_type_widget',
+        'settings' => array(
+          'display_label' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'inline',
+          'type' => 'schema__additional_type_formatter',
+          'settings' => array(),
+        ),
+      ),
+    );
+    
+    $field_name = 'efo__substrate_type';
+    $default_vocab = '';
+    $parent_term = '';
+    $description = 'Select the substrate type.';
+    $info[$field_name] =  array(
+      'field_name' => $field_name,
+      'entity_type' => $entity_type,
+      'bundle' => $bundle->name,
+      'label' => 'Substrate Type',
+      'description' => $description,
+      'required' => FALSE,
+      'settings' => array(
+        'auto_attach' => TRUE,
+        'chado_table' => $table_name,
+        'chado_column' => 'substratetype_id',
+        'base_table' => $table_name,
+        'vocabulary' => $default_vocab,
+        'parent_term' => $parent_term,
+        'term_vocabulary' => 'EFO',
+        'term_name' => 'substrate type',
+        'term_accession' => '0005522',
+      ),
+      'widget' => array(
+        'type' => 'schema__additional_type_widget',
+        'settings' => array(
+          'display_label' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'inline',
+          'type' => 'schema__additional_type_formatter',
+          'settings' => array(),
+        ),
+      ),
+    );
+  }
 
   // BASE ORGANISM_ID
     if ($table_name != 'organism' and
@@ -1271,7 +1418,7 @@ function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle
       'entity_type' => $entity_type,
       'bundle' => $bundle->name,
       'label' => 'Contact',
-      'description' => 'An indviddual or organization that serves as a contact for this record.',
+      'description' => 'An indvidual or organization that serves as a contact for this record.',
       'required' => FALSE,
       'settings' => array(
         'auto_attach' => FALSE,
@@ -1294,6 +1441,40 @@ function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle
       ),
     );
   }
+  if ($table_name == 'arraydesign') {
+    $field_name = 'efo__array_manufacturer';
+    $field_type = 'local__contact';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'entity_type' => $entity_type,
+      'bundle' => $bundle->name,
+      'label' => 'Manufacturer',
+      'description' => 'A manufacturer\'s contact details',
+      'required' => TRUE,
+      'settings' => array(
+        'auto_attach' => FALSE,
+        'chado_table' => 'arraydesign',
+        'chado_column' => 'manufacturer_id',
+        'base_table' => 'arraydesign',
+        'term_vocabulary' => 'EFO',
+        'term_name' => 'aarray manufacturer',
+        'term_accession' => '0001728',
+      ),
+      'widget' => array(
+        'type' => 'local__contact_widget',
+        'settings' => array(
+          'display_label' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'inline',
+          'type' => 'local__contact_formatter',
+          'settings' => array(),
+        ),
+      ),
+    );
+  }
 
   // BASE CVTERM
   if ($table_name == 'cvterm') {
@@ -1718,7 +1899,7 @@ function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle
 
 
   // PROTOCOL FIELD
-   if ($table_name != 'protocol' and
+  if ($table_name != 'protocol' and
     (array_key_exists('protocol_id', $schema['fields']))) {
 
     $field_name = 'sep__protocol';
@@ -1756,6 +1937,43 @@ function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle
       ),
     );
   } 
+  // pub_id field in table.
+  $schema = chado_get_schema($table_name);
+  if (array_key_exists('pub_id', $schema['fields'])) {
+    
+    // Remove the schema__publication added by the 
+    // tripal_chado_bunde_instnaces_info_base function.
+    unset($info['schema__publication']);
+      
+    $field_name = 'schema__publication_single';
+    $info[$field_name] =  array(
+      'field_name' => $field_name,
+      'entity_type' => $entity_type,
+      'bundle' => $bundle->name,
+      'label' => 'Publication',
+      'description' => 'This record has been referenced or is sourced from these publications.',
+      'required' => FALSE,
+      'settings' => array(
+        'auto_attach' => TRUE,
+        'chado_table' => $table_name,
+        'chado_column' => 'pub_id',
+        'base_table' => $table_name,
+      ),
+      'widget' => array(
+        'type' => 'schema__publication_widget',
+        'settings' => array(
+          'display_label' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'hidden',
+          'type' => 'schema__publication_formatter',
+          'settings' => array(),
+        ),
+      ),
+    );
+  } 
 
 }
 
@@ -2194,7 +2412,6 @@ function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle
     );
   }
 
-
   // PUBLICATIONS
   $pub_table = $table_name . '_pub';
   if (chado_table_exists($pub_table)) {

+ 11 - 0
tripal_chado/includes/tripal_chado.semweb.inc

@@ -1978,6 +1978,17 @@ function tripal_chado_populate_vocab_NCIT() {
     'definition' => 'A plan detailing how a study will be performed in order to represent the phenomenon under examination, to answer the research questions that have been asked, and defining the methods of data analysis. Study design is driven by research hypothesis being posed, study subject/population/sample available, logistics/resources: technology, support, networking, collaborative support, etc. [ NCI ]',
   ));
   chado_associate_semweb_term(NULL, 'studydesign_id', $term);
+  
+  // The Company term is missing for the Tripal Contact ontology, but is
+  // useful for the arraydesign.manufacturer which is an FK to Contact.
+  // It seems better to use a term from a curated ontology than to add to 
+  // Tripal Contact.
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C54131',
+    'name' => 'Company',
+    'cv_name' => 'ncit',
+    'definition' => 'Any formal business entity for profit, which may be a corporation, a partnership, association or individual proprietorship. [ NCI http://dictionary.law.com ]',
+  ));
 }
 
 /**