Browse Source

Added query() function to many of the ChadoFields

Stephen Ficklin 8 years ago
parent
commit
a4e7b2e76e

+ 26 - 10
tripal_chado/api/modules/tripal_chado.pub.api.inc

@@ -1000,6 +1000,9 @@ function tripal_pub_create_citation($pub) {
 /**
  * Retrieves the minimal information to uniquely describe any publication.
  *
+ * The returned array is an associative array where the keys are
+ * the controlled vocabulary terms in the form [vocab]:[accession]
+ *
  * @param $pub
  *   A publication object as created by chado_generate_var()
  *
@@ -1054,7 +1057,7 @@ function tripal_get_minimal_pub_info($pub) {
     $abstract_text = htmlspecialchars($abstract->value);
   }
 
-  // get the author list
+  // Get the author list.
   $values = array(
     'pub_id' => $pub->pub_id,
     'type_id' => array(
@@ -1072,7 +1075,7 @@ function tripal_get_minimal_pub_info($pub) {
     $authors_list = $authors->value;
   }
 
-  // get the first database cross-reference with a url
+  // get the first database cross-reference with a url.
   $options = array('return_array' => 1);
   $pub = chado_expand_var($pub, 'table', 'pub_dbxref', $options);
   $dbxref = NULL;
@@ -1084,15 +1087,13 @@ function tripal_get_minimal_pub_info($pub) {
     }
   }
 
-  // get the URL
-  // get the author list
+  // get the URL.
   $values = array(
     'pub_id' => $pub->pub_id,
     'type_id' => array(
       'name' => 'URL',
     ),
   );
-
   $options = array(
     'return_array' => 1,
     'include_fk' => array(),
@@ -1105,11 +1106,26 @@ function tripal_get_minimal_pub_info($pub) {
       $url = $urls[0]->value;
     }
   }
+
+  // Get the list of database cross references.
+  $values = array(
+    'pub_id' => $pub->pub_id,
+  );
+  $options = array(
+    'return_array' => 1,
+  );
+  $pub_dbxrefs = chado_generate_var('pub_dbxref', $values, $options);
+  $dbxrefs = array();
+  foreach ($pub_dbxrefs as $pub_dbxref) {
+    $dbxrefs[] = $pub_dbxref->dbxref_id->db_id->name . ':' . $pub_dbxref->dbxref_id->accession;
+  }
+
   return array(
-    'Title' => $pub->title,
-    'Citation' => $citation,
-    'Abstract' => $abstract_text,
-    'Authors' => $authors_list,
-    'URL' => $url,
+    'TPUB:0000039' => $pub->title,
+    'TPUB:0000003' => $citation,
+    'TPUB:0000050' => $abstract_text,
+    'TPUB:0000047' => $authors_list,
+    'TPUB:0000052' => $url,
+    'SBO:0000554' => $dbxrefs,
   );
 }

+ 9 - 1
tripal_chado/api/tripal_chado.semweb.api.inc

@@ -214,13 +214,21 @@ function tripal_get_chado_semweb_column($chado_table, $term) {
     $cvterm_id = $column->cvterm_id;
     if ($cvterm_id) {
       $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
+      // Does the term match identically?
       if ($term == $cvterm->name) {
         return $column->chado_column;
       }
+      // Is the term a concatenation of the vocab and the accession?
+      else if ($term == $cvterm->dbxref_id->db_id->name . ':' . $cvterm->dbxref_id->accession) {
+        return $column->chado_column;
+      }
+      // Does the term have spaces that are renamed to underscores?
       else if ($term == preg_replace('/ /', '_', $cvterm->name)) {
         return $column->chado_column;
       }
-      else if ($term == $cvterm->dbxref_id->db_id->name . ':' . $cvterm->dbxref_id->accession) {
+      // Does the term have spaces that are renamed to underscores and
+      // all lowercase.
+      else if (strtolower($term) == strtolower(preg_replace('/ /', '_', $cvterm->name))) {
         return $column->chado_column;
       }
     }

+ 19 - 0
tripal_chado/includes/TripalFields/ChadoField.inc

@@ -71,7 +71,26 @@ class ChadoField extends TripalField {
    *   The field specific condition as set in the TripalFieldQuery object.
    */
   public function query($query, $condition) {
+    // If we are here it is because the child class did not implement the
+    // query function.  So, we will do our best to make the query work.
+    $chado_table = $this->instance['settings']['chado_table'];
+    $base_table = $this->instance['settings']['base_table'];
+    $bschema = chado_get_schema($base_table);
+    $bpkey = $bschema['primary key'][0];
+    $alias = 'dbx_linker';
+    $operator = $condition['operator'];
 
+    // If the chado_table and the base_table are the same then this is easy.
+    if ($chado_table == $base_table) {
+      // Get the base table column that is associated with the term
+      // passed as $condition['column'].
+      $base_field = tripal_get_chado_semweb_column($chado_table, $condition['column']);
+      $query->condition('base.' . $base_field , $condition['value'], $operator);
+    }
+    else {
+      // If the two are not the same then we expect that the child class
+      // will implement a query() function.
+    }
   }
 
   /**

+ 21 - 0
tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact.inc

@@ -142,6 +142,27 @@ class chado_linker__contact extends ChadoField {
       }
     }
   }
+
+  /**
+   * @see ChadoField::query()
+   */
+  public function query($query, $condition) {
+    $contact_linker = $this->instance['settings']['chado_table'];
+    $base_table = $this->instance['settings']['base_table'];
+    $bschema = chado_get_schema($base_table);
+    $bpkey = $bschema['primary key'][0];
+    $alias = 'contact_linker';
+    $operator = $condition['operator'];
+
+    if ($condition['column'] == 'contact.name') {
+      $query->join($contact_linker, $alias, "base.$bpkey = $alias.$bpkey");
+      $query->join('contact', 'C', "C.contact_id = $alias.contact_id");
+      $query->condition("C.name", $condition['value'], $operator);
+    }
+    if ($condition['column'] == 'contact.type') {
+
+    }
+  }
 }
 
 /**

+ 15 - 17
tripal_chado/includes/TripalFields/chado_linker__cvterm/chado_linker__cvterm.inc

@@ -130,7 +130,6 @@ class chado_linker__cvterm extends ChadoField {
       );
     }
   }
-
 }
 
 /**
@@ -147,23 +146,22 @@ function theme_chado_linker__cvterm_widget($variables) {
   $fkey = $element['#fkey_field'];
 
   $layout = "
-      <div class=\"annotation-cvterm-widget\">
-        <div class=\"annotation-cvterm-widget-item\">" .
-        drupal_render($element['cv__cv_id']) . "
-        </div>
-        <div class=\"annotation-cvterm-widget-item\">" .
-        drupal_render($element['cvterm__name']) . "
-        </div>
-        <div class=\"annotation-cvterm-widget-item\">" .
-        drupal_render($element['pub']) . "
-        </div>
-        <div class=\"annotation-cvterm-widget-item\">" .
-        drupal_render($element['chado-' . $table_name . '__is_not']) . "
-        </div>
+    <div class=\"annotation-cvterm-widget\">
+      <div class=\"annotation-cvterm-widget-item\">" .
+      drupal_render($element['cv__cv_id']) . "
       </div>
-    ";
-
-        return $layout;
+      <div class=\"annotation-cvterm-widget-item\">" .
+      drupal_render($element['cvterm__name']) . "
+      </div>
+      <div class=\"annotation-cvterm-widget-item\">" .
+      drupal_render($element['pub']) . "
+      </div>
+      <div class=\"annotation-cvterm-widget-item\">" .
+      drupal_render($element['chado-' . $table_name . '__is_not']) . "
+      </div>
+    </div>
+  ";
+  return $layout;
 }
 
 /**

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

@@ -80,7 +80,7 @@ class chado_linker__prop extends ChadoField {
 
     // Get the FK that links to the base record.
     $schema = chado_get_schema($field_table);
-    $pkey = $schema['primary key'][0];    
+    $pkey = $schema['primary key'][0];
     if (!isset($schema['foreign keys'][$base_table]['columns'])) {
       return;
     }
@@ -123,4 +123,26 @@ class chado_linker__prop extends ChadoField {
       }
     }
   }
+
+  /**
+   * @see ChadoField::query()
+   */
+  public function query($query, $condition) {
+    $prop_linker = $this->instance['settings']['chado_table'];
+    $base_table = $this->instance['settings']['base_table'];
+    $bschema = chado_get_schema($base_table);
+    $bpkey = $bschema['primary key'][0];
+    $alias = $this->field['field_name'];
+    $operator = $condition['operator'];
+
+    $vocab = $this->instance['settings']['term_vocabulary'];
+    $accession = $this->instance['settings']['term_accession'];
+
+    $cvterm = tripal_get_cvterm(array('id' => $vocab . ':' . $accession));
+
+    $query->join($prop_linker, $alias, "base.$bpkey = $alias.$bpkey");
+    $query->condition("$alias.type_id", $cvterm->cvterm_id);
+    $query->condition("$alias.value", $condition['value'], $operator);
+
+  }
 }

