You are here

function wf_crm_webform_base::findCaseForContact in Webform CiviCRM Integration 7.4

Same name and namespace in other branches
  1. 7.5 includes/wf_crm_webform_base.inc \wf_crm_webform_base::findCaseForContact()

Find a case matching criteria

Normally we could do this by passing filters into the api, but legacy case api doesn't support them So instead we fetch every case for the contact and loop through them to test against filters.

Parameters

array|int $cid:

array $filters:

Return value

null|array

2 calls to wf_crm_webform_base::findCaseForContact()
wf_crm_webform_postprocess::processActivities in includes/wf_crm_webform_postprocess.inc
Save activity data
wf_crm_webform_preprocess::findExistingCases in includes/wf_crm_webform_preprocess.inc
Find case ids based on url input or "existing case" settings

File

includes/wf_crm_webform_base.inc, line 854

Class

wf_crm_webform_base
Class wf_crm_webform_base

Code

function findCaseForContact($cid, $filters) {
  $case = NULL;
  foreach (wf_crm_apivalues('case', 'get', array(
    'client_id' => $cid,
  )) as $item) {
    if (empty($item['is_deleted'])) {
      $match = TRUE;
      foreach (array_filter($filters) as $filter => $value) {
        if (!array_intersect((array) $item[$filter], (array) $value)) {
          $match = FALSE;
        }
      }

      // Note: this loop has no break on purpose - this way we find the most recent case instead of stopping at the first
      if ($match) {
        $case = $item;
      }
    }
  }
  return $case;
}