public function local__contact::query

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

Overrides ChadoField::query

See also

ChadoField::query()

File

tripal_chado/includes/TripalFields/local__contact/local__contact.inc, line 161

Class

local__contact

Code

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

  $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');

  if ($field_table == 'biomaterial') {
    if ($record) {
      $contact = $record->biosourceprovider_id;

      // Join the contact table
      $calias = $alias . '_provider_id';
      $this->queryJoinOnce($query, 'contact', $calias, "base.biosourceprovider_id = $calias.contact_id");

      // Search by the contact name
      if ($condition['column'] == $field_term_id or 
        $condition['column'] == $field_term_id . ',' . $name_term) {
        $query->condition("$calias.name", $condition['value'], $operator);
      }
      // Search on the contact description.
      if ($condition['column'] == $field_term_id . ',' . $description_term) {
        $query->condition("$calias.description", $condition['value'], $operator);
      }
      // Search on the contact type.
      if ($condition['column'] == $field_term_id . ',' . $type_term) {
        $talias = $alias . 'provider_contact_type';
        $this->queryJoinOnce($query, 'cvterm', $talias, "$calias.type_id = $talias.cvterm_id");
        $query->condition("$talias.name", $condition['value'], $operator);
      }
    }
  }
}