add suport for order by clause for campaign and clean up
authoryashodha <yashodha@cividesk.com>
Fri, 21 Dec 2018 12:40:39 +0000 (18:10 +0530)
committeryashodha <yashodha@cividesk.com>
Fri, 21 Dec 2018 12:40:39 +0000 (18:10 +0530)
CRM/Report/Form.php
CRM/Report/Form/Contribute/Detail.php

index 4ff07aad457149b785bb4b5972f47e598c9f349e..479cb1670c1e0939278e2ece8101843ac650aa7f 100644 (file)
@@ -4276,9 +4276,14 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a
             'type' => CRM_Utils_Type::T_INT,
           );
         }
+
         if ($groupBy) {
           $this->_columns[$entityTable]['group_bys']['campaign_id'] = array('title' => ts('Campaign'));
         }
+
+        if ($orderBy) {
+          $this->_columns[$entityTable]['order_bys']['campaign_id'] = array('title' => ts('Campaign'));
+        }
       }
     }
   }
index 5764cbd911ed676b28b602fd8099da06a34ba1ad..f2f6b67f5c6349ca8f6e46d6acff6e272f70f357 100644 (file)
@@ -86,15 +86,6 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
    */
   public function __construct() {
     $this->_autoIncludeIndexedFieldsAsOrderBys = 1;
-    // 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);
-      $this->activeCampaigns = $getCampaigns['campaigns'];
-      asort($this->activeCampaigns);
-    }
-
     $this->_columns = array_merge($this->getColumns('Contact', array(
       'order_bys_defaults' => array('sort_name' => 'ASC '),
       'fields_defaults' => array('sort_name'),
@@ -354,21 +345,8 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
     $this->_columns['civicrm_contact']['fields']['sort_name']['title'] = ts('Donor Name');
     $this->_groupFilter = TRUE;
     $this->_tagFilter = TRUE;
-
-    // If we have active campaigns add those elements to both the fields and filters
-    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,
-        'type' => CRM_Utils_Type::T_INT,
-      );
-      $this->_columns['civicrm_contribution']['order_bys']['campaign_id'] = array('title' => ts('Campaign'));
-    }
+    // If we have campaigns enabled, add those elements to both the fields, filters and sorting
+    $this->addCampaignFields('civicrm_contribution', FALSE, TRUE);
 
     $this->_currencyColumn = 'civicrm_contribution_currency';
     parent::__construct();
@@ -723,7 +701,7 @@ UNION ALL
       // 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];
+          $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->campaigns[$value];
           $entryFound = TRUE;
         }
       }