You are here

private function wf_crm_admin_form::filterCaseSets in Webform CiviCRM Integration 7.4

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

Adjust case role fields to match creator/manager settings for a given case type

Parameters

int|null $case_type:

Return value

array

1 call to wf_crm_admin_form::filterCaseSets()
wf_crm_admin_form::buildCaseTab in includes/wf_crm_admin_form.inc
Case settings FIXME: This is exactly the same code as buildGrantTab. More utilities and less boilerplate needed.

File

includes/wf_crm_admin_form.inc, line 680
Webform CiviCRM module's admin form.

Class

wf_crm_admin_form
@file Webform CiviCRM module's admin form.

Code

private function filterCaseSets($case_type) {
  $case_sets = array();
  foreach ($this->sets as $sid => $set) {
    if ($set['entity_type'] == 'case' && (!$case_type || empty($set['sub_types']) || in_array($case_type, $set['sub_types']))) {
      if ($sid == 'caseRoles') {

        // Lookup case-role names
        $creator = $manager = NULL;

        // Use the vanilla civicrm_api for this because it will throw an error in CiviCRM 4.4 (api doesn't exist)
        $case_types = civicrm_api('case_type', 'get', array(
          'version' => 3,
          'id' => $case_type,
          'options' => array(
            'limit' => 0,
          ),
        ));
        foreach (wf_crm_aval($case_types, 'values', array()) as $type) {
          foreach ($type['definition']['caseRoles'] as $role) {
            if (!empty($role['creator'])) {
              $creator = $creator == $role['name'] || $creator === NULL ? $role['name'] : FALSE;
            }
            if (!empty($role['manager'])) {
              $manager = $manager == $role['name'] || $manager === NULL ? $role['name'] : FALSE;
            }
          }
        }
        if ($creator) {
          $rel_type = wf_civicrm_api('relationshipType', 'getsingle', array(
            'name_b_a' => $creator,
          ));
          $label = $creator == $manager ? ts('Case # Creator/Manager') : ts('Case # Creator');
          $set['fields']['case_creator_id']['name'] = $rel_type['label_b_a'] . ' (' . $label . ')';
          unset($set['fields']['case_role_' . $rel_type['id']]);
        }
        if ($manager && $manager != $creator) {
          $rel_type = wf_civicrm_api('relationshipType', 'getsingle', array(
            'name_b_a' => $manager,
          ));
          $set['fields']['case_role_' . $rel_type['id']]['name'] .= ' (' . ts('Case # Manager') . ')';
        }
      }
      $case_sets[$sid] = $set;
    }
  }
  return $case_sets;
}