From: colemanw Date: Mon, 29 Jan 2024 04:02:38 +0000 (-0500) Subject: Fix dev/core#4943 - Exclude case activities from count if appropriate X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=183c7821c06fe94ed20834e3c5d31cc289c97792;p=civicrm-core.git Fix dev/core#4943 - Exclude case activities from count if appropriate --- 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];