Skip to content

Commit

Permalink
CRM-19060 preliminary extract code to store group by array
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Dec 8, 2017
1 parent 4b885f8 commit 2cca5f9
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,9 @@ public function preProcess() {
}
}
}
if (!isset($this->_columns[$tableName]['metadata'][$fieldName])) {
$this->_columns[$tableName]['metadata'][$fieldName] = $this->_columns[$tableName][$fieldGrp][$fieldName];
}
}
}
}
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 2cca5f9

Please sign in to comment.