(dev/core#491) campaign cleanup for member summary report and show disabled campaigns...
authoryashodha <yashodha@cividesk.com>
Wed, 2 Jan 2019 11:39:36 +0000 (17:09 +0530)
committeryashodha <yashodha@cividesk.com>
Wed, 2 Jan 2019 11:39:36 +0000 (17:09 +0530)
CRM/Report/Form/Member/Summary.php

index 91c0e7fafbf4ad0f7b280b782eb69dec8d966c08..ee9c74337c6b82ac9b971a9fed414f1ef7d095a8 100644 (file)
@@ -62,19 +62,6 @@ class CRM_Report_Form_Member_Summary extends CRM_Report_Form {
    * Class constructor.
    */
   public function __construct() {
-
-    // UI for selecting columns to appear in the report list
-    // 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' => array(
         'dao' => 'CRM_Member_DAO_MembershipType',
@@ -186,20 +173,8 @@ 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' => ts('Campaign'),
-        'default' => 'false',
-      );
-      $this->_columns['civicrm_membership']['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_membership']['group_bys']['campaign_id'] = array('title' => ts('Campaign'));
-    }
+    // If we have campaigns enabled, add those elements to both the fields, filters and group by
+    $this->addCampaignFields('civicrm_membership', TRUE);
 
     $this->_groupFilter = TRUE;
     $this->_currencyColumn = 'civicrm_contribution_currency';
@@ -642,7 +617,7 @@ GROUP BY    {$this->_aliases['civicrm_contribution']}.currency
       // 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];
+          $rows[$rowNum]['civicrm_membership_campaign_id'] = $this->campaigns[$value];
         }
         $entryFound = TRUE;
       }