From 689c6bd28fbd7eaeb1264c3f6fb7d8fa8bf111ee Mon Sep 17 00:00:00 2001 From: yashodha Date: Wed, 5 Dec 2018 10:17:52 +0530 Subject: [PATCH] clean up campaigns for reports --- CRM/Report/Form.php | 36 +++++++++++++++++++++++++++ CRM/Report/Form/Contribute/Lybunt.php | 23 +---------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 8286f49d9e..f005e472f8 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -4247,6 +4247,42 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a return $this->_selectedTables; } + /** + * Add campaign fields. + * + * @param bool $groupBy + * Add GroupBy? Not appropriate for detail report. + * @param bool $orderBy + * Add OrderBy? Not appropriate for detail report. + * @param bool $filters + * + */ + public function addCampaignFields($entityTable = 'civicrm_contribution', $groupBy = FALSE, $orderBy = FALSE, $filters = TRUE) { + // 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, FALSE, FALSE, TRUE); + // If we have a campaign, build out the relevant elements + if (!empty($getCampaigns['campaigns'])) { + $campaigns = $getCampaigns['campaigns']; + asort($campaigns); + $this->_columns[$entityTable]['fields']['campaign_id'] = array('title' => ts('Campaign'), 'default' => 'false'); + if ($filters) { + $this->_columns[$entityTable]['filters']['campaign_id'] = array( + 'title' => ts('Campaign'), + 'operatorType' => CRM_Report_Form::OP_MULTISELECT, + 'options' => $campaigns, + 'type' => CRM_Utils_Type::T_INT, + ); + } + if ($groupBy) { + $this->_columns[$entityTable]['group_bys']['campaign_id'] = array('title' => ts('Campaign')); + } + } + } + } + /** * Add address fields. * diff --git a/CRM/Report/Form/Contribute/Lybunt.php b/CRM/Report/Form/Contribute/Lybunt.php index f7f9fca90d..03e89d2d69 100644 --- a/CRM/Report/Form/Contribute/Lybunt.php +++ b/CRM/Report/Form/Contribute/Lybunt.php @@ -89,15 +89,6 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { $date['minYear']++; } - // 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', @@ -271,19 +262,7 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { ); // If we have a campaign, build out the relevant elements - if ($campaignEnabled && !empty($this->activeCampaigns)) { - $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array( - 'title' => ts('Campaign'), - 'default' => 'false', - 'type' => CRM_Utils_Type::T_INT, - ); - $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array( - 'title' => ts('Campaign'), - 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => $this->activeCampaigns, - 'type' => CRM_Utils_Type::T_INT, - ); - } + $this->addCampaignFields('civicrm_contribution'); $this->_groupFilter = TRUE; $this->_tagFilter = TRUE; -- 2.25.1