You are here

function wf_crm_get_empty_sets in Webform CiviCRM Integration 7.4

Same name and namespace in other branches
  1. 7.5 includes/utils.inc \wf_crm_get_empty_sets()

Returns empty custom civicrm field sets

Return value

array $sets

2 calls to wf_crm_get_empty_sets()
wf_crm_admin_form::postProcess in includes/wf_crm_admin_form.inc
Submission handler, saves CiviCRM options for a Webform node
wf_crm_get_fields in includes/utils.inc
Fetches CiviCRM field data.

File

includes/utils.inc, line 1739
Webform CiviCRM module's common utility functions.

Code

function wf_crm_get_empty_sets() {
  $sets = array();
  $sql = "SELECT cg.id, cg.title, cg.help_pre, cg.extends, SUM(cf.is_active) as custom_field_sum\n          FROM civicrm_custom_group cg\n          LEFT OUTER JOIN civicrm_custom_field cf\n          ON (cg.id = cf.custom_group_id)\n          GROUP By cg.id";
  $dao = CRM_Core_DAO::executeQuery($sql);
  while ($dao
    ->fetch()) {

    // Because a set with all fields disabled = empty set
    if (empty($dao->custom_field_sum)) {
      $set = 'cg' . $dao->id;
      if ($dao->extends == 'address' || $dao->extends == 'relationship' || $dao->extends == 'membership') {
        $set = $dao->extends;
      }
      $sets[$set] = array(
        'label' => $dao->title,
        'entity_type' => strtolower($dao->extends),
        'help_text' => $dao->help_pre,
      );
    }
  }
  return $sets;
}