public function sio__annotation::queryOrder

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

Overrides ChadoField::queryOrder

See also

ChadoField::queryOrder()

File

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

Class

sio__annotation

Code

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

  $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 ($order['column'] == $vocabulary_term) {
    $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id", "LEFT OUTER");
    $this->queryJoinOnce($query, 'dbxref', $alias . '_dbxref', $alias . "_cvterm.dbxref_id = " . $alias . "_dbxref.dbxref_id", "LEFT OUTER");
    $this->queryJoinOnce($query, 'db', $alias . '_db', $alias . "_db.db_id = " . $alias . "_dbxref.db_id", "LEFT OUTER");
    $query->orderBy($alias . "_db.name", $order['direction']);
  }
  if ($order['column'] == $accession_term) {
    $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id", "LEFT OUTER");
    $this->queryJoinOnce($query, 'dbxref', $alias . '_dbxref', $alias . "_cvterm.dbxref_id = " . $alias . "_dbxref.dbxref_id", "LEFT OUTER");
    $query->orderBy($alias . "_dbxref.accession", $order['direction']);
  }
  if ($order['column'] == $definition_term) {
    $this->queryJoinOnce($query, 'cvterm', $alias . '_cvterm', $alias . ".cvterm_id = " . $alias . "_cvterm.cvterm_id");
    $query->orderBy($alias . "_cvterm.definition", $order['direction']);
  }
}