public function chado_linker__contact::queryOrder

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

Overrides ChadoField::queryOrder

See also

ChadoField::queryOrder()

File

tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact.inc, line 234

Class

chado_linker__contact

Code

public function queryOrder($query, $order) {
  $alias = $this->field['field_name'];
  $field_term_id = $this->getFieldTermID();
  $type_term = chado_get_semweb_term('contact', 'type_id');
  $name_term = chado_get_semweb_term('contact', 'name');
  $description_term = chado_get_semweb_term('contact', 'description');

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

  // Get the FK that links to the base record.
  $schema = chado_get_schema($contact_linker);
  $pkey = $schema['primary key'][0];
  $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
  $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];

  // Join the contact linker table and then join the contact table.
  $calias = $contact_linker . '_contact';
  $this->queryJoinOnce($query, $contact_linker, $alias, "base.$fkey_rcolumn = $alias.$fkey_lcolumn", "LEFT OUTER");
  $this->queryJoinOnce($query, 'contact', $calias, "$calias.contact_id = $alias.contact_id", "LEFT OUTER");

  // Search by the contact name
  if ($order['column'] == $field_term_id or 
    $order['column'] == $field_term_id . ',' . $name_term) {
    $query->orderBy("$calias.name", $order['direction']);
  }
  // Search on the contact description.
  if ($order['column'] == $field_term_id . ',' . $description_term) {
    $query->orderBy("$calias.description", $order['direction']);
  }
  // Search on the contact type.
  if ($order['column'] == $field_term_id . ',' . $type_term) {
    $talias = $contact_linker . '_contact_type';
    $this->queryJoinOnce($query, 'cvterm', $talias, "$calias.type_id = $talias.cvterm_id", "LEFT OUTER");
    $query->orderBy("$talias.name", $order['direction']);
  }
}