You are here

function webform_civicrm_get_contact_relationship_types in Webform CiviCRM Integration 7.2

Same name and namespace in other branches
  1. 6.2 webform_civicrm_utils.inc \webform_civicrm_get_contact_relationship_types()

Get valid relationship types for a given pair of contacts

1 call to webform_civicrm_get_contact_relationship_types()
webform_civicrm_field_options in ./webform_civicrm_utils.inc
Get options for a specific field @Param $field: Webform component array @Param $context: Where is this being called from? @Param $data: CiviCRM entity data

File

./webform_civicrm_utils.inc, line 276
Webform CiviCRM module's common utility functions. The code in this file is cross-compatible with D6/Civi3 and D7/Civi4 Drupal-version-specific functions belong in webform_civicrm_dx_functions.inc

Code

function webform_civicrm_get_contact_relationship_types($type_a, $type_b, $sub_type_a, $sub_type_b) {
  $ret = array();
  foreach (webform_civicrm_get_relationship_types() as $t) {
    if (($t['type_a'] == $type_a || !$t['type_a']) && ($t['type_b'] == $type_b || !$t['type_b']) && (in_array($t['sub_type_a'], $sub_type_a) || !$t['sub_type_a']) && (in_array($t['sub_type_b'], $sub_type_b) || !$t['sub_type_b'])) {
      $ret[$t['id'] . '_a'] = $t['label_a_b'];
    }

    // Reciprocal form - only show if different from above
    if (($t['type_a'] == $type_b || !$t['type_a']) && ($t['type_b'] == $type_a || !$t['type_b']) && (in_array($t['sub_type_a'], $sub_type_b) || !$t['sub_type_a']) && (in_array($t['sub_type_b'], $sub_type_a) || !$t['sub_type_b']) && ($t['label_a_b'] != $t['label_b_a'] && $t['label_b_a'] || $t['type_a'] != $t['type_b'])) {
      $ret[$t['id'] . '_b'] = $t['label_b_a'];
    }
  }
  return $ret;
}