From cd3936f8d53d18465aa236a6c156f5cef6100d92 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 9 Jul 2021 13:46:51 +1200 Subject: [PATCH] dev/core#2684 Fix filters tpl in civi reports to permit more than one table in a grouping --- CRM/Report/Form.php | 48 ++++++++++++++-------- templates/CRM/Report/Form/Tabs/Filters.tpl | 34 ++++++--------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 369628754d..1bb30fb303 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -684,7 +684,7 @@ class CRM_Report_Form extends CRM_Core_Form { $this->assign('mode', 'instance'); } elseif (!$this->noController) { - list($optionValueID, $optionValue) = CRM_Report_Utils_Report::getValueIDFromUrl(); + [$optionValueID, $optionValue] = CRM_Report_Utils_Report::getValueIDFromUrl(); $instanceCount = CRM_Report_Utils_Report::getInstanceCount($optionValue); if (($instanceCount > 0) && $optionValueID) { $this->assign('instanceUrl', @@ -1325,20 +1325,29 @@ class CRM_Report_Form extends CRM_Core_Form { */ public function addFilters() { $filters = $filterGroups = []; - $count = 1; foreach ($this->_filters as $table => $attributes) { - if (isset($this->_columns[$table]['group_title'])) { - // The presence of 'group_title' is secret code for 'is_a_custom_table' - // which magically means to 'display in an accordian' - // here we make this explicit. - $filterGroups[$table] = [ - 'group_title' => $this->_columns[$table]['group_title'], - 'use_accordian_for_field_selection' => TRUE, - - ]; + $groupingKey = $this->_columns[$table]['grouping'] ?? ''; + $filterGroups[$groupingKey]['tables'][$table] = []; + // If a prior table hasn't set group title then set it. + if (empty($filterGroups[$groupingKey]['group_title'])) { + $filterGroups[$groupingKey]['group_title'] = $this->_columns[$table]['group_title'] ?? ''; } + // The presence of 'group_title' is secret code for 'display in an accordion' + // here we make this explicit. + if (!isset($filterGroups[$groupingKey]['use_accordion_for_field_selection'])) { + if (isset($this->_columns[$table]['use_accordion_for_field_selection'])) { + $filterGroups[$groupingKey]['use_accordion_for_field_selection'] = $this->_columns[$table]['use_accordion_for_field_selection']; + } + else { + $filterGroups[$groupingKey]['use_accordion_for_field_selection'] = isset($this->_columns[$table]['group_title']); + } + } + foreach ($attributes as $fieldName => $field) { + $filterGroups[$groupingKey]['tables'][$table][$fieldName] = $field; + // Filters is deprecated in favour of filterGroups. + $filters[$table][$fieldName] = $field; // get ready with option value pair // @ todo being able to specific options for a field (e.g a date field) in the field spec as an array rather than an override // would be useful @@ -1346,8 +1355,6 @@ class CRM_Report_Form extends CRM_Core_Form { CRM_Utils_Array::value('operatorType', $field), $fieldName); - $filters[$table][$fieldName] = $field; - switch (CRM_Utils_Array::value('operatorType', $field)) { case CRM_Report_Form::OP_MONTH: if (!array_key_exists('options', $field) || @@ -1446,15 +1453,16 @@ class CRM_Report_Form extends CRM_Core_Form { } } } - if (!empty($filters)) { + if (!empty($filterGroups)) { $this->tabs['Filters'] = [ 'title' => ts('Filters'), 'tpl' => 'Filters', 'div_label' => 'set-filters', ]; } - $this->assign('filters', $filters); $this->assign('filterGroups', $filterGroups); + // Filters is deprecated in favour of filterGroups. + $this->assign('filters', $filters); } /** @@ -2271,7 +2279,7 @@ class CRM_Report_Form extends CRM_Core_Form { } if ($relative) { - list($from, $to) = $this->getFromTo($relative, $from, $to, $fromTime, $toTime); + [$from, $to] = $this->getFromTo($relative, $from, $to, $fromTime, $toTime); } if ($from) { @@ -3396,7 +3404,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND $from = $this->_params["{$fieldName}_from"] ?? NULL; $to = $this->_params["{$fieldName}_to"] ?? NULL; if (!empty($this->_params["{$fieldName}_relative"])) { - list($from, $to) = CRM_Utils_Date::getFromTo($this->_params["{$fieldName}_relative"], NULL, NULL); + [$from, $to] = CRM_Utils_Date::getFromTo($this->_params["{$fieldName}_relative"], NULL, NULL); } if (strlen($to) === 10) { // If we just have the date we assume the end of that day. @@ -3891,7 +3899,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND * @param string $tableAlias */ public function buildACLClause($tableAlias = 'contact_a') { - list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias); + [$this->_aclFrom, $this->_aclWhere] = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias); } /** @@ -5844,6 +5852,10 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a } } } + if (isset($options['grouping'])) { + $columns[$tableName]['grouping'] = $options['grouping']; + $columns[$tableName]['group_title'] = $options['group_title'] ?? ''; + } return $columns; } diff --git a/templates/CRM/Report/Form/Tabs/Filters.tpl b/templates/CRM/Report/Form/Tabs/Filters.tpl index f32628a5a2..5324ca33af 100644 --- a/templates/CRM/Report/Form/Tabs/Filters.tpl +++ b/templates/CRM/Report/Form/Tabs/Filters.tpl @@ -8,27 +8,21 @@ +--------------------------------------------------------------------+ *} -
- +
+
{assign var="counter" value=1} - {foreach from=$filters item=table key=tableName} - {assign var="filterCount" value=$table|@count} + {foreach from=$filterGroups item=filterGroup} {* Wrap custom field sets in collapsed accordion pane. *} - {if !empty($filterGroups.$tableName.group_title) and $filterCount gte 1} - {* we should close table that contains other filter elements before we start building custom group accordion - *} - {if $counter eq 1} -
- {assign var="counter" value=0} - {/if} + {if $filterGroup.use_accordion_for_field_selection} - {assign var=closed value="1"} {*-- ie table tags are closed-- *} - {else} - {assign var=closed value="0"} {*-- ie table tags are not closed-- *} {/if} {/foreach} - {if $closed eq 0 } - - {/if}
+ -- 2.25.1