Commit c3fdd2b7 authored by eileen's avatar eileen

Fix fatal on topDonor report

parent 0082105d
......@@ -1393,7 +1393,7 @@ class CRM_Report_Form extends CRM_Core_Form {
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;
......@@ -5191,45 +5191,45 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a
*/
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'];
}
}
}
}
}
}
}
......
......@@ -104,12 +104,13 @@ class CRM_Report_Form_Contribute_TopDonor extends CRM_Report_Form {
),
),
'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',
......@@ -159,6 +160,7 @@ class CRM_Report_Form_Contribute_TopDonor extends CRM_Report_Form {
'default' => array(1),
),
),
'group_bys' => ['contribution_currency' => ['name' => 'currency', 'required' => 1, 'no_display' => 1]],
),
'civicrm_financial_trxn' => array(
'dao' => 'CRM_Financial_DAO_FinancialTrxn',
......@@ -208,19 +210,6 @@ class CRM_Report_Form_Contribute_TopDonor extends CRM_Report_Form {
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
......@@ -319,10 +308,6 @@ class CRM_Report_Form_Contribute_TopDonor extends CRM_Report_Form {
}
}
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.
*
......
......@@ -188,7 +188,6 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase {
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',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment