Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api4: add calculated field contact_count to Group #26313

Merged
merged 2 commits into from
May 23, 2023

Conversation

aydun
Copy link
Contributor

@aydun aydun commented May 23, 2023

Overview

This adds a calculated field 'contact_countto theGroup.get()` API. This provides the current count of 'added' group members and smart group members. Note this does not rebuild the group cache so smart group counts may be out of date or zero.

Before

Cannot get count of smart group contacts.

After

Count of smart group contacts available as contact_count field

Technical Details

Contacts manually added to a smart group are included in the civicrm_group_contact_cache table. So if the count from that table is non-zero, the group is smart and the count is the total number of contacts. If the count is zero, either the group is not smart, or the cache table has not been rebuilt. Either way, report the number of contacts in civicrm_group_contact

Comments

Anything else you would like the reviewer to note

@civibot
Copy link

civibot bot commented May 23, 2023

(Standard links)

@civibot civibot bot added the master label May 23, 2023
aydun and others added 2 commits May 23, 2023 23:06
This provides the current count of 'added' group members and smart group
members.
Note this does not rebuild the group cache so smart group counts may be
out of date or zero.

See https://stackoverflow.com/questions/47918929/coalesce-for-zero-instead-of-null/47919047#47919047
for the COALESCE(NULLIF()) construct.
@colemanw
Copy link
Member

Great thanks @aydun - I've added a simple test

@eileenmcnaughton eileenmcnaughton merged commit 8761c83 into civicrm:master May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants