Fix dev/core#4943 - Exclude case activities from count if appropriate
authorcolemanw <coleman@civicrm.org>
Mon, 29 Jan 2024 04:02:38 +0000 (23:02 -0500)
committercolemanw <coleman@civicrm.org>
Mon, 29 Jan 2024 04:02:38 +0000 (23:02 -0500)
CRM/Contact/BAO/Contact.php

index 254d009eae5c9dee69b46eacaea5201c346cfa58..253b4d023c0f1cad5ecdb90b0fdd325112ae12f2 100644 (file)
@@ -2632,14 +2632,17 @@ LEFT JOIN civicrm_email    ON ( civicrm_contact.id = civicrm_email.contact_id )
         return CRM_Case_BAO_Case::caseCount($contactId);
 
       case 'activity':
-        return \Civi\Api4\Activity::get(TRUE)
+        $excludeCaseActivities = (CRM_Core_Component::isEnabled('CiviCase') && !\Civi::settings()->get('civicaseShowCaseActivities'));
+        $activityApi = \Civi\Api4\Activity::get(TRUE)
           ->selectRowCount()
           ->addJoin('ActivityContact AS activity_contact', 'INNER')
           ->addWhere('activity_contact.contact_id', '=', $contactId)
           ->addWhere('is_test', '=', FALSE)
-          ->addGroupBy('id')
-          ->execute()
-          ->count();
+          ->addGroupBy('id');
+        if ($excludeCaseActivities) {
+          $activityApi->addWhere('case_id', 'IS EMPTY');
+        }
+        return $activityApi->execute()->count();
 
       case 'mailing':
         $params = ['contact_id' => $contactId];