+ 17 - 0
tripal_chado/includes/TripalFields/data__accession/data__accession.inc

@@ -83,6 +83,23 @@ class data__accession extends ChadoField {
     }
   }
 
+  /**
+   * @see ChadoField::query()
+   */
+  public function query($query, $condition) {
+    $chado_table = $this->instance['settings']['chado_table'];
+    $base_table = $this->instance['settings']['base_table'];
+    $bschema = chado_get_schema($base_table);
+    $bpkey = $bschema['primary key'][0];
+    $alias = 'dbx_linker';
+    $operator = $condition['operator'];
+
+    if ($condition['column'] == 'accession') {
+      $query->join('dbxref', 'DBX', "DBX.dbxref_id = base.dbxref_id");
+      $query->condition("DBX.accession", $condition['value'], $operator);
+    }
+  }
+
   /**
    * @see TripalField::validate()
    */

+ 20 - 2
tripal_chado/includes/TripalFields/obi__organism/obi__organism.inc

@@ -193,13 +193,22 @@ class obi__organism extends ChadoField {
    */
   public function query($query, $condition) {
     $alias = $this->field['field_name'];
+    $operator = $condition['operator'];
+
     $query->join('organism', $alias, "base.organism_id = $alias.organism_id");
 
     if ($condition['column'] == 'organism.species') {
-      $query->condition("$alias.species", $condition['value']);
+      $query->condition("$alias.species", $condition['value'], $operator);
     }
     if ($condition['column'] == 'organism.genus') {
-      $query->condition("$alias.genus", $condition['value']);
+      $query->condition("$alias.genus", $condition['value'], $operator);
+    }
+    if ($condition['column'] == 'organism.infraspecies') {
+      $query->condition("$alias.infraspecific_name", $condition['value'], $operator);
+    }
+    if ($condition['column'] == 'organism.infraspecific_taxon') {
+      $query->join('cvterm', 'CVT', "base.type_id = CVT.cvterm_id");
+      $query->condition("CVT.name", $condition['value'], $operator);
     }
   }
 
@@ -222,5 +231,14 @@ class obi__organism extends ChadoField {
     if ($order['column'] == 'organism.genus') {
       $query->orderBy("$alias.species", $order['direction']);
     }
+    if ($order['column'] == 'organism.infraspecies') {
+      $query->orderBy("$alias.infraspecific_name", $order['direction']);
+    }
+    if ($order['column'] == 'organism.infraspecies') {
+      if (!in_array('CVT', $joins)) {
+        $query->join('cvterm', 'CVT', "base.type_id = CVT.cvterm_id");
+      }
+      $query->orderBy("CVT.name", $order['direction']);
+    }
   }
 }

