(dev/core#491) Campaign Cleanup in Activity, Member Contribution Detail and Member...
authorSeamus Lee <seamuslee001@gmail.com>
Wed, 2 Jan 2019 20:32:55 +0000 (07:32 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Thu, 3 Jan 2019 21:16:04 +0000 (08:16 +1100)
CRM/Report/Form/Activity.php
CRM/Report/Form/Member/ContributionDetail.php
CRM/Report/Form/Member/Lapse.php

index 6be426c8c70be7c8595d0383e9564571058b39b2..b85b2b73efb2a3e437521b6f9c6fb32373ad6f8d 100644 (file)
@@ -66,9 +66,6 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
     $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
     $caseEnabled = in_array("CiviCase", $config->enableComponents);
     if ($campaignEnabled) {
-      $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
-      $this->activeCampaigns = $getCampaigns['campaigns'];
-      asort($this->activeCampaigns);
       $this->engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel();
     }
 
@@ -345,18 +342,9 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
         'operator' => 'like',
         'type' => CRM_Utils_Type::T_STRING,
       );
-      if (!empty($this->activeCampaigns)) {
-        $this->_columns['civicrm_activity']['fields']['campaign_id'] = array(
-          'title' => ts('Campaign'),
-          'default' => 'false',
-        );
-        $this->_columns['civicrm_activity']['filters']['campaign_id'] = array(
-          'title' => ts('Campaign'),
-          'type' => CRM_Utils_Type::T_INT,
-          'operatorType' => CRM_Report_Form::OP_MULTISELECT,
-          'options' => $this->activeCampaigns,
-        );
-      }
+      // If we have campaigns enabled, add those elements to both the fields, filters.
+      $this->addCampaignFields('civicrm_activity');
+
       if (!empty($this->engagementLevels)) {
         $this->_columns['civicrm_activity']['fields']['engagement_level'] = array(
           'title' => ts('Engagement Index'),
@@ -1033,7 +1021,7 @@ GROUP BY civicrm_activity_id $having {$this->_orderBy}";
 
       if (array_key_exists('civicrm_activity_campaign_id', $row)) {
         if ($value = $row['civicrm_activity_campaign_id']) {
-          $rows[$rowNum]['civicrm_activity_campaign_id'] = $this->activeCampaigns[$value];
+          $rows[$rowNum]['civicrm_activity_campaign_id'] = $this->campaigns[$value];
           $entryFound = TRUE;
         }
       }
index d5b7bfd5eca3c71594261090a334ac87684ef65d..519c23ef5a508b877f81cc044c56498709f997f2 100644 (file)
@@ -57,13 +57,6 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form {
    * Class constructor.
    */
   public function __construct() {
-    $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',
@@ -376,19 +369,8 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form {
     $this->_groupFilter = TRUE;
     $this->_tagFilter = TRUE;
 
-    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();
@@ -780,7 +762,7 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form {
       // 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;
         }
       }
index 503288b074b826ff3421b1234e74ba3f681499a8..4a7f744e74558199f94f16389b8f7004dcf40793 100644 (file)
@@ -58,16 +58,6 @@ class CRM_Report_Form_Member_Lapse extends CRM_Report_Form {
    * Class constructor.
    */
   public 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 containing the columns, group_bys and filters build and provided to Form
     $this->_columns = array(
@@ -177,19 +167,8 @@ 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' => 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,
-      );
-    }
+    // If we have campaigns enabled, add those elements to both the fields, filters.
+    $this->addCampaignFields('civicrm_membership');
 
     $this->_groupFilter = TRUE;
     $this->_tagFilter = TRUE;
@@ -392,7 +371,7 @@ class CRM_Report_Form_Member_Lapse extends CRM_Report_Form {
       // 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;
       }