You are here

private function wf_crm_webform_preprocess::findExistingCases in Webform CiviCRM Integration 7.4

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

Find case ids based on url input or "existing case" settings

1 call to wf_crm_webform_preprocess::findExistingCases()
wf_crm_webform_preprocess::alterForm in includes/wf_crm_webform_preprocess.inc
Alter front-end of webforms: Called by hook_form_alter() when rendering a civicrm-enabled webform Add custom prefix. Display messages. Block users who should not have access. Set webform default values.

File

includes/wf_crm_webform_preprocess.inc, line 651

Class

wf_crm_webform_preprocess

Code

private function findExistingCases() {

  // Support legacy url param
  if (empty($_GET["case1"]) && !empty($_GET["caseid"])) {
    $_GET["case1"] = $_GET["caseid"];
  }
  for ($n = 1; $n <= $this->data['case']['number_of_case']; ++$n) {
    if (!empty($this->data['case'][$n]['case'][1]['client_id'])) {
      $clients = array();
      foreach ((array) $this->data['case'][$n]['case'][1]['client_id'] as $c) {
        if (!empty($this->ent['contact'][$c]['id'])) {
          $clients[] = $this->ent['contact'][$c]['id'];
        }
      }
      if ($clients) {

        // Populate via url argument
        if (isset($_GET["case{$n}"]) && wf_crm_is_positive($_GET["case{$n}"])) {
          $id = $_GET["case{$n}"];
          $item = wf_civicrm_api('case', 'getsingle', array(
            'id' => $id,
          ));
          if (array_intersect((array) wf_crm_aval($item, 'client_id'), $clients)) {
            $this->ent['case'][$n] = array(
              'id' => $id,
            );
          }
        }
        elseif (!empty($this->data['case'][$n]['existing_case_status'])) {
          $item = $this
            ->findCaseForContact($clients, array(
            'case_type_id' => wf_crm_aval($this->data['case'][$n], 'case:1:case_type_id'),
            'status_id' => $this->data['case'][$n]['existing_case_status'],
          ));
          if ($item) {
            $this->ent['case'][$n] = array(
              'id' => $item['id'],
            );
          }
        }
      }
    }
  }
}