From f0fc18d187e624cc25d166f3e27221a9d0a6f9fe Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 9 Jul 2021 17:01:24 +1200 Subject: [PATCH] Fix filter grouping This requires / works with https://github.com/civicrm/civicrm-core/pull/20820 --- .../Form/Report/ActivityExtended.php | 21 ++++++++++++++++--- .../Form/Report/ExtendedReport.php | 21 ++++++++++++------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/CRM/Extendedreport/Form/Report/ActivityExtended.php b/CRM/Extendedreport/Form/Report/ActivityExtended.php index 998ddf76..6399e2e4 100755 --- a/CRM/Extendedreport/Form/Report/ActivityExtended.php +++ b/CRM/Extendedreport/Form/Report/ActivityExtended.php @@ -1,5 +1,8 @@ '', 'prefix_label' => 'Source Contact ::', 'filters' => TRUE, + 'grouping' => 'source', + 'group_title' => E::ts('Source Contact'), ] ) + $this->getColumns( 'Email', @@ -33,14 +38,18 @@ public function __construct() { 'prefix' => '', 'prefix_label' => 'Source Contact Email ::', 'filters' => TRUE, + 'grouping' => 'source', + 'group_title' => E::ts('Source Contact'), ] - ) + $this->getColumns( + ) + $this->getColumns( 'Contact', [ 'prefix' => 'target_', 'group_by' => TRUE, 'prefix_label' => 'Target Contact ::', 'filters' => TRUE, + 'grouping' => 'target', + 'group_title' => E::ts('Target Contact'), ] ) + $this->getColumns( 'Email', @@ -48,12 +57,16 @@ public function __construct() { 'prefix' => 'target_', 'prefix_label' => 'Target Contact Email ::', 'filters' => TRUE, + 'grouping' => 'target', + 'group_title' => E::ts('Target Contact'), ] ) + $this->getColumns( 'Contact', [ 'prefix' => 'assignee_', 'prefix_label' => 'Assignee Contact ::', 'filters' => TRUE, + 'grouping' => 'assignee', + 'group_title' => E::ts('Assignee Contact'), ] ) + $this->getColumns( 'Email', @@ -61,8 +74,11 @@ public function __construct() { 'prefix' => 'assignee_', 'prefix_label' => 'Assignee Contact Email ::', 'filters' => TRUE, + 'grouping' => 'assignee', + 'group_title' => E::ts('Assignee Contact'), ] ) + $this->getColumns('Activity', ['group_by' => TRUE]); + parent::__construct(); } @@ -85,8 +101,7 @@ public function from() { LEFT JOIN civicrm_case ON case_activity_civireport.case_id = civicrm_case.id "; } - - + $this->joinEmailFromContact(); $this->joinEmailFromContact('target_'); $this->joinEmailFromContact('assignee_'); diff --git a/CRM/Extendedreport/Form/Report/ExtendedReport.php b/CRM/Extendedreport/Form/Report/ExtendedReport.php index 2750c3d5..5fb590f8 100644 --- a/CRM/Extendedreport/Form/Report/ExtendedReport.php +++ b/CRM/Extendedreport/Form/Report/ExtendedReport.php @@ -1310,13 +1310,18 @@ public function addFilters() { $count = 1; foreach ($this->getMetadataByType($filterString) as $fieldName => $field) { $table = $field['table_key']; + $groupingKey = $field['group_title'] ?? ''; if ($filterString === 'filters') { - $filterGroups[$table] = [ - 'group_title' => $this->_columns[$field['table_key']]['group_title'], - 'use_accordian_for_field_selection' => TRUE, - ]; + $filterGroups[$groupingKey]['group_title'] = $field['group_title'] ?? ''; + if (isset($field['use_accordion_for_field_selection'])) { + $filterGroups[$groupingKey]['use_accordion_for_field_selection'] = $field['table_key']['use_accordion_for_field_selection']; + } + else { + $filterGroups[$groupingKey]['use_accordion_for_field_selection'] = TRUE; + } } $prefix = ($filterString === 'join_filters') ? 'join_filter_' : ''; + $filterGroups[$groupingKey]['tables'][$table][$prefix . $fieldName] = $field; $filters[$table][$prefix . $fieldName] = $field; $this->addFilterFieldsToReport($field, $fieldName, $table, $count, $prefix); } @@ -3206,14 +3211,14 @@ protected function buildColumns($specs, $tableName, $daoName = NULL, $tableAlias $columns[$tableName]['prefix_label'] = isset($options['prefix_label']) ? $options['prefix_label'] : ''; $columns[$tableName]['is_required_for_acls'] = $options['is_required_for_acls'] ?? FALSE; if (isset($options['group_title'])) { - $groupTitle = $options['group_title']; + $columns[$tableName]['group_title'] = $options['group_title']; + $columns[$tableName]['grouping'] = $options['grouping']; } else { - // We can make one up but it won't be translated.... - $groupTitle = ucfirst(str_replace('_', ' ', str_replace('civicrm_', '', $tableName))); + $columns[$tableName]['group_title'] = ucfirst(str_replace('_', ' ', str_replace('civicrm_', '', $tableName))); } - $columns[$tableName]['group_title'] = $groupTitle; + return $columns; }