You are here

function wf_crm_find_case_roles in Webform CiviCRM Integration 7.4

Same name and namespace in other branches
  1. 7.5 includes/contact_component.inc \wf_crm_find_case_roles()

Returns ids of all contacts who are related to given contact for given case

_role

Parameters

$contact_a:

$case:

Return value

array

1 call to wf_crm_find_case_roles()
wf_crm_webform_base::findContact in includes/wf_crm_webform_base.inc
Find an existing contact based on matching criteria Used to populate a webform existing contact field

File

includes/contact_component.inc, line 1019

Code

function wf_crm_find_case_roles($contact_a, $case, $case_role) {
  if ($case_role == 'case_client') {

    // spl handling; this is not a relationship
    $result = civicrm_api3('Case', 'get', [
      'sequential' => 1,
      'id' => $case,
      'return' => [
        "contact_id",
      ],
    ]);
    if (isset($result['values'][0]['client_id'])) {
      $firstCaseClient = reset($result['values'][0]['client_id']);
      return array(
        $firstCaseClient => $firstCaseClient,
      );
    }
    return array();
  }
  $params = array(
    'sequential' => 1,
    'return' => [
      "contact_id_b",
    ],
    'relationship_type_id' => $case_role,
    'contact_id_a' => $contact_a,
    'case_id' => $case,
  );
  $result = wf_civicrm_api('Relationship', 'get', $params);
  if (isset($result['values'][0]['contact_id_b'])) {
    return array(
      $result['values'][0]['contact_id_b'] => $result['values'][0]['contact_id_b'],
    );
  }
  return array();
}