You are here

function redhen_relation_handler_sort_primary_contact::query in RedHen CRM 7

Called to add the field to a query.

Overrides views_handler_sort::query

File

modules/redhen_relation/includes/views/redhen_relation_handler_sort_primary_contact.inc, line 11
Field that indicates of a specific contact is the primary contact for an organization

Class

redhen_relation_handler_sort_primary_contact
@file Field that indicates of a specific contact is the primary contact for an organization

Code

function query() {
  $this
    ->ensure_my_table();

  // @todo Make the ensure_tables work so we are explicit about the relationships that give us the contact_id/primary_contact_id
  $contact_table = $this->query
    ->ensure_table('redhen_contact');
  $org_table = $this->query
    ->ensure_table('redhen_org', $this->relationship);
  $comparison = 'primary_contact_id = ' . $contact_table . '.contact_id';
  $this->field_alias = $this->query
    ->add_field(NULL, $comparison, 'is_primary');
  $this->query
    ->add_orderby(NULL, NULL, $this->options['order'], $this->field_alias);
}