From d62fab339058139136fff203cbd95ce6cfe2e0e9 Mon Sep 17 00:00:00 2001 From: Ravish Nair Date: Thu, 9 May 2013 10:27:49 +0530 Subject: [PATCH] -- CRM-12528 Added campaign column and filter to reports --- CRM/Report/Form/Contribute/Lybunt.php | 29 ++++++++++++++++++++++ CRM/Report/Form/Contribute/SoftCredit.php | 30 +++++++++++++++++++++++ CRM/Report/Form/Contribute/Sybunt.php | 29 ++++++++++++++++++++++ CRM/Report/Form/Member/Lapse.php | 30 +++++++++++++++++++++++ CRM/Report/Form/Pledge/Pbnp.php | 30 +++++++++++++++++++++++ templates/CRM/Report/Form/Criteria.tpl | 4 +-- 6 files changed, 150 insertions(+), 2 deletions(-) diff --git a/CRM/Report/Form/Contribute/Lybunt.php b/CRM/Report/Form/Contribute/Lybunt.php index 8065b49906..00b4caaf99 100644 --- a/CRM/Report/Form/Contribute/Lybunt.php +++ b/CRM/Report/Form/Contribute/Lybunt.php @@ -56,6 +56,15 @@ 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( @@ -170,6 +179,18 @@ 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', + ); + $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'), + 'operatorType' => CRM_Report_Form::OP_MULTISELECT, + 'options' => $this->activeCampaigns, + ); + } + $this->_tagFilter = TRUE; parent::__construct(); } @@ -431,6 +452,14 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contribution Details for this Contact."); } + + // convert campaign_id to campaign title + if (array_key_exists('civicrm_contribution_campaign_id', $row)) { + if ($value = $row['civicrm_contribution_campaign_id']) { + $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value]; + $entryFound = TRUE; + } + } } } diff --git a/CRM/Report/Form/Contribute/SoftCredit.php b/CRM/Report/Form/Contribute/SoftCredit.php index 9b9d58fb9d..ea25ca53c5 100644 --- a/CRM/Report/Form/Contribute/SoftCredit.php +++ b/CRM/Report/Form/Contribute/SoftCredit.php @@ -48,6 +48,16 @@ class CRM_Report_Form_Contribute_SoftCredit extends CRM_Report_Form { public $_drilldownReport = array('contribute/detail' => 'Link to Detail Report'); 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( @@ -226,6 +236,18 @@ class CRM_Report_Form_Contribute_SoftCredit 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', + ); + $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'), + 'operatorType' => CRM_Report_Form::OP_MULTISELECT, + 'options' => $this->activeCampaigns, + ); + } + $this->_tagFilter = TRUE; $this->_currencyColumn = 'civicrm_contribution_currency'; @@ -476,6 +498,14 @@ GROUP BY {$this->_aliases['civicrm_contribution']}.currency $entryFound = TRUE; } + // convert campaign_id to campaign title + if (array_key_exists('civicrm_contribution_campaign_id', $row)) { + if ($value = $row['civicrm_contribution_campaign_id']) { + $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value]; + $entryFound = TRUE; + } + } + // skip looking further in rows, if first row itself doesn't // have the column we need if (!$entryFound) { diff --git a/CRM/Report/Form/Contribute/Sybunt.php b/CRM/Report/Form/Contribute/Sybunt.php index ff5f5a87f2..e6362c4a30 100644 --- a/CRM/Report/Form/Contribute/Sybunt.php +++ b/CRM/Report/Form/Contribute/Sybunt.php @@ -53,6 +53,15 @@ class CRM_Report_Form_Contribute_Sybunt 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( @@ -166,6 +175,18 @@ class CRM_Report_Form_Contribute_Sybunt 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', + ); + $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'), + 'operatorType' => CRM_Report_Form::OP_MULTISELECT, + 'options' => $this->activeCampaigns, + ); + } + $this->_tagFilter = TRUE; parent::__construct(); } @@ -445,6 +466,14 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contribution Details for this Contact."); } + + // convert campaign_id to campaign title + if (array_key_exists('civicrm_contribution_campaign_id', $row)) { + if ($value = $row['civicrm_contribution_campaign_id']) { + $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value]; + $entryFound = TRUE; + } + } } } diff --git a/CRM/Report/Form/Member/Lapse.php b/CRM/Report/Form/Member/Lapse.php index 5ea8fddf28..01c69c0b95 100644 --- a/CRM/Report/Form/Member/Lapse.php +++ b/CRM/Report/Form/Member/Lapse.php @@ -46,6 +46,16 @@ class CRM_Report_Form_Member_Lapse extends CRM_Report_Form { public $_drilldownReport = array('member/detail' => 'Link to Detail Report'); 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); + } + // UI for selecting columns to appear in the report list // array conatining the columns, group_bys and filters build and provided to Form $this->_columns = array( @@ -190,6 +200,18 @@ class CRM_Report_Form_Member_Lapse extends CRM_Report_Form { ), ); + // If we have a campaign, build out the relevant elements + if ($campaignEnabled && !empty($this->activeCampaigns)) { + $this->_columns['civicrm_membership']['fields']['campaign_id'] = array( + 'title' => 'Campaign', + 'default' => 'false', + ); + $this->_columns['civicrm_membership']['filters']['campaign_id'] = array('title' => ts('Campaign'), + 'operatorType' => CRM_Report_Form::OP_MULTISELECT, + 'options' => $this->activeCampaigns, + ); + } + $this->_tagFilter = TRUE; parent::__construct(); } @@ -416,6 +438,14 @@ class CRM_Report_Form_Member_Lapse extends CRM_Report_Form { $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Membership Detail for this Contact."); } + // If using campaigns, convert campaign_id to campaign title + if (array_key_exists('civicrm_membership_campaign_id', $row)) { + if ($value = $row['civicrm_membership_campaign_id']) { + $rows[$rowNum]['civicrm_membership_campaign_id'] = $this->activeCampaigns[$value]; + } + $entryFound = TRUE; + } + // skip looking further in rows, if first row itself doesn't // have the column we need if (!$entryFound) { diff --git a/CRM/Report/Form/Pledge/Pbnp.php b/CRM/Report/Form/Pledge/Pbnp.php index be9e362c6e..6418825648 100644 --- a/CRM/Report/Form/Pledge/Pbnp.php +++ b/CRM/Report/Form/Pledge/Pbnp.php @@ -46,6 +46,16 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form { 'Pledge'); 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( @@ -178,6 +188,18 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form { ), ); + // If we have a campaign, build out the relevant elements + if ($campaignEnabled && !empty($this->activeCampaigns)) { + $this->_columns['civicrm_pledge']['fields']['campaign_id'] = array( + 'title' => 'Campaign', + 'default' => 'false', + ); + $this->_columns['civicrm_pledge']['filters']['campaign_id'] = array('title' => ts('Campaign'), + 'operatorType' => CRM_Report_Form::OP_MULTISELECT, + 'options' => $this->activeCampaigns, + ); + } + $this->_tagFilter = TRUE; $this->_currencyColumn = 'civicrm_pledge_currency'; parent::__construct(); @@ -359,6 +381,14 @@ class CRM_Report_Form_Pledge_Pbnp extends CRM_Report_Form { $entryFound = TRUE; } + // If using campaigns, convert campaign_id to campaign title + if (array_key_exists('civicrm_pledge_campaign_id', $row)) { + if ($value = $row['civicrm_pledge_campaign_id']) { + $rows[$rowNum]['civicrm_pledge_campaign_id'] = $this->activeCampaigns[$value]; + } + $entryFound = TRUE; + } + // skip looking further in rows, if first row itself doesn't // have the column we need if (!$entryFound) { diff --git a/templates/CRM/Report/Form/Criteria.tpl b/templates/CRM/Report/Form/Criteria.tpl index bd6f67f548..d0bb580174 100644 --- a/templates/CRM/Report/Form/Criteria.tpl +++ b/templates/CRM/Report/Form/Criteria.tpl @@ -255,8 +255,8 @@ } function selectGroupByFields(id) { - var field = 'fields\['+ id+'\]'; - var group = 'group_bys\['+ id+'\]'; + var field = 'fields_'+ id; + var group = 'group_bys_'+ id; var groups = document.getElementById( group ).checked; if ( groups == 1 ) { document.getElementById( field ).checked = true; -- 2.25.1