* @throws \CiviCRM_API3_Exception
*/
public static function populateTemporaryTableWithContactsInGroups(array $groupIDs, string $temporaryTable): void {
+ $childAndParentGroupIDs = array_merge($groupIDs, CRM_Contact_BAO_GroupNesting::getDescendentGroupIds($groupIDs));
$groups = civicrm_api3('Group', 'get', [
'is_active' => 1,
- 'id' => ['IN' => $groupIDs],
+ 'id' => ['IN' => $childAndParentGroupIDs],
'saved_search_id' => ['>' => 0],
'return' => 'id',
]);
$query = "
SELECT DISTINCT group_contact.contact_id as contact_id
FROM civicrm_group_contact group_contact
- WHERE group_contact.group_id IN (" . implode(', ', $groupIDs) . ")
+ WHERE group_contact.group_id IN (" . implode(', ', $childAndParentGroupIDs) . ")
AND group_contact.status = 'Added' ";
if (!empty($smartGroups)) {
->execute()->first()['id'];
}
+ $parentGroupId = \Civi\Api4\Group::create(FALSE)
+ ->setValues(['title' => uniqid()])
+ ->execute()->first()['id'];
+
$savedSearchA = civicrm_api4('SavedSearch', 'create', [
'values' => [
'api_entity' => 'Contact',
],
],
'chain' => [
- 'group' => ['Group', 'create', ['values' => ['title' => 'In A Test', 'saved_search_id' => '$id']], 0],
+ 'group' => ['Group', 'create', ['values' => ['parents' => [$parentGroupId], 'title' => 'In A Test', 'saved_search_id' => '$id']], 0],
],
])->first();
],
],
'chain' => [
- 'group' => ['Group', 'create', ['values' => ['title' => 'In B Test', 'saved_search_id' => '$id']], 0],
+ 'group' => ['Group', 'create', ['values' => ['parents' => [$parentGroupId], 'title' => 'In B Test', 'saved_search_id' => '$id']], 0],
],
])->first();
]);
$this->assertCount(15, $bothGroups);
+ // Parent group includes both groups a & b so should give the same results as above
+ $parentGroup = civicrm_api4('Contact', 'get', [
+ 'where' => [['groups', 'IN', [$parentGroupId]]],
+ ]);
+ $this->assertCount(15, $parentGroup);
+
$aNotB = civicrm_api4('Contact', 'get', [
'where' => [
['groups:name', 'IN', [$savedSearchA['group']['name']]],