Bladeren bron

Merge branch '7.x-3.x' into 423-tv3-remote_data_field

Stephen Ficklin 6 jaren geleden
bovenliggende
commit
9347583b92

+ 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',

+ 198 - 9
tripal/views_handlers/tripal_views_handler_area_collections.inc

@@ -11,24 +11,39 @@ class tripal_views_handler_area_collections extends views_handler_area_result {
    */
   function render($empty = FALSE) {
 
-    // If collections are dispabled then don't show anything.
+    // If collections are disabled then don't show anything.
     $collections_enabled = variable_get('tripal_data_collections_enabled', 1);
     if (!$collections_enabled) {
       return '';
     }
 
-    // This will only work with Tripal content types and the tripal_views_query
-    // plugin. So don't show anything for others.
-    if ($this->query->plugin_name != 'tripal_views_query') {
-      return '';
+    // We need a specific form to work with Tripal content types and the tripal_views_query plugin.
+    if ($this->query->plugin_name == 'tripal_views_query') {
+      $form = drupal_get_form('tripal_views_handler_area_collections_form', $this->view, $this->query);
+      return drupal_render($form);
+    }
+    // We also want to support views created via the Drupal Search API.
+    elseif ($this->query->plugin_name == 'search_api_views_query') {
+      $form = drupal_get_form('tripal_views_handler_area_collections_search_api_form', $this->view, $this->query);
+      return drupal_render($form);
+    }
+    // If we don't support this type of view, then we should tell the admin
+    // so they're not left scratching their head like I was ;-).
+    else {
+      tripal_set_message('Unfortunatly Tripal Collections are not supported for your current view type.');
     }
-    $form = drupal_get_form('tripal_views_handler_area_collections_form', $this->view, $this->query);
-    return drupal_render($form);
   }
 }
 
 /**
+ * Views Area Handler Form: Tripal Collections on Tripal Entity-based Views
  *
+ * @param $form
+ * @param $form_state
+ * @param $view
+ *   The views object that this form will be rendered on.
+ * @param $query
+ *   The views query object generating the views results.
  */
 function tripal_views_handler_area_collections_form($form, $form_state, $view, $query) {
 
@@ -186,6 +201,7 @@ function tripal_views_handler_area_collections_form($form, $form_state, $view, $
   $form['#suffix'] = '</div>';
   return $form;
 }
+
 /**
  * Theme the fields section of the tripal_views_handler_area_collections form.
  *
@@ -230,13 +246,14 @@ function theme_tripal_views_handler_area_collections_fields_fset($variables) {
 }
 
 /**
- *
+ * AJAX: Tripal Collections on Tripal Entity-based Views
  */
 function tripal_views_handler_area_collections_form_ajax($form, $form_state) {
   return $form;
 }
+
 /**
- *
+ * Views Area Handler Form SUBMIT: Tripal Collections on Tripal Entity-based Views
  */
 function tripal_views_handler_area_collections_form_submit($form, $form_state) {
   global $user;
@@ -268,6 +285,7 @@ function tripal_views_handler_area_collections_form_submit($form, $form_state) {
   foreach ($results['TripalEntity'] as $entity) {
     $entities[] = $entity->id;
   }
+
   $collection = tripal_create_collection(array(
     'uid'  => $uid,
     'collection_name' => $collection_name,
@@ -277,3 +295,174 @@ function tripal_views_handler_area_collections_form_submit($form, $form_state) {
     'fields' => $selected_fids,
   ));
 }
+
+/**
+ * Views Area Handler Form: Tripal Collections on Drupal Search API-based
+ *
+ * @param $form
+ * @param $form_state
+ * @param $view
+ *   The views object that this form will be rendered on.
+ * @param $query
+ *   The views query object generating the views results.
+ */
+function tripal_views_handler_area_collections_search_api_form($form, $form_state, $view, $query) {
+
+  // Set form defaults.
+  $collection_name = '';
+  $collection_desc = '';
+
+  $form['save_collection'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Save Results'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#description' => t('A data collection is a virtual container into which you can
+      save data.  You can place your search results into a data collection for
+      download or use with other tools on this site that support data collections.'),
+  );
+
+  // Save the results of the full query for further processing.
+  // We use clones to ensure we don't inadvertently change the current view.
+  $cloned_view = clone $view;
+  $cloned_query = clone $query;
+  $cloned_query->set_limit(0);
+  $cloned_query->execute($cloned_view);
+  $form['save_collection']['results'] = array(
+    '#type' => 'hidden',
+    '#value' => serialize($cloned_view->result),
+  );
+  unset($cloned_view, $cloned_query);
+
+  $form['save_collection']['summary'] = array(
+    '#type' => 'item',
+    '#title' => 'Results Summary',
+    '#markup' => t('There are @total_rows record(s) that can be added to a data collection.', array('@total_rows' => $view->total_rows)),
+  );
+
+  $form['save_collection']['collection_name'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Collection Name'),
+    '#description' => t('Please name this collection for future reference.'),
+    '#default_value' => $collection_name,
+    '#required' => TRUE,
+  );
+
+  $form['save_collection']['description_fset'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Add a Description'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+
+  $form['save_collection']['description_fset']['collection_desc'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Description'),
+    '#description' => t('Please provide a description about this data collection. This is meant to help you remember what is in the collection.'),
+    '#default_value' => $collection_name,
+  );
+
+  // @todo add ability to choose fields for the collection.
+
+  $form['save_collection']['button'] = array(
+    '#type' => 'submit',
+    '#value' => 'Save Data Collection',
+    '#name' => 'save_collection',
+    '#ajax' => array(
+      'callback' => "tripal_views_handler_area_collections_form_ajax",
+      'wrapper' => 'tripal-views-handler-area-collections',
+      'effect'   => 'fade',
+      'method'   => 'replace',
+      'prevent'  => 'click'
+    ),
+  );
+
+  $form['#prefix'] = '<div id="tripal-views-handler-area-collections">';
+  $form['#suffix'] = '</div>';
+
+  return $form;
+}
+
+/**
+ * Views Area Handler Form SUBMIT: Tripal Collections on Drupal Search API-based Views
+ */
+function tripal_views_handler_area_collections_search_api_form_validate($form, $form_state) {
+
+  // CHECK: Collection with the given name doesn't already exist.
+
+}
+
+/**
+ * Views Area Handler Form SUBMIT: Tripal Collections on Drupal Search API-based Views
+ */
+function tripal_views_handler_area_collections_search_api_form_submit($form, $form_state) {
+  global $user;
+
+  // Create the collection.
+  $collection_details = array(
+    'uid' => $user->uid,
+    'collection_name' => trim($form_state['values']['collection_name']),
+    'description' => $form_state['values']['collection_desc'],
+  );
+  // This can't be done via tripal_create_collection() since we support more
+  // then a single bundle. Instead we are going to use the controller class directly.
+  $collection = new TripalEntityCollection();
+  $collection->create($collection_details);
+  $collection_id = $collection->getCollectionID();
+
+  // First, determine the bundle for each entity in our resultset.
+  $entities = array();
+  $results = unserialize($form_state['values']['results']);
+  foreach($results as $r) {
+
+    // Retrieve the bundle for the current entity.
+    // ASSUMPTION: all search results are TripalEntities.
+    $wrapper = entity_metadata_wrapper('TripalEntity', $r->entity);
+    $bundle = $wrapper->getBundle();
+
+    // If this is the first time we've seen this bundle
+    // then initialize the array.
+    if (!isset($entities[$bundle])) {
+      $entities[$bundle] = array(
+        'bundle_name' => $bundle,
+        'ids' => array(),
+        'fields' => array(),
+      );
+    }
+    // Note: $r->entity is the entity_id due to the way the search_api saves results.
+    // Doing a check here just in case some search index backends store the data differently.
+    if (is_int($r->entity)) {
+      $entities[$bundle]['ids'][] = $r->entity;
+    }
+    elseif (is_object($r->entity) AND property_exists($r->entity, 'id')) {
+      $entities[$bundle]['ids'][] = $r->entity->id;
+    }
+    else {
+      tripal_report_error(
+        'Tripal Data Collection',
+        TRIPAL_ERROR,
+        'Unable to save entity to collection. Results from the view are: '.print_r($r, TRUE)
+      );
+    }
+  }
+
+  // Now add the entities to the collection based on bundle.
+  foreach($entities as $bundle_name => $bundle_col) {
+
+    $field_ids = array();
+    foreach (field_info_instances('TripalEntity', $bundle_name) as $field) {
+      $field_ids[] = $field['field_id'];
+    }
+    $bundle_col['fields'] = $field_ids;
+    $collection->addBundle($bundle_col);
+  }
+
+  // Finally, tell the user we're done and link them to the collection.
+  drupal_set_message(t("Collection '%name' created with %num_recs record(s). Check the !view to generate file links.",
+    array(
+      '%name' => $collection_details['collection_name'],
+      '%num_recs' => count($results),
+      '!view' => l('data collections page', 'user/' . $user->uid . '/data-collections'),
+    ))
+  );
+}

+ 11 - 8
tripal_chado/api/tripal_chado.schema.api.inc

@@ -588,7 +588,8 @@ function chado_get_base_tables() {
 
   // Initialize the base tables with those tables that are missing a type.
   // Ideally they should have a type, but that's for a future version of Chado.
-  $base_tables = array('organism', 'project', 'analysis', 'biomaterial', 'eimage');
+  $base_tables = array('organism', 'project', 'analysis', 'biomaterial', 
+    'eimage', 'assay');
 
   // We'll use the cvterm table to guide which tables are base tables. Typically
   // base tables (with a few exceptions) all have a type.  Iterate through the
@@ -617,12 +618,18 @@ function chado_get_base_tables() {
   // whose foreign key constraints link to two or more base table.
   $final_list = array();
   foreach ($base_tables as $i => $tablename) {
-    // The biomaterial table breaks our rule and seems to look like a linking
-    // table, but we want to keep it as a base table.
-    if ($tablename == 'biomaterial') {
+    // A few tables break our rule and seems to look 
+    // like a linking table, but we want to keep it as a base table.
+    if ($tablename == 'biomaterial' or $tablename == 'assay' or $tablename == 'arraydesign') {
       $final_list[] = $tablename;
       continue;
     }
+    
+    // Remove the phenotype table. It really shouldn't be a base table as
+    // it is meant to store individual phenotype measurements.
+    if ($tablename == 'phenotype') {
+      continue;
+    }
     $num_links = 0;
     $schema = chado_get_schema($tablename);
     $fkeys = $schema['foreign keys'];
@@ -637,10 +644,6 @@ function chado_get_base_tables() {
     }
   }
 
-  // Remove the phenotype table. It really shouldn't be a base table as
-  // it is meant to store individual phenotype measurements.
-  unset($final_list['phenotyp']);
-
   // Now add in the cvterm table to the list.
   $final_list[] = 'cvterm';
 

+ 2 - 2
tripal_chado/api/tripal_chado.semweb.api.inc

@@ -109,11 +109,11 @@ function chado_associate_semweb_term($chado_table, $chado_column, $term,
   if ($chado_table) {
     $schema = chado_get_schema($chado_table);
     if (!$schema) {
-      tripal_set_message('The $chado_table is not a known table in Chado.', TRIPAL_ERROR);
+      tripal_set_message("Cannot associate the term with the field because the $chado_table is not a known table in Chado.", TRIPAL_ERROR);
       return FALSE;
     }
     if (!array_key_exists($chado_column, $schema['fields'])) {
-      tripal_set_message('The $chado_column is not a known column in the $chado_table.', TRIPAL_ERROR);
+      tripal_set_message("Cannot associate the term with the field because the $chado_column is not a known column in the $chado_table.", TRIPAL_ERROR);
       return FALSE;
     }
   }

+ 19 - 18
tripal_chado/includes/TripalFields/local__contact/local__contact.inc

@@ -134,25 +134,26 @@ class local__contact extends ChadoField {
     );
 
     // Handle the biomaterial table.
-    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;
-          }
-        }
+    if (!$record) {
+      return;
+    }
+      
+    $linker_field = 'chado-' . $field_table . '__' . $field_column;
+    $contact = $record->{$field_column};
+    
+    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;

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

@@ -83,42 +83,84 @@ 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'] = '';
     }
   }
 

+ 96 - 13
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol.inc

@@ -106,39 +106,39 @@ class sep__protocol extends ChadoField {
    *
    */
   public function load($entity) {
-
     parent::load($entity);
-
-
     $record = $entity->chado_record;
     $settings = $this->instance['settings'];
 
-
     $field_name = $this->field['field_name'];
     $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 = $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_id" => $protocol_id,
-      "protocol_name" => $protocol_name,
-      "entity_id" => $entity_id,
+      $protocol_name_term => $protocol->name,
+      $protocol_type_term => $protocol->type_id->name,
     ];
+    
+    $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')) {
@@ -146,4 +146,87 @@ 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');
+
+    return [
+      $field_term => [
+        'operations' => ['eq', 'contains', 'starts'],
+        'sortable' => TRUE,
+        'searchable' => TRUE,
+        'readonly' => FALSE,
+        'type' => 'xs:complexType',
+        'elements' => [
+          'rdfs:label' => [
+            'searchable' => TRUE,
+            'name' => 'protocol_name',
+            'operations' => ['eq', 'ne', 'contains', 'starts'],
+            'sortable' => FALSE,
+            'type' => 'xs:string',
+            'readonly' => TRUE,
+            'required' => FALSE,
+          ],
+          'entity' => [
+            'searchable' => FALSE,
+          ],
+          $type_id_term => [
+            'searchable' => TRUE,
+            'name' => 'protocol_type',
+            'operations' => ['eq', 'ne', 'contains', 'starts'],
+            'sortable' => TRUE,
+            'readonly' => FALSE,
+            'required' => TRUE,
+            'type' => 'xs:integer',
+          ],
+        ],
+      ],
+    ];
+  }
+
+  /**
+   * Provide query support.  We only make use of the name and type.
+   * @param $query
+   * @param $condition
+   */
+
+  function query($query, $condition) {
+    $alias = $this->field['field_name'];
+    $operator = $condition['operator'];
+    $field_term_id = $this->getFieldTermID();
+    $type_id_term = $field_term_id . ',' . tripal_get_chado_semweb_term('protocol', 'type_id');
+
+    // Join to the protocol table for this field.
+    $this->queryJoinOnce($query, 'protocol', $alias, "base.protocol_id = $alias.protocol_id");
+
+
+    if ($condition['column'] == $field_term_id or
+      $condition['column'] == $field_term_id . ',rdfs:label') {
+      $query->condition("$alias.name", $condition['value'], $operator);
+    }
+    if ($condition['column'] == $type_id_term) {
+      $this->queryJoinOnce($query, 'cvterm', 'CVT', "base.type_id = CVT.cvterm_id");
+      $query->condition("CVT.name", $condition['value'], $operator);
+    }
+  }
+
+  function queryOrder($query, $order) {
+    $alias = $this->field['field_name'];
+    $field_term_id = $this->getFieldTermID();
+    $type_id_term = tripal_get_chado_semweb_term('protocol', 'type_id');
+    // Join to the protocol table for this field.
+    $this->queryJoinOnce($query, 'protocol', $alias, "base.protocol_id = $alias.organism_id");
+
+    if ($order['column'] == $type_id_term) {
+      if (!in_array('CVT', $joins)) {
+        $this->queryJoinOnce($query, 'cvterm', 'CVT', "base.type_id = CVT.cvterm_id");
+      }
+      $query->orderBy("CVT.name", $order['direction']);
+    }
+  }
+
+
 }

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

@@ -21,69 +21,23 @@ 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]['value']["protocol_id"];
-      $protocol_name = $items[0]['value']["protocol_name"];
+      
+      $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']);
       if ($entity_id) {
@@ -100,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) {
   }

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

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

+ 346 - 10
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') {
@@ -463,8 +503,9 @@ function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type,
     );
   }
 
-  //protocol
-  if ($table_name == 'protocol' and array_key_exists('protocol_id', $schema['fields'])) {
+  // Protocol.
+  if ($table_name != 'protocol' and 
+      array_key_exists('protocol_id', $schema['fields'])) {
     $field_name = 'sep__protocol';
     $field_type = 'sep__protocol';
     $info[$field_name] = array(
@@ -477,6 +518,42 @@ function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type,
       ),
     );
   }
+  
+  // Assay operator.
+  if ($table_name == 'assay') {
+      $field_name = 'assay__operator_id';
+      $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',
+        ),
+      );
+    }
+  
+  // 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',
+      ),
+    );
+  } 
 
 }
 