+ 32 - 0
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc

@@ -123,6 +123,38 @@ class sbo__database_cross_reference extends ChadoField {
       }
     }
   }
+
+  /**
+   * @see ChadoField::query()
+   */
+  public function query($query, $condition) {
+    $dbxref_linker = $this->instance['settings']['chado_table'];
+    $base_table = $this->instance['settings']['base_table'];
+    $bschema = chado_get_schema($base_table);
+    $bpkey = $bschema['primary key'][0];
+    $alias = 'dbx_linker';
+    $operator = $condition['operator'];
+
+    if ($condition['column'] == 'database_cross_reference.database_name') {
+      $query->join($dbxref_linker, $alias, "base.$bpkey = $alias.$bpkey");
+      $query->join('dbxref', 'DBX', "DBX.dbxref_id = $alias.dbxref_id");
+      $query->join('db', 'DB', "DB.db_id = DBX.db_id");
+      $query->condition("DB.name", $condition['value'], $operator);
+    }
+    if ($condition['column'] == 'database_cross_reference.accession') {
+      $query->join($dbxref_linker, $alias, "base.$bpkey = $alias.$bpkey");
+      $query->join('dbxref', 'DBX', "DBX.dbxref_id = $alias.dbxref_id");
+      $query->condition("DBX.accession", $condition['value'], $operator);
+    }
+  }
+
+  /**
+   * @see ChadoField::queryOrder()
+   */
+  public function queryOrder($query, $order) {
+
+  }
+
   /**
    * @see TripalField::validate()
    */

