public function sbo__relationship::query

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

Overrides ChadoField::query

See also

ChadoField::query()

File

tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc, line 472

Class

sbo__relationship

Code

public function query($query, $condition) {

  $alias = $this->field['field_name'];
  $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];
  $operator = $condition['operator'];

  // Bulid the list of expected elements that will be provided.
  $field_term_id = $this->getFieldTermID();
  $rel_subject = $field_term_id . ',local:relationship_subject';
  $rel_subject_type = $rel_subject . ',' . 'rdfs:type';
  $rel_subject_name = $rel_subject . ',' . 'schema:name';
  $rel_subject_identifier = $rel_subject . ',' . 'data:0842';
  $rel_type = $field_term_id . ',local:relationship_type';
  $rel_object = $field_term_id . ',local:relationship_object';
  $rel_object_type = $rel_object . ',' . 'rdfs:type';
  $rel_object_name = $rel_object . ',' . 'schema:name';
  $rel_object_identifier = $rel_object . ',' . 'data:0842';

  // Filter by the name of the subject or object.
  if ($condition['column'] == $rel_subject_name) {
    $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.object_id");
    $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.subject_id");
    $query->condition("base2.name", $condition['value'], $operator);
  }
  if ($condition['column'] == $rel_object_name) {
    $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.subject_id");
    $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.object_id");
    $query->condition("base2.name", $condition['value'], $operator);
  }

  // Filter by unique name of the subject or object.
  if ($condition['column'] == $rel_subject_identifier) {
    $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.object_id");
    $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.subject_id");
    $query->condition("base2.uniquename", $condition['value'], $operator);
  }
  if ($condition['column'] == $rel_object_identifier) {
    $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.subject_id");
    $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.object_id");
    $query->condition("base2.uniquename", $condition['value'], $operator);
  }

  // Filter by the type of the subject or object
  if ($condition['column'] == $rel_subject_type) {
    $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.object_id");
    $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.subject_id");
    $this->queryJoinOnce($query, 'cvterm', 'SubjectCVT', "SubjectCVT.cvterm_id = base2.type_id");
    $this->queryJoinOnce($query, "SubjectCVT.name", $condition['value'], $operator);
  }
  if ($condition['column'] == $rel_object_type) {
    $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.subject_id");
    $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.object_id");
    $this->queryJoinOnce($query, 'cvterm', 'ObjectCVT', "ObjectCVT.cvterm_id = base2.type_id");
    $query->condition("ObjectCVT.name", $condition['value'], $operator);
  }

  // Filter by relationship type
  if ($condition['column'] == 'relationship.relationship_type') {
    // This filter commented out because it's way to slow...
    //       $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.subject_id OR base.$bpkey = $alias.object_id");
    //       $this->queryJoinOnce($query, 'cvterm', 'RelTypeCVT', "RelTypeCVT.cvterm_id = $alias.type_id");
    //       $query->condition("RelTypeCVT.name", $condition['value'], $operator);
  }
}