From a49d6344407db965af454c7febd8f67acc0b8dda Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Thu, 10 Sep 2015 08:38:48 -0400 Subject: [PATCH] CRM-17191 - ensure Participant list report works with custom Grouping Previously, we got a trace back if a user defined a group by clause. I've removed what appears to be crufty code that tries to add the group by fields to an ORDER BY statement - which conflicts with the existing ORDER BY statement and seems unnecessary. Also, if the user wants to group by another field, we should not group by the participant id. --- .../Form/Event/ParticipantListCount.php | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/CRM/Report/Form/Event/ParticipantListCount.php b/CRM/Report/Form/Event/ParticipantListCount.php index dfd83d9aad..98fc91d949 100644 --- a/CRM/Report/Form/Event/ParticipantListCount.php +++ b/CRM/Report/Form/Event/ParticipantListCount.php @@ -465,29 +465,15 @@ class CRM_Report_Form_Event_ParticipantListCount extends CRM_Report_Form_Event { $this->_whereClauses[] = "{$this->_aliases['civicrm_participant']}.is_test = 0"; } + // We override this function because we use GROUP functions in the + // SELECT clause, therefore we have to group by *something*. If the + // user doesn't select a column to group by, we should group by + // participant id. public function groupBy() { - $this->_groupBy = ""; - if (!empty($this->_params['group_bys']) && - is_array($this->_params['group_bys']) && - !empty($this->_params['group_bys']) - ) { - foreach ($this->_columns as $tableName => $table) { - if (array_key_exists('group_bys', $table)) { - foreach ($table['group_bys'] as $fieldName => $field) { - if (!empty($this->_params['group_bys'][$fieldName])) { - $this->_groupBy[] = $field['dbAlias']; - } - } - } - } - } - - if (!empty($this->_groupBy)) { - $this->_groupBy = "ORDER BY " . implode(', ', $this->_groupBy) . - ", {$this->_aliases['civicrm_contact']}.sort_name"; + parent::groupBy(); + if(empty($this->_groupBy)) { + $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_participant']}.id"; } - $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_participant']}.id " . - $this->_groupBy; } public function postProcess() { -- 2.25.1