Quellcode durchsuchen

Merge branch '7.x-3.x' of github.com:tripal/tripal into 7.x-3.x

Chun-Huai Cheng vor 7 Jahren
Ursprung
Commit
946b7e3805
20 geänderte Dateien mit 550 neuen und 114 gelöschten Zeilen
  1. 10 3
      tripal/api/tripal.entities.api.inc
  2. 13 2
      tripal/includes/TripalJob.inc
  3. 187 0
      tripal/views_handlers/tripal_views_handler_filter_numeric.inc
  4. 14 8
      tripal_chado/api/modules/tripal_chado.cv.api.inc
  5. 2 1
      tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact_widget.inc
  6. 1 1
      tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_widget.inc
  7. 2 1
      tripal_chado/includes/TripalFields/data__accession/data__accession_widget.inc
  8. 0 2
      tripal_chado/includes/TripalFields/local__source_data/local__source_data.inc
  9. 29 5
      tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc
  10. 8 2
      tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_formatter.inc
  11. 16 5
      tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_widget.inc
  12. 2 1
      tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_widget.inc
  13. 2 1
      tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name_widget.inc
  14. 10 15
      tripal_chado/includes/TripalFields/sio__annotation/sio__annotation_widget.inc
  15. 92 6
      tripal_chado/includes/TripalFields/taxrank__infraspecific_taxon/taxrank__infraspecific_taxon.inc
  16. 16 0
      tripal_chado/includes/TripalFields/taxrank__infraspecific_taxon/taxrank__infraspecific_taxon_formatter.inc
  17. 74 14
      tripal_chado/includes/TripalFields/taxrank__infraspecific_taxon/taxrank__infraspecific_taxon_widget.inc
  18. 13 0
      tripal_chado/includes/tripal_chado.cv.inc
  19. 2 2
      tripal_chado/includes/tripal_chado.field_storage.inc
  20. 57 45
      tripal_chado/includes/tripal_chado.fields.inc

+ 10 - 3
tripal/api/tripal.entities.api.inc

@@ -1056,7 +1056,9 @@ function tripal_replace_entity_tokens($string, &$entity, $bundle_entity = NULL)
       // Note: there is a memory leak in field_get_items() so we can't use it
       // here or bulk publising will slowly erode memory.
       //$field_value = field_get_items('TripalEntity', $entity, $field_name);
-      $value = $entity->{$field_name}['und'][0]['value'];
+      if (array_key_exists(0, $entity->{$field_name}['und'])) {
+        $value = $entity->{$field_name}['und'][0]['value'];
+      }
       // TODO: deal with the value when it is not a scalar.
     }
     // The TripalBundle__bundle_id is a special token for substituting the
@@ -1076,8 +1078,13 @@ function tripal_replace_entity_tokens($string, &$entity, $bundle_entity = NULL)
       $value = $entity->id;
     }
 
-    // Perform the replacement of the token with the value.
-    $string = str_replace($token, $value, $string);
+    // We can't support tokens that have multiple elements (i.e. in an array).
+    if (is_array($value)) {
+      $string = str_replace($token, '', $string);
+    }
+    else {
+      $string = str_replace($token, $value, $string);
+    }
   }
 
   return $string;

+ 13 - 2
tripal/includes/TripalJob.inc

@@ -115,8 +115,19 @@ class TripalJob {
     }
 
     $includes = $details['includes'];
