Skip to content
Snippets Groups Projects
Commit 87a12723 authored by Kurund Jalmi's avatar Kurund Jalmi
Browse files

Merge pull request #2264 from dlobo/CRM-13606

CRM-13606 - Include / Exclude custom Search does not work properly
parents 109a3089 811a3ea4
Branches
Tags
No related merge requests found
......@@ -303,16 +303,19 @@ class CRM_Contact_Form_Search_Custom_Group
//search for smart group contacts
foreach ($this->_excludeGroups as $keys => $values) {
if (in_array($values, $smartGroup)) {
$ssId = CRM_Utils_Array::key($values, $smartGroup);
$smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
$smartSql = $smartSql . " AND contact_a.id NOT IN (
SELECT contact_id FROM civicrm_group_contact
WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
$ssGroup = new CRM_Contact_DAO_Group();
$ssGroup->id = $values;
if (!$ssGroup->find(TRUE)) {
CRM_Core_Error::fatal();
}
CRM_Contact_BAO_GroupContactCache::load($ssGroup);
$smartSql = "
SELECT gcc.contact_id
FROM civicrm_group_contact_cache gcc
WHERE gcc.group_id = {$ssGroup->id}
";
$smartGroupQuery = " INSERT IGNORE INTO Xg_{$this->_tableName}(contact_id) $smartSql";
CRM_Core_DAO::executeQuery($smartGroupQuery);
}
}
......@@ -366,18 +369,22 @@ class CRM_Contact_Form_Search_Custom_Group
foreach ($this->_includeGroups as $keys => $values) {
if (in_array($values, $smartGroup)) {
$ssGroup = new CRM_Contact_DAO_Group();
$ssGroup->id = $values;
if (!$ssGroup->find(TRUE)) {
CRM_Core_Error::fatal();
}
CRM_Contact_BAO_GroupContactCache::load($ssGroup);
$ssId = CRM_Utils_Array::key($values, $smartGroup);
$smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
$smartSql .= " AND contact_a.id NOT IN (
SELECT contact_id FROM civicrm_group_contact
WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
$smartSql = "
SELECT gcc.contact_id
FROM civicrm_group_contact_cache gcc
WHERE gcc.group_id = {$ssGroup->id}
";
//used only when exclude group is selected
if ($xGroups != 0) {
$smartSql .= " AND contact_a.id NOT IN (SELECT contact_id FROM Xg_{$this->_tableName})";
$smartSql .= " AND gcc.contact_id NOT IN (SELECT contact_id FROM Xg_{$this->_tableName})";
}
$smartGroupQuery = " INSERT IGNORE INTO Ig_{$this->_tableName}(contact_id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment