Skip to content

Commit

Permalink
dev/core#2684 Fix filters tpl in civi reports to permit more than one…
Browse files Browse the repository at this point in the history
… table in a grouping
  • Loading branch information
eileenmcnaughton committed Jul 15, 2021
1 parent 0a7b867 commit cd3936f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
48 changes: 30 additions & 18 deletions CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ public function preProcessCommon() {
$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',
Expand Down Expand Up @@ -1325,29 +1325,36 @@ public function addColumns() {
*/
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
$operations = $this->getOperationPair(
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) ||
Expand Down Expand Up @@ -1446,15 +1453,16 @@ public function addFilters() {
}
}
}
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);
}

/**
Expand Down Expand Up @@ -2271,7 +2279,7 @@ public function dateClause(
}

if ($relative) {
list($from, $to) = $this->getFromTo($relative, $from, $to, $fromTime, $toTime);
[$from, $to] = $this->getFromTo($relative, $from, $to, $fromTime, $toTime);
}

if ($from) {
Expand Down Expand Up @@ -3396,7 +3404,7 @@ public function filterStat(&$statistics) {
$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.
Expand Down Expand Up @@ -3891,7 +3899,7 @@ public function whereMembershipTypeClause($value, $op) {
* @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);
}

/**
Expand Down Expand Up @@ -5844,6 +5852,10 @@ protected function buildColumns($specs, $tableName, $daoName = NULL, $tableAlias
}
}
}
if (isset($options['grouping'])) {
$columns[$tableName]['grouping'] = $options['grouping'];
$columns[$tableName]['group_title'] = $options['group_title'] ?? '';
}
return $columns;
}

Expand Down
34 changes: 12 additions & 22 deletions templates/CRM/Report/Form/Tabs/Filters.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,21 @@
+--------------------------------------------------------------------+
*}

<div id="report-tab-set-filters" class="civireport-criteria">
<table class="report-layout">
<div id="report-tab-set-filters" class="civireport-criteria">
<div class="report-layout">
{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}
</table>
{assign var="counter" value=0}
{/if}
{if $filterGroup.use_accordion_for_field_selection}
<div class="crm-accordion-wrapper crm-accordion collapsed">
<div class="crm-accordion-header">
{$filterGroups.$tableName.group_title}
{$filterGroup.group_title}
</div><!-- /.crm-accordion-header -->
<div class="crm-accordion-body">
<table class="report-layout">
{/if}
{foreach from=$table item=field key=fieldName}
<table class="report-layout">
{foreach from=$filterGroup.tables item=table key=tableName}
{foreach from=$table item=field key=fieldName}
{assign var=fieldOp value=$fieldName|cat:"_op"}
{assign var=filterVal value=$fieldName|cat:"_value"}
{assign var=filterMin value=$fieldName|cat:"_min"}
Expand All @@ -51,17 +45,13 @@
</td>
</tr>
{/if}
{/foreach}
{/foreach}
{if !empty($filterGroups.$tableName.group_title)}
</table>
</table>
{if $filterGroup.use_accordion_for_field_selection}
</div><!-- /.crm-accordion-body -->
</div><!-- /.crm-accordion-wrapper -->
{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 }
</table>
{/if}
</div>
</div>

0 comments on commit cd3936f

Please sign in to comment.