You are here

function webform_civicrm_get_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_relationship_types()

Get relationship type data

3 calls to webform_civicrm_get_relationship_types()
webform_civicrm_configure_form_builder in ./webform_civicrm_admin.inc
Form to configure CiviCRM options for a Webform Called indirectly from hook_menu() for D7-D6 compatibility
webform_civicrm_get_contact_relationship_types in ./webform_civicrm_utils.inc
Get valid relationship types for a given pair of contacts
webform_civicrm_process_submission in ./webform_civicrm_forms.inc
Webform submission handler Create/update CiviCRM contacts and related data Called by presave, insert and update webform hooks

File

./webform_civicrm_utils.inc, line 247
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_relationship_types() {
  static $types = array();
  if (!$types) {
    $f = array(
      'id',
      'name_a_b',
      'name_b_a',
      'label_a_b',
      'label_b_a',
      'type_a',
      'type_b',
      'sub_type_a',
      'sub_type_b',
    );
    $sql = '
      SELECT id, name_a_b, name_b_a, label_a_b, label_b_a, LOWER(contact_type_a) AS type_a, LOWER(contact_type_b) AS type_b, contact_sub_type_a AS sub_type_a, contact_sub_type_b AS sub_type_b
      FROM civicrm_relationship_type
      WHERE is_active <> 0';
    $dao =& CRM_Core_DAO::executeQuery($sql);
    while ($dao
      ->fetch()) {
      foreach ($f as $field) {
        $types[$dao->id][$field] = $dao->{$field};
      }

      // Create a pseudo relationship type for "current employer"
      if ($dao->name_a_b == 'Employee of' && $dao->name_b_a == 'Employer of') {
        $types['ce'] = $types[$dao->id];
        $types['ce']['id'] = 'ce';
        $types['ce']['label_a_b'] = t('Current Employee of');
        $types['ce']['label_b_a'] = t('Current Employer of');
      }
    }
  }
  return $types;
}