-    foreach ($includes as $include) {
-      require_once($include);
+    foreach ($includes as $path) {
+      $full_path = $_SERVER['DOCUMENT_ROOT'] . base_path() . $path;
+      if (!empty($path)) {
+        if (file_exists($path)) {
+          require_once($path);
+        }
+        elseif (file_exists($full_path)) {
+          require_once($path);
+        }
+        elseif (!empty($path)) {
+          throw new Exception("Included files for Tripal Job must exist. This path ($full_path) doesn't exist.");
+        }
+      }
     }
     if (!function_exists($details['callback'])) {
       throw new Exception("Must provide a valid callback function to the tripal_add_job() function.");

+ 187 - 0
tripal/views_handlers/tripal_views_handler_filter_numeric.inc

@@ -0,0 +1,187 @@
+<?php
+
+class tripal_views_handler_filter_numeric extends tripal_views_handler_filter {
+
+  var $always_multiple = TRUE;
+
+  function operators() {
+    $operators = array(
+      '<' => array(
+        'title' => t('Is less than'),
+        'method' => 'op_simple',
+        'short' => t('<'),
+        'values' => 1,
+      ),
+      '<=' => array(
+        'title' => t('Is less than or equal to'),
+        'method' => 'op_simple',
+        'short' => t('<='),
+        'values' => 1,
+      ),
+      '=' => array(
+        'title' => t('Is equal to'),
+        'method' => 'op_simple',
+        'short' => t('='),
+        'values' => 1,
+      ),
+      '!=' => array(
+        'title' => t('Is not equal to'),
+        'method' => 'op_simple',
+        'short' => t('!='),
+        'values' => 1,
+      ),
+      '>=' => array(
+        'title' => t('Is greater than or equal to'),
+        'method' => 'op_simple',
+        'short' => t('>='),
+        'values' => 1,
+      ),
+      '>' => array(
+        'title' => t('Is greater than'),
+        'method' => 'op_simple',
+        'short' => t('>'),
+        'values' => 1,
+      ),
+    );
+
+    return $operators;
+  }
+
+
+  function op_simple($field) {
+    $this->query->add_where($this->options['group'], $field, $this->value, $this->operator);
+  }
+
+  function op_empty($field) {
+    if ($this->operator == 'empty') {
+      $operator = "IS NULL";
+    }
+    else {
+      $operator = "IS NOT NULL";
+    }
+
+    $this->query->add_where($this->options['group'], $field, NULL, $operator);
+  }
+
+
+
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['expose']['contains']['required'] = array('default' => FALSE, 'bool' => TRUE);
+
+    return $options;
+  }
+
+  /**
+   * Build strings from the operators() for 'select' options
+   */
+  function operator_options($which = 'title') {
+    $options = array();
+    foreach ($this->operators() as $id => $info) {
+      $options[$id] = $info[$which];
+    }
+
+    return $options;
+  }
+
+  function admin_summary() {
+    if ($this->is_a_group()) {
+      return t('grouped');
+    }
+    if (!empty($this->options['exposed'])) {
+      return t('exposed');
+    }
+
+    $options = $this->operator_options('short');
+    $output = '';
+    if (!empty($options[$this->operator])) {
+      $output = check_plain($options[$this->operator]);
+    }
+    if (in_array($this->operator, $this->operator_values(1))) {
+      $output .= ' ' . check_plain($this->value);
+    }
+    return $output;
+  }
+
+  function operator_values($values = 1) {
+    $options = array();
+    foreach ($this->operators() as $id => $info) {
+      if (isset($info['values']) && $info['values'] == $values) {
+        $options[] = $id;
+      }
+    }
+
+    return $options;
+  }
+
+  /**
+   * Provide a simple textfield for equality
+   */
+  function value_form(&$form, &$form_state) {
+
+    // We have to make some choices when creating this as an exposed
+    // filter form. For example, if the operator is locked and thus
+    // not rendered, we can't render dependencies; instead we only
+    // render the form items we need.
+    $which = 'all';
+    if (!empty($form['operator'])) {
+      $source = ($form['operator']['#type'] == 'radios') ? 'radio:options[operator]' : 'edit-options-operator';
+    }
+    if (!empty($form_state['exposed'])) {
+      $identifier = $this->options['expose']['identifier'];
+
+      if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator_id'])) {
+        // exposed and locked.
+        $which = in_array($this->operator, $this->operator_values(1)) ? 'value' : 'none';
+      }
+      else {
+        $source = 'edit-' . drupal_html_id($this->options['expose']['operator_id']);
+      }
+    }
+
+    if ($which == 'all' || $which == 'value') {
+      $form['value'] = array(
+        '#type' => 'textfield',
+        '#title' => t('Value'),
+        '#size' => 30,
+        '#default_value' => $this->value,
+      );
+      if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
+        $form_state['input'][$identifier] = $this->value;
+      }
+
+      if ($which == 'all') {
+        $form['value'] += array(
+          '#dependency' => array($source => $this->operator_values(1)),
+        );
+      }
+    }
+
+    if (!isset($form['value'])) {
+      // Ensure there is something in the 'value'.
+      $form['value'] = array(
+        '#type' => 'value',
+        '#value' => NULL
+      );
+    }
+  }
+
+  function operator() {
+    return $this->operator == '=' ? 'LIKE' : 'NOT LIKE';
+  }
+
+  /**
+   * Add this filter to the query.
+   */
+  function query() {
+    $this->ensure_my_table();
+    $field = "$this->table_alias.$this->real_field";
+
+    $info = $this->operators();
+    if (!empty($info[$this->operator]['method'])) {
+      $op_function = $info[$this->operator]['method'];
+      $this->{$op_function}($field);
+    }
+  }
+}

+ 14 - 8
tripal_chado/api/modules/tripal_chado.cv.api.inc

