From 883e1e760594121fd382aaf9209b68bcf1b3ce13 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Fri, 9 Dec 2016 11:38:02 +0530 Subject: [PATCH] revert operator changes and shift getChildGroupIds() definition --- CRM/Contact/BAO/Group.php | 22 ++++++++++++++++ CRM/Contact/BAO/Query.php | 26 ++----------------- CRM/Core/DAO/AllCoreTables.data.php | 2 +- CRM/Core/DAO/StateProvince.php | 2 +- .../CRM/Contact/BAO/GroupContactTest.php | 21 ++------------- 5 files changed, 28 insertions(+), 45 deletions(-) diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index 4715fead97..69e043be8a 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -1359,4 +1359,26 @@ WHERE {$whereClause}"; } } + /** + * Get child group ids + * + * @param array $ids + * Parent Group IDs + * + * @return array + */ + public static function getChildGroupIds($ids) { + $notFound = FALSE; + $childGroupIds = array(); + foreach ($ids as $id) { + $childId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $id, 'children'); + while (!empty($childId)) { + $childGroupIds[] = $childId; + $childId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $childId, 'children'); + } + } + + return $childGroupIds; + } + } diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 38ac4ec1b5..b7ff067238 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -2966,7 +2966,7 @@ class CRM_Contact_BAO_Query { } // include child groups IDs if any - $childGroupIds = self::getChildGroupIds($regularGroupIDs); + $childGroupIds = CRM_Contact_BAO_Group::getChildGroupIds($regularGroupIDs); $childClause = ''; if (count($childGroupIds)) { $gcTable = ($op == '!=') ? 'cgc' : $gcTable; @@ -2980,7 +2980,7 @@ class CRM_Contact_BAO_Query { $groupClause[] = " ( " . $this->addGroupContactCache($smartGroupIDs, NULL, "contact_a", $op) . " ) "; } - $and = ($op == 'IS NULL') ? 'AND' : $this->_operator; + $and = ($op == 'IS NULL') ? ' AND ' : ' OR '; $this->_where[$grouping][] = implode($and, $groupClause); list($qillop, $qillVal) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Contact_DAO_Group', 'id', $value, $op); @@ -2990,28 +2990,6 @@ class CRM_Contact_BAO_Query { } } - /** - * Get child group ids - * - * @param array $ids - * Parent Group IDs - * - * @return array - */ - public static function getChildGroupIds($ids) { - $notFound = FALSE; - $childGroupIds = array(); - foreach ($ids as $id) { - $childId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $id, 'children'); - while (!empty($childId)) { - $childGroupIds[] = $childId; - $childId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $childId, 'children'); - } - } - - return $childGroupIds; - } - /** * Function translates selection of group type into a list of groups. * @param $value diff --git a/CRM/Core/DAO/AllCoreTables.data.php b/CRM/Core/DAO/AllCoreTables.data.php index 0dbf28032f..edc60b48cf 100644 --- a/CRM/Core/DAO/AllCoreTables.data.php +++ b/CRM/Core/DAO/AllCoreTables.data.php @@ -24,7 +24,7 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ */ -// (GenCodeChecksum:89f332e5e88581181224fac51b45a1a4) +// (GenCodeChecksum:3785fda6260a05bff2e3914c11b593e7) return array( 'CRM_Core_DAO_AddressFormat' => array( 'name' => 'AddressFormat', diff --git a/CRM/Core/DAO/StateProvince.php b/CRM/Core/DAO/StateProvince.php index 06aae5a204..f5f037e885 100644 --- a/CRM/Core/DAO/StateProvince.php +++ b/CRM/Core/DAO/StateProvince.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Core/StateProvince.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:c27dc7717825021cafc443d7d3244c8d) + * (GenCodeChecksum:70c072816098c4cbd13b7c13218c35e8) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; diff --git a/tests/phpunit/CRM/Contact/BAO/GroupContactTest.php b/tests/phpunit/CRM/Contact/BAO/GroupContactTest.php index a613dc34af..0485d92c60 100644 --- a/tests/phpunit/CRM/Contact/BAO/GroupContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/GroupContactTest.php @@ -202,40 +202,23 @@ class CRM_Contact_BAO_GroupContactTest extends CiviUnitTestCase { array( 'form_value' => array('group' => $regularGroup['id']), 'expected_count' => 2, - 'operator' => 'AND', 'expected_contact' => array($contact2, $contact3), ), //Case 2: Find all contacts in smart group array( 'form_value' => array('group' => $smartGroup['id']), 'expected_count' => 2, - 'operator' => 'AND', 'expected_contact' => array($contact1, $contact2), ), - //Case 3: Find all contacts in regular group AND smart group - array( - 'form_value' => array('group' => array('IN' => array($regularGroup['id'], $smartGroup['id']))), - 'expected_count' => 1, - 'operator' => 'AND', - 'expected_contact' => array($contact2), - ), - //Case 4: Find all contacts in regular group OR smart group + //Case 3: Find all contacts in regular group and smart group array( 'form_value' => array('group' => array('IN' => array($regularGroup['id'], $smartGroup['id']))), 'expected_count' => 3, - 'operator' => 'OR', 'expected_contact' => array($contact1, $contact2, $contact3), ), ); foreach ($useCases as $case) { - $query = new CRM_Contact_BAO_Query( - CRM_Contact_BAO_Query::convertFormValues($case['form_value']), - NULL, NULL, - FALSE, FALSE, 1, - FALSE, TRUE, - TRUE, NULL, - $case['operator'] - ); + $query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($case['form_value'])); list($select, $from, $where, $having) = $query->query(); $groupContacts = CRM_Core_DAO::executeQuery("SELECT DISTINCT contact_a.id $from $where")->fetchAll(); foreach ($groupContacts as $key => $value) { -- 2.25.1