From 146578dfc17d9d86d07af7903bfe6202d94dad07 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 11 Oct 2023 14:59:23 +1300 Subject: [PATCH] Fix smarty compatibility on Report totals --- .../Smarty/plugins/function.sectionTotal.php | 9 +- templates/CRM/Report/Form/Layout/Table.tpl | 156 +++++++++--------- templates/CRM/Report/Form/Statistics.tpl | 4 +- templates/CRM/Report/Form/Tabs/Filters.tpl | 2 +- 4 files changed, 85 insertions(+), 86 deletions(-) diff --git a/CRM/Core/Smarty/plugins/function.sectionTotal.php b/CRM/Core/Smarty/plugins/function.sectionTotal.php index 37e3068652..5cc7fb5c3e 100644 --- a/CRM/Core/Smarty/plugins/function.sectionTotal.php +++ b/CRM/Core/Smarty/plugins/function.sectionTotal.php @@ -28,13 +28,14 @@ * * @param array $params * Template call's parameters. - * @param CRM_Core_Smarty $smarty - * The Smarty object. * * @return string * the string, translated by gettext + * + * @deprecated This is called from table.tpl but we aim to remove + * from there. */ -function smarty_function_sectionTotal($params, &$smarty) { +function smarty_function_sectionTotal(array $params) { /* section totals are stored in template variable 'sectionTotals', * which is a two-dimensional array keyed to a string which is a delimited * concatenation (using CRM_Core_DAO::VALUE_SEPARATOR) of ordered permutations @@ -59,5 +60,5 @@ function smarty_function_sectionTotal($params, &$smarty) { $totalsKey = implode(CRM_Core_DAO::VALUE_SEPARATOR, $sectionValues); // return the corresponding total - return $smarty->_tpl_vars['sectionTotals'][$totalsKey]; + return $params['totals'][$totalsKey]; } diff --git a/templates/CRM/Report/Form/Layout/Table.tpl b/templates/CRM/Report/Form/Layout/Table.tpl index e38b1c907a..8187b41455 100644 --- a/templates/CRM/Report/Form/Layout/Table.tpl +++ b/templates/CRM/Report/Form/Layout/Table.tpl @@ -52,91 +52,89 @@ {* pre-compile section header here, rather than doing it every time under foreach *} {capture assign=sectionHeaderTemplate} {assign var=columnCount value=$columnHeaders|@count} - {assign var=l value=$smarty.ldelim} - {assign var=r value=$smarty.rdelim} {assign var=pageBroke value=0} - {foreach from=$sections item=section key=column name=sections} - {counter assign="h"} - {$l}isValueChange value=$row.{$column} key="{$column}" assign=isValueChanged{$r} - {$l}if $isValueChanged{$r} - - {$l}if $sections.{$column}.type & 4{$r} - {$l}assign var=printValue value=$row.{$column}|crmDate{$r} - {$l}elseif $sections.{$column}.type eq 1024{$r} - {$l}assign var=printValue value=$row.{$column}|crmMoney{$r} - {$l}else{$r} - {$l}assign var=printValue value=$row.{$column}{$r} - {$l}/if{$r} - {$l}if $rowid neq 0{$r} - {if $section.pageBreak} - {$l}if $pageBroke >= {$h} or $pageBroke == 0{$r} - -
- - {$l}/if{$r} - {$l}assign var=pageBroke value={$h}{$r} - {/if} - {$l}/if{$r} - - {if $smarty.foreach.sections.last} - {$l}$tableHeader{$r} - {/if} - {$l}/if{$r} - {/foreach} {/capture} {foreach from=$rows item=row key=rowid} - {eval var=$sectionHeaderTemplate} - - {foreach from=$columnHeaders item=header key=field} - {assign var=fieldLink value=$field|cat:"_link"} - {assign var=fieldHover value=$field|cat:"_hover"} - {assign var=fieldClass value=$field|cat:"_class"} -
- - {$section.title|escape}: {$l}$printValue|default:"none"{$r} - ({$l}sectionTotal key=$row.{$column} depth={$smarty.foreach.sections.index}{$r}) - -
- {if array_key_exists($fieldLink, $row) && $row.$fieldLink} - - {/if} + {foreach from=$sections item=section key=column name=sections} + {counter start=1 assign="h"} + {assign var=sectionColumn value=$sections.$column} + {isValueChange value=$row.$column key=$column assign=isValueChanged} + {if $isValueChanged} - {if array_key_exists($field, $row) && is_array($row.$field)} - {foreach from=$row.$field item=fieldrow key=fieldid} -
{$fieldrow}
- {/foreach} - {elseif array_key_exists($field, $row) && $row.$field eq 'Subtotal'} - {$row.$field} - {elseif $header.type & 4 OR $header.type & 256} - {if $header.group_by eq 'MONTH' or $header.group_by eq 'QUARTER'} - {$row.$field|crmDate:$config->dateformatPartial} - {elseif $header.group_by eq 'YEAR'} - {$row.$field|crmDate:$config->dateformatYear} - {else} - {if $header.type == 4} - {$row.$field|truncate:10:''|crmDate} - {else} - {$row.$field|crmDate} - {/if} - {/if} - {elseif $header.type eq 1024} - {if $currencyColumn} - {$row.$field|crmMoney:$row.$currencyColumn} - {else} - {$row.$field|crmMoney} - {/if} - {elseif array_key_exists($field, $row)} - {$row.$field|smarty:nodefaults|purify} - {/if} + {if $sectionColumn.type & 4} + {assign var=printValue value=$row.$column|crmDate} + {elseif $sectionColumn.type eq 1024} + {assign var=printValue value=$row.$column|crmMoney} + {else} + {assign var=printValue value=$row.$column} + {/if} + {if $rowid neq 0} + {if $section.pageBreak} + {if $pageBroke >= $h or $pageBroke == 0} +
+
+ + {/if} + {assign var=pageBroke value=$h} + {/if} + {/if} + + {$section.title|escape}: {$printValue|default:"none"} + ({sectionTotal key=$row.$column depth=$smarty.foreach.sections.index totals=$sectionTotals}) + + + {if $smarty.foreach.sections.last} + {$tableHeader} + {/if} + {/if} + {/foreach} + + {foreach from=$columnHeaders item=header key=field} + {assign var=fieldLink value=$field|cat:"_link"} + {assign var=fieldHover value=$field|cat:"_hover"} + {assign var=fieldClass value=$field|cat:"_class"} + + {/foreach} + {/foreach} {if $grandStat} diff --git a/templates/CRM/Report/Form/Statistics.tpl b/templates/CRM/Report/Form/Statistics.tpl index e4625d9ab4..1564576e2d 100644 --- a/templates/CRM/Report/Form/Statistics.tpl +++ b/templates/CRM/Report/Form/Statistics.tpl @@ -37,9 +37,9 @@ {include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName=$fieldName hideRelativeLabel=1 from='_from' to='_to' class='' colspan=''} - {elseif $form.$fieldOp.html} + {elseif array_key_exists($fieldOp, $form) && $form.$fieldOp.html} -- 2.25.1
- {if array_key_exists($fieldLink, $row) && $row.$fieldLink}{/if} - - {/foreach} -
+ {if array_key_exists($fieldLink, $row) && $row.$fieldLink} + + {/if} + + {if array_key_exists($field, $row) && is_array($row.$field)} + {foreach from=$row.$field item=fieldrow key=fieldid} +
{$fieldrow}
+ {/foreach} + {elseif array_key_exists($field, $row) && $row.$field eq 'Subtotal'} + {$row.$field} + {elseif $header.type & 4 OR $header.type & 256} + {if $header.group_by eq 'MONTH' or $header.group_by eq 'QUARTER'} + {$row.$field|crmDate:$config->dateformatPartial} + {elseif $header.group_by eq 'YEAR'} + {$row.$field|crmDate:$config->dateformatYear} + {else} + {if $header.type == 4} + {$row.$field|truncate:10:''|crmDate} + {else} + {$row.$field|crmDate} + {/if} + {/if} + {elseif $header.type eq 1024} + {if $currencyColumn} + {$row.$field|crmMoney:$row.$currencyColumn} + {else} + {$row.$field|crmMoney} + {/if} + {elseif array_key_exists($field, $row)} + {$row.$field|smarty:nodefaults|purify} + {/if} + + {if array_key_exists($fieldLink, $row) && $row.$fieldLink}
{/if} +
{$row.title} - {if $row.type eq 1024} + {if array_key_exists('type', $row) && $row.type eq 1024} {$row.value|crmMoney|escape} - {elseif $row.type eq 2} + {elseif array_key_exists('type', $row) && $row.type eq 2} {$row.value|purify} {else} {$row.value|crmNumberFormat|escape} diff --git a/templates/CRM/Report/Form/Tabs/Filters.tpl b/templates/CRM/Report/Form/Tabs/Filters.tpl index e2f25de8b1..b3a701f52b 100644 --- a/templates/CRM/Report/Form/Tabs/Filters.tpl +++ b/templates/CRM/Report/Form/Tabs/Filters.tpl @@ -32,7 +32,7 @@ {if !empty($field.title)}{$field.title}{/if}