Skip to content

Commit

Permalink
Merge pull request #16006 from demeritcowboy/case-role-manager-api
Browse files Browse the repository at this point in the history
dev/core#1426 Return correct manager role info during Case api get
  • Loading branch information
colemanw authored Dec 4, 2019
2 parents ea9cd0a + c50e15c commit 6fe7706
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions CRM/Case/BAO/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ public static function getRelatedContacts($caseID, $includeDetails = TRUE) {

$values = [];
$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, ce.email, cp.phone
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
JOIN civicrm_relationship_type crt
ON crt.id = cr.relationship_type_id
Expand All @@ -1158,7 +1158,7 @@ public static function getRelatedContacts($caseID, $includeDetails = TRUE) {
AND cr.is_active
AND cc.id NOT IN (%2)
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, ce.email, cp.phone
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
JOIN civicrm_relationship_type crt
ON crt.id = cr.relationship_type_id
Expand Down Expand Up @@ -1196,7 +1196,8 @@ public static function getRelatedContacts($caseID, $includeDetails = TRUE) {
'phone' => $dao->phone,
];
// Add more info about the role (creator, manager)
$role = CRM_Utils_Array::value($dao->role_name, $caseRoles);
// The XML historically has the reverse direction, so look up reverse.
$role = CRM_Utils_Array::value($dao->role_name_reverse, $caseRoles);
if ($role) {
unset($role['name']);
$details += $role;
Expand Down
6 changes: 5 additions & 1 deletion tests/phpunit/api/v3/CaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,19 @@ public function testCaseGetWithRoles() {
'status_id' => "Open",
'return' => ['contacts'],
]);

$foundManager = FALSE;
foreach ($result['contacts'] as $contact) {
if ($contact['role'] == 'Client') {
$this->assertEquals(17, $contact['contact_id']);
}
elseif ($contact['role'] == 'Homeless Services Coordinator') {
elseif ($contact['role'] == 'Homeless Services Coordinator is') {
$this->assertEquals(1, $contact['creator']);
$this->assertEquals(1, $contact['manager']);
$foundManager = TRUE;
}
}
$this->assertTrue($foundManager);
}

public function testCaseGetWithDefinition() {
Expand Down

0 comments on commit 6fe7706

Please sign in to comment.