Count on Groups tab changes when tab is loaded
If a contact has been explicitly added to any Smart Groups, then the number on their Groups tab changes when the tab is loaded.
Steps to reproduce
- Explicitly add a contact to a Smart Group by going to their Groups tab, clicking the "+ Add to a group" dropdown, selecting a Smart Group and clicking the Add button.
- Refresh the page in the browser. Note the count on the Groups tab.
- Click the contact's Groups tab. Note the count on the Groups tab.
Expected results
The count on the Groups tab should be as accurate as reasonably possible, and should not change when the Groups tab is loaded.
Actual results
Before the Groups tab is loaded, the count does not include Smart Groups that the contact has been explicitly added to. After the Groups tab is loaded, the count changes to include Smart Groups that the contact has been explicitly added to.
Cause
The count is calculated using the CRM_Contact_BAO_GroupContact::getContactGroup function, which is called by CRM_Contact_BAO_Contact::getCountComponent when the contact page is loaded, and by CRM_Contact_Page_View_GroupContact::browse when the Groups tab is loaded. The discrepancy arises because the two calls to that function pass different arguments: The first call omits the $includeSmartGroups argument, which defaults to FALSE, whereas the second call passes TRUE to the $includeSmartGroups argument.
Proposal
I propose changing the call to CRM_Contact_BAO_GroupContact::getContactGroup in CRM_Contact_BAO_Contact::getContactGroup so that it passes TRUE to the $includeSmartGroups argument. This one-line change would ensure that the count on the Groups tab always includes Smart Groups to which the contact has been explicitly added.
Note that I'm only proposing counting groups to which the contact has been explicitly added; not all Smart Groups whose search criteria include the contact. Thus the change that I'm proposing avoids the documented problems with counting all Smart Groups. There is no significant performance hit.
I will submit a PR.