@@ -1066,7 +1143,85 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
     if ($table_name == 'contact' and $column_name == 'description') {
       $base_info['label'] = 'Short Description';
     }
-
+    //
+    // PROTOCOL TABLE
+    //
+    if ($table_name == 'protocol') {
+      if ($column_name == 'protocoldescription') {
+        $base_info['label'] = 'Protocol Description';
+      }
+      if ($column_name == 'uri') {
+        $base_info['label'] = 'URI';
+        $base_info['widget']['type'] = 'text_textfield';
+        $base_info['settings']['text_processing'] = '0';
+      }
+      if ($column_name == 'name') {
+        $base_info['widget']['type'] = 'text_textfield';
+        $base_info['settings']['text_processing'] = '0';
+      }
+      if ($column_name == 'hardwaredescription') {
+        $base_info['label'] = 'Instrument Description';
+        $base_info['description'] = 'The description of instruments used for this protocol';
+      }
+      if ($column_name == 'softwaredescription') {
+        $base_info['label'] = 'Software Description';
+        $base_info['description'] = 'The description of software used for this protocol';
+      }
+      if ($column_name == 'pub_id') {
+        $base_info['label'] = 'Publication';
+      }
+    }
+    //
+    // ASSAY TABLE
+    //
+    if ($table_name == 'assay') {
+      if ($column_name == 'name') {
+        $base_info['widget']['type'] = 'text_textfield';
+        $base_info['settings']['text_processing'] = '0';
+      }
+      if ($column_name == 'protcol_id') {
+        $base_info['label'] = 'Protocol';
+      }
+      if ($column_name == 'arraybatchidentifier') {
+        $base_info['label'] = 'Array Batch Identifier';
+        $base_info['widget']['type'] = 'text_textfield';
+        $base_info['settings']['text_processing'] = '0';
+      }
+      if ($column_name == 'operator_id') {
+        $base_info['label'] = 'Operator';
+      }
+      if ($column_name == 'arrayidentifier') {
+        $base_info['label'] = 'Array Identifier';
+        $base_info['widget']['type'] = 'text_textfield';
+        $base_info['settings']['text_processing'] = '0';
+      }
+      if ($column_name == 'arraydesign_id') {
+        $base_info['label'] = 'Array Design';
+      }
+      if ($column_name == 'assaydate') {
+        $base_info['label'] = 'Assay Date';
+      }
+    }
+    //
+    // ARRAYDESIGN TABLE
+    //
+    if ($table_name == 'arraydesign') {
+      if ($column_name == 'name' or $column_name == 'version' or 
+          $column_name == 'array_dimensions' or $column_name == 'element_dimensions') {
+        $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;
   }
@@ -1148,6 +1303,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
@@ -1202,7 +1433,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,
@@ -1225,6 +1456,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') {
@@ -1686,11 +1951,83 @@ 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(),
+        ),
+      ),
+    );
+  } 
+  
+  if ($table_name == 'assay') {      
+    // Remove the ncit__operator added by the
+    // tripal_chado_bunde_instnaces_info_base function.
+    unset($info['ncit__operator']);
+    
+    $field_name = 'assay__operator_id';
+    $info[$field_name] =  array(
+      'field_name' => $field_name,
+      'entity_type' => $entity_type,
+      'bundle' => $bundle->name,
+      'label' => 'Operator',
+      'description' => 'The individual responsible for performing the assay.',
+      'required' => TRUE,
+      'settings' => array(
+        'auto_attach' => TRUE,
+        'chado_table' => 'assay',
+        'chado_column' => 'operator_id',
+        'base_table' => 'assay',
+        'term_vocabulary' => 'NCIT',
+        'term_name' => 'Operator',
+        'term_accession' => 'C48036',
+        
+      ),
+      'widget' => array(
+        'type' => 'local__contact_widget',
+        'settings' => array(
+          'display_label' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'inline',
+          'type' => 'local__contact_formatter',
+          'settings' => array(),
+        ),
+      ),
+    );
+  } 
 }
 
 /**
@@ -2128,7 +2465,6 @@ function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle
     );
   }
 
-
   // PUBLICATIONS
   $pub_table = $table_name . '_pub';
   if (chado_table_exists($pub_table)) {

+ 417 - 48
tripal_chado/includes/tripal_chado.semweb.inc

@@ -22,10 +22,12 @@ function tripal_chado_populate_chado_semweb_table() {
   tripal_chado_populate_vocab_DC();
   tripal_chado_populate_vocab_EDAM();
   tripal_chado_populate_vocab_ERO();
+  tripal_chado_populate_vocab_EFO();
   tripal_chado_populate_vocab_FOAF();
   tripal_chado_populate_vocab_HYDRA();
   tripal_chado_populate_vocab_IAO();
   tripal_chado_populate_vocab_LOCAL();
+  tripal_chado_populate_vocab_NCIT();
   tripal_chado_populate_vocab_NCBITAXON();
   tripal_chado_populate_vocab_OBCS();
   tripal_chado_populate_vocab_OBI();
@@ -185,6 +187,8 @@ function tripal_chado_populate_vocab_SCHEMA() {
     'cv_name' => 'schema',
     'definition' => 'An alias for the item.',
   ));
+  chado_associate_semweb_term(NULL, 'synonym_id', $term);
+  chado_associate_semweb_term('cvtermsynonym', 'synonym', $term);
 
   $term = chado_insert_cvterm(array(
     'id' => 'schema:comment',
@@ -202,6 +206,7 @@ function tripal_chado_populate_vocab_SCHEMA() {
   ));
   chado_associate_semweb_term(NULL, 'description', $term);
   chado_associate_semweb_term('organism', 'comment', $term);
+  chado_associate_semweb_term('protocol', 'protocoldescription', $term);
 
   $term = chado_insert_cvterm(array(
     'id' => 'schema:publication',
@@ -250,6 +255,7 @@ function tripal_chado_populate_vocab_SCHEMA() {
     'cv_name' => 'schema',
     'definition' => 'A page devoted to a single item, such as a particular product or hotel.',
   ));
+  
 }
 
 /**
@@ -269,6 +275,16 @@ function tripal_chado_populate_vocab_SEP() {
     'cv_name' => 'sep',
     'definition' => 'A biological sample analysed by a particular technology.',
   ));
+  chado_associate_semweb_term(NULL, 'biomaterial_id', $term);
+  
+  $term = tripal_insert_cvterm([
+    'id' => 'sep:00101',
+    'name' => 'protocol',
+    'cv_name' => 'sep',
+    'definition' => 'A protocol is a process which is a parameterizable description of a process.',
+  ]);
+  chado_associate_semweb_term(NULL, 'protocol_id', $term);
+  chado_associate_semweb_term(NULL, 'nd_protocol_id', $term);
 }
 /**
  * Adds the SemanticScience database and terms.
@@ -347,6 +363,27 @@ function tripal_chado_populate_vocab_SIO() {
     'cv_name' => 'SIO',
     'definition' => 'an email address is an identifier to send mail to particular electronic mailbox.',
   ));
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'SIO:001007',
+    'name' => 'assay',
+    'cv_name' => 'SIO',
+    'definition' => 'An assay is an investigative (analytic) procedure in ' .
+      'laboratory medicine, pharmacology, environmental biology, and ' . 
+      'molecular biology for qualitatively assessing or quantitatively ' . 
+      'measuring the presence or amount or the functional activity of a ' . 
+      'target entity (the analyte) which can be a drug or biochemical ' .
+      'substance or a cell in an organism or organic sample.',
+  ));
+  chado_associate_semweb_term(NULL, 'assay_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'SIO:010054',
+    'name' => 'cell line',
+    'cv_name' => 'SIO',
+    'definition' => 'A cell line is a collection of genetically identifical cells.',
+  ));
+  chado_associate_semweb_term(NULL, 'cell_line_id', $term);
 }
 
 /**
@@ -360,6 +397,9 @@ function tripal_chado_populate_vocab_SO() {
     'urlprefix' => 'http://www.sequenceontology.org/browser/current_svn/term/{db}:{accession}',
   ));
   chado_insert_cv('sequence', 'The sequence ontology.');
+  
+  $term = chado_get_cvterm(['cv_id' => ['name' => 'sequence'], 'name' => 'sequence_feature']);
+  chado_associate_semweb_term(NULL, 'feature_id', $term);
 }
 
 /**
@@ -420,7 +460,16 @@ function tripal_chado_populate_vocab_EDAM() {
   ));
   chado_insert_cv(
     'EDAM',
-    'EDAM is an ontology of well established, familiar concepts that are prevalent within bioinformatics, including types of data and data identifiers, data formats, operations and topics. EDAM is a simple ontology - essentially a set of terms with synonyms and definitions - organised into an intuitive hierarchy for convenient use by curators, software developers and end-users. EDAM is suitable for large-scale semantic annotations and categorization of diverse bioinformatics resources. EDAM is also suitable for diverse application including for example within workbenches and workflow-management systems, software distributions, and resource registries.'
+    'EDAM is an ontology of well established, familiar concepts that are ' .
+    'prevalent within bioinformatics, including types of data and data ' . 
+    'identifiers, data formats, operations and topics. EDAM is a simple ' . 
+    'ontology - essentially a set of terms with synonyms and definitions - ' .
+    'organised into an intuitive hierarchy for convenient use by curators, ' . 
+    'software developers and end-users. EDAM is suitable for large-scale ' . 
+    'semantic annotations and categorization of diverse bioinformatics ' . 
+    'resources. EDAM is also suitable for diverse application including ' . 
+    'for example within workbenches and workflow-management systems, ' . 
+    'software distributions, and resource registries.'
   );
 
   $term = chado_insert_cvterm(array(
@@ -437,7 +486,7 @@ function tripal_chado_populate_vocab_EDAM() {
     'cv_name' => 'EDAM',
     'definition' => 'A fixed-size datum calculated (by using a hash function) for a molecular sequence, typically for purposes of error detection or indexing.',
   ));
-  chado_associate_semweb_term('feature', 'md5checksum', $term);
+  chado_associate_semweb_term(NULL, 'md5checksum', $term);
 
   $term = chado_insert_cvterm(array(
     'id' => 'data:2091',
@@ -463,6 +512,7 @@ function tripal_chado_populate_vocab_EDAM() {
     'definition' => 'A text token, number or something else which identifies an entity, but which may not be persistent (stable) or unique (the same identifier may identify multiple things).',
   ));
   chado_associate_semweb_term(NULL, 'uniquename', $term);
+  chado_associate_semweb_term('assay', 'arrayidentifier', $term);
 
   $term = chado_insert_cvterm(array(
     'id' => 'data:2976',
@@ -485,7 +535,7 @@ function tripal_chado_populate_vocab_EDAM() {
     'cv_name' => 'EDAM',
     'definition' => 'A map of (typically one) DNA sequence annotated with positional or non-positional features.',
   ));
-  chado_associate_semweb_term(NULL, 'eimage_id', $term);
+  chado_associate_semweb_term(NULL, 'featuremap_id', $term);
 
   $term = chado_insert_cvterm(array(
     'id' => 'data:1278',
@@ -532,6 +582,7 @@ function tripal_chado_populate_vocab_EDAM() {
     'definition' => 'The name of a biological or bioinformatics database.',
   ));
   chado_associate_semweb_term('analysis', 'sourceuri', $term);
+  chado_associate_semweb_term(NULL, 'uri', $term);
 
   $term = chado_insert_cvterm(array(
     'id' => 'data:2336',
@@ -564,7 +615,7 @@ function tripal_chado_populate_vocab_EDAM() {
     'cv_name' => 'EDAM',
     'definition' => 'Apply analytical methods to existing data of a specific type.',
   ));
-  chado_associate_semweb_term('phylotree', 'analysis_id', $term);
+  chado_associate_semweb_term(NULL, 'analysis_id', $term);
 
   $term = chado_insert_cvterm(array(
     'id' => 'data:0872',
@@ -572,6 +623,7 @@ function tripal_chado_populate_vocab_EDAM() {
     'cv_name' => 'EDAM',
     'definition' => 'The raw data (not just an image) from which a phylogenetic tree is directly generated or plotted, such as topology, lengths (in time or in expected amounts of variance) and a confidence interval for each length.',
   ));
+  chado_associate_semweb_term(NULL, 'phylotree_id', $term);
   $term = chado_insert_cvterm(array(
     'id' => 'data:3272',
     'name' => 'Species tree',
@@ -592,7 +644,59 @@ function tripal_chado_populate_vocab_EDAM() {
   ));
 
 }
-
+/**
+ * Adds the Experimental Factor Ontology and terms.
+ */
+function tripal_chado_populate_vocab_EFO() {
+  chado_insert_db(array(
+    'name' => 'EFO',
+    'description' => 'Experimental Factor Ontology',
+    'url' => 'http://www.ebi.ac.uk/efo/efo.owl',
+    'urlprefix' => 'http://www.ebi.ac.uk/efo/{db}_{accession}',
+  ));
+  chado_insert_cv(
+    'efo',
+    'The Experimental Factor Ontology (EFO) provides a systematic description of many experimental variables available in EBI databases, and for external projects such as the NHGRI GWAS catalogue. It combines parts of several biological ontologies, such as anatomy, disease and chemical compounds. The scope of EFO is to support the annotation, analysis and visualization of data handled by many groups at the EBI and as the core ontology for OpenTargets.org'
+  );
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'EFO:0000548',
+    'name' => 'instrument',
+    'cv_name' => 'efo',
+    'definition' => 'An instrument is a device which provides a mechanical or electronic function.',
+  ));
+  chado_associate_semweb_term('protocol', 'hardwaredescription', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'EFO:0000269',
+    'name' => 'array design',
+    'cv_name' => 'efo',
+    'definition' => 'An instrument design which describes the design of the array.',
+  ));
+  chado_associate_semweb_term(NULL, 'arraydesign_id', $term);
+   
+  $term = chado_insert_cvterm(array(
+    'id' => 'EFO:0005522',
+    'name' => 'substrate type',
+    'cv_name' => 'efo',
+    'definition' => 'Controlled terms for descriptors of types of array substrates.',
+  ));
+  chado_associate_semweb_term('arraydesign', 'substratetype_id', $term);
+  $term = chado_insert_cvterm(array(
+    'id' => 'EFO:0001728',
+    'name' => 'array manufacturer',
+    'cv_name' => 'efo',
+    'definition' => '',
+  ));
+  chado_associate_semweb_term('arraydesign', 'manufacturer_id', $term);
+  $term = chado_insert_cvterm(array(
+    'id' => 'EFO:0001728',
+    'name' => 'array manufacturer',
+    'cv_name' => 'efo',
+    'definition' => '',
+  ));
+  chado_associate_semweb_term('arraydesign', 'manufacturer_id', $term);
+}
 /**
  * Adds the Eagle-i Resource Ontology database and terms.
  */
