Skip to content

Commit

Permalink
RSE-1022: Fix Issue with API returning Case Clients As Part of Relate…
Browse files Browse the repository at this point in the history
…d Contacts

Included in CiviCRM 5.26
PR: civicrm#16837
  • Loading branch information
tunbola authored and erawat committed May 20, 2020
1 parent 903dba8 commit 60f8111
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions CRM/Case/BAO/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@ public static function getRelatedContacts($caseID, $includeDetails = TRUE) {
}

$values = [];
$caseClientCondition = !empty($caseInfo['client_id']) ? "AND cc.id NOT IN (%2)" : '';
$query = <<<HERESQL
SELECT cc.display_name as name, cc.sort_name as sort_name, cc.id, cr.relationship_type_id, crt.label_b_a as role, crt.name_b_a as role_name, crt.name_a_b as role_name_reverse, ce.email, cp.phone
FROM civicrm_relationship cr
Expand All @@ -1157,7 +1158,7 @@ public static function getRelatedContacts($caseID, $includeDetails = TRUE) {
AND cp.is_primary= 1
WHERE cr.case_id = %1
AND cr.is_active
AND cc.id NOT IN (%2)
{$caseClientCondition}
UNION
SELECT cc.display_name as name, cc.sort_name as sort_name, cc.id, cr.relationship_type_id, crt.label_a_b as role, crt.name_a_b as role_name, crt.name_b_a as role_name_reverse, ce.email, cp.phone
FROM civicrm_relationship cr
Expand All @@ -1174,12 +1175,15 @@ public static function getRelatedContacts($caseID, $includeDetails = TRUE) {
AND cp.is_primary= 1
WHERE cr.case_id = %1
AND cr.is_active
AND cc.id NOT IN (%2)
{$caseClientCondition}
HERESQL;
$params = [
1 => [$caseID, 'Integer'],
2 => [implode(',', $caseInfo['client_id']), 'String'],
];

if ($caseClientCondition) {
$params[2] = [implode(',', $caseInfo['client_id']), 'CommaSeparatedIntegers'];
}
$dao = CRM_Core_DAO::executeQuery($query, $params);

while ($dao->fetch()) {
Expand Down

0 comments on commit 60f8111

Please sign in to comment.