Some additional comments in Contribute/Summary. Added Campaign functionality to Membe...
authorChris Doten <cdoten@ndi.org>
Sat, 4 May 2013 23:51:23 +0000 (23:51 +0000)
committerChris Doten <cdoten@ndi.org>
Sat, 4 May 2013 23:51:23 +0000 (23:51 +0000)
CRM/Report/Form/Contribute/Summary.php
CRM/Report/Form/Member/Summary.php

index 4c0fbaf7717e1eb21fd85f6ebb9c0e927aca7670..e242505533324a6497bb4d5a7a52f97d3cc8512f 100644 (file)
@@ -48,13 +48,16 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
   public $_drilldownReport = array('contribute/detail' => 'Link to Detail Report');
 
   function __construct() {
-    $config = CRM_Core_Config::singleton();
+         
+       // 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(
@@ -215,6 +218,7 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
       ),
     ) + $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(
@@ -589,7 +593,7 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
         $entryFound = TRUE;
       }
 
-      // convert campaign_id to campaign title
+      // If using campaigns, 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];
@@ -598,7 +602,6 @@ class CRM_Report_Form_Contribute_Summary extends CRM_Report_Form {
       }
       $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s) for this ') ? TRUE : $entryFound;
 
-
       // skip looking further in rows, if first row itself doesn't
       // have the column we need
       if (!$entryFound) {
index b24d6dd918cdd37956523649eafc2a1147d87f4c..71255140755f80937372da90564a07d321d12747 100644 (file)
@@ -49,9 +49,19 @@ class CRM_Report_Form_Member_Summary extends CRM_Report_Form {
   protected $_customGroupGroupBy = FALSE; 
   public $_drilldownReport = array('member/detail' => 'Link to Detail Report');
 
-  function __construct() {
+  function __construct() {  
+         
     // UI for selecting columns to appear in the report list
-    // array conatining the columns, group_bys and filters build and provided to Form
+    // Array containing the columns, group_bys and filters build and provided to Form
+
+       // 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_membership' =>
@@ -164,6 +174,22 @@ class CRM_Report_Form_Member_Summary extends CRM_Report_Form {
       ),
     );
     $this->_tagFilter = TRUE;
+    
+    // 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->_columns['civicrm_membership']['grouping']['campaign_id'] = 'contri-fields';
+      $this->_columns['civicrm_membership']['group_bys']['campaign_id'] = array('title' => ts('Campaign'));
+    }
+    
+    
     $this->_groupFilter = TRUE;
     $this->_currencyColumn = 'civicrm_contribution_currency';
     parent::__construct();
@@ -613,6 +639,15 @@ GROUP BY    {$this->_aliases['civicrm_contribution']}.currency
         $rows[$rowNum]['civicrm_membership_membership_type_id'] = '<b>SubTotal</b>';
         $entryFound = TRUE;
       }
+      
+      
+      // 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