From 534c4d202cece62ce00e2a94cb55e89db669f07a Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 8 Dec 2017 13:39:38 +1300 Subject: [PATCH] CRM-19060 preliminary extract code to store group by array --- CRM/Report/Form.php | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 176bed40c1..75a614c836 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -814,6 +814,9 @@ class CRM_Report_Form extends CRM_Core_Form { } } } + if (!isset($this->_columns[$tableName]['metadata'][$fieldName])) { + $this->_columns[$tableName]['metadata'][$fieldName] = $this->_columns[$tableName][$fieldGrp][$fieldName]; + } } } } @@ -2281,6 +2284,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND */ public function select() { $select = $this->_selectAliases = array(); + $this->storeGroupByArray(); foreach ($this->_columns as $tableName => $table) { if (array_key_exists('fields', $table)) { @@ -5182,6 +5186,54 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a return $columns; } + /** + * Store group bys into array - so we can check elsewhere what is grouped. + */ + 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 (!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 * -- 2.25.1