diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 176bed40c18a..250ded92561b 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -814,6 +814,9 @@ public function preProcess() { } } } + if (!isset($this->_columns[$tableName]['metadata'][$fieldName])) { + $this->_columns[$tableName]['metadata'][$fieldName] = $this->_columns[$tableName][$fieldGrp][$fieldName]; + } } } } @@ -2281,6 +2284,7 @@ public function buildChart(&$rows) { */ public function select() { $select = $this->_selectAliases = array(); + $this->storeGroupByArray(); foreach ($this->_columns as $tableName => $table) { if (array_key_exists('fields', $table)) { @@ -5182,6 +5186,55 @@ protected function buildColumns($specs, $tableName, $daoName = NULL, $tableAlias return $columns; } + /** + * Store group bys into array - so we can check elsewhere what is grouped. + */ + 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 (!empty($table['group_bys'][$fieldName]['frequency']) && + !empty($this->_params['group_bys_freq'][$fieldName]) + ) { + + switch ($this->_params['group_bys_freq'][$fieldName]) { + case 'FISCALYEAR' : + $this->_groupByArray[$tableName . '_' . $fieldName . '_start'] = self::fiscalYearOffset($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']; + } + } + } + } + + } + } + } + } + /** * @param $options *