+ 14 - 19
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc

@@ -408,49 +408,44 @@ class sbo__relationship extends ChadoField {
     $base_table = $this->instance['settings']['base_table'];
     $bschema = chado_get_schema($base_table);
     $bpkey = $bschema['primary key'][0];
+    $operator = $condition['operator'];
 
     // Filter by the name of the subject or object.
-    if ($condition['column'] == 'relationship.clause_subject.schema:name' or
-        $condition['column'] == 'relationship.clause_subject.name') {
+    if ($condition['column'] == 'relationship.clause_subject.name') {
       $query->join($chado_table, $alias, "base.$bpkey = $alias.object_id");
       $query->join($base_table, 'base2', "base2.$bpkey = $alias.subject_id");
-      $query->condition("base2.name", $condition['value']);
+      $query->condition("base2.name", $condition['value'], $operator);
     }
-    if ($condition['column'] == 'relationship.clause_predicate.schema:name' or
-        $condition['column'] == 'relationship.clause_predicate.name') {
+    if ($condition['column'] == 'relationship.clause_predicate.name') {
       $query->join($chado_table, $alias, "base.$bpkey = $alias.subject_id");
       $query->join($base_table, 'base2', "base2.$bpkey = $alias.object_id");
-      $query->condition("base2.name", $condition['value']);
+      $query->condition("base2.name", $condition['value'], $operator);
     }
 
     // Filter by unique name of the subject or object.
-    if ($condition['column'] == 'relationship.clause_subject.data:0842' or
-        $condition['column'] == 'relationship.clause_subject.identifier') {
+    if ($condition['column'] == 'relationship.clause_subject.identifier') {
       $query->join($chado_table, $alias, "base.$bpkey = $alias.object_id");
       $query->join($base_table, 'base2', "base2.$bpkey = $alias.subject_id");
-      $query->condition("base2.uniquename", $condition['value']);
+      $query->condition("base2.uniquename", $condition['value'], $operator);
     }
-    if ($condition['column'] == 'relationship.clause_predicate.data:0842' or
-        $condition['column'] == 'relationship.clause_predicate.identifier') {
+    if ($condition['column'] == 'relationship.clause_predicate.identifier') {
       $query->join($chado_table, $alias, "base.$bpkey = $alias.subject_id");
       $query->join($base_table, 'base2', "base2.$bpkey = $alias.object_id");
-      $query->condition("base2.uniquename", $condition['value']);
+      $query->condition("base2.uniquename", $condition['value'], $operator);
     }
 
     // Filter by the type of the subject or object
-    if ($condition['column'] == 'relationship.clause_subject.rdfs:type' or
-        $condition['column'] == 'relationship.clause_subject.type') {
+    if ($condition['column'] == 'relationship.clause_subject.type') {
       $query->join($chado_table, $alias, "base.$bpkey = $alias.object_id");
       $query->join($base_table, 'base2', "base2.$bpkey = $alias.subject_id");
       $query->join('cvterm', 'SubjectCVT', "SubjectCVT.cvterm_id = base2.type_id");
-      $query->condition("SubjectCVT.name", $condition['value']);
+      $query->condition("SubjectCVT.name", $condition['value'], $operator);
     }
-    if ($condition['column'] == 'relationship.clause_predicate.rdfs:type' or
-        $condition['column'] == 'relationship.clause_predicate.type') {
+    if ($condition['column'] == 'relationship.clause_predicate.type') {
       $query->join($chado_table, $alias, "base.$bpkey = $alias.subject_id");
       $query->join($base_table, 'base2', "base2.$bpkey = $alias.object_id");
       $query->join('cvterm', 'ObjectCVT', "ObjectCVT.cvterm_id = base2.type_id");
-      $query->condition("ObjectCVT.name", $condition['value']);
+      $query->condition("ObjectCVT.name", $condition['value'], $operator);
     }
 
     // Filter by relationship type
@@ -458,7 +453,7 @@ class sbo__relationship extends ChadoField {
       // This filter commented out because it's way to slow...
 //       $query->join($chado_table, $alias, "base.$bpkey = $alias.subject_id OR base.$bpkey = $alias.object_id");
 //       $query->join('cvterm', 'RelTypeCVT', "RelTypeCVT.cvterm_id = $alias.type_id");
-//       $query->condition("RelTypeCVT.name", $condition['value']);
+//       $query->condition("RelTypeCVT.name", $condition['value'], $operator);
     }
   }
 

+ 18 - 0
tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name.inc

@@ -102,4 +102,22 @@ class schema__alternate_name extends ChadoField {
     }
   }
 
+  /**
+   * @see ChadoField::query()
+   */
+  public function query($query, $condition) {
+    $syn_linker = $this->instance['settings']['chado_table'];
+    $base_table = $this->instance['settings']['base_table'];
+    $bschema = chado_get_schema($base_table);
+    $bpkey = $bschema['primary key'][0];
+    $alias = 'syn_linker';
+    $operator = $condition['operator'];
+
+    if ($condition['column'] == 'alternatename') {
+      $query->join($syn_linker, $alias, "base.$bpkey = $alias.$bpkey");
+      $query->join('synonym', 'SYN', "SYN.synonym_id = $alias.synonym_id");
+      $query->condition("SYN.name", $condition['value']);
+    }
+  }
+
 }

+ 40 - 2
tripal_chado/includes/TripalFields/schema__publication/schema__publication.inc

@@ -96,8 +96,6 @@ class schema__publication extends ChadoField {
       foreach ($record->$linker_table as $index => $linker) {
         $pub = $linker->pub_id;
         $pub_details = tripal_get_minimal_pub_info($pub);
-        $pub_details['@type'] = $pub->type_id->dbxref_id->db_id->name . ':' . $pub->type_id->dbxref_id->accession;
-        $pub_details['publication']['type'] = $pub->type_id->name;
 
         $entity->{$field_name}['und'][$i]['value'] = $pub_details;
         $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $pkey] = $linker->$pkey;
@@ -113,4 +111,44 @@ class schema__publication extends ChadoField {
     }
   }
 
+  /**
+   * @see ChadoField::query()
+   */
+  public function query($query, $condition) {
+    $pub_linker = $this->instance['settings']['chado_table'];
+    $base_table = $this->instance['settings']['base_table'];
+    $bschema = chado_get_schema($base_table);
+    $bpkey = $bschema['primary key'][0];
+    $alias = 'pub_linker';
+    $operator = $condition['operator'];
+
+    if ($condition['column'] == 'publication.database_cross_reference') {
+      list($db_name, $accession) = explode(':', $condition['value']);
+
+      $query->join($pub_linker, $alias, "base.$bpkey = $alias.$bpkey");
+      $query->join('pub_dbxref', 'PDBX', "PDBX.pub_id = $alias.pub_id");
+      $query->join('dbxref', 'DBX', "DBX.dbxref_id = PDBX.dbxref_id");
+      $query->join('db', 'DB', "DB.db_id = DBX.db_id");
+      $query->condition("DB.name", $db_name);
+      $query->condition("DBX.accession", $accession);
+    }
+
+    if ($condition['column'] == 'publication.title') {
+      $query->join($pub_linker, $alias, "base.$bpkey = $alias.$bpkey");
+      $query->join('pub', 'PUB', "PUB.pub_id = $alias.pub_id");
+      $query->condition('PUB.title', $condition['value'], $operator);
+    }
+
+    if ($condition['column'] == 'publication.citation') {
+
+    }
+
+    if ($condition['column'] == 'publication.authors') {
+
+    }
+    if ($condition['column'] == 'publication.abstract') {
+
+    }
+  }
+
 }

+ 4 - 4
tripal_chado/includes/TripalFields/schema__publication/schema__publication_formatter.inc

@@ -23,13 +23,13 @@ class schema__publication_formatter extends ChadoFieldFormatter {
     $list_items = array();
     $chado_table = $this->instance['settings']['chado_table'];
     foreach ($items as $delta => $item) {
-      
-      $title = isset($item['value']['Title']) ? $item['value']['Title'] : '';
-      $citation = isset($item['value']['Citation']) ? $item['value']['Citation'] : '';
+
+      $title = isset($item['value']['TPUB:0000039']) ? $item['value']['TPUB:0000039'] : '';
+      $citation = isset($item['value']['TPUB:0000003']) ? $item['value']['TPUB:0000003'] : '';
       $entity = array_key_exists('entity', $item['value']) ? $item['value']['entity'] : '';
       if ($entity) {
         list($entity_type, $entity_id) = explode(':', $entity);
-        $new_title = l($title, 'bio_data/' . $entity_id); 
+        $new_title = l($title, 'bio_data/' . $entity_id);
         $citation = preg_replace("/$title/", $new_title, $citation);
       }
       $list_items[] = $citation;

+ 6 - 138
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -438,7 +438,6 @@ function tripal_chado_field_storage_query($query) {
   $cquery = chado_db_select($data_table, 'base');
   $cquery->fields('base', array($pkey));
 
-
   // Iterate through all the conditions and add to the filters array
   // a chado_select_record compatible set of filters.
   foreach ($query->fieldConditions as $index => $condition) {
@@ -490,8 +489,9 @@ function tripal_chado_field_storage_query($query) {
           $cquery->condition('base.' . $base_field , $condition['value'], $condition['operator']);
         }
         if ($chado_table != $base_table) {
-          // TODO: I don't think we'll get here but just in case here's a
-          // note to handle it.
+          // TODO: I don't think we'll get here because linker fields will
+          // always have a custom field that should implement a query()
+          // function. But just in case here's a note to handle it.
         }
       }
     }
@@ -576,6 +576,9 @@ function tripal_chado_field_storage_query($query) {
     } // end if ($sort['type'] == 'field') {
   } // end foreach ($query->order as $index => $sort) {
 
+  //print_r($cquery->__toString());
+  //print_r($cquery->getArguments());
+
   $records = $cquery->execute();
 
   $result = array();
@@ -585,138 +588,3 @@ function tripal_chado_field_storage_query($query) {
   }
   return $result;
 }
-
-/**
- * @return
- *   An array containing the chado_select_record() compatible array.
- */
-function tripal_chado_field_storage_query_build_sql(&$sql, $prev_table, $prev_column, $prev_term, $chado_table, $query_terms, $condition, $value, $depth = 0) {
-
-  // Get schema information for the previous (linker) Chado table.
-  $pschema = chado_get_schema($prev_table);
-  $ppkey = $pschema['primary key'][0];
-  $pfkeys = $pschema['foreign keys'];
-
-  // Get schema information for the current Chado table.
-  $schema = chado_get_schema($chado_table);
-  $pkey = $schema['primary key'][0];
-  $fkeys = $schema['foreign keys'];
-
-  // Get the first query term from the list and find out what column this
-  // term maps to in the Chado table.
-  $term = array_shift($query_terms);
-  $chado_column = tripal_get_chado_semweb_column($chado_table, $term);
-  if (!$chado_column) {
-    // TODO: we could get to this point because a field has a value that
-    // doesn't map to a database column but is a manually created
-    // element.  How do we deal with those?
-    return FALSE;
-  }
-
-  // reformat that term so it's compatible with SQL
-  $term = preg_replace('/[^\w]/', '_', $term);
-
-  // A query can be an array of column names separated by a period.  We
-  // want to split them apart and just deal with the column at the head
-  // of the array.  But before dealing with that head, we will recurse so that
-  // we build our filters array from the bottom up.
-  if (count($query_terms) > 0) {
-    // Since the $query_terms is not a single element that implies this
-    // query term represents a foreign key.
-    // We don't know which direction the foreign key is going, so we'll have
-    // to check both the previous and current tables to build the join
-    // statement correctly.
-    if (array_key_exists($prev_table, $fkeys) and
-        array_key_exists($chado_column, $fkeys[$prev_table]['columns'])) {
-      $fkey = $fkeys[$prev_table]['columns'][$chado_column];
-      $sql['join'][] = 'INNER JOIN {' . $chado_table . '} ' . $term . ' ON ' . $prev_term . '.' . $fkey . ' = ' . $term . '.' . $chado_column;
-    }
-    else {
-      $sql['join'][] = 'INNER JOIN {' . $chado_table . '} ' . $term . ' ON ' . $prev_term . '.' . $prev_column . ' = ' . $term . '.' . $chado_column;
-    }
-
-
-    // Get the table that this foreign key links to.
-    $next_table = '';
-    foreach ($fkeys as $fktable_name => $fk_details) {
-      foreach ($fk_details['columns'] as $lfkey => $rfkey) {
-        if ($lfkey == $chado_column) {
-          $next_table = $fktable_name;
-        }
-      }
-    }
-    if ($next_table) {
-      tripal_chado_field_storage_query_build_sql($sql, $chado_table, $chado_column, $term, $next_table, $query_terms, $condition, $value, $depth++);
-    }
-    else {
-      // TODO: we could get to this point because a field has a value that
-      // doesn't map to a database column but is a manually created
-      // element.  How do we deal with those?
-      return FALSE;
-    }
-    return FALSE;
-  }
-
-  // We don't know which direction the foreign key is going, so we'll have
-  // to check both the previous and current tables to build the join
-  // statement correctly.
-  if (array_key_exists($prev_table, $fkeys) and
-      array_key_exists($chado_column, $fkeys[$prev_table]['columns'])) {
-    $fkey = $fkeys[$prev_table]['columns'][$chado_column];
-    $sql['join'][] = 'INNER JOIN {' . $chado_table . '} ' . $term . ' ON ' . $prev_term . '.' . $fkey . ' = ' . $term . '.' . $chado_column;
-  }
-  else {
-    $sql['join'][] = 'INNER JOIN {' . $chado_table . '} ' . $term . ' ON ' . $prev_term . '.' . $prev_column . ' = ' . $term . '.' . $chado_column;
-  }
-
-  // Use the appropriate operator.
-  $operator = $condition['operator'] ? $condition['operator'] : '=';
-  switch ($operator) {
-    case '=':
-      $sql['where'][] = "$term.$chado_column = :value";
-      $sql['args'][':value'] = $value;
-      break;
-    case '>':
-    case '>=':
-    case '<':
-    case '<=':
-      $sql['where'][] = "$term.$chado_column $op :value";
-      $sql['args'][':value'] = $value;
-      break;
-    case '<>':
-      $sql['where'][] = "$term.$chado_column $op :value";
-      $sql['args'][':value'] = $value;
-      break;
-    case 'CONTAINS':
-      $sql['where'][] = "$term.$chado_column LIKE :value";
-      $sql['args'][':value'] = '%' . $value . '%';
-      break;
-    case 'NOT':
-      $subfilters[$chado_column] = array(
-      'op' => 'NOT LIKE',
-      'data' => '%' . $value . '%',
-      );
-      $sql['where'][] = "$term.$chado_column NOT LIKE :value";
-      $sql['args'][':value'] = '%' . $value . '%';
-      break;
-    case 'STARTS WITH':
-      $sql['where'][] = "$term.$chado_column LIKE :value";
-      $sql['args'][':value'] =  $value . '%';
-      break;
-    case 'NOT STARTS':
-      $sql['where'][] = "$term.$chado_column NOT LIKE :value";
-      $sql['args'][':value'] =  $value . '%';
-      break;
-    case 'ENDS WITH':
-      $sql['where'][] = "$term.$chado_column LIKE :value";
-      $sql['args'][':value'] =  '%' . $value;
-      break;
-    case 'NOT ENDS':
-      $sql['where'][] = "$term.$chado_column NOT LIKE :value";
-      $sql['args'][':value'] =  '%' . $value;
-      break;
-    default:
-      // unrecognized operation.
-      break;
-  }
-}

+ 1 - 1
tripal_chado/includes/tripal_chado.fields.inc

@@ -343,7 +343,7 @@ function tripal_chado_bundle_create_fields_linker(&$info, $details, $entity_type
     $info[$field_name] = array(
       'field_name' => $field_name,
       'type' => $field_type,
-      'cardinality' => 1,
+      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
       'locked' => FALSE,
       'storage' => array(
         'type' => 'field_chado_storage',

+ 1 - 1
tripal_chado/includes/tripal_chado.semweb.inc

@@ -351,7 +351,7 @@ function tripal_chado_populate_vocab_EDAM() {
 
   $term = tripal_insert_cvterm(array(
     'id' => 'data:1056',
-    'name' => 'Databse name',
+    'name' => 'Database name',
     'cv_name' => 'EDAM',
     'definition' => 'The name of a biological or bioinformatics database.',
   ));

+ 3 - 0
tripal_ws/includes/tripal_ws.rest_v0.1.inc

@@ -462,6 +462,9 @@ function tripal_ws_services_v0_1_get_content_type($api_url, &$response, $ws_path
       default:
         $op = '=';
     }
+
+    //print_r(array($field_name, $column_name, $value, $op));
+
     // We pass in the $column_name as an identifier for any sub fields
     // that are present for the fields.
     $query->fieldCondition($field_name, $column_name, $value, $op);