Skip to content

Commit

Permalink
Merge pull request civicrm#13341 from yashodha/campaign_reports
Browse files Browse the repository at this point in the history
add suport for order by clause for campaign and clean up
  • Loading branch information
seamuslee001 authored Dec 21, 2018
2 parents 1a47d07 + 9db913d commit 349c18c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4276,9 +4276,14 @@ public function addCampaignFields($entityTable = 'civicrm_contribution', $groupB
'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'));
}
}
}
}
Expand Down
28 changes: 3 additions & 25 deletions CRM/Report/Form/Contribute/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -354,21 +345,8 @@ public function __construct() {
$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();
Expand Down Expand Up @@ -723,7 +701,7 @@ public function alterDisplay(&$rows) {
// 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;
}
}
Expand Down

0 comments on commit 349c18c

Please sign in to comment.