/** * Get the count of a members in a group with the specific status. * * @param int $id * Group id. * @param string $status * status of members in group * @param bool $countChildGroups * * @return int * count of members in the group with above status */ public static function memberCount($id, $status = 'Added', $countChildGroups = FALSE) { $groupContact = new CRM_Contact_DAO_GroupContact(); $groupIds = array($id); if ($countChildGroups) { $groupIds = CRM_Contact_BAO_GroupNesting::getDescendentGroupIds($groupIds); } $count = 0; $contacts = self::getGroupContacts($id); foreach ($groupIds as $groupId) { $groupContacts = self::getGroupContacts($groupId); foreach ($groupContacts as $gcontact) { if ($groupId != $id) { // Loop through main group's contacts // and subtract from the count for each contact which // matches one in the present group, if it is not the // main group foreach ($contacts as $contact) { if ($contact['contact_id'] == $gcontact['contact_id']) { $count--; } } } } $groupContact->group_id = $groupId; if (isset($status)) { $groupContact->status = $status; } $groupContact->_query['condition'] = 'WHERE contact_id NOT IN (SELECT id FROM civicrm_contact WHERE is_deleted = 1)'; $count += $groupContact->count(); } return $count; }