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;
*/
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'];
}
}
}
-
}
+
}
}
}
),
),
'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',
'default' => array(1),
),
),
+ 'group_bys' => ['contribution_currency' => ['name' => 'currency', 'required' => 1, 'no_display' => 1]],
),
'civicrm_financial_trxn' => array(
'dao' => 'CRM_Financial_DAO_FinancialTrxn',
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
}
}
- 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.
*