You are here

function Utils::wf_crm_get_empty_sets in Webform CiviCRM Integration 8.5

Returns empty custom civicrm field sets

Return value

array $sets

Overrides UtilsInterface::wf_crm_get_empty_sets

File

src/Utils.php, line 881
Webform CiviCRM module's common utility functions.

Class

Utils

Namespace

Drupal\webform_civicrm

Code

function wf_crm_get_empty_sets() {
  $sets = [];
  $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] = [
        'label' => $dao->title,
        'entity_type' => strtolower($dao->extends),
        'help_text' => $dao->help_pre,
      ];
    }
  }
  return $sets;
}