From 085e6226cdd7b40c5436b060e02e909a2809fb92 Mon Sep 17 00:00:00 2001 From: "Donald A. Lobo" Date: Sun, 10 Nov 2013 19:53:35 -0800 Subject: [PATCH] CRM-13133 - also fix some notices and pass-by reference warnings ---------------------------------------- * CRM-13133: Advanced Search is incorrectly including contacts removed from a group http://issues.civicrm.org/jira/browse/CRM-13133 --- CRM/Contact/BAO/Query.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 78010bf4a8..b6ee557860 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -3818,9 +3818,12 @@ WHERE id IN ( $groupIDs ) self::$_relType = 'reciprocal'; } // if we are creating a temp table we build our own where for the relationship table + $relationshipTempTable = NULL; if(self::$_relType == 'reciprocal' && empty($targetGroup)) { $where = array(); - self::$_relationshipTempTable = $relationshipTempTable = 'civicrm_temp_rel' . rand(0,99999); + self::$_relationshipTempTable = + $relationshipTempTable = + CRM_Core_DAO::createTempTableName( 'civicrm_rel'); if($nameClause) { $where[$grouping][] = " sort_name $nameClause "; } @@ -3850,8 +3853,10 @@ WHERE id IN ( $groupIDs ) //add contacts from static groups $this->_tables['civicrm_relationship_group_contact'] = $this->_whereTables['civicrm_relationship_group_contact'] = - " LEFT JOIN civicrm_group_contact civicrm_relationship_group_contact ON civicrm_relationship_group_contact.contact_id = contact_b.id"; - $groupWhere[] = "( civicrm_relationship_group_contact.group_id IN (" . implode(",", $targetGroup[2]) . ") )"; + " LEFT JOIN civicrm_group_contact civicrm_relationship_group_contact ON civicrm_relationship_group_contact.contact_id = contact_b.id AND civicrm_relationship_group_contact.status = 'Added'"; + $groupWhere[] = + "( civicrm_relationship_group_contact.group_id IN (" . + implode(",", $targetGroup[2]) . ") ) "; //add contacts from saved searches $ssWhere = $this->addGroupContactCache($targetGroup[2], "civicrm_relationship_group_contact_cache", "contact_b"); @@ -3863,7 +3868,7 @@ WHERE id IN ( $groupIDs ) $this->_where[$grouping][] = "( " . implode(" OR ", $groupWhere) . " )"; //Get the names of the target groups for the qill - $groupNames = &CRM_Core_PseudoConstant::group(); + $groupNames = CRM_Core_PseudoConstant::group(); $qillNames = array(); foreach ($targetGroup[2] as $groupId) { if (array_key_exists($groupId, $groupNames)) { -- 2.25.1