Skip to content

Commit

Permalink
Fix fatal on topDonor report
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Apr 2, 2018
1 parent 0082105 commit c3fdd2b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 49 deletions.
60 changes: 30 additions & 30 deletions CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ public function addGroupBys() {
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('group_bys', $table)) {
foreach ($table['group_bys'] as $fieldName => $field) {
if (!empty($field)) {
if (!empty($field) && empty($field['no_display'])) {
$options[$field['title']] = $fieldName;
if (!empty($field['frequency'])) {
$freqElements[$field['title']] = $fieldName;
Expand Down Expand Up @@ -5191,45 +5191,45 @@ protected function buildColumns($specs, $tableName, $daoName = NULL, $tableAlias
*/
protected function storeGroupByArray() {

if (CRM_Utils_Array::value('group_bys', $this->_params) &&
is_array($this->_params['group_bys']) &&
!empty($this->_params['group_bys'])
) {
foreach ($this->_columns as $tableName => $table) {
$table = $this->_columns[$tableName];
if (array_key_exists('group_bys', $table)) {
foreach ($table['group_bys'] as $fieldName => $fieldData) {
$field = $this->_columns[$tableName]['metadata'][$fieldName];
if (!empty($this->_params['group_bys'][$fieldName])) {
if (!empty($field['chart'])) {
$this->assign('chartSupported', TRUE);
}
if (!CRM_Utils_Array::value('group_bys', $this->_params)
|| !is_array($this->_params['group_bys'])) {
$this->_params['group_bys'] = [];
}

if (!empty($table['group_bys'][$fieldName]['frequency']) &&
!empty($this->_params['group_bys_freq'][$fieldName])
) {
foreach ($this->_columns as $tableName => $table) {
$table = $this->_columns[$tableName];
if (array_key_exists('group_bys', $table)) {
foreach ($table['group_bys'] as $fieldName => $fieldData) {
$field = $this->_columns[$tableName]['metadata'][$fieldName];
if (!empty($this->_params['group_bys'][$fieldName]) || !empty($fieldData['required'])) {
if (!empty($field['chart'])) {
$this->assign('chartSupported', TRUE);
}

switch ($this->_params['group_bys_freq'][$fieldName]) {
case 'FISCALYEAR':
$this->_groupByArray[$tableName . '_' . $fieldName . '_start'] = self::fiscalYearOffset($field['dbAlias']);
if (!empty($table['group_bys'][$fieldName]['frequency']) &&
!empty($this->_params['group_bys_freq'][$fieldName])
) {

case 'YEAR':
$this->_groupByArray[$tableName . '_' . $fieldName . '_start'] = " {$this->_params['group_bys_freq'][$fieldName]}({$field['dbAlias']})";
switch ($this->_params['group_bys_freq'][$fieldName]) {
case 'FISCALYEAR':
$this->_groupByArray[$tableName . '_' . $fieldName . '_start'] = self::fiscalYearOffset($field['dbAlias']);

default:
$this->_groupByArray[$tableName . '_' . $fieldName . '_start'] = "EXTRACT(YEAR_{$this->_params['group_bys_freq'][$fieldName]} FROM {$field['dbAlias']})";
case 'YEAR':
$this->_groupByArray[$tableName . '_' . $fieldName . '_start'] = " {$this->_params['group_bys_freq'][$fieldName]}({$field['dbAlias']})";

default:
$this->_groupByArray[$tableName . '_' . $fieldName . '_start'] = "EXTRACT(YEAR_{$this->_params['group_bys_freq'][$fieldName]} FROM {$field['dbAlias']})";

}
}
else {
if (!in_array($field['dbAlias'], $this->_groupByArray)) {
$this->_groupByArray[$tableName . '_' . $fieldName] = $field['dbAlias'];
}
}
else {
if (!in_array($field['dbAlias'], $this->_groupByArray)) {
$this->_groupByArray[$tableName . '_' . $fieldName] = $field['dbAlias'];
}
}
}

}

}
}
}
Expand Down
21 changes: 3 additions & 18 deletions CRM/Report/Form/Contribute/TopDonor.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ public function __construct() {
),
),
'filters' => $this->getBasicContactFilters(),
'group_bys' => ['contact_contact_id' => ['name' => 'id', 'required' => 1, 'no_display' => 1]],
),
'civicrm_line_item' => array(
'dao' => 'CRM_Price_DAO_LineItem',
),
);
$this->_columns += $this->getAddressColumns();
$this->_columns += $this->getAddressColumns(['group_by' => FALSE]);
$this->_columns += array(
'civicrm_contribution' => array(
'dao' => 'CRM_Contribute_DAO_Contribution',
Expand Down Expand Up @@ -159,6 +160,7 @@ public function __construct() {
'default' => array(1),
),
),
'group_bys' => ['contribution_currency' => ['name' => 'currency', 'required' => 1, 'no_display' => 1]],
),
'civicrm_financial_trxn' => array(
'dao' => 'CRM_Financial_DAO_FinancialTrxn',
Expand Down Expand Up @@ -208,19 +210,6 @@ public function __construct() {
parent::__construct();
}

public function preProcess() {
parent::preProcess();
}

/**
* Select only contact ID when adding to group.
*
* @todo consider moving that to parent to support AddToGroup in general.
*/
public function select() {
parent::select();
}

/**
* @param $fields
* @param $files
Expand Down Expand Up @@ -319,10 +308,6 @@ public function where() {
}
}

public function groupBy() {
$this->_groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, array("{$this->_aliases['civicrm_contact']}.id", "{$this->_aliases['civicrm_contribution']}.currency"));
}

/**
* Build output rows.
*
Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/api/v3/ReportTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ public function testReportTemplateGetStatisticsAllReports($reportID) {
public static function getReportTemplates() {
$reportsToSkip = array(
'activity' => 'does not respect function signature on from clause',
'contribute/topDonor' => 'construction of query in postProcess makes inaccessible ',
'event/income' => 'I do no understand why but error is Call to undefined method CRM_Report_Form_Event_Income::from() in CRM/Report/Form.php on line 2120',
'logging/contact/summary' => '(likely to be test related) probably logging off Undefined index: Form/Contact/LoggingSummary.php(231): PHP',
'logging/contribute/summary' => '(likely to be test related) probably logging off DB Error: no such table',
Expand Down

0 comments on commit c3fdd2b

Please sign in to comment.