@@ -1239,7 +1239,7 @@ function tripal_submit_obo_job($obo) {
   $obo['file']   = (isset($obo['file']))   ? $obo['file']   : NULL;
 
   $includes = array(
-    module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.obo_loader'),
+    drupal_get_path('module', 'tripal_chado') . '/includes/tripal_chado.cv.inc',
   );
 
   if ($obo['obo_id']) {
@@ -1248,18 +1248,24 @@ function tripal_submit_obo_job($obo) {
 
     $args = array($result->obo_id);
     return tripal_add_job("Load OBO " . $result->name, 'tripal_chado',
-       "tripal_chado_load_obo_v1_2_id", $args, $user->uid, 10, $includes);
+       "tripal_cv_load_obo", $args, $user->uid, 10, $includes);
   }
   else {
     if ($obo['url']) {
-      $args = array($obo['name'], $obo['url']);
-      return tripal_add_job("Load OBO " . $obo['name'], 'tripal_chado',
-        "tripal_chado_load_obo_v1_2_url", $args, $user->uid, 10, $includes);
+      $sql = "SELECT * FROM {tripal_cv_obo} WHERE path = :url";
+      $result = db_query($sql, array(':url' => $obo['url']))->fetchObject();
+
+      $args = array($result->obo_id);
+      return tripal_add_job("Load OBO " . $result->name, 'tripal_chado',
+        "tripal_cv_load_obo", $args, $user->uid, 10, $includes);
     }
     elseif ($obo['file']) {
-      $args = array($obo['name'], $obo['file']);
-      return tripal_add_job("Load OBO " . $obo['name'], 'tripal_chado',
-        "tripal_chado_load_obo_v1_2_file", $args, $user->uid, 10, $includes);
+      $sql = "SELECT * FROM {tripal_cv_obo} WHERE path = :file";
+      $result = db_query($sql, array(':url' => $obo['file']))->fetchObject();
+
+      $args = array($result->obo_id);
+      return tripal_add_job("Load OBO " . $result->name, 'tripal_chado',
+        "tripal_cv_load_obo", $args, $user->uid, 10, $includes);
     }
   }
   return FALSE;

+ 2 - 1
tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact_widget.inc

@@ -46,7 +46,8 @@ class chado_linker__contact_widget extends ChadoFieldWidget {
     }
 
     // Check $form_state['values'] to see if an AJAX call set the values.
-    if (array_key_exists('values', $form_state) and array_key_exists($delta, $form_state['values'])) {
+    if (array_key_exists('values', $form_state) and
+        array_key_exists($field_name, $form_state['values'])) {
       $name = $form_state['values'][$field_name]['und'][$delta]['name'];
     }
 

+ 1 - 1
tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_widget.inc

@@ -50,7 +50,7 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
 
     // Check $form_state['values'] to see if an AJAX call set the values.
     if (array_key_exists('values', $form_state) and
-        array_key_exists($delta, $form_state['values'])) {
+        array_key_exists($field_name, $form_state['values'])) {
       $record_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $pkey];
       $fk_value = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $lfkey_field];
       $type_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__type_id'];

+ 2 - 1
tripal_chado/includes/TripalFields/data__accession/data__accession_widget.inc

@@ -31,7 +31,8 @@ class data__accession_widget extends ChadoFieldWidget {
     }
 
     // Check $form_state['values'] to see if an AJAX call set the values.
-    if (array_key_exists('values', $form_state)) {
+    if (array_key_exists('values', $form_state) and
+        array_key_exists($field_name, $form_state['values'])) {
       $dbxref_id = isset($form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $field_column]) ? $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $field_column] : '';
       $db_id = isset($form_state['values'][$field_name]['und'][$delta]['db_id']) ? $form_state['values'][$field_name]['und'][$delta]['db_id'] : '';
       $accession = isset($form_state['values'][$field_name]['und'][$delta]['accession']) ? $form_state['values'][$field_name]['und'][$delta]['accession'] : '';

+ 0 - 2
tripal_chado/includes/TripalFields/local__source_data/local__source_data.inc

@@ -121,8 +121,6 @@ class local__source_data extends ChadoField {
     $sourceversion_term = $field_term_id . ',' . tripal_get_chado_semweb_term('analysis', 'sourceversion');
     $sourceuri_term = $field_term_id . ',' . tripal_get_chado_semweb_term('analysis', 'sourceuri');
 
-    dpm($order);
-    dpm($sourceversion_term);
     if ($order['column'] == $sourcename_term) {
       $query->orderBy("base.sourcename", $order['direction']);
     }

+ 29 - 5
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc

@@ -70,24 +70,25 @@ class sbo__database_cross_reference extends ChadoField {
     return array(
       $field_term => array(
         'operations' => array(),
+        'label' => 'Cross Reference',
         'sortable' => FALSE,
         'searchable' => FALSE,
         'elements' => array(
           $dbname_term => array(
             'searchable' => TRUE,
-            'label' => 'Database Name',
+            'label' => 'Cross Reference Database Name',
             'help' => 'The name of the remote database that houses the cross reference.',
             'sortable' => TRUE,
           ),
           $accession_term => array(
             'searchable' => TRUE,
-            'label' => 'Database Accession',
+            'label' => 'Cross Reference Database Accession',
             'help' => 'The unique accession (identifier) in the database that houses the cross reference.',
             'sortable' => TRUE,
           ),
           $dburl_term => array(
             'searchable' => FALSE,
-            'label' => 'Database URL',
+            'label' => 'Cross Reference Database URL',
             'help' => 'The URL of the database that houses the cross reference.',
             'sortable' => FALSE,
           ),
@@ -182,11 +183,11 @@ class sbo__database_cross_reference extends ChadoField {
     $this->queryJoinOnce($query, 'dbxref', $alias . '_DBX', $alias . "_DBX.dbxref_id = $alias.dbxref_id");
 
     if ($condition['column'] == $dbname_term) {
-      $this->queryJoinOnce($query, $alias . '_DB', $alias . "_DB.db_id = " . $alias . "_DBX.db_id");
+      $this->queryJoinOnce($query, 'db', $alias . '_DB', $alias . "_DB.db_id = " . $alias . "_DBX.db_id");
       $query->condition($alias . "_DB.name", $condition['value'], $operator);
     }
     if ($condition['column'] == $accession_term) {
-      $query->condition($alias . "_DBX.dbxref", $condition['value'], $operator);
+      $query->condition($alias . "_DBX.accession", $condition['value'], $operator);
     }
   }
 
@@ -194,7 +195,30 @@ class sbo__database_cross_reference extends ChadoField {
    * @see ChadoField::queryOrder()
    */
   public function queryOrder($query, $order) {
+    $dbxref_linker = $this->instance['settings']['chado_table'];
+    $base_table = $this->instance['settings']['base_table'];
+    $field_table = $this->instance['settings']['chado_table'];
+
+    $bschema = chado_get_schema($base_table);
+    $bpkey = $bschema['primary key'][0];
+
+    $alias = $this->field['field_name'];
 
+    $field_term_id = $this->getFieldTermID();
+    $dbname_term = $field_term_id . ',' . tripal_get_chado_semweb_term('db', 'name');
+    $accession_term = $field_term_id . ',' . tripal_get_chado_semweb_term('dbxref', 'accession');
+    $dburl_term = $field_term_id . ',' . tripal_get_chado_semweb_term('db', 'url');
+
+    $this->queryJoinOnce($query, $field_table, $alias, "base.$bpkey = $alias.$bpkey", "LEFT OUTER");
+    $this->queryJoinOnce($query, 'dbxref', $alias . '_DBX', $alias . "_DBX.dbxref_id = $alias.dbxref_id", "LEFT OUTER");
+
+    if ($order['column'] == $dbname_term) {
+      $this->queryJoinOnce($query, 'db', $alias . '_DB', $alias . "_DB.db_id = " . $alias . "_DBX.db_id", "LEFT OUTER");
+      $query->orderBy($alias . "_DB.name", $order['direction']);
+    }
+    if ($order['column'] == $accession_term) {
+      $query->orderBy($alias . "_DBX.accession", $order['direction']);
+    }
   }
 
   /**

+ 8 - 2
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_formatter.inc

@@ -12,9 +12,15 @@ class sbo__database_cross_reference_formatter extends ChadoFieldFormatter {
    * @see TripalFieldFormatter::view()
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
-    $chado_table = $this->instance['settings']['chado_table'];
     $content = '';
 
+    $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'];
+    $base_table = $this->instance['settings']['base_table'];
+    $linker_table = $base_table . '_dbxref';
+
     $dbname_term = tripal_get_chado_semweb_term('db', 'name');
     $accession_term = tripal_get_chado_semweb_term('dbxref', 'accession');
     $dburl_term = tripal_get_chado_semweb_term('db', 'url');
@@ -25,7 +31,7 @@ class sbo__database_cross_reference_formatter extends ChadoFieldFormatter {
       }
       $content = $item['value'][$dbname_term] . ':' . $item['value'][$accession_term];
       if ($item['value'][$dburl_term]) {
-        $dbxref = tripal_get_dbxref(array('dbxref_id' => $item['chado-feature_dbxref__dbxref_id']));
+        $dbxref = tripal_get_dbxref(array('dbxref_id' => $item['chado-' . $linker_table . '__dbxref_id']));
         $url = tripal_get_dbxref_url($dbxref);
         $content = l($content, $url, array('attributes' => array('target' => '_blank')));
       }

+ 16 - 5
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_widget.inc

@@ -44,7 +44,7 @@ class sbo__database_cross_reference_widget extends ChadoFieldWidget {
 
     // Check $form_state['values'] to see if an AJAX call set the values.
     if (array_key_exists('values', $form_state) and
-        array_key_exists($delta, $form_state['values'])) {
+        array_key_exists($field_name, $form_state['values'])) {
       $record_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $pkey];
       $fkey_value = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $fkey];
       $dbxref_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__dbxref_id'];
@@ -164,8 +164,19 @@ class sbo__database_cross_reference_widget extends ChadoFieldWidget {
  * An Ajax callback for the dbxref widget.
  */
 function sbo__database_cross_reference_widget_form_ajax_callback($form, $form_state) {
-
-  $field_name = $form_state['triggering_element']['#parents'][0];
-
-  return $form[$field_name]['und'][$delta];
+  // Get the triggering element
+  $form_element_name = $form_state['triggering_element']['#name'];
+  preg_match('/(.+?)\[(.+?)\]\[(.+?)\]/', $form_element_name, $matches);
+  $field = $matches[1];
+  $lang = $matches[2];
+  $delta = $matches[3];
+
+  // Return the widget that triggered the AJAX call
+  if (isset($form[$field][$lang][$delta])) {
+    return $form[$field][$lang][$delta];
+  }
+  // Alternatively, return the default value widget for the widget setting form
+  else {
+    return $form['instance']['default_value_widget'][$field];
+  }
 }

+ 2 - 1
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_widget.inc

@@ -103,7 +103,8 @@ class sbo__relationship_widget extends ChadoFieldWidget {
     }
 
     // Check $form_state['values'] to see if an AJAX call set the values.
-    if (array_key_exists('values', $form_state) and array_key_exists($delta, $form_state['values'])) {
+    if (array_key_exists('values', $form_state) and
+        array_key_exists($field_name, $form_state['values'])) {
       $record_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $pkey];
       $subject_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $subject_id_key];
       $object_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $object_id_key];

+ 2 - 1
tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name_widget.inc

@@ -47,7 +47,8 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
     }
 
     // Check $form_state['values'] to see if an AJAX call set the values.
-    if (array_key_exists('values', $form_state) and array_key_exists($delta, $form_state['values'])) {
+    if (array_key_exists('values', $form_state) and
+        array_key_exists($field_name, $form_state['values'])) {
       $record_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__' . $pkey];
       $synonym_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__synonym_id'];
       $pub_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'];

+ 10 - 15
tripal_chado/includes/TripalFields/sio__annotation/sio__annotation_widget.inc

@@ -69,27 +69,22 @@ class sio__annotation_widget extends ChadoFieldWidget {
     }
 
     // Check $form_state['values'] to see if an AJAX call set the values.
-    if ((array_key_exists('values', $form_state) and array_key_exists($field_name, $form_state['values'])) or
-        (array_key_exists('input', $form_state) and array_key_exists($field_name, $form_state['input']))) {
+    if (array_key_exists('values', $form_state) and
+        array_key_exists($field_name, $form_state['values'])) {
 
-      $vtype = 'input';
-      if (array_key_exists('values', $form_state)) {
-        $vtype = 'values';
-      }
-
-      $record_id = $form_state[$vtype][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $pkey];
-      $fk_value = $form_state[$vtype][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $fkey_lcolumn];
-      $cvterm_id = $form_state[$vtype][$field_name]['und'][$delta]['chado-' . $field_table . '__cvterm_id'];
+      $record_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $pkey];
+      $fk_value = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $fkey_lcolumn];
+      $cvterm_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__cvterm_id'];
 
       if (array_key_exists('pub_id', $schema['fields'])) {
-        $pub_name = $form_state[$vtype][$field_name]['und'][$delta]['pub'];
-        $pub_id = $form_state[$vtype][$field_name]['und'][$delta]['chado-' . $field_table . '__pub_id'];
+        $pub_name = $form_state['values'][$field_name]['und'][$delta]['pub'];
+        $pub_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__pub_id'];
       }
       if (array_key_exists('is_not', $schema['fields'])) {
-        $is_not = $form_state[$vtype][$field_name]['und'][$delta]['chado-' . $field_table . '__is_not'];
+        $is_not = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__is_not'];
       }
-      $cvterm_name = $form_state[$vtype][$field_name]['und'][$delta]['cvterm_name'];
-      $cv_id = $form_state[$vtype][$field_name]['und'][$delta]['cv_id'];
+      $cvterm_name = $form_state['values'][$field_name]['und'][$delta]['cvterm_name'];
+      $cv_id = $form_state['values'][$field_name]['und'][$delta]['cv_id'];
       $cvterm = chado_generate_var('cvterm', array(
         'cv_id' => $cv_id,
         'name' => $cvterm_name,

+ 92 - 6
tripal_chado/includes/TripalFields/taxrank__infraspecific_taxon/taxrank__infraspecific_taxon.inc

@@ -59,15 +59,83 @@ class taxrank__infraspecific_taxon extends ChadoField {
    */
   public function elementInfo() {
     $field_term = $this->getFieldTermID();
+
+    $label_term = 'rdfs:label';
+    $infraspecific_name_term = tripal_get_chado_semweb_term('organism', 'infraspecific_name');
+    $infraspecific_type_term = tripal_get_chado_semweb_term('organism', 'type_id');
+
     return array(
       $field_term => array(
-        'operations' => array(),
         'sortable' => FALSE,
-        'searchable' => FALSE,
+        'searchable' => TRUE,
+        'elements' => array(
+          $label_term => array(
+            'sortable' => FALSE,
+            'searchable' => TRUE,
+            'label' => 'Infraspecific Full Name',
+            'help' => 'The full infraspecific name including the rank and name.',
+          ),
+          $infraspecific_name_term => array(
+            'sortable' => TRUE,
+            'searchable' => TRUE,
+            'label' => 'Infrasepcies Name',
+            'help' => 'The infraspecific name of the organism below the rank of species.',
+          ),
+          $infraspecific_type_term => array(
+            'sortable' => TRUE,
+            'searchable' => TRUE,
+            'label' => 'Infraspecific Rank',
+            'help' => 'The infraspecific rank of the organism below the rank of species.',
+          ),
+        )
       ),
     );
   }
 
+  /**
+   * @see ChadoField::query()
+   */
+  public function query($query, $condition){
+    $alias = $this->field['field_name'];
+    $operator = $condition['operator'];
+
+    $field_term_id = $this->getFieldTermID();
+    $label_term = $field_term_id . ',' . 'rdfs:label';
+    $infraspecific_name_term = $field_term_id . ',' . tripal_get_chado_semweb_term('organism', 'infraspecific_name');
+    $infraspecific_type_term = $field_term_id . ',' . tripal_get_chado_semweb_term('organism', 'type_id');
+
+    if ($condition['column'] == $label_term or $condition['column'] == $field_term_id) {
+      $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . "_cvterm.cvterm_id = base.type_id");
+      $query->where("CONCAT(" . $alias . "_cvterm.name, ' ', base.infraspecific_name) $operator :full_name",  array(':full_name' => $condition['value']));
+    }
+    if ($condition['column'] == $infraspecific_name_term) {
+      $query->condition('base.infraspecific_name', $condition['value'], $operator);
+    }
+    if ($condition['column'] == $infraspecific_type_term) {
+      $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . "_cvterm.cvterm_id = base.type_id");
+      $query->condition($alias . '_cvterm.name', $condition['value'], $operator);
+    }
+  }
+  /**
+   * @see ChadoField::queryOrder()
+   */
+  public function queryOrder($query, $order) {
+    $alias = $this->field['field_name'];
+
+    $field_term_id = $this->getFieldTermID();
+    $label_term = $field_term_id . ',' . 'rdfs:label';
+    $infraspecific_name_term = $field_term_id . ',' . tripal_get_chado_semweb_term('organism', 'infraspecific_name');
+    $infraspecific_type_term = $field_term_id . ',' . tripal_get_chado_semweb_term('organism', 'type_id');
+
+    if ($order['column'] == $infraspecific_name_term) {
+      $query->orderBy('base.infraspecific_name', $order['direction']);
+    }
+    if ($order['column'] == $infraspecific_type_term) {
+      $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . "_cvterm.cvterm_id = base.type_id", "LEFT OUTER");
+      $query->orderBy($alias . '_cvterm.name', $order['direction']);
+    }
+  }
+
   /**
    *
    * @see TripalField::load()
@@ -81,15 +149,33 @@ class taxrank__infraspecific_taxon extends ChadoField {
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
 
+    $entity->{$field_name}['und'][0]['value'] = '';
+
+    if (chado_get_version() < 1.3) {
+      return;
+    }
+
+    $label_term = 'rdfs:label';
+    $infraspecific_name_term = tripal_get_chado_semweb_term('organism', 'infraspecific_name');
+    $infraspecific_type_term = tripal_get_chado_semweb_term('organism', 'type_id');
+
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = array(
-      'value' => '',
-      'organism__type_id' => '',
+      'value' => array(),
+      'chado-organism__infraspecific_name' => '',
+      'chado-organism__type_id' => '',
     );
 
+    if ($record->infraspecific_name) {
+      $label = $record->type_id->name . ' ' . $record->infraspecific_name;
+      $entity->{$field_name}['und'][0]['value'][$label_term] = $label;
+      $entity->{$field_name}['und'][0]['value'][$infraspecific_name_term] = $record->infraspecific_name;
+      $entity->{$field_name}['und'][0]['chado-organism__infraspecific_name'] = $record->infraspecific_name;
+    }
+
     if ($record->type_id) {
-      $entity->{$field_name}['und'][0]['value'] = $record->type_id->name;
-      $entity->{$field_name}['und'][0]['organism__type_id'] = $record->type_id->cvterm_id;
+      $entity->{$field_name}['und'][0]['value'][$infraspecific_type_term] = $record->type_id->name;
+      $entity->{$field_name}['und'][0]['chado-organism__type_id'] = $record->type_id->cvterm_id;
     }
   }
 }

+ 16 - 0
tripal_chado/includes/TripalFields/taxrank__infraspecific_taxon/taxrank__infraspecific_taxon_formatter.inc

@@ -13,5 +13,21 @@ class taxrank__infraspecific_taxon_formatter extends ChadoFieldFormatter {
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
 
+    $label_term = 'rdfs:label';
+    $infraspecific_name_term = tripal_get_chado_semweb_term('organism', 'infraspecific_name');
+    $infraspecific_type_term = tripal_get_chado_semweb_term('organism', 'type_id');
+
+    if (is_array($items[0]['value']) and array_key_exists($infraspecific_name_term, $items[0]['value'])) {
+      $infraspecific_name = $items[0]['value'][$infraspecific_name_term];
+      $infraspecific_type = $items[0]['value'][$infraspecific_type_term];
+      $content = $items[0]['value'][$label_term];
+
+      // The cardinality of this field is 1 so we don't have to
+      // iterate through the items array, as there will never be more than 1.
+      $element[0] = array(
+        '#type' => 'markup',
+        '#markup' => $content,
+      );
+    }
   }
 }

+ 74 - 14
tripal_chado/includes/TripalFields/taxrank__infraspecific_taxon/taxrank__infraspecific_taxon_widget.inc

@@ -7,50 +7,110 @@ class taxrank__infraspecific_taxon_widget extends ChadoFieldWidget {
   // The list of field types for which this formatter is appropriate.
   public static $field_types = array('taxrank__infraspecific_taxon');
 
+
   /**
    *
    * @see TripalFieldWidget::form()
    */
   public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
+
     $settings = $this->field['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'];
 
+    $infra_name = '';
     $type_id = 0;
-    if (count($items) > 0 and array_key_exists('organism__type_id', $items[0])) {
-      $type_id = $items[0]['organism__type_id'];
+
+    if (count($items) > 0) {
+      $type_id = array_key_exists('chado-organism__type_id', $items[0]) ? $items[0]['chado-organism__type_id'] : $type_id;
+      $infra_name = array_key_exists('chado-organism__infraspecific_name', $items[0]) ? $items[0]['chado-organism__infraspecific_name'] : $infra_name;
     }
 
-    $form['value'] = array(
+    if (array_key_exists('values', $form_state) and
+        array_key_exists($field_name, $form_state['values'])) {
+      $type_id = $form_state['values'][$field_name][$langcode][$delta]['infraname']['specific_epithet'];
+      $infra_name = $form_state['values'][$field_name][$langcode][$delta]['infraname']['infrapsecific_epithet'];
+    }
+
+    $widget['value'] = array(
       '#type' => 'value',
       '#value' =>  array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
     );
+    $widget['chado-organism__type_id'] = array(
+      '#type' => 'value',
+      '#value' =>  $type_id,
+    );
+    $widget['chado-organism__infraspecific_name'] = array(
+      '#type' => 'value',
+      '#value' =>  $infra_name,
+    );
 
-    $cv = tripal_get_default_cv($field_table, $field_column);
+    $cv = tripal_get_cv(array('name' => 'taxonomic_rank'));
+    $terms = tripal_get_cvterm_select_options($cv->cv_id);
+
+    // Unfortunately the taxonomic_rank vocabulary is not properly organized
+    // such that we an only include terms below 'species'. Therefore we will
+    // just list them here and hope we haven't missed one.
+    $valid_terms = array('cultivar', 'subspecies', 'varietas', 'subvariety', 'forma', 'subforma');
     $options = array();
-    if ($cv) {
-      $options = tripal_get_cvterm_select_options($cv->cv_id);
+    $options[] = '--Select a rank--';
+    foreach  ($terms as $cvterm_id => $name) {
+      if (in_array($name, $valid_terms)) {
+        $options[$cvterm_id] = $name;
+      }
     }
-    $widget['organism__type_id'] = array(
-      '#type' => 'select',
+
+    $widget['infraname'] = array(
+      '#type' => 'fieldset',
       '#title' => $element['#title'],
-      '#description' => $element['#description'],
+      '#collapsible' => FALSE,
+      '#collapsed' => FALSE,
+      '#description' => $element['#description']
+    );
+    $widget['infraname']['specific_epithet'] = array(
+      '#type' => 'select',
+      '#title' => 'Specific Epithet',
+      '#description' => 'The rank below species. This field may be left blank if not appropriate.',
       '#options' => $options,
       '#default_value' => $type_id,
+    );
+    $widget['infraname']['infrapsecific_epithet'] = array(
+      '#type' => 'textfield',
+      '#title' => 'Infrapsecific Epithet',
+      '#description' => 'The name below species.',
+      '#default_value' => $infra_name,
       '#required' => $element['#required'],
-      '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
-      '#delta' => $delta,
     );
   }
 
   /**
-   *
-   * @see TripalFieldWidget::submit()
+   * @see TripalFieldWidget::validate()
    */
-  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+  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'];
+
+    $type_id = $form_state['values'][$field_name]['und'][0]['infraname']['specific_epithet'];
+    $infra_name = $form_state['values'][$field_name]['und'][0]['infraname']['infrapsecific_epithet'];
+
+    if ($infra_name and $type_id) {
+      $form_state['values'][$field_name]['und'][0]['value'] = $infra_name;
+      $form_state['values'][$field_name]['und'][0]['chado-organism__type_id'] = $type_id;
+      $form_state['values'][$field_name]['und'][0]['chado-organism__infraspecific_name'] = $infra_name;
+    }
+    if ($infra_name and !$type_id) {
+      $form_state['values'][$field_name]['und'][0]['value'] = $infra_name;
+      $form_state['values'][$field_name]['und'][0]['chado-organism__type_id'] = '__NULL__';
+      $form_state['values'][$field_name]['und'][0]['chado-organism__infraspecific_name'] = $infra_name;
+    }
+    else {
+      $form_state['values'][$field_name]['und'][0]['chado-organism__type_id'] = '__NULL__';
+      $form_state['values'][$field_name]['und'][0]['chado-organism__infraspecific_name'] = '__NULL__';
+    }
 
   }
 }

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

@@ -1,4 +1,17 @@
 <?php
+
+/**
+ * Loads an OBO File using the new TripalImporter. Expected to be run by a Tripal Job.
+ */
+function tripal_cv_load_obo($obo_id) {
+
+  module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/OBOImporter');
+  $obo_importer = new OBOImporter();
+  $obo_importer->create(array('obo_id' => $obo_id));
+  $obo_importer->run();
+
+}
+
 /**
  * Provide landing page to the new admin pages
  *

+ 2 - 2
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -628,8 +628,8 @@ function tripal_chado_field_storage_query($query) {
     } // end if ($sort['type'] == 'field') {
   } // end foreach ($query->order as $index => $sort) {
 
-     dpm($cquery->__toString());
-     dpm($cquery->getArguments());
+      dpm($cquery->__toString());
+      dpm($cquery->getArguments());
 
   $records = $cquery->execute();
 

+ 57 - 45
tripal_chado/includes/tripal_chado.fields.inc

@@ -70,6 +70,13 @@ function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $b
       continue;
     }
 
+    // Skip the infraspecific type_id and name from the organism table as we
+    // have a special field for those.
+    if ($table_name == 'organism' and ($column_name == 'type_id' or
+        $column_name == 'infraspecific_name')) {
+      continue;
+    }
+
     // Skip the cvterm.is_relationshptype.
     if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
       continue;
@@ -342,21 +349,19 @@ function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type,
   }
 
   // ORGANISM TYPE_ID
-//   if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
-//     $field_name = 'taxarank__infraspecific_taxon';
-//     $field_type = 'taxarank__infraspecific_taxon';
-//     $info[$field_name] = array(
-//       'field_name' => $field_name,
-//       'type' => $field_type,
-//       'cardinality' => 1,
-//       'locked' => FALSE,
-//       'storage' => array(
-//         'type' => 'field_chado_storage',
-//       ),
-//       'settings' => array(
-//       ),
-//     );
-//   }
+  if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
+    $field_name = 'taxrank__infraspecific_taxon';
+    $field_type = 'taxrank__infraspecific_taxon';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'type' => $field_type,
+      'cardinality' => 1,
+      'locked' => FALSE,
+      'storage' => array(
+        'type' => 'field_chado_storage',
+      ),
+    );
+  }
 
   // FEATUREMAP UNITTYPE_ID
   if ($table_name == 'featuremap') {
@@ -723,6 +728,13 @@ function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle,
       continue;
     }
 
+    // Skip the infraspecific type_id and name from the organism table as we
+    // have a special field for those.
+    if ($table_name == 'organism' and ($column_name == 'type_id' or
+        $column_name == 'infraspecific_name')) {
+          continue;
+        }
+
     // Don't create base fields for the primary key and the type_id field.
     if ($column_name == $pkey or $column_name == $type_column) {
       continue;
@@ -1267,36 +1279,36 @@ function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle
   }
 
   // ORGANISM TYPE_ID
-//   if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
-//     $field_name = 'taxarank__infraspecific_taxon';
-//     $info[$field_name] = array(
-//       'field_name' => $field_name,
-//       'entity_type' => $entity_type,
-//       'bundle' => $bundle->name,
-//       'label' => 'Infraspecific Taxon',
-//       'description' => 'The Infraspecific Taxon.',
-//       'required' => FALSE,
-//       'settings' => array(
-//         'auto_attach' => TRUE,
-//         'chado_table' => 'organism',
-//         'chado_column' => 'type_id',
-//         'base_table' => 'organism',
-//       ),
-//       'widget' => array(
-//         'type' => 'taxarank__infraspecific_taxon_widget',
-//         'settings' => array(
-//           'display_label' => 1,
-//         ),
-//       ),
-//       'display' => array(
-//         'default' => array(
-//           'label' => 'inline',
-//           'type' => 'taxarank__infraspecific_taxon_formatter',
-//           'settings' => array(),
-//         ),
-//       ),
-//     );
-//   }
+  if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
+    $field_name = 'taxrank__infraspecific_taxon';
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'entity_type' => $entity_type,
+      'bundle' => $bundle->name,
+      'label' => 'Infraspecific Taxon',
+      'description' => 'The Infraspecific Taxon.',
+      'required' => FALSE,
+      'settings' => array(
+        'auto_attach' => TRUE,
+        'chado_table' => 'organism',
+        'chado_column' => 'type_id',
+        'base_table' => 'organism',
+      ),
+      'widget' => array(
+        'type' => 'taxrank__infraspecific_taxon_widget',
+        'settings' => array(
+          'display_label' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'inline',
+          'type' => 'taxrank__infraspecific_taxon_formatter',
+          'settings' => array(),
+        ),
+      ),
+    );
+  }
 
 
   // FEATURE SEQLEN