/**
  * Function to return singleton object
  * 
  * @return object $_singleton
  * @access public
  * @static
  */
 public static function &singleton()
 {
     if (self::$_singleton === NULL) {
         self::$_singleton = new CRM_Lidmaatschapbijdragerapport_Config();
     }
     return self::$_singleton;
 }
 function __construct()
 {
     // Check if CiviCampaign is a) enabled and b) has active campaigns
     $config = CRM_Core_Config::singleton();
     $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
     if ($campaignEnabled) {
         $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
         $this->activeCampaigns = $getCampaigns['campaigns'];
         asort($this->activeCampaigns);
     }
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('sort_name' => array('title' => ts('Contact Name'), 'no_repeat' => TRUE, 'default' => TRUE), 'first_name' => array('title' => ts('First Name'), 'default' => TRUE), 'middle_name' => array('title' => ts('Middle Name'), 'default' => TRUE), 'last_name' => array('title' => ts('Last Name'), 'default' => TRUE), 'postal_greeting_display' => array('title' => ts('Postal Greeting')), 'id' => array('no_display' => TRUE, 'required' => TRUE), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact SubType'))), 'grouping' => 'contact-fields', 'group_bys' => array('id' => array('title' => ts('Contact ID'), 'default' => TRUE), 'sort_name' => array('title' => ts('Contact Name')))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => TRUE, 'default' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => TRUE, 'default' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_financial_type' => array('dao' => 'CRM_Financial_DAO_FinancialType', 'fields' => array('financial_type' => null), 'grouping' => 'contri-fields', 'group_bys' => array('financial_type' => array('title' => ts('Financial Type')))), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_source' => array('title' => ts('Source')), 'currency' => array('required' => TRUE, 'no_display' => TRUE), 'total_amount' => array('title' => ts('Contribution Amount Stats'), 'default' => TRUE, 'statistics' => array('sum' => ts('Contributions Aggregate'), 'count' => ts('Contributions'), 'avg' => ts('Contributions Avg')))), 'grouping' => 'contri-fields', 'filters' => array('receive_date' => array('title' => ts('Receive Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'default' => '0'), 'contribution_status_id' => array('title' => ts('Donation Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(1), 'type' => CRM_Utils_Type::T_INT), 'currency' => array('title' => 'Currency', 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING), 'financial_type_id' => array('title' => ts('Financial Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::financialType(), 'type' => CRM_Utils_Type::T_INT), 'contribution_page_id' => array('title' => ts('Contribution Page'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionPage(), 'type' => CRM_Utils_Type::T_INT), 'total_amount' => array('title' => ts('Contribution Amount')), 'total_sum' => array('title' => ts('Contributions Aggregate'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_total_amount_sum', 'having' => TRUE), 'total_count' => array('title' => ts('Contributions Count'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_total_amount_count', 'having' => TRUE), 'total_avg' => array('title' => ts('Contributions Avg'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_total_amount_avg', 'having' => TRUE)), 'group_bys' => array('receive_date' => array('frequency' => TRUE, 'default' => TRUE, 'chart' => TRUE), 'contribution_source' => NULL)), 'civicrm_contribution_soft' => array('dao' => 'CRM_Contribute_DAO_ContributionSoft', 'fields' => array('soft_amount' => array('title' => ts('Soft Credit Amount Stats'), 'name' => 'amount', 'statistics' => array('sum' => ts('Soft Credit Aggregate'), 'count' => ts('Soft Credits'), 'avg' => ts('Soft Credit Avg')))), 'grouping' => 'contri-fields', 'filters' => array('amount' => array('title' => ts('Soft Credit Amount')), 'soft_sum' => array('title' => ts('Soft Credit Aggregate'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_soft_soft_amount_sum', 'having' => TRUE), 'soft_count' => array('title' => ts('Soft Credits Count'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_soft_soft_amount_count', 'having' => TRUE), 'soft_avg' => array('title' => ts('Soft Credit Avg'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_soft_soft_amount_avg', 'having' => TRUE))), 'civicrm_group' => array('dao' => 'CRM_Contact_DAO_GroupContact', 'alias' => 'cgroup', 'filters' => array('gid' => array('name' => 'group_id', 'title' => ts('Group'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'group' => TRUE, 'options' => CRM_Core_PseudoConstant::group(), 'type' => CRM_Utils_Type::T_INT)))) + $this->addAddressFields();
     // If we have a campaign, build out the relevant elements
     $this->_tagFilter = TRUE;
     if ($campaignEnabled && !empty($this->activeCampaigns)) {
         $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array('title' => 'Campaign', 'default' => 'false');
         $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activeCampaigns);
         $this->_columns['civicrm_contribution']['group_bys']['campaign_id'] = array('title' => ts('Campaign'));
     }
     /*
      * BOSW1508247 vnv.nl - exporteren data clubcollect
      * Hack uncheck land field
      */
     $this->_columns['civicrm_address']['fields']['street_address']['default'] = TRUE;
     $this->_columns['civicrm_address']['fields']['supplemental_address_1']['default'] = TRUE;
     $this->_columns['civicrm_address']['fields']['supplemental_address_2']['default'] = TRUE;
     $this->_columns['civicrm_address']['fields']['postal_code']['default'] = TRUE;
     $this->_columns['civicrm_address']['fields']['city']['default'] = TRUE;
     $this->_currencyColumn = 'civicrm_contribution_currency';
     parent::__construct();
     /*
      * BOSW1508247 vnv.nl - exporteren data clubcollect
      * Add country name or the country id will show in the Preview Excel 
      */
     // hide country_id field
     $this->_columns['civicrm_address']['fields']['country_id'] = array('no_display' => TRUE, 'required' => TRUE);
     // add country field
     $this->_columns['civicrm_country'] = array('dao' => 'CRM_Core_DAO_County', 'grouping' => 'location-fields', 'fields' => array('civicrm_country_name' => array('title' => ts('Country'), 'default' => TRUE, 'dbAlias' => 'country_civireport.name')));
     /*
      * BOSW1508247 vnv.nl - exporteren data clubcollect
      * Membership
      */
     // add membership for lidmaatschap
     $this->_columns['civicrm_membership'] = array('dao' => 'CRM_Member_DAO_Membership', 'grouping' => 'civicrm_membership', 'group_title' => ts('Membership'), 'fields' => array('id' => array('no_display' => TRUE, 'title' => ts('Membership Id'), 'required' => TRUE, 'no_repeat' => TRUE), 'membership_type_id' => array('no_display' => TRUE, 'title' => ts('Membership Type'), 'default' => TRUE, 'required' => TRUE), 'membership_start_date' => array('title' => ts('Start Date')), 'membership_end_date' => array('title' => ts('End Date')), 'join_date' => array('title' => ts('Join Date')), 'source' => array('title' => 'Source')));
     $this->_columns['civicrm_membership_type'] = array('dao' => 'CRM_Member_DAO_MembershipType', 'grouping' => 'civicrm_membership', 'group_title' => ts('Membership'), 'fields' => array('name' => array('title' => ts('Membership Type'), 'default' => TRUE)));
     /*
      * BOSW1508247 vnv.nl - exporteren data clubcollect
      * Lidmaatschap - Maatschappij
      */
     $lidmaatschapbijdrage_config = CRM_Lidmaatschapbijdragerapport_Config::singleton();
     $lidmaatschap_custom_group = $lidmaatschapbijdrage_config->get_lidmaatschap_custom_group();
     // add the Lidmaatschap - Maatschappij
     $this->_columns[$lidmaatschap_custom_group['table_name']] = array('dao' => 'CRM_Contact_DAO_Contact', 'extends' => 'Membership', 'grouping' => $lidmaatschap_custom_group['table_name'], 'group_title' => $lidmaatschap_custom_group['title'], 'fields' => array());
     // add the Lidmaatschap - Maatschappij fields
     foreach ($lidmaatschapbijdrage_config->get_lidmaatschap_custom_fields() as $custom_field_id => $custom_field) {
         $this->_columns[$lidmaatschap_custom_group['table_name']]['fields']['custom_' . $custom_field_id] = array('name' => strtolower($custom_field['name']) . '_' . $custom_field_id, 'title' => $custom_field['label']);
         // check only lidnr and
         if ('lidnr' == $custom_field['name']) {
             $this->_columns[$lidmaatschap_custom_group['table_name']]['fields']['custom_' . $custom_field_id]['default'] = TRUE;
         }
     }
 }