public function sio__annotation::query

3.x sio__annotation.inc public sio__annotation::query($query, $condition)

Overrides ChadoField::query

See also

ChadoField::query()

File

tripal_chado/includes/TripalFields/sio__annotation/sio__annotation.inc, line 166

Class

sio__annotation

Code

public function query($query, $condition) {
  $alias = $this->field['field_name'];
  $operator = $condition['operator'];

  $field_table = $this->instance['settings']['chado_table'];
  $base_table = $this->instance['settings']['base_table'];

  $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];

  $field_term_id = $this->getFieldTermID();

  $vocabulary_term = $field_term_id . ',' . chado_get_semweb_term('cvterm', 'cv_id');
  $accession_term = $field_term_id . ',' . chado_get_semweb_term('dbxref', 'accession');
  $definition_term = $field_term_id . ',' . chado_get_semweb_term('cvterm', 'definition');


  // Join to the xxx_cvterm table for this field.
  $this->queryJoinOnce($query, $field_table, $alias, "base.$fkey_rcolumn = $alias.$fkey_lcolumn");

  if ($condition['column'] == $vocabulary_term) {
    $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
    $this->queryJoinOnce($query, 'dbxref', $alias . '_dbxref', $alias . "_cvterm.dbxref_id = " . $alias . "_dbxref.dbxref_id");
    $this->queryJoinOnce($query, 'db', $alias . '_db', $alias . "_db.db_id = " . $alias . "_dbxref.db_id");
    $query->condition($alias . '_db.name', $condition['value'], $operator);
  }
  if ($condition['column'] == $accession_term) {
    $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
    $this->queryJoinOnce($query, 'dbxref', $alias . '_dbxref', $alias . "_cvterm.dbxref_id = " . $alias . "_dbxref.dbxref_id");
    $query->condition($alias . '_dbxref.accession', $condition['value'], $operator);
  }
  if ($condition['column'] == $definition_term) {
    $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
    $query->condition($alias . '_cvterm.definition', $condition['value'], $operator);
  }
}