You are here

function WebformCivicrmBase::findCaseForContact in Webform CiviCRM Integration 8.5

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

3 calls to WebformCivicrmBase::findCaseForContact()
WebformCivicrmPostProcess::processActivities in src/WebformCivicrmPostProcess.php
Save activity data
WebformCivicrmPostProcess::processCases in src/WebformCivicrmPostProcess.php
Save case data
WebformCivicrmPreProcess::findExistingCases in src/WebformCivicrmPreProcess.php
Find case ids based on url input or "existing case" settings

File

src/WebformCivicrmBase.php, line 713
Front-end form handler base class.

Class

WebformCivicrmBase
Class WebformCivicrmBase

Namespace

Drupal\webform_civicrm

Code

function findCaseForContact($cid, $filters) {
  $case = NULL;
  $utils = \Drupal::service('webform_civicrm.utils');
  foreach ($utils
    ->wf_crm_apivalues('case', 'get', [
    '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;
}