@@ -614,6 +718,15 @@ function tripal_chado_populate_vocab_ERO() {
     'cv_name' => 'ero',
     'definition' => 'A database is an organized collection of data, today typically in digital form.',
   ));
+  chado_associate_semweb_term(NULL, 'db_id', $term);
+  $term = chado_insert_cvterm(array(
+    'id' => 'ERO:0000387',
+    'name' => 'data acquisition',
+    'cv_name' => 'ero',
+    'definition' => 'A technique that samples real world physical conditions and conversion of the resulting samples into digital numeric values that can be manipulated by a computer.',
+  ));
+  chado_associate_semweb_term(NULL, 'acquisition_id', $term);
+  
 }
 
 /**
@@ -965,6 +1078,22 @@ function tripal_chado_populate_vocab_LOCAL() {
   ));
   chado_associate_semweb_term(NULL, 'is_obsolete', $term);
 
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:is_current',
+    'name' => 'is_current',
+    'definition' => 'Indicates if this record is current.',
+    'cv_name' => 'local',
+  ));
+  chado_associate_semweb_term(NULL, 'is_current', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:is_internal',
+    'name' => 'is_internal',
+    'definition' => 'Indicates if this record is internal and not normally available outside of a local setting.',
+    'cv_name' => 'local',
+  ));
+  chado_associate_semweb_term(NULL, 'is_internal', $term);
+  
   $term = chado_insert_cvterm(array(
     'id' => 'local:miniref',
     'name' => 'Mini-ref',
@@ -973,6 +1102,15 @@ function tripal_chado_populate_vocab_LOCAL() {
   ));
   chado_associate_semweb_term('pub', 'miniref', $term);
 
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:array_batch_identifier',
+    'name' => 'Array Batch Identifier',
+    'definition' => 'A unique identifier for an array batch.',
+    'cv_name' => 'local',
+  ));
+  chado_associate_semweb_term('assay', 'arraybatchidentifier', $term);
+  
   //-----------------------------
   // Relationship Terms
   //-----------------------------
@@ -1135,10 +1273,19 @@ function tripal_chado_populate_vocab_LOCAL() {
   //--------------
   // Library Terms
   //--------------
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:library',
+    'name' => 'Library',
+    'definition' => 'A group of physical entities organized into a collection',
+    'cv_name' => 'local',
+    'db_name' => 'local'
+  ));
+  chado_associate_semweb_term(NULL, 'library_id', $term);
+  
   // Insert cvterm 'library_description' into cvterm table of chado
   // database. This CV term is used to keep track of the library
   // description in the libraryprop table.
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'id' => 'local:library_description',
     'name' => 'Library Description',
     'definition' => 'Description of a library',
@@ -1147,42 +1294,42 @@ function tripal_chado_populate_vocab_LOCAL() {
   ));
 
   // add cvterms for the map unit types
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'id' => 'local:cdna_library',
     'name' => 'cdna_library',
     'definition' => 'cDNA library',
     'cv_name' => 'library_type',
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'id' => 'local:bac_library',
     'name' => 'bac_library',
     'definition' => 'Bacterial Artifical Chromsome (BAC) library',
     'cv_name' => 'library_type',
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'id' => 'local:fosmid_library',
     'name' => 'fosmid_library',
     'definition' => 'Fosmid library',
     'cv_name' => 'library_type',
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'id' => 'local:cosmid_library',
     'name' => 'cosmid_library',
     'definition' => 'Cosmid library',
     'cv_name' => 'library_type',
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'id' => 'local:yac_library',
     'name' => 'yac_library',
     'definition' => 'Yeast Artificial Chromosome (YAC) library',
     'cv_name' => 'library_type',
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'id' => 'local:genomic_library',
     'name' => 'genomic_library',
     'definition' => 'Genomic Library',
@@ -1194,35 +1341,35 @@ function tripal_chado_populate_vocab_LOCAL() {
   // Feature Map
   //--------------
   // add cvterms for the map unit types
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'cM',
     'definition' => 'Centimorgan units',
     'cv_name' => 'featuremap_units',
     'is_relationship' => 0,
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'bp',
     'definition' => 'Base pairs units',
     'cv_name' => 'featuremap_units',
     'is_relationship' => 0,
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'bin_unit',
     'definition' => 'The bin unit',
     'cv_name' => 'featuremap_units',
     'is_relationship' => 0,
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'marker_order',
     'definition' => 'Units simply to define marker order.',
     'cv_name' => 'featuremap_units',
     'is_relationship' => 0,
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'undefined',
     'definition' => 'A catch-all for an undefined unit type',
     'cv_name' => 'featuremap_units',
@@ -1230,14 +1377,14 @@ function tripal_chado_populate_vocab_LOCAL() {
     'db_name' => 'local'
   ));
   // featurepos properties
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'start',
     'definition' => 'The start coordinate for a map feature.',
     'cv_name' => 'featurepos_property',
     'is_relationship' => 0,
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'stop',
     'definition' => 'The end coordinate for a map feature',
     'cv_name' => 'featurepos_property',
@@ -1245,7 +1392,7 @@ function tripal_chado_populate_vocab_LOCAL() {
     'db_name' => 'local'
   ));
   // add cvterms for map properties
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'Map Dbxref',
     'definition' => 'A unique identifer for the map in a remote database.  The '
       . 'format is a database abbreviation and a unique accession separated '
@@ -1254,21 +1401,21 @@ function tripal_chado_populate_vocab_LOCAL() {
     'is_relationship' => 0,
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'Map Type',
     'definition' => 'The type of Map (e.g. QTL, Physical, etc.)',
     'cv_name' => 'featuremap_property',
     'is_relationship' => 0,
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'Genome Group',
     'definition' => '',
     'cv_name' => 'featuremap_property',
     'is_relationship' => 0,
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'URL',
     'definition' => 'A univeral resource locator (URL) reference where the '
       . 'publication can be found.  For maps found online, this would be '
@@ -1277,7 +1424,7 @@ function tripal_chado_populate_vocab_LOCAL() {
     'is_relationship' => 0,
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'Population Type',
     'definition' => 'A brief description of the population type used to generate '
     . 'the map (e.g. RIL, F2, BC1, etc).',
@@ -1285,29 +1432,21 @@ function tripal_chado_populate_vocab_LOCAL() {
     'is_relationship' => 0,
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'Population Size',
     'definition' => 'The size of the population used to construct the map.',
     'cv_name' => 'featuremap_property',
     'is_relationship' => 0,
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'Methods',
     'definition' => 'A brief description of the methods used to construct the map.',
     'cv_name' => 'featuremap_property',
     'is_relationship' => 0,
     'db_name' => 'local'
   ));
-  chado_insert_cvterm(array(
-    'name' => 'Software',
-    'definition' => 'The software used to construct the map.',
-    'cv_name' => 'featuremap_property',
-    'is_relationship' => 0,
-    'db_name' => 'local'
-  ));
-
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'Software',
     'definition' => 'The software used to construct the map.',
     'cv_name' => 'featuremap_property',
@@ -1355,7 +1494,7 @@ function tripal_chado_populate_vocab_LOCAL() {
   //--------------
   // add analysis_date.  This is no longer used (as far as we can tell) but we don't
   // get rid of it in case it is used, so just keep it in the Tripal CV
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'analysis_date',
     'definition' => 'The date that an analysis was performed.',
     'cv_name' => 'tripal_analysis',
@@ -1365,7 +1504,7 @@ function tripal_chado_populate_vocab_LOCAL() {
 
   // add analysis_short_name.  This is no longer used (as far as we can tell) but we don't
   // get rid of it in case it is used, so just keep it in the Tripal CV
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
       'name' => 'analysis_short_name',
       'definition' => 'A computer legible (no spaces or special characters) '
         . 'abbreviation for the analysis.',
@@ -1377,7 +1516,7 @@ function tripal_chado_populate_vocab_LOCAL() {
 
   // the 'analysis_property' vocabulary is for user definable properties wo we
   // will add an 'Analysis Type' to this vocubulary
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'name' => 'Analysis Type',
     'definition' => 'The type of analysis that was performed.',
     'cv_name' => 'analysis_property',
@@ -1386,7 +1525,7 @@ function tripal_chado_populate_vocab_LOCAL() {
   ), array('update_existing' => TRUE));
 
   // Add a term to be used for an inherent 'type_id' for the organism table.
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'id' => 'local:analysis',
     'name' => 'analysis',
     'definition' => 'A process as a method of studying the nature of something ' .
@@ -1397,7 +1536,7 @@ function tripal_chado_populate_vocab_LOCAL() {
   ));
 
   // TODO: change this to foaf:Project
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'id' => 'local:project',
     'name' => 'project',
     'definition' => 'A plan or proposal for accomplishing something. ' .
@@ -1405,8 +1544,10 @@ function tripal_chado_populate_vocab_LOCAL() {
     'Copyright © 2011 by Houghton Mifflin Harcourt Publishing Company).',
     'cv_name' => 'local',
   ));
+  chado_associate_semweb_term(NULL, 'project_id', $term);
+  
 
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'id' => 'local:source_data',
     'name' => 'source_data',
     'definition' => 'The location where data that is being used come from.',
@@ -1425,16 +1566,17 @@ function tripal_chado_populate_vocab_LOCAL() {
     'cv_name' => 'local',
   ));
   chado_associate_semweb_term('biomaterial', 'biosourceprovider_id', $term);
+  chado_associate_semweb_term(NULL, 'contact_id', $term);
 
 
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'id' => 'local:relationship',
     'name' => 'relationship',
     'definition' => 'The way in which two things are connected.',
     'cv_name' => 'local',
   ));
 
-  chado_insert_cvterm(array(
+  $term = chado_insert_cvterm(array(
     'id' => 'local:biomaterial',
     'name' => 'biomaterial',
     'definition' => 'A biomaterial represents the MAGE concept of BioSource, BioSample, ' .
@@ -1443,6 +1585,73 @@ function tripal_chado_populate_vocab_LOCAL() {
     'biomaterials via the biomaterialrelationship table.',
     'cv_name' => 'local',
   ));
+  
+  //
+  // Terms for arraydesign table
+  //
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:array_dimensions',
+    'name' => 'array_dimensions',
+    'definition' => 'The dimensions of an array.',
+    'cv_name' => 'local',
+  ));
+  chado_associate_semweb_term('arraydesign', 'array_dimensions', $term);
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:element_dimensions',
+    'name' => 'element_dimensions',
+    'definition' => 'The dimensions of an element.',
+    'cv_name' => 'local',
+  ));
+  chado_associate_semweb_term('arraydesign', 'element_dimensions', $term);
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:num_of_elements',
+    'name' => 'num_of_elements',
+    'definition' => 'The number of elements.',
+    'cv_name' => 'local',
+  ));
+  chado_associate_semweb_term('arraydesign', 'num_of_elements', $term);
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:num_array_columns',
+    'name' => 'num_array_columns',
+    'definition' => 'The number of columns in an array.',
+    'cv_name' => 'local',
+  ));
+  chado_associate_semweb_term('arraydesign', 'num_array_columns', $term);
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:num_array_rows',
+    'name' => 'num_array_rows',
+    'definition' => 'The number of rows in an array.',
+    'cv_name' => 'local',
+  ));
+  chado_associate_semweb_term('arraydesign', 'num_array_rows', $term);
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:num_grid_columns',
+    'name' => 'num_grid_columns',
+    'definition' => 'The number of columns in a grid.',
+    'cv_name' => 'local',
+  ));
+  chado_associate_semweb_term('arraydesign', 'num_grid_columns', $term);
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:num_grid_rows',
+    'name' => 'num_grid_rows',
+    'definition' => 'The number of rows in a grid.',
+    'cv_name' => 'local',
+  ));
+  chado_associate_semweb_term('arraydesign', 'num_grid_rows', $term);
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:num_sub_columns',
+    'name' => 'num_sub_columns',
+    'definition' => 'The number of sub columns.',
+    'cv_name' => 'local',
+  ));
+  chado_associate_semweb_term('arraydesign', 'num_sub_columns', $term);
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:num_sub_rows',
+    'name' => 'num_sub_rows',
+    'definition' => 'The number of sub rows.',
+    'cv_name' => 'local',
+  ));
+  chado_associate_semweb_term('arraydesign', 'num_sub_rows', $term);
 }
 /**
  * Adds the Systems Biology Ontology database and terms.
@@ -1482,16 +1691,17 @@ function tripal_chado_populate_vocab_SBO() {
 }
 
 /**
- * Adds the Software Ontology database and terms.
+ * Adds the "Bioinformatics operations, data types, formats, identifiers and 
+ * topics" database and terms.
  */
 function tripal_chado_populate_vocab_SWO() {
   chado_insert_db(array(
     'name' => 'SWO',
-    'description' => 'Software Ontology',
+    'description' => 'Bioinformatics operations, data types, formats, identifiers and topics',
     'url' => 'http://purl.obolibrary.org/obo/swo',
-    'urlprefix' => 'http://www.ebi.ac.uk/swo/',
+    'urlprefix' => 'http://www.ebi.ac.uk/swo/{db}_{accession}',
   ));
-  chado_insert_cv('swo','Software Ontology.');
+  chado_insert_cv('swo','Bioinformatics operations, data types, formats, identifiers and topics.');
 
   $term = chado_insert_cvterm(array(
     'id' => 'SWO:0000001',
@@ -1505,6 +1715,7 @@ function tripal_chado_populate_vocab_SWO() {
       'specific operations.',
   ));
   chado_associate_semweb_term('analysis', 'program', $term);
+  chado_associate_semweb_term('protocol', 'softwaredescription', $term);
 }
 
 /**
@@ -1623,6 +1834,163 @@ function tripal_chado_populate_vocab_TAXRANK() {
   chado_associate_semweb_term('organism', 'infraspecific_name', $term);
 }
 
+/**
+ * Adds the NCIT vocabulary database and terms.
+ */
+function tripal_chado_populate_vocab_NCIT() {
+  chado_insert_db(array(
+    'name' => 'NCI Thesaurus OBO Edition',
+    'description' => 'NCI Thesaurus OBO Edition.',
+    'url' => 'http://purl.obolibrary.org/obo/ncit.owl',
+    'urlprefix' => ' http://purl.obolibrary.org/obo/{db}_{accession}',
+  ));
+  chado_insert_cv(
+    'ncit',
+    'The NCIt OBO Edition project aims to increase integration of the NCIt with OBO Library ontologies. NCIt is a reference terminology that includes broad coverage of the cancer domain, including cancer related diseases, findings and abnormalities. NCIt OBO Edition releases should be considered experimental.'
+  );
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C25164',
+    'name' => 'Date',
+    'cv_name' => 'ncit',
+    'definition' => 'The particular day, month and year an event has happened or will happen.',
+  ));
+  chado_associate_semweb_term('assay', 'assaydate', $term);
+  chado_associate_semweb_term('acquisition', 'acquisitiondate', $term);
+  chado_associate_semweb_term('quantification', 'quantificationdate', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C48036',
+    'name' => 'Operator',
+    'cv_name' => 'ncit',
+    'definition' => 'A person that operates some apparatus or machine',
+  ));
+  chado_associate_semweb_term(NULL, 'operator_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C45378',
+    'name' => 'Technology Platform',
+    'cv_name' => 'ncit',
+    'definition' => 'The specific version (manufacturer, model, etc.) of a technology that is used to carry out a laboratory or computational experiment.',
+  ));
+  chado_associate_semweb_term('arraydesign', 'platformtype_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C25712',
+    'name' => 'Value',
+    'cv_name' => 'ncit',
+    'definition' => 'A numerical quantity measured or assigned or computed.',
+  ));
+  chado_associate_semweb_term(NULL, 'value', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C44170',
+    'name' => 'Channel',
+    'cv_name' => 'ncit',
+    'definition' => 'An independent acquisition scheme, i.e., a route or conduit through which flows data consisting of one particular measurement using one particular parameter.',
+  ));
+  chado_associate_semweb_term(NULL, 'channel_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C48697',
+    'name' => 'Controlled Vocabulary',
+    'cv_name' => 'ncit',
+    'definition' => 'A set of terms that are selected and defined based on the requirements set out by the user group, usually a set of vocabulary is chosen to promote consistency across data collection projects. [ NCI ]',
+  ));
+  chado_associate_semweb_term(NULL, 'cv_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C45559',
+    'name' => 'Term',
+    'cv_name' => 'ncit',
+    'definition' => 'A word or expression used for some particular thing. [ NCI ]',
+  ));
+  chado_associate_semweb_term(NULL, 'cvterm_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C80488',
+    'name' => 'Expression',
+    'cv_name' => 'ncit',
+    'definition' => 'A combination of symbols that represents a value. [ NCI ]',
+  ));
+  chado_associate_semweb_term(NULL, 'expression_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C16977',
+    'name' => 'Phenotype',
+    'cv_name' => 'ncit',
+    'definition' => 'The assemblage of traits or outward appearance of an individual. It is the product of interactions between genes and between genes and the environment. [ NCI ]',
+  ));
+  chado_associate_semweb_term(NULL, 'phenotype_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C16631',
+    'name' => 'Genotype',
+    'cv_name' => 'ncit',
+    'definition' => 'The genetic constitution of an organism or cell, as distinct from its expressed features or phenotype. [ NCI ]',
+  ));
+  chado_associate_semweb_term(NULL, 'genotype_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C25341',
+    'name' => 'Location',
+    'cv_name' => 'ncit',
+    'definition' => 'A position, site, or point in space where something can be found. [ NCI ]',
+  ));
+  chado_associate_semweb_term(NULL, 'nd_geolocation_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C802',
+    'name' => 'Reagent',
+    'cv_name' => 'ncit',
+    'definition' => 'Any natural or synthetic substance used in a chemical or biological reaction in order to produce, identify, or measure another substance. [ NCI ]',
+  ));
+  chado_associate_semweb_term(NULL, 'nd_reagent_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C16551',
+    'name' => 'Environment',
+    'cv_name' => 'ncit',
+    'definition' => 'The totality of surrounding conditions. [ NCI ]',
+  ));
+  chado_associate_semweb_term(NULL, 'environment_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C42765',
+    'name' => 'Tree Node',
+    'cv_name' => 'ncit',
+    'definition' => 'A term that refers to any individual item or entity in a hierarchy or pedigree. [ NCI ]',
+  ));
+  chado_associate_semweb_term(NULL, 'phylonode_id', $term);
+    
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C63536',
+    'name' => 'Study',
+    'cv_name' => 'ncit',
+    'definition' => 'A detailed examination, analysis, or critical inspection of a subject designed to discover facts about it. [ NCI ]',
+  ));
+  chado_associate_semweb_term(NULL, 'study_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C15320',
+    'name' => 'Study Design',
+    'cv_name' => '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 ]',
+  ));
+}
+
 /**
  * Adds the NCBI Taxon vocabulary database and terms.
  */
