From 183c7821c06fe94ed20834e3c5d31cc289c97792 Mon Sep 17 00:00:00 2001 From: colemanw Date: Sun, 28 Jan 2024 23:02:38 -0500 Subject: [PATCH] Fix dev/core#4943 - Exclude case activities from count if appropriate --- CRM/Contact/BAO/Contact.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 254d009eae..253b4d023c 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -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]; -- 2.25.1