3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * CiviCRM's Smarty report section totals plugin
15 * Prints the correct report section total based on the given key and order in the section hierarchy
18 * @author Allen Shaw <allen@nswebsolutions.com>
19 * @copyright CiviCRM LLC https://civicrm.org/licensing
23 * Smarty block function for printing the correct report section total
25 * Smarty param: string $key value of the current section column
26 * Smarty param: int $depth the depth of the current section
27 * (sections declared first have lesser depth, starting at 0)
29 * @param array $params
30 * Template call's parameters.
31 * @param CRM_Core_Smarty $smarty
35 * the string, translated by gettext
37 function smarty_function_sectionTotal($params, &$smarty) {
38 /* section totals are stored in template variable 'sectionTotals',
39 * which is a two-dimensional array keyed to a string which is a delimited
40 * concatenation (using CRM_Core_DAO::VALUE_SEPARATOR) of ordered permutations
41 * of section header values, e.g.,
43 * 'foo[VALUE_SEAPARATOR]bar' => 5,
44 * 'foo[VALUE_SEAPARATOR]bar2' => 5
45 * Note: This array is created and assigned to the template in CRM_Report_Form::sectionTotals()
48 static $sectionValues = [];
50 // move back in the stack, if necessary
51 if (count($sectionValues) > $params['depth']) {
52 $sectionValues = array_slice($sectionValues, 0, $params['depth']);
55 // append the current value
56 $sectionValues[] = $params['key'];
58 // concatenate with pipes to build the right key
59 $totalsKey = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $sectionValues);
61 // return the corresponding total
62 return $smarty->_tpl_vars
['sectionTotals'][$totalsKey];