Skip to content

Commit

Permalink
Merge pull request #30 from seamuslee001/group_filter_fix
Browse files Browse the repository at this point in the history
Fix filtering when using a smart group
  • Loading branch information
bjendres authored Mar 5, 2024
2 parents c525c54 + 3b17a01 commit ac2d83e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions CRM/Xdedupe/Filter/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ public function addJOINS(&$joins)
$is_smart_group = CRM_Core_DAO::singleValueQuery(
"SELECT saved_search_id FROM civicrm_group WHERE id = %1",
[1 => [$this->group_id, 'Integer']]);
$table = 'civicrm_group_contact';
if ($is_smart_group) {
CRM_Contact_BAO_GroupContactCache::loadAll($this->group_id);
CRM_Contact_BAO_GroupContactCache::loadAll([$this->group_id]);
$table = 'civicrm_group_contact_cache';
}

// finally: add the join
$joins[] = "LEFT JOIN civicrm_group_contact {$this->alias} ON {$this->alias}.contact_id = contact.id
AND {$this->alias}.group_id = {$this->group_id}
AND {$this->alias}.status = 'Added'";
$joins[] = "LEFT JOIN {$table} {$this->alias} ON {$this->alias}.contact_id = contact.id
AND {$this->alias}.group_id = {$this->group_id}" . ($is_smart_group ? '' : " AND {$this->alias}.status = 'Added'");
}
}

Expand All @@ -85,9 +86,9 @@ public function addJOINS(&$joins)
public function addWHERES(&$wheres)
{
if ($this->include) {
$wheres[] = "{$this->alias}.id IS NOT NULL";
$wheres[] = "{$this->alias}.contact_id IS NOT NULL";
} else {
$wheres[] = "{$this->alias}.id IS NULL";
$wheres[] = "{$this->alias}.contact_id IS NULL";
}
}
}

0 comments on commit ac2d83e

Please sign in to comment.