Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/drupal#58 - Add Contact ID operator to the contact reference filt… #579

Open
wants to merge 1 commit into
base: 7.x-master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions modules/views/civicrm/civicrm_handler_filter_contact_ref.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,36 @@ class civicrm_handler_filter_contact_ref extends views_handler_filter_string {
$this->filterContactRef($field);
}

/**
* @param string $field
*/
public function op_contact_id($field) {
$this->operator = '=';
$this->filterContactRef($field, 'id');
}

/**
* Add Contact ID to the list of operators.
*/
public function operators() {
$op = parent::operators();
$op['contact_id'] = [
'title' => t('Contact ID'),
'short' => t('contact_id'),
'method' => 'op_contact_id',
'values' => 1,
];
return $op;
}

/**
* Adds where clause to the view query to filter
* by contact sort_name instead of id.
* by contact sort_name OR id based on operator selected.
*
* @param string $field
* @param string $fieldName
*/
public function filterContactRef($field) {
public function filterContactRef($field, $fieldName = 'sort_name') {
if (!empty($this->value)) {
$op = $this->operator;
if ($this->operator != '=' && $this->operator != '!=') {
Expand All @@ -58,7 +81,7 @@ class civicrm_handler_filter_contact_ref extends views_handler_filter_string {
}
$contacts = db_select('civicrm_contact', 'cc')
->fields('cc', array('id'))
->condition('cc.sort_name', $this->value, $op);
->condition("cc.{$fieldName}", $this->value, $op);

$this->query->add_where($this->options['group'], $field, $contacts, 'IN');
}
Expand Down