@@ -1662,7 +2030,7 @@ function tripal_chado_semweb_form($form, &$form_state, $chado_table = NULL) {
   $form['chado_table'] = array(
     '#type' => 'select',
     '#title' => 'Chado Table',
-    '#description' => t('Select a chado table to set web services terms used for its columns.'),
+    '#description' => t('Select a chado table to set vocabulary terms used for its columns.'),
     '#options' => $chado_tables,
     '#default_value' => $chado_table,
     '#ajax' => array(
@@ -1712,6 +2080,7 @@ function tripal_chado_semweb_form($form, &$form_state, $chado_table = NULL) {
         $sw_accession = '';
         if($cvterm_id) {
           $term = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
+          $term = chado_expand_var($term, 'field', 'cvterm.definition');
           $sw_voc = $term->cv_id->name;
           $sw_term = $term->name;
           $sw_accession = l($term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession,

+ 38 - 0
tripal_chado/tripal_chado.install

@@ -1513,4 +1513,42 @@ function tripal_chado_update_7324() {
   }
 }
 
+/**
+ * Adding additional vocabulary term mapping to Chado table columns.
+ */
+function tripal_chado_update_7325() {
+  try {
+    module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.semweb');
+    tripal_chado_populate_chado_semweb_table();
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: '. $error);
+  }
+}
+
+
+/**
+ * Adding a "Company" term.
+ */
+function tripal_chado_update_7326() {
+  try {
+    // 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 ]',
+    ));
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: '. $error);
+  }
+}
+
+